2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 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
;
63 uint8_t abort_active
= test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
);
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
;
75 DEBUG11(printk("qla2x00_mailbox_command(%ld): entered.\n",
78 * Wait for active mailbox commands to finish by waiting at most
79 * tov seconds. This is to serialize actual issuing of mailbox cmds
80 * during non ISP abort time.
83 if (qla2x00_down_timeout(&ha
->mbx_cmd_sem
, mcp
->tov
* HZ
)) {
84 /* Timeout occurred. Return error. */
85 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): cmd "
86 "access timeout. Exiting.\n", ha
->host_no
);)
87 return QLA_FUNCTION_TIMEOUT
;
91 ha
->flags
.mbox_busy
= 1;
92 /* Save mailbox command for debug */
95 /* Try to get mailbox register access */
97 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
99 DEBUG11(printk("scsi%d: prepare to issue mbox cmd=0x%x.\n",
100 (int)ha
->host_no
, mcp
->mb
[0]);)
102 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
104 /* Load mailbox registers. */
105 optr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 0);
108 command
= mcp
->mb
[0];
109 mboxes
= mcp
->out_mb
;
111 for (cnt
= 0; cnt
< ha
->mbx_count
; cnt
++) {
112 if (IS_QLA2200(ha
) && cnt
== 8)
113 optr
= (uint16_t __iomem
*)MAILBOX_REG(ha
, reg
, 8);
115 WRT_REG_WORD(optr
, *iptr
);
122 #if defined(QL_DEBUG_LEVEL_1)
123 printk("qla2x00_mailbox_command: Loaded MBX registers "
124 "(displayed in bytes) = \n");
125 qla2x00_dump_buffer((uint8_t *)mcp
->mb
, 16);
127 qla2x00_dump_buffer(((uint8_t *)mcp
->mb
+ 0x10), 16);
129 qla2x00_dump_buffer(((uint8_t *)mcp
->mb
+ 0x20), 8);
131 printk("qla2x00_mailbox_command: I/O address = %lx.\n",
133 qla2x00_dump_regs(ha
);
136 /* Issue set host interrupt command to send cmd out. */
137 ha
->flags
.mbox_int
= 0;
138 clear_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
140 /* Unlock mbx registers and wait for interrupt */
142 DEBUG11(printk("qla2x00_mailbox_command: going to unlock irq & "
143 "waiting for interrupt. jiffies=%lx.\n", jiffies
);)
145 /* Wait for mbx cmd completion until timeout */
147 if (!abort_active
&& io_lock_on
) {
148 /* sleep on completion semaphore */
149 DEBUG11(printk("qla2x00_mailbox_command(%ld): "
150 "INTERRUPT MODE. Initializing timer.\n",
153 init_timer(&tmp_intr_timer
);
154 tmp_intr_timer
.data
= (unsigned long)&ha
->mbx_intr_sem
;
155 tmp_intr_timer
.expires
= jiffies
+ mcp
->tov
* HZ
;
156 tmp_intr_timer
.function
=
157 (void (*)(unsigned long))qla2x00_mbx_sem_timeout
;
159 DEBUG11(printk("qla2x00_mailbox_command(%ld): "
160 "Adding timer.\n", ha
->host_no
);)
161 add_timer(&tmp_intr_timer
);
163 DEBUG11(printk("qla2x00_mailbox_command: going to "
164 "unlock & sleep. time=0x%lx.\n", jiffies
);)
166 set_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
168 WRT_REG_WORD(®
->hccr
, HCCR_SET_HOST_INT
);
169 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
172 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, mbx_flags
);
174 /* Wait for either the timer to expire
175 * or the mbox completion interrupt
177 down(&ha
->mbx_intr_sem
);
179 DEBUG11(printk("qla2x00_mailbox_command:"
181 "time=0x%lx\n", jiffies
);)
182 clear_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
184 /* delete the timer */
185 del_timer(&tmp_intr_timer
);
188 DEBUG3_11(printk("qla2x00_mailbox_command(%ld): cmd=%x "
189 "POLLING MODE.\n", ha
->host_no
, command
);)
191 WRT_REG_WORD(®
->hccr
, HCCR_SET_HOST_INT
);
192 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
194 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, mbx_flags
);
196 wait_time
= jiffies
+ mcp
->tov
* HZ
; /* wait at most tov secs */
197 while (!ha
->flags
.mbox_int
) {
198 if (time_after(jiffies
, wait_time
))
201 /* Check for pending interrupts. */
204 udelay(10); /* v4.27 */
209 spin_lock_irqsave(&ha
->mbx_reg_lock
, mbx_flags
);
211 /* Check whether we timed out */
212 if (ha
->flags
.mbox_int
) {
215 DEBUG3_11(printk("qla2x00_mailbox_cmd: cmd %x completed.\n",
218 /* Got interrupt. Clear the flag. */
219 ha
->flags
.mbox_int
= 0;
220 clear_bit(MBX_INTERRUPT
, &ha
->mbx_cmd_flags
);
222 if (ha
->mailbox_out
[0] != MBS_COMMAND_COMPLETE
) {
223 qla2x00_stats
.mboxerr
++;
224 rval
= QLA_FUNCTION_FAILED
;
227 /* Load return mailbox registers. */
229 iptr
= (uint16_t *)&ha
->mailbox_out
[0];
231 for (cnt
= 0; cnt
< ha
->mbx_count
; cnt
++) {
241 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
242 defined(QL_DEBUG_LEVEL_11)
243 printk("qla2x00_mailbox_command(%ld): **** MB Command Timeout "
244 "for cmd %x ****\n", ha
->host_no
, command
);
245 printk("qla2x00_mailbox_command: icontrol=%x jiffies=%lx\n",
246 RD_REG_WORD(®
->ictrl
), jiffies
);
247 printk("qla2x00_mailbox_command: *** mailbox[0] = 0x%x ***\n",
249 qla2x00_dump_regs(ha
);
252 qla2x00_stats
.mboxtout
++;
253 ha
->total_mbx_timeout
++;
254 rval
= QLA_FUNCTION_TIMEOUT
;
258 spin_unlock_irqrestore(&ha
->mbx_reg_lock
, mbx_flags
);
260 ha
->flags
.mbox_busy
= 0;
266 DEBUG11(printk("qla2x00_mailbox_cmd: checking for additional "
267 "resp interrupt.\n");)
269 /* polling mode for non isp_abort commands. */
273 if (rval
== QLA_FUNCTION_TIMEOUT
) {
274 if (!io_lock_on
|| (mcp
->flags
& IOCTL_CMD
)) {
275 /* not in dpc. schedule it for dpc to take over. */
276 DEBUG(printk("qla2x00_mailbox_command(%ld): timeout "
277 "schedule isp_abort_needed.\n",
279 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): "
280 "timeout schedule isp_abort_needed.\n",
282 qla_printk(KERN_WARNING
, ha
,
283 "Mailbox command timeout occured. Scheduling ISP "
285 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
286 if (ha
->dpc_wait
&& !ha
->dpc_active
)
289 } else if (!abort_active
) {
291 /* call abort directly since we are in the DPC thread */
292 DEBUG(printk("qla2x00_mailbox_command(%ld): timeout "
293 "calling abort_isp\n", ha
->host_no
);)
294 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): "
295 "timeout calling abort_isp\n", 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
);
308 DEBUG(printk("qla2x00_mailbox_command: finished "
310 DEBUG2_3_11(printk("qla2x00_mailbox_command: finished "
315 /* Allow next mbx cmd to come in. */
317 up(&ha
->mbx_cmd_sem
);
320 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): **** FAILED. "
321 "mbx0=%x, mbx1=%x, mbx2=%x, cmd=%x ****\n",
322 ha
->host_no
, mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[2], command
);)
324 DEBUG11(printk("qla2x00_mailbox_command(%ld): done.\n",
328 DEBUG11(printk("qla2x00_mailbox_command(%ld): exiting.\n",
336 * Load adapter RAM using DMA.
339 * ha = adapter block pointer.
342 * qla2x00 local function return status code.
348 qla2x00_load_ram(scsi_qla_host_t
*ha
, dma_addr_t req_dma
, uint16_t risc_addr
,
349 uint16_t risc_code_size
)
353 mbx_cmd_t
*mcp
= &mc
;
359 DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
362 req_len
= risc_code_size
;
366 normalized
= qla2x00_normalize_dma_addr(&req_dma
, &req_len
, &nml_dma
,
369 /* Load first segment */
370 mcp
->mb
[0] = MBC_LOAD_RISC_RAM
;
371 mcp
->mb
[1] = risc_addr
;
372 mcp
->mb
[2] = MSW(req_dma
);
373 mcp
->mb
[3] = LSW(req_dma
);
374 mcp
->mb
[4] = (uint16_t)req_len
;
375 mcp
->mb
[6] = MSW(MSD(req_dma
));
376 mcp
->mb
[7] = LSW(MSD(req_dma
));
377 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
381 rval
= qla2x00_mailbox_command(ha
, mcp
);
383 /* Load second segment - if necessary */
384 if (normalized
&& (rval
== QLA_SUCCESS
)) {
385 mcp
->mb
[0] = MBC_LOAD_RISC_RAM
;
386 mcp
->mb
[1] = risc_addr
+ (uint16_t)req_len
;
387 mcp
->mb
[2] = MSW(nml_dma
);
388 mcp
->mb
[3] = LSW(nml_dma
);
389 mcp
->mb
[4] = (uint16_t)nml_len
;
390 mcp
->mb
[6] = MSW(MSD(nml_dma
));
391 mcp
->mb
[7] = LSW(MSD(nml_dma
));
392 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
396 rval
= qla2x00_mailbox_command(ha
, mcp
);
399 if (rval
== QLA_SUCCESS
) {
401 DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha
->host_no
);)
404 DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
405 "mb[0]=%x.\n", ha
->host_no
, rval
, mcp
->mb
[0]);)
411 * qla2x00_load_ram_ext
412 * Load adapter extended RAM using DMA.
415 * ha = adapter block pointer.
418 * qla2x00 local function return status code.
424 qla2x00_load_ram_ext(scsi_qla_host_t
*ha
, dma_addr_t req_dma
,
425 uint32_t risc_addr
, uint16_t risc_code_size
)
429 mbx_cmd_t
*mcp
= &mc
;
435 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
437 req_len
= risc_code_size
;
441 normalized
= qla2x00_normalize_dma_addr(&req_dma
, &req_len
, &nml_dma
,
444 /* Load first segment */
445 mcp
->mb
[0] = MBC_LOAD_RISC_RAM_EXTENDED
;
446 mcp
->mb
[1] = LSW(risc_addr
);
447 mcp
->mb
[2] = MSW(req_dma
);
448 mcp
->mb
[3] = LSW(req_dma
);
449 mcp
->mb
[4] = (uint16_t)req_len
;
450 mcp
->mb
[6] = MSW(MSD(req_dma
));
451 mcp
->mb
[7] = LSW(MSD(req_dma
));
452 mcp
->mb
[8] = MSW(risc_addr
);
453 mcp
->out_mb
= MBX_8
|MBX_7
|MBX_6
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
457 rval
= qla2x00_mailbox_command(ha
, mcp
);
459 /* Load second segment - if necessary */
460 if (normalized
&& (rval
== QLA_SUCCESS
)) {
461 risc_addr
+= req_len
;
462 mcp
->mb
[0] = MBC_LOAD_RISC_RAM_EXTENDED
;
463 mcp
->mb
[1] = LSW(risc_addr
);
464 mcp
->mb
[2] = MSW(nml_dma
);
465 mcp
->mb
[3] = LSW(nml_dma
);
466 mcp
->mb
[4] = (uint16_t)nml_len
;
467 mcp
->mb
[6] = MSW(MSD(nml_dma
));
468 mcp
->mb
[7] = LSW(MSD(nml_dma
));
469 mcp
->mb
[8] = MSW(risc_addr
);
470 mcp
->out_mb
= MBX_8
|MBX_7
|MBX_6
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
474 rval
= qla2x00_mailbox_command(ha
, mcp
);
477 if (rval
!= QLA_SUCCESS
) {
479 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n",
480 __func__
, ha
->host_no
, rval
, mcp
->mb
[0]));
483 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
491 * Start adapter firmware.
494 * ha = adapter block pointer.
495 * TARGET_QUEUE_LOCK must be released.
496 * ADAPTER_STATE_LOCK must be released.
499 * qla2x00 local function return status code.
505 qla2x00_execute_fw(scsi_qla_host_t
*ha
)
509 mbx_cmd_t
*mcp
= &mc
;
511 DEBUG11(printk("qla2x00_execute_fw(%ld): entered.\n", ha
->host_no
);)
513 mcp
->mb
[0] = MBC_EXECUTE_FIRMWARE
;
514 mcp
->mb
[1] = *ha
->brd_info
->fw_info
[0].fwstart
;
515 mcp
->out_mb
= MBX_1
|MBX_0
;
516 if (IS_QLA2322(ha
) || IS_QLA6322(ha
)) {
518 mcp
->out_mb
|= MBX_2
;
524 rval
= qla2x00_mailbox_command(ha
, mcp
);
526 DEBUG11(printk("qla2x00_execute_fw(%ld): done.\n", ha
->host_no
);)
532 * qla2x00_get_fw_version
533 * Get firmware version.
536 * ha: adapter state pointer.
537 * major: pointer for major number.
538 * minor: pointer for minor number.
539 * subminor: pointer for subminor number.
542 * qla2x00 local function return status code.
548 qla2x00_get_fw_version(scsi_qla_host_t
*ha
, uint16_t *major
, uint16_t *minor
,
549 uint16_t *subminor
, uint16_t *attributes
, uint32_t *memory
)
553 mbx_cmd_t
*mcp
= &mc
;
555 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
557 mcp
->mb
[0] = MBC_GET_FIRMWARE_VERSION
;
559 mcp
->in_mb
= MBX_6
|MBX_5
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
562 rval
= qla2x00_mailbox_command(ha
, mcp
);
564 /* Return mailbox data. */
567 *subminor
= mcp
->mb
[3];
568 *attributes
= mcp
->mb
[6];
569 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
570 *memory
= 0x1FFFF; /* Defaults to 128KB. */
572 *memory
= (mcp
->mb
[5] << 16) | mcp
->mb
[4];
574 if (rval
!= QLA_SUCCESS
) {
576 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
580 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
585 * qla2x00_get_fw_options
586 * Set firmware options.
589 * ha = adapter block pointer.
590 * fwopt = pointer for firmware options.
593 * qla2x00 local function return status code.
599 qla2x00_get_fw_options(scsi_qla_host_t
*ha
, uint16_t *fwopts
)
603 mbx_cmd_t
*mcp
= &mc
;
605 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
607 mcp
->mb
[0] = MBC_GET_FIRMWARE_OPTION
;
609 mcp
->in_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
612 rval
= qla2x00_mailbox_command(ha
, mcp
);
614 if (rval
!= QLA_SUCCESS
) {
616 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
619 fwopts
[1] = mcp
->mb
[1];
620 fwopts
[2] = mcp
->mb
[2];
621 fwopts
[3] = mcp
->mb
[3];
623 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
631 * qla2x00_set_fw_options
632 * Set firmware options.
635 * ha = adapter block pointer.
636 * fwopt = pointer for firmware options.
639 * qla2x00 local function return status code.
645 qla2x00_set_fw_options(scsi_qla_host_t
*ha
, uint16_t *fwopts
)
649 mbx_cmd_t
*mcp
= &mc
;
651 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
653 mcp
->mb
[0] = MBC_SET_FIRMWARE_OPTION
;
654 mcp
->mb
[1] = fwopts
[1];
655 mcp
->mb
[2] = fwopts
[2];
656 mcp
->mb
[3] = fwopts
[3];
657 mcp
->mb
[10] = fwopts
[10];
658 mcp
->mb
[11] = fwopts
[11];
659 mcp
->mb
[12] = 0; /* Undocumented, but used */
660 mcp
->out_mb
= MBX_12
|MBX_11
|MBX_10
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
664 rval
= qla2x00_mailbox_command(ha
, mcp
);
666 if (rval
!= QLA_SUCCESS
) {
668 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
672 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));
679 * qla2x00_mbx_reg_test
680 * Mailbox register wrap test.
683 * ha = adapter block pointer.
684 * TARGET_QUEUE_LOCK must be released.
685 * ADAPTER_STATE_LOCK must be released.
688 * qla2x00 local function return status code.
694 qla2x00_mbx_reg_test(scsi_qla_host_t
*ha
)
698 mbx_cmd_t
*mcp
= &mc
;
700 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha
->host_no
);)
702 mcp
->mb
[0] = MBC_MAILBOX_REGISTER_TEST
;
710 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_5
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
711 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_5
|MBX_4
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
714 rval
= qla2x00_mailbox_command(ha
, mcp
);
716 if (rval
== QLA_SUCCESS
) {
717 if (mcp
->mb
[1] != 0xAAAA || mcp
->mb
[2] != 0x5555 ||
718 mcp
->mb
[3] != 0xAA55 || mcp
->mb
[4] != 0x55AA)
719 rval
= QLA_FUNCTION_FAILED
;
720 if (mcp
->mb
[5] != 0xA5A5 || mcp
->mb
[6] != 0x5A5A ||
721 mcp
->mb
[7] != 0x2525)
722 rval
= QLA_FUNCTION_FAILED
;
725 if (rval
!= QLA_SUCCESS
) {
727 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
731 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
739 * qla2x00_verify_checksum
740 * Verify firmware checksum.
743 * ha = adapter block pointer.
744 * TARGET_QUEUE_LOCK must be released.
745 * ADAPTER_STATE_LOCK must be released.
748 * qla2x00 local function return status code.
754 qla2x00_verify_checksum(scsi_qla_host_t
*ha
)
758 mbx_cmd_t
*mcp
= &mc
;
760 DEBUG11(printk("qla2x00_verify_checksum(%ld): entered.\n",
763 mcp
->mb
[0] = MBC_VERIFY_CHECKSUM
;
764 mcp
->mb
[1] = *ha
->brd_info
->fw_info
[0].fwstart
;
765 mcp
->out_mb
= MBX_1
|MBX_0
;
766 mcp
->in_mb
= MBX_2
|MBX_0
;
769 rval
= qla2x00_mailbox_command(ha
, mcp
);
771 if (rval
!= QLA_SUCCESS
) {
773 DEBUG2_3_11(printk("qla2x00_verify_checksum(%ld): failed=%x.\n",
777 DEBUG11(printk("qla2x00_verify_checksum(%ld): done.\n",
786 * Issue IOCB using mailbox command
789 * ha = adapter state pointer.
790 * buffer = buffer pointer.
791 * phys_addr = physical address of buffer.
792 * size = size of buffer.
793 * TARGET_QUEUE_LOCK must be released.
794 * ADAPTER_STATE_LOCK must be released.
797 * qla2x00 local function return status code.
803 qla2x00_issue_iocb(scsi_qla_host_t
*ha
, void* buffer
, dma_addr_t phys_addr
,
808 mbx_cmd_t
*mcp
= &mc
;
810 mcp
->mb
[0] = MBC_IOCB_COMMAND_A64
;
812 mcp
->mb
[2] = MSW(phys_addr
);
813 mcp
->mb
[3] = LSW(phys_addr
);
814 mcp
->mb
[6] = MSW(MSD(phys_addr
));
815 mcp
->mb
[7] = LSW(MSD(phys_addr
));
816 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
817 mcp
->in_mb
= MBX_2
|MBX_0
;
820 rval
= qla2x00_mailbox_command(ha
, mcp
);
822 if (rval
!= QLA_SUCCESS
) {
824 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
826 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
836 * qla2x00_abort_command
837 * Abort command aborts a specified IOCB.
840 * ha = adapter block pointer.
841 * sp = SB structure pointer.
844 * qla2x00 local function return status code.
850 qla2x00_abort_command(scsi_qla_host_t
*ha
, srb_t
*sp
)
852 unsigned long flags
= 0;
857 mbx_cmd_t
*mcp
= &mc
;
859 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha
->host_no
);)
861 fcport
= sp
->fclun
->fcport
;
863 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
864 atomic_read(&fcport
->state
) == FCS_DEVICE_LOST
) {
868 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
869 for (handle
= 1; handle
< MAX_OUTSTANDING_COMMANDS
; handle
++) {
870 if (ha
->outstanding_cmds
[handle
] == sp
)
873 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
875 if (handle
== MAX_OUTSTANDING_COMMANDS
) {
876 /* command not found */
877 return QLA_FUNCTION_FAILED
;
880 mcp
->mb
[0] = MBC_ABORT_COMMAND
;
881 if (HAS_EXTENDED_IDS(ha
))
882 mcp
->mb
[1] = fcport
->loop_id
;
884 mcp
->mb
[1] = fcport
->loop_id
<< 8;
885 mcp
->mb
[2] = (uint16_t)handle
;
886 mcp
->mb
[3] = (uint16_t)(handle
>> 16);
887 mcp
->mb
[6] = (uint16_t)sp
->fclun
->lun
;
888 mcp
->out_mb
= MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
892 rval
= qla2x00_mailbox_command(ha
, mcp
);
894 if (rval
!= QLA_SUCCESS
) {
895 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
898 sp
->flags
|= SRB_ABORT_PENDING
;
899 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
908 * qla2x00_abort_target
909 * Issue abort target mailbox command.
912 * ha = adapter block pointer.
915 * qla2x00 local function return status code.
921 qla2x00_abort_target(fc_port_t
*fcport
)
925 mbx_cmd_t
*mcp
= &mc
;
927 DEBUG11(printk("qla2x00_abort_target(%ld): entered.\n",
928 fcport
->ha
->host_no
);)
930 if (fcport
== NULL
) {
931 /* no target to abort */
935 mcp
->mb
[0] = MBC_ABORT_TARGET
;
936 mcp
->out_mb
= MBX_2
|MBX_1
|MBX_0
;
937 if (HAS_EXTENDED_IDS(fcport
->ha
)) {
938 mcp
->mb
[1] = fcport
->loop_id
;
940 mcp
->out_mb
|= MBX_10
;
942 mcp
->mb
[1] = fcport
->loop_id
<< 8;
944 mcp
->mb
[2] = fcport
->ha
->loop_reset_delay
;
949 rval
= qla2x00_mailbox_command(fcport
->ha
, mcp
);
951 /* Issue marker command. */
952 fcport
->ha
->marker_needed
= 1;
954 if (rval
!= QLA_SUCCESS
) {
955 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
956 fcport
->ha
->host_no
, rval
);)
959 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
960 fcport
->ha
->host_no
);)
968 * qla2x00_target_reset
969 * Issue target reset mailbox command.
972 * ha = adapter block pointer.
973 * TARGET_QUEUE_LOCK must be released.
974 * ADAPTER_STATE_LOCK must be released.
977 * qla2x00 local function return status code.
983 qla2x00_target_reset(scsi_qla_host_t
*ha
, uint16_t b
, uint16_t t
)
987 mbx_cmd_t
*mcp
= &mc
;
990 DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha
->host_no
);)
993 if (tgt
->fcport
== NULL
) {
994 /* no target to abort */
997 if (atomic_read(&tgt
->fcport
->state
) != FCS_ONLINE
) {
998 /* target not online */
1002 mcp
->mb
[0] = MBC_TARGET_RESET
;
1003 if (HAS_EXTENDED_IDS(ha
))
1004 mcp
->mb
[1] = tgt
->fcport
->loop_id
;
1006 mcp
->mb
[1] = tgt
->fcport
->loop_id
<< 8;
1007 mcp
->mb
[2] = ha
->loop_reset_delay
;
1008 mcp
->out_mb
= MBX_2
|MBX_1
|MBX_0
;
1012 rval
= qla2x00_mailbox_command(ha
, mcp
);
1014 if (rval
!= QLA_SUCCESS
) {
1016 DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
1017 ha
->host_no
, rval
);)
1020 DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
1028 * qla2x00_get_adapter_id
1029 * Get adapter ID and topology.
1032 * ha = adapter block pointer.
1033 * id = pointer for loop ID.
1034 * al_pa = pointer for AL_PA.
1035 * area = pointer for area.
1036 * domain = pointer for domain.
1037 * top = pointer for topology.
1038 * TARGET_QUEUE_LOCK must be released.
1039 * ADAPTER_STATE_LOCK must be released.
1042 * qla2x00 local function return status code.
1048 qla2x00_get_adapter_id(scsi_qla_host_t
*ha
, uint16_t *id
, uint8_t *al_pa
,
1049 uint8_t *area
, uint8_t *domain
, uint16_t *top
)
1053 mbx_cmd_t
*mcp
= &mc
;
1055 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
1058 mcp
->mb
[0] = MBC_GET_ADAPTER_LOOP_ID
;
1059 mcp
->out_mb
= MBX_0
;
1060 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1063 rval
= qla2x00_mailbox_command(ha
, mcp
);
1067 *al_pa
= LSB(mcp
->mb
[2]);
1068 *area
= MSB(mcp
->mb
[2]);
1069 *domain
= LSB(mcp
->mb
[3]);
1072 if (rval
!= QLA_SUCCESS
) {
1074 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
1075 ha
->host_no
, rval
);)
1078 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
1086 * qla2x00_get_retry_cnt
1087 * Get current firmware login retry count and delay.
1090 * ha = adapter block pointer.
1091 * retry_cnt = pointer to login retry count.
1092 * tov = pointer to login timeout value.
1095 * qla2x00 local function return status code.
1101 qla2x00_get_retry_cnt(scsi_qla_host_t
*ha
, uint8_t *retry_cnt
, uint8_t *tov
,
1107 mbx_cmd_t
*mcp
= &mc
;
1109 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1112 mcp
->mb
[0] = MBC_GET_RETRY_COUNT
;
1113 mcp
->out_mb
= MBX_0
;
1114 mcp
->in_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1117 rval
= qla2x00_mailbox_command(ha
, mcp
);
1119 if (rval
!= QLA_SUCCESS
) {
1121 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1122 ha
->host_no
, mcp
->mb
[0]);)
1124 /* Convert returned data and check our values. */
1125 *r_a_tov
= mcp
->mb
[3] / 2;
1126 ratov
= (mcp
->mb
[3]/2) / 10; /* mb[3] value is in 100ms */
1127 if (mcp
->mb
[1] * ratov
> (*retry_cnt
) * (*tov
)) {
1128 /* Update to the larger values */
1129 *retry_cnt
= (uint8_t)mcp
->mb
[1];
1133 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1134 "ratov=%d.\n", ha
->host_no
, mcp
->mb
[3], ratov
);)
1141 * qla2x00_init_firmware
1142 * Initialize adapter firmware.
1145 * ha = adapter block pointer.
1146 * dptr = Initialization control block pointer.
1147 * size = size of initialization control block.
1148 * TARGET_QUEUE_LOCK must be released.
1149 * ADAPTER_STATE_LOCK must be released.
1152 * qla2x00 local function return status code.
1158 qla2x00_init_firmware(scsi_qla_host_t
*ha
, uint16_t size
)
1162 mbx_cmd_t
*mcp
= &mc
;
1164 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1167 mcp
->mb
[0] = MBC_INITIALIZE_FIRMWARE
;
1168 mcp
->mb
[2] = MSW(ha
->init_cb_dma
);
1169 mcp
->mb
[3] = LSW(ha
->init_cb_dma
);
1172 mcp
->mb
[6] = MSW(MSD(ha
->init_cb_dma
));
1173 mcp
->mb
[7] = LSW(MSD(ha
->init_cb_dma
));
1174 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
1175 mcp
->in_mb
= MBX_5
|MBX_4
|MBX_0
;
1176 mcp
->buf_size
= size
;
1177 mcp
->flags
= MBX_DMA_OUT
;
1179 rval
= qla2x00_mailbox_command(ha
, mcp
);
1181 if (rval
!= QLA_SUCCESS
) {
1183 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1185 ha
->host_no
, rval
, mcp
->mb
[0]);)
1188 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1196 * qla2x00_get_port_database
1197 * Issue normal/enhanced get port database mailbox command
1198 * and copy device name as necessary.
1201 * ha = adapter state pointer.
1202 * dev = structure pointer.
1203 * opt = enhanced cmd option byte.
1206 * qla2x00 local function return status code.
1212 qla2x00_get_port_database(scsi_qla_host_t
*ha
, fc_port_t
*fcport
, uint8_t opt
)
1216 mbx_cmd_t
*mcp
= &mc
;
1217 port_database_t
*pd
;
1220 DEBUG11(printk("qla2x00_get_port_database(%ld): entered.\n",
1223 pd
= dma_pool_alloc(ha
->s_dma_pool
, GFP_ATOMIC
, &pd_dma
);
1225 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): **** "
1226 "Mem Alloc Failed ****", ha
->host_no
);)
1227 return QLA_MEMORY_ALLOC_FAILED
;
1229 memset(pd
, 0, PORT_DATABASE_SIZE
);
1232 mcp
->mb
[0] = MBC_ENHANCED_GET_PORT_DATABASE
;
1234 mcp
->mb
[0] = MBC_GET_PORT_DATABASE
;
1235 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1236 if (HAS_EXTENDED_IDS(ha
)) {
1237 mcp
->mb
[1] = fcport
->loop_id
;
1239 mcp
->out_mb
|= MBX_10
;
1241 mcp
->mb
[1] = fcport
->loop_id
<< 8 | opt
;
1243 mcp
->mb
[2] = MSW(pd_dma
);
1244 mcp
->mb
[3] = LSW(pd_dma
);
1245 mcp
->mb
[6] = MSW(MSD(pd_dma
));
1246 mcp
->mb
[7] = LSW(MSD(pd_dma
));
1249 mcp
->buf_size
= PORT_DATABASE_SIZE
;
1250 mcp
->flags
= MBX_DMA_IN
;
1251 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1252 rval
= qla2x00_mailbox_command(ha
, mcp
);
1253 if (rval
!= QLA_SUCCESS
)
1256 /* Check for logged in state. */
1257 if (pd
->master_state
!= PD_STATE_PORT_LOGGED_IN
&&
1258 pd
->slave_state
!= PD_STATE_PORT_LOGGED_IN
) {
1259 rval
= QLA_FUNCTION_FAILED
;
1263 /* Names are little-endian. */
1264 memcpy(fcport
->node_name
, pd
->node_name
, WWN_SIZE
);
1265 memcpy(fcport
->port_name
, pd
->port_name
, WWN_SIZE
);
1267 /* Get port_id of device. */
1268 fcport
->d_id
.b
.al_pa
= pd
->port_id
[2];
1269 fcport
->d_id
.b
.area
= pd
->port_id
[3];
1270 fcport
->d_id
.b
.domain
= pd
->port_id
[0];
1271 fcport
->d_id
.b
.rsvd_1
= 0;
1273 /* Check for device require authentication. */
1274 pd
->common_features
& BIT_5
? (fcport
->flags
|= FCF_AUTH_REQ
) :
1275 (fcport
->flags
&= ~FCF_AUTH_REQ
);
1277 /* If not target must be initiator or unknown type. */
1278 if ((pd
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
1279 fcport
->port_type
= FCT_INITIATOR
;
1281 fcport
->port_type
= FCT_TARGET
;
1284 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1286 if (rval
!= QLA_SUCCESS
) {
1288 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): "
1289 "failed=%x.\n", ha
->host_no
, rval
);)
1292 DEBUG11(printk("qla2x00_get_port_database(%ld): done.\n",
1300 * qla2x00_get_firmware_state
1301 * Get adapter firmware state.
1304 * ha = adapter block pointer.
1305 * dptr = pointer for firmware state.
1306 * TARGET_QUEUE_LOCK must be released.
1307 * ADAPTER_STATE_LOCK must be released.
1310 * qla2x00 local function return status code.
1316 qla2x00_get_firmware_state(scsi_qla_host_t
*ha
, uint16_t *dptr
)
1320 mbx_cmd_t
*mcp
= &mc
;
1322 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1325 mcp
->mb
[0] = MBC_GET_FIRMWARE_STATE
;
1326 mcp
->out_mb
= MBX_0
;
1327 mcp
->in_mb
= MBX_2
|MBX_1
|MBX_0
;
1330 rval
= qla2x00_mailbox_command(ha
, mcp
);
1332 /* Return firmware state. */
1335 if (rval
!= QLA_SUCCESS
) {
1337 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1338 "failed=%x.\n", ha
->host_no
, rval
);)
1341 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1349 * qla2x00_get_port_name
1350 * Issue get port name mailbox command.
1351 * Returned name is in big endian format.
1354 * ha = adapter block pointer.
1355 * loop_id = loop ID of device.
1356 * name = pointer for name.
1357 * TARGET_QUEUE_LOCK must be released.
1358 * ADAPTER_STATE_LOCK must be released.
1361 * qla2x00 local function return status code.
1367 qla2x00_get_port_name(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t *name
,
1372 mbx_cmd_t
*mcp
= &mc
;
1374 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1377 mcp
->mb
[0] = MBC_GET_PORT_NAME
;
1378 mcp
->out_mb
= MBX_1
|MBX_0
;
1379 if (HAS_EXTENDED_IDS(ha
)) {
1380 mcp
->mb
[1] = loop_id
;
1382 mcp
->out_mb
|= MBX_10
;
1384 mcp
->mb
[1] = loop_id
<< 8 | opt
;
1387 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1390 rval
= qla2x00_mailbox_command(ha
, mcp
);
1392 if (rval
!= QLA_SUCCESS
) {
1394 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1395 ha
->host_no
, rval
);)
1398 /* This function returns name in big endian. */
1399 name
[0] = LSB(mcp
->mb
[2]);
1400 name
[1] = MSB(mcp
->mb
[2]);
1401 name
[2] = LSB(mcp
->mb
[3]);
1402 name
[3] = MSB(mcp
->mb
[3]);
1403 name
[4] = LSB(mcp
->mb
[6]);
1404 name
[5] = MSB(mcp
->mb
[6]);
1405 name
[6] = LSB(mcp
->mb
[7]);
1406 name
[7] = MSB(mcp
->mb
[7]);
1409 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1418 * Issue LIP reset mailbox command.
1421 * ha = adapter block pointer.
1422 * TARGET_QUEUE_LOCK must be released.
1423 * ADAPTER_STATE_LOCK must be released.
1426 * qla2x00 local function return status code.
1432 qla2x00_lip_reset(scsi_qla_host_t
*ha
)
1436 mbx_cmd_t
*mcp
= &mc
;
1438 DEBUG11(printk("qla2x00_lip_reset(%ld): entered.\n",
1441 mcp
->mb
[0] = MBC_LIP_RESET
;
1442 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1443 if (HAS_EXTENDED_IDS(ha
)) {
1444 mcp
->mb
[1] = 0x00ff;
1446 mcp
->out_mb
|= MBX_10
;
1448 mcp
->mb
[1] = 0xff00;
1450 mcp
->mb
[2] = ha
->loop_reset_delay
;
1456 rval
= qla2x00_mailbox_command(ha
, mcp
);
1458 if (rval
!= QLA_SUCCESS
) {
1460 DEBUG2_3_11(printk("qla2x00_lip_reset(%ld): failed=%x.\n",
1461 ha
->host_no
, rval
);)
1464 DEBUG11(printk("qla2x00_lip_reset(%ld): done.\n", ha
->host_no
);)
1475 * ha = adapter block pointer.
1476 * sns = pointer for command.
1477 * cmd_size = command size.
1478 * buf_size = response/command size.
1479 * TARGET_QUEUE_LOCK must be released.
1480 * ADAPTER_STATE_LOCK must be released.
1483 * qla2x00 local function return status code.
1489 qla2x00_send_sns(scsi_qla_host_t
*ha
, dma_addr_t sns_phys_address
,
1490 uint16_t cmd_size
, size_t buf_size
)
1494 mbx_cmd_t
*mcp
= &mc
;
1496 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1499 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1500 "tov=%d.\n", ha
->retry_count
, ha
->login_timeout
, mcp
->tov
);)
1502 mcp
->mb
[0] = MBC_SEND_SNS_COMMAND
;
1503 mcp
->mb
[1] = cmd_size
;
1504 mcp
->mb
[2] = MSW(sns_phys_address
);
1505 mcp
->mb
[3] = LSW(sns_phys_address
);
1506 mcp
->mb
[6] = MSW(MSD(sns_phys_address
));
1507 mcp
->mb
[7] = LSW(MSD(sns_phys_address
));
1508 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1509 mcp
->in_mb
= MBX_0
|MBX_1
;
1510 mcp
->buf_size
= buf_size
;
1511 mcp
->flags
= MBX_DMA_OUT
|MBX_DMA_IN
;
1512 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1513 rval
= qla2x00_mailbox_command(ha
, mcp
);
1515 if (rval
!= QLA_SUCCESS
) {
1517 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1518 "mb[1]=%x.\n", ha
->host_no
, rval
, mcp
->mb
[0], mcp
->mb
[1]);)
1519 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1520 "mb[1]=%x.\n", ha
->host_no
, rval
, mcp
->mb
[0], mcp
->mb
[1]);)
1523 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha
->host_no
);)
1530 * qla2x00_login_fabric
1531 * Issue login fabric port mailbox command.
1534 * ha = adapter block pointer.
1535 * loop_id = device loop ID.
1536 * domain = device domain.
1537 * area = device area.
1538 * al_pa = device AL_PA.
1539 * status = pointer for return status.
1540 * opt = command options.
1541 * TARGET_QUEUE_LOCK must be released.
1542 * ADAPTER_STATE_LOCK must be released.
1545 * qla2x00 local function return status code.
1551 qla2x00_login_fabric(scsi_qla_host_t
*ha
, uint16_t loop_id
, uint8_t domain
,
1552 uint8_t area
, uint8_t al_pa
, uint16_t *mb
, uint8_t opt
)
1556 mbx_cmd_t
*mcp
= &mc
;
1558 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha
->host_no
);)
1560 mcp
->mb
[0] = MBC_LOGIN_FABRIC_PORT
;
1561 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1562 if (HAS_EXTENDED_IDS(ha
)) {
1563 mcp
->mb
[1] = loop_id
;
1565 mcp
->out_mb
|= MBX_10
;
1567 mcp
->mb
[1] = (loop_id
<< 8) | opt
;
1569 mcp
->mb
[2] = domain
;
1570 mcp
->mb
[3] = area
<< 8 | al_pa
;
1572 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_2
|MBX_1
|MBX_0
;
1573 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1575 rval
= qla2x00_mailbox_command(ha
, mcp
);
1577 /* Return mailbox statuses. */
1586 if (rval
!= QLA_SUCCESS
) {
1587 /* RLU tmp code: need to change main mailbox_command function to
1588 * return ok even when the mailbox completion value is not
1589 * SUCCESS. The caller needs to be responsible to interpret
1590 * the return values of this mailbox command if we're not
1591 * to change too much of the existing code.
1593 if (mcp
->mb
[0] == 0x4001 || mcp
->mb
[0] == 0x4002 ||
1594 mcp
->mb
[0] == 0x4003 || mcp
->mb
[0] == 0x4005 ||
1595 mcp
->mb
[0] == 0x4006)
1599 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1600 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha
->host_no
, rval
,
1601 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[2]);)
1604 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1612 * qla2x00_login_local_device
1613 * Issue login loop port mailbox command.
1616 * ha = adapter block pointer.
1617 * loop_id = device loop ID.
1618 * opt = command options.
1621 * Return status code.
1628 qla2x00_login_local_device(scsi_qla_host_t
*ha
, uint16_t loop_id
,
1629 uint16_t *mb_ret
, uint8_t opt
)
1633 mbx_cmd_t
*mcp
= &mc
;
1635 DEBUG3(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
);)
1637 mcp
->mb
[0] = MBC_LOGIN_LOOP_PORT
;
1638 if (HAS_EXTENDED_IDS(ha
))
1639 mcp
->mb
[1] = loop_id
;
1641 mcp
->mb
[1] = loop_id
<< 8;
1643 mcp
->out_mb
= MBX_2
|MBX_1
|MBX_0
;
1644 mcp
->in_mb
= MBX_7
|MBX_6
|MBX_1
|MBX_0
;
1645 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1647 rval
= qla2x00_mailbox_command(ha
, mcp
);
1649 /* Return mailbox statuses. */
1650 if (mb_ret
!= NULL
) {
1651 mb_ret
[0] = mcp
->mb
[0];
1652 mb_ret
[1] = mcp
->mb
[1];
1653 mb_ret
[6] = mcp
->mb
[6];
1654 mb_ret
[7] = mcp
->mb
[7];
1657 if (rval
!= QLA_SUCCESS
) {
1658 /* AV tmp code: need to change main mailbox_command function to
1659 * return ok even when the mailbox completion value is not
1660 * SUCCESS. The caller needs to be responsible to interpret
1661 * the return values of this mailbox command if we're not
1662 * to change too much of the existing code.
1664 if (mcp
->mb
[0] == 0x4005 || mcp
->mb
[0] == 0x4006)
1667 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1668 "mb[6]=%x mb[7]=%x.\n", __func__
, ha
->host_no
, rval
,
1669 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[6], mcp
->mb
[7]);)
1670 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1671 "mb[6]=%x mb[7]=%x.\n", __func__
, ha
->host_no
, rval
,
1672 mcp
->mb
[0], mcp
->mb
[1], mcp
->mb
[6], mcp
->mb
[7]);)
1675 DEBUG3(printk("%s(%ld): done.\n", __func__
, ha
->host_no
);)
1682 * qla2x00_fabric_logout
1683 * Issue logout fabric port mailbox command.
1686 * ha = adapter block pointer.
1687 * loop_id = device loop ID.
1688 * TARGET_QUEUE_LOCK must be released.
1689 * ADAPTER_STATE_LOCK must be released.
1692 * qla2x00 local function return status code.
1698 qla2x00_fabric_logout(scsi_qla_host_t
*ha
, uint16_t loop_id
)
1702 mbx_cmd_t
*mcp
= &mc
;
1704 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1707 mcp
->mb
[0] = MBC_LOGOUT_FABRIC_PORT
;
1708 mcp
->out_mb
= MBX_1
|MBX_0
;
1709 if (HAS_EXTENDED_IDS(ha
)) {
1710 mcp
->mb
[1] = loop_id
;
1712 mcp
->out_mb
|= MBX_10
;
1714 mcp
->mb
[1] = loop_id
<< 8;
1717 mcp
->in_mb
= MBX_1
|MBX_0
;
1720 rval
= qla2x00_mailbox_command(ha
, mcp
);
1722 if (rval
!= QLA_SUCCESS
) {
1724 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1725 "mbx1=%x.\n", ha
->host_no
, rval
, mcp
->mb
[1]);)
1728 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1736 * qla2x00_full_login_lip
1737 * Issue full login LIP mailbox command.
1740 * ha = adapter block pointer.
1741 * TARGET_QUEUE_LOCK must be released.
1742 * ADAPTER_STATE_LOCK must be released.
1745 * qla2x00 local function return status code.
1751 qla2x00_full_login_lip(scsi_qla_host_t
*ha
)
1755 mbx_cmd_t
*mcp
= &mc
;
1757 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1760 mcp
->mb
[0] = MBC_LIP_FULL_LOGIN
;
1764 mcp
->out_mb
= MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1768 rval
= qla2x00_mailbox_command(ha
, mcp
);
1770 if (rval
!= QLA_SUCCESS
) {
1772 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1773 ha
->instance
, rval
);)
1776 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1784 * qla2x00_get_id_list
1787 * ha = adapter block pointer.
1790 * qla2x00 local function return status code.
1796 qla2x00_get_id_list(scsi_qla_host_t
*ha
, void *id_list
, dma_addr_t id_list_dma
,
1801 mbx_cmd_t
*mcp
= &mc
;
1803 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1806 if (id_list
== NULL
)
1807 return QLA_FUNCTION_FAILED
;
1809 mcp
->mb
[0] = MBC_GET_ID_LIST
;
1810 mcp
->mb
[1] = MSW(id_list_dma
);
1811 mcp
->mb
[2] = LSW(id_list_dma
);
1812 mcp
->mb
[3] = MSW(MSD(id_list_dma
));
1813 mcp
->mb
[6] = LSW(MSD(id_list_dma
));
1814 mcp
->out_mb
= MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1815 mcp
->in_mb
= MBX_1
|MBX_0
;
1818 rval
= qla2x00_mailbox_command(ha
, mcp
);
1820 if (rval
!= QLA_SUCCESS
) {
1822 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1823 ha
->host_no
, rval
);)
1825 *entries
= mcp
->mb
[1];
1826 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1834 * qla2x00_get_resource_cnts
1835 * Get current firmware resource counts.
1838 * ha = adapter block pointer.
1841 * qla2x00 local function return status code.
1847 qla2x00_get_resource_cnts(scsi_qla_host_t
*ha
, uint16_t *cur_xchg_cnt
,
1848 uint16_t *orig_xchg_cnt
, uint16_t *cur_iocb_cnt
, uint16_t *orig_iocb_cnt
)
1852 mbx_cmd_t
*mcp
= &mc
;
1854 DEBUG11(printk("%s(%ld): entered.\n", __func__
, ha
->host_no
));
1856 mcp
->mb
[0] = MBC_GET_RESOURCE_COUNTS
;
1857 mcp
->out_mb
= MBX_0
;
1858 mcp
->in_mb
= MBX_10
|MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_1
|MBX_0
;
1861 rval
= qla2x00_mailbox_command(ha
, mcp
);
1863 if (rval
!= QLA_SUCCESS
) {
1865 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__
,
1866 ha
->host_no
, mcp
->mb
[0]);)
1868 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1869 "mb7=%x mb10=%x.\n", __func__
, ha
->host_no
,
1870 mcp
->mb
[1], mcp
->mb
[2], mcp
->mb
[3], mcp
->mb
[6], mcp
->mb
[7],
1874 *cur_xchg_cnt
= mcp
->mb
[3];
1876 *orig_xchg_cnt
= mcp
->mb
[6];
1878 *cur_iocb_cnt
= mcp
->mb
[7];
1880 *orig_iocb_cnt
= mcp
->mb
[10];
1886 #if defined(QL_DEBUG_LEVEL_3)
1888 * qla2x00_get_fcal_position_map
1889 * Get FCAL (LILP) position map using mailbox command
1892 * ha = adapter state pointer.
1893 * pos_map = buffer pointer (can be NULL).
1896 * qla2x00 local function return status code.
1902 qla2x00_get_fcal_position_map(scsi_qla_host_t
*ha
, char *pos_map
)
1906 mbx_cmd_t
*mcp
= &mc
;
1908 dma_addr_t pmap_dma
;
1910 pmap
= dma_pool_alloc(ha
->s_dma_pool
, GFP_ATOMIC
, &pmap_dma
);
1912 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1913 __func__
, ha
->host_no
));
1914 return QLA_MEMORY_ALLOC_FAILED
;
1916 memset(pmap
, 0, FCAL_MAP_SIZE
);
1918 mcp
->mb
[0] = MBC_GET_FC_AL_POSITION_MAP
;
1919 mcp
->mb
[2] = MSW(pmap_dma
);
1920 mcp
->mb
[3] = LSW(pmap_dma
);
1921 mcp
->mb
[6] = MSW(MSD(pmap_dma
));
1922 mcp
->mb
[7] = LSW(MSD(pmap_dma
));
1923 mcp
->out_mb
= MBX_7
|MBX_6
|MBX_3
|MBX_2
|MBX_0
;
1924 mcp
->in_mb
= MBX_1
|MBX_0
;
1925 mcp
->buf_size
= FCAL_MAP_SIZE
;
1926 mcp
->flags
= MBX_DMA_IN
;
1927 mcp
->tov
= (ha
->login_timeout
* 2) + (ha
->login_timeout
/ 2);
1928 rval
= qla2x00_mailbox_command(ha
, mcp
);
1930 if (rval
== QLA_SUCCESS
) {
1931 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
1932 "size (%x)\n", __func__
, ha
->host_no
, mcp
->mb
[0],
1933 mcp
->mb
[1], (unsigned)pmap
[0]));
1934 DEBUG11(qla2x00_dump_buffer(pmap
, pmap
[0] + 1));
1937 memcpy(pos_map
, pmap
, FCAL_MAP_SIZE
);
1939 dma_pool_free(ha
->s_dma_pool
, pmap
, pmap_dma
);
1941 if (rval
!= QLA_SUCCESS
) {
1942 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__
,
1943 ha
->host_no
, rval
));
1945 DEBUG11(printk("%s(%ld): done.\n", __func__
, ha
->host_no
));