blob: 3ba9a2b56556125d491bbbe493b149c393b82fe8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/delay.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12/*
13 * qla2x00_mailbox_command
14 * Issue mailbox command and waits for completion.
15 *
16 * Input:
17 * ha = adapter block pointer.
18 * mcp = driver internal mbx struct pointer.
19 *
20 * Output:
21 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
22 *
23 * Returns:
24 * 0 : QLA_SUCCESS = cmd performed success
25 * 1 : QLA_FUNCTION_FAILED (error encountered)
26 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
27 *
28 * Context:
29 * Kernel context.
30 */
31static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080032qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 int rval;
35 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070036 device_reg_t __iomem *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070037 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070038 uint8_t io_lock_on;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 uint16_t command;
40 uint16_t *iptr;
41 uint16_t __iomem *optr;
42 uint32_t cnt;
43 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080045 struct qla_hw_data *ha = vha->hw;
46 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070047
Seokmann Jub9b12f72009-03-24 09:08:18 -070048 if (ha->pdev->error_state > pci_channel_io_frozen)
49 return QLA_FUNCTION_TIMEOUT;
50
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070051 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080052 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080055 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080057 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070058
Andrew Vasquez85880802009-12-15 21:29:46 -080059 if (ha->flags.pci_channel_io_perm_failure) {
60 DEBUG(printk("%s(%ld): Perm failure on EEH, timeout MBX "
61 "Exiting.\n", __func__, vha->host_no));
62 return QLA_FUNCTION_TIMEOUT;
63 }
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070066 * Wait for active mailbox commands to finish by waiting at most tov
67 * seconds. This is to serialize actual issuing of mailbox cmds during
68 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080070 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
71 /* Timeout occurred. Return error. */
72 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
73 "Exiting.\n", __func__, base_vha->host_no));
74 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 }
76
77 ha->flags.mbox_busy = 1;
78 /* Save mailbox command for debug */
79 ha->mcp = mcp;
80
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070081 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080082 base_vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 spin_lock_irqsave(&ha->hardware_lock, flags);
85
86 /* Load mailbox registers. */
Andrew Vasqueze4289242007-07-19 15:05:56 -070087 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070088 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
89 else
90 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 iptr = mcp->mb;
93 command = mcp->mb[0];
94 mboxes = mcp->out_mb;
95
96 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
97 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070098 optr =
99 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 if (mboxes & BIT_0)
101 WRT_REG_WORD(optr, *iptr);
102
103 mboxes >>= 1;
104 optr++;
105 iptr++;
106 }
107
108#if defined(QL_DEBUG_LEVEL_1)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700109 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800110 __func__, base_vha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
112 printk("\n");
113 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
114 printk("\n");
115 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
116 printk("\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800117 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
118 optr);
119 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#endif
121
122 /* Issue set host interrupt command to send cmd out. */
123 ha->flags.mbox_int = 0;
124 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
125
126 /* Unlock mbx registers and wait for interrupt */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700127 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800128 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /* Wait for mbx cmd completion until timeout */
131
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800132 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
134
Andrew Vasqueze4289242007-07-19 15:05:56 -0700135 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700136 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
137 else
138 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 spin_unlock_irqrestore(&ha->hardware_lock, flags);
140
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800141 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700146 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800147 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Andrew Vasqueze4289242007-07-19 15:05:56 -0700149 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700150 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
151 else
152 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
156 while (!ha->flags.mbox_int) {
157 if (time_after(jiffies, wait_time))
158 break;
159
160 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800161 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Andrew Vasquez85880802009-12-15 21:29:46 -0800163 if (!ha->flags.mbox_int &&
164 !(IS_QLA2200(ha) &&
165 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800166 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 } /* while */
Andrew Vasquez85880802009-12-15 21:29:46 -0800168 DEBUG17(qla_printk(KERN_WARNING, ha,
169 "Waited %d sec\n",
170 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 /* Check whether we timed out */
174 if (ha->flags.mbox_int) {
175 uint16_t *iptr2;
176
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700177 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800178 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* Got interrupt. Clear the flag. */
181 ha->flags.mbox_int = 0;
182 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
183
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400184 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187 /* Load return mailbox registers. */
188 iptr2 = mcp->mb;
189 iptr = (uint16_t *)&ha->mailbox_out[0];
190 mboxes = mcp->in_mb;
191 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
192 if (mboxes & BIT_0)
193 *iptr2 = *iptr;
194
195 mboxes >>= 1;
196 iptr2++;
197 iptr++;
198 }
199 } else {
200
201#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
202 defined(QL_DEBUG_LEVEL_11)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700203 uint16_t mb0;
204 uint32_t ictrl;
205
Andrew Vasqueze4289242007-07-19 15:05:56 -0700206 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700207 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
208 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
209 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700210 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700211 ictrl = RD_REG_WORD(&reg->isp.ictrl);
212 }
213 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800214 __func__, base_vha->host_no, command);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700215 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800216 base_vha->host_no, ictrl, jiffies);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700217 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800218 base_vha->host_no, mb0);
219 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220#endif
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 rval = QLA_FUNCTION_TIMEOUT;
223 }
224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 ha->flags.mbox_busy = 0;
226
227 /* Clean up */
228 ha->mcp = NULL;
229
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800230 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700231 DEBUG11(printk("%s(%ld): checking for additional resp "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800232 "interrupt.\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800235 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700238 if (rval == QLA_FUNCTION_TIMEOUT &&
239 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800240 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
241 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700243 DEBUG(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800244 "isp_abort_needed.\n", __func__,
245 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700246 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800247 "isp_abort_needed.\n", __func__,
248 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 qla_printk(KERN_WARNING, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700250 "Mailbox command timeout occurred. Scheduling ISP "
Andrew Vasquez85880802009-12-15 21:29:46 -0800251 "abort. eeh_busy: 0x%x\n", ha->flags.eeh_busy);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800252 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
253 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700256 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800257 __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700258 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800259 "abort_isp\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 qla_printk(KERN_WARNING, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700261 "Mailbox command timeout occurred. Issuing ISP "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 "abort.\n");
263
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800264 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
265 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
266 if (qla2x00_abort_isp(base_vha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700267 /* Failed. retry later. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800268 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800270 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700271 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800272 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700273 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800274 __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 }
276 }
277
278 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800279 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700282 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800283 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700284 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800286 DEBUG11(printk("%s(%ld): done.\n", __func__,
287 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 }
289
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return rval;
291}
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800294qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800295 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296{
297 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800298 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 mbx_cmd_t mc;
300 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800302 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Andrew Vasqueze4289242007-07-19 15:05:56 -0700304 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800305 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
306 mcp->mb[8] = MSW(risc_addr);
307 mcp->out_mb = MBX_8|MBX_0;
308 } else {
309 mcp->mb[0] = MBC_LOAD_RISC_RAM;
310 mcp->out_mb = MBX_0;
311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 mcp->mb[1] = LSW(risc_addr);
313 mcp->mb[2] = MSW(req_dma);
314 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 mcp->mb[6] = MSW(MSD(req_dma));
316 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800317 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700318 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700319 mcp->mb[4] = MSW(risc_code_size);
320 mcp->mb[5] = LSW(risc_code_size);
321 mcp->out_mb |= MBX_5|MBX_4;
322 } else {
323 mcp->mb[4] = LSW(risc_code_size);
324 mcp->out_mb |= MBX_4;
325 }
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700328 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800330 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700333 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800334 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800336 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 }
338
339 return rval;
340}
341
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700342#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343/*
344 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700345 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 *
347 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700348 * ha = adapter block pointer.
349 * TARGET_QUEUE_LOCK must be released.
350 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 *
352 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700353 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 *
355 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700356 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 */
358int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800359qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
361 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800362 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 mbx_cmd_t mc;
364 mbx_cmd_t *mcp = &mc;
365
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800366 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700369 mcp->out_mb = MBX_0;
370 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700371 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700372 mcp->mb[1] = MSW(risc_addr);
373 mcp->mb[2] = LSW(risc_addr);
374 mcp->mb[3] = 0;
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700375 if (IS_QLA81XX(ha)) {
376 struct nvram_81xx *nv = ha->nvram;
377 mcp->mb[4] = (nv->enhanced_features &
378 EXTENDED_BB_CREDITS);
379 } else
380 mcp->mb[4] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700381 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700382 mcp->in_mb |= MBX_1;
383 } else {
384 mcp->mb[1] = LSW(risc_addr);
385 mcp->out_mb |= MBX_1;
386 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
387 mcp->mb[2] = 0;
388 mcp->out_mb |= MBX_2;
389 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391
Ravi Anandb93480e2008-04-03 13:13:25 -0700392 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800394 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700396 if (rval != QLA_SUCCESS) {
397 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800398 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700399 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700400 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700401 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800402 __func__, vha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700403 } else {
404 DEBUG11(printk("%s(%ld): done.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800405 vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700406 }
407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409 return rval;
410}
411
412/*
413 * qla2x00_get_fw_version
414 * Get firmware version.
415 *
416 * Input:
417 * ha: adapter state pointer.
418 * major: pointer for major number.
419 * minor: pointer for minor number.
420 * subminor: pointer for subminor number.
421 *
422 * Returns:
423 * qla2x00 local function return status code.
424 *
425 * Context:
426 * Kernel context.
427 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700428int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800429qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800430 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700431 uint32_t *mpi_caps, uint8_t *phy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432{
433 int rval;
434 mbx_cmd_t mc;
435 mbx_cmd_t *mcp = &mc;
436
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800437 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
439 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
440 mcp->out_mb = MBX_0;
441 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800442 if (IS_QLA81XX(vha->hw))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700443 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700445 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800446 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700447 if (rval != QLA_SUCCESS)
448 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 /* Return mailbox data. */
451 *major = mcp->mb[1];
452 *minor = mcp->mb[2];
453 *subminor = mcp->mb[3];
454 *attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800455 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 *memory = 0x1FFFF; /* Defaults to 128KB. */
457 else
458 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800459 if (IS_QLA81XX(vha->hw)) {
Andrew Vasquez55a96152009-03-24 09:08:03 -0700460 mpi[0] = mcp->mb[10] & 0xff;
461 mpi[1] = mcp->mb[11] >> 8;
462 mpi[2] = mcp->mb[11] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800463 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
Andrew Vasquez55a96152009-03-24 09:08:03 -0700464 phy[0] = mcp->mb[8] & 0xff;
465 phy[1] = mcp->mb[9] >> 8;
466 phy[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800467 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700468failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 if (rval != QLA_SUCCESS) {
470 /*EMPTY*/
471 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800472 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 } else {
474 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800475 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700477 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478}
479
480/*
481 * qla2x00_get_fw_options
482 * Set firmware options.
483 *
484 * Input:
485 * ha = adapter block pointer.
486 * fwopt = pointer for firmware options.
487 *
488 * Returns:
489 * qla2x00 local function return status code.
490 *
491 * Context:
492 * Kernel context.
493 */
494int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800495qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 int rval;
498 mbx_cmd_t mc;
499 mbx_cmd_t *mcp = &mc;
500
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800501 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
504 mcp->out_mb = MBX_0;
505 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700506 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800508 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 if (rval != QLA_SUCCESS) {
511 /*EMPTY*/
512 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800513 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700515 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 fwopts[1] = mcp->mb[1];
517 fwopts[2] = mcp->mb[2];
518 fwopts[3] = mcp->mb[3];
519
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800520 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522
523 return rval;
524}
525
526
527/*
528 * qla2x00_set_fw_options
529 * Set firmware options.
530 *
531 * Input:
532 * ha = adapter block pointer.
533 * fwopt = pointer for firmware options.
534 *
535 * Returns:
536 * qla2x00 local function return status code.
537 *
538 * Context:
539 * Kernel context.
540 */
541int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800542qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
544 int rval;
545 mbx_cmd_t mc;
546 mbx_cmd_t *mcp = &mc;
547
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800548 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
551 mcp->mb[1] = fwopts[1];
552 mcp->mb[2] = fwopts[2];
553 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700554 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800556 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700557 mcp->in_mb |= MBX_1;
558 } else {
559 mcp->mb[10] = fwopts[10];
560 mcp->mb[11] = fwopts[11];
561 mcp->mb[12] = 0; /* Undocumented, but used */
562 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
563 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700564 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800566 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700568 fwopts[0] = mcp->mb[0];
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 if (rval != QLA_SUCCESS) {
571 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700572 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800573 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 } else {
575 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800576 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 }
578
579 return rval;
580}
581
582/*
583 * qla2x00_mbx_reg_test
584 * Mailbox register wrap test.
585 *
586 * Input:
587 * ha = adapter block pointer.
588 * TARGET_QUEUE_LOCK must be released.
589 * ADAPTER_STATE_LOCK must be released.
590 *
591 * Returns:
592 * qla2x00 local function return status code.
593 *
594 * Context:
595 * Kernel context.
596 */
597int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800598qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
600 int rval;
601 mbx_cmd_t mc;
602 mbx_cmd_t *mcp = &mc;
603
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800604 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
607 mcp->mb[1] = 0xAAAA;
608 mcp->mb[2] = 0x5555;
609 mcp->mb[3] = 0xAA55;
610 mcp->mb[4] = 0x55AA;
611 mcp->mb[5] = 0xA5A5;
612 mcp->mb[6] = 0x5A5A;
613 mcp->mb[7] = 0x2525;
614 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
615 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700616 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800618 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 if (rval == QLA_SUCCESS) {
621 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
622 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
623 rval = QLA_FUNCTION_FAILED;
624 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
625 mcp->mb[7] != 0x2525)
626 rval = QLA_FUNCTION_FAILED;
627 }
628
629 if (rval != QLA_SUCCESS) {
630 /*EMPTY*/
631 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800632 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 } else {
634 /*EMPTY*/
635 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800636 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638
639 return rval;
640}
641
642/*
643 * qla2x00_verify_checksum
644 * Verify firmware checksum.
645 *
646 * Input:
647 * ha = adapter block pointer.
648 * TARGET_QUEUE_LOCK must be released.
649 * ADAPTER_STATE_LOCK must be released.
650 *
651 * Returns:
652 * qla2x00 local function return status code.
653 *
654 * Context:
655 * Kernel context.
656 */
657int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800658qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
660 int rval;
661 mbx_cmd_t mc;
662 mbx_cmd_t *mcp = &mc;
663
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800664 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
666 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700667 mcp->out_mb = MBX_0;
668 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800669 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700670 mcp->mb[1] = MSW(risc_addr);
671 mcp->mb[2] = LSW(risc_addr);
672 mcp->out_mb |= MBX_2|MBX_1;
673 mcp->in_mb |= MBX_2|MBX_1;
674 } else {
675 mcp->mb[1] = LSW(risc_addr);
676 mcp->out_mb |= MBX_1;
677 mcp->in_mb |= MBX_1;
678 }
679
Ravi Anandb93480e2008-04-03 13:13:25 -0700680 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800682 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
684 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700685 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800686 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
Andrew Vasqueze4289242007-07-19 15:05:56 -0700687 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800689 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691
692 return rval;
693}
694
695/*
696 * qla2x00_issue_iocb
697 * Issue IOCB using mailbox command
698 *
699 * Input:
700 * ha = adapter state pointer.
701 * buffer = buffer pointer.
702 * phys_addr = physical address of buffer.
703 * size = size of buffer.
704 * TARGET_QUEUE_LOCK must be released.
705 * ADAPTER_STATE_LOCK must be released.
706 *
707 * Returns:
708 * qla2x00 local function return status code.
709 *
710 * Context:
711 * Kernel context.
712 */
Adrian Bunk3b8117b2008-04-24 15:21:28 -0700713static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800714qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700715 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716{
717 int rval;
718 mbx_cmd_t mc;
719 mbx_cmd_t *mcp = &mc;
720
721 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
722 mcp->mb[1] = 0;
723 mcp->mb[2] = MSW(phys_addr);
724 mcp->mb[3] = LSW(phys_addr);
725 mcp->mb[6] = MSW(MSD(phys_addr));
726 mcp->mb[7] = LSW(MSD(phys_addr));
727 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
728 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700729 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800731 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 if (rval != QLA_SUCCESS) {
734 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700735 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800736 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700738 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
739
740 /* Mask reserved bits. */
741 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800742 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744
745 return rval;
746}
747
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700748int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800749qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700750 size_t size)
751{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800752 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700753 MBX_TOV_SECONDS);
754}
755
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756/*
757 * qla2x00_abort_command
758 * Abort command aborts a specified IOCB.
759 *
760 * Input:
761 * ha = adapter block pointer.
762 * sp = SB structure pointer.
763 *
764 * Returns:
765 * qla2x00 local function return status code.
766 *
767 * Context:
768 * Kernel context.
769 */
770int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700771qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772{
773 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800775 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 mbx_cmd_t mc;
777 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700778 fc_port_t *fcport = sp->fcport;
779 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800780 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700781 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800783 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700785 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800787 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 break;
789 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700790 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 if (handle == MAX_OUTSTANDING_COMMANDS) {
793 /* command not found */
794 return QLA_FUNCTION_FAILED;
795 }
796
797 mcp->mb[0] = MBC_ABORT_COMMAND;
798 if (HAS_EXTENDED_IDS(ha))
799 mcp->mb[1] = fcport->loop_id;
800 else
801 mcp->mb[1] = fcport->loop_id << 8;
802 mcp->mb[2] = (uint16_t)handle;
803 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500804 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
806 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700807 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800809 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 if (rval != QLA_SUCCESS) {
812 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800813 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800816 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 }
818
819 return rval;
820}
821
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700823qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700825 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 mbx_cmd_t mc;
827 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800828 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800829 struct req_que *req;
830 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800832 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700833
Andrew Vasquez523ec772008-04-03 13:13:24 -0700834 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800835 vha = fcport->vha;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700836 req = vha->hw->req_q_map[tag];
837 rsp = vha->hw->rsp_q_map[tag];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700839 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800840 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 mcp->mb[1] = fcport->loop_id;
842 mcp->mb[10] = 0;
843 mcp->out_mb |= MBX_10;
844 } else {
845 mcp->mb[1] = fcport->loop_id << 8;
846 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800847 mcp->mb[2] = vha->hw->loop_reset_delay;
848 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700851 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800853 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700855 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800856 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700857 }
858
859 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800860 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
861 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700862 if (rval2 != QLA_SUCCESS) {
863 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800864 "(%x).\n", __func__, vha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800866 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700867 }
868
869 return rval;
870}
871
872int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700873qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700874{
875 int rval, rval2;
876 mbx_cmd_t mc;
877 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800878 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800879 struct req_que *req;
880 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700881
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800882 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700883
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800884 vha = fcport->vha;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700885 req = vha->hw->req_q_map[tag];
886 rsp = vha->hw->rsp_q_map[tag];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700887 mcp->mb[0] = MBC_LUN_RESET;
888 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800889 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700890 mcp->mb[1] = fcport->loop_id;
891 else
892 mcp->mb[1] = fcport->loop_id << 8;
893 mcp->mb[2] = l;
894 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700896
897 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700898 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700899 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800900 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700901 if (rval != QLA_SUCCESS) {
902 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800903 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700904 }
905
906 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800907 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
908 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700909 if (rval2 != QLA_SUCCESS) {
910 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800911 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700912 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800913 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914 }
915
916 return rval;
917}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 * qla2x00_get_adapter_id
921 * Get adapter ID and topology.
922 *
923 * Input:
924 * ha = adapter block pointer.
925 * id = pointer for loop ID.
926 * al_pa = pointer for AL_PA.
927 * area = pointer for area.
928 * domain = pointer for domain.
929 * top = pointer for topology.
930 * TARGET_QUEUE_LOCK must be released.
931 * ADAPTER_STATE_LOCK must be released.
932 *
933 * Returns:
934 * qla2x00 local function return status code.
935 *
936 * Context:
937 * Kernel context.
938 */
939int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800940qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700941 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942{
943 int rval;
944 mbx_cmd_t mc;
945 mbx_cmd_t *mcp = &mc;
946
947 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800948 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800951 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800952 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700953 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquezbad70012009-04-06 22:33:38 -0700954 if (IS_QLA81XX(vha->hw))
955 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -0700956 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800959 if (mcp->mb[0] == MBS_COMMAND_ERROR)
960 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700961 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
962 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 /* Return data. */
965 *id = mcp->mb[1];
966 *al_pa = LSB(mcp->mb[2]);
967 *area = MSB(mcp->mb[2]);
968 *domain = LSB(mcp->mb[3]);
969 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700970 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 if (rval != QLA_SUCCESS) {
973 /*EMPTY*/
974 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800975 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800978 vha->host_no));
Andrew Vasquezbad70012009-04-06 22:33:38 -0700979
980 if (IS_QLA81XX(vha->hw)) {
981 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
982 vha->fcoe_fcf_idx = mcp->mb[10];
983 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
984 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
985 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
986 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
987 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
988 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
989 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 }
991
992 return rval;
993}
994
995/*
996 * qla2x00_get_retry_cnt
997 * Get current firmware login retry count and delay.
998 *
999 * Input:
1000 * ha = adapter block pointer.
1001 * retry_cnt = pointer to login retry count.
1002 * tov = pointer to login timeout value.
1003 *
1004 * Returns:
1005 * qla2x00 local function return status code.
1006 *
1007 * Context:
1008 * Kernel context.
1009 */
1010int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001011qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 uint16_t *r_a_tov)
1013{
1014 int rval;
1015 uint16_t ratov;
1016 mbx_cmd_t mc;
1017 mbx_cmd_t *mcp = &mc;
1018
1019 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001020 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1023 mcp->out_mb = MBX_0;
1024 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001025 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001027 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
1029 if (rval != QLA_SUCCESS) {
1030 /*EMPTY*/
1031 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001032 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 } else {
1034 /* Convert returned data and check our values. */
1035 *r_a_tov = mcp->mb[3] / 2;
1036 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1037 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1038 /* Update to the larger values */
1039 *retry_cnt = (uint8_t)mcp->mb[1];
1040 *tov = ratov;
1041 }
1042
1043 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001044 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046
1047 return rval;
1048}
1049
1050/*
1051 * qla2x00_init_firmware
1052 * Initialize adapter firmware.
1053 *
1054 * Input:
1055 * ha = adapter block pointer.
1056 * dptr = Initialization control block pointer.
1057 * size = size of initialization control block.
1058 * TARGET_QUEUE_LOCK must be released.
1059 * ADAPTER_STATE_LOCK must be released.
1060 *
1061 * Returns:
1062 * qla2x00 local function return status code.
1063 *
1064 * Context:
1065 * Kernel context.
1066 */
1067int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001068qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069{
1070 int rval;
1071 mbx_cmd_t mc;
1072 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001073 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001076 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001078 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001079 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1080 else
1081 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1082
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001083 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 mcp->mb[2] = MSW(ha->init_cb_dma);
1085 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1087 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001088 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1089 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1090 mcp->mb[1] = BIT_0;
1091 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1092 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1093 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1094 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1095 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1096 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1097 }
1098 mcp->in_mb = MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 mcp->buf_size = size;
1100 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001101 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001102 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 if (rval != QLA_SUCCESS) {
1105 /*EMPTY*/
1106 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1107 "mb0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001108 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 } else {
1110 /*EMPTY*/
1111 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001112 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 }
1114
1115 return rval;
1116}
1117
1118/*
1119 * qla2x00_get_port_database
1120 * Issue normal/enhanced get port database mailbox command
1121 * and copy device name as necessary.
1122 *
1123 * Input:
1124 * ha = adapter state pointer.
1125 * dev = structure pointer.
1126 * opt = enhanced cmd option byte.
1127 *
1128 * Returns:
1129 * qla2x00 local function return status code.
1130 *
1131 * Context:
1132 * Kernel context.
1133 */
1134int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001135qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
1137 int rval;
1138 mbx_cmd_t mc;
1139 mbx_cmd_t *mcp = &mc;
1140 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001141 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001143 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001145 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001147 pd24 = NULL;
1148 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001150 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001151 "structure.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 return QLA_MEMORY_ALLOC_FAILED;
1153 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001154 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001156 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001157 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 mcp->mb[2] = MSW(pd_dma);
1160 mcp->mb[3] = LSW(pd_dma);
1161 mcp->mb[6] = MSW(MSD(pd_dma));
1162 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001163 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001164 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001166 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001167 mcp->mb[1] = fcport->loop_id;
1168 mcp->mb[10] = opt;
1169 mcp->out_mb |= MBX_10|MBX_1;
1170 mcp->in_mb |= MBX_1;
1171 } else if (HAS_EXTENDED_IDS(ha)) {
1172 mcp->mb[1] = fcport->loop_id;
1173 mcp->mb[10] = opt;
1174 mcp->out_mb |= MBX_10|MBX_1;
1175 } else {
1176 mcp->mb[1] = fcport->loop_id << 8 | opt;
1177 mcp->out_mb |= MBX_1;
1178 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001179 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1180 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 mcp->flags = MBX_DMA_IN;
1182 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001183 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 if (rval != QLA_SUCCESS)
1185 goto gpd_error_out;
1186
Andrew Vasqueze4289242007-07-19 15:05:56 -07001187 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001188 pd24 = (struct port_database_24xx *) pd;
1189
1190 /* Check for logged in state. */
1191 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1192 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1193 DEBUG2(printk("%s(%ld): Unable to verify "
1194 "login-state (%x/%x) for loop_id %x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001195 __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001196 pd24->current_login_state,
1197 pd24->last_login_state, fcport->loop_id));
1198 rval = QLA_FUNCTION_FAILED;
1199 goto gpd_error_out;
1200 }
1201
1202 /* Names are little-endian. */
1203 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1204 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1205
1206 /* Get port_id of device. */
1207 fcport->d_id.b.domain = pd24->port_id[0];
1208 fcport->d_id.b.area = pd24->port_id[1];
1209 fcport->d_id.b.al_pa = pd24->port_id[2];
1210 fcport->d_id.b.rsvd_1 = 0;
1211
1212 /* If not target must be initiator or unknown type. */
1213 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1214 fcport->port_type = FCT_INITIATOR;
1215 else
1216 fcport->port_type = FCT_TARGET;
1217 } else {
1218 /* Check for logged in state. */
1219 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1220 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1221 rval = QLA_FUNCTION_FAILED;
1222 goto gpd_error_out;
1223 }
1224
1225 /* Names are little-endian. */
1226 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1227 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1228
1229 /* Get port_id of device. */
1230 fcport->d_id.b.domain = pd->port_id[0];
1231 fcport->d_id.b.area = pd->port_id[3];
1232 fcport->d_id.b.al_pa = pd->port_id[2];
1233 fcport->d_id.b.rsvd_1 = 0;
1234
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001235 /* If not target must be initiator or unknown type. */
1236 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1237 fcport->port_type = FCT_INITIATOR;
1238 else
1239 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001240
1241 /* Passback COS information. */
1242 fcport->supported_classes = (pd->options & BIT_4) ?
1243 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
1245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246gpd_error_out:
1247 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1248
1249 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001250 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001251 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001253 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 }
1255
1256 return rval;
1257}
1258
1259/*
1260 * qla2x00_get_firmware_state
1261 * Get adapter firmware state.
1262 *
1263 * Input:
1264 * ha = adapter block pointer.
1265 * dptr = pointer for firmware state.
1266 * TARGET_QUEUE_LOCK must be released.
1267 * ADAPTER_STATE_LOCK must be released.
1268 *
1269 * Returns:
1270 * qla2x00 local function return status code.
1271 *
1272 * Context:
1273 * Kernel context.
1274 */
1275int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001276qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277{
1278 int rval;
1279 mbx_cmd_t mc;
1280 mbx_cmd_t *mcp = &mc;
1281
1282 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001283 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1286 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001287 if (IS_FWI2_CAPABLE(vha->hw))
1288 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1289 else
1290 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001291 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001293 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001295 /* Return firmware states. */
1296 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001297 if (IS_FWI2_CAPABLE(vha->hw)) {
1298 states[1] = mcp->mb[2];
1299 states[2] = mcp->mb[3];
1300 states[3] = mcp->mb[4];
1301 states[4] = mcp->mb[5];
1302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 if (rval != QLA_SUCCESS) {
1305 /*EMPTY*/
1306 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001307 "failed=%x.\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 } else {
1309 /*EMPTY*/
1310 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001311 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313
1314 return rval;
1315}
1316
1317/*
1318 * qla2x00_get_port_name
1319 * Issue get port name mailbox command.
1320 * Returned name is in big endian format.
1321 *
1322 * Input:
1323 * ha = adapter block pointer.
1324 * loop_id = loop ID of device.
1325 * name = pointer for name.
1326 * TARGET_QUEUE_LOCK must be released.
1327 * ADAPTER_STATE_LOCK must be released.
1328 *
1329 * Returns:
1330 * qla2x00 local function return status code.
1331 *
1332 * Context:
1333 * Kernel context.
1334 */
1335int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001336qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 uint8_t opt)
1338{
1339 int rval;
1340 mbx_cmd_t mc;
1341 mbx_cmd_t *mcp = &mc;
1342
1343 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001344 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
1346 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001347 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001348 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001349 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 mcp->mb[1] = loop_id;
1351 mcp->mb[10] = opt;
1352 mcp->out_mb |= MBX_10;
1353 } else {
1354 mcp->mb[1] = loop_id << 8 | opt;
1355 }
1356
1357 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001358 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001360 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 if (rval != QLA_SUCCESS) {
1363 /*EMPTY*/
1364 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001365 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 } else {
1367 if (name != NULL) {
1368 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001369 name[0] = MSB(mcp->mb[2]);
1370 name[1] = LSB(mcp->mb[2]);
1371 name[2] = MSB(mcp->mb[3]);
1372 name[3] = LSB(mcp->mb[3]);
1373 name[4] = MSB(mcp->mb[6]);
1374 name[5] = LSB(mcp->mb[6]);
1375 name[6] = MSB(mcp->mb[7]);
1376 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 }
1378
1379 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001380 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 }
1382
1383 return rval;
1384}
1385
1386/*
1387 * qla2x00_lip_reset
1388 * Issue LIP reset mailbox command.
1389 *
1390 * Input:
1391 * ha = adapter block pointer.
1392 * TARGET_QUEUE_LOCK must be released.
1393 * ADAPTER_STATE_LOCK must be released.
1394 *
1395 * Returns:
1396 * qla2x00 local function return status code.
1397 *
1398 * Context:
1399 * Kernel context.
1400 */
1401int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001402qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
1404 int rval;
1405 mbx_cmd_t mc;
1406 mbx_cmd_t *mcp = &mc;
1407
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001408 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001410 if (IS_QLA81XX(vha->hw)) {
1411 /* Logout across all FCFs. */
1412 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1413 mcp->mb[1] = BIT_1;
1414 mcp->mb[2] = 0;
1415 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1416 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001417 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001418 mcp->mb[1] = BIT_6;
1419 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001420 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001421 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001423 mcp->mb[0] = MBC_LIP_RESET;
1424 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001425 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001426 mcp->mb[1] = 0x00ff;
1427 mcp->mb[10] = 0;
1428 mcp->out_mb |= MBX_10;
1429 } else {
1430 mcp->mb[1] = 0xff00;
1431 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001432 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001433 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001436 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001438 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440 if (rval != QLA_SUCCESS) {
1441 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001442 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001443 __func__, vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 } else {
1445 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001446 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 }
1448
1449 return rval;
1450}
1451
1452/*
1453 * qla2x00_send_sns
1454 * Send SNS command.
1455 *
1456 * Input:
1457 * ha = adapter block pointer.
1458 * sns = pointer for command.
1459 * cmd_size = command size.
1460 * buf_size = response/command size.
1461 * TARGET_QUEUE_LOCK must be released.
1462 * ADAPTER_STATE_LOCK must be released.
1463 *
1464 * Returns:
1465 * qla2x00 local function return status code.
1466 *
1467 * Context:
1468 * Kernel context.
1469 */
1470int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001471qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 uint16_t cmd_size, size_t buf_size)
1473{
1474 int rval;
1475 mbx_cmd_t mc;
1476 mbx_cmd_t *mcp = &mc;
1477
1478 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001479 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001482 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1483 mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1486 mcp->mb[1] = cmd_size;
1487 mcp->mb[2] = MSW(sns_phys_address);
1488 mcp->mb[3] = LSW(sns_phys_address);
1489 mcp->mb[6] = MSW(MSD(sns_phys_address));
1490 mcp->mb[7] = LSW(MSD(sns_phys_address));
1491 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1492 mcp->in_mb = MBX_0|MBX_1;
1493 mcp->buf_size = buf_size;
1494 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001495 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1496 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497
1498 if (rval != QLA_SUCCESS) {
1499 /*EMPTY*/
1500 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001501 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001503 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 } else {
1505 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001506 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 }
1508
1509 return rval;
1510}
1511
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001512int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001513qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001514 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1515{
1516 int rval;
1517
1518 struct logio_entry_24xx *lg;
1519 dma_addr_t lg_dma;
1520 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001521 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001522 struct req_que *req;
1523 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001524
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001525 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001526
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001527 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001528 req = ha->req_q_map[0];
1529 else
1530 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001531 rsp = req->rsp;
1532
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001533 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1534 if (lg == NULL) {
1535 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001536 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001537 return QLA_MEMORY_ALLOC_FAILED;
1538 }
1539 memset(lg, 0, sizeof(struct logio_entry_24xx));
1540
1541 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1542 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001543 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001544 lg->nport_handle = cpu_to_le16(loop_id);
1545 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1546 if (opt & BIT_0)
1547 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001548 if (opt & BIT_1)
1549 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001550 lg->port_id[0] = al_pa;
1551 lg->port_id[1] = area;
1552 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001553 lg->vp_index = vha->vp_idx;
1554 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001555 if (rval != QLA_SUCCESS) {
1556 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001557 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001558 } else if (lg->entry_status != 0) {
1559 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001560 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001561 lg->entry_status));
1562 rval = QLA_FUNCTION_FAILED;
1563 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1564 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1565 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1566
1567 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1568 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001569 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001570 iop[1]));
1571
1572 switch (iop[0]) {
1573 case LSC_SCODE_PORTID_USED:
1574 mb[0] = MBS_PORT_ID_USED;
1575 mb[1] = LSW(iop[1]);
1576 break;
1577 case LSC_SCODE_NPORT_USED:
1578 mb[0] = MBS_LOOP_ID_USED;
1579 break;
1580 case LSC_SCODE_NOLINK:
1581 case LSC_SCODE_NOIOCB:
1582 case LSC_SCODE_NOXCB:
1583 case LSC_SCODE_CMD_FAILED:
1584 case LSC_SCODE_NOFABRIC:
1585 case LSC_SCODE_FW_NOT_READY:
1586 case LSC_SCODE_NOT_LOGGED_IN:
1587 case LSC_SCODE_NOPCB:
1588 case LSC_SCODE_ELS_REJECT:
1589 case LSC_SCODE_CMD_PARAM_ERR:
1590 case LSC_SCODE_NONPORT:
1591 case LSC_SCODE_LOGGED_IN:
1592 case LSC_SCODE_NOFLOGI_ACC:
1593 default:
1594 mb[0] = MBS_COMMAND_ERROR;
1595 break;
1596 }
1597 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001598 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001599
1600 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1601
1602 mb[0] = MBS_COMMAND_COMPLETE;
1603 mb[1] = 0;
1604 if (iop[0] & BIT_4) {
1605 if (iop[0] & BIT_8)
1606 mb[1] |= BIT_1;
1607 } else
1608 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001609
1610 /* Passback COS information. */
1611 mb[10] = 0;
1612 if (lg->io_parameter[7] || lg->io_parameter[8])
1613 mb[10] |= BIT_0; /* Class 2. */
1614 if (lg->io_parameter[9] || lg->io_parameter[10])
1615 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001616 }
1617
1618 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1619
1620 return rval;
1621}
1622
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623/*
1624 * qla2x00_login_fabric
1625 * Issue login fabric port mailbox command.
1626 *
1627 * Input:
1628 * ha = adapter block pointer.
1629 * loop_id = device loop ID.
1630 * domain = device domain.
1631 * area = device area.
1632 * al_pa = device AL_PA.
1633 * status = pointer for return status.
1634 * opt = command options.
1635 * TARGET_QUEUE_LOCK must be released.
1636 * ADAPTER_STATE_LOCK must be released.
1637 *
1638 * Returns:
1639 * qla2x00 local function return status code.
1640 *
1641 * Context:
1642 * Kernel context.
1643 */
1644int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001645qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1647{
1648 int rval;
1649 mbx_cmd_t mc;
1650 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001651 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001653 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1656 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1657 if (HAS_EXTENDED_IDS(ha)) {
1658 mcp->mb[1] = loop_id;
1659 mcp->mb[10] = opt;
1660 mcp->out_mb |= MBX_10;
1661 } else {
1662 mcp->mb[1] = (loop_id << 8) | opt;
1663 }
1664 mcp->mb[2] = domain;
1665 mcp->mb[3] = area << 8 | al_pa;
1666
1667 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1668 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1669 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001670 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
1672 /* Return mailbox statuses. */
1673 if (mb != NULL) {
1674 mb[0] = mcp->mb[0];
1675 mb[1] = mcp->mb[1];
1676 mb[2] = mcp->mb[2];
1677 mb[6] = mcp->mb[6];
1678 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001679 /* COS retrieved from Get-Port-Database mailbox command. */
1680 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 }
1682
1683 if (rval != QLA_SUCCESS) {
1684 /* RLU tmp code: need to change main mailbox_command function to
1685 * return ok even when the mailbox completion value is not
1686 * SUCCESS. The caller needs to be responsible to interpret
1687 * the return values of this mailbox command if we're not
1688 * to change too much of the existing code.
1689 */
1690 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1691 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1692 mcp->mb[0] == 0x4006)
1693 rval = QLA_SUCCESS;
1694
1695 /*EMPTY*/
1696 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001697 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001698 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 } else {
1700 /*EMPTY*/
1701 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001702 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
1704
1705 return rval;
1706}
1707
1708/*
1709 * qla2x00_login_local_device
1710 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001711 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 * Input:
1713 * ha = adapter block pointer.
1714 * loop_id = device loop ID.
1715 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001716 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 * Returns:
1718 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001719 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 * Context:
1721 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001722 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 */
1724int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001725qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 uint16_t *mb_ret, uint8_t opt)
1727{
1728 int rval;
1729 mbx_cmd_t mc;
1730 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001731 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
Andrew Vasqueze4289242007-07-19 15:05:56 -07001733 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001734 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001735 fcport->d_id.b.domain, fcport->d_id.b.area,
1736 fcport->d_id.b.al_pa, mb_ret, opt);
1737
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001738 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739
1740 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1741 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001742 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001744 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 mcp->mb[2] = opt;
1746 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1747 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1748 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1749 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001750 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 /* Return mailbox statuses. */
1753 if (mb_ret != NULL) {
1754 mb_ret[0] = mcp->mb[0];
1755 mb_ret[1] = mcp->mb[1];
1756 mb_ret[6] = mcp->mb[6];
1757 mb_ret[7] = mcp->mb[7];
1758 }
1759
1760 if (rval != QLA_SUCCESS) {
1761 /* AV tmp code: need to change main mailbox_command function to
1762 * return ok even when the mailbox completion value is not
1763 * SUCCESS. The caller needs to be responsible to interpret
1764 * the return values of this mailbox command if we're not
1765 * to change too much of the existing code.
1766 */
1767 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1768 rval = QLA_SUCCESS;
1769
1770 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001771 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001772 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001774 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001775 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 } else {
1777 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001778 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 }
1780
1781 return (rval);
1782}
1783
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001784int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001785qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001786 uint8_t area, uint8_t al_pa)
1787{
1788 int rval;
1789 struct logio_entry_24xx *lg;
1790 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001791 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001792 struct req_que *req;
1793 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001794
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001795 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001796
1797 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1798 if (lg == NULL) {
1799 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001800 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001801 return QLA_MEMORY_ALLOC_FAILED;
1802 }
1803 memset(lg, 0, sizeof(struct logio_entry_24xx));
1804
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001805 if (ql2xmaxqueues > 1)
1806 req = ha->req_q_map[0];
1807 else
1808 req = vha->req;
1809 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001810 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1811 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001812 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001813 lg->nport_handle = cpu_to_le16(loop_id);
1814 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001815 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001816 lg->port_id[0] = al_pa;
1817 lg->port_id[1] = area;
1818 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001819 lg->vp_index = vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001820
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001821 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001822 if (rval != QLA_SUCCESS) {
1823 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001824 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001825 } else if (lg->entry_status != 0) {
1826 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001827 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001828 lg->entry_status));
1829 rval = QLA_FUNCTION_FAILED;
1830 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001831 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001832 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001833 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001834 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001835 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001836 } else {
1837 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001838 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001839 }
1840
1841 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1842
1843 return rval;
1844}
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846/*
1847 * qla2x00_fabric_logout
1848 * Issue logout fabric port mailbox command.
1849 *
1850 * Input:
1851 * ha = adapter block pointer.
1852 * loop_id = device loop ID.
1853 * TARGET_QUEUE_LOCK must be released.
1854 * ADAPTER_STATE_LOCK must be released.
1855 *
1856 * Returns:
1857 * qla2x00 local function return status code.
1858 *
1859 * Context:
1860 * Kernel context.
1861 */
1862int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001863qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001864 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865{
1866 int rval;
1867 mbx_cmd_t mc;
1868 mbx_cmd_t *mcp = &mc;
1869
1870 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001871 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
1873 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1874 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001875 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 mcp->mb[1] = loop_id;
1877 mcp->mb[10] = 0;
1878 mcp->out_mb |= MBX_10;
1879 } else {
1880 mcp->mb[1] = loop_id << 8;
1881 }
1882
1883 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001884 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001886 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888 if (rval != QLA_SUCCESS) {
1889 /*EMPTY*/
1890 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001891 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 } else {
1893 /*EMPTY*/
1894 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001895 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
1897
1898 return rval;
1899}
1900
1901/*
1902 * qla2x00_full_login_lip
1903 * Issue full login LIP mailbox command.
1904 *
1905 * Input:
1906 * ha = adapter block pointer.
1907 * TARGET_QUEUE_LOCK must be released.
1908 * ADAPTER_STATE_LOCK must be released.
1909 *
1910 * Returns:
1911 * qla2x00 local function return status code.
1912 *
1913 * Context:
1914 * Kernel context.
1915 */
1916int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001917qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
1919 int rval;
1920 mbx_cmd_t mc;
1921 mbx_cmd_t *mcp = &mc;
1922
1923 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001924 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
1926 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001927 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001928 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 mcp->mb[3] = 0;
1930 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1931 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001932 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001934 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
1936 if (rval != QLA_SUCCESS) {
1937 /*EMPTY*/
1938 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001939 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 } else {
1941 /*EMPTY*/
1942 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001943 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 }
1945
1946 return rval;
1947}
1948
1949/*
1950 * qla2x00_get_id_list
1951 *
1952 * Input:
1953 * ha = adapter block pointer.
1954 *
1955 * Returns:
1956 * qla2x00 local function return status code.
1957 *
1958 * Context:
1959 * Kernel context.
1960 */
1961int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001962qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 uint16_t *entries)
1964{
1965 int rval;
1966 mbx_cmd_t mc;
1967 mbx_cmd_t *mcp = &mc;
1968
1969 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001970 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
1972 if (id_list == NULL)
1973 return QLA_FUNCTION_FAILED;
1974
1975 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001976 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001977 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001978 mcp->mb[2] = MSW(id_list_dma);
1979 mcp->mb[3] = LSW(id_list_dma);
1980 mcp->mb[6] = MSW(MSD(id_list_dma));
1981 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001982 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001983 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001984 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001985 } else {
1986 mcp->mb[1] = MSW(id_list_dma);
1987 mcp->mb[2] = LSW(id_list_dma);
1988 mcp->mb[3] = MSW(MSD(id_list_dma));
1989 mcp->mb[6] = LSW(MSD(id_list_dma));
1990 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001993 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001995 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 if (rval != QLA_SUCCESS) {
1998 /*EMPTY*/
1999 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002000 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 } else {
2002 *entries = mcp->mb[1];
2003 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002004 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 }
2006
2007 return rval;
2008}
2009
2010/*
2011 * qla2x00_get_resource_cnts
2012 * Get current firmware resource counts.
2013 *
2014 * Input:
2015 * ha = adapter block pointer.
2016 *
2017 * Returns:
2018 * qla2x00 local function return status code.
2019 *
2020 * Context:
2021 * Kernel context.
2022 */
2023int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002024qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002025 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002026 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027{
2028 int rval;
2029 mbx_cmd_t mc;
2030 mbx_cmd_t *mcp = &mc;
2031
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002032 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2035 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002036 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002037 if (IS_QLA81XX(vha->hw))
2038 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002039 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002041 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
2043 if (rval != QLA_SUCCESS) {
2044 /*EMPTY*/
2045 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002046 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 } else {
2048 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002049 "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
2050 vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
2051 mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
2052 mcp->mb[12]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 if (cur_xchg_cnt)
2055 *cur_xchg_cnt = mcp->mb[3];
2056 if (orig_xchg_cnt)
2057 *orig_xchg_cnt = mcp->mb[6];
2058 if (cur_iocb_cnt)
2059 *cur_iocb_cnt = mcp->mb[7];
2060 if (orig_iocb_cnt)
2061 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002062 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002063 *max_npiv_vports = mcp->mb[11];
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002064 if (IS_QLA81XX(vha->hw) && max_fcfs)
2065 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 }
2067
2068 return (rval);
2069}
2070
2071#if defined(QL_DEBUG_LEVEL_3)
2072/*
2073 * qla2x00_get_fcal_position_map
2074 * Get FCAL (LILP) position map using mailbox command
2075 *
2076 * Input:
2077 * ha = adapter state pointer.
2078 * pos_map = buffer pointer (can be NULL).
2079 *
2080 * Returns:
2081 * qla2x00 local function return status code.
2082 *
2083 * Context:
2084 * Kernel context.
2085 */
2086int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002087qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
2089 int rval;
2090 mbx_cmd_t mc;
2091 mbx_cmd_t *mcp = &mc;
2092 char *pmap;
2093 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002094 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Andrew Vasquez4b892582008-09-11 21:22:48 -07002096 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 if (pmap == NULL) {
2098 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002099 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 return QLA_MEMORY_ALLOC_FAILED;
2101 }
2102 memset(pmap, 0, FCAL_MAP_SIZE);
2103
2104 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2105 mcp->mb[2] = MSW(pmap_dma);
2106 mcp->mb[3] = LSW(pmap_dma);
2107 mcp->mb[6] = MSW(MSD(pmap_dma));
2108 mcp->mb[7] = LSW(MSD(pmap_dma));
2109 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2110 mcp->in_mb = MBX_1|MBX_0;
2111 mcp->buf_size = FCAL_MAP_SIZE;
2112 mcp->flags = MBX_DMA_IN;
2113 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002114 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 if (rval == QLA_SUCCESS) {
2117 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002118 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 mcp->mb[1], (unsigned)pmap[0]));
2120 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2121
2122 if (pos_map)
2123 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2124 }
2125 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2126
2127 if (rval != QLA_SUCCESS) {
2128 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002129 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002131 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 }
2133
2134 return rval;
2135}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002136#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002137
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002138/*
2139 * qla2x00_get_link_status
2140 *
2141 * Input:
2142 * ha = adapter block pointer.
2143 * loop_id = device loop ID.
2144 * ret_buf = pointer to link status return buffer.
2145 *
2146 * Returns:
2147 * 0 = success.
2148 * BIT_0 = mem alloc error.
2149 * BIT_1 = mailbox error.
2150 */
2151int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002152qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002153 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002154{
2155 int rval;
2156 mbx_cmd_t mc;
2157 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002158 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002159 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002160
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002161 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002162
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002163 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002164 mcp->mb[2] = MSW(stats_dma);
2165 mcp->mb[3] = LSW(stats_dma);
2166 mcp->mb[6] = MSW(MSD(stats_dma));
2167 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002168 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2169 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002170 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002171 mcp->mb[1] = loop_id;
2172 mcp->mb[4] = 0;
2173 mcp->mb[10] = 0;
2174 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2175 mcp->in_mb |= MBX_1;
2176 } else if (HAS_EXTENDED_IDS(ha)) {
2177 mcp->mb[1] = loop_id;
2178 mcp->mb[10] = 0;
2179 mcp->out_mb |= MBX_10|MBX_1;
2180 } else {
2181 mcp->mb[1] = loop_id << 8;
2182 mcp->out_mb |= MBX_1;
2183 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002184 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002185 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002186 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002187
2188 if (rval == QLA_SUCCESS) {
2189 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2190 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002191 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002192 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002193 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002194 /* Copy over data -- firmware data is LE. */
2195 dwords = offsetof(struct link_statistics, unused1) / 4;
2196 siter = diter = &stats->link_fail_cnt;
2197 while (dwords--)
2198 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002199 }
2200 } else {
2201 /* Failed. */
2202 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002203 vha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002204 }
2205
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002206 return rval;
2207}
2208
2209int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002210qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002211 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002212{
2213 int rval;
2214 mbx_cmd_t mc;
2215 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002216 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002217
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002218 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002219
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002220 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002221 mcp->mb[2] = MSW(stats_dma);
2222 mcp->mb[3] = LSW(stats_dma);
2223 mcp->mb[6] = MSW(MSD(stats_dma));
2224 mcp->mb[7] = LSW(MSD(stats_dma));
2225 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002226 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002227 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002228 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002229 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002230 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002231 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002232 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002233
2234 if (rval == QLA_SUCCESS) {
2235 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2236 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002237 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002238 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002239 } else {
2240 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002241 dwords = sizeof(struct link_statistics) / 4;
2242 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002243 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002244 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002245 }
2246 } else {
2247 /* Failed. */
2248 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002249 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002250 }
2251
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002252 return rval;
2253}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002254
2255int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002256qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002257{
2258 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002259 unsigned long flags = 0;
2260
2261 struct abort_entry_24xx *abt;
2262 dma_addr_t abt_dma;
2263 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002264 fc_port_t *fcport = sp->fcport;
2265 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002266 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002267 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002268
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002269 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002270
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002271 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002272 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002273 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002274 break;
2275 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002276 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002277 if (handle == MAX_OUTSTANDING_COMMANDS) {
2278 /* Command not found. */
2279 return QLA_FUNCTION_FAILED;
2280 }
2281
2282 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2283 if (abt == NULL) {
2284 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002285 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002286 return QLA_MEMORY_ALLOC_FAILED;
2287 }
2288 memset(abt, 0, sizeof(struct abort_entry_24xx));
2289
2290 abt->entry_type = ABORT_IOCB_TYPE;
2291 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002292 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002293 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2294 abt->handle_to_abort = handle;
2295 abt->port_id[0] = fcport->d_id.b.al_pa;
2296 abt->port_id[1] = fcport->d_id.b.area;
2297 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002298 abt->vp_index = fcport->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002299
2300 abt->req_que_no = cpu_to_le16(req->id);
2301
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002302 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002303 if (rval != QLA_SUCCESS) {
2304 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002305 __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002306 } else if (abt->entry_status != 0) {
2307 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002308 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002309 abt->entry_status));
2310 rval = QLA_FUNCTION_FAILED;
2311 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2312 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002313 "-- completion status (%x).\n", __func__, vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002314 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002315 rval = QLA_FUNCTION_FAILED;
2316 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002317 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002318 }
2319
2320 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2321
2322 return rval;
2323}
2324
2325struct tsk_mgmt_cmd {
2326 union {
2327 struct tsk_mgmt_entry tsk;
2328 struct sts_entry_24xx sts;
2329 } p;
2330};
2331
Andrew Vasquez523ec772008-04-03 13:13:24 -07002332static int
2333__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002334 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002335{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002336 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002337 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002338 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002339 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002340 scsi_qla_host_t *vha;
2341 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002342 struct req_que *req;
2343 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002344
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08002345 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002346
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002347 vha = fcport->vha;
2348 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002349 req = vha->req;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002350 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002351 rsp = ha->rsp_q_map[tag + 1];
2352 else
2353 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002354 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002355 if (tsk == NULL) {
2356 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002357 "IOCB.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002358 return QLA_MEMORY_ALLOC_FAILED;
2359 }
2360 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2361
2362 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2363 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002364 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002365 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002366 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002367 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002368 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2369 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2370 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002371 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002372 if (type == TCF_LUN_RESET) {
2373 int_to_scsilun(l, &tsk->p.tsk.lun);
2374 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2375 sizeof(tsk->p.tsk.lun));
2376 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002377
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002378 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002379 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002380 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002381 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002382 "(%x).\n", __func__, vha->host_no, name, rval));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002383 } else if (sts->entry_status != 0) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002384 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002385 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002386 sts->entry_status));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002387 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002388 } else if (sts->comp_status !=
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002389 __constant_cpu_to_le16(CS_COMPLETE)) {
2390 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2391 "-- completion status (%x).\n", __func__,
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002392 vha->host_no, le16_to_cpu(sts->comp_status)));
2393 rval = QLA_FUNCTION_FAILED;
2394 } else if (!(le16_to_cpu(sts->scsi_status) &
2395 SS_RESPONSE_INFO_LEN_VALID)) {
2396 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2397 "-- no response info (%x).\n", __func__, vha->host_no,
2398 le16_to_cpu(sts->scsi_status)));
2399 rval = QLA_FUNCTION_FAILED;
2400 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
2401 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2402 "-- not enough response info (%d).\n", __func__,
2403 vha->host_no, le32_to_cpu(sts->rsp_data_len)));
2404 rval = QLA_FUNCTION_FAILED;
2405 } else if (sts->data[3]) {
2406 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2407 "-- response (%x).\n", __func__,
2408 vha->host_no, sts->data[3]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002409 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002410 }
2411
2412 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002413 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002414 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2415 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002416 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002417 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002418 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002419 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002420 }
2421
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002422 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002423
2424 return rval;
2425}
2426
Andrew Vasquez523ec772008-04-03 13:13:24 -07002427int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002428qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002429{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002430 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002431}
2432
2433int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002434qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002435{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002436 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002437}
2438
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002439int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002440qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002441{
2442 int rval;
2443 mbx_cmd_t mc;
2444 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002445 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002446
Andrew Vasquez68af0812008-05-12 22:21:13 -07002447 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002448 return QLA_FUNCTION_FAILED;
2449
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002450 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002451
2452 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2453 mcp->out_mb = MBX_0;
2454 mcp->in_mb = MBX_0;
2455 mcp->tov = 5;
2456 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002457 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002458
2459 if (rval != QLA_SUCCESS) {
2460 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002461 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002462 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002463 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002464 }
2465
2466 return rval;
2467}
2468
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002469/**
2470 * qla2x00_set_serdes_params() -
2471 * @ha: HA context
2472 *
2473 * Returns
2474 */
2475int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002476qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002477 uint16_t sw_em_2g, uint16_t sw_em_4g)
2478{
2479 int rval;
2480 mbx_cmd_t mc;
2481 mbx_cmd_t *mcp = &mc;
2482
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002483 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002484
2485 mcp->mb[0] = MBC_SERDES_PARAMS;
2486 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002487 mcp->mb[2] = sw_em_1g | BIT_15;
2488 mcp->mb[3] = sw_em_2g | BIT_15;
2489 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002490 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2491 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002492 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002493 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002494 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002495
2496 if (rval != QLA_SUCCESS) {
2497 /*EMPTY*/
2498 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002499 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002500 } else {
2501 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002502 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002503 }
2504
2505 return rval;
2506}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002507
2508int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002509qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002510{
2511 int rval;
2512 mbx_cmd_t mc;
2513 mbx_cmd_t *mcp = &mc;
2514
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002515 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002516 return QLA_FUNCTION_FAILED;
2517
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002518 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002519
2520 mcp->mb[0] = MBC_STOP_FIRMWARE;
2521 mcp->out_mb = MBX_0;
2522 mcp->in_mb = MBX_0;
2523 mcp->tov = 5;
2524 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002525 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002526
2527 if (rval != QLA_SUCCESS) {
2528 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002529 vha->host_no, rval));
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07002530 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2531 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002532 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002533 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002534 }
2535
2536 return rval;
2537}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002538
2539int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002540qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002541 uint16_t buffers)
2542{
2543 int rval;
2544 mbx_cmd_t mc;
2545 mbx_cmd_t *mcp = &mc;
2546
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002547 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002548 return QLA_FUNCTION_FAILED;
2549
Andrew Vasquez85880802009-12-15 21:29:46 -08002550 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2551 return QLA_FUNCTION_FAILED;
2552
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002553 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002554
2555 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002556 mcp->mb[1] = TC_EFT_ENABLE;
2557 mcp->mb[2] = LSW(eft_dma);
2558 mcp->mb[3] = MSW(eft_dma);
2559 mcp->mb[4] = LSW(MSD(eft_dma));
2560 mcp->mb[5] = MSW(MSD(eft_dma));
2561 mcp->mb[6] = buffers;
2562 mcp->mb[7] = TC_AEN_DISABLE;
2563 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002564 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002565 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002566 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002567 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002568 if (rval != QLA_SUCCESS) {
2569 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002570 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002571 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002572 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002573 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002574
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002575 return rval;
2576}
2577
2578int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002579qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002580{
2581 int rval;
2582 mbx_cmd_t mc;
2583 mbx_cmd_t *mcp = &mc;
2584
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002585 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002586 return QLA_FUNCTION_FAILED;
2587
Andrew Vasquez85880802009-12-15 21:29:46 -08002588 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2589 return QLA_FUNCTION_FAILED;
2590
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002591 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002592
2593 mcp->mb[0] = MBC_TRACE_CONTROL;
2594 mcp->mb[1] = TC_EFT_DISABLE;
2595 mcp->out_mb = MBX_1|MBX_0;
2596 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002597 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002598 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002599 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002600 if (rval != QLA_SUCCESS) {
2601 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002602 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002603 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002604 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002605 }
2606
2607 return rval;
2608}
2609
Andrew Vasquez88729e52006-06-23 16:10:50 -07002610int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002611qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002612 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2613{
2614 int rval;
2615 mbx_cmd_t mc;
2616 mbx_cmd_t *mcp = &mc;
2617
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002618 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002619 return QLA_FUNCTION_FAILED;
2620
Andrew Vasquez85880802009-12-15 21:29:46 -08002621 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2622 return QLA_FUNCTION_FAILED;
2623
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002624 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002625
2626 mcp->mb[0] = MBC_TRACE_CONTROL;
2627 mcp->mb[1] = TC_FCE_ENABLE;
2628 mcp->mb[2] = LSW(fce_dma);
2629 mcp->mb[3] = MSW(fce_dma);
2630 mcp->mb[4] = LSW(MSD(fce_dma));
2631 mcp->mb[5] = MSW(MSD(fce_dma));
2632 mcp->mb[6] = buffers;
2633 mcp->mb[7] = TC_AEN_DISABLE;
2634 mcp->mb[8] = 0;
2635 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2636 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2637 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2638 MBX_1|MBX_0;
2639 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002640 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002641 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002642 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002643 if (rval != QLA_SUCCESS) {
2644 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002645 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002646 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002647 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002648
2649 if (mb)
2650 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2651 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002652 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002653 }
2654
2655 return rval;
2656}
2657
2658int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002659qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002660{
2661 int rval;
2662 mbx_cmd_t mc;
2663 mbx_cmd_t *mcp = &mc;
2664
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002665 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002666 return QLA_FUNCTION_FAILED;
2667
Andrew Vasquez85880802009-12-15 21:29:46 -08002668 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2669 return QLA_FUNCTION_FAILED;
2670
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002671 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002672
2673 mcp->mb[0] = MBC_TRACE_CONTROL;
2674 mcp->mb[1] = TC_FCE_DISABLE;
2675 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2676 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2677 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2678 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002679 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002680 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002681 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002682 if (rval != QLA_SUCCESS) {
2683 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002684 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002685 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002686 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002687
2688 if (wr)
2689 *wr = (uint64_t) mcp->mb[5] << 48 |
2690 (uint64_t) mcp->mb[4] << 32 |
2691 (uint64_t) mcp->mb[3] << 16 |
2692 (uint64_t) mcp->mb[2];
2693 if (rd)
2694 *rd = (uint64_t) mcp->mb[9] << 48 |
2695 (uint64_t) mcp->mb[8] << 32 |
2696 (uint64_t) mcp->mb[7] << 16 |
2697 (uint64_t) mcp->mb[6];
2698 }
2699
2700 return rval;
2701}
2702
2703int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002704qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
Andrew Vasquez88729e52006-06-23 16:10:50 -07002705 uint16_t off, uint16_t count)
2706{
2707 int rval;
2708 mbx_cmd_t mc;
2709 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002710
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002711 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002712 return QLA_FUNCTION_FAILED;
2713
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002714 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002715
2716 mcp->mb[0] = MBC_READ_SFP;
2717 mcp->mb[1] = addr;
2718 mcp->mb[2] = MSW(sfp_dma);
2719 mcp->mb[3] = LSW(sfp_dma);
2720 mcp->mb[6] = MSW(MSD(sfp_dma));
2721 mcp->mb[7] = LSW(MSD(sfp_dma));
2722 mcp->mb[8] = count;
2723 mcp->mb[9] = off;
2724 mcp->mb[10] = 0;
2725 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2726 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002727 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002728 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002729 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez88729e52006-06-23 16:10:50 -07002730
2731 if (rval != QLA_SUCCESS) {
2732 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002733 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002734 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002735 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002736 }
2737
2738 return rval;
2739}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002740
2741int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002742qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002743 uint16_t port_speed, uint16_t *mb)
2744{
2745 int rval;
2746 mbx_cmd_t mc;
2747 mbx_cmd_t *mcp = &mc;
2748
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002749 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002750 return QLA_FUNCTION_FAILED;
2751
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002752 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002753
2754 mcp->mb[0] = MBC_PORT_PARAMS;
2755 mcp->mb[1] = loop_id;
2756 mcp->mb[2] = BIT_0;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002757 if (IS_QLA81XX(vha->hw))
2758 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2759 else
2760 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2761 mcp->mb[9] = vha->vp_idx;
2762 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2763 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002764 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002765 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002766 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002767
2768 /* Return mailbox statuses. */
2769 if (mb != NULL) {
2770 mb[0] = mcp->mb[0];
2771 mb[1] = mcp->mb[1];
2772 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002773 }
2774
2775 if (rval != QLA_SUCCESS) {
2776 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002777 vha->host_no, rval));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002778 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002779 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002780 }
2781
2782 return rval;
2783}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002784
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002785void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002786qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002787 struct vp_rpt_id_entry_24xx *rptid_entry)
2788{
2789 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07002790 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002791 struct qla_hw_data *ha = vha->hw;
2792 scsi_qla_host_t *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002793 scsi_qla_host_t *tvp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002794
2795 if (rptid_entry->entry_status != 0)
2796 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002797
2798 if (rptid_entry->format == 0) {
2799 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002800 " number of VPs acquired %d\n", __func__, vha->host_no,
Andrew Vasquez09ccbcc2009-08-04 23:38:21 -07002801 MSB(le16_to_cpu(rptid_entry->vp_count)),
2802 LSB(le16_to_cpu(rptid_entry->vp_count))));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002803 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2804 rptid_entry->port_id[2], rptid_entry->port_id[1],
2805 rptid_entry->port_id[0]));
2806 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07002807 vp_idx = LSB(stat);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002808 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2809 "- status %d - "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002810 "with port id %02x%02x%02x\n", __func__, vha->host_no,
Seokmann Juc6852c42008-04-24 15:21:29 -07002811 vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002812 rptid_entry->port_id[2], rptid_entry->port_id[1],
2813 rptid_entry->port_id[0]));
Andrew Vasquez531a82d2009-10-13 15:16:51 -07002814
2815 vp = vha;
2816 if (vp_idx == 0 && (MSB(stat) != 1))
2817 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002819 if (MSB(stat) == 1) {
2820 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2821 "VP[%d].\n", vha->host_no, vp_idx));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002822 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002823 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002824
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002825 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002826 if (vp_idx == vp->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002827 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002828 if (!vp)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002829 return;
2830
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002831 vp->d_id.b.domain = rptid_entry->port_id[2];
2832 vp->d_id.b.area = rptid_entry->port_id[1];
2833 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002834
2835 /*
2836 * Cannot configure here as we are still sitting on the
2837 * response queue. Handle it in dpc context.
2838 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002839 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002840
Andrew Vasquez531a82d2009-10-13 15:16:51 -07002841reg_needed:
2842 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
2843 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
2844 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002845 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002846 }
2847}
2848
2849/*
2850 * qla24xx_modify_vp_config
2851 * Change VP configuration for vha
2852 *
2853 * Input:
2854 * vha = adapter block pointer.
2855 *
2856 * Returns:
2857 * qla2xxx local function return status code.
2858 *
2859 * Context:
2860 * Kernel context.
2861 */
2862int
2863qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2864{
2865 int rval;
2866 struct vp_config_entry_24xx *vpmod;
2867 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002868 struct qla_hw_data *ha = vha->hw;
2869 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002870
2871 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002872
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002873 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002874 if (!vpmod) {
2875 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002876 "IOCB.\n", __func__, vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002877 return QLA_MEMORY_ALLOC_FAILED;
2878 }
2879
2880 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2881 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2882 vpmod->entry_count = 1;
2883 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2884 vpmod->vp_count = 1;
2885 vpmod->vp_index1 = vha->vp_idx;
2886 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2887 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2888 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2889 vpmod->entry_count = 1;
2890
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002891 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002892 if (rval != QLA_SUCCESS) {
2893 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002894 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002895 } else if (vpmod->comp_status != 0) {
2896 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002897 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002898 vpmod->comp_status));
2899 rval = QLA_FUNCTION_FAILED;
2900 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2901 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002902 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002903 le16_to_cpu(vpmod->comp_status)));
2904 rval = QLA_FUNCTION_FAILED;
2905 } else {
2906 /* EMPTY */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002907 DEBUG11(printk("%s(%ld): done.\n", __func__,
2908 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002909 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2910 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002911 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002912
2913 return rval;
2914}
2915
2916/*
2917 * qla24xx_control_vp
2918 * Enable a virtual port for given host
2919 *
2920 * Input:
2921 * ha = adapter block pointer.
2922 * vhba = virtual adapter (unused)
2923 * index = index number for enabled VP
2924 *
2925 * Returns:
2926 * qla2xxx local function return status code.
2927 *
2928 * Context:
2929 * Kernel context.
2930 */
2931int
2932qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2933{
2934 int rval;
2935 int map, pos;
2936 struct vp_ctrl_entry_24xx *vce;
2937 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002938 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002939 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002940 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002941
2942 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002943 vha->host_no, vp_index));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002944
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002945 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002946 return QLA_PARAMETER_ERROR;
2947
2948 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2949 if (!vce) {
2950 DEBUG2_3(printk("%s(%ld): "
2951 "failed to allocate VP Control IOCB.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002952 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002953 return QLA_MEMORY_ALLOC_FAILED;
2954 }
2955 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2956
2957 vce->entry_type = VP_CTRL_IOCB_TYPE;
2958 vce->entry_count = 1;
2959 vce->command = cpu_to_le16(cmd);
2960 vce->vp_count = __constant_cpu_to_le16(1);
2961
2962 /* index map in firmware starts with 1; decrement index
2963 * this is ok as we never use index 0
2964 */
2965 map = (vp_index - 1) / 8;
2966 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002967 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002968 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002969 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002970
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002971 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002972 if (rval != QLA_SUCCESS) {
2973 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002974 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002975 printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002976 "(%x).\n", __func__, base_vha->host_no, rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002977 } else if (vce->entry_status != 0) {
2978 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002979 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002980 vce->entry_status));
2981 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002982 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002983 vce->entry_status);
2984 rval = QLA_FUNCTION_FAILED;
2985 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2986 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002987 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002988 le16_to_cpu(vce->comp_status)));
2989 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002990 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002991 le16_to_cpu(vce->comp_status));
2992 rval = QLA_FUNCTION_FAILED;
2993 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002994 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002995 }
2996
2997 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2998
2999 return rval;
3000}
3001
3002/*
3003 * qla2x00_send_change_request
3004 * Receive or disable RSCN request from fabric controller
3005 *
3006 * Input:
3007 * ha = adapter block pointer
3008 * format = registration format:
3009 * 0 - Reserved
3010 * 1 - Fabric detected registration
3011 * 2 - N_port detected registration
3012 * 3 - Full registration
3013 * FF - clear registration
3014 * vp_idx = Virtual port index
3015 *
3016 * Returns:
3017 * qla2x00 local function return status code.
3018 *
3019 * Context:
3020 * Kernel Context
3021 */
3022
3023int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003024qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003025 uint16_t vp_idx)
3026{
3027 int rval;
3028 mbx_cmd_t mc;
3029 mbx_cmd_t *mcp = &mc;
3030
3031 /*
3032 * This command is implicitly executed by firmware during login for the
3033 * physical hosts
3034 */
3035 if (vp_idx == 0)
3036 return QLA_FUNCTION_FAILED;
3037
3038 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3039 mcp->mb[1] = format;
3040 mcp->mb[9] = vp_idx;
3041 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3042 mcp->in_mb = MBX_0|MBX_1;
3043 mcp->tov = MBX_TOV_SECONDS;
3044 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003045 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003046
3047 if (rval == QLA_SUCCESS) {
3048 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3049 rval = BIT_1;
3050 }
3051 } else
3052 rval = BIT_1;
3053
3054 return rval;
3055}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003056
3057int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003058qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003059 uint32_t size)
3060{
3061 int rval;
3062 mbx_cmd_t mc;
3063 mbx_cmd_t *mcp = &mc;
3064
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003065 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003066
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003067 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003068 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3069 mcp->mb[8] = MSW(addr);
3070 mcp->out_mb = MBX_8|MBX_0;
3071 } else {
3072 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3073 mcp->out_mb = MBX_0;
3074 }
3075 mcp->mb[1] = LSW(addr);
3076 mcp->mb[2] = MSW(req_dma);
3077 mcp->mb[3] = LSW(req_dma);
3078 mcp->mb[6] = MSW(MSD(req_dma));
3079 mcp->mb[7] = LSW(MSD(req_dma));
3080 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003081 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003082 mcp->mb[4] = MSW(size);
3083 mcp->mb[5] = LSW(size);
3084 mcp->out_mb |= MBX_5|MBX_4;
3085 } else {
3086 mcp->mb[4] = LSW(size);
3087 mcp->out_mb |= MBX_4;
3088 }
3089
3090 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003091 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003092 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003093 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003094
3095 if (rval != QLA_SUCCESS) {
3096 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003097 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003098 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003099 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003100 }
3101
3102 return rval;
3103}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003104
3105/* 84XX Support **************************************************************/
3106
3107struct cs84xx_mgmt_cmd {
3108 union {
3109 struct verify_chip_entry_84xx req;
3110 struct verify_chip_rsp_84xx rsp;
3111 } p;
3112};
3113
3114int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003115qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003116{
3117 int rval, retry;
3118 struct cs84xx_mgmt_cmd *mn;
3119 dma_addr_t mn_dma;
3120 uint16_t options;
3121 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003122 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003123
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003124 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003125
3126 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3127 if (mn == NULL) {
3128 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003129 "IOCB.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003130 return QLA_MEMORY_ALLOC_FAILED;
3131 }
3132
3133 /* Force Update? */
3134 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3135 /* Diagnostic firmware? */
3136 /* options |= MENLO_DIAG_FW; */
3137 /* We update the firmware with only one data sequence. */
3138 options |= VCO_END_OF_DATA;
3139
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003140 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003141 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003142 memset(mn, 0, sizeof(*mn));
3143 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3144 mn->p.req.entry_count = 1;
3145 mn->p.req.options = cpu_to_le16(options);
3146
3147 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003148 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003149 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3150 sizeof(*mn)));
3151
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003152 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003153 if (rval != QLA_SUCCESS) {
3154 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003155 "IOCB (%x).\n", __func__, vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003156 goto verify_done;
3157 }
3158
3159 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003160 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003161 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3162 sizeof(*mn)));
3163
3164 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3165 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3166 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3167 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003168 vha->host_no, status[0], status[1]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003169
3170 if (status[0] != CS_COMPLETE) {
3171 rval = QLA_FUNCTION_FAILED;
3172 if (!(options & VCO_DONT_UPDATE_FW)) {
3173 DEBUG2_16(printk("%s(%ld): Firmware update "
3174 "failed. Retrying without update "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003175 "firmware.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003176 options |= VCO_DONT_UPDATE_FW;
3177 options &= ~VCO_FORCE_UPDATE;
3178 retry = 1;
3179 }
3180 } else {
3181 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003182 __func__, vha->host_no,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003183 le32_to_cpu(mn->p.rsp.fw_ver)));
3184
3185 /* NOTE: we only update OP firmware. */
3186 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3187 ha->cs84xx->op_fw_version =
3188 le32_to_cpu(mn->p.rsp.fw_ver);
3189 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3190 flags);
3191 }
3192 } while (retry);
3193
3194verify_done:
3195 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3196
3197 if (rval != QLA_SUCCESS) {
3198 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003199 vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003200 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003201 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003202 }
3203
3204 return rval;
3205}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003206
3207int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003208qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003209{
3210 int rval;
3211 unsigned long flags;
3212 mbx_cmd_t mc;
3213 mbx_cmd_t *mcp = &mc;
3214 struct device_reg_25xxmq __iomem *reg;
3215 struct qla_hw_data *ha = vha->hw;
3216
3217 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003218 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003219 mcp->mb[2] = MSW(LSD(req->dma));
3220 mcp->mb[3] = LSW(LSD(req->dma));
3221 mcp->mb[6] = MSW(MSD(req->dma));
3222 mcp->mb[7] = LSW(MSD(req->dma));
3223 mcp->mb[5] = req->length;
3224 if (req->rsp)
3225 mcp->mb[10] = req->rsp->id;
3226 mcp->mb[12] = req->qos;
3227 mcp->mb[11] = req->vp_idx;
3228 mcp->mb[13] = req->rid;
3229
3230 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3231 QLA_QUE_PAGE * req->id);
3232
3233 mcp->mb[4] = req->id;
3234 /* que in ptr index */
3235 mcp->mb[8] = 0;
3236 /* que out ptr index */
3237 mcp->mb[9] = 0;
3238 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3239 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3240 mcp->in_mb = MBX_0;
3241 mcp->flags = MBX_DMA_OUT;
3242 mcp->tov = 60;
3243
3244 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003245 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003246 WRT_REG_DWORD(&reg->req_q_in, 0);
3247 WRT_REG_DWORD(&reg->req_q_out, 0);
3248 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003249 req->req_q_in = &reg->req_q_in;
3250 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003251 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3252
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003253 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003254 if (rval != QLA_SUCCESS)
3255 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3256 __func__, vha->host_no, rval, mcp->mb[0]));
3257 return rval;
3258}
3259
3260int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003261qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003262{
3263 int rval;
3264 unsigned long flags;
3265 mbx_cmd_t mc;
3266 mbx_cmd_t *mcp = &mc;
3267 struct device_reg_25xxmq __iomem *reg;
3268 struct qla_hw_data *ha = vha->hw;
3269
3270 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003271 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003272 mcp->mb[2] = MSW(LSD(rsp->dma));
3273 mcp->mb[3] = LSW(LSD(rsp->dma));
3274 mcp->mb[6] = MSW(MSD(rsp->dma));
3275 mcp->mb[7] = LSW(MSD(rsp->dma));
3276 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003277 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003278 mcp->mb[13] = rsp->rid;
3279
3280 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3281 QLA_QUE_PAGE * rsp->id);
3282
3283 mcp->mb[4] = rsp->id;
3284 /* que in ptr index */
3285 mcp->mb[8] = 0;
3286 /* que out ptr index */
3287 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003288 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003289 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3290 mcp->in_mb = MBX_0;
3291 mcp->flags = MBX_DMA_OUT;
3292 mcp->tov = 60;
3293
3294 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003295 if (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003296 WRT_REG_DWORD(&reg->rsp_q_out, 0);
3297 WRT_REG_DWORD(&reg->rsp_q_in, 0);
3298 }
3299
3300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3301
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003302 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003303 if (rval != QLA_SUCCESS)
3304 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3305 "mb0=%x.\n", __func__,
3306 vha->host_no, rval, mcp->mb[0]));
3307 return rval;
3308}
3309
Andrew Vasquez8a659572009-02-08 20:50:12 -08003310int
3311qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3312{
3313 int rval;
3314 mbx_cmd_t mc;
3315 mbx_cmd_t *mcp = &mc;
3316
3317 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3318
3319 mcp->mb[0] = MBC_IDC_ACK;
3320 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3321 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3322 mcp->in_mb = MBX_0;
3323 mcp->tov = MBX_TOV_SECONDS;
3324 mcp->flags = 0;
3325 rval = qla2x00_mailbox_command(vha, mcp);
3326
3327 if (rval != QLA_SUCCESS) {
3328 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3329 vha->host_no, rval, mcp->mb[0]));
3330 } else {
3331 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3332 }
3333
3334 return rval;
3335}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003336
3337int
3338qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3339{
3340 int rval;
3341 mbx_cmd_t mc;
3342 mbx_cmd_t *mcp = &mc;
3343
3344 if (!IS_QLA81XX(vha->hw))
3345 return QLA_FUNCTION_FAILED;
3346
3347 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3348
3349 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3350 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3351 mcp->out_mb = MBX_1|MBX_0;
3352 mcp->in_mb = MBX_1|MBX_0;
3353 mcp->tov = MBX_TOV_SECONDS;
3354 mcp->flags = 0;
3355 rval = qla2x00_mailbox_command(vha, mcp);
3356
3357 if (rval != QLA_SUCCESS) {
3358 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3359 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3360 } else {
3361 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3362 *sector_size = mcp->mb[1];
3363 }
3364
3365 return rval;
3366}
3367
3368int
3369qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3370{
3371 int rval;
3372 mbx_cmd_t mc;
3373 mbx_cmd_t *mcp = &mc;
3374
3375 if (!IS_QLA81XX(vha->hw))
3376 return QLA_FUNCTION_FAILED;
3377
3378 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3379
3380 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3381 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3382 FAC_OPT_CMD_WRITE_PROTECT;
3383 mcp->out_mb = MBX_1|MBX_0;
3384 mcp->in_mb = MBX_1|MBX_0;
3385 mcp->tov = MBX_TOV_SECONDS;
3386 mcp->flags = 0;
3387 rval = qla2x00_mailbox_command(vha, mcp);
3388
3389 if (rval != QLA_SUCCESS) {
3390 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3391 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3392 } else {
3393 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3394 }
3395
3396 return rval;
3397}
3398
3399int
3400qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3401{
3402 int rval;
3403 mbx_cmd_t mc;
3404 mbx_cmd_t *mcp = &mc;
3405
3406 if (!IS_QLA81XX(vha->hw))
3407 return QLA_FUNCTION_FAILED;
3408
3409 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3410
3411 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3412 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3413 mcp->mb[2] = LSW(start);
3414 mcp->mb[3] = MSW(start);
3415 mcp->mb[4] = LSW(finish);
3416 mcp->mb[5] = MSW(finish);
3417 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3418 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3419 mcp->tov = MBX_TOV_SECONDS;
3420 mcp->flags = 0;
3421 rval = qla2x00_mailbox_command(vha, mcp);
3422
3423 if (rval != QLA_SUCCESS) {
3424 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3425 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3426 mcp->mb[1], mcp->mb[2]));
3427 } else {
3428 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3429 }
3430
3431 return rval;
3432}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003433
3434int
3435qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3436{
3437 int rval = 0;
3438 mbx_cmd_t mc;
3439 mbx_cmd_t *mcp = &mc;
3440
3441 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3442
3443 mcp->mb[0] = MBC_RESTART_MPI_FW;
3444 mcp->out_mb = MBX_0;
3445 mcp->in_mb = MBX_0|MBX_1;
3446 mcp->tov = MBX_TOV_SECONDS;
3447 mcp->flags = 0;
3448 rval = qla2x00_mailbox_command(vha, mcp);
3449
3450 if (rval != QLA_SUCCESS) {
3451 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3452 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3453 } else {
3454 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3455 }
3456
3457 return rval;
3458}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003459
3460int
3461qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3462 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3463{
3464 int rval;
3465 mbx_cmd_t mc;
3466 mbx_cmd_t *mcp = &mc;
3467
3468 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3469
3470 mcp->mb[0] = MBC_READ_SFP;
3471 mcp->mb[1] = dev;
3472 mcp->mb[2] = MSW(sfp_dma);
3473 mcp->mb[3] = LSW(sfp_dma);
3474 mcp->mb[6] = MSW(MSD(sfp_dma));
3475 mcp->mb[7] = LSW(MSD(sfp_dma));
3476 mcp->mb[8] = len;
3477 mcp->mb[9] = adr;
3478 mcp->mb[10] = opt;
3479 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3480 mcp->in_mb = MBX_0;
3481 mcp->tov = MBX_TOV_SECONDS;
3482 mcp->flags = 0;
3483 rval = qla2x00_mailbox_command(vha, mcp);
3484
3485 if (opt & BIT_0)
3486 if (sfp)
3487 *sfp = mcp->mb[8];
3488
3489 if (rval != QLA_SUCCESS) {
3490 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3491 vha->host_no, rval, mcp->mb[0]));
3492 } else {
Andrew Vasquez76403352009-04-06 22:33:39 -07003493 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003494 }
3495
3496 return rval;
3497}
3498
3499int
3500qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3501 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3502{
3503 int rval;
3504 mbx_cmd_t mc;
3505 mbx_cmd_t *mcp = &mc;
3506
3507 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3508
3509 if (opt & BIT_0)
3510 if (sfp)
3511 len = *sfp;
3512
3513 mcp->mb[0] = MBC_WRITE_SFP;
3514 mcp->mb[1] = dev;
3515 mcp->mb[2] = MSW(sfp_dma);
3516 mcp->mb[3] = LSW(sfp_dma);
3517 mcp->mb[6] = MSW(MSD(sfp_dma));
3518 mcp->mb[7] = LSW(MSD(sfp_dma));
3519 mcp->mb[8] = len;
3520 mcp->mb[9] = adr;
3521 mcp->mb[10] = opt;
3522 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3523 mcp->in_mb = MBX_0;
3524 mcp->tov = MBX_TOV_SECONDS;
3525 mcp->flags = 0;
3526 rval = qla2x00_mailbox_command(vha, mcp);
3527
3528 if (rval != QLA_SUCCESS) {
3529 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3530 vha->host_no, rval, mcp->mb[0]));
3531 } else {
3532 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3533 }
3534
3535 return rval;
3536}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003537
3538int
3539qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3540 uint16_t size_in_bytes, uint16_t *actual_size)
3541{
3542 int rval;
3543 mbx_cmd_t mc;
3544 mbx_cmd_t *mcp = &mc;
3545
3546 if (!IS_QLA81XX(vha->hw))
3547 return QLA_FUNCTION_FAILED;
3548
3549 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3550
3551 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3552 mcp->mb[2] = MSW(stats_dma);
3553 mcp->mb[3] = LSW(stats_dma);
3554 mcp->mb[6] = MSW(MSD(stats_dma));
3555 mcp->mb[7] = LSW(MSD(stats_dma));
3556 mcp->mb[8] = size_in_bytes >> 2;
3557 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3558 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3559 mcp->tov = MBX_TOV_SECONDS;
3560 mcp->flags = 0;
3561 rval = qla2x00_mailbox_command(vha, mcp);
3562
3563 if (rval != QLA_SUCCESS) {
3564 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3565 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3566 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3567 } else {
3568 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3569
3570 *actual_size = mcp->mb[2] << 2;
3571 }
3572
3573 return rval;
3574}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003575
3576int
3577qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3578 uint16_t size)
3579{
3580 int rval;
3581 mbx_cmd_t mc;
3582 mbx_cmd_t *mcp = &mc;
3583
3584 if (!IS_QLA81XX(vha->hw))
3585 return QLA_FUNCTION_FAILED;
3586
3587 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3588
3589 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3590 mcp->mb[1] = 0;
3591 mcp->mb[2] = MSW(tlv_dma);
3592 mcp->mb[3] = LSW(tlv_dma);
3593 mcp->mb[6] = MSW(MSD(tlv_dma));
3594 mcp->mb[7] = LSW(MSD(tlv_dma));
3595 mcp->mb[8] = size;
3596 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3597 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3598 mcp->tov = MBX_TOV_SECONDS;
3599 mcp->flags = 0;
3600 rval = qla2x00_mailbox_command(vha, mcp);
3601
3602 if (rval != QLA_SUCCESS) {
3603 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3604 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3605 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3606 } else {
3607 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3608 }
3609
3610 return rval;
3611}
Andrew Vasquez18e75552009-06-03 09:55:30 -07003612
3613int
3614qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3615{
3616 int rval;
3617 mbx_cmd_t mc;
3618 mbx_cmd_t *mcp = &mc;
3619
3620 if (!IS_FWI2_CAPABLE(vha->hw))
3621 return QLA_FUNCTION_FAILED;
3622
3623 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3624
3625 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3626 mcp->mb[1] = LSW(risc_addr);
3627 mcp->mb[8] = MSW(risc_addr);
3628 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3629 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3630 mcp->tov = 30;
3631 mcp->flags = 0;
3632 rval = qla2x00_mailbox_command(vha, mcp);
3633 if (rval != QLA_SUCCESS) {
3634 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3635 vha->host_no, rval, mcp->mb[0]));
3636 } else {
3637 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3638 *data = mcp->mb[3] << 16 | mcp->mb[2];
3639 }
3640
3641 return rval;
3642}
3643
3644int
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003645qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3646{
3647 int rval;
3648 mbx_cmd_t mc;
3649 mbx_cmd_t *mcp = &mc;
3650 uint32_t iter_cnt = 0x1;
3651
3652 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3653
3654 memset(mcp->mb, 0 , sizeof(mcp->mb));
3655 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3656 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3657
3658 /* transfer count */
3659 mcp->mb[10] = LSW(mreq->transfer_size);
3660 mcp->mb[11] = MSW(mreq->transfer_size);
3661
3662 /* send data address */
3663 mcp->mb[14] = LSW(mreq->send_dma);
3664 mcp->mb[15] = MSW(mreq->send_dma);
3665 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3666 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3667
3668 /* recieve data address */
3669 mcp->mb[16] = LSW(mreq->rcv_dma);
3670 mcp->mb[17] = MSW(mreq->rcv_dma);
3671 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3672 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3673
3674 /* Iteration count */
3675 mcp->mb[18] = LSW(iter_cnt);
3676 mcp->mb[19] = MSW(iter_cnt);
3677
3678 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3679 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3680 if (IS_QLA81XX(vha->hw))
3681 mcp->out_mb |= MBX_2;
3682 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3683
3684 mcp->buf_size = mreq->transfer_size;
3685 mcp->tov = MBX_TOV_SECONDS;
3686 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3687
3688 rval = qla2x00_mailbox_command(vha, mcp);
3689
3690 if (rval != QLA_SUCCESS) {
3691 DEBUG2(printk(KERN_WARNING
3692 "(%ld): failed=%x mb[0]=0x%x "
3693 "mb[1]=0x%x mb[2]=0x%x mb[3]=0x%x mb[18]=0x%x mb[19]=0x%x. \n", vha->host_no, rval,
3694 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[18], mcp->mb[19]));
3695 } else {
3696 DEBUG2(printk(KERN_WARNING
3697 "scsi(%ld): done.\n", vha->host_no));
3698 }
3699
3700 /* Copy mailbox information */
3701 memcpy( mresp, mcp->mb, 64);
3702 mresp[3] = mcp->mb[18];
3703 mresp[4] = mcp->mb[19];
3704 return rval;
3705}
3706
3707int
3708qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq, uint16_t *mresp)
3709{
3710 int rval;
3711 mbx_cmd_t mc;
3712 mbx_cmd_t *mcp = &mc;
3713 struct qla_hw_data *ha = vha->hw;
3714
3715 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3716
3717 memset(mcp->mb, 0 , sizeof(mcp->mb));
3718 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3719 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
3720 if (IS_QLA81XX(ha))
3721 mcp->mb[1] |= BIT_15;
3722 mcp->mb[2] = IS_QLA81XX(ha) ? vha->fcoe_fcf_idx : 0;
3723 mcp->mb[16] = LSW(mreq->rcv_dma);
3724 mcp->mb[17] = MSW(mreq->rcv_dma);
3725 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3726 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3727
3728 mcp->mb[10] = LSW(mreq->transfer_size);
3729
3730 mcp->mb[14] = LSW(mreq->send_dma);
3731 mcp->mb[15] = MSW(mreq->send_dma);
3732 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3733 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3734
3735 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3736 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
3737 if (IS_QLA81XX(ha))
3738 mcp->out_mb |= MBX_2;
3739
3740 mcp->in_mb = MBX_0;
3741 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
3742 mcp->in_mb |= MBX_1;
3743 if (IS_QLA81XX(ha))
3744 mcp->in_mb |= MBX_3;
3745
3746 mcp->tov = MBX_TOV_SECONDS;
3747 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3748 mcp->buf_size = mreq->transfer_size;
3749
3750 rval = qla2x00_mailbox_command(vha, mcp);
3751
3752 if (rval != QLA_SUCCESS) {
3753 DEBUG2(printk(KERN_WARNING
3754 "(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3755 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3756 } else {
3757 DEBUG2(printk(KERN_WARNING
3758 "scsi(%ld): done.\n", vha->host_no));
3759 }
3760
3761 /* Copy mailbox information */
3762 memcpy( mresp, mcp->mb, 32);
3763 return rval;
3764}
3765int
3766qla84xx_reset_chip(scsi_qla_host_t *ha, uint16_t enable_diagnostic,
3767 uint16_t *cmd_status)
3768{
3769 int rval;
3770 mbx_cmd_t mc;
3771 mbx_cmd_t *mcp = &mc;
3772
3773 DEBUG16(printk("%s(%ld): enable_diag=%d entered.\n", __func__,
3774 ha->host_no, enable_diagnostic));
3775
3776 mcp->mb[0] = MBC_ISP84XX_RESET;
3777 mcp->mb[1] = enable_diagnostic;
3778 mcp->out_mb = MBX_1|MBX_0;
3779 mcp->in_mb = MBX_1|MBX_0;
3780 mcp->tov = MBX_TOV_SECONDS;
3781 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3782 rval = qla2x00_mailbox_command(ha, mcp);
3783
3784 /* Return mailbox statuses. */
3785 *cmd_status = mcp->mb[0];
3786 if (rval != QLA_SUCCESS)
3787 DEBUG16(printk("%s(%ld): failed=%x.\n", __func__, ha->host_no,
3788 rval));
3789 else
3790 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3791
3792 return rval;
3793}
3794
3795int
Andrew Vasquez18e75552009-06-03 09:55:30 -07003796qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3797{
3798 int rval;
3799 mbx_cmd_t mc;
3800 mbx_cmd_t *mcp = &mc;
3801
3802 if (!IS_FWI2_CAPABLE(vha->hw))
3803 return QLA_FUNCTION_FAILED;
3804
3805 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3806
3807 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3808 mcp->mb[1] = LSW(risc_addr);
3809 mcp->mb[2] = LSW(data);
3810 mcp->mb[3] = MSW(data);
3811 mcp->mb[8] = MSW(risc_addr);
3812 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3813 mcp->in_mb = MBX_0;
3814 mcp->tov = 30;
3815 mcp->flags = 0;
3816 rval = qla2x00_mailbox_command(vha, mcp);
3817 if (rval != QLA_SUCCESS) {
3818 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3819 vha->host_no, rval, mcp->mb[0]));
3820 } else {
3821 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3822 }
3823
3824 return rval;
3825}
Michael Hernandez3064ff32009-12-15 21:29:44 -08003826
3827int
3828qla2x00_get_data_rate(scsi_qla_host_t *vha)
3829{
3830 int rval;
3831 mbx_cmd_t mc;
3832 mbx_cmd_t *mcp = &mc;
3833 struct qla_hw_data *ha = vha->hw;
3834
3835 if (!IS_FWI2_CAPABLE(ha))
3836 return QLA_FUNCTION_FAILED;
3837
3838 DEBUG11(printk(KERN_INFO "%s(%ld): entered.\n", __func__, vha->host_no));
3839
3840 mcp->mb[0] = MBC_DATA_RATE;
3841 mcp->mb[1] = 0;
3842 mcp->out_mb = MBX_1|MBX_0;
3843 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3844 mcp->tov = MBX_TOV_SECONDS;
3845 mcp->flags = 0;
3846 rval = qla2x00_mailbox_command(vha, mcp);
3847 if (rval != QLA_SUCCESS) {
3848 DEBUG2_3_11(printk(KERN_INFO "%s(%ld): failed=%x mb[0]=%x.\n",
3849 __func__, vha->host_no, rval, mcp->mb[0]));
3850 } else {
3851 DEBUG11(printk(KERN_INFO
3852 "%s(%ld): done.\n", __func__, vha->host_no));
3853 if (mcp->mb[1] != 0x7)
3854 ha->link_data_rate = mcp->mb[1];
3855 }
3856
3857 return rval;
3858}