2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/delay.h>
12 qla2x00_mbx_sem_timeout(unsigned long data
)
14 struct semaphore
*sem_ptr
= (struct semaphore
*)data
;
16 DEBUG11(printk("qla2x00_sem_timeout: entered.\n");)
18 if (sem_ptr
!= NULL
) {
22 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)
26 * qla2x00_mailbox_command
27 * Issue mailbox command and waits for completion.
30 * ha = adapter block pointer.
31 * mcp = driver internal mbx struct pointer.
34 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
37 * 0 : QLA_SUCCESS = cmd performed success
38 * 1 : QLA_FUNCTION_FAILED (error encountered)
39 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
45 qla2x00_mailbox_command(scsi_qla_host_t
*ha
, mbx_cmd_t
*mcp
)
48 unsigned long flags
= 0;
49 device_reg_t __iomem
*reg
= ha
->iobase
;
50 struct timer_list tmp_intr_timer
;
52 uint8_t io_lock_on
= ha
->flags
.init_done
;
55 uint16_t __iomem
*optr
;
58 unsigned long mbx_flags
= 0;
59 unsigned long wait_time
;
62 abort_active
= test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
64 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
67 * Wait for active mailbox commands to finish by waiting at most tov
68 * seconds. This is to serialize actual issuing of mailbox cmds during
72 if (qla2x00_down_timeout(&ha
->mbx_cmd_sem
, mcp
->tov
* HZ
)) {
73 /* Timeout occurred. Return error. */
74 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
75 "Exiting.\n", __func__
, ha
->host_no
);)
76 return QLA_FUNCTION_TIMEOUT
;
80 ha
->flags
.mbox_busy
= 1;
81 /* Save mailbox command for debug */
84 /* Try to get mailbox register access */
86 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
88 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
89 ha
->host_no
, mcp
->mb
[0]);)
91 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
93 /* Load mailbox registers. */
94 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
95 optr
= (uint16_t __iomem
*)®
->isp24
.mailbox0
;
97 optr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, ®
->isp
, 0);
100 command
= mcp
->mb
[0];
101 mboxes
= mcp
->out_mb
;
103 for (cnt
= 0; cnt
< ha
->mbx_count
; cnt
++) {
104 if (IS_QLA2200(ha
) && cnt
== 8)
106 (uint16_t __iomem
*)MAILBOX_REG(ha
, ®
->isp
, 8);
108 WRT_REG_WORD(optr
, *iptr
);
115 #if defined(QL_DEBUG_LEVEL_1)
116 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
117 __func__
, ha
->host_no
);
118 qla2x00_dump_buffer((uint8_t *)mcp
->mb
, 16);
120 qla2x00_dump_buffer(((uint8_t *)mcp
->mb
+ 0x10), 16);
122 qla2x00_dump_buffer(((uint8_t *)mcp
->mb
+ 0x20), 8);
124 printk("%s(%ld): I/O address = %p.\n", __func__
, ha
->host_no
, optr
);
125 qla2x00_dump_regs(ha
);
128 /* Issue set host interrupt command to send cmd out. */
129 ha
->flags
.mbox_int
= 0;
130 clear_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
132 /* Unlock mbx registers and wait for interrupt */
133 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
134 "jiffies=%lx.\n", __func__
, ha
->host_no
, jiffies
);)
136 /* Wait for mbx cmd completion until timeout */
138 if (!abort_active
&& io_lock_on
) {
139 /* sleep on completion semaphore */
140 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
141 __func__
, ha
->host_no
);)
143 init_timer(&tmp_intr_timer
);
144 tmp_intr_timer
.data
= (unsigned long)&ha
->mbx_intr_sem
;
145 tmp_intr_timer
.expires
= jiffies
+ mcp
->tov
* HZ
;
146 tmp_intr_timer
.function
=
147 (void (*)(unsigned long))qla2x00_mbx_sem_timeout
;
149 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__
,
151 add_timer(&tmp_intr_timer
);
153 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
154 "time=0x%lx.\n", __func__
, ha
->host_no
, jiffies
);)
156 set_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
158 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
159 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_SET_HOST_INT
);
161 WRT_REG_WORD(®
->isp
.hccr
, HCCR_SET_HOST_INT
);
162 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
165 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, mbx_flags
);
167 /* Wait for either the timer to expire
168 * or the mbox completion interrupt
170 down(&ha
->mbx_intr_sem
);
172 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__
,
173 ha
->host_no
, jiffies
);)
174 clear_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
176 /* delete the timer */
177 del_timer(&tmp_intr_timer
);
179 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__
,
180 ha
->host_no
, command
);)
182 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
183 WRT_REG_DWORD(®
->isp24
.hccr
, HCCRX_SET_HOST_INT
);
185 WRT_REG_WORD(®
->isp
.hccr
, HCCR_SET_HOST_INT
);
186 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
188 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, mbx_flags
);
190 wait_time
= jiffies
+ mcp
->tov
* HZ
; /* wait at most tov secs */
191 while (!ha
->flags
.mbox_int
) {
192 if (time_after(jiffies
, wait_time
))
195 /* Check for pending interrupts. */
198 if (command
!= MBC_LOAD_RISC_RAM_EXTENDED
&&
205 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
207 /* Check whether we timed out */
208 if (ha
->flags
.mbox_int
) {
211 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__
,
212 ha
->host_no
, command
);)
214 /* Got interrupt. Clear the flag. */
215 ha
->flags
.mbox_int
= 0;
216 clear_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
218 if (ha
->mailbox_out
[0] != MBS_COMMAND_COMPLETE
)
219 rval
= QLA_FUNCTION_FAILED
;
221 /* Load return mailbox registers. */
223 iptr
= (uint16_t *)&ha
->mailbox_out
[0];
225 for (cnt
= 0; cnt
< ha
->mbx_count
; cnt
++) {
235 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
236 defined(QL_DEBUG_LEVEL_11)
240 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
241 mb0
= RD_REG_WORD(®
->isp24
.mailbox0
);
242 ictrl
= RD_REG_DWORD(®
->isp24
.ictrl
);
244 mb0
= RD_MAILBOX_REG(ha
, ®
->isp
, 0);
245 ictrl
= RD_REG_WORD(®
->isp
.ictrl
);
247 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
248 __func__
, ha
->host_no
, command
);
249 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__
,
250 ha
->host_no
, ictrl
, jiffies
);
251 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__
,
253 qla2x00_dump_regs(ha
);
256 rval
= QLA_FUNCTION_TIMEOUT
;
260 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, mbx_flags
);
262 ha
->flags
.mbox_busy
= 0;
268 DEBUG11(printk("%s(%ld): checking for additional resp "
269 "interrupt.\n", __func__
, ha
->host_no
);)
271 /* polling mode for non isp_abort commands. */
275 if (rval
== QLA_FUNCTION_TIMEOUT
&&
276 mcp
->mb
[0] != MBC_GEN_SYSTEM_ERROR
) {
277 if (!io_lock_on
|| (mcp
->flags
& IOCTL_CMD
)) {
278 /* not in dpc. schedule it for dpc to take over. */
279 DEBUG(printk("%s(%ld): timeout schedule "
280 "isp_abort_needed.\n", __func__
, ha
->host_no
);)
281 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
282 "isp_abort_needed.\n", __func__
, ha
->host_no
);)
283 qla_printk(KERN_WARNING
, ha
,
284 "Mailbox command timeout occured. Scheduling ISP "
286 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
287 if (ha
->dpc_wait
&& !ha
->dpc_active
)
290 } else if (!abort_active
) {
291 /* call abort directly since we are in the DPC thread */
292 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
293 __func__
, ha
->host_no
);)
294 DEBUG2_3_11(printk("%s(%ld): timeout calling "
295 "abort_isp\n", __func__
, ha
->host_no
);)
296 qla_printk(KERN_WARNING
, ha
,
297 "Mailbox command timeout occured. Issuing ISP "
300 set_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
301 clear_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
302 if (qla2x00_abort_isp(ha
)) {
303 /* Failed. retry later. */
304 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
306 clear_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
307 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__
,
309 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
310 __func__
, ha
->host_no
);)
314 /* Allow next mbx cmd to come in. */
316 up(&ha
->mbx_cmd_sem
);
319 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
320 "mbx2=%x, cmd=%x ****\n", __func__
, ha
->host_no
,
321 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[2], command
);)
323 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
330 qla2x00_load_ram(scsi_qla_host_t
*ha
, dma_addr_t req_dma
, uint32_t risc_addr
,
331 uint32_t risc_code_size
)
335 mbx_cmd_t
*mcp
= &mc
;
337 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
339 if (MSW(risc_addr
) || IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
340 mcp
->mb
[0] = MBC_LOAD_RISC_RAM_EXTENDED
;
341 mcp
->mb
[8] = MSW(risc_addr
);
342 mcp
->out_mb
= MBX_8
|MBX_0
;
344 mcp
->mb
[0] = MBC_LOAD_RISC_RAM
;
347 mcp
->mb
[1] = LSW(risc_addr
);
348 mcp
->mb
[2] = MSW(req_dma
);
349 mcp
->mb
[3] = LSW(req_dma
);
350 mcp
->mb
[6] = MSW(MSD(req_dma
));
351 mcp
->mb
[7] = LSW(MSD(req_dma
));
352 mcp
->out_mb
|= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
;
353 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
354 mcp
->mb
[4] = MSW(risc_code_size
);
355 mcp
->mb
[5] = LSW(risc_code_size
);
356 mcp
->out_mb
|= MBX_5
|MBX_4
;
358 mcp
->mb
[4] = LSW(risc_code_size
);
359 mcp
->out_mb
|= MBX_4
;
365 rval
= qla2x00_mailbox_command(ha
, mcp
);
367 if (rval
!= QLA_SUCCESS
) {
368 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__
,
369 ha
->host_no
, rval
, mcp
->mb
[0]));
371 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
379 * Start adapter firmware.
382 * ha = adapter block pointer.
383 * TARGET_QUEUE_LOCK must be released.
384 * ADAPTER_STATE_LOCK must be released.
387 * qla2x00 local function return status code.
393 qla2x00_execute_fw(scsi_qla_host_t
*ha
, uint32_t risc_addr
)
397 mbx_cmd_t
*mcp
= &mc
;
399 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
401 mcp
->mb
[0] = MBC_EXECUTE_FIRMWARE
;
404 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
405 mcp
->mb
[1] = MSW(risc_addr
);
406 mcp
->mb
[2] = LSW(risc_addr
);
408 mcp
->out_mb
|= MBX_3
|MBX_2
|MBX_1
;
411 mcp
->mb
[1] = LSW(risc_addr
);
412 mcp
->out_mb
|= MBX_1
;
413 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
415 mcp
->out_mb
|= MBX_2
;
421 rval
= qla2x00_mailbox_command(ha
, mcp
);
423 if (rval
!= QLA_SUCCESS
) {
424 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__
,
425 ha
->host_no
, rval
, mcp
->mb
[0]));
427 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
428 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
429 __func__
, ha
->host_no
, mcp
->mb
[1]);)
431 DEBUG11(printk("%s(%ld): done.\n", __func__
,
440 * qla2x00_get_fw_version
441 * Get firmware version.
444 * ha: adapter state pointer.
445 * major: pointer for major number.
446 * minor: pointer for minor number.
447 * subminor: pointer for subminor number.
450 * qla2x00 local function return status code.
456 qla2x00_get_fw_version(scsi_qla_host_t
*ha
, uint16_t *major
, uint16_t *minor
,
457 uint16_t *subminor
, uint16_t *attributes
, uint32_t *memory
)
461 mbx_cmd_t
*mcp
= &mc
;
463 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
465 mcp
->mb
[0] = MBC_GET_FIRMWARE_VERSION
;
467 mcp
->in_mb
= MBX_6
|MBX_5
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
470 rval
= qla2x00_mailbox_command(ha
, mcp
);
472 /* Return mailbox data. */
475 *subminor
= mcp
->mb
[3];
476 *attributes
= mcp
->mb
[6];
477 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
478 *memory
= 0x1FFFF; /* Defaults to 128KB. */
480 *memory
= (mcp
->mb
[5] << 16) | mcp
->mb
[4];
482 if (rval
!= QLA_SUCCESS
) {
484 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
488 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
493 * qla2x00_get_fw_options
494 * Set firmware options.
497 * ha = adapter block pointer.
498 * fwopt = pointer for firmware options.
501 * qla2x00 local function return status code.
507 qla2x00_get_fw_options(scsi_qla_host_t
*ha
, uint16_t *fwopts
)
511 mbx_cmd_t
*mcp
= &mc
;
513 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
515 mcp
->mb
[0] = MBC_GET_FIRMWARE_OPTION
;
517 mcp
->in_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
520 rval
= qla2x00_mailbox_command(ha
, mcp
);
522 if (rval
!= QLA_SUCCESS
) {
524 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
527 fwopts
[0] = mcp
->mb
[0];
528 fwopts
[1] = mcp
->mb
[1];
529 fwopts
[2] = mcp
->mb
[2];
530 fwopts
[3] = mcp
->mb
[3];
532 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
540 * qla2x00_set_fw_options
541 * Set firmware options.
544 * ha = adapter block pointer.
545 * fwopt = pointer for firmware options.
548 * qla2x00 local function return status code.
554 qla2x00_set_fw_options(scsi_qla_host_t
*ha
, uint16_t *fwopts
)
558 mbx_cmd_t
*mcp
= &mc
;
560 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
562 mcp
->mb
[0] = MBC_SET_FIRMWARE_OPTION
;
563 mcp
->mb
[1] = fwopts
[1];
564 mcp
->mb
[2] = fwopts
[2];
565 mcp
->mb
[3] = fwopts
[3];
566 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
568 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
571 mcp
->mb
[10] = fwopts
[10];
572 mcp
->mb
[11] = fwopts
[11];
573 mcp
->mb
[12] = 0; /* Undocumented, but used */
574 mcp
->out_mb
|= MBX_12
|MBX_11
|MBX_10
;
578 rval
= qla2x00_mailbox_command(ha
, mcp
);
580 fwopts
[0] = mcp
->mb
[0];
582 if (rval
!= QLA_SUCCESS
) {
584 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__
,
585 ha
->host_no
, rval
, mcp
->mb
[0], mcp
->mb
[1]));
588 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
595 * qla2x00_mbx_reg_test
596 * Mailbox register wrap test.
599 * ha = adapter block pointer.
600 * TARGET_QUEUE_LOCK must be released.
601 * ADAPTER_STATE_LOCK must be released.
604 * qla2x00 local function return status code.
610 qla2x00_mbx_reg_test(scsi_qla_host_t
*ha
)
614 mbx_cmd_t
*mcp
= &mc
;
616 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha
->host_no
);)
618 mcp
->mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
626 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_5
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
627 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_5
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
630 rval
= qla2x00_mailbox_command(ha
, mcp
);
632 if (rval
== QLA_SUCCESS
) {
633 if (mcp
->mb
[1] != 0xAAAA || mcp
->mb
[2] != 0x5555 ||
634 mcp
->mb
[3] != 0xAA55 || mcp
->mb
[4] != 0x55AA)
635 rval
= QLA_FUNCTION_FAILED
;
636 if (mcp
->mb
[5] != 0xA5A5 || mcp
->mb
[6] != 0x5A5A ||
637 mcp
->mb
[7] != 0x2525)
638 rval
= QLA_FUNCTION_FAILED
;
641 if (rval
!= QLA_SUCCESS
) {
643 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
647 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
655 * qla2x00_verify_checksum
656 * Verify firmware checksum.
659 * ha = adapter block pointer.
660 * TARGET_QUEUE_LOCK must be released.
661 * ADAPTER_STATE_LOCK must be released.
664 * qla2x00 local function return status code.
670 qla2x00_verify_checksum(scsi_qla_host_t
*ha
, uint32_t risc_addr
)
674 mbx_cmd_t
*mcp
= &mc
;
676 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
678 mcp
->mb
[0] = MBC_VERIFY_CHECKSUM
;
681 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
682 mcp
->mb
[1] = MSW(risc_addr
);
683 mcp
->mb
[2] = LSW(risc_addr
);
684 mcp
->out_mb
|= MBX_2
|MBX_1
;
685 mcp
->in_mb
|= MBX_2
|MBX_1
;
687 mcp
->mb
[1] = LSW(risc_addr
);
688 mcp
->out_mb
|= MBX_1
;
694 rval
= qla2x00_mailbox_command(ha
, mcp
);
696 if (rval
!= QLA_SUCCESS
) {
697 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__
,
698 ha
->host_no
, rval
, (IS_QLA24XX(ha
) || IS_QLA25XX(ha
) ?
699 (mcp
->mb
[2] << 16) | mcp
->mb
[1]: mcp
->mb
[1]));)
701 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
709 * Issue IOCB using mailbox command
712 * ha = adapter state pointer.
713 * buffer = buffer pointer.
714 * phys_addr = physical address of buffer.
715 * size = size of buffer.
716 * TARGET_QUEUE_LOCK must be released.
717 * ADAPTER_STATE_LOCK must be released.
720 * qla2x00 local function return status code.
726 qla2x00_issue_iocb(scsi_qla_host_t
*ha
, void* buffer
, dma_addr_t phys_addr
,
731 mbx_cmd_t
*mcp
= &mc
;
733 mcp
->mb
[0] = MBC_IOCB_COMMAND_A64
;
735 mcp
->mb
[2] = MSW(phys_addr
);
736 mcp
->mb
[3] = LSW(phys_addr
);
737 mcp
->mb
[6] = MSW(MSD(phys_addr
));
738 mcp
->mb
[7] = LSW(MSD(phys_addr
));
739 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
740 mcp
->in_mb
= MBX_2
|MBX_0
;
743 rval
= qla2x00_mailbox_command(ha
, mcp
);
745 if (rval
!= QLA_SUCCESS
) {
747 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
749 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
752 sts_entry_t
*sts_entry
= (sts_entry_t
*) buffer
;
754 /* Mask reserved bits. */
755 sts_entry
->entry_status
&=
756 IS_QLA24XX(ha
) || IS_QLA25XX(ha
) ? RF_MASK_24XX
:RF_MASK
;
763 * qla2x00_abort_command
764 * Abort command aborts a specified IOCB.
767 * ha = adapter block pointer.
768 * sp = SB structure pointer.
771 * qla2x00 local function return status code.
777 qla2x00_abort_command(scsi_qla_host_t
*ha
, srb_t
*sp
)
779 unsigned long flags
= 0;
784 mbx_cmd_t
*mcp
= &mc
;
786 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha
->host_no
);)
790 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
791 for (handle
= 1; handle
< MAX_OUTSTANDING_COMMANDS
; handle
++) {
792 if (ha
->outstanding_cmds
[handle
] == sp
)
795 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
797 if (handle
== MAX_OUTSTANDING_COMMANDS
) {
798 /* command not found */
799 return QLA_FUNCTION_FAILED
;
802 mcp
->mb
[0] = MBC_ABORT_COMMAND
;
803 if (HAS_EXTENDED_IDS(ha
))
804 mcp
->mb
[1] = fcport
->loop_id
;
806 mcp
->mb
[1] = fcport
->loop_id
<< 8;
807 mcp
->mb
[2] = (uint16_t)handle
;
808 mcp
->mb
[3] = (uint16_t)(handle
>> 16);
809 mcp
->mb
[6] = (uint16_t)sp
->cmd
->device
->lun
;
810 mcp
->out_mb
= MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
814 rval
= qla2x00_mailbox_command(ha
, mcp
);
816 if (rval
!= QLA_SUCCESS
) {
817 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
820 sp
->flags
|= SRB_ABORT_PENDING
;
821 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
830 * qla2x00_abort_target
831 * Issue abort target mailbox command.
834 * ha = adapter block pointer.
837 * qla2x00 local function return status code.
843 qla2x00_abort_target(fc_port_t
*fcport
)
847 mbx_cmd_t
*mcp
= &mc
;
853 DEBUG11(printk("%s(%ld): entered.\n", __func__
, fcport
->ha
->host_no
);)
856 mcp
->mb
[0] = MBC_ABORT_TARGET
;
857 mcp
->out_mb
= MBX_2
|MBX_1
|MBX_0
;
858 if (HAS_EXTENDED_IDS(ha
)) {
859 mcp
->mb
[1] = fcport
->loop_id
;
861 mcp
->out_mb
|= MBX_10
;
863 mcp
->mb
[1] = fcport
->loop_id
<< 8;
865 mcp
->mb
[2] = ha
->loop_reset_delay
;
870 rval
= qla2x00_mailbox_command(ha
, mcp
);
872 /* Issue marker command. */
873 ha
->marker_needed
= 1;
875 if (rval
!= QLA_SUCCESS
) {
876 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
880 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
889 * qla2x00_get_adapter_id
890 * Get adapter ID and topology.
893 * ha = adapter block pointer.
894 * id = pointer for loop ID.
895 * al_pa = pointer for AL_PA.
896 * area = pointer for area.
897 * domain = pointer for domain.
898 * top = pointer for topology.
899 * TARGET_QUEUE_LOCK must be released.
900 * ADAPTER_STATE_LOCK must be released.
903 * qla2x00 local function return status code.
909 qla2x00_get_adapter_id(scsi_qla_host_t
*ha
, uint16_t *id
, uint8_t *al_pa
,
910 uint8_t *area
, uint8_t *domain
, uint16_t *top
)
914 mbx_cmd_t
*mcp
= &mc
;
916 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
919 mcp
->mb
[0] = MBC_GET_ADAPTER_LOOP_ID
;
921 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
924 rval
= qla2x00_mailbox_command(ha
, mcp
);
925 if (mcp
->mb
[0] == MBS_COMMAND_ERROR
)
926 rval
= QLA_COMMAND_ERROR
;
930 *al_pa
= LSB(mcp
->mb
[2]);
931 *area
= MSB(mcp
->mb
[2]);
932 *domain
= LSB(mcp
->mb
[3]);
935 if (rval
!= QLA_SUCCESS
) {
937 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
941 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
949 * qla2x00_get_retry_cnt
950 * Get current firmware login retry count and delay.
953 * ha = adapter block pointer.
954 * retry_cnt = pointer to login retry count.
955 * tov = pointer to login timeout value.
958 * qla2x00 local function return status code.
964 qla2x00_get_retry_cnt(scsi_qla_host_t
*ha
, uint8_t *retry_cnt
, uint8_t *tov
,
970 mbx_cmd_t
*mcp
= &mc
;
972 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
975 mcp
->mb
[0] = MBC_GET_RETRY_COUNT
;
977 mcp
->in_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
980 rval
= qla2x00_mailbox_command(ha
, mcp
);
982 if (rval
!= QLA_SUCCESS
) {
984 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
985 ha
->host_no
, mcp
->mb
[0]);)
987 /* Convert returned data and check our values. */
988 *r_a_tov
= mcp
->mb
[3] / 2;
989 ratov
= (mcp
->mb
[3]/2) / 10; /* mb[3] value is in 100ms */
990 if (mcp
->mb
[1] * ratov
> (*retry_cnt
) * (*tov
)) {
991 /* Update to the larger values */
992 *retry_cnt
= (uint8_t)mcp
->mb
[1];
996 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
997 "ratov=%d.\n", ha
->host_no
, mcp
->mb
[3], ratov
);)
1004 * qla2x00_init_firmware
1005 * Initialize adapter firmware.
1008 * ha = adapter block pointer.
1009 * dptr = Initialization control block pointer.
1010 * size = size of initialization control block.
1011 * TARGET_QUEUE_LOCK must be released.
1012 * ADAPTER_STATE_LOCK must be released.
1015 * qla2x00 local function return status code.
1021 qla2x00_init_firmware(scsi_qla_host_t
*ha
, uint16_t size
)
1025 mbx_cmd_t
*mcp
= &mc
;
1027 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1030 mcp
->mb
[0] = MBC_INITIALIZE_FIRMWARE
;
1031 mcp
->mb
[2] = MSW(ha
->init_cb_dma
);
1032 mcp
->mb
[3] = LSW(ha
->init_cb_dma
);
1035 mcp
->mb
[6] = MSW(MSD(ha
->init_cb_dma
));
1036 mcp
->mb
[7] = LSW(MSD(ha
->init_cb_dma
));
1037 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
1038 mcp
->in_mb
= MBX_5
|MBX_4
|MBX_0
;
1039 mcp
->buf_size
= size
;
1040 mcp
->flags
= MBX_DMA_OUT
;
1042 rval
= qla2x00_mailbox_command(ha
, mcp
);
1044 if (rval
!= QLA_SUCCESS
) {
1046 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1048 ha
->host_no
, rval
, mcp
->mb
[0]);)
1051 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1059 * qla2x00_get_port_database
1060 * Issue normal/enhanced get port database mailbox command
1061 * and copy device name as necessary.
1064 * ha = adapter state pointer.
1065 * dev = structure pointer.
1066 * opt = enhanced cmd option byte.
1069 * qla2x00 local function return status code.
1075 qla2x00_get_port_database(scsi_qla_host_t
*ha
, fc_port_t
*fcport
, uint8_t opt
)
1079 mbx_cmd_t
*mcp
= &mc
;
1080 port_database_t
*pd
;
1081 struct port_database_24xx
*pd24
;
1084 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
1087 pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
1089 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1090 "structure.\n", __func__
, ha
->host_no
));
1091 return QLA_MEMORY_ALLOC_FAILED
;
1093 memset(pd
, 0, max(PORT_DATABASE_SIZE
, PORT_DATABASE_24XX_SIZE
));
1095 mcp
->mb
[0] = MBC_GET_PORT_DATABASE
;
1096 if (opt
!= 0 && !IS_QLA24XX(ha
) && !IS_QLA25XX(ha
))
1097 mcp
->mb
[0] = MBC_ENHANCED_GET_PORT_DATABASE
;
1098 mcp
->mb
[2] = MSW(pd_dma
);
1099 mcp
->mb
[3] = LSW(pd_dma
);
1100 mcp
->mb
[6] = MSW(MSD(pd_dma
));
1101 mcp
->mb
[7] = LSW(MSD(pd_dma
));
1102 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
1104 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1105 mcp
->mb
[1] = fcport
->loop_id
;
1107 mcp
->out_mb
|= MBX_10
|MBX_1
;
1108 mcp
->in_mb
|= MBX_1
;
1109 } else if (HAS_EXTENDED_IDS(ha
)) {
1110 mcp
->mb
[1] = fcport
->loop_id
;
1112 mcp
->out_mb
|= MBX_10
|MBX_1
;
1114 mcp
->mb
[1] = fcport
->loop_id
<< 8 | opt
;
1115 mcp
->out_mb
|= MBX_1
;
1117 mcp
->buf_size
= (IS_QLA24XX(ha
) || IS_QLA25XX(ha
) ?
1118 PORT_DATABASE_24XX_SIZE
: PORT_DATABASE_SIZE
);
1119 mcp
->flags
= MBX_DMA_IN
;
1120 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1121 rval
= qla2x00_mailbox_command(ha
, mcp
);
1122 if (rval
!= QLA_SUCCESS
)
1125 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1126 pd24
= (struct port_database_24xx
*) pd
;
1128 /* Check for logged in state. */
1129 if (pd24
->current_login_state
!= PDS_PRLI_COMPLETE
&&
1130 pd24
->last_login_state
!= PDS_PRLI_COMPLETE
) {
1131 DEBUG2(printk("%s(%ld): Unable to verify "
1132 "login-state (%x/%x) for loop_id %x\n",
1133 __func__
, ha
->host_no
,
1134 pd24
->current_login_state
,
1135 pd24
->last_login_state
, fcport
->loop_id
));
1136 rval
= QLA_FUNCTION_FAILED
;
1140 /* Names are little-endian. */
1141 memcpy(fcport
->node_name
, pd24
->node_name
, WWN_SIZE
);
1142 memcpy(fcport
->port_name
, pd24
->port_name
, WWN_SIZE
);
1144 /* Get port_id of device. */
1145 fcport
->d_id
.b
.domain
= pd24
->port_id
[0];
1146 fcport
->d_id
.b
.area
= pd24
->port_id
[1];
1147 fcport
->d_id
.b
.al_pa
= pd24
->port_id
[2];
1148 fcport
->d_id
.b
.rsvd_1
= 0;
1150 /* If not target must be initiator or unknown type. */
1151 if ((pd24
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
1152 fcport
->port_type
= FCT_INITIATOR
;
1154 fcport
->port_type
= FCT_TARGET
;
1156 /* Check for logged in state. */
1157 if (pd
->master_state
!= PD_STATE_PORT_LOGGED_IN
&&
1158 pd
->slave_state
!= PD_STATE_PORT_LOGGED_IN
) {
1159 rval
= QLA_FUNCTION_FAILED
;
1163 /* Names are little-endian. */
1164 memcpy(fcport
->node_name
, pd
->node_name
, WWN_SIZE
);
1165 memcpy(fcport
->port_name
, pd
->port_name
, WWN_SIZE
);
1167 /* Get port_id of device. */
1168 fcport
->d_id
.b
.domain
= pd
->port_id
[0];
1169 fcport
->d_id
.b
.area
= pd
->port_id
[3];
1170 fcport
->d_id
.b
.al_pa
= pd
->port_id
[2];
1171 fcport
->d_id
.b
.rsvd_1
= 0;
1173 /* Check for device require authentication. */
1174 pd
->common_features
& BIT_5
? (fcport
->flags
|= FCF_AUTH_REQ
) :
1175 (fcport
->flags
&= ~FCF_AUTH_REQ
);
1177 /* If not target must be initiator or unknown type. */
1178 if ((pd
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
1179 fcport
->port_type
= FCT_INITIATOR
;
1181 fcport
->port_type
= FCT_TARGET
;
1183 /* Passback COS information. */
1184 fcport
->supported_classes
= (pd
->options
& BIT_4
) ?
1185 FC_COS_CLASS2
: FC_COS_CLASS3
;
1189 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1191 if (rval
!= QLA_SUCCESS
) {
1192 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1193 __func__
, ha
->host_no
, rval
, mcp
->mb
[0], mcp
->mb
[1]));
1195 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
1202 * qla2x00_get_firmware_state
1203 * Get adapter firmware state.
1206 * ha = adapter block pointer.
1207 * dptr = pointer for firmware state.
1208 * TARGET_QUEUE_LOCK must be released.
1209 * ADAPTER_STATE_LOCK must be released.
1212 * qla2x00 local function return status code.
1218 qla2x00_get_firmware_state(scsi_qla_host_t
*ha
, uint16_t *dptr
)
1222 mbx_cmd_t
*mcp
= &mc
;
1224 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1227 mcp
->mb
[0] = MBC_GET_FIRMWARE_STATE
;
1228 mcp
->out_mb
= MBX_0
;
1229 mcp
->in_mb
= MBX_2
|MBX_1
|MBX_0
;
1232 rval
= qla2x00_mailbox_command(ha
, mcp
);
1234 /* Return firmware state. */
1237 if (rval
!= QLA_SUCCESS
) {
1239 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1240 "failed=%x.\n", ha
->host_no
, rval
);)
1243 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1251 * qla2x00_get_port_name
1252 * Issue get port name mailbox command.
1253 * Returned name is in big endian format.
1256 * ha = adapter block pointer.
1257 * loop_id = loop ID of device.
1258 * name = pointer for name.
1259 * TARGET_QUEUE_LOCK must be released.
1260 * ADAPTER_STATE_LOCK must be released.
1263 * qla2x00 local function return status code.
1269 qla2x00_get_port_name(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t *name
,
1274 mbx_cmd_t
*mcp
= &mc
;
1276 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1279 mcp
->mb
[0] = MBC_GET_PORT_NAME
;
1280 mcp
->out_mb
= MBX_1
|MBX_0
;
1281 if (HAS_EXTENDED_IDS(ha
)) {
1282 mcp
->mb
[1] = loop_id
;
1284 mcp
->out_mb
|= MBX_10
;
1286 mcp
->mb
[1] = loop_id
<< 8 | opt
;
1289 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1292 rval
= qla2x00_mailbox_command(ha
, mcp
);
1294 if (rval
!= QLA_SUCCESS
) {
1296 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1297 ha
->host_no
, rval
);)
1300 /* This function returns name in big endian. */
1301 name
[0] = LSB(mcp
->mb
[2]);
1302 name
[1] = MSB(mcp
->mb
[2]);
1303 name
[2] = LSB(mcp
->mb
[3]);
1304 name
[3] = MSB(mcp
->mb
[3]);
1305 name
[4] = LSB(mcp
->mb
[6]);
1306 name
[5] = MSB(mcp
->mb
[6]);
1307 name
[6] = LSB(mcp
->mb
[7]);
1308 name
[7] = MSB(mcp
->mb
[7]);
1311 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1320 * Issue LIP reset mailbox command.
1323 * ha = adapter block pointer.
1324 * TARGET_QUEUE_LOCK must be released.
1325 * ADAPTER_STATE_LOCK must be released.
1328 * qla2x00 local function return status code.
1334 qla2x00_lip_reset(scsi_qla_host_t
*ha
)
1338 mbx_cmd_t
*mcp
= &mc
;
1340 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
1342 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1343 mcp
->mb
[0] = MBC_LIP_FULL_LOGIN
;
1347 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1349 mcp
->mb
[0] = MBC_LIP_RESET
;
1350 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1351 if (HAS_EXTENDED_IDS(ha
)) {
1352 mcp
->mb
[1] = 0x00ff;
1354 mcp
->out_mb
|= MBX_10
;
1356 mcp
->mb
[1] = 0xff00;
1358 mcp
->mb
[2] = ha
->loop_reset_delay
;
1364 rval
= qla2x00_mailbox_command(ha
, mcp
);
1366 if (rval
!= QLA_SUCCESS
) {
1368 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1369 __func__
, ha
->host_no
, rval
);)
1372 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
1383 * ha = adapter block pointer.
1384 * sns = pointer for command.
1385 * cmd_size = command size.
1386 * buf_size = response/command size.
1387 * TARGET_QUEUE_LOCK must be released.
1388 * ADAPTER_STATE_LOCK must be released.
1391 * qla2x00 local function return status code.
1397 qla2x00_send_sns(scsi_qla_host_t
*ha
, dma_addr_t sns_phys_address
,
1398 uint16_t cmd_size
, size_t buf_size
)
1402 mbx_cmd_t
*mcp
= &mc
;
1404 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1407 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1408 "tov=%d.\n", ha
->retry_count
, ha
->login_timeout
, mcp
->tov
);)
1410 mcp
->mb
[0] = MBC_SEND_SNS_COMMAND
;
1411 mcp
->mb
[1] = cmd_size
;
1412 mcp
->mb
[2] = MSW(sns_phys_address
);
1413 mcp
->mb
[3] = LSW(sns_phys_address
);
1414 mcp
->mb
[6] = MSW(MSD(sns_phys_address
));
1415 mcp
->mb
[7] = LSW(MSD(sns_phys_address
));
1416 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1417 mcp
->in_mb
= MBX_0
|MBX_1
;
1418 mcp
->buf_size
= buf_size
;
1419 mcp
->flags
= MBX_DMA_OUT
|MBX_DMA_IN
;
1420 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1421 rval
= qla2x00_mailbox_command(ha
, mcp
);
1423 if (rval
!= QLA_SUCCESS
) {
1425 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1426 "mb[1]=%x.\n", ha
->host_no
, rval
, mcp
->mb
[0], mcp
->mb
[1]);)
1427 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1428 "mb[1]=%x.\n", ha
->host_no
, rval
, mcp
->mb
[0], mcp
->mb
[1]);)
1431 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha
->host_no
);)
1438 qla24xx_login_fabric(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t domain
,
1439 uint8_t area
, uint8_t al_pa
, uint16_t *mb
, uint8_t opt
)
1443 struct logio_entry_24xx
*lg
;
1447 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
1449 lg
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &lg_dma
);
1451 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1452 __func__
, ha
->host_no
));
1453 return QLA_MEMORY_ALLOC_FAILED
;
1455 memset(lg
, 0, sizeof(struct logio_entry_24xx
));
1457 lg
->entry_type
= LOGINOUT_PORT_IOCB_TYPE
;
1458 lg
->entry_count
= 1;
1459 lg
->nport_handle
= cpu_to_le16(loop_id
);
1460 lg
->control_flags
= __constant_cpu_to_le16(LCF_COMMAND_PLOGI
);
1462 lg
->control_flags
|= __constant_cpu_to_le16(LCF_COND_PLOGI
);
1463 lg
->port_id
[0] = al_pa
;
1464 lg
->port_id
[1] = area
;
1465 lg
->port_id
[2] = domain
;
1466 rval
= qla2x00_issue_iocb(ha
, lg
, lg_dma
, 0);
1467 if (rval
!= QLA_SUCCESS
) {
1468 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1469 "(%x).\n", __func__
, ha
->host_no
, rval
);)
1470 } else if (lg
->entry_status
!= 0) {
1471 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1472 "-- error status (%x).\n", __func__
, ha
->host_no
,
1474 rval
= QLA_FUNCTION_FAILED
;
1475 } else if (lg
->comp_status
!= __constant_cpu_to_le16(CS_COMPLETE
)) {
1476 iop
[0] = le32_to_cpu(lg
->io_parameter
[0]);
1477 iop
[1] = le32_to_cpu(lg
->io_parameter
[1]);
1479 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1480 "-- completion status (%x) ioparam=%x/%x.\n", __func__
,
1481 ha
->host_no
, le16_to_cpu(lg
->comp_status
), iop
[0],
1485 case LSC_SCODE_PORTID_USED
:
1486 mb
[0] = MBS_PORT_ID_USED
;
1487 mb
[1] = LSW(iop
[1]);
1489 case LSC_SCODE_NPORT_USED
:
1490 mb
[0] = MBS_LOOP_ID_USED
;
1492 case LSC_SCODE_NOLINK
:
1493 case LSC_SCODE_NOIOCB
:
1494 case LSC_SCODE_NOXCB
:
1495 case LSC_SCODE_CMD_FAILED
:
1496 case LSC_SCODE_NOFABRIC
:
1497 case LSC_SCODE_FW_NOT_READY
:
1498 case LSC_SCODE_NOT_LOGGED_IN
:
1499 case LSC_SCODE_NOPCB
:
1500 case LSC_SCODE_ELS_REJECT
:
1501 case LSC_SCODE_CMD_PARAM_ERR
:
1502 case LSC_SCODE_NONPORT
:
1503 case LSC_SCODE_LOGGED_IN
:
1504 case LSC_SCODE_NOFLOGI_ACC
:
1506 mb
[0] = MBS_COMMAND_ERROR
;
1510 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
1512 iop
[0] = le32_to_cpu(lg
->io_parameter
[0]);
1514 mb
[0] = MBS_COMMAND_COMPLETE
;
1516 if (iop
[0] & BIT_4
) {
1522 /* Passback COS information. */
1524 if (lg
->io_parameter
[7] || lg
->io_parameter
[8])
1525 mb
[10] |= BIT_0
; /* Class 2. */
1526 if (lg
->io_parameter
[9] || lg
->io_parameter
[10])
1527 mb
[10] |= BIT_1
; /* Class 3. */
1530 dma_pool_free(ha
->s_dma_pool
, lg
, lg_dma
);
1536 * qla2x00_login_fabric
1537 * Issue login fabric port mailbox command.
1540 * ha = adapter block pointer.
1541 * loop_id = device loop ID.
1542 * domain = device domain.
1543 * area = device area.
1544 * al_pa = device AL_PA.
1545 * status = pointer for return status.
1546 * opt = command options.
1547 * TARGET_QUEUE_LOCK must be released.
1548 * ADAPTER_STATE_LOCK must be released.
1551 * qla2x00 local function return status code.
1557 qla2x00_login_fabric(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t domain
,
1558 uint8_t area
, uint8_t al_pa
, uint16_t *mb
, uint8_t opt
)
1562 mbx_cmd_t
*mcp
= &mc
;
1564 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha
->host_no
);)
1566 mcp
->mb
[0] = MBC_LOGIN_FABRIC_PORT
;
1567 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1568 if (HAS_EXTENDED_IDS(ha
)) {
1569 mcp
->mb
[1] = loop_id
;
1571 mcp
->out_mb
|= MBX_10
;
1573 mcp
->mb
[1] = (loop_id
<< 8) | opt
;
1575 mcp
->mb
[2] = domain
;
1576 mcp
->mb
[3] = area
<< 8 | al_pa
;
1578 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_2
|MBX_1
|MBX_0
;
1579 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1581 rval
= qla2x00_mailbox_command(ha
, mcp
);
1583 /* Return mailbox statuses. */
1590 /* COS retrieved from Get-Port-Database mailbox command. */
1594 if (rval
!= QLA_SUCCESS
) {
1595 /* RLU tmp code: need to change main mailbox_command function to
1596 * return ok even when the mailbox completion value is not
1597 * SUCCESS. The caller needs to be responsible to interpret
1598 * the return values of this mailbox command if we're not
1599 * to change too much of the existing code.
1601 if (mcp
->mb
[0] == 0x4001 || mcp
->mb
[0] == 0x4002 ||
1602 mcp
->mb
[0] == 0x4003 || mcp
->mb
[0] == 0x4005 ||
1603 mcp
->mb
[0] == 0x4006)
1607 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1608 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha
->host_no
, rval
,
1609 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[2]);)
1612 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1620 * qla2x00_login_local_device
1621 * Issue login loop port mailbox command.
1624 * ha = adapter block pointer.
1625 * loop_id = device loop ID.
1626 * opt = command options.
1629 * Return status code.
1636 qla2x00_login_local_device(scsi_qla_host_t
*ha
, uint16_t loop_id
,
1637 uint16_t *mb_ret
, uint8_t opt
)
1641 mbx_cmd_t
*mcp
= &mc
;
1643 DEBUG3(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
1645 mcp
->mb
[0] = MBC_LOGIN_LOOP_PORT
;
1646 if (HAS_EXTENDED_IDS(ha
))
1647 mcp
->mb
[1] = loop_id
;
1649 mcp
->mb
[1] = loop_id
<< 8;
1651 mcp
->out_mb
= MBX_2
|MBX_1
|MBX_0
;
1652 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_1
|MBX_0
;
1653 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1655 rval
= qla2x00_mailbox_command(ha
, mcp
);
1657 /* Return mailbox statuses. */
1658 if (mb_ret
!= NULL
) {
1659 mb_ret
[0] = mcp
->mb
[0];
1660 mb_ret
[1] = mcp
->mb
[1];
1661 mb_ret
[6] = mcp
->mb
[6];
1662 mb_ret
[7] = mcp
->mb
[7];
1665 if (rval
!= QLA_SUCCESS
) {
1666 /* AV tmp code: need to change main mailbox_command function to
1667 * return ok even when the mailbox completion value is not
1668 * SUCCESS. The caller needs to be responsible to interpret
1669 * the return values of this mailbox command if we're not
1670 * to change too much of the existing code.
1672 if (mcp
->mb
[0] == 0x4005 || mcp
->mb
[0] == 0x4006)
1675 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1676 "mb[6]=%x mb[7]=%x.\n", __func__
, ha
->host_no
, rval
,
1677 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[6], mcp
->mb
[7]);)
1678 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1679 "mb[6]=%x mb[7]=%x.\n", __func__
, ha
->host_no
, rval
,
1680 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[6], mcp
->mb
[7]);)
1683 DEBUG3(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
1690 qla24xx_fabric_logout(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t domain
,
1691 uint8_t area
, uint8_t al_pa
)
1694 struct logio_entry_24xx
*lg
;
1697 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
1699 lg
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &lg_dma
);
1701 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1702 __func__
, ha
->host_no
));
1703 return QLA_MEMORY_ALLOC_FAILED
;
1705 memset(lg
, 0, sizeof(struct logio_entry_24xx
));
1707 lg
->entry_type
= LOGINOUT_PORT_IOCB_TYPE
;
1708 lg
->entry_count
= 1;
1709 lg
->nport_handle
= cpu_to_le16(loop_id
);
1711 __constant_cpu_to_le16(LCF_COMMAND_LOGO
|LCF_EXPL_LOGO
);
1712 lg
->port_id
[0] = al_pa
;
1713 lg
->port_id
[1] = area
;
1714 lg
->port_id
[2] = domain
;
1715 rval
= qla2x00_issue_iocb(ha
, lg
, lg_dma
, 0);
1716 if (rval
!= QLA_SUCCESS
) {
1717 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1718 "(%x).\n", __func__
, ha
->host_no
, rval
);)
1719 } else if (lg
->entry_status
!= 0) {
1720 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1721 "-- error status (%x).\n", __func__
, ha
->host_no
,
1723 rval
= QLA_FUNCTION_FAILED
;
1724 } else if (lg
->comp_status
!= __constant_cpu_to_le16(CS_COMPLETE
)) {
1725 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1726 "-- completion status (%x) ioparam=%x/%x.\n", __func__
,
1727 ha
->host_no
, le16_to_cpu(lg
->comp_status
),
1728 le32_to_cpu(lg
->io_parameter
[0]),
1729 le32_to_cpu(lg
->io_parameter
[1]));)
1732 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
1735 dma_pool_free(ha
->s_dma_pool
, lg
, lg_dma
);
1741 * qla2x00_fabric_logout
1742 * Issue logout fabric port mailbox command.
1745 * ha = adapter block pointer.
1746 * loop_id = device loop ID.
1747 * TARGET_QUEUE_LOCK must be released.
1748 * ADAPTER_STATE_LOCK must be released.
1751 * qla2x00 local function return status code.
1757 qla2x00_fabric_logout(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t domain
,
1758 uint8_t area
, uint8_t al_pa
)
1762 mbx_cmd_t
*mcp
= &mc
;
1764 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1767 mcp
->mb
[0] = MBC_LOGOUT_FABRIC_PORT
;
1768 mcp
->out_mb
= MBX_1
|MBX_0
;
1769 if (HAS_EXTENDED_IDS(ha
)) {
1770 mcp
->mb
[1] = loop_id
;
1772 mcp
->out_mb
|= MBX_10
;
1774 mcp
->mb
[1] = loop_id
<< 8;
1777 mcp
->in_mb
= MBX_1
|MBX_0
;
1780 rval
= qla2x00_mailbox_command(ha
, mcp
);
1782 if (rval
!= QLA_SUCCESS
) {
1784 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1785 "mbx1=%x.\n", ha
->host_no
, rval
, mcp
->mb
[1]);)
1788 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1796 * qla2x00_full_login_lip
1797 * Issue full login LIP mailbox command.
1800 * ha = adapter block pointer.
1801 * TARGET_QUEUE_LOCK must be released.
1802 * ADAPTER_STATE_LOCK must be released.
1805 * qla2x00 local function return status code.
1811 qla2x00_full_login_lip(scsi_qla_host_t
*ha
)
1815 mbx_cmd_t
*mcp
= &mc
;
1817 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1820 mcp
->mb
[0] = MBC_LIP_FULL_LOGIN
;
1824 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1828 rval
= qla2x00_mailbox_command(ha
, mcp
);
1830 if (rval
!= QLA_SUCCESS
) {
1832 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1833 ha
->host_no
, rval
);)
1836 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1844 * qla2x00_get_id_list
1847 * ha = adapter block pointer.
1850 * qla2x00 local function return status code.
1856 qla2x00_get_id_list(scsi_qla_host_t
*ha
, void *id_list
, dma_addr_t id_list_dma
,
1861 mbx_cmd_t
*mcp
= &mc
;
1863 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1866 if (id_list
== NULL
)
1867 return QLA_FUNCTION_FAILED
;
1869 mcp
->mb
[0] = MBC_GET_ID_LIST
;
1870 mcp
->out_mb
= MBX_0
;
1871 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
1872 mcp
->mb
[2] = MSW(id_list_dma
);
1873 mcp
->mb
[3] = LSW(id_list_dma
);
1874 mcp
->mb
[6] = MSW(MSD(id_list_dma
));
1875 mcp
->mb
[7] = LSW(MSD(id_list_dma
));
1877 mcp
->out_mb
|= MBX_8
|MBX_7
|MBX_6
|MBX_3
|MBX_2
;
1879 mcp
->mb
[1] = MSW(id_list_dma
);
1880 mcp
->mb
[2] = LSW(id_list_dma
);
1881 mcp
->mb
[3] = MSW(MSD(id_list_dma
));
1882 mcp
->mb
[6] = LSW(MSD(id_list_dma
));
1883 mcp
->out_mb
|= MBX_6
|MBX_3
|MBX_2
|MBX_1
;
1885 mcp
->in_mb
= MBX_1
|MBX_0
;
1888 rval
= qla2x00_mailbox_command(ha
, mcp
);
1890 if (rval
!= QLA_SUCCESS
) {
1892 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1893 ha
->host_no
, rval
);)
1895 *entries
= mcp
->mb
[1];
1896 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1904 * qla2x00_get_resource_cnts
1905 * Get current firmware resource counts.
1908 * ha = adapter block pointer.
1911 * qla2x00 local function return status code.
1917 qla2x00_get_resource_cnts(scsi_qla_host_t
*ha
, uint16_t *cur_xchg_cnt
,
1918 uint16_t *orig_xchg_cnt
, uint16_t *cur_iocb_cnt
, uint16_t *orig_iocb_cnt
)
1922 mbx_cmd_t
*mcp
= &mc
;
1924 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
1926 mcp
->mb
[0] = MBC_GET_RESOURCE_COUNTS
;
1927 mcp
->out_mb
= MBX_0
;
1928 mcp
->in_mb
= MBX_10
|MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1931 rval
= qla2x00_mailbox_command(ha
, mcp
);
1933 if (rval
!= QLA_SUCCESS
) {
1935 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__
,
1936 ha
->host_no
, mcp
->mb
[0]);)
1938 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1939 "mb7=%x mb10=%x.\n", __func__
, ha
->host_no
,
1940 mcp
->mb
[1], mcp
->mb
[2], mcp
->mb
[3], mcp
->mb
[6], mcp
->mb
[7],
1944 *cur_xchg_cnt
= mcp
->mb
[3];
1946 *orig_xchg_cnt
= mcp
->mb
[6];
1948 *cur_iocb_cnt
= mcp
->mb
[7];
1950 *orig_iocb_cnt
= mcp
->mb
[10];
1956 #if defined(QL_DEBUG_LEVEL_3)
1958 * qla2x00_get_fcal_position_map
1959 * Get FCAL (LILP) position map using mailbox command
1962 * ha = adapter state pointer.
1963 * pos_map = buffer pointer (can be NULL).
1966 * qla2x00 local function return status code.
1972 qla2x00_get_fcal_position_map(scsi_qla_host_t
*ha
, char *pos_map
)
1976 mbx_cmd_t
*mcp
= &mc
;
1978 dma_addr_t pmap_dma
;
1980 pmap
= dma_pool_alloc(ha
->s_dma_pool
, GFP_ATOMIC
, &pmap_dma
);
1982 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1983 __func__
, ha
->host_no
));
1984 return QLA_MEMORY_ALLOC_FAILED
;
1986 memset(pmap
, 0, FCAL_MAP_SIZE
);
1988 mcp
->mb
[0] = MBC_GET_FC_AL_POSITION_MAP
;
1989 mcp
->mb
[2] = MSW(pmap_dma
);
1990 mcp
->mb
[3] = LSW(pmap_dma
);
1991 mcp
->mb
[6] = MSW(MSD(pmap_dma
));
1992 mcp
->mb
[7] = LSW(MSD(pmap_dma
));
1993 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
1994 mcp
->in_mb
= MBX_1
|MBX_0
;
1995 mcp
->buf_size
= FCAL_MAP_SIZE
;
1996 mcp
->flags
= MBX_DMA_IN
;
1997 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1998 rval
= qla2x00_mailbox_command(ha
, mcp
);
2000 if (rval
== QLA_SUCCESS
) {
2001 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2002 "size (%x)\n", __func__
, ha
->host_no
, mcp
->mb
[0],
2003 mcp
->mb
[1], (unsigned)pmap
[0]));
2004 DEBUG11(qla2x00_dump_buffer(pmap
, pmap
[0] + 1));
2007 memcpy(pos_map
, pmap
, FCAL_MAP_SIZE
);
2009 dma_pool_free(ha
->s_dma_pool
, pmap
, pmap_dma
);
2011 if (rval
!= QLA_SUCCESS
) {
2012 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
2013 ha
->host_no
, rval
));
2015 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
2023 * qla2x00_get_link_status
2026 * ha = adapter block pointer.
2027 * loop_id = device loop ID.
2028 * ret_buf = pointer to link status return buffer.
2032 * BIT_0 = mem alloc error.
2033 * BIT_1 = mailbox error.
2036 qla2x00_get_link_status(scsi_qla_host_t
*ha
, uint16_t loop_id
,
2037 link_stat_t
*ret_buf
, uint16_t *status
)
2041 mbx_cmd_t
*mcp
= &mc
;
2042 link_stat_t
*stat_buf
;
2043 dma_addr_t stat_buf_dma
;
2045 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
2047 stat_buf
= dma_pool_alloc(ha
->s_dma_pool
, GFP_ATOMIC
, &stat_buf_dma
);
2048 if (stat_buf
== NULL
) {
2049 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2050 __func__
, ha
->host_no
));
2053 memset(stat_buf
, 0, sizeof(link_stat_t
));
2055 mcp
->mb
[0] = MBC_GET_LINK_STATUS
;
2056 mcp
->mb
[2] = MSW(stat_buf_dma
);
2057 mcp
->mb
[3] = LSW(stat_buf_dma
);
2058 mcp
->mb
[6] = MSW(MSD(stat_buf_dma
));
2059 mcp
->mb
[7] = LSW(MSD(stat_buf_dma
));
2060 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
2062 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
2063 mcp
->mb
[1] = loop_id
;
2066 mcp
->out_mb
|= MBX_10
|MBX_4
|MBX_1
;
2067 mcp
->in_mb
|= MBX_1
;
2068 } else if (HAS_EXTENDED_IDS(ha
)) {
2069 mcp
->mb
[1] = loop_id
;
2071 mcp
->out_mb
|= MBX_10
|MBX_1
;
2073 mcp
->mb
[1] = loop_id
<< 8;
2074 mcp
->out_mb
|= MBX_1
;
2077 mcp
->flags
= IOCTL_CMD
;
2078 rval
= qla2x00_mailbox_command(ha
, mcp
);
2080 if (rval
== QLA_SUCCESS
) {
2081 if (mcp
->mb
[0] != MBS_COMMAND_COMPLETE
) {
2082 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2083 __func__
, ha
->host_no
, mcp
->mb
[0]);)
2084 status
[0] = mcp
->mb
[0];
2087 /* copy over data -- firmware data is LE. */
2088 ret_buf
->link_fail_cnt
=
2089 le32_to_cpu(stat_buf
->link_fail_cnt
);
2090 ret_buf
->loss_sync_cnt
=
2091 le32_to_cpu(stat_buf
->loss_sync_cnt
);
2092 ret_buf
->loss_sig_cnt
=
2093 le32_to_cpu(stat_buf
->loss_sig_cnt
);
2094 ret_buf
->prim_seq_err_cnt
=
2095 le32_to_cpu(stat_buf
->prim_seq_err_cnt
);
2096 ret_buf
->inval_xmit_word_cnt
=
2097 le32_to_cpu(stat_buf
->inval_xmit_word_cnt
);
2098 ret_buf
->inval_crc_cnt
=
2099 le32_to_cpu(stat_buf
->inval_crc_cnt
);
2101 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2102 "loss_sync=%d loss_sig=%d seq_err=%d "
2103 "inval_xmt_word=%d inval_crc=%d.\n", __func__
,
2104 ha
->host_no
, stat_buf
->link_fail_cnt
,
2105 stat_buf
->loss_sync_cnt
, stat_buf
->loss_sig_cnt
,
2106 stat_buf
->prim_seq_err_cnt
,
2107 stat_buf
->inval_xmit_word_cnt
,
2108 stat_buf
->inval_crc_cnt
);)
2112 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
2113 ha
->host_no
, rval
);)
2117 dma_pool_free(ha
->s_dma_pool
, stat_buf
, stat_buf_dma
);
2123 qla24xx_get_isp_stats(scsi_qla_host_t
*ha
, uint32_t *dwbuf
, uint32_t dwords
,
2128 mbx_cmd_t
*mcp
= &mc
;
2129 uint32_t *sbuf
, *siter
;
2130 dma_addr_t sbuf_dma
;
2132 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
2134 if (dwords
> (DMA_POOL_SIZE
/ 4)) {
2135 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2136 "(max %d).\n", __func__
, ha
->host_no
, dwords
,
2137 DMA_POOL_SIZE
/ 4));
2140 sbuf
= dma_pool_alloc(ha
->s_dma_pool
, GFP_ATOMIC
, &sbuf_dma
);
2142 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2143 __func__
, ha
->host_no
));
2146 memset(sbuf
, 0, DMA_POOL_SIZE
);
2148 mcp
->mb
[0] = MBC_GET_LINK_PRIV_STATS
;
2149 mcp
->mb
[2] = MSW(sbuf_dma
);
2150 mcp
->mb
[3] = LSW(sbuf_dma
);
2151 mcp
->mb
[6] = MSW(MSD(sbuf_dma
));
2152 mcp
->mb
[7] = LSW(MSD(sbuf_dma
));
2153 mcp
->mb
[8] = dwords
;
2155 mcp
->out_mb
= MBX_10
|MBX_8
|MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
2156 mcp
->in_mb
= MBX_2
|MBX_1
|MBX_0
;
2158 mcp
->flags
= IOCTL_CMD
;
2159 rval
= qla2x00_mailbox_command(ha
, mcp
);
2161 if (rval
== QLA_SUCCESS
) {
2162 if (mcp
->mb
[0] != MBS_COMMAND_COMPLETE
) {
2163 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2164 __func__
, ha
->host_no
, mcp
->mb
[0]));
2165 status
[0] = mcp
->mb
[0];
2168 /* Copy over data -- firmware data is LE. */
2171 *dwbuf
++ = le32_to_cpu(*siter
++);
2175 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
2176 ha
->host_no
, rval
));
2180 dma_pool_free(ha
->s_dma_pool
, sbuf
, sbuf_dma
);
2186 qla24xx_abort_command(scsi_qla_host_t
*ha
, srb_t
*sp
)
2190 unsigned long flags
= 0;
2192 struct abort_entry_24xx
*abt
;
2196 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
2198 fcport
= sp
->fcport
;
2200 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2201 for (handle
= 1; handle
< MAX_OUTSTANDING_COMMANDS
; handle
++) {
2202 if (ha
->outstanding_cmds
[handle
] == sp
)
2205 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2206 if (handle
== MAX_OUTSTANDING_COMMANDS
) {
2207 /* Command not found. */
2208 return QLA_FUNCTION_FAILED
;
2211 abt
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &abt_dma
);
2213 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2214 __func__
, ha
->host_no
));
2215 return QLA_MEMORY_ALLOC_FAILED
;
2217 memset(abt
, 0, sizeof(struct abort_entry_24xx
));
2219 abt
->entry_type
= ABORT_IOCB_TYPE
;
2220 abt
->entry_count
= 1;
2221 abt
->nport_handle
= cpu_to_le16(fcport
->loop_id
);
2222 abt
->handle_to_abort
= handle
;
2223 abt
->port_id
[0] = fcport
->d_id
.b
.al_pa
;
2224 abt
->port_id
[1] = fcport
->d_id
.b
.area
;
2225 abt
->port_id
[2] = fcport
->d_id
.b
.domain
;
2226 rval
= qla2x00_issue_iocb(ha
, abt
, abt_dma
, 0);
2227 if (rval
!= QLA_SUCCESS
) {
2228 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2229 __func__
, ha
->host_no
, rval
);)
2230 } else if (abt
->entry_status
!= 0) {
2231 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2232 "-- error status (%x).\n", __func__
, ha
->host_no
,
2233 abt
->entry_status
));
2234 rval
= QLA_FUNCTION_FAILED
;
2235 } else if (abt
->nport_handle
!= __constant_cpu_to_le16(0)) {
2236 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2237 "-- completion status (%x).\n", __func__
, ha
->host_no
,
2238 le16_to_cpu(abt
->nport_handle
));)
2239 rval
= QLA_FUNCTION_FAILED
;
2241 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
2242 sp
->flags
|= SRB_ABORT_PENDING
;
2245 dma_pool_free(ha
->s_dma_pool
, abt
, abt_dma
);
2250 struct tsk_mgmt_cmd
{
2252 struct tsk_mgmt_entry tsk
;
2253 struct sts_entry_24xx sts
;
2258 qla24xx_abort_target(fc_port_t
*fcport
)
2261 struct tsk_mgmt_cmd
*tsk
;
2263 scsi_qla_host_t
*ha
;
2268 DEBUG11(printk("%s(%ld): entered.\n", __func__
, fcport
->ha
->host_no
);)
2271 tsk
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &tsk_dma
);
2273 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2274 "IOCB.\n", __func__
, ha
->host_no
));
2275 return QLA_MEMORY_ALLOC_FAILED
;
2277 memset(tsk
, 0, sizeof(struct tsk_mgmt_cmd
));
2279 tsk
->p
.tsk
.entry_type
= TSK_MGMT_IOCB_TYPE
;
2280 tsk
->p
.tsk
.entry_count
= 1;
2281 tsk
->p
.tsk
.nport_handle
= cpu_to_le16(fcport
->loop_id
);
2282 tsk
->p
.tsk
.timeout
= __constant_cpu_to_le16(25);
2283 tsk
->p
.tsk
.control_flags
= __constant_cpu_to_le32(TCF_TARGET_RESET
);
2284 tsk
->p
.tsk
.port_id
[0] = fcport
->d_id
.b
.al_pa
;
2285 tsk
->p
.tsk
.port_id
[1] = fcport
->d_id
.b
.area
;
2286 tsk
->p
.tsk
.port_id
[2] = fcport
->d_id
.b
.domain
;
2287 rval
= qla2x00_issue_iocb(ha
, tsk
, tsk_dma
, 0);
2288 if (rval
!= QLA_SUCCESS
) {
2289 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2290 "(%x).\n", __func__
, ha
->host_no
, rval
);)
2292 } else if (tsk
->p
.sts
.entry_status
!= 0) {
2293 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2294 "-- error status (%x).\n", __func__
, ha
->host_no
,
2295 tsk
->p
.sts
.entry_status
));
2296 rval
= QLA_FUNCTION_FAILED
;
2298 } else if (tsk
->p
.sts
.comp_status
!=
2299 __constant_cpu_to_le16(CS_COMPLETE
)) {
2300 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2301 "-- completion status (%x).\n", __func__
,
2302 ha
->host_no
, le16_to_cpu(tsk
->p
.sts
.comp_status
));)
2303 rval
= QLA_FUNCTION_FAILED
;
2307 /* Issue marker IOCB. */
2308 rval
= qla2x00_marker(ha
, fcport
->loop_id
, 0, MK_SYNC_ID
);
2309 if (rval
!= QLA_SUCCESS
) {
2310 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2311 "(%x).\n", __func__
, ha
->host_no
, rval
);)
2313 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
2317 dma_pool_free(ha
->s_dma_pool
, tsk
, tsk_dma
);
2323 qla2x00_system_error(scsi_qla_host_t
*ha
)
2327 mbx_cmd_t
*mcp
= &mc
;
2329 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
))
2330 return QLA_FUNCTION_FAILED
;
2332 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
2334 mcp
->mb
[0] = MBC_GEN_SYSTEM_ERROR
;
2335 mcp
->out_mb
= MBX_0
;
2339 rval
= qla2x00_mailbox_command(ha
, mcp
);
2341 if (rval
!= QLA_SUCCESS
) {
2342 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
2343 ha
->host_no
, rval
));
2345 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
2352 * qla2x00_get_serdes_params() -
2358 qla2x00_get_serdes_params(scsi_qla_host_t
*ha
, uint16_t *sw_em_1g
,
2359 uint16_t *sw_em_2g
, uint16_t *sw_em_4g
)
2363 mbx_cmd_t
*mcp
= &mc
;
2365 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
2367 mcp
->mb
[0] = MBC_SERDES_PARAMS
;
2369 mcp
->out_mb
= MBX_1
|MBX_0
;
2370 mcp
->in_mb
= MBX_4
|MBX_3
|MBX_2
|MBX_0
;
2373 rval
= qla2x00_mailbox_command(ha
, mcp
);
2375 if (rval
!= QLA_SUCCESS
) {
2377 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__
,
2378 ha
->host_no
, rval
, mcp
->mb
[0]));
2380 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
2383 *sw_em_1g
= mcp
->mb
[2];
2385 *sw_em_2g
= mcp
->mb
[3];
2387 *sw_em_4g
= mcp
->mb
[4];
2394 * qla2x00_set_serdes_params() -
2400 qla2x00_set_serdes_params(scsi_qla_host_t
*ha
, uint16_t sw_em_1g
,
2401 uint16_t sw_em_2g
, uint16_t sw_em_4g
)
2405 mbx_cmd_t
*mcp
= &mc
;
2407 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
2409 mcp
->mb
[0] = MBC_SERDES_PARAMS
;
2411 mcp
->mb
[2] = sw_em_1g
;
2412 mcp
->mb
[3] = sw_em_2g
;
2413 mcp
->mb
[4] = sw_em_4g
;
2414 mcp
->out_mb
= MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
2418 rval
= qla2x00_mailbox_command(ha
, mcp
);
2420 if (rval
!= QLA_SUCCESS
) {
2422 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__
,
2423 ha
->host_no
, rval
, mcp
->mb
[0]));
2426 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
2433 qla2x00_stop_firmware(scsi_qla_host_t
*ha
)
2437 mbx_cmd_t
*mcp
= &mc
;
2439 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
))
2440 return QLA_FUNCTION_FAILED
;
2442 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
2444 mcp
->mb
[0] = MBC_STOP_FIRMWARE
;
2445 mcp
->out_mb
= MBX_0
;
2449 rval
= qla2x00_mailbox_command(ha
, mcp
);
2451 if (rval
!= QLA_SUCCESS
) {
2452 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
2453 ha
->host_no
, rval
));
2455 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));