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 qla_printk(KERN_WARNING, ha,
283 "Mailbox command timeout occured. Scheduling ISP "
285 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
286 if (ha->dpc_wait && !ha->dpc_active)
289 } else if (!abort_active) {
291 /* call abort directly since we are in the DPC thread */
292 DEBUG(printk("qla2x00_mailbox_command(%ld): timeout "
293 "calling abort_isp\n", ha->host_no);)
294 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): "
295 "timeout calling abort_isp\n", ha->host_no);)
296 qla_printk(KERN_WARNING, ha,
297 "Mailbox command timeout occured. Issuing ISP "
300 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
301 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
302 if (qla2x00_abort_isp(ha)) {
303 /* failed. retry later. */
304 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
306 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
308 DEBUG(printk("qla2x00_mailbox_command: finished "
310 DEBUG2_3_11(printk("qla2x00_mailbox_command: finished "
315 /* Allow next mbx cmd to come in. */
317 up(&ha->mbx_cmd_sem);
320 DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): **** FAILED. "
321 "mbx0=%x, mbx1=%x, mbx2=%x, cmd=%x ****\n",
322 ha->host_no, mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
324 DEBUG11(printk("qla2x00_mailbox_command(%ld): done.\n",
328 DEBUG11(printk("qla2x00_mailbox_command(%ld): exiting.\n",
336 * Load adapter RAM using DMA.
339 * ha = adapter block pointer.
342 * qla2x00 local function return status code.
348 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
349 uint16_t risc_code_size)
353 mbx_cmd_t *mcp = &mc;
359 DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
362 req_len = risc_code_size;
366 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
369 /* Load first segment */
370 mcp->mb[0] = MBC_LOAD_RISC_RAM;
371 mcp->mb[1] = risc_addr;
372 mcp->mb[2] = MSW(req_dma);
373 mcp->mb[3] = LSW(req_dma);
374 mcp->mb[4] = (uint16_t)req_len;
375 mcp->mb[6] = MSW(MSD(req_dma));
376 mcp->mb[7] = LSW(MSD(req_dma));
377 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
381 rval = qla2x00_mailbox_command(ha, mcp);
383 /* Load second segment - if necessary */
384 if (normalized && (rval == QLA_SUCCESS)) {
385 mcp->mb[0] = MBC_LOAD_RISC_RAM;
386 mcp->mb[1] = risc_addr + (uint16_t)req_len;
387 mcp->mb[2] = MSW(nml_dma);
388 mcp->mb[3] = LSW(nml_dma);
389 mcp->mb[4] = (uint16_t)nml_len;
390 mcp->mb[6] = MSW(MSD(nml_dma));
391 mcp->mb[7] = LSW(MSD(nml_dma));
392 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
396 rval = qla2x00_mailbox_command(ha, mcp);
399 if (rval == QLA_SUCCESS) {
401 DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
404 DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
405 "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
411 * qla2x00_load_ram_ext
412 * Load adapter extended RAM using DMA.
415 * ha = adapter block pointer.
418 * qla2x00 local function return status code.
424 qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
425 uint32_t risc_addr, uint16_t risc_code_size)
429 mbx_cmd_t *mcp = &mc;
435 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
437 req_len = risc_code_size;
441 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
444 /* Load first segment */
445 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
446 mcp->mb[1] = LSW(risc_addr);
447 mcp->mb[2] = MSW(req_dma);
448 mcp->mb[3] = LSW(req_dma);
449 mcp->mb[4] = (uint16_t)req_len;
450 mcp->mb[6] = MSW(MSD(req_dma));
451 mcp->mb[7] = LSW(MSD(req_dma));
452 mcp->mb[8] = MSW(risc_addr);
453 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
457 rval = qla2x00_mailbox_command(ha, mcp);
459 /* Load second segment - if necessary */
460 if (normalized && (rval == QLA_SUCCESS)) {
461 risc_addr += req_len;
462 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
463 mcp->mb[1] = LSW(risc_addr);
464 mcp->mb[2] = MSW(nml_dma);
465 mcp->mb[3] = LSW(nml_dma);
466 mcp->mb[4] = (uint16_t)nml_len;
467 mcp->mb[6] = MSW(MSD(nml_dma));
468 mcp->mb[7] = LSW(MSD(nml_dma));
469 mcp->mb[8] = MSW(risc_addr);
470 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
474 rval = qla2x00_mailbox_command(ha, mcp);
477 if (rval != QLA_SUCCESS) {
479 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n",
480 __func__, ha->host_no, rval, mcp->mb[0]));
483 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
491 * Start adapter firmware.
494 * ha = adapter block pointer.
495 * TARGET_QUEUE_LOCK must be released.
496 * ADAPTER_STATE_LOCK must be released.
499 * qla2x00 local function return status code.
505 qla2x00_execute_fw(scsi_qla_host_t *ha)
509 mbx_cmd_t *mcp = &mc;
511 DEBUG11(printk("qla2x00_execute_fw(%ld): entered.\n", ha->host_no);)
513 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
514 mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart;
515 mcp->out_mb = MBX_1|MBX_0;
516 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
518 mcp->out_mb |= MBX_2;
524 rval = qla2x00_mailbox_command(ha, mcp);
526 DEBUG11(printk("qla2x00_execute_fw(%ld): done.\n", ha->host_no);)
532 * qla2x00_get_fw_version
533 * Get firmware version.
536 * ha: adapter state pointer.
537 * major: pointer for major number.
538 * minor: pointer for minor number.
539 * subminor: pointer for subminor number.
542 * qla2x00 local function return status code.
548 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
549 uint16_t *subminor, uint16_t *attributes)
553 mbx_cmd_t *mcp = &mc;
555 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
557 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
559 mcp->in_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
562 rval = qla2x00_mailbox_command(ha, mcp);
564 /* Return mailbox data. */
567 *subminor = mcp->mb[3];
568 *attributes = mcp->mb[6];
570 if (rval != QLA_SUCCESS) {
572 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
576 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
581 * qla2x00_get_fw_options
582 * Set firmware options.
585 * ha = adapter block pointer.
586 * fwopt = pointer for firmware options.
589 * qla2x00 local function return status code.
595 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
599 mbx_cmd_t *mcp = &mc;
601 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
603 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
605 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
608 rval = qla2x00_mailbox_command(ha, mcp);
610 if (rval != QLA_SUCCESS) {
612 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
615 fwopts[1] = mcp->mb[1];
616 fwopts[2] = mcp->mb[2];
617 fwopts[3] = mcp->mb[3];
619 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
627 * qla2x00_set_fw_options
628 * Set firmware options.
631 * ha = adapter block pointer.
632 * fwopt = pointer for firmware options.
635 * qla2x00 local function return status code.
641 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
645 mbx_cmd_t *mcp = &mc;
647 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
649 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
650 mcp->mb[1] = fwopts[1];
651 mcp->mb[2] = fwopts[2];
652 mcp->mb[3] = fwopts[3];
653 mcp->mb[10] = fwopts[10];
654 mcp->mb[11] = fwopts[11];
655 mcp->mb[12] = 0; /* Undocumented, but used */
656 mcp->out_mb = MBX_12|MBX_11|MBX_10|MBX_3|MBX_2|MBX_1|MBX_0;
660 rval = qla2x00_mailbox_command(ha, mcp);
662 if (rval != QLA_SUCCESS) {
664 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
668 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
675 * qla2x00_read_ram_word
678 * ha = adapter block pointer.
681 * qla2x00 local function return status code.
687 qla2x00_read_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t *data)
691 mbx_cmd_t *mcp = &mc;
693 DEBUG11(printk("qla2x00_read_ram_word(%ld): entered.\n", ha->host_no);)
695 mcp->mb[0] = MBC_READ_RAM_WORD;
697 mcp->out_mb = MBX_1|MBX_0;
698 mcp->in_mb = MBX_0|MBX_2;
701 rval = qla2x00_mailbox_command(ha, mcp);
703 if (rval != QLA_SUCCESS) {
705 DEBUG2_3_11(printk("qla2x00_read_ram_word(%ld): failed=%x.\n",
709 DEBUG11(printk("qla2x00_read_ram_word(%ld): done.\n",
717 * qla2x00_write_ram_word
720 * ha = adapter block pointer.
723 * qla2x00 local function return status code.
729 qla2x00_write_ram_word(scsi_qla_host_t *ha, uint16_t addr, uint16_t data)
733 mbx_cmd_t *mcp = &mc;
735 DEBUG11(printk("qla2x00_write_ram_word(%ld): entered.\n",
738 mcp->mb[0] = MBC_WRITE_RAM_WORD;
741 mcp->out_mb = MBX_2|MBX_1|MBX_0;
745 rval = qla2x00_mailbox_command(ha, mcp);
747 if (rval != QLA_SUCCESS) {
749 DEBUG2_3_11(printk("qla2x00_write_ram_word(%ld): failed=%x.\n",
753 DEBUG11(printk("qla2x00_write_ram_word(%ld): done.\n",
761 * qla2x00_write_ram_word_ext
764 * ha = adapter block pointer.
767 * qla2x00 local function return status code.
773 qla2x00_write_ram_word_ext(scsi_qla_host_t *ha, uint32_t addr, uint16_t data)
777 mbx_cmd_t *mcp = &mc;
779 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
781 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
782 mcp->mb[1] = LSW(addr);
784 mcp->mb[8] = MSW(addr);
785 mcp->out_mb = MBX_8|MBX_2|MBX_1|MBX_0;
789 rval = qla2x00_mailbox_command(ha, mcp);
791 if (rval != QLA_SUCCESS) {
793 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
797 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
804 * qla2x00_mbx_reg_test
805 * Mailbox register wrap test.
808 * ha = adapter block pointer.
809 * TARGET_QUEUE_LOCK must be released.
810 * ADAPTER_STATE_LOCK must be released.
813 * qla2x00 local function return status code.
819 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
823 mbx_cmd_t *mcp = &mc;
825 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
827 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
835 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
836 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
839 rval = qla2x00_mailbox_command(ha, mcp);
841 if (rval == QLA_SUCCESS) {
842 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
843 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
844 rval = QLA_FUNCTION_FAILED;
845 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
846 mcp->mb[7] != 0x2525)
847 rval = QLA_FUNCTION_FAILED;
850 if (rval != QLA_SUCCESS) {
852 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
856 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
864 * qla2x00_verify_checksum
865 * Verify firmware checksum.
868 * ha = adapter block pointer.
869 * TARGET_QUEUE_LOCK must be released.
870 * ADAPTER_STATE_LOCK must be released.
873 * qla2x00 local function return status code.
879 qla2x00_verify_checksum(scsi_qla_host_t *ha)
883 mbx_cmd_t *mcp = &mc;
885 DEBUG11(printk("qla2x00_verify_checksum(%ld): entered.\n",
888 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
889 mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart;
890 mcp->out_mb = MBX_1|MBX_0;
891 mcp->in_mb = MBX_2|MBX_0;
894 rval = qla2x00_mailbox_command(ha, mcp);
896 if (rval != QLA_SUCCESS) {
898 DEBUG2_3_11(printk("qla2x00_verify_checksum(%ld): failed=%x.\n",
902 DEBUG11(printk("qla2x00_verify_checksum(%ld): done.\n",
911 * Issue IOCB using mailbox command
914 * ha = adapter state pointer.
915 * buffer = buffer pointer.
916 * phys_addr = physical address of buffer.
917 * size = size of buffer.
918 * TARGET_QUEUE_LOCK must be released.
919 * ADAPTER_STATE_LOCK must be released.
922 * qla2x00 local function return status code.
928 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
933 mbx_cmd_t *mcp = &mc;
935 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
937 mcp->mb[2] = MSW(phys_addr);
938 mcp->mb[3] = LSW(phys_addr);
939 mcp->mb[6] = MSW(MSD(phys_addr));
940 mcp->mb[7] = LSW(MSD(phys_addr));
941 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
942 mcp->in_mb = MBX_2|MBX_0;
945 rval = qla2x00_mailbox_command(ha, mcp);
947 if (rval != QLA_SUCCESS) {
949 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
951 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x",
961 * qla2x00_abort_command
962 * Abort command aborts a specified IOCB.
965 * ha = adapter block pointer.
966 * sp = SB structure pointer.
969 * qla2x00 local function return status code.
975 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
977 unsigned long flags = 0;
982 mbx_cmd_t *mcp = &mc;
984 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
986 fcport = sp->fclun->fcport;
988 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
989 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
993 spin_lock_irqsave(&ha->hardware_lock, flags);
994 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
995 if (ha->outstanding_cmds[handle] == sp)
998 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1000 if (handle == MAX_OUTSTANDING_COMMANDS) {
1001 /* command not found */
1002 return QLA_FUNCTION_FAILED;
1005 mcp->mb[0] = MBC_ABORT_COMMAND;
1006 if (HAS_EXTENDED_IDS(ha))
1007 mcp->mb[1] = fcport->loop_id;
1009 mcp->mb[1] = fcport->loop_id << 8;
1010 mcp->mb[2] = (uint16_t)handle;
1011 mcp->mb[3] = (uint16_t)(handle >> 16);
1012 mcp->mb[6] = (uint16_t)sp->fclun->lun;
1013 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1017 rval = qla2x00_mailbox_command(ha, mcp);
1019 if (rval != QLA_SUCCESS) {
1020 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
1021 ha->host_no, rval);)
1023 sp->flags |= SRB_ABORT_PENDING;
1024 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
1032 * qla2x00_abort_device
1035 * ha = adapter block pointer.
1036 * loop_id = FC loop ID
1040 * qla2x00 local function return status code.
1046 qla2x00_abort_device(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun)
1050 mbx_cmd_t *mcp = &mc;
1052 DEBUG11(printk("qla2x00_abort_device(%ld): entered.\n", ha->host_no);)
1054 mcp->mb[0] = MBC_ABORT_DEVICE;
1055 if (HAS_EXTENDED_IDS(ha))
1056 mcp->mb[1] = loop_id;
1058 mcp->mb[1] = loop_id << 8;
1060 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1064 rval = qla2x00_mailbox_command(ha, mcp);
1066 /* Issue marker command. */
1067 qla2x00_marker(ha, loop_id, lun, MK_SYNC_ID_LUN);
1069 if (rval != QLA_SUCCESS) {
1070 qla_printk(KERN_WARNING, ha,
1071 "Failed Abort Device Mailbox command. Scheduling ISP "
1073 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1074 if (ha->dpc_wait && !ha->dpc_active)
1076 DEBUG2_3_11(printk("qla2x00_abort_device(%ld): failed=%x.\n",
1077 ha->host_no, rval);)
1080 DEBUG11(printk("qla2x00_abort_device(%ld): done.\n",
1089 * qla2x00_abort_target
1090 * Issue abort target mailbox command.
1093 * ha = adapter block pointer.
1096 * qla2x00 local function return status code.
1102 qla2x00_abort_target(fc_port_t *fcport)
1106 mbx_cmd_t *mcp = &mc;
1108 DEBUG11(printk("qla2x00_abort_target(%ld): entered.\n",
1109 fcport->ha->host_no);)
1111 if (fcport == NULL) {
1112 /* no target to abort */
1116 mcp->mb[0] = MBC_ABORT_TARGET;
1117 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1118 if (HAS_EXTENDED_IDS(fcport->ha)) {
1119 mcp->mb[1] = fcport->loop_id;
1121 mcp->out_mb |= MBX_10;
1123 mcp->mb[1] = fcport->loop_id << 8;
1125 mcp->mb[2] = fcport->ha->loop_reset_delay;
1130 rval = qla2x00_mailbox_command(fcport->ha, mcp);
1132 /* Issue marker command. */
1133 fcport->ha->marker_needed = 1;
1135 if (rval != QLA_SUCCESS) {
1136 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
1137 fcport->ha->host_no, rval);)
1140 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
1141 fcport->ha->host_no);)
1149 * qla2x00_target_reset
1150 * Issue target reset mailbox command.
1153 * ha = adapter block pointer.
1154 * TARGET_QUEUE_LOCK must be released.
1155 * ADAPTER_STATE_LOCK must be released.
1158 * qla2x00 local function return status code.
1164 qla2x00_target_reset(scsi_qla_host_t *ha, uint16_t b, uint16_t t)
1168 mbx_cmd_t *mcp = &mc;
1171 DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);)
1174 if (tgt->fcport == NULL) {
1175 /* no target to abort */
1178 if (atomic_read(&tgt->fcport->state) != FCS_ONLINE) {
1179 /* target not online */
1183 mcp->mb[0] = MBC_TARGET_RESET;
1184 if (HAS_EXTENDED_IDS(ha))
1185 mcp->mb[1] = tgt->fcport->loop_id;
1187 mcp->mb[1] = tgt->fcport->loop_id << 8;
1188 mcp->mb[2] = ha->loop_reset_delay;
1189 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1193 rval = qla2x00_mailbox_command(ha, mcp);
1195 if (rval != QLA_SUCCESS) {
1197 DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n",
1198 ha->host_no, rval);)
1201 DEBUG11(printk("qla2x00_target_reset(%ld): done.\n",
1209 * qla2x00_get_adapter_id
1210 * Get adapter ID and topology.
1213 * ha = adapter block pointer.
1214 * id = pointer for loop ID.
1215 * al_pa = pointer for AL_PA.
1216 * area = pointer for area.
1217 * domain = pointer for domain.
1218 * top = pointer for topology.
1219 * TARGET_QUEUE_LOCK must be released.
1220 * ADAPTER_STATE_LOCK must be released.
1223 * qla2x00 local function return status code.
1229 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
1230 uint8_t *area, uint8_t *domain, uint16_t *top)
1234 mbx_cmd_t *mcp = &mc;
1236 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
1239 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
1240 mcp->out_mb = MBX_0;
1241 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1244 rval = qla2x00_mailbox_command(ha, mcp);
1248 *al_pa = LSB(mcp->mb[2]);
1249 *area = MSB(mcp->mb[2]);
1250 *domain = LSB(mcp->mb[3]);
1253 if (rval != QLA_SUCCESS) {
1255 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
1256 ha->host_no, rval);)
1259 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
1267 * qla2x00_get_retry_cnt
1268 * Get current firmware login retry count and delay.
1271 * ha = adapter block pointer.
1272 * retry_cnt = pointer to login retry count.
1273 * tov = pointer to login timeout value.
1276 * qla2x00 local function return status code.
1282 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
1288 mbx_cmd_t *mcp = &mc;
1290 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1293 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1294 mcp->out_mb = MBX_0;
1295 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1298 rval = qla2x00_mailbox_command(ha, mcp);
1300 if (rval != QLA_SUCCESS) {
1302 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1303 ha->host_no, mcp->mb[0]);)
1305 /* Convert returned data and check our values. */
1306 *r_a_tov = mcp->mb[3] / 2;
1307 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1308 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1309 /* Update to the larger values */
1310 *retry_cnt = (uint8_t)mcp->mb[1];
1314 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1315 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
1322 * qla2x00_init_firmware
1323 * Initialize adapter firmware.
1326 * ha = adapter block pointer.
1327 * dptr = Initialization control block pointer.
1328 * size = size of initialization control block.
1329 * TARGET_QUEUE_LOCK must be released.
1330 * ADAPTER_STATE_LOCK must be released.
1333 * qla2x00 local function return status code.
1339 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1343 mbx_cmd_t *mcp = &mc;
1345 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1348 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1349 mcp->mb[2] = MSW(ha->init_cb_dma);
1350 mcp->mb[3] = LSW(ha->init_cb_dma);
1353 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1354 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1355 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1356 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1357 mcp->buf_size = size;
1358 mcp->flags = MBX_DMA_OUT;
1360 rval = qla2x00_mailbox_command(ha, mcp);
1362 if (rval != QLA_SUCCESS) {
1364 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1366 ha->host_no, rval, mcp->mb[0]);)
1369 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1377 * qla2x00_get_port_database
1378 * Issue normal/enhanced get port database mailbox command
1379 * and copy device name as necessary.
1382 * ha = adapter state pointer.
1383 * dev = structure pointer.
1384 * opt = enhanced cmd option byte.
1387 * qla2x00 local function return status code.
1393 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1397 mbx_cmd_t *mcp = &mc;
1398 port_database_t *pd;
1401 DEBUG11(printk("qla2x00_get_port_database(%ld): entered.\n",
1404 pd = pci_alloc_consistent(ha->pdev, PORT_DATABASE_SIZE, &pd_dma);
1406 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): **** "
1407 "Mem Alloc Failed ****", ha->host_no);)
1408 return QLA_MEMORY_ALLOC_FAILED;
1410 memset(pd, 0, PORT_DATABASE_SIZE);
1413 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1415 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1416 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1417 if (HAS_EXTENDED_IDS(ha)) {
1418 mcp->mb[1] = fcport->loop_id;
1420 mcp->out_mb |= MBX_10;
1422 mcp->mb[1] = fcport->loop_id << 8 | opt;
1424 mcp->mb[2] = MSW(pd_dma);
1425 mcp->mb[3] = LSW(pd_dma);
1426 mcp->mb[6] = MSW(MSD(pd_dma));
1427 mcp->mb[7] = LSW(MSD(pd_dma));
1430 mcp->buf_size = PORT_DATABASE_SIZE;
1431 mcp->flags = MBX_DMA_IN;
1432 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1433 rval = qla2x00_mailbox_command(ha, mcp);
1435 if (rval == QLA_SUCCESS) {
1436 /* Names are little-endian. */
1437 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1438 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1440 /* Get port_id of device. */
1441 fcport->d_id.b.al_pa = pd->port_id[2];
1442 fcport->d_id.b.area = pd->port_id[3];
1443 fcport->d_id.b.domain = pd->port_id[0];
1444 fcport->d_id.b.rsvd_1 = 0;
1446 /* Check for device require authentication. */
1447 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1448 (fcport->flags &= ~FCF_AUTH_REQ);
1450 /* If not target must be initiator or unknown type. */
1451 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) {
1452 fcport->port_type = FCT_INITIATOR;
1454 fcport->port_type = FCT_TARGET;
1456 /* Check for logged in. */
1457 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1458 pd->slave_state != PD_STATE_PORT_LOGGED_IN)
1459 rval = QLA_FUNCTION_FAILED;
1463 pci_free_consistent(ha->pdev, PORT_DATABASE_SIZE, pd, pd_dma);
1465 if (rval != QLA_SUCCESS) {
1467 DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): "
1468 "failed=%x.\n", ha->host_no, rval);)
1471 DEBUG11(printk("qla2x00_get_port_database(%ld): done.\n",
1479 * qla2x00_get_firmware_state
1480 * Get adapter firmware state.
1483 * ha = adapter block pointer.
1484 * dptr = pointer for firmware state.
1485 * TARGET_QUEUE_LOCK must be released.
1486 * ADAPTER_STATE_LOCK must be released.
1489 * qla2x00 local function return status code.
1495 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1499 mbx_cmd_t *mcp = &mc;
1501 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1504 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1505 mcp->out_mb = MBX_0;
1506 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1509 rval = qla2x00_mailbox_command(ha, mcp);
1511 /* Return firmware state. */
1514 if (rval != QLA_SUCCESS) {
1516 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1517 "failed=%x.\n", ha->host_no, rval);)
1520 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1528 * qla2x00_get_port_name
1529 * Issue get port name mailbox command.
1530 * Returned name is in big endian format.
1533 * ha = adapter block pointer.
1534 * loop_id = loop ID of device.
1535 * name = pointer for name.
1536 * TARGET_QUEUE_LOCK must be released.
1537 * ADAPTER_STATE_LOCK must be released.
1540 * qla2x00 local function return status code.
1546 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1551 mbx_cmd_t *mcp = &mc;
1553 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1556 mcp->mb[0] = MBC_GET_PORT_NAME;
1557 mcp->out_mb = MBX_1|MBX_0;
1558 if (HAS_EXTENDED_IDS(ha)) {
1559 mcp->mb[1] = loop_id;
1561 mcp->out_mb |= MBX_10;
1563 mcp->mb[1] = loop_id << 8 | opt;
1566 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1569 rval = qla2x00_mailbox_command(ha, mcp);
1571 if (rval != QLA_SUCCESS) {
1573 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1574 ha->host_no, rval);)
1577 /* This function returns name in big endian. */
1578 name[0] = LSB(mcp->mb[2]);
1579 name[1] = MSB(mcp->mb[2]);
1580 name[2] = LSB(mcp->mb[3]);
1581 name[3] = MSB(mcp->mb[3]);
1582 name[4] = LSB(mcp->mb[6]);
1583 name[5] = MSB(mcp->mb[6]);
1584 name[6] = LSB(mcp->mb[7]);
1585 name[7] = MSB(mcp->mb[7]);
1588 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1596 * qla2x00_get_link_status
1599 * ha = adapter block pointer.
1600 * loop_id = device loop ID.
1601 * ret_buf = pointer to link status return buffer.
1605 * BIT_0 = mem alloc error.
1606 * BIT_1 = mailbox error.
1609 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
1610 link_stat_t *ret_buf, uint16_t *status)
1614 mbx_cmd_t *mcp = &mc;
1615 link_stat_t *stat_buf;
1616 dma_addr_t phys_address = 0;
1619 DEBUG11(printk("qla2x00_get_link_status(%ld): entered.\n",
1622 stat_buf = pci_alloc_consistent(ha->pdev, sizeof(link_stat_t),
1624 if (stat_buf == NULL) {
1625 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): Failed to "
1626 "allocate memory.\n", ha->host_no));
1629 memset(stat_buf, 0, sizeof(link_stat_t));
1631 mcp->mb[0] = MBC_GET_LINK_STATUS;
1632 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1633 if (HAS_EXTENDED_IDS(ha)) {
1634 mcp->mb[1] = loop_id;
1636 mcp->out_mb |= MBX_10;
1638 mcp->mb[1] = loop_id << 8;
1640 mcp->mb[2] = MSW(phys_address);
1641 mcp->mb[3] = LSW(phys_address);
1642 mcp->mb[6] = MSW(MSD(phys_address));
1643 mcp->mb[7] = LSW(MSD(phys_address));
1647 mcp->flags = IOCTL_CMD;
1648 rval = qla2x00_mailbox_command(ha, mcp);
1650 if (rval == QLA_SUCCESS) {
1651 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
1652 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): cmd "
1653 "failed. mbx0=%x.\n", ha->host_no, mcp->mb[0]);)
1654 status[0] = mcp->mb[0];
1657 /* copy over data -- firmware data is LE. */
1658 ret_buf->link_fail_cnt =
1659 le32_to_cpu(stat_buf->link_fail_cnt);
1660 ret_buf->loss_sync_cnt =
1661 le32_to_cpu(stat_buf->loss_sync_cnt);
1662 ret_buf->loss_sig_cnt =
1663 le32_to_cpu(stat_buf->loss_sig_cnt);
1664 ret_buf->prim_seq_err_cnt =
1665 le32_to_cpu(stat_buf->prim_seq_err_cnt);
1666 ret_buf->inval_xmit_word_cnt =
1667 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
1668 ret_buf->inval_crc_cnt =
1669 le32_to_cpu(stat_buf->inval_crc_cnt);
1671 DEBUG11(printk("qla2x00_get_link_status(%ld): stat "
1672 "dump: fail_cnt=%d loss_sync=%d loss_sig=%d "
1673 "seq_err=%d inval_xmt_word=%d inval_crc=%d.\n",
1675 stat_buf->link_fail_cnt, stat_buf->loss_sync_cnt,
1676 stat_buf->loss_sig_cnt, stat_buf->prim_seq_err_cnt,
1677 stat_buf->inval_xmit_word_cnt,
1678 stat_buf->inval_crc_cnt);)
1682 DEBUG2_3_11(printk("qla2x00_get_link_status(%ld): failed=%x.\n",
1683 ha->host_no, rval);)
1687 pci_free_consistent(ha->pdev, sizeof(link_stat_t), stat_buf,
1695 * Issue LIP reset mailbox command.
1698 * ha = adapter block pointer.
1699 * TARGET_QUEUE_LOCK must be released.
1700 * ADAPTER_STATE_LOCK must be released.
1703 * qla2x00 local function return status code.
1709 qla2x00_lip_reset(scsi_qla_host_t *ha)
1713 mbx_cmd_t *mcp = &mc;
1715 DEBUG11(printk("qla2x00_lip_reset(%ld): entered.\n",
1718 mcp->mb[0] = MBC_LIP_RESET;
1719 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1720 if (HAS_EXTENDED_IDS(ha)) {
1721 mcp->mb[1] = 0x00ff;
1723 mcp->out_mb |= MBX_10;
1725 mcp->mb[1] = 0xff00;
1727 mcp->mb[2] = ha->loop_reset_delay;
1733 rval = qla2x00_mailbox_command(ha, mcp);
1735 if (rval != QLA_SUCCESS) {
1737 DEBUG2_3_11(printk("qla2x00_lip_reset(%ld): failed=%x.\n",
1738 ha->host_no, rval);)
1741 DEBUG11(printk("qla2x00_lip_reset(%ld): done.\n", ha->host_no);)
1752 * ha = adapter block pointer.
1753 * sns = pointer for command.
1754 * cmd_size = command size.
1755 * buf_size = response/command size.
1756 * TARGET_QUEUE_LOCK must be released.
1757 * ADAPTER_STATE_LOCK must be released.
1760 * qla2x00 local function return status code.
1766 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1767 uint16_t cmd_size, size_t buf_size)
1771 mbx_cmd_t *mcp = &mc;
1773 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1776 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1777 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1779 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1780 mcp->mb[1] = cmd_size;
1781 mcp->mb[2] = MSW(sns_phys_address);
1782 mcp->mb[3] = LSW(sns_phys_address);
1783 mcp->mb[6] = MSW(MSD(sns_phys_address));
1784 mcp->mb[7] = LSW(MSD(sns_phys_address));
1785 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1786 mcp->in_mb = MBX_0|MBX_1;
1787 mcp->buf_size = buf_size;
1788 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1789 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1790 rval = qla2x00_mailbox_command(ha, mcp);
1792 if (rval != QLA_SUCCESS) {
1794 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1795 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1796 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1797 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1800 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1807 * qla2x00_login_fabric
1808 * Issue login fabric port mailbox command.
1811 * ha = adapter block pointer.
1812 * loop_id = device loop ID.
1813 * domain = device domain.
1814 * area = device area.
1815 * al_pa = device AL_PA.
1816 * status = pointer for return status.
1817 * opt = command options.
1818 * TARGET_QUEUE_LOCK must be released.
1819 * ADAPTER_STATE_LOCK must be released.
1822 * qla2x00 local function return status code.
1828 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1829 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1833 mbx_cmd_t *mcp = &mc;
1835 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
1837 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1838 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1839 if (HAS_EXTENDED_IDS(ha)) {
1840 mcp->mb[1] = loop_id;
1842 mcp->out_mb |= MBX_10;
1844 mcp->mb[1] = (loop_id << 8) | opt;
1846 mcp->mb[2] = domain;
1847 mcp->mb[3] = area << 8 | al_pa;
1849 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1850 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1852 rval = qla2x00_mailbox_command(ha, mcp);
1854 /* Return mailbox statuses. */
1863 if (rval != QLA_SUCCESS) {
1864 /* RLU tmp code: need to change main mailbox_command function to
1865 * return ok even when the mailbox completion value is not
1866 * SUCCESS. The caller needs to be responsible to interpret
1867 * the return values of this mailbox command if we're not
1868 * to change too much of the existing code.
1870 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1871 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1872 mcp->mb[0] == 0x4006)
1876 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1877 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1878 mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
1881 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1889 * qla2x00_login_local_device
1890 * Issue login loop port mailbox command.
1893 * ha = adapter block pointer.
1894 * loop_id = device loop ID.
1895 * opt = command options.
1898 * Return status code.
1905 qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
1906 uint16_t *mb_ret, uint8_t opt)
1910 mbx_cmd_t *mcp = &mc;
1912 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1914 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1915 if (HAS_EXTENDED_IDS(ha))
1916 mcp->mb[1] = loop_id;
1918 mcp->mb[1] = loop_id << 8;
1920 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1921 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1922 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1924 rval = qla2x00_mailbox_command(ha, mcp);
1926 /* Return mailbox statuses. */
1927 if (mb_ret != NULL) {
1928 mb_ret[0] = mcp->mb[0];
1929 mb_ret[1] = mcp->mb[1];
1930 mb_ret[6] = mcp->mb[6];
1931 mb_ret[7] = mcp->mb[7];
1934 if (rval != QLA_SUCCESS) {
1935 /* AV tmp code: need to change main mailbox_command function to
1936 * return ok even when the mailbox completion value is not
1937 * SUCCESS. The caller needs to be responsible to interpret
1938 * the return values of this mailbox command if we're not
1939 * to change too much of the existing code.
1941 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1944 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1945 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1946 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1947 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1948 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1949 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1952 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1959 * qla2x00_fabric_logout
1960 * Issue logout fabric port mailbox command.
1963 * ha = adapter block pointer.
1964 * loop_id = device loop ID.
1965 * TARGET_QUEUE_LOCK must be released.
1966 * ADAPTER_STATE_LOCK must be released.
1969 * qla2x00 local function return status code.
1975 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id)
1979 mbx_cmd_t *mcp = &mc;
1981 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1984 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1985 mcp->out_mb = MBX_1|MBX_0;
1986 if (HAS_EXTENDED_IDS(ha)) {
1987 mcp->mb[1] = loop_id;
1989 mcp->out_mb |= MBX_10;
1991 mcp->mb[1] = loop_id << 8;
1994 mcp->in_mb = MBX_1|MBX_0;
1997 rval = qla2x00_mailbox_command(ha, mcp);
1999 if (rval != QLA_SUCCESS) {
2001 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
2002 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
2005 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
2013 * qla2x00_full_login_lip
2014 * Issue full login LIP mailbox command.
2017 * ha = adapter block pointer.
2018 * TARGET_QUEUE_LOCK must be released.
2019 * ADAPTER_STATE_LOCK must be released.
2022 * qla2x00 local function return status code.
2028 qla2x00_full_login_lip(scsi_qla_host_t *ha)
2032 mbx_cmd_t *mcp = &mc;
2034 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
2037 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2041 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2045 rval = qla2x00_mailbox_command(ha, mcp);
2047 if (rval != QLA_SUCCESS) {
2049 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
2050 ha->instance, rval);)
2053 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
2061 * qla2x00_get_id_list
2064 * ha = adapter block pointer.
2067 * qla2x00 local function return status code.
2073 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
2078 mbx_cmd_t *mcp = &mc;
2080 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
2083 if (id_list == NULL)
2084 return QLA_FUNCTION_FAILED;
2086 mcp->mb[0] = MBC_GET_ID_LIST;
2087 mcp->mb[1] = MSW(id_list_dma);
2088 mcp->mb[2] = LSW(id_list_dma);
2089 mcp->mb[3] = MSW(MSD(id_list_dma));
2090 mcp->mb[6] = LSW(MSD(id_list_dma));
2091 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2092 mcp->in_mb = MBX_1|MBX_0;
2095 rval = qla2x00_mailbox_command(ha, mcp);
2097 if (rval != QLA_SUCCESS) {
2099 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
2100 ha->host_no, rval);)
2102 *entries = mcp->mb[1];
2103 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
2112 * Issue lun reset mailbox command.
2115 * ha = adapter block pointer.
2116 * loop_id = device loop ID.
2117 * lun = lun to be reset.
2118 * TARGET_QUEUE_LOCK must be released.
2119 * ADAPTER_STATE_LOCK must be released.
2122 * qla2x00 local function return status code.
2128 qla2x00_lun_reset(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun)
2132 mbx_cmd_t *mcp = &mc;
2134 mcp->mb[0] = MBC_LUN_RESET;
2135 if (HAS_EXTENDED_IDS(ha))
2136 mcp->mb[1] = loop_id;
2138 mcp->mb[1] = loop_id << 8;
2140 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2144 rval = qla2x00_mailbox_command(ha, mcp);
2146 if (rval != QLA_SUCCESS) {
2148 printk(KERN_WARNING "qla2x00_lun_reset(%d): failed = %d",
2149 (int)ha->instance, rval);
2158 * qla2x00_send_rnid_mbx
2159 * Issue RNID ELS using mailbox command
2162 * ha = adapter state pointer.
2163 * loop_id = loop ID of the target device.
2164 * data_fmt = currently supports only 0xDF.
2165 * buffer = buffer pointer.
2166 * buf_size = size of buffer.
2167 * mb_reg = pointer to return mailbox registers.
2170 * qla2x00 local function return status code.
2176 qla2x00_send_rnid_mbx(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t data_fmt,
2177 dma_addr_t buf_phys_addr, size_t buf_size, uint16_t *mb_reg)
2181 mbx_cmd_t *mcp = &mc;
2183 DEBUG11(printk("qla2x00_send_rnid_mbx(%ld): entered.\n",
2186 mcp->mb[0] = MBC_SEND_RNID_ELS;
2187 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2188 if (HAS_EXTENDED_IDS(ha)) {
2189 mcp->mb[1] = loop_id;
2190 mcp->mb[10] = data_fmt;
2191 mcp->out_mb |= MBX_10;
2193 mcp->mb[1] = (loop_id << 8) | data_fmt;
2195 mcp->mb[2] = MSW(buf_phys_addr);
2196 mcp->mb[3] = LSW(buf_phys_addr);
2197 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2198 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2200 mcp->in_mb = MBX_1|MBX_0;
2201 mcp->buf_size = buf_size;
2202 mcp->flags = MBX_DMA_IN;
2204 rval = qla2x00_mailbox_command(ha, mcp);
2206 if (rval != QLA_SUCCESS) {
2207 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2209 DEBUG2_3_11(printk("qla2x00_send_rnid_mbx(%ld): failed=%x "
2211 ha->host_no, mcp->mb[0], mcp->mb[1]);)
2214 DEBUG11(printk("qla2x00_send_rnid_mbx(%ld): done.\n",
2222 * qla2x00_set_rnid_params_mbx
2223 * Set RNID parameters using mailbox command
2226 * ha = adapter state pointer.
2227 * buffer = buffer pointer.
2228 * buf_size = size of buffer.
2229 * mb_reg = pointer to return mailbox registers.
2232 * qla2x00 local function return status code.
2238 qla2x00_set_rnid_params_mbx(scsi_qla_host_t *ha, dma_addr_t buf_phys_addr,
2239 size_t buf_size, uint16_t *mb_reg)
2243 mbx_cmd_t *mcp = &mc;
2245 DEBUG11(printk("qla2x00_set_rnid_params_mbx(%ld): entered.\n",
2248 mcp->mb[0] = MBC_SET_RNID_PARAMS;
2250 mcp->mb[2] = MSW(buf_phys_addr);
2251 mcp->mb[3] = LSW(buf_phys_addr);
2252 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2253 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2254 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2255 mcp->in_mb = MBX_1|MBX_0;
2256 mcp->buf_size = buf_size;
2257 mcp->flags = MBX_DMA_OUT;
2259 rval = qla2x00_mailbox_command(ha, mcp);
2261 if (rval != QLA_SUCCESS) {
2262 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2264 DEBUG2_3_11(printk("qla2x00_set_rnid_params_mbx(%ld): "
2265 "failed=%x mb[1]=%x.\n", ha->host_no, mcp->mb[0],
2269 DEBUG11(printk("qla2x00_set_rnid_params_mbx(%ld): done.\n",
2277 * qla2x00_get_rnid_params_mbx
2278 * Get RNID parameters using mailbox command
2281 * ha = adapter state pointer.
2282 * buffer = buffer pointer.
2283 * buf_size = size of buffer.
2284 * mb_reg = pointer to return mailbox registers.
2287 * qla2x00 local function return status code.
2293 qla2x00_get_rnid_params_mbx(scsi_qla_host_t *ha, dma_addr_t buf_phys_addr,
2294 size_t buf_size, uint16_t *mb_reg)
2298 mbx_cmd_t *mcp = &mc;
2300 DEBUG11(printk("qla2x00_get_rnid_params_mbx(%ld): entered.\n",
2303 mcp->mb[0] = MBC_GET_RNID_PARAMS;
2305 mcp->mb[2] = MSW(buf_phys_addr);
2306 mcp->mb[3] = LSW(buf_phys_addr);
2307 mcp->mb[6] = MSW(MSD(buf_phys_addr));
2308 mcp->mb[7] = LSW(MSD(buf_phys_addr));
2309 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2310 mcp->in_mb = MBX_1|MBX_0;
2311 mcp->buf_size = buf_size;
2312 mcp->flags = MBX_DMA_IN;
2314 rval = qla2x00_mailbox_command(ha, mcp);
2316 if (rval != QLA_SUCCESS) {
2317 memcpy(mb_reg, mcp->mb, 2 * 2); /* 2 status regs */
2319 DEBUG2_3_11(printk("qla2x00_get_rnid_params_mbx(%ld): "
2320 "failed=%x mb[1]=%x.\n", ha->host_no, mcp->mb[0],
2324 DEBUG11(printk("qla2x00_get_rnid_params_mbx(%ld): done.\n",
2332 * qla2x00_get_resource_cnts
2333 * Get current firmware resource counts.
2336 * ha = adapter block pointer.
2339 * qla2x00 local function return status code.
2345 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
2346 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
2350 mbx_cmd_t *mcp = &mc;
2352 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2354 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2355 mcp->out_mb = MBX_0;
2356 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2359 rval = qla2x00_mailbox_command(ha, mcp);
2361 if (rval != QLA_SUCCESS) {
2363 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2364 ha->host_no, mcp->mb[0]);)
2366 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2367 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
2368 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
2372 *cur_xchg_cnt = mcp->mb[3];
2374 *orig_xchg_cnt = mcp->mb[6];
2376 *cur_iocb_cnt = mcp->mb[7];
2378 *orig_iocb_cnt = mcp->mb[10];
2384 #if defined(QL_DEBUG_LEVEL_3)
2386 * qla2x00_get_fcal_position_map
2387 * Get FCAL (LILP) position map using mailbox command
2390 * ha = adapter state pointer.
2391 * pos_map = buffer pointer (can be NULL).
2394 * qla2x00 local function return status code.
2400 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
2404 mbx_cmd_t *mcp = &mc;
2406 dma_addr_t pmap_dma;
2408 pmap = pci_alloc_consistent(ha->pdev, FCAL_MAP_SIZE, &pmap_dma);
2410 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2411 __func__, ha->host_no));
2412 return QLA_MEMORY_ALLOC_FAILED;
2414 memset(pmap, 0, FCAL_MAP_SIZE);
2416 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2417 mcp->mb[2] = MSW(pmap_dma);
2418 mcp->mb[3] = LSW(pmap_dma);
2419 mcp->mb[6] = MSW(MSD(pmap_dma));
2420 mcp->mb[7] = LSW(MSD(pmap_dma));
2421 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2422 mcp->in_mb = MBX_1|MBX_0;
2423 mcp->buf_size = FCAL_MAP_SIZE;
2424 mcp->flags = MBX_DMA_IN;
2425 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2426 rval = qla2x00_mailbox_command(ha, mcp);
2428 if (rval == QLA_SUCCESS) {
2429 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2430 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2431 mcp->mb[1], (unsigned)pmap[0]));
2432 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2435 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2437 pci_free_consistent(ha->pdev, FCAL_MAP_SIZE, pmap, pmap_dma);
2439 if (rval != QLA_SUCCESS) {
2440 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2441 ha->host_no, rval));
2443 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));