2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/delay.h>
24 qla2x00_mbx_sem_timeout(unsigned long data)
26 struct semaphore *sem_ptr = (struct semaphore *)data;
28 DEBUG11(printk("qla2x00_sem_timeout: entered.\n");)
30 if (sem_ptr != NULL) {
34 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)
38 * qla2x00_mailbox_command
39 * Issue mailbox command and waits for completion.
42 * ha = adapter block pointer.
43 * mcp = driver internal mbx struct pointer.
46 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
49 * 0 : QLA_SUCCESS = cmd performed success
50 * 1 : QLA_FUNCTION_FAILED (error encountered)
51 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
57 qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
60 unsigned long flags = 0;
61 device_reg_t __iomem *reg = ha->iobase;
62 struct timer_list tmp_intr_timer;
64 uint8_t io_lock_on = ha->flags.init_done;
67 uint16_t __iomem *optr;
70 unsigned long mbx_flags = 0;
71 unsigned long wait_time;
74 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
76 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
79 * Wait for active mailbox commands to finish by waiting at most tov
80 * seconds. This is to serialize actual issuing of mailbox cmds during
84 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
85 /* Timeout occurred. Return error. */
86 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
87 "Exiting.\n", __func__, ha->host_no);)
88 return QLA_FUNCTION_TIMEOUT;
92 ha->flags.mbox_busy = 1;
93 /* Save mailbox command for debug */
96 /* Try to get mailbox register access */
98 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
100 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
101 ha->host_no, mcp->mb[0]);)
103 spin_lock_irqsave(&ha->hardware_lock, flags);
105 /* Load mailbox registers. */
106 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
107 optr = (uint16_t __iomem *)®->isp24.mailbox0;
109 optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0);
112 command = mcp->mb[0];
113 mboxes = mcp->out_mb;
115 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
116 if (IS_QLA2200(ha) && cnt == 8)
118 (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8);
120 WRT_REG_WORD(optr, *iptr);
127 #if defined(QL_DEBUG_LEVEL_1)
128 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
129 __func__, ha->host_no);
130 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
132 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
134 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
136 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
137 qla2x00_dump_regs(ha);
140 /* Issue set host interrupt command to send cmd out. */
141 ha->flags.mbox_int = 0;
142 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
144 /* Unlock mbx registers and wait for interrupt */
145 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
146 "jiffies=%lx.\n", __func__, ha->host_no, jiffies);)
148 /* Wait for mbx cmd completion until timeout */
150 if (!abort_active && io_lock_on) {
151 /* sleep on completion semaphore */
152 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
153 __func__, ha->host_no);)
155 init_timer(&tmp_intr_timer);
156 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
157 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
158 tmp_intr_timer.function =
159 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
161 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
163 add_timer(&tmp_intr_timer);
165 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
166 "time=0x%lx.\n", __func__, ha->host_no, jiffies);)
168 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
170 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
171 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
173 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
174 spin_unlock_irqrestore(&ha->hardware_lock, flags);
177 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
179 /* Wait for either the timer to expire
180 * or the mbox completion interrupt
182 down(&ha->mbx_intr_sem);
184 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
185 ha->host_no, jiffies);)
186 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
188 /* delete the timer */
189 del_timer(&tmp_intr_timer);
191 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
192 ha->host_no, command);)
194 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
195 WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT);
197 WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT);
198 spin_unlock_irqrestore(&ha->hardware_lock, flags);
200 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
202 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
203 while (!ha->flags.mbox_int) {
204 if (time_after(jiffies, wait_time))
207 /* Check for pending interrupts. */
210 udelay(10); /* v4.27 */
215 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
217 /* Check whether we timed out */
218 if (ha->flags.mbox_int) {
221 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
222 ha->host_no, command);)
224 /* Got interrupt. Clear the flag. */
225 ha->flags.mbox_int = 0;
226 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
228 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
229 rval = QLA_FUNCTION_FAILED;
231 /* Load return mailbox registers. */
233 iptr = (uint16_t *)&ha->mailbox_out[0];
235 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
245 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
246 defined(QL_DEBUG_LEVEL_11)
250 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
251 mb0 = RD_REG_WORD(®->isp24.mailbox0);
252 ictrl = RD_REG_DWORD(®->isp24.ictrl);
254 mb0 = RD_MAILBOX_REG(ha, reg->isp, 0);
255 ictrl = RD_REG_WORD(®->isp.ictrl);
257 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
258 __func__, ha->host_no, command);
259 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
260 ha->host_no, ictrl, jiffies);
261 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
263 qla2x00_dump_regs(ha);
266 rval = QLA_FUNCTION_TIMEOUT;
270 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
272 ha->flags.mbox_busy = 0;
278 DEBUG11(printk("%s(%ld): checking for additional resp "
279 "interrupt.\n", __func__, ha->host_no);)
281 /* polling mode for non isp_abort commands. */
285 if (rval == QLA_FUNCTION_TIMEOUT &&
286 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
287 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
288 /* not in dpc. schedule it for dpc to take over. */
289 DEBUG(printk("%s(%ld): timeout schedule "
290 "isp_abort_needed.\n", __func__, ha->host_no);)
291 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
292 "isp_abort_needed.\n", __func__, ha->host_no);)
293 qla_printk(KERN_WARNING, ha,
294 "Mailbox command timeout occured. Scheduling ISP "
296 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
297 if (ha->dpc_wait && !ha->dpc_active)
300 } else if (!abort_active) {
301 /* call abort directly since we are in the DPC thread */
302 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
303 __func__, ha->host_no);)
304 DEBUG2_3_11(printk("%s(%ld): timeout calling "
305 "abort_isp\n", __func__, ha->host_no);)
306 qla_printk(KERN_WARNING, ha,
307 "Mailbox command timeout occured. Issuing ISP "
310 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
311 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
312 if (qla2x00_abort_isp(ha)) {
313 /* Failed. retry later. */
314 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
316 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
317 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
319 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
320 __func__, ha->host_no);)
324 /* Allow next mbx cmd to come in. */
326 up(&ha->mbx_cmd_sem);
329 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
330 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
331 mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
333 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
341 * Load adapter RAM using DMA.
344 * ha = adapter block pointer.
347 * qla2x00 local function return status code.
353 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
354 uint16_t risc_code_size)
358 mbx_cmd_t *mcp = &mc;
364 DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
367 req_len = risc_code_size;
371 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
374 /* Load first segment */
375 mcp->mb[0] = MBC_LOAD_RISC_RAM;
376 mcp->mb[1] = risc_addr;
377 mcp->mb[2] = MSW(req_dma);
378 mcp->mb[3] = LSW(req_dma);
379 mcp->mb[4] = (uint16_t)req_len;
380 mcp->mb[6] = MSW(MSD(req_dma));
381 mcp->mb[7] = LSW(MSD(req_dma));
382 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
386 rval = qla2x00_mailbox_command(ha, mcp);
388 /* Load second segment - if necessary */
389 if (normalized && (rval == QLA_SUCCESS)) {
390 mcp->mb[0] = MBC_LOAD_RISC_RAM;
391 mcp->mb[1] = risc_addr + (uint16_t)req_len;
392 mcp->mb[2] = MSW(nml_dma);
393 mcp->mb[3] = LSW(nml_dma);
394 mcp->mb[4] = (uint16_t)nml_len;
395 mcp->mb[6] = MSW(MSD(nml_dma));
396 mcp->mb[7] = LSW(MSD(nml_dma));
397 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
401 rval = qla2x00_mailbox_command(ha, mcp);
404 if (rval == QLA_SUCCESS) {
406 DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
409 DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
410 "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
416 * qla2x00_load_ram_ext
417 * Load adapter extended RAM using DMA.
420 * ha = adapter block pointer.
423 * qla2x00 local function return status code.
429 qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
430 uint32_t risc_addr, uint32_t risc_code_size)
434 mbx_cmd_t *mcp = &mc;
436 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
438 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
439 mcp->mb[1] = LSW(risc_addr);
440 mcp->mb[2] = MSW(req_dma);
441 mcp->mb[3] = LSW(req_dma);
442 mcp->mb[6] = MSW(MSD(req_dma));
443 mcp->mb[7] = LSW(MSD(req_dma));
444 mcp->mb[8] = MSW(risc_addr);
445 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
446 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
447 mcp->mb[4] = MSW(risc_code_size);
448 mcp->mb[5] = LSW(risc_code_size);
449 mcp->out_mb |= MBX_5|MBX_4;
451 mcp->mb[4] = LSW(risc_code_size);
452 mcp->out_mb |= MBX_4;
458 rval = qla2x00_mailbox_command(ha, mcp);
460 if (rval != QLA_SUCCESS) {
461 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
462 ha->host_no, rval, mcp->mb[0]));
464 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
472 * Start adapter firmware.
475 * ha = adapter block pointer.
476 * TARGET_QUEUE_LOCK must be released.
477 * ADAPTER_STATE_LOCK must be released.
480 * qla2x00 local function return status code.
486 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
490 mbx_cmd_t *mcp = &mc;
492 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
494 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
497 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
498 mcp->mb[1] = MSW(risc_addr);
499 mcp->mb[2] = LSW(risc_addr);
501 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
504 mcp->mb[1] = LSW(risc_addr);
505 mcp->out_mb |= MBX_1;
506 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
508 mcp->out_mb |= MBX_2;
514 rval = qla2x00_mailbox_command(ha, mcp);
516 if (rval != QLA_SUCCESS) {
517 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
518 ha->host_no, rval, mcp->mb[0]));
520 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
521 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
522 __func__, ha->host_no, mcp->mb[1]);)
524 DEBUG11(printk("%s(%ld): done.\n", __func__,
533 * qla2x00_get_fw_version
534 * Get firmware version.
537 * ha: adapter state pointer.
538 * major: pointer for major number.
539 * minor: pointer for minor number.
540 * subminor: pointer for subminor number.
543 * qla2x00 local function return status code.
549 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
550 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
554 mbx_cmd_t *mcp = &mc;
556 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
558 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
560 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
563 rval = qla2x00_mailbox_command(ha, mcp);
565 /* Return mailbox data. */
568 *subminor = mcp->mb[3];
569 *attributes = mcp->mb[6];
570 if (IS_QLA2100(ha) || IS_QLA2200(ha))
571 *memory = 0x1FFFF; /* Defaults to 128KB. */
573 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
575 if (rval != QLA_SUCCESS) {
577 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
581 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
586 * qla2x00_get_fw_options
587 * Set firmware options.
590 * ha = adapter block pointer.
591 * fwopt = pointer for firmware options.
594 * qla2x00 local function return status code.
600 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
604 mbx_cmd_t *mcp = &mc;
606 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
608 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
610 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
613 rval = qla2x00_mailbox_command(ha, mcp);
615 if (rval != QLA_SUCCESS) {
617 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
620 fwopts[0] = mcp->mb[0];
621 fwopts[1] = mcp->mb[1];
622 fwopts[2] = mcp->mb[2];
623 fwopts[3] = mcp->mb[3];
625 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
633 * qla2x00_set_fw_options
634 * Set firmware options.
637 * ha = adapter block pointer.
638 * fwopt = pointer for firmware options.
641 * qla2x00 local function return status code.
647 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
651 mbx_cmd_t *mcp = &mc;
653 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
655 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
656 mcp->mb[1] = fwopts[1];
657 mcp->mb[2] = fwopts[2];
658 mcp->mb[3] = fwopts[3];
659 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
661 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
664 mcp->mb[10] = fwopts[10];
665 mcp->mb[11] = fwopts[11];
666 mcp->mb[12] = 0; /* Undocumented, but used */
667 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
671 rval = qla2x00_mailbox_command(ha, mcp);
673 fwopts[0] = mcp->mb[0];
675 if (rval != QLA_SUCCESS) {
677 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
678 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
681 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
688 * qla2x00_mbx_reg_test
689 * Mailbox register wrap test.
692 * ha = adapter block pointer.
693 * TARGET_QUEUE_LOCK must be released.
694 * ADAPTER_STATE_LOCK must be released.
697 * qla2x00 local function return status code.
703 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
707 mbx_cmd_t *mcp = &mc;
709 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
711 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
719 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
720 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
723 rval = qla2x00_mailbox_command(ha, mcp);
725 if (rval == QLA_SUCCESS) {
726 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
727 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
728 rval = QLA_FUNCTION_FAILED;
729 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
730 mcp->mb[7] != 0x2525)
731 rval = QLA_FUNCTION_FAILED;
734 if (rval != QLA_SUCCESS) {
736 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
740 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
748 * qla2x00_verify_checksum
749 * Verify firmware checksum.
752 * ha = adapter block pointer.
753 * TARGET_QUEUE_LOCK must be released.
754 * ADAPTER_STATE_LOCK must be released.
757 * qla2x00 local function return status code.
763 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
767 mbx_cmd_t *mcp = &mc;
769 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
771 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
774 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
775 mcp->mb[1] = MSW(risc_addr);
776 mcp->mb[2] = LSW(risc_addr);
777 mcp->out_mb |= MBX_2|MBX_1;
778 mcp->in_mb |= MBX_2|MBX_1;
780 mcp->mb[1] = LSW(risc_addr);
781 mcp->out_mb |= MBX_1;
787 rval = qla2x00_mailbox_command(ha, mcp);
789 if (rval != QLA_SUCCESS) {
790 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
791 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
792 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));)
794 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
802 * Issue IOCB using mailbox command
805 * ha = adapter state pointer.
806 * buffer = buffer pointer.
807 * phys_addr = physical address of buffer.
808 * size = size of buffer.
809 * TARGET_QUEUE_LOCK must be released.
810 * ADAPTER_STATE_LOCK must be released.
813 * qla2x00 local function return status code.
819 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
824 mbx_cmd_t *mcp = &mc;
826 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
828 mcp->mb[2] = MSW(phys_addr);
829 mcp->mb[3] = LSW(phys_addr);
830 mcp->mb[6] = MSW(MSD(phys_addr));
831 mcp->mb[7] = LSW(MSD(phys_addr));
832 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
833 mcp->in_mb = MBX_2|MBX_0;
836 rval = qla2x00_mailbox_command(ha, mcp);
838 if (rval != QLA_SUCCESS) {
840 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
842 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
845 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
847 /* Mask reserved bits. */
848 sts_entry->entry_status &=
849 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RF_MASK_24XX :RF_MASK;
856 * qla2x00_abort_command
857 * Abort command aborts a specified IOCB.
860 * ha = adapter block pointer.
861 * sp = SB structure pointer.
864 * qla2x00 local function return status code.
870 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
872 unsigned long flags = 0;
877 mbx_cmd_t *mcp = &mc;
879 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
882 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
883 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
887 spin_lock_irqsave(&ha->hardware_lock, flags);
888 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
889 if (ha->outstanding_cmds[handle] == sp)
892 spin_unlock_irqrestore(&ha->hardware_lock, flags);
894 if (handle == MAX_OUTSTANDING_COMMANDS) {
895 /* command not found */
896 return QLA_FUNCTION_FAILED;
899 mcp->mb[0] = MBC_ABORT_COMMAND;
900 if (HAS_EXTENDED_IDS(ha))
901 mcp->mb[1] = fcport->loop_id;
903 mcp->mb[1] = fcport->loop_id << 8;
904 mcp->mb[2] = (uint16_t)handle;
905 mcp->mb[3] = (uint16_t)(handle >> 16);
906 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
907 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
911 rval = qla2x00_mailbox_command(ha, mcp);
913 if (rval != QLA_SUCCESS) {
914 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
917 sp->flags |= SRB_ABORT_PENDING;
918 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
927 * qla2x00_abort_target
928 * Issue abort target mailbox command.
931 * ha = adapter block pointer.
934 * qla2x00 local function return status code.
940 qla2x00_abort_target(fc_port_t *fcport)
944 mbx_cmd_t *mcp = &mc;
950 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
953 mcp->mb[0] = MBC_ABORT_TARGET;
954 mcp->out_mb = MBX_2|MBX_1|MBX_0;
955 if (HAS_EXTENDED_IDS(ha)) {
956 mcp->mb[1] = fcport->loop_id;
958 mcp->out_mb |= MBX_10;
960 mcp->mb[1] = fcport->loop_id << 8;
962 mcp->mb[2] = ha->loop_reset_delay;
967 rval = qla2x00_mailbox_command(ha, mcp);
969 /* Issue marker command. */
970 ha->marker_needed = 1;
972 if (rval != QLA_SUCCESS) {
973 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
977 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
986 * qla2x00_target_reset
987 * Issue target reset mailbox command.
990 * ha = adapter block pointer.
991 * TARGET_QUEUE_LOCK must be released.
992 * ADAPTER_STATE_LOCK must be released.
995 * qla2x00 local function return status code.
1001 qla2x00_target_reset(scsi_qla_host_t *ha, struct fc_port *fcport)
1005 mbx_cmd_t *mcp = &mc;
1007 DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
1009 if (atomic_read(&fcport->state) != FCS_ONLINE)
1012 mcp->mb[0] = MBC_TARGET_RESET;
1013 if (HAS_EXTENDED_IDS(ha))
1014 mcp->mb[1] = fcport->loop_id;
1016 mcp->mb[1] = fcport->loop_id << 8;
1017 mcp->mb[2] = ha->loop_reset_delay;
1018 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1022 rval = qla2x00_mailbox_command(ha, mcp);
1024 if (rval != QLA_SUCCESS) {
1026 DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
1027 ha->host_no, rval);)
1030 DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
1038 * qla2x00_get_adapter_id
1039 * Get adapter ID and topology.
1042 * ha = adapter block pointer.
1043 * id = pointer for loop ID.
1044 * al_pa = pointer for AL_PA.
1045 * area = pointer for area.
1046 * domain = pointer for domain.
1047 * top = pointer for topology.
1048 * TARGET_QUEUE_LOCK must be released.
1049 * ADAPTER_STATE_LOCK must be released.
1052 * qla2x00 local function return status code.
1058 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
1059 uint8_t *area, uint8_t *domain, uint16_t *top)
1063 mbx_cmd_t *mcp = &mc;
1065 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
1068 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
1069 mcp->out_mb = MBX_0;
1070 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1073 rval = qla2x00_mailbox_command(ha, mcp);
1077 *al_pa = LSB(mcp->mb[2]);
1078 *area = MSB(mcp->mb[2]);
1079 *domain = LSB(mcp->mb[3]);
1082 if (rval != QLA_SUCCESS) {
1084 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
1085 ha->host_no, rval);)
1088 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
1096 * qla2x00_get_retry_cnt
1097 * Get current firmware login retry count and delay.
1100 * ha = adapter block pointer.
1101 * retry_cnt = pointer to login retry count.
1102 * tov = pointer to login timeout value.
1105 * qla2x00 local function return status code.
1111 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
1117 mbx_cmd_t *mcp = &mc;
1119 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1122 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1123 mcp->out_mb = MBX_0;
1124 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1127 rval = qla2x00_mailbox_command(ha, mcp);
1129 if (rval != QLA_SUCCESS) {
1131 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1132 ha->host_no, mcp->mb[0]);)
1134 /* Convert returned data and check our values. */
1135 *r_a_tov = mcp->mb[3] / 2;
1136 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1137 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1138 /* Update to the larger values */
1139 *retry_cnt = (uint8_t)mcp->mb[1];
1143 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1144 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
1151 * qla2x00_init_firmware
1152 * Initialize adapter firmware.
1155 * ha = adapter block pointer.
1156 * dptr = Initialization control block pointer.
1157 * size = size of initialization control block.
1158 * TARGET_QUEUE_LOCK must be released.
1159 * ADAPTER_STATE_LOCK must be released.
1162 * qla2x00 local function return status code.
1168 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1172 mbx_cmd_t *mcp = &mc;
1174 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1177 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1178 mcp->mb[2] = MSW(ha->init_cb_dma);
1179 mcp->mb[3] = LSW(ha->init_cb_dma);
1182 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1183 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1184 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1185 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1186 mcp->buf_size = size;
1187 mcp->flags = MBX_DMA_OUT;
1189 rval = qla2x00_mailbox_command(ha, mcp);
1191 if (rval != QLA_SUCCESS) {
1193 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1195 ha->host_no, rval, mcp->mb[0]);)
1198 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1206 * qla2x00_get_port_database
1207 * Issue normal/enhanced get port database mailbox command
1208 * and copy device name as necessary.
1211 * ha = adapter state pointer.
1212 * dev = structure pointer.
1213 * opt = enhanced cmd option byte.
1216 * qla2x00 local function return status code.
1222 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1226 mbx_cmd_t *mcp = &mc;
1227 port_database_t *pd;
1228 struct port_database_24xx *pd24;
1231 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1234 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1236 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1237 "structure.\n", __func__, ha->host_no));
1238 return QLA_MEMORY_ALLOC_FAILED;
1240 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1242 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1243 if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA25XX(ha))
1244 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1245 mcp->mb[2] = MSW(pd_dma);
1246 mcp->mb[3] = LSW(pd_dma);
1247 mcp->mb[6] = MSW(MSD(pd_dma));
1248 mcp->mb[7] = LSW(MSD(pd_dma));
1249 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1251 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1252 mcp->mb[1] = fcport->loop_id;
1254 mcp->out_mb |= MBX_10|MBX_1;
1255 mcp->in_mb |= MBX_1;
1256 } else if (HAS_EXTENDED_IDS(ha)) {
1257 mcp->mb[1] = fcport->loop_id;
1259 mcp->out_mb |= MBX_10|MBX_1;
1261 mcp->mb[1] = fcport->loop_id << 8 | opt;
1262 mcp->out_mb |= MBX_1;
1264 mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
1265 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
1266 mcp->flags = MBX_DMA_IN;
1267 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1268 rval = qla2x00_mailbox_command(ha, mcp);
1269 if (rval != QLA_SUCCESS)
1272 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1273 pd24 = (struct port_database_24xx *) pd;
1275 /* Check for logged in state. */
1276 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1277 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1278 DEBUG2(printk("%s(%ld): Unable to verify "
1279 "login-state (%x/%x) for loop_id %x\n",
1280 __func__, ha->host_no,
1281 pd24->current_login_state,
1282 pd24->last_login_state, fcport->loop_id));
1283 rval = QLA_FUNCTION_FAILED;
1287 /* Names are little-endian. */
1288 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1289 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1291 /* Get port_id of device. */
1292 fcport->d_id.b.domain = pd24->port_id[0];
1293 fcport->d_id.b.area = pd24->port_id[1];
1294 fcport->d_id.b.al_pa = pd24->port_id[2];
1295 fcport->d_id.b.rsvd_1 = 0;
1297 /* If not target must be initiator or unknown type. */
1298 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1299 fcport->port_type = FCT_INITIATOR;
1301 fcport->port_type = FCT_TARGET;
1303 /* Check for logged in state. */
1304 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1305 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1306 rval = QLA_FUNCTION_FAILED;
1310 /* Names are little-endian. */
1311 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1312 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1314 /* Get port_id of device. */
1315 fcport->d_id.b.domain = pd->port_id[0];
1316 fcport->d_id.b.area = pd->port_id[3];
1317 fcport->d_id.b.al_pa = pd->port_id[2];
1318 fcport->d_id.b.rsvd_1 = 0;
1320 /* Check for device require authentication. */
1321 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1322 (fcport->flags &= ~FCF_AUTH_REQ);
1324 /* If not target must be initiator or unknown type. */
1325 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1326 fcport->port_type = FCT_INITIATOR;
1328 fcport->port_type = FCT_TARGET;
1332 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1334 if (rval != QLA_SUCCESS) {
1335 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1336 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1338 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1345 * qla2x00_get_firmware_state
1346 * Get adapter firmware state.
1349 * ha = adapter block pointer.
1350 * dptr = pointer for firmware state.
1351 * TARGET_QUEUE_LOCK must be released.
1352 * ADAPTER_STATE_LOCK must be released.
1355 * qla2x00 local function return status code.
1361 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1365 mbx_cmd_t *mcp = &mc;
1367 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1370 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1371 mcp->out_mb = MBX_0;
1372 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1375 rval = qla2x00_mailbox_command(ha, mcp);
1377 /* Return firmware state. */
1380 if (rval != QLA_SUCCESS) {
1382 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1383 "failed=%x.\n", ha->host_no, rval);)
1386 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1394 * qla2x00_get_port_name
1395 * Issue get port name mailbox command.
1396 * Returned name is in big endian format.
1399 * ha = adapter block pointer.
1400 * loop_id = loop ID of device.
1401 * name = pointer for name.
1402 * TARGET_QUEUE_LOCK must be released.
1403 * ADAPTER_STATE_LOCK must be released.
1406 * qla2x00 local function return status code.
1412 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1417 mbx_cmd_t *mcp = &mc;
1419 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1422 mcp->mb[0] = MBC_GET_PORT_NAME;
1423 mcp->out_mb = MBX_1|MBX_0;
1424 if (HAS_EXTENDED_IDS(ha)) {
1425 mcp->mb[1] = loop_id;
1427 mcp->out_mb |= MBX_10;
1429 mcp->mb[1] = loop_id << 8 | opt;
1432 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1435 rval = qla2x00_mailbox_command(ha, mcp);
1437 if (rval != QLA_SUCCESS) {
1439 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1440 ha->host_no, rval);)
1443 /* This function returns name in big endian. */
1444 name[0] = LSB(mcp->mb[2]);
1445 name[1] = MSB(mcp->mb[2]);
1446 name[2] = LSB(mcp->mb[3]);
1447 name[3] = MSB(mcp->mb[3]);
1448 name[4] = LSB(mcp->mb[6]);
1449 name[5] = MSB(mcp->mb[6]);
1450 name[6] = LSB(mcp->mb[7]);
1451 name[7] = MSB(mcp->mb[7]);
1454 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1463 * Issue LIP reset mailbox command.
1466 * ha = adapter block pointer.
1467 * TARGET_QUEUE_LOCK must be released.
1468 * ADAPTER_STATE_LOCK must be released.
1471 * qla2x00 local function return status code.
1477 qla2x00_lip_reset(scsi_qla_host_t *ha)
1481 mbx_cmd_t *mcp = &mc;
1483 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1485 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1486 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1490 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1492 mcp->mb[0] = MBC_LIP_RESET;
1493 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1494 if (HAS_EXTENDED_IDS(ha)) {
1495 mcp->mb[1] = 0x00ff;
1497 mcp->out_mb |= MBX_10;
1499 mcp->mb[1] = 0xff00;
1501 mcp->mb[2] = ha->loop_reset_delay;
1507 rval = qla2x00_mailbox_command(ha, mcp);
1509 if (rval != QLA_SUCCESS) {
1511 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1512 __func__, ha->host_no, rval);)
1515 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1526 * ha = adapter block pointer.
1527 * sns = pointer for command.
1528 * cmd_size = command size.
1529 * buf_size = response/command size.
1530 * TARGET_QUEUE_LOCK must be released.
1531 * ADAPTER_STATE_LOCK must be released.
1534 * qla2x00 local function return status code.
1540 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1541 uint16_t cmd_size, size_t buf_size)
1545 mbx_cmd_t *mcp = &mc;
1547 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1550 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1551 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1553 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1554 mcp->mb[1] = cmd_size;
1555 mcp->mb[2] = MSW(sns_phys_address);
1556 mcp->mb[3] = LSW(sns_phys_address);
1557 mcp->mb[6] = MSW(MSD(sns_phys_address));
1558 mcp->mb[7] = LSW(MSD(sns_phys_address));
1559 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1560 mcp->in_mb = MBX_0|MBX_1;
1561 mcp->buf_size = buf_size;
1562 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1563 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1564 rval = qla2x00_mailbox_command(ha, mcp);
1566 if (rval != QLA_SUCCESS) {
1568 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1569 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1570 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1571 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1574 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1581 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1582 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1586 struct logio_entry_24xx *lg;
1590 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1592 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1594 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1595 __func__, ha->host_no));
1596 return QLA_MEMORY_ALLOC_FAILED;
1598 memset(lg, 0, sizeof(struct logio_entry_24xx));
1600 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1601 lg->entry_count = 1;
1602 lg->nport_handle = cpu_to_le16(loop_id);
1603 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1605 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1606 lg->port_id[0] = al_pa;
1607 lg->port_id[1] = area;
1608 lg->port_id[2] = domain;
1609 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1610 if (rval != QLA_SUCCESS) {
1611 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1612 "(%x).\n", __func__, ha->host_no, rval);)
1613 } else if (lg->entry_status != 0) {
1614 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1615 "-- error status (%x).\n", __func__, ha->host_no,
1617 rval = QLA_FUNCTION_FAILED;
1618 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1619 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1620 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1622 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1623 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1624 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1628 case LSC_SCODE_PORTID_USED:
1629 mb[0] = MBS_PORT_ID_USED;
1630 mb[1] = LSW(iop[1]);
1632 case LSC_SCODE_NPORT_USED:
1633 mb[0] = MBS_LOOP_ID_USED;
1635 case LSC_SCODE_NOLINK:
1636 case LSC_SCODE_NOIOCB:
1637 case LSC_SCODE_NOXCB:
1638 case LSC_SCODE_CMD_FAILED:
1639 case LSC_SCODE_NOFABRIC:
1640 case LSC_SCODE_FW_NOT_READY:
1641 case LSC_SCODE_NOT_LOGGED_IN:
1642 case LSC_SCODE_NOPCB:
1643 case LSC_SCODE_ELS_REJECT:
1644 case LSC_SCODE_CMD_PARAM_ERR:
1645 case LSC_SCODE_NONPORT:
1646 case LSC_SCODE_LOGGED_IN:
1647 case LSC_SCODE_NOFLOGI_ACC:
1649 mb[0] = MBS_COMMAND_ERROR;
1653 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1655 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1657 mb[0] = MBS_COMMAND_COMPLETE;
1659 if (iop[0] & BIT_4) {
1666 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1672 * qla2x00_login_fabric
1673 * Issue login fabric port mailbox command.
1676 * ha = adapter block pointer.
1677 * loop_id = device loop ID.
1678 * domain = device domain.
1679 * area = device area.
1680 * al_pa = device AL_PA.
1681 * status = pointer for return status.
1682 * opt = command options.
1683 * TARGET_QUEUE_LOCK must be released.
1684 * ADAPTER_STATE_LOCK must be released.
1687 * qla2x00 local function return status code.
1693 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1694 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1698 mbx_cmd_t *mcp = &mc;
1700 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
1702 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1703 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1704 if (HAS_EXTENDED_IDS(ha)) {
1705 mcp->mb[1] = loop_id;
1707 mcp->out_mb |= MBX_10;
1709 mcp->mb[1] = (loop_id << 8) | opt;
1711 mcp->mb[2] = domain;
1712 mcp->mb[3] = area << 8 | al_pa;
1714 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1715 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1717 rval = qla2x00_mailbox_command(ha, mcp);
1719 /* Return mailbox statuses. */
1728 if (rval != QLA_SUCCESS) {
1729 /* RLU tmp code: need to change main mailbox_command function to
1730 * return ok even when the mailbox completion value is not
1731 * SUCCESS. The caller needs to be responsible to interpret
1732 * the return values of this mailbox command if we're not
1733 * to change too much of the existing code.
1735 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1736 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1737 mcp->mb[0] == 0x4006)
1741 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1742 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1743 mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
1746 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1754 * qla2x00_login_local_device
1755 * Issue login loop port mailbox command.
1758 * ha = adapter block pointer.
1759 * loop_id = device loop ID.
1760 * opt = command options.
1763 * Return status code.
1770 qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
1771 uint16_t *mb_ret, uint8_t opt)
1775 mbx_cmd_t *mcp = &mc;
1777 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1779 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1780 if (HAS_EXTENDED_IDS(ha))
1781 mcp->mb[1] = loop_id;
1783 mcp->mb[1] = loop_id << 8;
1785 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1786 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1787 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1789 rval = qla2x00_mailbox_command(ha, mcp);
1791 /* Return mailbox statuses. */
1792 if (mb_ret != NULL) {
1793 mb_ret[0] = mcp->mb[0];
1794 mb_ret[1] = mcp->mb[1];
1795 mb_ret[6] = mcp->mb[6];
1796 mb_ret[7] = mcp->mb[7];
1799 if (rval != QLA_SUCCESS) {
1800 /* AV tmp code: need to change main mailbox_command function to
1801 * return ok even when the mailbox completion value is not
1802 * SUCCESS. The caller needs to be responsible to interpret
1803 * the return values of this mailbox command if we're not
1804 * to change too much of the existing code.
1806 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1809 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1810 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1811 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1812 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1813 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1814 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1817 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1824 qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1825 uint8_t area, uint8_t al_pa)
1828 struct logio_entry_24xx *lg;
1831 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1833 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1835 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1836 __func__, ha->host_no));
1837 return QLA_MEMORY_ALLOC_FAILED;
1839 memset(lg, 0, sizeof(struct logio_entry_24xx));
1841 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1842 lg->entry_count = 1;
1843 lg->nport_handle = cpu_to_le16(loop_id);
1845 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO);
1846 lg->port_id[0] = al_pa;
1847 lg->port_id[1] = area;
1848 lg->port_id[2] = domain;
1849 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1850 if (rval != QLA_SUCCESS) {
1851 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1852 "(%x).\n", __func__, ha->host_no, rval);)
1853 } else if (lg->entry_status != 0) {
1854 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1855 "-- error status (%x).\n", __func__, ha->host_no,
1857 rval = QLA_FUNCTION_FAILED;
1858 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1859 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1860 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1861 ha->host_no, le16_to_cpu(lg->comp_status),
1862 le32_to_cpu(lg->io_parameter[0]),
1863 le32_to_cpu(lg->io_parameter[1]));)
1866 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1869 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1875 * qla2x00_fabric_logout
1876 * Issue logout fabric port mailbox command.
1879 * ha = adapter block pointer.
1880 * loop_id = device loop ID.
1881 * TARGET_QUEUE_LOCK must be released.
1882 * ADAPTER_STATE_LOCK must be released.
1885 * qla2x00 local function return status code.
1891 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1892 uint8_t area, uint8_t al_pa)
1896 mbx_cmd_t *mcp = &mc;
1898 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1901 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1902 mcp->out_mb = MBX_1|MBX_0;
1903 if (HAS_EXTENDED_IDS(ha)) {
1904 mcp->mb[1] = loop_id;
1906 mcp->out_mb |= MBX_10;
1908 mcp->mb[1] = loop_id << 8;
1911 mcp->in_mb = MBX_1|MBX_0;
1914 rval = qla2x00_mailbox_command(ha, mcp);
1916 if (rval != QLA_SUCCESS) {
1918 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1919 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
1922 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1930 * qla2x00_full_login_lip
1931 * Issue full login LIP mailbox command.
1934 * ha = adapter block pointer.
1935 * TARGET_QUEUE_LOCK must be released.
1936 * ADAPTER_STATE_LOCK must be released.
1939 * qla2x00 local function return status code.
1945 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1949 mbx_cmd_t *mcp = &mc;
1951 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1954 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1958 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1962 rval = qla2x00_mailbox_command(ha, mcp);
1964 if (rval != QLA_SUCCESS) {
1966 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1967 ha->host_no, rval);)
1970 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1978 * qla2x00_get_id_list
1981 * ha = adapter block pointer.
1984 * qla2x00 local function return status code.
1990 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1995 mbx_cmd_t *mcp = &mc;
1997 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
2000 if (id_list == NULL)
2001 return QLA_FUNCTION_FAILED;
2003 mcp->mb[0] = MBC_GET_ID_LIST;
2004 mcp->out_mb = MBX_0;
2005 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
2006 mcp->mb[2] = MSW(id_list_dma);
2007 mcp->mb[3] = LSW(id_list_dma);
2008 mcp->mb[6] = MSW(MSD(id_list_dma));
2009 mcp->mb[7] = LSW(MSD(id_list_dma));
2010 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2;
2012 mcp->mb[1] = MSW(id_list_dma);
2013 mcp->mb[2] = LSW(id_list_dma);
2014 mcp->mb[3] = MSW(MSD(id_list_dma));
2015 mcp->mb[6] = LSW(MSD(id_list_dma));
2016 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2018 mcp->in_mb = MBX_1|MBX_0;
2021 rval = qla2x00_mailbox_command(ha, mcp);
2023 if (rval != QLA_SUCCESS) {
2025 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
2026 ha->host_no, rval);)
2028 *entries = mcp->mb[1];
2029 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2037 * qla2x00_get_resource_cnts
2038 * Get current firmware resource counts.
2041 * ha = adapter block pointer.
2044 * qla2x00 local function return status code.
2050 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
2051 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
2055 mbx_cmd_t *mcp = &mc;
2057 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2059 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2060 mcp->out_mb = MBX_0;
2061 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2064 rval = qla2x00_mailbox_command(ha, mcp);
2066 if (rval != QLA_SUCCESS) {
2068 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2069 ha->host_no, mcp->mb[0]);)
2071 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2072 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
2073 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
2077 *cur_xchg_cnt = mcp->mb[3];
2079 *orig_xchg_cnt = mcp->mb[6];
2081 *cur_iocb_cnt = mcp->mb[7];
2083 *orig_iocb_cnt = mcp->mb[10];
2089 #if defined(QL_DEBUG_LEVEL_3)
2091 * qla2x00_get_fcal_position_map
2092 * Get FCAL (LILP) position map using mailbox command
2095 * ha = adapter state pointer.
2096 * pos_map = buffer pointer (can be NULL).
2099 * qla2x00 local function return status code.
2105 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
2109 mbx_cmd_t *mcp = &mc;
2111 dma_addr_t pmap_dma;
2113 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
2115 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2116 __func__, ha->host_no));
2117 return QLA_MEMORY_ALLOC_FAILED;
2119 memset(pmap, 0, FCAL_MAP_SIZE);
2121 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2122 mcp->mb[2] = MSW(pmap_dma);
2123 mcp->mb[3] = LSW(pmap_dma);
2124 mcp->mb[6] = MSW(MSD(pmap_dma));
2125 mcp->mb[7] = LSW(MSD(pmap_dma));
2126 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2127 mcp->in_mb = MBX_1|MBX_0;
2128 mcp->buf_size = FCAL_MAP_SIZE;
2129 mcp->flags = MBX_DMA_IN;
2130 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2131 rval = qla2x00_mailbox_command(ha, mcp);
2133 if (rval == QLA_SUCCESS) {
2134 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2135 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2136 mcp->mb[1], (unsigned)pmap[0]));
2137 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2140 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2142 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2144 if (rval != QLA_SUCCESS) {
2145 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2146 ha->host_no, rval));
2148 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2155 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2160 mbx_cmd_t *mcp = &mc;
2161 uint32_t *sbuf, *siter;
2162 dma_addr_t sbuf_dma;
2164 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2166 if (dwords > (DMA_POOL_SIZE / 4)) {
2167 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2168 "(max %d).\n", __func__, ha->host_no, dwords,
2169 DMA_POOL_SIZE / 4));
2172 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2174 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2175 __func__, ha->host_no));
2178 memset(sbuf, 0, DMA_POOL_SIZE);
2180 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2181 mcp->mb[2] = MSW(sbuf_dma);
2182 mcp->mb[3] = LSW(sbuf_dma);
2183 mcp->mb[6] = MSW(MSD(sbuf_dma));
2184 mcp->mb[7] = LSW(MSD(sbuf_dma));
2185 mcp->mb[8] = dwords;
2187 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2188 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2190 mcp->flags = IOCTL_CMD;
2191 rval = qla2x00_mailbox_command(ha, mcp);
2193 if (rval == QLA_SUCCESS) {
2194 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2195 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2196 __func__, ha->host_no, mcp->mb[0]));
2197 status[0] = mcp->mb[0];
2200 /* Copy over data -- firmware data is LE. */
2203 *dwbuf++ = le32_to_cpu(*siter++);
2207 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2208 ha->host_no, rval));
2212 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2219 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2223 unsigned long flags = 0;
2225 struct abort_entry_24xx *abt;
2229 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2231 fcport = sp->fcport;
2232 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
2233 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2234 return QLA_FUNCTION_FAILED;
2237 spin_lock_irqsave(&ha->hardware_lock, flags);
2238 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2239 if (ha->outstanding_cmds[handle] == sp)
2242 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2243 if (handle == MAX_OUTSTANDING_COMMANDS) {
2244 /* Command not found. */
2245 return QLA_FUNCTION_FAILED;
2248 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2250 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2251 __func__, ha->host_no));
2252 return QLA_MEMORY_ALLOC_FAILED;
2254 memset(abt, 0, sizeof(struct abort_entry_24xx));
2256 abt->entry_type = ABORT_IOCB_TYPE;
2257 abt->entry_count = 1;
2258 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2259 abt->handle_to_abort = handle;
2260 abt->port_id[0] = fcport->d_id.b.al_pa;
2261 abt->port_id[1] = fcport->d_id.b.area;
2262 abt->port_id[2] = fcport->d_id.b.domain;
2263 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2264 if (rval != QLA_SUCCESS) {
2265 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2266 __func__, ha->host_no, rval);)
2267 } else if (abt->entry_status != 0) {
2268 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2269 "-- error status (%x).\n", __func__, ha->host_no,
2270 abt->entry_status));
2271 rval = QLA_FUNCTION_FAILED;
2272 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2273 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2274 "-- completion status (%x).\n", __func__, ha->host_no,
2275 le16_to_cpu(abt->nport_handle));)
2276 rval = QLA_FUNCTION_FAILED;
2278 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2279 sp->flags |= SRB_ABORT_PENDING;
2282 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2287 struct tsk_mgmt_cmd {
2289 struct tsk_mgmt_entry tsk;
2290 struct sts_entry_24xx sts;
2295 qla24xx_abort_target(fc_port_t *fcport)
2298 struct tsk_mgmt_cmd *tsk;
2300 scsi_qla_host_t *ha;
2305 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
2308 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2310 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2311 "IOCB.\n", __func__, ha->host_no));
2312 return QLA_MEMORY_ALLOC_FAILED;
2314 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2316 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2317 tsk->p.tsk.entry_count = 1;
2318 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2319 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2320 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2321 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2322 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2323 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2324 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2325 if (rval != QLA_SUCCESS) {
2326 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2327 "(%x).\n", __func__, ha->host_no, rval);)
2329 } else if (tsk->p.sts.entry_status != 0) {
2330 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2331 "-- error status (%x).\n", __func__, ha->host_no,
2332 tsk->p.sts.entry_status));
2333 rval = QLA_FUNCTION_FAILED;
2335 } else if (tsk->p.sts.comp_status !=
2336 __constant_cpu_to_le16(CS_COMPLETE)) {
2337 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2338 "-- completion status (%x).\n", __func__,
2339 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));)
2340 rval = QLA_FUNCTION_FAILED;
2344 /* Issue marker IOCB. */
2345 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2346 if (rval != QLA_SUCCESS) {
2347 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2348 "(%x).\n", __func__, ha->host_no, rval);)
2350 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2354 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2360 qla2x00_system_error(scsi_qla_host_t *ha)
2364 mbx_cmd_t *mcp = &mc;
2366 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
2367 return QLA_FUNCTION_FAILED;
2369 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2371 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2372 mcp->out_mb = MBX_0;
2376 rval = qla2x00_mailbox_command(ha, mcp);
2378 if (rval != QLA_SUCCESS) {
2379 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2380 ha->host_no, rval));
2382 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2389 * qla2x00_get_serdes_params() -
2395 qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2396 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2400 mbx_cmd_t *mcp = &mc;
2402 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2404 mcp->mb[0] = MBC_SERDES_PARAMS;
2406 mcp->out_mb = MBX_1|MBX_0;
2407 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2410 rval = qla2x00_mailbox_command(ha, mcp);
2412 if (rval != QLA_SUCCESS) {
2414 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2415 ha->host_no, rval, mcp->mb[0]));
2417 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2420 *sw_em_1g = mcp->mb[2];
2422 *sw_em_2g = mcp->mb[3];
2424 *sw_em_4g = mcp->mb[4];
2431 * qla2x00_set_serdes_params() -
2437 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2438 uint16_t sw_em_2g, uint16_t sw_em_4g)
2442 mbx_cmd_t *mcp = &mc;
2444 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2446 mcp->mb[0] = MBC_SERDES_PARAMS;
2448 mcp->mb[2] = sw_em_1g;
2449 mcp->mb[3] = sw_em_2g;
2450 mcp->mb[4] = sw_em_4g;
2451 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2455 rval = qla2x00_mailbox_command(ha, mcp);
2457 if (rval != QLA_SUCCESS) {
2459 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2460 ha->host_no, rval, mcp->mb[0]));
2463 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));