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.
26 qla2x00_mbx_sem_timeout(unsigned long data)
28 struct semaphore *sem_ptr = (struct semaphore *)data;
30 DEBUG11(printk("qla2x00_sem_timeout: entered.\n");)
32 if (sem_ptr != NULL) {
36 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)
40 * qla2x00_mailbox_command
41 * Issue mailbox command and waits for completion.
44 * ha = adapter block pointer.
45 * mcp = driver internal mbx struct pointer.
48 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
51 * 0 : QLA_SUCCESS = cmd performed success
52 * 1 : QLA_FUNCTION_FAILED (error encountered)
53 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
59 qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
62 unsigned long flags = 0;
63 device_reg_t *reg = ha->iobase;
64 struct timer_list tmp_intr_timer;
65 uint8_t abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
66 uint8_t io_lock_on = ha->flags.init_done;
68 uint16_t *iptr, *optr;
71 unsigned long mbx_flags = 0;
72 unsigned long wait_time;
76 DEBUG11(printk("qla2x00_mailbox_command(%ld): entered.\n",
79 * Wait for active mailbox commands to finish by waiting at most
80 * tov seconds. This is to serialize actual issuing of mailbox cmds
81 * during non ISP abort time.
84 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
85 /* Timeout occurred. Return error. */
86 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): cmd "
87 "access timeout. Exiting.\n", ha->host_no);)
88 return QLA_FUNCTION_TIMEOUT;
92 ha->flags.mbox_busy = TRUE;
93 /* Save mailbox command for debug */
96 /* Try to get mailbox register access */
98 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
100 DEBUG11(printk("scsi%d: prepare to issue mbox cmd=0x%x.\n",
101 (int)ha->host_no, mcp->mb[0]);)
103 spin_lock_irqsave(&ha->hardware_lock, flags);
105 /* Load mailbox registers. */
106 optr = (uint16_t *)MAILBOX_REG(ha, reg, 0);
109 command = mcp->mb[0];
110 mboxes = mcp->out_mb;
112 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
113 if (IS_QLA2200(ha) && cnt == 8)
114 optr = (uint16_t *)MAILBOX_REG(ha, reg, 8);
116 WRT_REG_WORD(optr, *iptr);
123 #if defined(QL_DEBUG_LEVEL_1)
124 printk("qla2x00_mailbox_command: Loaded MBX registers "
125 "(displayed in bytes) = \n");
126 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
128 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
130 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
132 printk("qla2x00_mailbox_command: I/O address = %lx.\n",
134 qla2x00_dump_regs(ha);
137 /* Issue set host interrupt command to send cmd out. */
138 ha->flags.mbox_int = FALSE;
139 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
141 /* Unlock mbx registers and wait for interrupt */
143 DEBUG11(printk("qla2x00_mailbox_command: going to unlock irq & "
144 "waiting for interrupt. jiffies=%lx.\n", jiffies);)
146 /* Wait for mbx cmd completion until timeout */
148 if (!abort_active && io_lock_on) {
149 /* sleep on completion semaphore */
150 DEBUG11(printk("qla2x00_mailbox_command(%ld): "
151 "INTERRUPT MODE. Initializing timer.\n",
154 init_timer(&tmp_intr_timer);
155 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
156 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
157 tmp_intr_timer.function =
158 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
160 DEBUG11(printk("qla2x00_mailbox_command(%ld): "
161 "Adding timer.\n", ha->host_no);)
162 add_timer(&tmp_intr_timer);
164 DEBUG11(printk("qla2x00_mailbox_command: going to "
165 "unlock & sleep. time=0x%lx.\n", jiffies);)
167 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
169 WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT);
170 spin_unlock_irqrestore(&ha->hardware_lock, flags);
173 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
175 /* Wait for either the timer to expire
176 * or the mbox completion interrupt
178 down(&ha->mbx_intr_sem);
180 DEBUG11(printk("qla2x00_mailbox_command:"
182 "time=0x%lx\n", jiffies);)
183 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
185 /* delete the timer */
186 del_timer(&tmp_intr_timer);
189 DEBUG3_11(printk("qla2x00_mailbox_command(%ld): cmd=%x "
190 "POLLING MODE.\n", ha->host_no, command);)
192 WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT);
193 spin_unlock_irqrestore(&ha->hardware_lock, flags);
195 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
197 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
198 while (!ha->flags.mbox_int) {
199 if (time_after(jiffies, wait_time))
202 /* Check for pending interrupts. */
205 udelay(10); /* v4.27 */
210 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
212 /* Check whether we timed out */
213 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 = FALSE;
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 = FALSE;
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 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
283 if (ha->dpc_wait && !ha->dpc_active)
286 } else if (!abort_active) {
288 /* call abort directly since we are in the DPC thread */
289 DEBUG(printk("qla2x00_mailbox_command(%ld): timeout "
290 "calling abort_isp\n", ha->host_no);)
291 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): "
292 "timeout calling abort_isp\n", ha->host_no);)
294 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
295 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
296 if (qla2x00_abort_isp(ha)) {
297 /* failed. retry later. */
298 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
300 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
302 DEBUG(printk("qla2x00_mailbox_command: finished "
304 DEBUG2_3_11(printk("qla2x00_mailbox_command: finished "
309 /* Allow next mbx cmd to come in. */
311 up(&ha->mbx_cmd_sem);
314 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): **** FAILED. "
315 "mbx0=%x, mbx1=%x, mbx2=%x, cmd=%x ****\n",
316 ha->host_no, mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
318 DEBUG11(printk("qla2x00_mailbox_command(%ld): done.\n",
322 DEBUG11(printk("qla2x00_mailbox_command(%ld): exiting.\n",
330 * Load adapter RAM using DMA.
333 * ha = adapter block pointer.
336 * qla2x00 local function return status code.
342 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
343 uint16_t risc_code_size)
347 mbx_cmd_t *mcp = &mc;
353 DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
356 req_len = risc_code_size;
360 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
363 /* Load first segment */
364 mcp->mb[0] = MBC_LOAD_RISC_RAM;
365 mcp->mb[1] = risc_addr;
366 mcp->mb[2] = MSW(req_dma);
367 mcp->mb[3] = LSW(req_dma);
368 mcp->mb[4] = (uint16_t)req_len;
369 mcp->mb[6] = MSW(MSD(req_dma));
370 mcp->mb[7] = LSW(MSD(req_dma));
371 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
375 rval = qla2x00_mailbox_command(ha, mcp);
377 /* Load second segment - if necessary */
378 if (normalized && (rval == QLA_SUCCESS)) {
379 mcp->mb[0] = MBC_LOAD_RISC_RAM;
380 mcp->mb[1] = risc_addr + (uint16_t)req_len;
381 mcp->mb[2] = MSW(nml_dma);
382 mcp->mb[3] = LSW(nml_dma);
383 mcp->mb[4] = (uint16_t)nml_len;
384 mcp->mb[6] = MSW(MSD(nml_dma));
385 mcp->mb[7] = LSW(MSD(nml_dma));
386 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
390 rval = qla2x00_mailbox_command(ha, mcp);
393 if (rval == QLA_SUCCESS) {
395 DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
398 DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
399 "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
405 * qla2x00_load_ram_ext
406 * Load adapter extended RAM using DMA.
409 * ha = adapter block pointer.
412 * qla2x00 local function return status code.
418 qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
419 uint32_t risc_addr, uint16_t risc_code_size)
423 mbx_cmd_t *mcp = &mc;
429 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
431 req_len = risc_code_size;
435 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
438 /* Load first segment */
439 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
440 mcp->mb[1] = LSW(risc_addr);
441 mcp->mb[2] = MSW(req_dma);
442 mcp->mb[3] = LSW(req_dma);
443 mcp->mb[4] = (uint16_t)req_len;
444 mcp->mb[6] = MSW(MSD(req_dma));
445 mcp->mb[7] = LSW(MSD(req_dma));
446 mcp->mb[8] = MSW(risc_addr);
447 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
451 rval = qla2x00_mailbox_command(ha, mcp);
453 /* Load second segment - if necessary */
454 if (normalized && (rval == QLA_SUCCESS)) {
455 risc_addr += req_len;
456 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
457 mcp->mb[1] = LSW(risc_addr);
458 mcp->mb[2] = MSW(nml_dma);
459 mcp->mb[3] = LSW(nml_dma);
460 mcp->mb[4] = (uint16_t)nml_len;
461 mcp->mb[6] = MSW(MSD(nml_dma));
462 mcp->mb[7] = LSW(MSD(nml_dma));
463 mcp->mb[8] = MSW(risc_addr);
464 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
468 rval = qla2x00_mailbox_command(ha, mcp);
471 if (rval != QLA_SUCCESS) {
473 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n",
474 __func__, ha->host_no, rval, mcp->mb[0]));
477 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
485 * Start adapter firmware.
488 * ha = adapter block pointer.
489 * TARGET_QUEUE_LOCK must be released.
490 * ADAPTER_STATE_LOCK must be released.
493 * qla2x00 local function return status code.
499 qla2x00_execute_fw(scsi_qla_host_t *ha)
503 mbx_cmd_t *mcp = &mc;
505 DEBUG11(printk("qla2x00_execute_fw(%ld): entered.\n", ha->host_no);)
507 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
508 mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart;
509 mcp->out_mb = MBX_1|MBX_0;
510 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
512 mcp->out_mb |= MBX_2;
518 rval = qla2x00_mailbox_command(ha, mcp);
520 DEBUG11(printk("qla2x00_execute_fw(%ld): done.\n", ha->host_no);)
526 * qla2x00_get_fw_version
527 * Get firmware version.
530 * ha: adapter state pointer.
531 * major: pointer for major number.
532 * minor: pointer for minor number.
533 * subminor: pointer for subminor number.
536 * qla2x00 local function return status code.
542 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
543 uint16_t *subminor, uint16_t *attributes)
547 mbx_cmd_t *mcp = &mc;
549 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
551 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
553 mcp->in_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
556 rval = qla2x00_mailbox_command(ha, mcp);
558 /* Return mailbox data. */
561 *subminor = mcp->mb[3];
562 *attributes = mcp->mb[6];
564 if (rval != QLA_SUCCESS) {
566 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
570 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
575 * qla2x00_get_fw_options
576 * Set firmware options.
579 * ha = adapter block pointer.
580 * fwopt = pointer for firmware options.
583 * qla2x00 local function return status code.
589 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
593 mbx_cmd_t *mcp = &mc;
595 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
597 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
599 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
602 rval = qla2x00_mailbox_command(ha, mcp);
604 if (rval != QLA_SUCCESS) {
606 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
609 fwopts[1] = mcp->mb[1];
610 fwopts[2] = mcp->mb[2];
611 fwopts[3] = mcp->mb[3];
613 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
621 * qla2x00_set_fw_options
622 * Set firmware options.
625 * ha = adapter block pointer.
626 * fwopt = pointer for firmware options.
629 * qla2x00 local function return status code.
635 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
639 mbx_cmd_t *mcp = &mc;
641 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
643 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
644 mcp->mb[1] = fwopts[1];
645 mcp->mb[2] = fwopts[2];
646 mcp->mb[3] = fwopts[3];
647 mcp->mb[10] = fwopts[10];
648 mcp->mb[11] = fwopts[11];
649 mcp->mb[12] = 0; /* Undocumented, but used */
650 mcp->out_mb = MBX_12|MBX_11|MBX_10|MBX_3|MBX_2|MBX_1|MBX_0;
654 rval = qla2x00_mailbox_command(ha, mcp);
656 if (rval != QLA_SUCCESS) {
658 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
662 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
669 * qla2x00_read_ram_word
672 * ha = adapter block pointer.
675 * qla2x00 local function return status code.
681 qla2x00_read_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t *data)
685 mbx_cmd_t *mcp = &mc;
687 DEBUG11(printk("qla2x00_read_ram_word(%ld): entered.\n", ha->host_no);)
689 mcp->mb[0] = MBC_READ_RAM_WORD;
691 mcp->out_mb = MBX_1|MBX_0;
692 mcp->in_mb = MBX_0|MBX_2;
695 rval = qla2x00_mailbox_command(ha, mcp);
697 if (rval != QLA_SUCCESS) {
699 DEBUG2_3_11(printk("qla2x00_read_ram_word(%ld): failed=%x.\n",
703 DEBUG11(printk("qla2x00_read_ram_word(%ld): done.\n",
711 * qla2x00_write_ram_word
714 * ha = adapter block pointer.
717 * qla2x00 local function return status code.
723 qla2x00_write_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t data)
727 mbx_cmd_t *mcp = &mc;
729 DEBUG11(printk("qla2x00_write_ram_word(%ld): entered.\n",
732 mcp->mb[0] = MBC_WRITE_RAM_WORD;
735 mcp->out_mb = MBX_2|MBX_1|MBX_0;
739 rval = qla2x00_mailbox_command(ha, mcp);
741 if (rval != QLA_SUCCESS) {
743 DEBUG2_3_11(printk("qla2x00_write_ram_word(%ld): failed=%x.\n",
747 DEBUG11(printk("qla2x00_write_ram_word(%ld): done.\n",
755 * qla2x00_write_ram_word_ext
758 * ha = adapter block pointer.
761 * qla2x00 local function return status code.
767 qla2x00_write_ram_word_ext(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
771 mbx_cmd_t *mcp = &mc;
773 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
775 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
776 mcp->mb[1] = LSW(addr);
778 mcp->mb[8] = MSW(addr);
779 mcp->out_mb = MBX_8|MBX_2|MBX_1|MBX_0;
783 rval = qla2x00_mailbox_command(ha, mcp);
785 if (rval != QLA_SUCCESS) {
787 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
791 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
798 * qla2x00_mbx_reg_test
799 * Mailbox register wrap test.
802 * ha = adapter block pointer.
803 * TARGET_QUEUE_LOCK must be released.
804 * ADAPTER_STATE_LOCK must be released.
807 * qla2x00 local function return status code.
813 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
817 mbx_cmd_t *mcp = &mc;
819 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
821 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
829 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
830 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
833 rval = qla2x00_mailbox_command(ha, mcp);
835 if (rval == QLA_SUCCESS) {
836 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
837 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
838 rval = QLA_FUNCTION_FAILED;
839 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
840 mcp->mb[7] != 0x2525)
841 rval = QLA_FUNCTION_FAILED;
844 if (rval != QLA_SUCCESS) {
846 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
850 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
858 * qla2x00_verify_checksum
859 * Verify firmware checksum.
862 * ha = adapter block pointer.
863 * TARGET_QUEUE_LOCK must be released.
864 * ADAPTER_STATE_LOCK must be released.
867 * qla2x00 local function return status code.
873 qla2x00_verify_checksum(scsi_qla_host_t *ha)
877 mbx_cmd_t *mcp = &mc;
879 DEBUG11(printk("qla2x00_verify_checksum(%ld): entered.\n",
882 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
883 mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart;
884 mcp->out_mb = MBX_1|MBX_0;
885 mcp->in_mb = MBX_2|MBX_0;
888 rval = qla2x00_mailbox_command(ha, mcp);
890 if (rval != QLA_SUCCESS) {
892 DEBUG2_3_11(printk("qla2x00_verify_checksum(%ld): failed=%x.\n",
896 DEBUG11(printk("qla2x00_verify_checksum(%ld): done.\n",
905 * Issue IOCB using mailbox command
908 * ha = adapter state pointer.
909 * buffer = buffer pointer.
910 * phys_addr = physical address of buffer.
911 * size = size of buffer.
912 * TARGET_QUEUE_LOCK must be released.
913 * ADAPTER_STATE_LOCK must be released.
916 * qla2x00 local function return status code.
922 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
927 mbx_cmd_t *mcp = &mc;
929 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
931 mcp->mb[2] = MSW(phys_addr);
932 mcp->mb[3] = LSW(phys_addr);
933 mcp->mb[6] = MSW(MSD(phys_addr));
934 mcp->mb[7] = LSW(MSD(phys_addr));
935 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
936 mcp->in_mb = MBX_2|MBX_0;
939 rval = qla2x00_mailbox_command(ha, mcp);
941 if (rval != QLA_SUCCESS) {
943 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
945 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
955 * qla2x00_abort_command
956 * Abort command aborts a specified IOCB.
959 * ha = adapter block pointer.
960 * sp = SB structure pointer.
963 * qla2x00 local function return status code.
969 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
971 unsigned long flags = 0;
976 mbx_cmd_t *mcp = &mc;
978 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
980 fcport = sp->fclun->fcport;
982 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
983 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
984 /* v2.19.8 Ignore abort request if port is down */
988 spin_lock_irqsave(&ha->hardware_lock, flags);
989 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
990 if (ha->outstanding_cmds[handle] == sp)
993 spin_unlock_irqrestore(&ha->hardware_lock, flags);
995 if (handle == MAX_OUTSTANDING_COMMANDS) {
996 /* command not found */
997 return QLA_FUNCTION_FAILED;
1000 mcp->mb[0] = MBC_ABORT_COMMAND;
1001 if (HAS_EXTENDED_IDS(ha))
1002 mcp->mb[1] = fcport->loop_id;
1004 mcp->mb[1] = fcport->loop_id << 8;
1005 mcp->mb[2] = (uint16_t)handle;
1006 mcp->mb[3] = (uint16_t)(handle >> 16);
1007 mcp->mb[6] = (uint16_t)sp->fclun->lun;
1008 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1012 rval = qla2x00_mailbox_command(ha, mcp);
1014 if (rval != QLA_SUCCESS) {
1015 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
1016 ha->host_no, rval);)
1018 sp->flags |= SRB_ABORT_PENDING;
1019 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
1027 * qla2x00_abort_device
1030 * ha = adapter block pointer.
1031 * loop_id = FC loop ID
1035 * qla2x00 local function return status code.
1041 qla2x00_abort_device(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun)
1045 mbx_cmd_t *mcp = &mc;
1047 DEBUG11(printk("qla2x00_abort_device(%ld): entered.\n", ha->host_no);)
1049 mcp->mb[0] = MBC_ABORT_DEVICE;
1050 if (HAS_EXTENDED_IDS(ha))
1051 mcp->mb[1] = loop_id;
1053 mcp->mb[1] = loop_id << 8;
1055 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1059 rval = qla2x00_mailbox_command(ha, mcp);
1061 /* Issue marker command. */
1062 qla2x00_marker(ha, loop_id, lun, MK_SYNC_ID_LUN);
1064 if (rval != QLA_SUCCESS) {
1065 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1066 if (ha->dpc_wait && !ha->dpc_active)
1068 DEBUG2_3_11(printk("qla2x00_abort_device(%ld): failed=%x.\n",
1069 ha->host_no, rval);)
1072 DEBUG11(printk("qla2x00_abort_device(%ld): done.\n",
1081 * qla2x00_abort_target
1082 * Issue abort target mailbox command.
1085 * ha = adapter block pointer.
1088 * qla2x00 local function return status code.
1094 qla2x00_abort_target(fc_port_t *fcport)
1098 mbx_cmd_t *mcp = &mc;
1100 DEBUG11(printk("qla2x00_abort_target(%ld): entered.\n",
1101 fcport->ha->host_no);)
1103 if (fcport == NULL) {
1104 /* no target to abort */
1108 mcp->mb[0] = MBC_ABORT_TARGET;
1109 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1110 if (HAS_EXTENDED_IDS(fcport->ha)) {
1111 mcp->mb[1] = fcport->loop_id;
1113 mcp->out_mb |= MBX_10;
1115 mcp->mb[1] = fcport->loop_id << 8;
1117 mcp->mb[2] = fcport->ha->loop_reset_delay;
1122 rval = qla2x00_mailbox_command(fcport->ha, mcp);
1124 /* Issue marker command. */
1125 fcport->ha->marker_needed = 1;
1127 if (rval != QLA_SUCCESS) {
1128 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
1129 fcport->ha->host_no, rval);)
1132 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
1133 fcport->ha->host_no);)
1141 * qla2x00_target_reset
1142 * Issue target reset mailbox command.
1145 * ha = adapter block pointer.
1146 * TARGET_QUEUE_LOCK must be released.
1147 * ADAPTER_STATE_LOCK must be released.
1150 * qla2x00 local function return status code.
1156 qla2x00_target_reset(scsi_qla_host_t *ha, uint16_t b, uint16_t t)
1160 mbx_cmd_t *mcp = &mc;
1163 DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
1166 if (tgt->fcport == NULL) {
1167 /* no target to abort */
1170 if (atomic_read(&tgt->fcport->state) != FCS_ONLINE) {
1171 /* target not online */
1175 mcp->mb[0] = MBC_TARGET_RESET;
1176 if (HAS_EXTENDED_IDS(ha))
1177 mcp->mb[1] = tgt->fcport->loop_id;
1179 mcp->mb[1] = tgt->fcport->loop_id << 8;
1180 mcp->mb[2] = ha->loop_reset_delay;
1181 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1185 rval = qla2x00_mailbox_command(ha, mcp);
1187 if (rval != QLA_SUCCESS) {
1189 DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
1190 ha->host_no, rval);)
1193 DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
1201 * qla2x00_get_adapter_id
1202 * Get adapter ID and topology.
1205 * ha = adapter block pointer.
1206 * id = pointer for loop ID.
1207 * al_pa = pointer for AL_PA.
1208 * area = pointer for area.
1209 * domain = pointer for domain.
1210 * top = pointer for topology.
1211 * TARGET_QUEUE_LOCK must be released.
1212 * ADAPTER_STATE_LOCK must be released.
1215 * qla2x00 local function return status code.
1221 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
1222 uint8_t *area, uint8_t *domain, uint16_t *top)
1226 mbx_cmd_t *mcp = &mc;
1228 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
1231 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
1232 mcp->out_mb = MBX_0;
1233 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1236 rval = qla2x00_mailbox_command(ha, mcp);
1240 *al_pa = LSB(mcp->mb[2]);
1241 *area = MSB(mcp->mb[2]);
1242 *domain = LSB(mcp->mb[3]);
1245 if (rval != QLA_SUCCESS) {
1247 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
1248 ha->host_no, rval);)
1251 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
1259 * qla2x00_get_retry_cnt
1260 * Get current firmware login retry count and delay.
1263 * ha = adapter block pointer.
1264 * retry_cnt = pointer to login retry count.
1265 * tov = pointer to login timeout value.
1268 * qla2x00 local function return status code.
1274 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
1280 mbx_cmd_t *mcp = &mc;
1282 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1285 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1286 mcp->out_mb = MBX_0;
1287 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1290 rval = qla2x00_mailbox_command(ha, mcp);
1292 if (rval != QLA_SUCCESS) {
1294 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1295 ha->host_no, mcp->mb[0]);)
1297 /* Convert returned data and check our values. */
1298 *r_a_tov = mcp->mb[3] / 2;
1299 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1300 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1301 /* Update to the larger values */
1302 *retry_cnt = (uint8_t)mcp->mb[1];
1306 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1307 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
1314 * qla2x00_init_firmware
1315 * Initialize adapter firmware.
1318 * ha = adapter block pointer.
1319 * dptr = Initialization control block pointer.
1320 * size = size of initialization control block.
1321 * TARGET_QUEUE_LOCK must be released.
1322 * ADAPTER_STATE_LOCK must be released.
1325 * qla2x00 local function return status code.
1331 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1335 mbx_cmd_t *mcp = &mc;
1337 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1340 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1341 mcp->mb[2] = MSW(ha->init_cb_dma);
1342 mcp->mb[3] = LSW(ha->init_cb_dma);
1345 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1346 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1347 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1348 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1349 mcp->buf_size = size;
1350 mcp->flags = MBX_DMA_OUT;
1352 rval = qla2x00_mailbox_command(ha, mcp);
1354 if (rval != QLA_SUCCESS) {
1356 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1358 ha->host_no, rval, mcp->mb[0]);)
1361 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1369 * qla2x00_get_port_database
1370 * Issue normal/enhanced get port database mailbox command
1371 * and copy device name as necessary.
1374 * ha = adapter state pointer.
1375 * dev = structure pointer.
1376 * opt = enhanced cmd option byte.
1379 * qla2x00 local function return status code.
1385 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1389 mbx_cmd_t *mcp = &mc;
1390 port_database_t *pd;
1393 DEBUG11(printk("qla2x00_get_port_database(%ld): entered.\n",
1396 pd = pci_alloc_consistent(ha->pdev, PORT_DATABASE_SIZE, &pd_dma);
1398 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): **** "
1399 "Mem Alloc Failed ****", ha->host_no);)
1400 return QLA_MEMORY_ALLOC_FAILED;
1402 memset(pd, 0, PORT_DATABASE_SIZE);
1405 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1407 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1408 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1409 if (HAS_EXTENDED_IDS(ha)) {
1410 mcp->mb[1] = fcport->loop_id;
1412 mcp->out_mb |= MBX_10;
1414 mcp->mb[1] = fcport->loop_id << 8 | opt;
1416 mcp->mb[2] = MSW(pd_dma);
1417 mcp->mb[3] = LSW(pd_dma);
1418 mcp->mb[6] = MSW(MSD(pd_dma));
1419 mcp->mb[7] = LSW(MSD(pd_dma));
1422 mcp->buf_size = PORT_DATABASE_SIZE;
1423 mcp->flags = MBX_DMA_IN;
1424 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1425 rval = qla2x00_mailbox_command(ha, mcp);
1427 if (rval == QLA_SUCCESS) {
1428 /* Names are little-endian. */
1429 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1430 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1432 /* Get port_id of device. */
1433 fcport->d_id.b.al_pa = pd->port_id[2];
1434 fcport->d_id.b.area = pd->port_id[3];
1435 fcport->d_id.b.domain = pd->port_id[0];
1436 fcport->d_id.b.rsvd_1 = 0;
1438 /* Check for device require authentication. */
1439 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1440 (fcport->flags &= ~FCF_AUTH_REQ);
1442 /* If not target must be initiator or unknown type. */
1443 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) {
1444 fcport->port_type = FCT_INITIATOR;
1446 fcport->port_type = FCT_TARGET;
1448 /* Check for logged in. */
1449 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1450 pd->slave_state != PD_STATE_PORT_LOGGED_IN)
1451 rval = QLA_FUNCTION_FAILED;
1455 pci_free_consistent(ha->pdev, PORT_DATABASE_SIZE, pd, pd_dma);
1457 if (rval != QLA_SUCCESS) {
1459 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): "
1460 "failed=%x.\n", ha->host_no, rval);)
1463 DEBUG11(printk("qla2x00_get_port_database(%ld): done.\n",
1471 * qla2x00_get_firmware_state
1472 * Get adapter firmware state.
1475 * ha = adapter block pointer.
1476 * dptr = pointer for firmware state.
1477 * TARGET_QUEUE_LOCK must be released.
1478 * ADAPTER_STATE_LOCK must be released.
1481 * qla2x00 local function return status code.
1487 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1491 mbx_cmd_t *mcp = &mc;
1493 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1496 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1497 mcp->out_mb = MBX_0;
1498 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1501 rval = qla2x00_mailbox_command(ha, mcp);
1503 /* Return firmware state. */
1506 if (rval != QLA_SUCCESS) {
1508 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1509 "failed=%x.\n", ha->host_no, rval);)
1512 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1520 * qla2x00_get_port_name
1521 * Issue get port name mailbox command.
1522 * Returned name is in big endian format.
1525 * ha = adapter block pointer.
1526 * loop_id = loop ID of device.
1527 * name = pointer for name.
1528 * TARGET_QUEUE_LOCK must be released.
1529 * ADAPTER_STATE_LOCK must be released.
1532 * qla2x00 local function return status code.
1538 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1543 mbx_cmd_t *mcp = &mc;
1545 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1548 mcp->mb[0] = MBC_GET_PORT_NAME;
1549 mcp->out_mb = MBX_1|MBX_0;
1550 if (HAS_EXTENDED_IDS(ha)) {
1551 mcp->mb[1] = loop_id;
1553 mcp->out_mb |= MBX_10;
1555 mcp->mb[1] = loop_id << 8 | opt;
1558 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1561 rval = qla2x00_mailbox_command(ha, mcp);
1563 if (rval != QLA_SUCCESS) {
1565 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1566 ha->host_no, rval);)
1569 /* This function returns name in big endian. */
1570 name[0] = LSB(mcp->mb[2]);
1571 name[1] = MSB(mcp->mb[2]);
1572 name[2] = LSB(mcp->mb[3]);
1573 name[3] = MSB(mcp->mb[3]);
1574 name[4] = LSB(mcp->mb[6]);
1575 name[5] = MSB(mcp->mb[6]);
1576 name[6] = LSB(mcp->mb[7]);
1577 name[7] = MSB(mcp->mb[7]);
1580 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1588 * qla2x00_get_link_status
1591 * ha = adapter block pointer.
1592 * loop_id = device loop ID.
1593 * ret_buf = pointer to link status return buffer.
1597 * BIT_0 = mem alloc error.
1598 * BIT_1 = mailbox error.
1601 qla2x00_get_link_status(scsi_qla_host_t *ha, uint8_t loop_id,
1602 link_stat_t *ret_buf, uint16_t *status)
1606 mbx_cmd_t *mcp = &mc;
1607 link_stat_t *stat_buf;
1608 dma_addr_t phys_address = 0;
1611 DEBUG11(printk("qla2x00_get_link_status(%ld): entered.\n",
1614 stat_buf = pci_alloc_consistent(ha->pdev, sizeof(link_stat_t),
1616 if (stat_buf == NULL) {
1617 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): Failed to "
1618 "allocate memory.\n", ha->host_no));
1621 memset(stat_buf, 0, sizeof(link_stat_t));
1623 mcp->mb[0] = MBC_GET_LINK_STATUS;
1624 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1625 if (HAS_EXTENDED_IDS(ha)) {
1626 mcp->mb[1] = loop_id;
1628 mcp->out_mb |= MBX_10;
1630 mcp->mb[1] = loop_id << 8;
1632 mcp->mb[2] = MSW(phys_address);
1633 mcp->mb[3] = LSW(phys_address);
1634 mcp->mb[6] = MSW(MSD(phys_address));
1635 mcp->mb[7] = LSW(MSD(phys_address));
1639 mcp->flags = IOCTL_CMD;
1640 rval = qla2x00_mailbox_command(ha, mcp);
1642 if (rval == QLA_SUCCESS) {
1643 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
1644 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): cmd "
1645 "failed. mbx0=%x.\n", ha->host_no, mcp->mb[0]);)
1646 status[0] = mcp->mb[0];
1649 /* copy over data -- firmware data is LE. */
1650 ret_buf->link_fail_cnt =
1651 le32_to_cpu(stat_buf->link_fail_cnt);
1652 ret_buf->loss_sync_cnt =
1653 le32_to_cpu(stat_buf->loss_sync_cnt);
1654 ret_buf->loss_sig_cnt =
1655 le32_to_cpu(stat_buf->loss_sig_cnt);
1656 ret_buf->prim_seq_err_cnt =
1657 le32_to_cpu(stat_buf->prim_seq_err_cnt);
1658 ret_buf->inval_xmit_word_cnt =
1659 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
1660 ret_buf->inval_crc_cnt =
1661 le32_to_cpu(stat_buf->inval_crc_cnt);
1663 DEBUG11(printk("qla2x00_get_link_status(%ld): stat "
1664 "dump: fail_cnt=%d loss_sync=%d loss_sig=%d "
1665 "seq_err=%d inval_xmt_word=%d inval_crc=%d.\n",
1667 stat_buf->link_fail_cnt, stat_buf->loss_sync_cnt,
1668 stat_buf->loss_sig_cnt, stat_buf->prim_seq_err_cnt,
1669 stat_buf->inval_xmit_word_cnt,
1670 stat_buf->inval_crc_cnt);)
1674 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): failed=%x.\n",
1675 ha->host_no, rval);)
1679 pci_free_consistent(ha->pdev, sizeof(link_stat_t), stat_buf,
1687 * Issue LIP reset mailbox command.
1690 * ha = adapter block pointer.
1691 * TARGET_QUEUE_LOCK must be released.
1692 * ADAPTER_STATE_LOCK must be released.
1695 * qla2x00 local function return status code.
1701 qla2x00_lip_reset(scsi_qla_host_t *ha)
1705 mbx_cmd_t *mcp = &mc;
1707 DEBUG11(printk("qla2x00_lip_reset(%ld): entered.\n",
1710 mcp->mb[0] = MBC_LIP_RESET;
1711 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1712 if (HAS_EXTENDED_IDS(ha)) {
1713 mcp->mb[1] = 0x00ff;
1715 mcp->out_mb |= MBX_10;
1717 mcp->mb[1] = 0xff00;
1719 mcp->mb[2] = ha->loop_reset_delay;
1725 rval = qla2x00_mailbox_command(ha, mcp);
1727 if (rval != QLA_SUCCESS) {
1729 DEBUG2_3_11(printk("qla2x00_lip_reset(%ld): failed=%x.\n",
1730 ha->host_no, rval);)
1733 DEBUG11(printk("qla2x00_lip_reset(%ld): done.\n", ha->host_no);)
1744 * ha = adapter block pointer.
1745 * sns = pointer for command.
1746 * cmd_size = command size.
1747 * buf_size = response/command size.
1748 * TARGET_QUEUE_LOCK must be released.
1749 * ADAPTER_STATE_LOCK must be released.
1752 * qla2x00 local function return status code.
1758 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1759 uint16_t cmd_size, size_t buf_size)
1763 mbx_cmd_t *mcp = &mc;
1765 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1768 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1769 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1771 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1772 mcp->mb[1] = cmd_size;
1773 mcp->mb[2] = MSW(sns_phys_address);
1774 mcp->mb[3] = LSW(sns_phys_address);
1775 mcp->mb[6] = MSW(MSD(sns_phys_address));
1776 mcp->mb[7] = LSW(MSD(sns_phys_address));
1777 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1778 mcp->in_mb = MBX_0|MBX_1;
1779 mcp->buf_size = buf_size;
1780 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1781 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1782 rval = qla2x00_mailbox_command(ha, mcp);
1784 if (rval != QLA_SUCCESS) {
1786 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1787 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1788 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1789 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1792 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1799 * qla2x00_login_fabric
1800 * Issue login fabric port mailbox command.
1803 * ha = adapter block pointer.
1804 * loop_id = device loop ID.
1805 * domain = device domain.
1806 * area = device area.
1807 * al_pa = device AL_PA.
1808 * status = pointer for return status.
1809 * opt = command options.
1810 * TARGET_QUEUE_LOCK must be released.
1811 * ADAPTER_STATE_LOCK must be released.
1814 * qla2x00 local function return status code.
1820 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1821 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1825 mbx_cmd_t *mcp = &mc;
1827 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
1829 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1830 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1831 if (HAS_EXTENDED_IDS(ha)) {
1832 mcp->mb[1] = loop_id;
1834 mcp->out_mb |= MBX_10;
1836 mcp->mb[1] = (loop_id << 8) | opt;
1838 mcp->mb[2] = domain;
1839 mcp->mb[3] = area << 8 | al_pa;
1841 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1842 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1844 rval = qla2x00_mailbox_command(ha, mcp);
1846 /* Return mailbox statuses. */
1855 if (rval != QLA_SUCCESS) {
1856 /* RLU tmp code: need to change main mailbox_command function to
1857 * return ok even when the mailbox completion value is not
1858 * SUCCESS. The caller needs to be responsible to interpret
1859 * the return values of this mailbox command if we're not
1860 * to change too much of the existing code.
1862 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1863 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1864 mcp->mb[0] == 0x4006)
1868 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1869 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1870 mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
1873 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1881 * qla2x00_login_local_device
1882 * Issue login loop port mailbox command.
1885 * ha = adapter block pointer.
1886 * loop_id = device loop ID.
1887 * opt = command options.
1890 * Return status code.
1897 qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
1898 uint16_t *mb_ret, uint8_t opt)
1902 mbx_cmd_t *mcp = &mc;
1904 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1906 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1907 if (HAS_EXTENDED_IDS(ha))
1908 mcp->mb[1] = loop_id;
1910 mcp->mb[1] = loop_id << 8;
1912 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1913 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1914 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1916 rval = qla2x00_mailbox_command(ha, mcp);
1918 /* Return mailbox statuses. */
1919 if (mb_ret != NULL) {
1920 mb_ret[0] = mcp->mb[0];
1921 mb_ret[1] = mcp->mb[1];
1922 mb_ret[6] = mcp->mb[6];
1923 mb_ret[7] = mcp->mb[7];
1926 if (rval != QLA_SUCCESS) {
1927 /* AV tmp code: need to change main mailbox_command function to
1928 * return ok even when the mailbox completion value is not
1929 * SUCCESS. The caller needs to be responsible to interpret
1930 * the return values of this mailbox command if we're not
1931 * to change too much of the existing code.
1933 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1936 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1937 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1938 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1939 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1940 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1941 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1944 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1951 * qla2x00_fabric_logout
1952 * Issue logout fabric port mailbox command.
1955 * ha = adapter block pointer.
1956 * loop_id = device loop ID.
1957 * TARGET_QUEUE_LOCK must be released.
1958 * ADAPTER_STATE_LOCK must be released.
1961 * qla2x00 local function return status code.
1967 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id)
1971 mbx_cmd_t *mcp = &mc;
1973 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1976 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1977 mcp->out_mb = MBX_1|MBX_0;
1978 if (HAS_EXTENDED_IDS(ha)) {
1979 mcp->mb[1] = loop_id;
1981 mcp->out_mb |= MBX_10;
1983 mcp->mb[1] = loop_id << 8;
1986 mcp->in_mb = MBX_1|MBX_0;
1989 rval = qla2x00_mailbox_command(ha, mcp);
1991 if (rval != QLA_SUCCESS) {
1993 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1994 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
1997 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
2005 * qla2x00_full_login_lip
2006 * Issue full login LIP mailbox command.
2009 * ha = adapter block pointer.
2010 * TARGET_QUEUE_LOCK must be released.
2011 * ADAPTER_STATE_LOCK must be released.
2014 * qla2x00 local function return status code.
2020 qla2x00_full_login_lip(scsi_qla_host_t *ha)
2024 mbx_cmd_t *mcp = &mc;
2026 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
2029 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2033 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2037 rval = qla2x00_mailbox_command(ha, mcp);
2039 if (rval != QLA_SUCCESS) {
2041 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
2042 ha->instance, rval);)
2045 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
2053 * qla2x00_get_id_list
2056 * ha = adapter block pointer.
2059 * qla2x00 local function return status code.
2065 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
2070 mbx_cmd_t *mcp = &mc;
2072 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
2075 if (id_list == NULL)
2076 return QLA_FUNCTION_FAILED;
2078 mcp->mb[0] = MBC_GET_ID_LIST;
2079 mcp->mb[1] = MSW(id_list_dma);
2080 mcp->mb[2] = LSW(id_list_dma);
2081 mcp->mb[3] = MSW(MSD(id_list_dma));
2082 mcp->mb[6] = LSW(MSD(id_list_dma));
2083 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2084 mcp->in_mb = MBX_1|MBX_0;
2087 rval = qla2x00_mailbox_command(ha, mcp);
2089 if (rval != QLA_SUCCESS) {
2091 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
2092 ha->host_no, rval);)
2094 *entries = mcp->mb[1];
2095 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2104 * Issue lun reset mailbox command.
2107 * ha = adapter block pointer.
2108 * loop_id = device loop ID.
2109 * lun = lun to be reset.
2110 * TARGET_QUEUE_LOCK must be released.
2111 * ADAPTER_STATE_LOCK must be released.
2114 * qla2x00 local function return status code.
2120 qla2x00_lun_reset(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun)
2124 mbx_cmd_t *mcp = &mc;
2126 mcp->mb[0] = MBC_LUN_RESET;
2127 if (HAS_EXTENDED_IDS(ha))
2128 mcp->mb[1] = loop_id;
2130 mcp->mb[1] = loop_id << 8;
2132 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2136 rval = qla2x00_mailbox_command(ha, mcp);
2138 if (rval != QLA_SUCCESS) {
2140 printk(KERN_WARNING "qla2x00_lun_reset(%d): failed = %d",
2141 (int)ha->instance, rval);
2150 * qla2x00_send_rnid_mbx
2151 * Issue RNID ELS using mailbox command
2154 * ha = adapter state pointer.
2155 * loop_id = loop ID of the target device.
2156 * data_fmt = currently supports only 0xDF.
2157 * buffer = buffer pointer.
2158 * buf_size = size of buffer.
2159 * mb_reg = pointer to return mailbox registers.
2162 * qla2x00 local function return status code.
2168 qla2x00_send_rnid_mbx(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t data_fmt,
2169 dma_addr_t buf_phys_addr, size_t buf_size, uint16_t *mb_reg)
2173 mbx_cmd_t *mcp = &mc;
2175 DEBUG11(printk("qla2x00_send_rnid_mbx(%ld): entered.\n",
2178 mcp->mb[0] = MBC_SEND_RNID_ELS;
2179 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2180 if (HAS_EXTENDED_IDS(ha)) {
2181 mcp->mb[1] = loop_id;
2182 mcp->mb[10] = data_fmt;
2183 mcp->out_mb |= MBX_10;
2185 mcp->mb[1] = (loop_id << 8) | data_fmt;
2187 mcp->mb[2] = MSW(buf_phys_addr);
2188 mcp->mb[3] = LSW(buf_phys_addr);
2189 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2190 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2192 mcp->in_mb = MBX_1|MBX_0;
2193 mcp->buf_size = buf_size;
2194 mcp->flags = MBX_DMA_IN;
2196 rval = qla2x00_mailbox_command(ha, mcp);
2198 if (rval != QLA_SUCCESS) {
2199 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2201 DEBUG2_3_11(printk("qla2x00_send_rnid_mbx(%ld): failed=%x "
2203 ha->host_no, mcp->mb[0], mcp->mb[1]);)
2206 DEBUG11(printk("qla2x00_send_rnid_mbx(%ld): done.\n",
2214 * qla2x00_set_rnid_params_mbx
2215 * Set RNID parameters using mailbox command
2218 * ha = adapter state pointer.
2219 * buffer = buffer pointer.
2220 * buf_size = size of buffer.
2221 * mb_reg = pointer to return mailbox registers.
2224 * qla2x00 local function return status code.
2230 qla2x00_set_rnid_params_mbx(scsi_qla_host_t *ha, dma_addr_t buf_phys_addr,
2231 size_t buf_size, uint16_t *mb_reg)
2235 mbx_cmd_t *mcp = &mc;
2237 DEBUG11(printk("qla2x00_set_rnid_params_mbx(%ld): entered.\n",
2240 mcp->mb[0] = MBC_SET_RNID_PARAMS;
2242 mcp->mb[2] = MSW(buf_phys_addr);
2243 mcp->mb[3] = LSW(buf_phys_addr);
2244 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2245 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2246 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2247 mcp->in_mb = MBX_1|MBX_0;
2248 mcp->buf_size = buf_size;
2249 mcp->flags = MBX_DMA_OUT;
2251 rval = qla2x00_mailbox_command(ha, mcp);
2253 if (rval != QLA_SUCCESS) {
2254 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2256 DEBUG2_3_11(printk("qla2x00_set_rnid_params_mbx(%ld): "
2257 "failed=%x mb[1]=%x.\n", ha->host_no, mcp->mb[0],
2261 DEBUG11(printk("qla2x00_set_rnid_params_mbx(%ld): done.\n",
2269 * qla2x00_get_rnid_params_mbx
2270 * Get RNID parameters using mailbox command
2273 * ha = adapter state pointer.
2274 * buffer = buffer pointer.
2275 * buf_size = size of buffer.
2276 * mb_reg = pointer to return mailbox registers.
2279 * qla2x00 local function return status code.
2285 qla2x00_get_rnid_params_mbx(scsi_qla_host_t *ha, dma_addr_t buf_phys_addr,
2286 size_t buf_size, uint16_t *mb_reg)
2290 mbx_cmd_t *mcp = &mc;
2292 DEBUG11(printk("qla2x00_get_rnid_params_mbx(%ld): entered.\n",
2295 mcp->mb[0] = MBC_GET_RNID_PARAMS;
2297 mcp->mb[2] = MSW(buf_phys_addr);
2298 mcp->mb[3] = LSW(buf_phys_addr);
2299 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2300 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2301 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2302 mcp->in_mb = MBX_1|MBX_0;
2303 mcp->buf_size = buf_size;
2304 mcp->flags = MBX_DMA_IN;
2306 rval = qla2x00_mailbox_command(ha, mcp);
2308 if (rval != QLA_SUCCESS) {
2309 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2311 DEBUG2_3_11(printk("qla2x00_get_rnid_params_mbx(%ld): "
2312 "failed=%x mb[1]=%x.\n", ha->host_no, mcp->mb[0],
2316 DEBUG11(printk("qla2x00_get_rnid_params_mbx(%ld): done.\n",
2324 * qla2x00_get_resource_cnts
2325 * Get current firmware resource counts.
2328 * ha = adapter block pointer.
2331 * qla2x00 local function return status code.
2337 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
2338 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
2342 mbx_cmd_t *mcp = &mc;
2344 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2346 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2347 mcp->out_mb = MBX_0;
2348 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2351 rval = qla2x00_mailbox_command(ha, mcp);
2353 if (rval != QLA_SUCCESS) {
2355 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2356 ha->host_no, mcp->mb[0]);)
2358 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2359 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
2360 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
2364 *cur_xchg_cnt = mcp->mb[3];
2366 *orig_xchg_cnt = mcp->mb[6];
2368 *cur_iocb_cnt = mcp->mb[7];
2370 *orig_iocb_cnt = mcp->mb[10];
2376 #if defined(QL_DEBUG_LEVEL_3)
2378 * qla2x00_get_fcal_position_map
2379 * Get FCAL (LILP) position map using mailbox command
2382 * ha = adapter state pointer.
2383 * pos_map = buffer pointer (can be NULL).
2386 * qla2x00 local function return status code.
2392 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
2396 mbx_cmd_t *mcp = &mc;
2398 dma_addr_t pmap_dma;
2400 pmap = pci_alloc_consistent(ha->pdev, FCAL_MAP_SIZE, &pmap_dma);
2402 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2403 __func__, ha->host_no));
2404 return QLA_MEMORY_ALLOC_FAILED;
2406 memset(pmap, 0, FCAL_MAP_SIZE);
2408 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2409 mcp->mb[2] = MSW(pmap_dma);
2410 mcp->mb[3] = LSW(pmap_dma);
2411 mcp->mb[6] = MSW(MSD(pmap_dma));
2412 mcp->mb[7] = LSW(MSD(pmap_dma));
2413 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2414 mcp->in_mb = MBX_1|MBX_0;
2415 mcp->buf_size = FCAL_MAP_SIZE;
2416 mcp->flags = MBX_DMA_IN;
2417 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2418 rval = qla2x00_mailbox_command(ha, mcp);
2420 if (rval == QLA_SUCCESS) {
2421 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2422 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2423 mcp->mb[1], (unsigned)pmap[0]));
2424 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2427 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2429 pci_free_consistent(ha->pdev, FCAL_MAP_SIZE, pmap, pmap_dma);
2431 if (rval != QLA_SUCCESS) {
2432 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2433 ha->host_no, rval));
2435 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));