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 *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;
66 uint16_t *iptr, *optr;
69 unsigned long mbx_flags = 0;
70 unsigned long wait_time;
74 DEBUG11(printk("qla2x00_mailbox_command(%ld): entered.\n",
77 * Wait for active mailbox commands to finish by waiting at most
78 * tov seconds. This is to serialize actual issuing of mailbox cmds
79 * during non ISP abort time.
82 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
83 /* Timeout occurred. Return error. */
84 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): cmd "
85 "access timeout. Exiting.\n", ha->host_no);)
86 return QLA_FUNCTION_TIMEOUT;
90 ha->flags.mbox_busy = 1;
91 /* Save mailbox command for debug */
94 /* Try to get mailbox register access */
96 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
98 DEBUG11(printk("scsi%d: prepare to issue mbox cmd=0x%x.\n",
99 (int)ha->host_no, mcp->mb[0]);)
101 spin_lock_irqsave(&ha->hardware_lock, flags);
103 /* Load mailbox registers. */
104 optr = (uint16_t *)MAILBOX_REG(ha, reg, 0);
107 command = mcp->mb[0];
108 mboxes = mcp->out_mb;
110 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
111 if (IS_QLA2200(ha) && cnt == 8)
112 optr = (uint16_t *)MAILBOX_REG(ha, reg, 8);
114 WRT_REG_WORD(optr, *iptr);
121 #if defined(QL_DEBUG_LEVEL_1)
122 printk("qla2x00_mailbox_command: Loaded MBX registers "
123 "(displayed in bytes) = \n");
124 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
126 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
128 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
130 printk("qla2x00_mailbox_command: I/O address = %lx.\n",
132 qla2x00_dump_regs(ha);
135 /* Issue set host interrupt command to send cmd out. */
136 ha->flags.mbox_int = 0;
137 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
139 /* Unlock mbx registers and wait for interrupt */
141 DEBUG11(printk("qla2x00_mailbox_command: going to unlock irq & "
142 "waiting for interrupt. jiffies=%lx.\n", jiffies);)
144 /* Wait for mbx cmd completion until timeout */
146 if (!abort_active && io_lock_on) {
147 /* sleep on completion semaphore */
148 DEBUG11(printk("qla2x00_mailbox_command(%ld): "
149 "INTERRUPT MODE. Initializing timer.\n",
152 init_timer(&tmp_intr_timer);
153 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
154 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
155 tmp_intr_timer.function =
156 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
158 DEBUG11(printk("qla2x00_mailbox_command(%ld): "
159 "Adding timer.\n", ha->host_no);)
160 add_timer(&tmp_intr_timer);
162 DEBUG11(printk("qla2x00_mailbox_command: going to "
163 "unlock & sleep. time=0x%lx.\n", jiffies);)
165 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
167 WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT);
168 spin_unlock_irqrestore(&ha->hardware_lock, flags);
171 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
173 /* Wait for either the timer to expire
174 * or the mbox completion interrupt
176 down(&ha->mbx_intr_sem);
178 DEBUG11(printk("qla2x00_mailbox_command:"
180 "time=0x%lx\n", jiffies);)
181 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
183 /* delete the timer */
184 del_timer(&tmp_intr_timer);
187 DEBUG3_11(printk("qla2x00_mailbox_command(%ld): cmd=%x "
188 "POLLING MODE.\n", ha->host_no, command);)
190 WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT);
191 spin_unlock_irqrestore(&ha->hardware_lock, flags);
193 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
195 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
196 while (!ha->flags.mbox_int) {
197 if (time_after(jiffies, wait_time))
200 /* Check for pending interrupts. */
203 udelay(10); /* v4.27 */
208 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
210 /* Check whether we timed out */
211 if (ha->flags.mbox_int) {
213 DEBUG3_11(printk("qla2x00_mailbox_cmd: cmd %x completed.\n",
216 /* Got interrupt. Clear the flag. */
217 ha->flags.mbox_int = 0;
218 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
220 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) {
221 qla2x00_stats.mboxerr++;
222 rval = QLA_FUNCTION_FAILED;
225 /* Load return mailbox registers. */
227 iptr = (uint16_t *)&ha->mailbox_out[0];
229 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
239 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
240 defined(QL_DEBUG_LEVEL_11)
241 printk("qla2x00_mailbox_command(%ld): **** MB Command Timeout "
242 "for cmd %x ****\n", ha->host_no, command);
243 printk("qla2x00_mailbox_command: icontrol=%x jiffies=%lx\n",
244 RD_REG_WORD(®->ictrl), jiffies);
245 printk("qla2x00_mailbox_command: *** mailbox[0] = 0x%x ***\n",
247 qla2x00_dump_regs(ha);
250 qla2x00_stats.mboxtout++;
251 ha->total_mbx_timeout++;
252 rval = QLA_FUNCTION_TIMEOUT;
256 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
258 ha->flags.mbox_busy = 0;
264 DEBUG11(printk("qla2x00_mailbox_cmd: checking for additional "
265 "resp interrupt.\n");)
267 /* polling mode for non isp_abort commands. */
271 if (rval == QLA_FUNCTION_TIMEOUT) {
272 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
273 /* not in dpc. schedule it for dpc to take over. */
274 DEBUG(printk("qla2x00_mailbox_command(%ld): timeout "
275 "schedule isp_abort_needed.\n",
277 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): "
278 "timeout schedule isp_abort_needed.\n",
280 qla_printk(KERN_WARNING, ha,
281 "Mailbox command timeout occured. Scheduling ISP "
283 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
284 if (ha->dpc_wait && !ha->dpc_active)
287 } else if (!abort_active) {
289 /* call abort directly since we are in the DPC thread */
290 DEBUG(printk("qla2x00_mailbox_command(%ld): timeout "
291 "calling abort_isp\n", ha->host_no);)
292 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): "
293 "timeout calling abort_isp\n", ha->host_no);)
294 qla_printk(KERN_WARNING, ha,
295 "Mailbox command timeout occured. Issuing ISP "
298 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
299 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
300 if (qla2x00_abort_isp(ha)) {
301 /* failed. retry later. */
302 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
304 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
306 DEBUG(printk("qla2x00_mailbox_command: finished "
308 DEBUG2_3_11(printk("qla2x00_mailbox_command: finished "
313 /* Allow next mbx cmd to come in. */
315 up(&ha->mbx_cmd_sem);
318 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): **** FAILED. "
319 "mbx0=%x, mbx1=%x, mbx2=%x, cmd=%x ****\n",
320 ha->host_no, mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
322 DEBUG11(printk("qla2x00_mailbox_command(%ld): done.\n",
326 DEBUG11(printk("qla2x00_mailbox_command(%ld): exiting.\n",
334 * Load adapter RAM using DMA.
337 * ha = adapter block pointer.
340 * qla2x00 local function return status code.
346 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
347 uint16_t risc_code_size)
351 mbx_cmd_t *mcp = &mc;
357 DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
360 req_len = risc_code_size;
364 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
367 /* Load first segment */
368 mcp->mb[0] = MBC_LOAD_RISC_RAM;
369 mcp->mb[1] = risc_addr;
370 mcp->mb[2] = MSW(req_dma);
371 mcp->mb[3] = LSW(req_dma);
372 mcp->mb[4] = (uint16_t)req_len;
373 mcp->mb[6] = MSW(MSD(req_dma));
374 mcp->mb[7] = LSW(MSD(req_dma));
375 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
379 rval = qla2x00_mailbox_command(ha, mcp);
381 /* Load second segment - if necessary */
382 if (normalized && (rval == QLA_SUCCESS)) {
383 mcp->mb[0] = MBC_LOAD_RISC_RAM;
384 mcp->mb[1] = risc_addr + (uint16_t)req_len;
385 mcp->mb[2] = MSW(nml_dma);
386 mcp->mb[3] = LSW(nml_dma);
387 mcp->mb[4] = (uint16_t)nml_len;
388 mcp->mb[6] = MSW(MSD(nml_dma));
389 mcp->mb[7] = LSW(MSD(nml_dma));
390 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
394 rval = qla2x00_mailbox_command(ha, mcp);
397 if (rval == QLA_SUCCESS) {
399 DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
402 DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
403 "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
409 * qla2x00_load_ram_ext
410 * Load adapter extended RAM using DMA.
413 * ha = adapter block pointer.
416 * qla2x00 local function return status code.
422 qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
423 uint32_t risc_addr, uint16_t risc_code_size)
427 mbx_cmd_t *mcp = &mc;
433 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
435 req_len = risc_code_size;
439 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
442 /* Load first segment */
443 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
444 mcp->mb[1] = LSW(risc_addr);
445 mcp->mb[2] = MSW(req_dma);
446 mcp->mb[3] = LSW(req_dma);
447 mcp->mb[4] = (uint16_t)req_len;
448 mcp->mb[6] = MSW(MSD(req_dma));
449 mcp->mb[7] = LSW(MSD(req_dma));
450 mcp->mb[8] = MSW(risc_addr);
451 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
455 rval = qla2x00_mailbox_command(ha, mcp);
457 /* Load second segment - if necessary */
458 if (normalized && (rval == QLA_SUCCESS)) {
459 risc_addr += req_len;
460 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
461 mcp->mb[1] = LSW(risc_addr);
462 mcp->mb[2] = MSW(nml_dma);
463 mcp->mb[3] = LSW(nml_dma);
464 mcp->mb[4] = (uint16_t)nml_len;
465 mcp->mb[6] = MSW(MSD(nml_dma));
466 mcp->mb[7] = LSW(MSD(nml_dma));
467 mcp->mb[8] = MSW(risc_addr);
468 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
472 rval = qla2x00_mailbox_command(ha, mcp);
475 if (rval != QLA_SUCCESS) {
477 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n",
478 __func__, ha->host_no, rval, mcp->mb[0]));
481 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
489 * Start adapter firmware.
492 * ha = adapter block pointer.
493 * TARGET_QUEUE_LOCK must be released.
494 * ADAPTER_STATE_LOCK must be released.
497 * qla2x00 local function return status code.
503 qla2x00_execute_fw(scsi_qla_host_t *ha)
507 mbx_cmd_t *mcp = &mc;
509 DEBUG11(printk("qla2x00_execute_fw(%ld): entered.\n", ha->host_no);)
511 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
512 mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart;
513 mcp->out_mb = MBX_1|MBX_0;
514 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
516 mcp->out_mb |= MBX_2;
522 rval = qla2x00_mailbox_command(ha, mcp);
524 DEBUG11(printk("qla2x00_execute_fw(%ld): done.\n", ha->host_no);)
530 * qla2x00_get_fw_version
531 * Get firmware version.
534 * ha: adapter state pointer.
535 * major: pointer for major number.
536 * minor: pointer for minor number.
537 * subminor: pointer for subminor number.
540 * qla2x00 local function return status code.
546 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
547 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
551 mbx_cmd_t *mcp = &mc;
553 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
555 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
557 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
560 rval = qla2x00_mailbox_command(ha, mcp);
562 /* Return mailbox data. */
565 *subminor = mcp->mb[3];
566 *attributes = mcp->mb[6];
567 if (IS_QLA2100(ha) || IS_QLA2200(ha))
568 *memory = 0x1FFFF; /* Defaults to 128KB. */
570 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
572 if (rval != QLA_SUCCESS) {
574 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
578 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
583 * qla2x00_get_fw_options
584 * Set firmware options.
587 * ha = adapter block pointer.
588 * fwopt = pointer for firmware options.
591 * qla2x00 local function return status code.
597 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
601 mbx_cmd_t *mcp = &mc;
603 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
605 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
607 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
610 rval = qla2x00_mailbox_command(ha, mcp);
612 if (rval != QLA_SUCCESS) {
614 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
617 fwopts[1] = mcp->mb[1];
618 fwopts[2] = mcp->mb[2];
619 fwopts[3] = mcp->mb[3];
621 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
629 * qla2x00_set_fw_options
630 * Set firmware options.
633 * ha = adapter block pointer.
634 * fwopt = pointer for firmware options.
637 * qla2x00 local function return status code.
643 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
647 mbx_cmd_t *mcp = &mc;
649 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
651 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
652 mcp->mb[1] = fwopts[1];
653 mcp->mb[2] = fwopts[2];
654 mcp->mb[3] = fwopts[3];
655 mcp->mb[10] = fwopts[10];
656 mcp->mb[11] = fwopts[11];
657 mcp->mb[12] = 0; /* Undocumented, but used */
658 mcp->out_mb = MBX_12|MBX_11|MBX_10|MBX_3|MBX_2|MBX_1|MBX_0;
662 rval = qla2x00_mailbox_command(ha, mcp);
664 if (rval != QLA_SUCCESS) {
666 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
670 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
677 * qla2x00_read_ram_word
680 * ha = adapter block pointer.
683 * qla2x00 local function return status code.
689 qla2x00_read_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t *data)
693 mbx_cmd_t *mcp = &mc;
695 DEBUG11(printk("qla2x00_read_ram_word(%ld): entered.\n", ha->host_no);)
697 mcp->mb[0] = MBC_READ_RAM_WORD;
699 mcp->out_mb = MBX_1|MBX_0;
700 mcp->in_mb = MBX_0|MBX_2;
703 rval = qla2x00_mailbox_command(ha, mcp);
705 if (rval != QLA_SUCCESS) {
707 DEBUG2_3_11(printk("qla2x00_read_ram_word(%ld): failed=%x.\n",
711 DEBUG11(printk("qla2x00_read_ram_word(%ld): done.\n",
719 * qla2x00_write_ram_word
722 * ha = adapter block pointer.
725 * qla2x00 local function return status code.
731 qla2x00_write_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t data)
735 mbx_cmd_t *mcp = &mc;
737 DEBUG11(printk("qla2x00_write_ram_word(%ld): entered.\n",
740 mcp->mb[0] = MBC_WRITE_RAM_WORD;
743 mcp->out_mb = MBX_2|MBX_1|MBX_0;
747 rval = qla2x00_mailbox_command(ha, mcp);
749 if (rval != QLA_SUCCESS) {
751 DEBUG2_3_11(printk("qla2x00_write_ram_word(%ld): failed=%x.\n",
755 DEBUG11(printk("qla2x00_write_ram_word(%ld): done.\n",
763 * qla2x00_write_ram_word_ext
766 * ha = adapter block pointer.
769 * qla2x00 local function return status code.
775 qla2x00_write_ram_word_ext(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
779 mbx_cmd_t *mcp = &mc;
781 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
783 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
784 mcp->mb[1] = LSW(addr);
786 mcp->mb[8] = MSW(addr);
787 mcp->out_mb = MBX_8|MBX_2|MBX_1|MBX_0;
791 rval = qla2x00_mailbox_command(ha, mcp);
793 if (rval != QLA_SUCCESS) {
795 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
799 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
806 * qla2x00_mbx_reg_test
807 * Mailbox register wrap test.
810 * ha = adapter block pointer.
811 * TARGET_QUEUE_LOCK must be released.
812 * ADAPTER_STATE_LOCK must be released.
815 * qla2x00 local function return status code.
821 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
825 mbx_cmd_t *mcp = &mc;
827 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
829 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
837 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
838 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
841 rval = qla2x00_mailbox_command(ha, mcp);
843 if (rval == QLA_SUCCESS) {
844 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
845 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
846 rval = QLA_FUNCTION_FAILED;
847 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
848 mcp->mb[7] != 0x2525)
849 rval = QLA_FUNCTION_FAILED;
852 if (rval != QLA_SUCCESS) {
854 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
858 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
866 * qla2x00_verify_checksum
867 * Verify firmware checksum.
870 * ha = adapter block pointer.
871 * TARGET_QUEUE_LOCK must be released.
872 * ADAPTER_STATE_LOCK must be released.
875 * qla2x00 local function return status code.
881 qla2x00_verify_checksum(scsi_qla_host_t *ha)
885 mbx_cmd_t *mcp = &mc;
887 DEBUG11(printk("qla2x00_verify_checksum(%ld): entered.\n",
890 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
891 mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart;
892 mcp->out_mb = MBX_1|MBX_0;
893 mcp->in_mb = MBX_2|MBX_0;
896 rval = qla2x00_mailbox_command(ha, mcp);
898 if (rval != QLA_SUCCESS) {
900 DEBUG2_3_11(printk("qla2x00_verify_checksum(%ld): failed=%x.\n",
904 DEBUG11(printk("qla2x00_verify_checksum(%ld): done.\n",
913 * Issue IOCB using mailbox command
916 * ha = adapter state pointer.
917 * buffer = buffer pointer.
918 * phys_addr = physical address of buffer.
919 * size = size of buffer.
920 * TARGET_QUEUE_LOCK must be released.
921 * ADAPTER_STATE_LOCK must be released.
924 * qla2x00 local function return status code.
930 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
935 mbx_cmd_t *mcp = &mc;
937 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
939 mcp->mb[2] = MSW(phys_addr);
940 mcp->mb[3] = LSW(phys_addr);
941 mcp->mb[6] = MSW(MSD(phys_addr));
942 mcp->mb[7] = LSW(MSD(phys_addr));
943 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
944 mcp->in_mb = MBX_2|MBX_0;
947 rval = qla2x00_mailbox_command(ha, mcp);
949 if (rval != QLA_SUCCESS) {
951 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
953 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
963 * qla2x00_abort_command
964 * Abort command aborts a specified IOCB.
967 * ha = adapter block pointer.
968 * sp = SB structure pointer.
971 * qla2x00 local function return status code.
977 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
979 unsigned long flags = 0;
984 mbx_cmd_t *mcp = &mc;
986 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
988 fcport = sp->fclun->fcport;
990 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
991 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
995 spin_lock_irqsave(&ha->hardware_lock, flags);
996 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
997 if (ha->outstanding_cmds[handle] == sp)
1000 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1002 if (handle == MAX_OUTSTANDING_COMMANDS) {
1003 /* command not found */
1004 return QLA_FUNCTION_FAILED;
1007 mcp->mb[0] = MBC_ABORT_COMMAND;
1008 if (HAS_EXTENDED_IDS(ha))
1009 mcp->mb[1] = fcport->loop_id;
1011 mcp->mb[1] = fcport->loop_id << 8;
1012 mcp->mb[2] = (uint16_t)handle;
1013 mcp->mb[3] = (uint16_t)(handle >> 16);
1014 mcp->mb[6] = (uint16_t)sp->fclun->lun;
1015 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1019 rval = qla2x00_mailbox_command(ha, mcp);
1021 if (rval != QLA_SUCCESS) {
1022 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
1023 ha->host_no, rval);)
1025 sp->flags |= SRB_ABORT_PENDING;
1026 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
1034 * qla2x00_abort_device
1037 * ha = adapter block pointer.
1038 * loop_id = FC loop ID
1042 * qla2x00 local function return status code.
1048 qla2x00_abort_device(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun)
1052 mbx_cmd_t *mcp = &mc;
1054 DEBUG11(printk("qla2x00_abort_device(%ld): entered.\n", ha->host_no);)
1056 mcp->mb[0] = MBC_ABORT_DEVICE;
1057 if (HAS_EXTENDED_IDS(ha))
1058 mcp->mb[1] = loop_id;
1060 mcp->mb[1] = loop_id << 8;
1062 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1066 rval = qla2x00_mailbox_command(ha, mcp);
1068 /* Issue marker command. */
1069 qla2x00_marker(ha, loop_id, lun, MK_SYNC_ID_LUN);
1071 if (rval != QLA_SUCCESS) {
1072 qla_printk(KERN_WARNING, ha,
1073 "Failed Abort Device Mailbox command. Scheduling ISP "
1075 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1076 if (ha->dpc_wait && !ha->dpc_active)
1078 DEBUG2_3_11(printk("qla2x00_abort_device(%ld): failed=%x.\n",
1079 ha->host_no, rval);)
1082 DEBUG11(printk("qla2x00_abort_device(%ld): done.\n",
1091 * qla2x00_abort_target
1092 * Issue abort target mailbox command.
1095 * ha = adapter block pointer.
1098 * qla2x00 local function return status code.
1104 qla2x00_abort_target(fc_port_t *fcport)
1108 mbx_cmd_t *mcp = &mc;
1110 DEBUG11(printk("qla2x00_abort_target(%ld): entered.\n",
1111 fcport->ha->host_no);)
1113 if (fcport == NULL) {
1114 /* no target to abort */
1118 mcp->mb[0] = MBC_ABORT_TARGET;
1119 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1120 if (HAS_EXTENDED_IDS(fcport->ha)) {
1121 mcp->mb[1] = fcport->loop_id;
1123 mcp->out_mb |= MBX_10;
1125 mcp->mb[1] = fcport->loop_id << 8;
1127 mcp->mb[2] = fcport->ha->loop_reset_delay;
1132 rval = qla2x00_mailbox_command(fcport->ha, mcp);
1134 /* Issue marker command. */
1135 fcport->ha->marker_needed = 1;
1137 if (rval != QLA_SUCCESS) {
1138 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
1139 fcport->ha->host_no, rval);)
1142 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
1143 fcport->ha->host_no);)
1151 * qla2x00_target_reset
1152 * Issue target reset mailbox command.
1155 * ha = adapter block pointer.
1156 * TARGET_QUEUE_LOCK must be released.
1157 * ADAPTER_STATE_LOCK must be released.
1160 * qla2x00 local function return status code.
1166 qla2x00_target_reset(scsi_qla_host_t *ha, uint16_t b, uint16_t t)
1170 mbx_cmd_t *mcp = &mc;
1173 DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
1176 if (tgt->fcport == NULL) {
1177 /* no target to abort */
1180 if (atomic_read(&tgt->fcport->state) != FCS_ONLINE) {
1181 /* target not online */
1185 mcp->mb[0] = MBC_TARGET_RESET;
1186 if (HAS_EXTENDED_IDS(ha))
1187 mcp->mb[1] = tgt->fcport->loop_id;
1189 mcp->mb[1] = tgt->fcport->loop_id << 8;
1190 mcp->mb[2] = ha->loop_reset_delay;
1191 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1195 rval = qla2x00_mailbox_command(ha, mcp);
1197 if (rval != QLA_SUCCESS) {
1199 DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
1200 ha->host_no, rval);)
1203 DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
1211 * qla2x00_get_adapter_id
1212 * Get adapter ID and topology.
1215 * ha = adapter block pointer.
1216 * id = pointer for loop ID.
1217 * al_pa = pointer for AL_PA.
1218 * area = pointer for area.
1219 * domain = pointer for domain.
1220 * top = pointer for topology.
1221 * TARGET_QUEUE_LOCK must be released.
1222 * ADAPTER_STATE_LOCK must be released.
1225 * qla2x00 local function return status code.
1231 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
1232 uint8_t *area, uint8_t *domain, uint16_t *top)
1236 mbx_cmd_t *mcp = &mc;
1238 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
1241 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
1242 mcp->out_mb = MBX_0;
1243 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1246 rval = qla2x00_mailbox_command(ha, mcp);
1250 *al_pa = LSB(mcp->mb[2]);
1251 *area = MSB(mcp->mb[2]);
1252 *domain = LSB(mcp->mb[3]);
1255 if (rval != QLA_SUCCESS) {
1257 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
1258 ha->host_no, rval);)
1261 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
1269 * qla2x00_get_retry_cnt
1270 * Get current firmware login retry count and delay.
1273 * ha = adapter block pointer.
1274 * retry_cnt = pointer to login retry count.
1275 * tov = pointer to login timeout value.
1278 * qla2x00 local function return status code.
1284 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
1290 mbx_cmd_t *mcp = &mc;
1292 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1295 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1296 mcp->out_mb = MBX_0;
1297 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1300 rval = qla2x00_mailbox_command(ha, mcp);
1302 if (rval != QLA_SUCCESS) {
1304 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1305 ha->host_no, mcp->mb[0]);)
1307 /* Convert returned data and check our values. */
1308 *r_a_tov = mcp->mb[3] / 2;
1309 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1310 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1311 /* Update to the larger values */
1312 *retry_cnt = (uint8_t)mcp->mb[1];
1316 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1317 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
1324 * qla2x00_init_firmware
1325 * Initialize adapter firmware.
1328 * ha = adapter block pointer.
1329 * dptr = Initialization control block pointer.
1330 * size = size of initialization control block.
1331 * TARGET_QUEUE_LOCK must be released.
1332 * ADAPTER_STATE_LOCK must be released.
1335 * qla2x00 local function return status code.
1341 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1345 mbx_cmd_t *mcp = &mc;
1347 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1350 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1351 mcp->mb[2] = MSW(ha->init_cb_dma);
1352 mcp->mb[3] = LSW(ha->init_cb_dma);
1355 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1356 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1357 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1358 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1359 mcp->buf_size = size;
1360 mcp->flags = MBX_DMA_OUT;
1362 rval = qla2x00_mailbox_command(ha, mcp);
1364 if (rval != QLA_SUCCESS) {
1366 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1368 ha->host_no, rval, mcp->mb[0]);)
1371 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1379 * qla2x00_get_port_database
1380 * Issue normal/enhanced get port database mailbox command
1381 * and copy device name as necessary.
1384 * ha = adapter state pointer.
1385 * dev = structure pointer.
1386 * opt = enhanced cmd option byte.
1389 * qla2x00 local function return status code.
1395 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1399 mbx_cmd_t *mcp = &mc;
1400 port_database_t *pd;
1403 DEBUG11(printk("qla2x00_get_port_database(%ld): entered.\n",
1406 pd = pci_alloc_consistent(ha->pdev, PORT_DATABASE_SIZE, &pd_dma);
1408 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): **** "
1409 "Mem Alloc Failed ****", ha->host_no);)
1410 return QLA_MEMORY_ALLOC_FAILED;
1412 memset(pd, 0, PORT_DATABASE_SIZE);
1415 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1417 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1418 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1419 if (HAS_EXTENDED_IDS(ha)) {
1420 mcp->mb[1] = fcport->loop_id;
1422 mcp->out_mb |= MBX_10;
1424 mcp->mb[1] = fcport->loop_id << 8 | opt;
1426 mcp->mb[2] = MSW(pd_dma);
1427 mcp->mb[3] = LSW(pd_dma);
1428 mcp->mb[6] = MSW(MSD(pd_dma));
1429 mcp->mb[7] = LSW(MSD(pd_dma));
1432 mcp->buf_size = PORT_DATABASE_SIZE;
1433 mcp->flags = MBX_DMA_IN;
1434 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1435 rval = qla2x00_mailbox_command(ha, mcp);
1436 if (rval != QLA_SUCCESS)
1439 /* Check for logged in state. */
1440 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1441 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1442 rval = QLA_FUNCTION_FAILED;
1446 /* Names are little-endian. */
1447 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1448 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1450 /* Get port_id of device. */
1451 fcport->d_id.b.al_pa = pd->port_id[2];
1452 fcport->d_id.b.area = pd->port_id[3];
1453 fcport->d_id.b.domain = pd->port_id[0];
1454 fcport->d_id.b.rsvd_1 = 0;
1456 /* Check for device require authentication. */
1457 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1458 (fcport->flags &= ~FCF_AUTH_REQ);
1460 /* If not target must be initiator or unknown type. */
1461 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1462 fcport->port_type = FCT_INITIATOR;
1464 fcport->port_type = FCT_TARGET;
1467 pci_free_consistent(ha->pdev, PORT_DATABASE_SIZE, pd, pd_dma);
1469 if (rval != QLA_SUCCESS) {
1471 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): "
1472 "failed=%x.\n", ha->host_no, rval);)
1475 DEBUG11(printk("qla2x00_get_port_database(%ld): done.\n",
1483 * qla2x00_get_firmware_state
1484 * Get adapter firmware state.
1487 * ha = adapter block pointer.
1488 * dptr = pointer for firmware state.
1489 * TARGET_QUEUE_LOCK must be released.
1490 * ADAPTER_STATE_LOCK must be released.
1493 * qla2x00 local function return status code.
1499 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1503 mbx_cmd_t *mcp = &mc;
1505 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1508 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1509 mcp->out_mb = MBX_0;
1510 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1513 rval = qla2x00_mailbox_command(ha, mcp);
1515 /* Return firmware state. */
1518 if (rval != QLA_SUCCESS) {
1520 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1521 "failed=%x.\n", ha->host_no, rval);)
1524 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1532 * qla2x00_get_port_name
1533 * Issue get port name mailbox command.
1534 * Returned name is in big endian format.
1537 * ha = adapter block pointer.
1538 * loop_id = loop ID of device.
1539 * name = pointer for name.
1540 * TARGET_QUEUE_LOCK must be released.
1541 * ADAPTER_STATE_LOCK must be released.
1544 * qla2x00 local function return status code.
1550 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1555 mbx_cmd_t *mcp = &mc;
1557 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1560 mcp->mb[0] = MBC_GET_PORT_NAME;
1561 mcp->out_mb = 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;
1570 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1573 rval = qla2x00_mailbox_command(ha, mcp);
1575 if (rval != QLA_SUCCESS) {
1577 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1578 ha->host_no, rval);)
1581 /* This function returns name in big endian. */
1582 name[0] = LSB(mcp->mb[2]);
1583 name[1] = MSB(mcp->mb[2]);
1584 name[2] = LSB(mcp->mb[3]);
1585 name[3] = MSB(mcp->mb[3]);
1586 name[4] = LSB(mcp->mb[6]);
1587 name[5] = MSB(mcp->mb[6]);
1588 name[6] = LSB(mcp->mb[7]);
1589 name[7] = MSB(mcp->mb[7]);
1592 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1600 * qla2x00_get_link_status
1603 * ha = adapter block pointer.
1604 * loop_id = device loop ID.
1605 * ret_buf = pointer to link status return buffer.
1609 * BIT_0 = mem alloc error.
1610 * BIT_1 = mailbox error.
1613 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
1614 link_stat_t *ret_buf, uint16_t *status)
1618 mbx_cmd_t *mcp = &mc;
1619 link_stat_t *stat_buf;
1620 dma_addr_t phys_address = 0;
1623 DEBUG11(printk("qla2x00_get_link_status(%ld): entered.\n",
1626 stat_buf = pci_alloc_consistent(ha->pdev, sizeof(link_stat_t),
1628 if (stat_buf == NULL) {
1629 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): Failed to "
1630 "allocate memory.\n", ha->host_no));
1633 memset(stat_buf, 0, sizeof(link_stat_t));
1635 mcp->mb[0] = MBC_GET_LINK_STATUS;
1636 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1637 if (HAS_EXTENDED_IDS(ha)) {
1638 mcp->mb[1] = loop_id;
1640 mcp->out_mb |= MBX_10;
1642 mcp->mb[1] = loop_id << 8;
1644 mcp->mb[2] = MSW(phys_address);
1645 mcp->mb[3] = LSW(phys_address);
1646 mcp->mb[6] = MSW(MSD(phys_address));
1647 mcp->mb[7] = LSW(MSD(phys_address));
1651 mcp->flags = IOCTL_CMD;
1652 rval = qla2x00_mailbox_command(ha, mcp);
1654 if (rval == QLA_SUCCESS) {
1655 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
1656 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): cmd "
1657 "failed. mbx0=%x.\n", ha->host_no, mcp->mb[0]);)
1658 status[0] = mcp->mb[0];
1661 /* copy over data -- firmware data is LE. */
1662 ret_buf->link_fail_cnt =
1663 le32_to_cpu(stat_buf->link_fail_cnt);
1664 ret_buf->loss_sync_cnt =
1665 le32_to_cpu(stat_buf->loss_sync_cnt);
1666 ret_buf->loss_sig_cnt =
1667 le32_to_cpu(stat_buf->loss_sig_cnt);
1668 ret_buf->prim_seq_err_cnt =
1669 le32_to_cpu(stat_buf->prim_seq_err_cnt);
1670 ret_buf->inval_xmit_word_cnt =
1671 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
1672 ret_buf->inval_crc_cnt =
1673 le32_to_cpu(stat_buf->inval_crc_cnt);
1675 DEBUG11(printk("qla2x00_get_link_status(%ld): stat "
1676 "dump: fail_cnt=%d loss_sync=%d loss_sig=%d "
1677 "seq_err=%d inval_xmt_word=%d inval_crc=%d.\n",
1679 stat_buf->link_fail_cnt, stat_buf->loss_sync_cnt,
1680 stat_buf->loss_sig_cnt, stat_buf->prim_seq_err_cnt,
1681 stat_buf->inval_xmit_word_cnt,
1682 stat_buf->inval_crc_cnt);)
1686 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): failed=%x.\n",
1687 ha->host_no, rval);)
1691 pci_free_consistent(ha->pdev, sizeof(link_stat_t), stat_buf,
1699 * Issue LIP reset mailbox command.
1702 * ha = adapter block pointer.
1703 * TARGET_QUEUE_LOCK must be released.
1704 * ADAPTER_STATE_LOCK must be released.
1707 * qla2x00 local function return status code.
1713 qla2x00_lip_reset(scsi_qla_host_t *ha)
1717 mbx_cmd_t *mcp = &mc;
1719 DEBUG11(printk("qla2x00_lip_reset(%ld): entered.\n",
1722 mcp->mb[0] = MBC_LIP_RESET;
1723 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1724 if (HAS_EXTENDED_IDS(ha)) {
1725 mcp->mb[1] = 0x00ff;
1727 mcp->out_mb |= MBX_10;
1729 mcp->mb[1] = 0xff00;
1731 mcp->mb[2] = ha->loop_reset_delay;
1737 rval = qla2x00_mailbox_command(ha, mcp);
1739 if (rval != QLA_SUCCESS) {
1741 DEBUG2_3_11(printk("qla2x00_lip_reset(%ld): failed=%x.\n",
1742 ha->host_no, rval);)
1745 DEBUG11(printk("qla2x00_lip_reset(%ld): done.\n", ha->host_no);)
1756 * ha = adapter block pointer.
1757 * sns = pointer for command.
1758 * cmd_size = command size.
1759 * buf_size = response/command size.
1760 * TARGET_QUEUE_LOCK must be released.
1761 * ADAPTER_STATE_LOCK must be released.
1764 * qla2x00 local function return status code.
1770 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1771 uint16_t cmd_size, size_t buf_size)
1775 mbx_cmd_t *mcp = &mc;
1777 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1780 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1781 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1783 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1784 mcp->mb[1] = cmd_size;
1785 mcp->mb[2] = MSW(sns_phys_address);
1786 mcp->mb[3] = LSW(sns_phys_address);
1787 mcp->mb[6] = MSW(MSD(sns_phys_address));
1788 mcp->mb[7] = LSW(MSD(sns_phys_address));
1789 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1790 mcp->in_mb = MBX_0|MBX_1;
1791 mcp->buf_size = buf_size;
1792 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1793 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1794 rval = qla2x00_mailbox_command(ha, mcp);
1796 if (rval != QLA_SUCCESS) {
1798 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1799 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1800 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1801 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1804 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1811 * qla2x00_login_fabric
1812 * Issue login fabric port mailbox command.
1815 * ha = adapter block pointer.
1816 * loop_id = device loop ID.
1817 * domain = device domain.
1818 * area = device area.
1819 * al_pa = device AL_PA.
1820 * status = pointer for return status.
1821 * opt = command options.
1822 * TARGET_QUEUE_LOCK must be released.
1823 * ADAPTER_STATE_LOCK must be released.
1826 * qla2x00 local function return status code.
1832 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1833 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1837 mbx_cmd_t *mcp = &mc;
1839 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
1841 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1842 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1843 if (HAS_EXTENDED_IDS(ha)) {
1844 mcp->mb[1] = loop_id;
1846 mcp->out_mb |= MBX_10;
1848 mcp->mb[1] = (loop_id << 8) | opt;
1850 mcp->mb[2] = domain;
1851 mcp->mb[3] = area << 8 | al_pa;
1853 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1854 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1856 rval = qla2x00_mailbox_command(ha, mcp);
1858 /* Return mailbox statuses. */
1867 if (rval != QLA_SUCCESS) {
1868 /* RLU tmp code: need to change main mailbox_command function to
1869 * return ok even when the mailbox completion value is not
1870 * SUCCESS. The caller needs to be responsible to interpret
1871 * the return values of this mailbox command if we're not
1872 * to change too much of the existing code.
1874 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1875 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1876 mcp->mb[0] == 0x4006)
1880 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1881 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1882 mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
1885 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1893 * qla2x00_login_local_device
1894 * Issue login loop port mailbox command.
1897 * ha = adapter block pointer.
1898 * loop_id = device loop ID.
1899 * opt = command options.
1902 * Return status code.
1909 qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
1910 uint16_t *mb_ret, uint8_t opt)
1914 mbx_cmd_t *mcp = &mc;
1916 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1918 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1919 if (HAS_EXTENDED_IDS(ha))
1920 mcp->mb[1] = loop_id;
1922 mcp->mb[1] = loop_id << 8;
1924 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1925 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1926 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1928 rval = qla2x00_mailbox_command(ha, mcp);
1930 /* Return mailbox statuses. */
1931 if (mb_ret != NULL) {
1932 mb_ret[0] = mcp->mb[0];
1933 mb_ret[1] = mcp->mb[1];
1934 mb_ret[6] = mcp->mb[6];
1935 mb_ret[7] = mcp->mb[7];
1938 if (rval != QLA_SUCCESS) {
1939 /* AV tmp code: need to change main mailbox_command function to
1940 * return ok even when the mailbox completion value is not
1941 * SUCCESS. The caller needs to be responsible to interpret
1942 * the return values of this mailbox command if we're not
1943 * to change too much of the existing code.
1945 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1948 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1949 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1950 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1951 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1952 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1953 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1956 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1963 * qla2x00_fabric_logout
1964 * Issue logout fabric port mailbox command.
1967 * ha = adapter block pointer.
1968 * loop_id = device loop ID.
1969 * TARGET_QUEUE_LOCK must be released.
1970 * ADAPTER_STATE_LOCK must be released.
1973 * qla2x00 local function return status code.
1979 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id)
1983 mbx_cmd_t *mcp = &mc;
1985 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1988 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1989 mcp->out_mb = MBX_1|MBX_0;
1990 if (HAS_EXTENDED_IDS(ha)) {
1991 mcp->mb[1] = loop_id;
1993 mcp->out_mb |= MBX_10;
1995 mcp->mb[1] = loop_id << 8;
1998 mcp->in_mb = MBX_1|MBX_0;
2001 rval = qla2x00_mailbox_command(ha, mcp);
2003 if (rval != QLA_SUCCESS) {
2005 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
2006 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
2009 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
2017 * qla2x00_full_login_lip
2018 * Issue full login LIP mailbox command.
2021 * ha = adapter block pointer.
2022 * TARGET_QUEUE_LOCK must be released.
2023 * ADAPTER_STATE_LOCK must be released.
2026 * qla2x00 local function return status code.
2032 qla2x00_full_login_lip(scsi_qla_host_t *ha)
2036 mbx_cmd_t *mcp = &mc;
2038 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
2041 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2045 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2049 rval = qla2x00_mailbox_command(ha, mcp);
2051 if (rval != QLA_SUCCESS) {
2053 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
2054 ha->instance, rval);)
2057 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
2065 * qla2x00_get_id_list
2068 * ha = adapter block pointer.
2071 * qla2x00 local function return status code.
2077 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
2082 mbx_cmd_t *mcp = &mc;
2084 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
2087 if (id_list == NULL)
2088 return QLA_FUNCTION_FAILED;
2090 mcp->mb[0] = MBC_GET_ID_LIST;
2091 mcp->mb[1] = MSW(id_list_dma);
2092 mcp->mb[2] = LSW(id_list_dma);
2093 mcp->mb[3] = MSW(MSD(id_list_dma));
2094 mcp->mb[6] = LSW(MSD(id_list_dma));
2095 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2096 mcp->in_mb = MBX_1|MBX_0;
2099 rval = qla2x00_mailbox_command(ha, mcp);
2101 if (rval != QLA_SUCCESS) {
2103 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
2104 ha->host_no, rval);)
2106 *entries = mcp->mb[1];
2107 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2116 * Issue lun reset mailbox command.
2119 * ha = adapter block pointer.
2120 * loop_id = device loop ID.
2121 * lun = lun to be reset.
2122 * TARGET_QUEUE_LOCK must be released.
2123 * ADAPTER_STATE_LOCK must be released.
2126 * qla2x00 local function return status code.
2132 qla2x00_lun_reset(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun)
2136 mbx_cmd_t *mcp = &mc;
2138 mcp->mb[0] = MBC_LUN_RESET;
2139 if (HAS_EXTENDED_IDS(ha))
2140 mcp->mb[1] = loop_id;
2142 mcp->mb[1] = loop_id << 8;
2144 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2148 rval = qla2x00_mailbox_command(ha, mcp);
2150 if (rval != QLA_SUCCESS) {
2152 printk(KERN_WARNING "qla2x00_lun_reset(%d): failed = %d",
2153 (int)ha->instance, rval);
2162 * qla2x00_send_rnid_mbx
2163 * Issue RNID ELS using mailbox command
2166 * ha = adapter state pointer.
2167 * loop_id = loop ID of the target device.
2168 * data_fmt = currently supports only 0xDF.
2169 * buffer = buffer pointer.
2170 * buf_size = size of buffer.
2171 * mb_reg = pointer to return mailbox registers.
2174 * qla2x00 local function return status code.
2180 qla2x00_send_rnid_mbx(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t data_fmt,
2181 dma_addr_t buf_phys_addr, size_t buf_size, uint16_t *mb_reg)
2185 mbx_cmd_t *mcp = &mc;
2187 DEBUG11(printk("qla2x00_send_rnid_mbx(%ld): entered.\n",
2190 mcp->mb[0] = MBC_SEND_RNID_ELS;
2191 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2192 if (HAS_EXTENDED_IDS(ha)) {
2193 mcp->mb[1] = loop_id;
2194 mcp->mb[10] = data_fmt;
2195 mcp->out_mb |= MBX_10;
2197 mcp->mb[1] = (loop_id << 8) | data_fmt;
2199 mcp->mb[2] = MSW(buf_phys_addr);
2200 mcp->mb[3] = LSW(buf_phys_addr);
2201 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2202 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2204 mcp->in_mb = MBX_1|MBX_0;
2205 mcp->buf_size = buf_size;
2206 mcp->flags = MBX_DMA_IN;
2208 rval = qla2x00_mailbox_command(ha, mcp);
2210 if (rval != QLA_SUCCESS) {
2211 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2213 DEBUG2_3_11(printk("qla2x00_send_rnid_mbx(%ld): failed=%x "
2215 ha->host_no, mcp->mb[0], mcp->mb[1]);)
2218 DEBUG11(printk("qla2x00_send_rnid_mbx(%ld): done.\n",
2226 * qla2x00_set_rnid_params_mbx
2227 * Set RNID parameters using mailbox command
2230 * ha = adapter state pointer.
2231 * buffer = buffer pointer.
2232 * buf_size = size of buffer.
2233 * mb_reg = pointer to return mailbox registers.
2236 * qla2x00 local function return status code.
2242 qla2x00_set_rnid_params_mbx(scsi_qla_host_t *ha, dma_addr_t buf_phys_addr,
2243 size_t buf_size, uint16_t *mb_reg)
2247 mbx_cmd_t *mcp = &mc;
2249 DEBUG11(printk("qla2x00_set_rnid_params_mbx(%ld): entered.\n",
2252 mcp->mb[0] = MBC_SET_RNID_PARAMS;
2254 mcp->mb[2] = MSW(buf_phys_addr);
2255 mcp->mb[3] = LSW(buf_phys_addr);
2256 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2257 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2258 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2259 mcp->in_mb = MBX_1|MBX_0;
2260 mcp->buf_size = buf_size;
2261 mcp->flags = MBX_DMA_OUT;
2263 rval = qla2x00_mailbox_command(ha, mcp);
2265 if (rval != QLA_SUCCESS) {
2266 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2268 DEBUG2_3_11(printk("qla2x00_set_rnid_params_mbx(%ld): "
2269 "failed=%x mb[1]=%x.\n", ha->host_no, mcp->mb[0],
2273 DEBUG11(printk("qla2x00_set_rnid_params_mbx(%ld): done.\n",
2281 * qla2x00_get_rnid_params_mbx
2282 * Get RNID parameters using mailbox command
2285 * ha = adapter state pointer.
2286 * buffer = buffer pointer.
2287 * buf_size = size of buffer.
2288 * mb_reg = pointer to return mailbox registers.
2291 * qla2x00 local function return status code.
2297 qla2x00_get_rnid_params_mbx(scsi_qla_host_t *ha, dma_addr_t buf_phys_addr,
2298 size_t buf_size, uint16_t *mb_reg)
2302 mbx_cmd_t *mcp = &mc;
2304 DEBUG11(printk("qla2x00_get_rnid_params_mbx(%ld): entered.\n",
2307 mcp->mb[0] = MBC_GET_RNID_PARAMS;
2309 mcp->mb[2] = MSW(buf_phys_addr);
2310 mcp->mb[3] = LSW(buf_phys_addr);
2311 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2312 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2313 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2314 mcp->in_mb = MBX_1|MBX_0;
2315 mcp->buf_size = buf_size;
2316 mcp->flags = MBX_DMA_IN;
2318 rval = qla2x00_mailbox_command(ha, mcp);
2320 if (rval != QLA_SUCCESS) {
2321 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2323 DEBUG2_3_11(printk("qla2x00_get_rnid_params_mbx(%ld): "
2324 "failed=%x mb[1]=%x.\n", ha->host_no, mcp->mb[0],
2328 DEBUG11(printk("qla2x00_get_rnid_params_mbx(%ld): done.\n",
2336 * qla2x00_get_resource_cnts
2337 * Get current firmware resource counts.
2340 * ha = adapter block pointer.
2343 * qla2x00 local function return status code.
2349 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
2350 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
2354 mbx_cmd_t *mcp = &mc;
2356 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2358 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2359 mcp->out_mb = MBX_0;
2360 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2363 rval = qla2x00_mailbox_command(ha, mcp);
2365 if (rval != QLA_SUCCESS) {
2367 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2368 ha->host_no, mcp->mb[0]);)
2370 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2371 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
2372 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
2376 *cur_xchg_cnt = mcp->mb[3];
2378 *orig_xchg_cnt = mcp->mb[6];
2380 *cur_iocb_cnt = mcp->mb[7];
2382 *orig_iocb_cnt = mcp->mb[10];
2388 #if defined(QL_DEBUG_LEVEL_3)
2390 * qla2x00_get_fcal_position_map
2391 * Get FCAL (LILP) position map using mailbox command
2394 * ha = adapter state pointer.
2395 * pos_map = buffer pointer (can be NULL).
2398 * qla2x00 local function return status code.
2404 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
2408 mbx_cmd_t *mcp = &mc;
2410 dma_addr_t pmap_dma;
2412 pmap = pci_alloc_consistent(ha->pdev, FCAL_MAP_SIZE, &pmap_dma);
2414 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2415 __func__, ha->host_no));
2416 return QLA_MEMORY_ALLOC_FAILED;
2418 memset(pmap, 0, FCAL_MAP_SIZE);
2420 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2421 mcp->mb[2] = MSW(pmap_dma);
2422 mcp->mb[3] = LSW(pmap_dma);
2423 mcp->mb[6] = MSW(MSD(pmap_dma));
2424 mcp->mb[7] = LSW(MSD(pmap_dma));
2425 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2426 mcp->in_mb = MBX_1|MBX_0;
2427 mcp->buf_size = FCAL_MAP_SIZE;
2428 mcp->flags = MBX_DMA_IN;
2429 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2430 rval = qla2x00_mailbox_command(ha, mcp);
2432 if (rval == QLA_SUCCESS) {
2433 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2434 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2435 mcp->mb[1], (unsigned)pmap[0]));
2436 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2439 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2441 pci_free_consistent(ha->pdev, FCAL_MAP_SIZE, pmap, pmap_dma);
2443 if (rval != QLA_SUCCESS) {
2444 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2445 ha->host_no, rval));
2447 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));