blob: 7d7de592f720deb35848c40de540e39294484b7d [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
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070032qla2x00_mailbox_command(scsi_qla_host_t *pvha, 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;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070045 scsi_qla_host_t *ha = to_qla_parent(pvha);
46
47 reg = ha->iobase;
48 io_lock_on = ha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 rval = QLA_SUCCESS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070051 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070053 DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070056 * Wait for active mailbox commands to finish by waiting at most tov
57 * seconds. This is to serialize actual issuing of mailbox cmds during
58 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 */
60 if (!abort_active) {
Marcus Barrow0b05a1f2008-01-17 09:02:13 -080061 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp,
62 mcp->tov * HZ)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 /* Timeout occurred. Return error. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070064 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070065 "Exiting.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 return QLA_FUNCTION_TIMEOUT;
67 }
68 }
69
70 ha->flags.mbox_busy = 1;
71 /* Save mailbox command for debug */
72 ha->mcp = mcp;
73
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070074 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070075 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77 spin_lock_irqsave(&ha->hardware_lock, flags);
78
79 /* Load mailbox registers. */
Andrew Vasqueze4289242007-07-19 15:05:56 -070080 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070081 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
82 else
83 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85 iptr = mcp->mb;
86 command = mcp->mb[0];
87 mboxes = mcp->out_mb;
88
89 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
90 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070091 optr =
92 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (mboxes & BIT_0)
94 WRT_REG_WORD(optr, *iptr);
95
96 mboxes >>= 1;
97 optr++;
98 iptr++;
99 }
100
101#if defined(QL_DEBUG_LEVEL_1)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700102 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
103 __func__, ha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
105 printk("\n");
106 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
107 printk("\n");
108 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
109 printk("\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700110 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 qla2x00_dump_regs(ha);
112#endif
113
114 /* Issue set host interrupt command to send cmd out. */
115 ha->flags.mbox_int = 0;
116 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
117
118 /* Unlock mbx registers and wait for interrupt */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700119 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700120 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
122 /* Wait for mbx cmd completion until timeout */
123
124 if (!abort_active && io_lock_on) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
126 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
127
Andrew Vasqueze4289242007-07-19 15:05:56 -0700128 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700129 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
130 else
131 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 spin_unlock_irqrestore(&ha->hardware_lock, flags);
133
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800134 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700139 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700140 ha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Andrew Vasqueze4289242007-07-19 15:05:56 -0700142 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700143 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
144 else
145 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
149 while (!ha->flags.mbox_int) {
150 if (time_after(jiffies, wait_time))
151 break;
152
153 /* Check for pending interrupts. */
154 qla2x00_poll(ha);
155
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800156 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
157 !ha->flags.mbox_int)
158 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 } /* while */
160 }
161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* Check whether we timed out */
163 if (ha->flags.mbox_int) {
164 uint16_t *iptr2;
165
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700166 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700167 ha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* Got interrupt. Clear the flag. */
170 ha->flags.mbox_int = 0;
171 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
172
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400173 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 /* Load return mailbox registers. */
177 iptr2 = mcp->mb;
178 iptr = (uint16_t *)&ha->mailbox_out[0];
179 mboxes = mcp->in_mb;
180 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
181 if (mboxes & BIT_0)
182 *iptr2 = *iptr;
183
184 mboxes >>= 1;
185 iptr2++;
186 iptr++;
187 }
188 } else {
189
190#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
191 defined(QL_DEBUG_LEVEL_11)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700192 uint16_t mb0;
193 uint32_t ictrl;
194
Andrew Vasqueze4289242007-07-19 15:05:56 -0700195 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700196 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
197 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
198 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700199 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700200 ictrl = RD_REG_WORD(&reg->isp.ictrl);
201 }
202 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
203 __func__, ha->host_no, command);
204 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
205 ha->host_no, ictrl, jiffies);
206 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
207 ha->host_no, mb0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 qla2x00_dump_regs(ha);
209#endif
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 rval = QLA_FUNCTION_TIMEOUT;
212 }
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 ha->flags.mbox_busy = 0;
215
216 /* Clean up */
217 ha->mcp = NULL;
218
Andrew Vasqueza3a63d52007-10-19 15:59:14 -0700219 if (abort_active || !io_lock_on) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700220 DEBUG11(printk("%s(%ld): checking for additional resp "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700221 "interrupt.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
223 /* polling mode for non isp_abort commands. */
224 qla2x00_poll(ha);
225 }
226
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700227 if (rval == QLA_FUNCTION_TIMEOUT &&
228 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
230 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700231 DEBUG(printk("%s(%ld): timeout schedule "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700232 "isp_abort_needed.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700233 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700234 "isp_abort_needed.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 qla_printk(KERN_WARNING, ha,
236 "Mailbox command timeout occured. Scheduling ISP "
237 "abort.\n");
238 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100239 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700242 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700243 __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700244 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700245 "abort_isp\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 qla_printk(KERN_WARNING, ha,
247 "Mailbox command timeout occured. Issuing ISP "
248 "abort.\n");
249
250 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
251 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
252 if (qla2x00_abort_isp(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700253 /* Failed. retry later. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
255 }
256 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700257 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700258 ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700259 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700260 __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 }
262 }
263
264 /* Allow next mbx cmd to come in. */
265 if (!abort_active)
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800266 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700269 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
270 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700271 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700273 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 }
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return rval;
277}
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279int
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800280qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
281 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
283 int rval;
284 mbx_cmd_t mc;
285 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
288
Andrew Vasqueze4289242007-07-19 15:05:56 -0700289 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800290 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
291 mcp->mb[8] = MSW(risc_addr);
292 mcp->out_mb = MBX_8|MBX_0;
293 } else {
294 mcp->mb[0] = MBC_LOAD_RISC_RAM;
295 mcp->out_mb = MBX_0;
296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 mcp->mb[1] = LSW(risc_addr);
298 mcp->mb[2] = MSW(req_dma);
299 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 mcp->mb[6] = MSW(MSD(req_dma));
301 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800302 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700303 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700304 mcp->mb[4] = MSW(risc_code_size);
305 mcp->mb[5] = LSW(risc_code_size);
306 mcp->out_mb |= MBX_5|MBX_4;
307 } else {
308 mcp->mb[4] = LSW(risc_code_size);
309 mcp->out_mb |= MBX_4;
310 }
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700313 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 mcp->flags = 0;
315 rval = qla2x00_mailbox_command(ha, mcp);
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700318 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
319 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
322 }
323
324 return rval;
325}
326
327/*
328 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700329 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 *
331 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700332 * ha = adapter block pointer.
333 * TARGET_QUEUE_LOCK must be released.
334 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 *
336 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700337 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 *
339 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700340 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 */
342int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700343qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344{
345 int rval;
346 mbx_cmd_t mc;
347 mbx_cmd_t *mcp = &mc;
348
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700349 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700352 mcp->out_mb = MBX_0;
353 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700354 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700355 mcp->mb[1] = MSW(risc_addr);
356 mcp->mb[2] = LSW(risc_addr);
357 mcp->mb[3] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700358 mcp->mb[4] = 0;
359 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700360 mcp->in_mb |= MBX_1;
361 } else {
362 mcp->mb[1] = LSW(risc_addr);
363 mcp->out_mb |= MBX_1;
364 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
365 mcp->mb[2] = 0;
366 mcp->out_mb |= MBX_2;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
Ravi Anandb93480e2008-04-03 13:13:25 -0700370 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 mcp->flags = 0;
372 rval = qla2x00_mailbox_command(ha, mcp);
373
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700374 if (rval != QLA_SUCCESS) {
375 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
376 ha->host_no, rval, mcp->mb[0]));
377 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700378 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700379 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700380 __func__, ha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700381 } else {
382 DEBUG11(printk("%s(%ld): done.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700383 ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700384 }
385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 return rval;
388}
389
390/*
391 * qla2x00_get_fw_version
392 * Get firmware version.
393 *
394 * Input:
395 * ha: adapter state pointer.
396 * major: pointer for major number.
397 * minor: pointer for minor number.
398 * subminor: pointer for subminor number.
399 *
400 * Returns:
401 * qla2x00 local function return status code.
402 *
403 * Context:
404 * Kernel context.
405 */
406void
407qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
408 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
409{
410 int rval;
411 mbx_cmd_t mc;
412 mbx_cmd_t *mcp = &mc;
413
414 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
415
416 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
417 mcp->out_mb = MBX_0;
418 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
419 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700420 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 rval = qla2x00_mailbox_command(ha, mcp);
422
423 /* Return mailbox data. */
424 *major = mcp->mb[1];
425 *minor = mcp->mb[2];
426 *subminor = mcp->mb[3];
427 *attributes = mcp->mb[6];
428 if (IS_QLA2100(ha) || IS_QLA2200(ha))
429 *memory = 0x1FFFF; /* Defaults to 128KB. */
430 else
431 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
432
433 if (rval != QLA_SUCCESS) {
434 /*EMPTY*/
435 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
436 ha->host_no, rval));
437 } else {
438 /*EMPTY*/
439 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
440 }
441}
442
443/*
444 * qla2x00_get_fw_options
445 * Set firmware options.
446 *
447 * Input:
448 * ha = adapter block pointer.
449 * fwopt = pointer for firmware options.
450 *
451 * Returns:
452 * qla2x00 local function return status code.
453 *
454 * Context:
455 * Kernel context.
456 */
457int
458qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
459{
460 int rval;
461 mbx_cmd_t mc;
462 mbx_cmd_t *mcp = &mc;
463
464 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
465
466 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
467 mcp->out_mb = MBX_0;
468 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700469 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 mcp->flags = 0;
471 rval = qla2x00_mailbox_command(ha, mcp);
472
473 if (rval != QLA_SUCCESS) {
474 /*EMPTY*/
475 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
476 ha->host_no, rval));
477 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700478 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 fwopts[1] = mcp->mb[1];
480 fwopts[2] = mcp->mb[2];
481 fwopts[3] = mcp->mb[3];
482
483 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
484 }
485
486 return rval;
487}
488
489
490/*
491 * qla2x00_set_fw_options
492 * Set firmware options.
493 *
494 * Input:
495 * ha = adapter block pointer.
496 * fwopt = pointer for firmware options.
497 *
498 * Returns:
499 * qla2x00 local function return status code.
500 *
501 * Context:
502 * Kernel context.
503 */
504int
505qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
506{
507 int rval;
508 mbx_cmd_t mc;
509 mbx_cmd_t *mcp = &mc;
510
511 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
512
513 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
514 mcp->mb[1] = fwopts[1];
515 mcp->mb[2] = fwopts[2];
516 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700517 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700519 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700520 mcp->in_mb |= MBX_1;
521 } else {
522 mcp->mb[10] = fwopts[10];
523 mcp->mb[11] = fwopts[11];
524 mcp->mb[12] = 0; /* Undocumented, but used */
525 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
526 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700527 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 mcp->flags = 0;
529 rval = qla2x00_mailbox_command(ha, mcp);
530
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700531 fwopts[0] = mcp->mb[0];
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 if (rval != QLA_SUCCESS) {
534 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700535 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
536 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 } else {
538 /*EMPTY*/
539 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
540 }
541
542 return rval;
543}
544
545/*
546 * qla2x00_mbx_reg_test
547 * Mailbox register wrap test.
548 *
549 * Input:
550 * ha = adapter block pointer.
551 * TARGET_QUEUE_LOCK must be released.
552 * ADAPTER_STATE_LOCK must be released.
553 *
554 * Returns:
555 * qla2x00 local function return status code.
556 *
557 * Context:
558 * Kernel context.
559 */
560int
561qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
562{
563 int rval;
564 mbx_cmd_t mc;
565 mbx_cmd_t *mcp = &mc;
566
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700567 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
570 mcp->mb[1] = 0xAAAA;
571 mcp->mb[2] = 0x5555;
572 mcp->mb[3] = 0xAA55;
573 mcp->mb[4] = 0x55AA;
574 mcp->mb[5] = 0xA5A5;
575 mcp->mb[6] = 0x5A5A;
576 mcp->mb[7] = 0x2525;
577 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
578 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 -0700579 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 mcp->flags = 0;
581 rval = qla2x00_mailbox_command(ha, mcp);
582
583 if (rval == QLA_SUCCESS) {
584 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
585 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
586 rval = QLA_FUNCTION_FAILED;
587 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
588 mcp->mb[7] != 0x2525)
589 rval = QLA_FUNCTION_FAILED;
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700590 if (rval == QLA_FUNCTION_FAILED) {
591 struct device_reg_24xx __iomem *reg =
592 &ha->iobase->isp24;
593
594 qla2xxx_hw_event_log(ha, HW_EVENT_ISP_ERR, 0,
595 LSW(RD_REG_DWORD(&reg->hccr)),
596 LSW(RD_REG_DWORD(&reg->istatus)));
597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 }
599
600 if (rval != QLA_SUCCESS) {
601 /*EMPTY*/
602 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700603 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 } else {
605 /*EMPTY*/
606 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700607 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 }
609
610 return rval;
611}
612
613/*
614 * qla2x00_verify_checksum
615 * Verify firmware checksum.
616 *
617 * Input:
618 * ha = adapter block pointer.
619 * TARGET_QUEUE_LOCK must be released.
620 * ADAPTER_STATE_LOCK must be released.
621 *
622 * Returns:
623 * qla2x00 local function return status code.
624 *
625 * Context:
626 * Kernel context.
627 */
628int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700629qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630{
631 int rval;
632 mbx_cmd_t mc;
633 mbx_cmd_t *mcp = &mc;
634
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700635 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700638 mcp->out_mb = MBX_0;
639 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700640 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700641 mcp->mb[1] = MSW(risc_addr);
642 mcp->mb[2] = LSW(risc_addr);
643 mcp->out_mb |= MBX_2|MBX_1;
644 mcp->in_mb |= MBX_2|MBX_1;
645 } else {
646 mcp->mb[1] = LSW(risc_addr);
647 mcp->out_mb |= MBX_1;
648 mcp->in_mb |= MBX_1;
649 }
650
Ravi Anandb93480e2008-04-03 13:13:25 -0700651 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 mcp->flags = 0;
653 rval = qla2x00_mailbox_command(ha, mcp);
654
655 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700656 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
Andrew Vasqueze4289242007-07-19 15:05:56 -0700657 ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
658 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700660 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
662
663 return rval;
664}
665
666/*
667 * qla2x00_issue_iocb
668 * Issue IOCB using mailbox command
669 *
670 * Input:
671 * ha = adapter state pointer.
672 * buffer = buffer pointer.
673 * phys_addr = physical address of buffer.
674 * size = size of buffer.
675 * TARGET_QUEUE_LOCK must be released.
676 * ADAPTER_STATE_LOCK must be released.
677 *
678 * Returns:
679 * qla2x00 local function return status code.
680 *
681 * Context:
682 * Kernel context.
683 */
Adrian Bunk3b8117b2008-04-24 15:21:28 -0700684static int
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700685qla2x00_issue_iocb_timeout(scsi_qla_host_t *ha, void *buffer,
686 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 int rval;
689 mbx_cmd_t mc;
690 mbx_cmd_t *mcp = &mc;
691
692 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
693 mcp->mb[1] = 0;
694 mcp->mb[2] = MSW(phys_addr);
695 mcp->mb[3] = LSW(phys_addr);
696 mcp->mb[6] = MSW(MSD(phys_addr));
697 mcp->mb[7] = LSW(MSD(phys_addr));
698 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
699 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700700 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 mcp->flags = 0;
702 rval = qla2x00_mailbox_command(ha, mcp);
703
704 if (rval != QLA_SUCCESS) {
705 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700706 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700707 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700708 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700709 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700711 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
712
713 /* Mask reserved bits. */
714 sts_entry->entry_status &=
Andrew Vasqueze4289242007-07-19 15:05:56 -0700715 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
718 return rval;
719}
720
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700721int
722qla2x00_issue_iocb(scsi_qla_host_t *ha, void *buffer, dma_addr_t phys_addr,
723 size_t size)
724{
725 return qla2x00_issue_iocb_timeout(ha, buffer, phys_addr, size,
726 MBX_TOV_SECONDS);
727}
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729/*
730 * qla2x00_abort_command
731 * Abort command aborts a specified IOCB.
732 *
733 * Input:
734 * ha = adapter block pointer.
735 * sp = SB structure pointer.
736 *
737 * Returns:
738 * qla2x00 local function return status code.
739 *
740 * Context:
741 * Kernel context.
742 */
743int
744qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
745{
746 unsigned long flags = 0;
747 fc_port_t *fcport;
748 int rval;
749 uint32_t handle;
750 mbx_cmd_t mc;
751 mbx_cmd_t *mcp = &mc;
Seokmann Ju246de422008-07-10 16:55:55 -0700752 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700754 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
bdf79622005-04-17 15:06:53 -0500756 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
Seokmann Ju246de422008-07-10 16:55:55 -0700758 spin_lock_irqsave(&pha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
760 if (ha->outstanding_cmds[handle] == sp)
761 break;
762 }
Seokmann Ju246de422008-07-10 16:55:55 -0700763 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 if (handle == MAX_OUTSTANDING_COMMANDS) {
766 /* command not found */
767 return QLA_FUNCTION_FAILED;
768 }
769
770 mcp->mb[0] = MBC_ABORT_COMMAND;
771 if (HAS_EXTENDED_IDS(ha))
772 mcp->mb[1] = fcport->loop_id;
773 else
774 mcp->mb[1] = fcport->loop_id << 8;
775 mcp->mb[2] = (uint16_t)handle;
776 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500777 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
779 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700780 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 mcp->flags = 0;
782 rval = qla2x00_mailbox_command(ha, mcp);
783
784 if (rval != QLA_SUCCESS) {
785 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700786 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700789 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791
792 return rval;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700796qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700798 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 mbx_cmd_t mc;
800 mbx_cmd_t *mcp = &mc;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700801 scsi_qla_host_t *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700803 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700804
Andrew Vasquez523ec772008-04-03 13:13:24 -0700805 l = l;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700806 ha = fcport->ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700808 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700809 if (HAS_EXTENDED_IDS(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 mcp->mb[1] = fcport->loop_id;
811 mcp->mb[10] = 0;
812 mcp->out_mb |= MBX_10;
813 } else {
814 mcp->mb[1] = fcport->loop_id << 8;
815 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700816 mcp->mb[2] = ha->loop_reset_delay;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700817 mcp->mb[9] = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700820 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 mcp->flags = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700822 rval = qla2x00_mailbox_command(ha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700824 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700825 ha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700826 }
827
828 /* Issue marker IOCB. */
829 rval2 = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
830 if (rval2 != QLA_SUCCESS) {
831 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
832 "(%x).\n", __func__, ha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 } else {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700834 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
835 }
836
837 return rval;
838}
839
840int
841qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
842{
843 int rval, rval2;
844 mbx_cmd_t mc;
845 mbx_cmd_t *mcp = &mc;
846 scsi_qla_host_t *ha;
847
848 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
849
850 ha = fcport->ha;
851 mcp->mb[0] = MBC_LUN_RESET;
852 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
853 if (HAS_EXTENDED_IDS(ha))
854 mcp->mb[1] = fcport->loop_id;
855 else
856 mcp->mb[1] = fcport->loop_id << 8;
857 mcp->mb[2] = l;
858 mcp->mb[3] = 0;
859 mcp->mb[9] = ha->vp_idx;
860
861 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700862 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700863 mcp->flags = 0;
864 rval = qla2x00_mailbox_command(ha, mcp);
865 if (rval != QLA_SUCCESS) {
866 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
867 ha->host_no, rval));
868 }
869
870 /* Issue marker IOCB. */
871 rval2 = qla2x00_marker(ha, fcport->loop_id, l, MK_SYNC_ID_LUN);
872 if (rval2 != QLA_SUCCESS) {
873 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
874 "(%x).\n", __func__, ha->host_no, rval2));
875 } else {
876 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
878
879 return rval;
880}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 * qla2x00_get_adapter_id
884 * Get adapter ID and topology.
885 *
886 * Input:
887 * ha = adapter block pointer.
888 * id = pointer for loop ID.
889 * al_pa = pointer for AL_PA.
890 * area = pointer for area.
891 * domain = pointer for domain.
892 * top = pointer for topology.
893 * TARGET_QUEUE_LOCK must be released.
894 * ADAPTER_STATE_LOCK must be released.
895 *
896 * Returns:
897 * qla2x00 local function return status code.
898 *
899 * Context:
900 * Kernel context.
901 */
902int
903qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700904 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
906 int rval;
907 mbx_cmd_t mc;
908 mbx_cmd_t *mcp = &mc;
909
910 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700911 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700914 mcp->mb[9] = ha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800915 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700916 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700917 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 mcp->flags = 0;
919 rval = qla2x00_mailbox_command(ha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800920 if (mcp->mb[0] == MBS_COMMAND_ERROR)
921 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700922 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
923 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 /* Return data. */
926 *id = mcp->mb[1];
927 *al_pa = LSB(mcp->mb[2]);
928 *area = MSB(mcp->mb[2]);
929 *domain = LSB(mcp->mb[3]);
930 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700931 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 if (rval != QLA_SUCCESS) {
934 /*EMPTY*/
935 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700936 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 } else {
938 /*EMPTY*/
939 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700940 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
942
943 return rval;
944}
945
946/*
947 * qla2x00_get_retry_cnt
948 * Get current firmware login retry count and delay.
949 *
950 * Input:
951 * ha = adapter block pointer.
952 * retry_cnt = pointer to login retry count.
953 * tov = pointer to login timeout value.
954 *
955 * Returns:
956 * qla2x00 local function return status code.
957 *
958 * Context:
959 * Kernel context.
960 */
961int
962qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
963 uint16_t *r_a_tov)
964{
965 int rval;
966 uint16_t ratov;
967 mbx_cmd_t mc;
968 mbx_cmd_t *mcp = &mc;
969
970 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700971 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 mcp->mb[0] = MBC_GET_RETRY_COUNT;
974 mcp->out_mb = MBX_0;
975 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700976 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 mcp->flags = 0;
978 rval = qla2x00_mailbox_command(ha, mcp);
979
980 if (rval != QLA_SUCCESS) {
981 /*EMPTY*/
982 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700983 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 } else {
985 /* Convert returned data and check our values. */
986 *r_a_tov = mcp->mb[3] / 2;
987 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
988 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
989 /* Update to the larger values */
990 *retry_cnt = (uint8_t)mcp->mb[1];
991 *tov = ratov;
992 }
993
994 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700995 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997
998 return rval;
999}
1000
1001/*
1002 * qla2x00_init_firmware
1003 * Initialize adapter firmware.
1004 *
1005 * Input:
1006 * ha = adapter block pointer.
1007 * dptr = Initialization control block pointer.
1008 * size = size of initialization control block.
1009 * TARGET_QUEUE_LOCK must be released.
1010 * ADAPTER_STATE_LOCK must be released.
1011 *
1012 * Returns:
1013 * qla2x00 local function return status code.
1014 *
1015 * Context:
1016 * Kernel context.
1017 */
1018int
1019qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1020{
1021 int rval;
1022 mbx_cmd_t mc;
1023 mbx_cmd_t *mcp = &mc;
1024
1025 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001026 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001028 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001029 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1030 else
1031 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 mcp->mb[2] = MSW(ha->init_cb_dma);
1034 mcp->mb[3] = LSW(ha->init_cb_dma);
1035 mcp->mb[4] = 0;
1036 mcp->mb[5] = 0;
1037 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1038 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1039 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1040 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1041 mcp->buf_size = size;
1042 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001043 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 rval = qla2x00_mailbox_command(ha, mcp);
1045
1046 if (rval != QLA_SUCCESS) {
1047 /*EMPTY*/
1048 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1049 "mb0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001050 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 } else {
1052 /*EMPTY*/
1053 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001054 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056
1057 return rval;
1058}
1059
1060/*
1061 * qla2x00_get_port_database
1062 * Issue normal/enhanced get port database mailbox command
1063 * and copy device name as necessary.
1064 *
1065 * Input:
1066 * ha = adapter state pointer.
1067 * dev = structure pointer.
1068 * opt = enhanced cmd option byte.
1069 *
1070 * Returns:
1071 * qla2x00 local function return status code.
1072 *
1073 * Context:
1074 * Kernel context.
1075 */
1076int
1077qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1078{
1079 int rval;
1080 mbx_cmd_t mc;
1081 mbx_cmd_t *mcp = &mc;
1082 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001083 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 dma_addr_t pd_dma;
1085
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001086 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001088 pd24 = NULL;
1089 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001091 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1092 "structure.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 return QLA_MEMORY_ALLOC_FAILED;
1094 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001095 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001097 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001098 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 mcp->mb[2] = MSW(pd_dma);
1101 mcp->mb[3] = LSW(pd_dma);
1102 mcp->mb[6] = MSW(MSD(pd_dma));
1103 mcp->mb[7] = LSW(MSD(pd_dma));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001104 mcp->mb[9] = ha->vp_idx;
1105 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001107 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001108 mcp->mb[1] = fcport->loop_id;
1109 mcp->mb[10] = opt;
1110 mcp->out_mb |= MBX_10|MBX_1;
1111 mcp->in_mb |= MBX_1;
1112 } else if (HAS_EXTENDED_IDS(ha)) {
1113 mcp->mb[1] = fcport->loop_id;
1114 mcp->mb[10] = opt;
1115 mcp->out_mb |= MBX_10|MBX_1;
1116 } else {
1117 mcp->mb[1] = fcport->loop_id << 8 | opt;
1118 mcp->out_mb |= MBX_1;
1119 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001120 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1121 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 mcp->flags = MBX_DMA_IN;
1123 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1124 rval = qla2x00_mailbox_command(ha, mcp);
1125 if (rval != QLA_SUCCESS)
1126 goto gpd_error_out;
1127
Andrew Vasqueze4289242007-07-19 15:05:56 -07001128 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001129 pd24 = (struct port_database_24xx *) pd;
1130
1131 /* Check for logged in state. */
1132 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1133 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1134 DEBUG2(printk("%s(%ld): Unable to verify "
1135 "login-state (%x/%x) for loop_id %x\n",
1136 __func__, ha->host_no,
1137 pd24->current_login_state,
1138 pd24->last_login_state, fcport->loop_id));
1139 rval = QLA_FUNCTION_FAILED;
1140 goto gpd_error_out;
1141 }
1142
1143 /* Names are little-endian. */
1144 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1145 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1146
1147 /* Get port_id of device. */
1148 fcport->d_id.b.domain = pd24->port_id[0];
1149 fcport->d_id.b.area = pd24->port_id[1];
1150 fcport->d_id.b.al_pa = pd24->port_id[2];
1151 fcport->d_id.b.rsvd_1 = 0;
1152
1153 /* If not target must be initiator or unknown type. */
1154 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1155 fcport->port_type = FCT_INITIATOR;
1156 else
1157 fcport->port_type = FCT_TARGET;
1158 } else {
1159 /* Check for logged in state. */
1160 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1161 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1162 rval = QLA_FUNCTION_FAILED;
1163 goto gpd_error_out;
1164 }
1165
1166 /* Names are little-endian. */
1167 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1168 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1169
1170 /* Get port_id of device. */
1171 fcport->d_id.b.domain = pd->port_id[0];
1172 fcport->d_id.b.area = pd->port_id[3];
1173 fcport->d_id.b.al_pa = pd->port_id[2];
1174 fcport->d_id.b.rsvd_1 = 0;
1175
1176 /* Check for device require authentication. */
1177 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1178 (fcport->flags &= ~FCF_AUTH_REQ);
1179
1180 /* If not target must be initiator or unknown type. */
1181 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1182 fcport->port_type = FCT_INITIATOR;
1183 else
1184 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001185
1186 /* Passback COS information. */
1187 fcport->supported_classes = (pd->options & BIT_4) ?
1188 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191gpd_error_out:
1192 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1193
1194 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001195 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1196 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001198 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 }
1200
1201 return rval;
1202}
1203
1204/*
1205 * qla2x00_get_firmware_state
1206 * Get adapter firmware state.
1207 *
1208 * Input:
1209 * ha = adapter block pointer.
1210 * dptr = pointer for firmware state.
1211 * TARGET_QUEUE_LOCK must be released.
1212 * ADAPTER_STATE_LOCK must be released.
1213 *
1214 * Returns:
1215 * qla2x00 local function return status code.
1216 *
1217 * Context:
1218 * Kernel context.
1219 */
1220int
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001221qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222{
1223 int rval;
1224 mbx_cmd_t mc;
1225 mbx_cmd_t *mcp = &mc;
1226
1227 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001228 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1231 mcp->out_mb = MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001232 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001233 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 mcp->flags = 0;
1235 rval = qla2x00_mailbox_command(ha, mcp);
1236
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001237 /* Return firmware states. */
1238 states[0] = mcp->mb[1];
1239 states[1] = mcp->mb[2];
1240 states[2] = mcp->mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
1242 if (rval != QLA_SUCCESS) {
1243 /*EMPTY*/
1244 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001245 "failed=%x.\n", ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 } else {
1247 /*EMPTY*/
1248 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001249 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 }
1251
1252 return rval;
1253}
1254
1255/*
1256 * qla2x00_get_port_name
1257 * Issue get port name mailbox command.
1258 * Returned name is in big endian format.
1259 *
1260 * Input:
1261 * ha = adapter block pointer.
1262 * loop_id = loop ID of device.
1263 * name = pointer for name.
1264 * TARGET_QUEUE_LOCK must be released.
1265 * ADAPTER_STATE_LOCK must be released.
1266 *
1267 * Returns:
1268 * qla2x00 local function return status code.
1269 *
1270 * Context:
1271 * Kernel context.
1272 */
1273int
1274qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1275 uint8_t opt)
1276{
1277 int rval;
1278 mbx_cmd_t mc;
1279 mbx_cmd_t *mcp = &mc;
1280
1281 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001282 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 mcp->mb[0] = MBC_GET_PORT_NAME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001285 mcp->mb[9] = ha->vp_idx;
1286 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 if (HAS_EXTENDED_IDS(ha)) {
1288 mcp->mb[1] = loop_id;
1289 mcp->mb[10] = opt;
1290 mcp->out_mb |= MBX_10;
1291 } else {
1292 mcp->mb[1] = loop_id << 8 | opt;
1293 }
1294
1295 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001296 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 mcp->flags = 0;
1298 rval = qla2x00_mailbox_command(ha, mcp);
1299
1300 if (rval != QLA_SUCCESS) {
1301 /*EMPTY*/
1302 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001303 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 } else {
1305 if (name != NULL) {
1306 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001307 name[0] = MSB(mcp->mb[2]);
1308 name[1] = LSB(mcp->mb[2]);
1309 name[2] = MSB(mcp->mb[3]);
1310 name[3] = LSB(mcp->mb[3]);
1311 name[4] = MSB(mcp->mb[6]);
1312 name[5] = LSB(mcp->mb[6]);
1313 name[6] = MSB(mcp->mb[7]);
1314 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 }
1316
1317 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001318 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 }
1320
1321 return rval;
1322}
1323
1324/*
1325 * qla2x00_lip_reset
1326 * Issue LIP reset mailbox command.
1327 *
1328 * Input:
1329 * ha = adapter block pointer.
1330 * TARGET_QUEUE_LOCK must be released.
1331 * ADAPTER_STATE_LOCK must be released.
1332 *
1333 * Returns:
1334 * qla2x00 local function return status code.
1335 *
1336 * Context:
1337 * Kernel context.
1338 */
1339int
1340qla2x00_lip_reset(scsi_qla_host_t *ha)
1341{
1342 int rval;
1343 mbx_cmd_t mc;
1344 mbx_cmd_t *mcp = &mc;
1345
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001346 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347
Andrew Vasqueze4289242007-07-19 15:05:56 -07001348 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001349 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001350 mcp->mb[1] = BIT_6;
1351 mcp->mb[2] = 0;
1352 mcp->mb[3] = ha->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001353 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001355 mcp->mb[0] = MBC_LIP_RESET;
1356 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1357 if (HAS_EXTENDED_IDS(ha)) {
1358 mcp->mb[1] = 0x00ff;
1359 mcp->mb[10] = 0;
1360 mcp->out_mb |= MBX_10;
1361 } else {
1362 mcp->mb[1] = 0xff00;
1363 }
1364 mcp->mb[2] = ha->loop_reset_delay;
1365 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001368 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 mcp->flags = 0;
1370 rval = qla2x00_mailbox_command(ha, mcp);
1371
1372 if (rval != QLA_SUCCESS) {
1373 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001374 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001375 __func__, ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 } else {
1377 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001378 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380
1381 return rval;
1382}
1383
1384/*
1385 * qla2x00_send_sns
1386 * Send SNS command.
1387 *
1388 * Input:
1389 * ha = adapter block pointer.
1390 * sns = pointer for command.
1391 * cmd_size = command size.
1392 * buf_size = response/command size.
1393 * TARGET_QUEUE_LOCK must be released.
1394 * ADAPTER_STATE_LOCK must be released.
1395 *
1396 * Returns:
1397 * qla2x00 local function return status code.
1398 *
1399 * Context:
1400 * Kernel context.
1401 */
1402int
1403qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1404 uint16_t cmd_size, size_t buf_size)
1405{
1406 int rval;
1407 mbx_cmd_t mc;
1408 mbx_cmd_t *mcp = &mc;
1409
1410 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001411 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001414 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
1416 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1417 mcp->mb[1] = cmd_size;
1418 mcp->mb[2] = MSW(sns_phys_address);
1419 mcp->mb[3] = LSW(sns_phys_address);
1420 mcp->mb[6] = MSW(MSD(sns_phys_address));
1421 mcp->mb[7] = LSW(MSD(sns_phys_address));
1422 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1423 mcp->in_mb = MBX_0|MBX_1;
1424 mcp->buf_size = buf_size;
1425 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1426 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1427 rval = qla2x00_mailbox_command(ha, mcp);
1428
1429 if (rval != QLA_SUCCESS) {
1430 /*EMPTY*/
1431 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001432 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001434 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 } else {
1436 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001437 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439
1440 return rval;
1441}
1442
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001443int
1444qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1445 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1446{
1447 int rval;
1448
1449 struct logio_entry_24xx *lg;
1450 dma_addr_t lg_dma;
1451 uint32_t iop[2];
1452
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001453 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001454
1455 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1456 if (lg == NULL) {
1457 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1458 __func__, ha->host_no));
1459 return QLA_MEMORY_ALLOC_FAILED;
1460 }
1461 memset(lg, 0, sizeof(struct logio_entry_24xx));
1462
1463 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1464 lg->entry_count = 1;
1465 lg->nport_handle = cpu_to_le16(loop_id);
1466 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1467 if (opt & BIT_0)
1468 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001469 if (opt & BIT_1)
1470 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001471 lg->port_id[0] = al_pa;
1472 lg->port_id[1] = area;
1473 lg->port_id[2] = domain;
Seokmann Juc6852c42008-04-24 15:21:29 -07001474 lg->vp_index = ha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001475 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1476 if (rval != QLA_SUCCESS) {
1477 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001478 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001479 } else if (lg->entry_status != 0) {
1480 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1481 "-- error status (%x).\n", __func__, ha->host_no,
1482 lg->entry_status));
1483 rval = QLA_FUNCTION_FAILED;
1484 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1485 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1486 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1487
1488 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1489 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1490 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1491 iop[1]));
1492
1493 switch (iop[0]) {
1494 case LSC_SCODE_PORTID_USED:
1495 mb[0] = MBS_PORT_ID_USED;
1496 mb[1] = LSW(iop[1]);
1497 break;
1498 case LSC_SCODE_NPORT_USED:
1499 mb[0] = MBS_LOOP_ID_USED;
1500 break;
1501 case LSC_SCODE_NOLINK:
1502 case LSC_SCODE_NOIOCB:
1503 case LSC_SCODE_NOXCB:
1504 case LSC_SCODE_CMD_FAILED:
1505 case LSC_SCODE_NOFABRIC:
1506 case LSC_SCODE_FW_NOT_READY:
1507 case LSC_SCODE_NOT_LOGGED_IN:
1508 case LSC_SCODE_NOPCB:
1509 case LSC_SCODE_ELS_REJECT:
1510 case LSC_SCODE_CMD_PARAM_ERR:
1511 case LSC_SCODE_NONPORT:
1512 case LSC_SCODE_LOGGED_IN:
1513 case LSC_SCODE_NOFLOGI_ACC:
1514 default:
1515 mb[0] = MBS_COMMAND_ERROR;
1516 break;
1517 }
1518 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001519 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001520
1521 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1522
1523 mb[0] = MBS_COMMAND_COMPLETE;
1524 mb[1] = 0;
1525 if (iop[0] & BIT_4) {
1526 if (iop[0] & BIT_8)
1527 mb[1] |= BIT_1;
1528 } else
1529 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001530
1531 /* Passback COS information. */
1532 mb[10] = 0;
1533 if (lg->io_parameter[7] || lg->io_parameter[8])
1534 mb[10] |= BIT_0; /* Class 2. */
1535 if (lg->io_parameter[9] || lg->io_parameter[10])
1536 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001537 }
1538
1539 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1540
1541 return rval;
1542}
1543
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544/*
1545 * qla2x00_login_fabric
1546 * Issue login fabric port mailbox command.
1547 *
1548 * Input:
1549 * ha = adapter block pointer.
1550 * loop_id = device loop ID.
1551 * domain = device domain.
1552 * area = device area.
1553 * al_pa = device AL_PA.
1554 * status = pointer for return status.
1555 * opt = command options.
1556 * TARGET_QUEUE_LOCK must be released.
1557 * ADAPTER_STATE_LOCK must be released.
1558 *
1559 * Returns:
1560 * qla2x00 local function return status code.
1561 *
1562 * Context:
1563 * Kernel context.
1564 */
1565int
1566qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1567 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1568{
1569 int rval;
1570 mbx_cmd_t mc;
1571 mbx_cmd_t *mcp = &mc;
1572
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001573 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
1575 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1576 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1577 if (HAS_EXTENDED_IDS(ha)) {
1578 mcp->mb[1] = loop_id;
1579 mcp->mb[10] = opt;
1580 mcp->out_mb |= MBX_10;
1581 } else {
1582 mcp->mb[1] = (loop_id << 8) | opt;
1583 }
1584 mcp->mb[2] = domain;
1585 mcp->mb[3] = area << 8 | al_pa;
1586
1587 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1588 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1589 mcp->flags = 0;
1590 rval = qla2x00_mailbox_command(ha, mcp);
1591
1592 /* Return mailbox statuses. */
1593 if (mb != NULL) {
1594 mb[0] = mcp->mb[0];
1595 mb[1] = mcp->mb[1];
1596 mb[2] = mcp->mb[2];
1597 mb[6] = mcp->mb[6];
1598 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001599 /* COS retrieved from Get-Port-Database mailbox command. */
1600 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 }
1602
1603 if (rval != QLA_SUCCESS) {
1604 /* RLU tmp code: need to change main mailbox_command function to
1605 * return ok even when the mailbox completion value is not
1606 * SUCCESS. The caller needs to be responsible to interpret
1607 * the return values of this mailbox command if we're not
1608 * to change too much of the existing code.
1609 */
1610 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1611 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1612 mcp->mb[0] == 0x4006)
1613 rval = QLA_SUCCESS;
1614
1615 /*EMPTY*/
1616 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1617 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001618 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 } else {
1620 /*EMPTY*/
1621 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001622 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 }
1624
1625 return rval;
1626}
1627
1628/*
1629 * qla2x00_login_local_device
1630 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001631 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 * Input:
1633 * ha = adapter block pointer.
1634 * loop_id = device loop ID.
1635 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001636 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 * Returns:
1638 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001639 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 * Context:
1641 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001642 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 */
1644int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001645qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 uint16_t *mb_ret, uint8_t opt)
1647{
1648 int rval;
1649 mbx_cmd_t mc;
1650 mbx_cmd_t *mcp = &mc;
1651
Andrew Vasqueze4289242007-07-19 15:05:56 -07001652 if (IS_FWI2_CAPABLE(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001653 return qla24xx_login_fabric(ha, fcport->loop_id,
1654 fcport->d_id.b.domain, fcport->d_id.b.area,
1655 fcport->d_id.b.al_pa, mb_ret, opt);
1656
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001657 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1660 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001661 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001663 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 mcp->mb[2] = opt;
1665 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1666 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1667 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1668 mcp->flags = 0;
1669 rval = qla2x00_mailbox_command(ha, mcp);
1670
1671 /* Return mailbox statuses. */
1672 if (mb_ret != NULL) {
1673 mb_ret[0] = mcp->mb[0];
1674 mb_ret[1] = mcp->mb[1];
1675 mb_ret[6] = mcp->mb[6];
1676 mb_ret[7] = mcp->mb[7];
1677 }
1678
1679 if (rval != QLA_SUCCESS) {
1680 /* AV tmp code: need to change main mailbox_command function to
1681 * return ok even when the mailbox completion value is not
1682 * SUCCESS. The caller needs to be responsible to interpret
1683 * the return values of this mailbox command if we're not
1684 * to change too much of the existing code.
1685 */
1686 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1687 rval = QLA_SUCCESS;
1688
1689 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1690 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001691 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1693 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001694 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 } else {
1696 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001697 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 }
1699
1700 return (rval);
1701}
1702
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001703int
1704qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1705 uint8_t area, uint8_t al_pa)
1706{
1707 int rval;
1708 struct logio_entry_24xx *lg;
1709 dma_addr_t lg_dma;
1710
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001711 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001712
1713 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1714 if (lg == NULL) {
1715 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1716 __func__, ha->host_no));
1717 return QLA_MEMORY_ALLOC_FAILED;
1718 }
1719 memset(lg, 0, sizeof(struct logio_entry_24xx));
1720
1721 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1722 lg->entry_count = 1;
1723 lg->nport_handle = cpu_to_le16(loop_id);
1724 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001725 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001726 lg->port_id[0] = al_pa;
1727 lg->port_id[1] = area;
1728 lg->port_id[2] = domain;
Seokmann Juc6852c42008-04-24 15:21:29 -07001729 lg->vp_index = ha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001730 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1731 if (rval != QLA_SUCCESS) {
1732 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001733 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001734 } else if (lg->entry_status != 0) {
1735 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1736 "-- error status (%x).\n", __func__, ha->host_no,
1737 lg->entry_status));
1738 rval = QLA_FUNCTION_FAILED;
1739 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1740 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1741 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1742 ha->host_no, le16_to_cpu(lg->comp_status),
1743 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001744 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001745 } else {
1746 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001747 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001748 }
1749
1750 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1751
1752 return rval;
1753}
1754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755/*
1756 * qla2x00_fabric_logout
1757 * Issue logout fabric port mailbox command.
1758 *
1759 * Input:
1760 * ha = adapter block pointer.
1761 * loop_id = device loop ID.
1762 * TARGET_QUEUE_LOCK must be released.
1763 * ADAPTER_STATE_LOCK must be released.
1764 *
1765 * Returns:
1766 * qla2x00 local function return status code.
1767 *
1768 * Context:
1769 * Kernel context.
1770 */
1771int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001772qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1773 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 int rval;
1776 mbx_cmd_t mc;
1777 mbx_cmd_t *mcp = &mc;
1778
1779 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001780 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1783 mcp->out_mb = MBX_1|MBX_0;
1784 if (HAS_EXTENDED_IDS(ha)) {
1785 mcp->mb[1] = loop_id;
1786 mcp->mb[10] = 0;
1787 mcp->out_mb |= MBX_10;
1788 } else {
1789 mcp->mb[1] = loop_id << 8;
1790 }
1791
1792 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001793 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 mcp->flags = 0;
1795 rval = qla2x00_mailbox_command(ha, mcp);
1796
1797 if (rval != QLA_SUCCESS) {
1798 /*EMPTY*/
1799 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001800 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 } else {
1802 /*EMPTY*/
1803 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001804 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 }
1806
1807 return rval;
1808}
1809
1810/*
1811 * qla2x00_full_login_lip
1812 * Issue full login LIP mailbox command.
1813 *
1814 * Input:
1815 * ha = adapter block pointer.
1816 * TARGET_QUEUE_LOCK must be released.
1817 * ADAPTER_STATE_LOCK must be released.
1818 *
1819 * Returns:
1820 * qla2x00 local function return status code.
1821 *
1822 * Context:
1823 * Kernel context.
1824 */
1825int
1826qla2x00_full_login_lip(scsi_qla_host_t *ha)
1827{
1828 int rval;
1829 mbx_cmd_t mc;
1830 mbx_cmd_t *mcp = &mc;
1831
1832 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001833 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001836 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001837 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 mcp->mb[3] = 0;
1839 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1840 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001841 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 mcp->flags = 0;
1843 rval = qla2x00_mailbox_command(ha, mcp);
1844
1845 if (rval != QLA_SUCCESS) {
1846 /*EMPTY*/
1847 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001848 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 } else {
1850 /*EMPTY*/
1851 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001852 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 }
1854
1855 return rval;
1856}
1857
1858/*
1859 * qla2x00_get_id_list
1860 *
1861 * Input:
1862 * ha = adapter block pointer.
1863 *
1864 * Returns:
1865 * qla2x00 local function return status code.
1866 *
1867 * Context:
1868 * Kernel context.
1869 */
1870int
1871qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1872 uint16_t *entries)
1873{
1874 int rval;
1875 mbx_cmd_t mc;
1876 mbx_cmd_t *mcp = &mc;
1877
1878 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001879 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
1881 if (id_list == NULL)
1882 return QLA_FUNCTION_FAILED;
1883
1884 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001885 mcp->out_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001886 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001887 mcp->mb[2] = MSW(id_list_dma);
1888 mcp->mb[3] = LSW(id_list_dma);
1889 mcp->mb[6] = MSW(MSD(id_list_dma));
1890 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001891 mcp->mb[8] = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001892 mcp->mb[9] = ha->vp_idx;
1893 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001894 } else {
1895 mcp->mb[1] = MSW(id_list_dma);
1896 mcp->mb[2] = LSW(id_list_dma);
1897 mcp->mb[3] = MSW(MSD(id_list_dma));
1898 mcp->mb[6] = LSW(MSD(id_list_dma));
1899 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001902 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 mcp->flags = 0;
1904 rval = qla2x00_mailbox_command(ha, mcp);
1905
1906 if (rval != QLA_SUCCESS) {
1907 /*EMPTY*/
1908 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001909 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 } else {
1911 *entries = mcp->mb[1];
1912 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001913 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 }
1915
1916 return rval;
1917}
1918
1919/*
1920 * qla2x00_get_resource_cnts
1921 * Get current firmware resource counts.
1922 *
1923 * Input:
1924 * ha = adapter block pointer.
1925 *
1926 * Returns:
1927 * qla2x00 local function return status code.
1928 *
1929 * Context:
1930 * Kernel context.
1931 */
1932int
1933qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001934 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1935 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936{
1937 int rval;
1938 mbx_cmd_t mc;
1939 mbx_cmd_t *mcp = &mc;
1940
1941 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1942
1943 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1944 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001945 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001946 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 mcp->flags = 0;
1948 rval = qla2x00_mailbox_command(ha, mcp);
1949
1950 if (rval != QLA_SUCCESS) {
1951 /*EMPTY*/
1952 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001953 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 } else {
1955 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001956 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001957 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001958 mcp->mb[10], mcp->mb[11]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
1960 if (cur_xchg_cnt)
1961 *cur_xchg_cnt = mcp->mb[3];
1962 if (orig_xchg_cnt)
1963 *orig_xchg_cnt = mcp->mb[6];
1964 if (cur_iocb_cnt)
1965 *cur_iocb_cnt = mcp->mb[7];
1966 if (orig_iocb_cnt)
1967 *orig_iocb_cnt = mcp->mb[10];
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001968 if (max_npiv_vports)
1969 *max_npiv_vports = mcp->mb[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 }
1971
1972 return (rval);
1973}
1974
1975#if defined(QL_DEBUG_LEVEL_3)
1976/*
1977 * qla2x00_get_fcal_position_map
1978 * Get FCAL (LILP) position map using mailbox command
1979 *
1980 * Input:
1981 * ha = adapter state pointer.
1982 * pos_map = buffer pointer (can be NULL).
1983 *
1984 * Returns:
1985 * qla2x00 local function return status code.
1986 *
1987 * Context:
1988 * Kernel context.
1989 */
1990int
1991qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1992{
1993 int rval;
1994 mbx_cmd_t mc;
1995 mbx_cmd_t *mcp = &mc;
1996 char *pmap;
1997 dma_addr_t pmap_dma;
1998
1999 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
2000 if (pmap == NULL) {
2001 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2002 __func__, ha->host_no));
2003 return QLA_MEMORY_ALLOC_FAILED;
2004 }
2005 memset(pmap, 0, FCAL_MAP_SIZE);
2006
2007 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2008 mcp->mb[2] = MSW(pmap_dma);
2009 mcp->mb[3] = LSW(pmap_dma);
2010 mcp->mb[6] = MSW(MSD(pmap_dma));
2011 mcp->mb[7] = LSW(MSD(pmap_dma));
2012 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2013 mcp->in_mb = MBX_1|MBX_0;
2014 mcp->buf_size = FCAL_MAP_SIZE;
2015 mcp->flags = MBX_DMA_IN;
2016 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2017 rval = qla2x00_mailbox_command(ha, mcp);
2018
2019 if (rval == QLA_SUCCESS) {
2020 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2021 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2022 mcp->mb[1], (unsigned)pmap[0]));
2023 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2024
2025 if (pos_map)
2026 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2027 }
2028 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2029
2030 if (rval != QLA_SUCCESS) {
2031 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2032 ha->host_no, rval));
2033 } else {
2034 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2035 }
2036
2037 return rval;
2038}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002039#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002040
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002041/*
2042 * qla2x00_get_link_status
2043 *
2044 * Input:
2045 * ha = adapter block pointer.
2046 * loop_id = device loop ID.
2047 * ret_buf = pointer to link status return buffer.
2048 *
2049 * Returns:
2050 * 0 = success.
2051 * BIT_0 = mem alloc error.
2052 * BIT_1 = mailbox error.
2053 */
2054int
2055qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002056 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002057{
2058 int rval;
2059 mbx_cmd_t mc;
2060 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002061 uint32_t *siter, *diter, dwords;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002062
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002063 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002064
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002065 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002066 mcp->mb[2] = MSW(stats_dma);
2067 mcp->mb[3] = LSW(stats_dma);
2068 mcp->mb[6] = MSW(MSD(stats_dma));
2069 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002070 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2071 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002072 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002073 mcp->mb[1] = loop_id;
2074 mcp->mb[4] = 0;
2075 mcp->mb[10] = 0;
2076 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2077 mcp->in_mb |= MBX_1;
2078 } else if (HAS_EXTENDED_IDS(ha)) {
2079 mcp->mb[1] = loop_id;
2080 mcp->mb[10] = 0;
2081 mcp->out_mb |= MBX_10|MBX_1;
2082 } else {
2083 mcp->mb[1] = loop_id << 8;
2084 mcp->out_mb |= MBX_1;
2085 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002086 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002087 mcp->flags = IOCTL_CMD;
2088 rval = qla2x00_mailbox_command(ha, mcp);
2089
2090 if (rval == QLA_SUCCESS) {
2091 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2092 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002093 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002094 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002095 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002096 /* Copy over data -- firmware data is LE. */
2097 dwords = offsetof(struct link_statistics, unused1) / 4;
2098 siter = diter = &stats->link_fail_cnt;
2099 while (dwords--)
2100 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002101 }
2102 } else {
2103 /* Failed. */
2104 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002105 ha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002106 }
2107
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002108 return rval;
2109}
2110
2111int
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002112qla24xx_get_isp_stats(scsi_qla_host_t *ha, struct link_statistics *stats,
2113 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002114{
2115 int rval;
2116 mbx_cmd_t mc;
2117 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002118 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002119
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002120 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002121
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002122 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002123 mcp->mb[2] = MSW(stats_dma);
2124 mcp->mb[3] = LSW(stats_dma);
2125 mcp->mb[6] = MSW(MSD(stats_dma));
2126 mcp->mb[7] = LSW(MSD(stats_dma));
2127 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2128 mcp->mb[9] = ha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002129 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002130 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 -07002131 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002132 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002133 mcp->flags = IOCTL_CMD;
2134 rval = qla2x00_mailbox_command(ha, mcp);
2135
2136 if (rval == QLA_SUCCESS) {
2137 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2138 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2139 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002140 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002141 } else {
2142 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002143 dwords = sizeof(struct link_statistics) / 4;
2144 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002145 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002146 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002147 }
2148 } else {
2149 /* Failed. */
2150 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2151 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002152 }
2153
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002154 return rval;
2155}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002156
2157int
2158qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2159{
2160 int rval;
2161 fc_port_t *fcport;
2162 unsigned long flags = 0;
2163
2164 struct abort_entry_24xx *abt;
2165 dma_addr_t abt_dma;
2166 uint32_t handle;
Seokmann Ju246de422008-07-10 16:55:55 -07002167 scsi_qla_host_t *pha = to_qla_parent(ha);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002168
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002169 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002170
2171 fcport = sp->fcport;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002172
Seokmann Ju246de422008-07-10 16:55:55 -07002173 spin_lock_irqsave(&pha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002174 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2175 if (ha->outstanding_cmds[handle] == sp)
2176 break;
2177 }
Seokmann Ju246de422008-07-10 16:55:55 -07002178 spin_unlock_irqrestore(&pha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002179 if (handle == MAX_OUTSTANDING_COMMANDS) {
2180 /* Command not found. */
2181 return QLA_FUNCTION_FAILED;
2182 }
2183
2184 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2185 if (abt == NULL) {
2186 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2187 __func__, ha->host_no));
2188 return QLA_MEMORY_ALLOC_FAILED;
2189 }
2190 memset(abt, 0, sizeof(struct abort_entry_24xx));
2191
2192 abt->entry_type = ABORT_IOCB_TYPE;
2193 abt->entry_count = 1;
2194 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2195 abt->handle_to_abort = handle;
2196 abt->port_id[0] = fcport->d_id.b.al_pa;
2197 abt->port_id[1] = fcport->d_id.b.area;
2198 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002199 abt->vp_index = fcport->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002200 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2201 if (rval != QLA_SUCCESS) {
2202 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002203 __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002204 } else if (abt->entry_status != 0) {
2205 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2206 "-- error status (%x).\n", __func__, ha->host_no,
2207 abt->entry_status));
2208 rval = QLA_FUNCTION_FAILED;
2209 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2210 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2211 "-- completion status (%x).\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002212 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002213 rval = QLA_FUNCTION_FAILED;
2214 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002215 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002216 }
2217
2218 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2219
2220 return rval;
2221}
2222
2223struct tsk_mgmt_cmd {
2224 union {
2225 struct tsk_mgmt_entry tsk;
2226 struct sts_entry_24xx sts;
2227 } p;
2228};
2229
Andrew Vasquez523ec772008-04-03 13:13:24 -07002230static int
2231__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2232 unsigned int l)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002233{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002234 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002235 struct tsk_mgmt_cmd *tsk;
2236 dma_addr_t tsk_dma;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002237 scsi_qla_host_t *ha, *pha;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002238
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002239 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002240
2241 ha = fcport->ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002242 pha = to_qla_parent(ha);
2243 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002244 if (tsk == NULL) {
2245 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2246 "IOCB.\n", __func__, ha->host_no));
2247 return QLA_MEMORY_ALLOC_FAILED;
2248 }
2249 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2250
2251 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2252 tsk->p.tsk.entry_count = 1;
2253 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002254 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002255 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002256 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2257 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2258 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002259 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002260 if (type == TCF_LUN_RESET) {
2261 int_to_scsilun(l, &tsk->p.tsk.lun);
2262 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2263 sizeof(tsk->p.tsk.lun));
2264 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002265
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002266 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2267 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002268 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2269 "(%x).\n", __func__, ha->host_no, name, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002270 } else if (tsk->p.sts.entry_status != 0) {
2271 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2272 "-- error status (%x).\n", __func__, ha->host_no,
2273 tsk->p.sts.entry_status));
2274 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002275 } else if (tsk->p.sts.comp_status !=
2276 __constant_cpu_to_le16(CS_COMPLETE)) {
2277 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2278 "-- completion status (%x).\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002279 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002280 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002281 }
2282
2283 /* Issue marker IOCB. */
Andrew Vasquez523ec772008-04-03 13:13:24 -07002284 rval2 = qla2x00_marker(ha, fcport->loop_id, l,
2285 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2286 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002287 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Andrew Vasquez523ec772008-04-03 13:13:24 -07002288 "(%x).\n", __func__, ha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002289 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002290 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002291 }
2292
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002293 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002294
2295 return rval;
2296}
2297
Andrew Vasquez523ec772008-04-03 13:13:24 -07002298int
2299qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2300{
2301 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2302}
2303
2304int
2305qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2306{
2307 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2308}
2309
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002310int
2311qla2x00_system_error(scsi_qla_host_t *ha)
2312{
2313 int rval;
2314 mbx_cmd_t mc;
2315 mbx_cmd_t *mcp = &mc;
2316
Andrew Vasquez68af0812008-05-12 22:21:13 -07002317 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002318 return QLA_FUNCTION_FAILED;
2319
2320 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2321
2322 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2323 mcp->out_mb = MBX_0;
2324 mcp->in_mb = MBX_0;
2325 mcp->tov = 5;
2326 mcp->flags = 0;
2327 rval = qla2x00_mailbox_command(ha, mcp);
2328
2329 if (rval != QLA_SUCCESS) {
2330 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2331 ha->host_no, rval));
2332 } else {
2333 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2334 }
2335
2336 return rval;
2337}
2338
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002339/**
2340 * qla2x00_set_serdes_params() -
2341 * @ha: HA context
2342 *
2343 * Returns
2344 */
2345int
2346qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2347 uint16_t sw_em_2g, uint16_t sw_em_4g)
2348{
2349 int rval;
2350 mbx_cmd_t mc;
2351 mbx_cmd_t *mcp = &mc;
2352
2353 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2354
2355 mcp->mb[0] = MBC_SERDES_PARAMS;
2356 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002357 mcp->mb[2] = sw_em_1g | BIT_15;
2358 mcp->mb[3] = sw_em_2g | BIT_15;
2359 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002360 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2361 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002362 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002363 mcp->flags = 0;
2364 rval = qla2x00_mailbox_command(ha, mcp);
2365
2366 if (rval != QLA_SUCCESS) {
2367 /*EMPTY*/
2368 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2369 ha->host_no, rval, mcp->mb[0]));
2370 } else {
2371 /*EMPTY*/
2372 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2373 }
2374
2375 return rval;
2376}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002377
2378int
2379qla2x00_stop_firmware(scsi_qla_host_t *ha)
2380{
2381 int rval;
2382 mbx_cmd_t mc;
2383 mbx_cmd_t *mcp = &mc;
2384
Andrew Vasqueze4289242007-07-19 15:05:56 -07002385 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002386 return QLA_FUNCTION_FAILED;
2387
2388 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2389
2390 mcp->mb[0] = MBC_STOP_FIRMWARE;
2391 mcp->out_mb = MBX_0;
2392 mcp->in_mb = MBX_0;
2393 mcp->tov = 5;
2394 mcp->flags = 0;
2395 rval = qla2x00_mailbox_command(ha, mcp);
2396
2397 if (rval != QLA_SUCCESS) {
2398 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2399 ha->host_no, rval));
2400 } else {
2401 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2402 }
2403
2404 return rval;
2405}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002406
2407int
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002408qla2x00_enable_eft_trace(scsi_qla_host_t *ha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002409 uint16_t buffers)
2410{
2411 int rval;
2412 mbx_cmd_t mc;
2413 mbx_cmd_t *mcp = &mc;
2414
Andrew Vasqueze4289242007-07-19 15:05:56 -07002415 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002416 return QLA_FUNCTION_FAILED;
2417
2418 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2419
2420 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002421 mcp->mb[1] = TC_EFT_ENABLE;
2422 mcp->mb[2] = LSW(eft_dma);
2423 mcp->mb[3] = MSW(eft_dma);
2424 mcp->mb[4] = LSW(MSD(eft_dma));
2425 mcp->mb[5] = MSW(MSD(eft_dma));
2426 mcp->mb[6] = buffers;
2427 mcp->mb[7] = TC_AEN_DISABLE;
2428 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 -07002429 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002430 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002431 mcp->flags = 0;
2432 rval = qla2x00_mailbox_command(ha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002433 if (rval != QLA_SUCCESS) {
2434 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2435 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2436 } else {
2437 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2438 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002439
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002440 return rval;
2441}
2442
2443int
2444qla2x00_disable_eft_trace(scsi_qla_host_t *ha)
2445{
2446 int rval;
2447 mbx_cmd_t mc;
2448 mbx_cmd_t *mcp = &mc;
2449
2450 if (!IS_FWI2_CAPABLE(ha))
2451 return QLA_FUNCTION_FAILED;
2452
2453 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2454
2455 mcp->mb[0] = MBC_TRACE_CONTROL;
2456 mcp->mb[1] = TC_EFT_DISABLE;
2457 mcp->out_mb = MBX_1|MBX_0;
2458 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002459 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002460 mcp->flags = 0;
2461 rval = qla2x00_mailbox_command(ha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002462 if (rval != QLA_SUCCESS) {
2463 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2464 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2465 } else {
2466 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2467 }
2468
2469 return rval;
2470}
2471
Andrew Vasquez88729e52006-06-23 16:10:50 -07002472int
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002473qla2x00_enable_fce_trace(scsi_qla_host_t *ha, dma_addr_t fce_dma,
2474 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2475{
2476 int rval;
2477 mbx_cmd_t mc;
2478 mbx_cmd_t *mcp = &mc;
2479
2480 if (!IS_QLA25XX(ha))
2481 return QLA_FUNCTION_FAILED;
2482
2483 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2484
2485 mcp->mb[0] = MBC_TRACE_CONTROL;
2486 mcp->mb[1] = TC_FCE_ENABLE;
2487 mcp->mb[2] = LSW(fce_dma);
2488 mcp->mb[3] = MSW(fce_dma);
2489 mcp->mb[4] = LSW(MSD(fce_dma));
2490 mcp->mb[5] = MSW(MSD(fce_dma));
2491 mcp->mb[6] = buffers;
2492 mcp->mb[7] = TC_AEN_DISABLE;
2493 mcp->mb[8] = 0;
2494 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2495 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2496 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2497 MBX_1|MBX_0;
2498 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002499 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002500 mcp->flags = 0;
2501 rval = qla2x00_mailbox_command(ha, mcp);
2502 if (rval != QLA_SUCCESS) {
2503 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2504 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2505 } else {
2506 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2507
2508 if (mb)
2509 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2510 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002511 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002512 }
2513
2514 return rval;
2515}
2516
2517int
2518qla2x00_disable_fce_trace(scsi_qla_host_t *ha, uint64_t *wr, uint64_t *rd)
2519{
2520 int rval;
2521 mbx_cmd_t mc;
2522 mbx_cmd_t *mcp = &mc;
2523
2524 if (!IS_FWI2_CAPABLE(ha))
2525 return QLA_FUNCTION_FAILED;
2526
2527 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2528
2529 mcp->mb[0] = MBC_TRACE_CONTROL;
2530 mcp->mb[1] = TC_FCE_DISABLE;
2531 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2532 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2533 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2534 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002535 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002536 mcp->flags = 0;
2537 rval = qla2x00_mailbox_command(ha, mcp);
2538 if (rval != QLA_SUCCESS) {
2539 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2540 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2541 } else {
2542 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2543
2544 if (wr)
2545 *wr = (uint64_t) mcp->mb[5] << 48 |
2546 (uint64_t) mcp->mb[4] << 32 |
2547 (uint64_t) mcp->mb[3] << 16 |
2548 (uint64_t) mcp->mb[2];
2549 if (rd)
2550 *rd = (uint64_t) mcp->mb[9] << 48 |
2551 (uint64_t) mcp->mb[8] << 32 |
2552 (uint64_t) mcp->mb[7] << 16 |
2553 (uint64_t) mcp->mb[6];
2554 }
2555
2556 return rval;
2557}
2558
2559int
Andrew Vasquez88729e52006-06-23 16:10:50 -07002560qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2561 uint16_t off, uint16_t count)
2562{
2563 int rval;
2564 mbx_cmd_t mc;
2565 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002566
Andrew Vasqueze4289242007-07-19 15:05:56 -07002567 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002568 return QLA_FUNCTION_FAILED;
2569
2570 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2571
2572 mcp->mb[0] = MBC_READ_SFP;
2573 mcp->mb[1] = addr;
2574 mcp->mb[2] = MSW(sfp_dma);
2575 mcp->mb[3] = LSW(sfp_dma);
2576 mcp->mb[6] = MSW(MSD(sfp_dma));
2577 mcp->mb[7] = LSW(MSD(sfp_dma));
2578 mcp->mb[8] = count;
2579 mcp->mb[9] = off;
2580 mcp->mb[10] = 0;
2581 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2582 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002583 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002584 mcp->flags = 0;
2585 rval = qla2x00_mailbox_command(ha, mcp);
2586
2587 if (rval != QLA_SUCCESS) {
2588 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2589 ha->host_no, rval, mcp->mb[0]));
2590 } else {
2591 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2592 }
2593
2594 return rval;
2595}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002596
2597int
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002598qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2599 uint16_t port_speed, uint16_t *mb)
2600{
2601 int rval;
2602 mbx_cmd_t mc;
2603 mbx_cmd_t *mcp = &mc;
2604
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002605 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002606 return QLA_FUNCTION_FAILED;
2607
2608 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2609
2610 mcp->mb[0] = MBC_PORT_PARAMS;
2611 mcp->mb[1] = loop_id;
2612 mcp->mb[2] = BIT_0;
2613 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2614 mcp->mb[4] = mcp->mb[5] = 0;
2615 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2616 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002617 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002618 mcp->flags = 0;
2619 rval = qla2x00_mailbox_command(ha, mcp);
2620
2621 /* Return mailbox statuses. */
2622 if (mb != NULL) {
2623 mb[0] = mcp->mb[0];
2624 mb[1] = mcp->mb[1];
2625 mb[3] = mcp->mb[3];
2626 mb[4] = mcp->mb[4];
2627 mb[5] = mcp->mb[5];
2628 }
2629
2630 if (rval != QLA_SUCCESS) {
2631 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2632 ha->host_no, rval));
2633 } else {
2634 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2635 }
2636
2637 return rval;
2638}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002639
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002640void
2641qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2642 struct vp_rpt_id_entry_24xx *rptid_entry)
2643{
2644 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07002645 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002646 scsi_qla_host_t *vha;
2647
2648 if (rptid_entry->entry_status != 0)
2649 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002650
2651 if (rptid_entry->format == 0) {
2652 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2653 " number of VPs acquired %d\n", __func__, ha->host_no,
2654 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2655 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2656 rptid_entry->port_id[2], rptid_entry->port_id[1],
2657 rptid_entry->port_id[0]));
2658 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07002659 vp_idx = LSB(stat);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002660 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2661 "- status %d - "
2662 "with port id %02x%02x%02x\n",__func__,ha->host_no,
Seokmann Juc6852c42008-04-24 15:21:29 -07002663 vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002664 rptid_entry->port_id[2], rptid_entry->port_id[1],
2665 rptid_entry->port_id[0]));
2666 if (vp_idx == 0)
2667 return;
2668
Seokmann Juc6852c42008-04-24 15:21:29 -07002669 if (MSB(stat) == 1)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002670 return;
2671
2672 list_for_each_entry(vha, &ha->vp_list, vp_list)
2673 if (vp_idx == vha->vp_idx)
2674 break;
2675
2676 if (!vha)
2677 return;
2678
2679 vha->d_id.b.domain = rptid_entry->port_id[2];
2680 vha->d_id.b.area = rptid_entry->port_id[1];
2681 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2682
2683 /*
2684 * Cannot configure here as we are still sitting on the
2685 * response queue. Handle it in dpc context.
2686 */
2687 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2688 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2689
2690 wake_up_process(ha->dpc_thread);
2691 }
2692}
2693
2694/*
2695 * qla24xx_modify_vp_config
2696 * Change VP configuration for vha
2697 *
2698 * Input:
2699 * vha = adapter block pointer.
2700 *
2701 * Returns:
2702 * qla2xxx local function return status code.
2703 *
2704 * Context:
2705 * Kernel context.
2706 */
2707int
2708qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2709{
2710 int rval;
2711 struct vp_config_entry_24xx *vpmod;
2712 dma_addr_t vpmod_dma;
2713 scsi_qla_host_t *pha;
2714
2715 /* This can be called by the parent */
2716 pha = to_qla_parent(vha);
2717
2718 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2719 if (!vpmod) {
2720 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2721 "IOCB.\n", __func__, pha->host_no));
2722 return QLA_MEMORY_ALLOC_FAILED;
2723 }
2724
2725 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2726 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2727 vpmod->entry_count = 1;
2728 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2729 vpmod->vp_count = 1;
2730 vpmod->vp_index1 = vha->vp_idx;
2731 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2732 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2733 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2734 vpmod->entry_count = 1;
2735
2736 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2737 if (rval != QLA_SUCCESS) {
2738 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2739 "(%x).\n", __func__, pha->host_no, rval));
2740 } else if (vpmod->comp_status != 0) {
2741 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2742 "-- error status (%x).\n", __func__, pha->host_no,
2743 vpmod->comp_status));
2744 rval = QLA_FUNCTION_FAILED;
2745 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2746 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2747 "-- completion status (%x).\n", __func__, pha->host_no,
2748 le16_to_cpu(vpmod->comp_status)));
2749 rval = QLA_FUNCTION_FAILED;
2750 } else {
2751 /* EMPTY */
2752 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2753 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2754 }
2755 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2756
2757 return rval;
2758}
2759
2760/*
2761 * qla24xx_control_vp
2762 * Enable a virtual port for given host
2763 *
2764 * Input:
2765 * ha = adapter block pointer.
2766 * vhba = virtual adapter (unused)
2767 * index = index number for enabled VP
2768 *
2769 * Returns:
2770 * qla2xxx local function return status code.
2771 *
2772 * Context:
2773 * Kernel context.
2774 */
2775int
2776qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2777{
2778 int rval;
2779 int map, pos;
2780 struct vp_ctrl_entry_24xx *vce;
2781 dma_addr_t vce_dma;
2782 scsi_qla_host_t *ha = vha->parent;
2783 int vp_index = vha->vp_idx;
2784
2785 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2786 ha->host_no, vp_index));
2787
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002788 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002789 return QLA_PARAMETER_ERROR;
2790
2791 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2792 if (!vce) {
2793 DEBUG2_3(printk("%s(%ld): "
2794 "failed to allocate VP Control IOCB.\n", __func__,
2795 ha->host_no));
2796 return QLA_MEMORY_ALLOC_FAILED;
2797 }
2798 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2799
2800 vce->entry_type = VP_CTRL_IOCB_TYPE;
2801 vce->entry_count = 1;
2802 vce->command = cpu_to_le16(cmd);
2803 vce->vp_count = __constant_cpu_to_le16(1);
2804
2805 /* index map in firmware starts with 1; decrement index
2806 * this is ok as we never use index 0
2807 */
2808 map = (vp_index - 1) / 8;
2809 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002810 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002811 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002812 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002813
2814 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2815 if (rval != QLA_SUCCESS) {
2816 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2817 "(%x).\n", __func__, ha->host_no, rval));
2818 printk("%s(%ld): failed to issue VP control IOCB"
2819 "(%x).\n", __func__, ha->host_no, rval);
2820 } else if (vce->entry_status != 0) {
2821 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2822 "-- error status (%x).\n", __func__, ha->host_no,
2823 vce->entry_status));
2824 printk("%s(%ld): failed to complete IOCB "
2825 "-- error status (%x).\n", __func__, ha->host_no,
2826 vce->entry_status);
2827 rval = QLA_FUNCTION_FAILED;
2828 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2829 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2830 "-- completion status (%x).\n", __func__, ha->host_no,
2831 le16_to_cpu(vce->comp_status)));
2832 printk("%s(%ld): failed to complete IOCB "
2833 "-- completion status (%x).\n", __func__, ha->host_no,
2834 le16_to_cpu(vce->comp_status));
2835 rval = QLA_FUNCTION_FAILED;
2836 } else {
2837 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2838 }
2839
2840 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2841
2842 return rval;
2843}
2844
2845/*
2846 * qla2x00_send_change_request
2847 * Receive or disable RSCN request from fabric controller
2848 *
2849 * Input:
2850 * ha = adapter block pointer
2851 * format = registration format:
2852 * 0 - Reserved
2853 * 1 - Fabric detected registration
2854 * 2 - N_port detected registration
2855 * 3 - Full registration
2856 * FF - clear registration
2857 * vp_idx = Virtual port index
2858 *
2859 * Returns:
2860 * qla2x00 local function return status code.
2861 *
2862 * Context:
2863 * Kernel Context
2864 */
2865
2866int
2867qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2868 uint16_t vp_idx)
2869{
2870 int rval;
2871 mbx_cmd_t mc;
2872 mbx_cmd_t *mcp = &mc;
2873
2874 /*
2875 * This command is implicitly executed by firmware during login for the
2876 * physical hosts
2877 */
2878 if (vp_idx == 0)
2879 return QLA_FUNCTION_FAILED;
2880
2881 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2882 mcp->mb[1] = format;
2883 mcp->mb[9] = vp_idx;
2884 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2885 mcp->in_mb = MBX_0|MBX_1;
2886 mcp->tov = MBX_TOV_SECONDS;
2887 mcp->flags = 0;
2888 rval = qla2x00_mailbox_command(ha, mcp);
2889
2890 if (rval == QLA_SUCCESS) {
2891 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2892 rval = BIT_1;
2893 }
2894 } else
2895 rval = BIT_1;
2896
2897 return rval;
2898}
Andrew Vasquez338c9162007-09-20 14:07:33 -07002899
2900int
2901qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2902 uint32_t size)
2903{
2904 int rval;
2905 mbx_cmd_t mc;
2906 mbx_cmd_t *mcp = &mc;
2907
2908 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2909
2910 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2911 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2912 mcp->mb[8] = MSW(addr);
2913 mcp->out_mb = MBX_8|MBX_0;
2914 } else {
2915 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2916 mcp->out_mb = MBX_0;
2917 }
2918 mcp->mb[1] = LSW(addr);
2919 mcp->mb[2] = MSW(req_dma);
2920 mcp->mb[3] = LSW(req_dma);
2921 mcp->mb[6] = MSW(MSD(req_dma));
2922 mcp->mb[7] = LSW(MSD(req_dma));
2923 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2924 if (IS_FWI2_CAPABLE(ha)) {
2925 mcp->mb[4] = MSW(size);
2926 mcp->mb[5] = LSW(size);
2927 mcp->out_mb |= MBX_5|MBX_4;
2928 } else {
2929 mcp->mb[4] = LSW(size);
2930 mcp->out_mb |= MBX_4;
2931 }
2932
2933 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002934 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07002935 mcp->flags = 0;
2936 rval = qla2x00_mailbox_command(ha, mcp);
2937
2938 if (rval != QLA_SUCCESS) {
2939 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2940 ha->host_no, rval, mcp->mb[0]));
2941 } else {
2942 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2943 }
2944
2945 return rval;
2946}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002947
2948/* 84XX Support **************************************************************/
2949
2950struct cs84xx_mgmt_cmd {
2951 union {
2952 struct verify_chip_entry_84xx req;
2953 struct verify_chip_rsp_84xx rsp;
2954 } p;
2955};
2956
2957int
2958qla84xx_verify_chip(struct scsi_qla_host *ha, uint16_t *status)
2959{
2960 int rval, retry;
2961 struct cs84xx_mgmt_cmd *mn;
2962 dma_addr_t mn_dma;
2963 uint16_t options;
2964 unsigned long flags;
2965
2966 DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2967
2968 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
2969 if (mn == NULL) {
2970 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
2971 "IOCB.\n", __func__, ha->host_no));
2972 return QLA_MEMORY_ALLOC_FAILED;
2973 }
2974
2975 /* Force Update? */
2976 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
2977 /* Diagnostic firmware? */
2978 /* options |= MENLO_DIAG_FW; */
2979 /* We update the firmware with only one data sequence. */
2980 options |= VCO_END_OF_DATA;
2981
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002982 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07002983 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002984 memset(mn, 0, sizeof(*mn));
2985 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
2986 mn->p.req.entry_count = 1;
2987 mn->p.req.options = cpu_to_le16(options);
2988
2989 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
2990 ha->host_no));
2991 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
2992 sizeof(*mn)));
2993
2994 rval = qla2x00_issue_iocb_timeout(ha, mn, mn_dma, 0, 120);
2995 if (rval != QLA_SUCCESS) {
2996 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
2997 "IOCB (%x).\n", __func__, ha->host_no, rval));
2998 goto verify_done;
2999 }
3000
3001 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3002 ha->host_no));
3003 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3004 sizeof(*mn)));
3005
3006 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3007 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3008 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3009 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3010 ha->host_no, status[0], status[1]));
3011
3012 if (status[0] != CS_COMPLETE) {
3013 rval = QLA_FUNCTION_FAILED;
3014 if (!(options & VCO_DONT_UPDATE_FW)) {
3015 DEBUG2_16(printk("%s(%ld): Firmware update "
3016 "failed. Retrying without update "
3017 "firmware.\n", __func__, ha->host_no));
3018 options |= VCO_DONT_UPDATE_FW;
3019 options &= ~VCO_FORCE_UPDATE;
3020 retry = 1;
3021 }
3022 } else {
3023 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3024 __func__, ha->host_no,
3025 le32_to_cpu(mn->p.rsp.fw_ver)));
3026
3027 /* NOTE: we only update OP firmware. */
3028 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3029 ha->cs84xx->op_fw_version =
3030 le32_to_cpu(mn->p.rsp.fw_ver);
3031 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3032 flags);
3033 }
3034 } while (retry);
3035
3036verify_done:
3037 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3038
3039 if (rval != QLA_SUCCESS) {
3040 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3041 ha->host_no, rval));
3042 } else {
3043 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3044 }
3045
3046 return rval;
3047}