blob: beff743c536be64edebedfc1de14b693640ef55a [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 */
684int
685qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
686 size_t size)
687{
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;
Ravi Anandb93480e2008-04-03 13:13:25 -0700700 mcp->tov = MBX_TOV_SECONDS;
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
721/*
722 * qla2x00_abort_command
723 * Abort command aborts a specified IOCB.
724 *
725 * Input:
726 * ha = adapter block pointer.
727 * sp = SB structure pointer.
728 *
729 * Returns:
730 * qla2x00 local function return status code.
731 *
732 * Context:
733 * Kernel context.
734 */
735int
736qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
737{
738 unsigned long flags = 0;
739 fc_port_t *fcport;
740 int rval;
741 uint32_t handle;
742 mbx_cmd_t mc;
743 mbx_cmd_t *mcp = &mc;
744
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700745 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
bdf79622005-04-17 15:06:53 -0500747 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
749 spin_lock_irqsave(&ha->hardware_lock, flags);
750 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
751 if (ha->outstanding_cmds[handle] == sp)
752 break;
753 }
754 spin_unlock_irqrestore(&ha->hardware_lock, flags);
755
756 if (handle == MAX_OUTSTANDING_COMMANDS) {
757 /* command not found */
758 return QLA_FUNCTION_FAILED;
759 }
760
761 mcp->mb[0] = MBC_ABORT_COMMAND;
762 if (HAS_EXTENDED_IDS(ha))
763 mcp->mb[1] = fcport->loop_id;
764 else
765 mcp->mb[1] = fcport->loop_id << 8;
766 mcp->mb[2] = (uint16_t)handle;
767 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500768 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
770 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700771 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 mcp->flags = 0;
773 rval = qla2x00_mailbox_command(ha, mcp);
774
775 if (rval != QLA_SUCCESS) {
776 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700777 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 } else {
779 sp->flags |= SRB_ABORT_PENDING;
780 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700781 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 }
783
784 return rval;
785}
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700788qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700790 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 mbx_cmd_t mc;
792 mbx_cmd_t *mcp = &mc;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700793 scsi_qla_host_t *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700795 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700796
Andrew Vasquez523ec772008-04-03 13:13:24 -0700797 l = l;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700798 ha = fcport->ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700800 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700801 if (HAS_EXTENDED_IDS(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 mcp->mb[1] = fcport->loop_id;
803 mcp->mb[10] = 0;
804 mcp->out_mb |= MBX_10;
805 } else {
806 mcp->mb[1] = fcport->loop_id << 8;
807 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700808 mcp->mb[2] = ha->loop_reset_delay;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700809 mcp->mb[9] = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810
811 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700812 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 mcp->flags = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700814 rval = qla2x00_mailbox_command(ha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700816 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700817 ha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700818 }
819
820 /* Issue marker IOCB. */
821 rval2 = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
822 if (rval2 != QLA_SUCCESS) {
823 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
824 "(%x).\n", __func__, ha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 } else {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700826 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
827 }
828
829 return rval;
830}
831
832int
833qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
834{
835 int rval, rval2;
836 mbx_cmd_t mc;
837 mbx_cmd_t *mcp = &mc;
838 scsi_qla_host_t *ha;
839
840 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
841
842 ha = fcport->ha;
843 mcp->mb[0] = MBC_LUN_RESET;
844 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
845 if (HAS_EXTENDED_IDS(ha))
846 mcp->mb[1] = fcport->loop_id;
847 else
848 mcp->mb[1] = fcport->loop_id << 8;
849 mcp->mb[2] = l;
850 mcp->mb[3] = 0;
851 mcp->mb[9] = ha->vp_idx;
852
853 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700854 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700855 mcp->flags = 0;
856 rval = qla2x00_mailbox_command(ha, mcp);
857 if (rval != QLA_SUCCESS) {
858 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
859 ha->host_no, rval));
860 }
861
862 /* Issue marker IOCB. */
863 rval2 = qla2x00_marker(ha, fcport->loop_id, l, MK_SYNC_ID_LUN);
864 if (rval2 != QLA_SUCCESS) {
865 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
866 "(%x).\n", __func__, ha->host_no, rval2));
867 } else {
868 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870
871 return rval;
872}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
874/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 * qla2x00_get_adapter_id
876 * Get adapter ID and topology.
877 *
878 * Input:
879 * ha = adapter block pointer.
880 * id = pointer for loop ID.
881 * al_pa = pointer for AL_PA.
882 * area = pointer for area.
883 * domain = pointer for domain.
884 * top = pointer for topology.
885 * TARGET_QUEUE_LOCK must be released.
886 * ADAPTER_STATE_LOCK must be released.
887 *
888 * Returns:
889 * qla2x00 local function return status code.
890 *
891 * Context:
892 * Kernel context.
893 */
894int
895qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700896 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
898 int rval;
899 mbx_cmd_t mc;
900 mbx_cmd_t *mcp = &mc;
901
902 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700903 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700906 mcp->mb[9] = ha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800907 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700908 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700909 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 mcp->flags = 0;
911 rval = qla2x00_mailbox_command(ha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800912 if (mcp->mb[0] == MBS_COMMAND_ERROR)
913 rval = QLA_COMMAND_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 /* Return data. */
916 *id = mcp->mb[1];
917 *al_pa = LSB(mcp->mb[2]);
918 *area = MSB(mcp->mb[2]);
919 *domain = LSB(mcp->mb[3]);
920 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700921 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 if (rval != QLA_SUCCESS) {
924 /*EMPTY*/
925 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700926 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 } else {
928 /*EMPTY*/
929 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700930 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932
933 return rval;
934}
935
936/*
937 * qla2x00_get_retry_cnt
938 * Get current firmware login retry count and delay.
939 *
940 * Input:
941 * ha = adapter block pointer.
942 * retry_cnt = pointer to login retry count.
943 * tov = pointer to login timeout value.
944 *
945 * Returns:
946 * qla2x00 local function return status code.
947 *
948 * Context:
949 * Kernel context.
950 */
951int
952qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
953 uint16_t *r_a_tov)
954{
955 int rval;
956 uint16_t ratov;
957 mbx_cmd_t mc;
958 mbx_cmd_t *mcp = &mc;
959
960 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700961 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 mcp->mb[0] = MBC_GET_RETRY_COUNT;
964 mcp->out_mb = MBX_0;
965 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700966 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 mcp->flags = 0;
968 rval = qla2x00_mailbox_command(ha, mcp);
969
970 if (rval != QLA_SUCCESS) {
971 /*EMPTY*/
972 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700973 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 } else {
975 /* Convert returned data and check our values. */
976 *r_a_tov = mcp->mb[3] / 2;
977 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
978 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
979 /* Update to the larger values */
980 *retry_cnt = (uint8_t)mcp->mb[1];
981 *tov = ratov;
982 }
983
984 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700985 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 }
987
988 return rval;
989}
990
991/*
992 * qla2x00_init_firmware
993 * Initialize adapter firmware.
994 *
995 * Input:
996 * ha = adapter block pointer.
997 * dptr = Initialization control block pointer.
998 * size = size of initialization control block.
999 * TARGET_QUEUE_LOCK must be released.
1000 * ADAPTER_STATE_LOCK must be released.
1001 *
1002 * Returns:
1003 * qla2x00 local function return status code.
1004 *
1005 * Context:
1006 * Kernel context.
1007 */
1008int
1009qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1010{
1011 int rval;
1012 mbx_cmd_t mc;
1013 mbx_cmd_t *mcp = &mc;
1014
1015 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001016 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001018 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001019 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1020 else
1021 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 mcp->mb[2] = MSW(ha->init_cb_dma);
1024 mcp->mb[3] = LSW(ha->init_cb_dma);
1025 mcp->mb[4] = 0;
1026 mcp->mb[5] = 0;
1027 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1028 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1029 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1030 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1031 mcp->buf_size = size;
1032 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001033 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 rval = qla2x00_mailbox_command(ha, mcp);
1035
1036 if (rval != QLA_SUCCESS) {
1037 /*EMPTY*/
1038 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1039 "mb0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001040 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 } else {
1042 /*EMPTY*/
1043 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001044 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 }
1046
1047 return rval;
1048}
1049
1050/*
1051 * qla2x00_get_port_database
1052 * Issue normal/enhanced get port database mailbox command
1053 * and copy device name as necessary.
1054 *
1055 * Input:
1056 * ha = adapter state pointer.
1057 * dev = structure pointer.
1058 * opt = enhanced cmd option byte.
1059 *
1060 * Returns:
1061 * qla2x00 local function return status code.
1062 *
1063 * Context:
1064 * Kernel context.
1065 */
1066int
1067qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1068{
1069 int rval;
1070 mbx_cmd_t mc;
1071 mbx_cmd_t *mcp = &mc;
1072 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001073 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 dma_addr_t pd_dma;
1075
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001076 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001078 pd24 = NULL;
1079 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001081 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1082 "structure.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 return QLA_MEMORY_ALLOC_FAILED;
1084 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001085 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001087 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001088 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 mcp->mb[2] = MSW(pd_dma);
1091 mcp->mb[3] = LSW(pd_dma);
1092 mcp->mb[6] = MSW(MSD(pd_dma));
1093 mcp->mb[7] = LSW(MSD(pd_dma));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001094 mcp->mb[9] = ha->vp_idx;
1095 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001097 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001098 mcp->mb[1] = fcport->loop_id;
1099 mcp->mb[10] = opt;
1100 mcp->out_mb |= MBX_10|MBX_1;
1101 mcp->in_mb |= MBX_1;
1102 } else if (HAS_EXTENDED_IDS(ha)) {
1103 mcp->mb[1] = fcport->loop_id;
1104 mcp->mb[10] = opt;
1105 mcp->out_mb |= MBX_10|MBX_1;
1106 } else {
1107 mcp->mb[1] = fcport->loop_id << 8 | opt;
1108 mcp->out_mb |= MBX_1;
1109 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001110 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1111 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 mcp->flags = MBX_DMA_IN;
1113 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1114 rval = qla2x00_mailbox_command(ha, mcp);
1115 if (rval != QLA_SUCCESS)
1116 goto gpd_error_out;
1117
Andrew Vasqueze4289242007-07-19 15:05:56 -07001118 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001119 pd24 = (struct port_database_24xx *) pd;
1120
1121 /* Check for logged in state. */
1122 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1123 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1124 DEBUG2(printk("%s(%ld): Unable to verify "
1125 "login-state (%x/%x) for loop_id %x\n",
1126 __func__, ha->host_no,
1127 pd24->current_login_state,
1128 pd24->last_login_state, fcport->loop_id));
1129 rval = QLA_FUNCTION_FAILED;
1130 goto gpd_error_out;
1131 }
1132
1133 /* Names are little-endian. */
1134 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1135 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1136
1137 /* Get port_id of device. */
1138 fcport->d_id.b.domain = pd24->port_id[0];
1139 fcport->d_id.b.area = pd24->port_id[1];
1140 fcport->d_id.b.al_pa = pd24->port_id[2];
1141 fcport->d_id.b.rsvd_1 = 0;
1142
1143 /* If not target must be initiator or unknown type. */
1144 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1145 fcport->port_type = FCT_INITIATOR;
1146 else
1147 fcport->port_type = FCT_TARGET;
1148 } else {
1149 /* Check for logged in state. */
1150 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1151 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1152 rval = QLA_FUNCTION_FAILED;
1153 goto gpd_error_out;
1154 }
1155
1156 /* Names are little-endian. */
1157 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1158 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1159
1160 /* Get port_id of device. */
1161 fcport->d_id.b.domain = pd->port_id[0];
1162 fcport->d_id.b.area = pd->port_id[3];
1163 fcport->d_id.b.al_pa = pd->port_id[2];
1164 fcport->d_id.b.rsvd_1 = 0;
1165
1166 /* Check for device require authentication. */
1167 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1168 (fcport->flags &= ~FCF_AUTH_REQ);
1169
1170 /* If not target must be initiator or unknown type. */
1171 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1172 fcport->port_type = FCT_INITIATOR;
1173 else
1174 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001175
1176 /* Passback COS information. */
1177 fcport->supported_classes = (pd->options & BIT_4) ?
1178 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 }
1180
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181gpd_error_out:
1182 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1183
1184 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001185 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1186 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001188 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 }
1190
1191 return rval;
1192}
1193
1194/*
1195 * qla2x00_get_firmware_state
1196 * Get adapter firmware state.
1197 *
1198 * Input:
1199 * ha = adapter block pointer.
1200 * dptr = pointer for firmware state.
1201 * TARGET_QUEUE_LOCK must be released.
1202 * ADAPTER_STATE_LOCK must be released.
1203 *
1204 * Returns:
1205 * qla2x00 local function return status code.
1206 *
1207 * Context:
1208 * Kernel context.
1209 */
1210int
1211qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1212{
1213 int rval;
1214 mbx_cmd_t mc;
1215 mbx_cmd_t *mcp = &mc;
1216
1217 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001218 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1221 mcp->out_mb = MBX_0;
1222 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001223 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 mcp->flags = 0;
1225 rval = qla2x00_mailbox_command(ha, mcp);
1226
1227 /* Return firmware state. */
1228 *dptr = mcp->mb[1];
1229
1230 if (rval != QLA_SUCCESS) {
1231 /*EMPTY*/
1232 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001233 "failed=%x.\n", ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 } else {
1235 /*EMPTY*/
1236 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001237 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
1239
1240 return rval;
1241}
1242
1243/*
1244 * qla2x00_get_port_name
1245 * Issue get port name mailbox command.
1246 * Returned name is in big endian format.
1247 *
1248 * Input:
1249 * ha = adapter block pointer.
1250 * loop_id = loop ID of device.
1251 * name = pointer for name.
1252 * TARGET_QUEUE_LOCK must be released.
1253 * ADAPTER_STATE_LOCK must be released.
1254 *
1255 * Returns:
1256 * qla2x00 local function return status code.
1257 *
1258 * Context:
1259 * Kernel context.
1260 */
1261int
1262qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1263 uint8_t opt)
1264{
1265 int rval;
1266 mbx_cmd_t mc;
1267 mbx_cmd_t *mcp = &mc;
1268
1269 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001270 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 mcp->mb[0] = MBC_GET_PORT_NAME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001273 mcp->mb[9] = ha->vp_idx;
1274 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 if (HAS_EXTENDED_IDS(ha)) {
1276 mcp->mb[1] = loop_id;
1277 mcp->mb[10] = opt;
1278 mcp->out_mb |= MBX_10;
1279 } else {
1280 mcp->mb[1] = loop_id << 8 | opt;
1281 }
1282
1283 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001284 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 mcp->flags = 0;
1286 rval = qla2x00_mailbox_command(ha, mcp);
1287
1288 if (rval != QLA_SUCCESS) {
1289 /*EMPTY*/
1290 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001291 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 } else {
1293 if (name != NULL) {
1294 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001295 name[0] = MSB(mcp->mb[2]);
1296 name[1] = LSB(mcp->mb[2]);
1297 name[2] = MSB(mcp->mb[3]);
1298 name[3] = LSB(mcp->mb[3]);
1299 name[4] = MSB(mcp->mb[6]);
1300 name[5] = LSB(mcp->mb[6]);
1301 name[6] = MSB(mcp->mb[7]);
1302 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 }
1304
1305 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001306 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308
1309 return rval;
1310}
1311
1312/*
1313 * qla2x00_lip_reset
1314 * Issue LIP reset mailbox command.
1315 *
1316 * Input:
1317 * ha = adapter block pointer.
1318 * TARGET_QUEUE_LOCK must be released.
1319 * ADAPTER_STATE_LOCK must be released.
1320 *
1321 * Returns:
1322 * qla2x00 local function return status code.
1323 *
1324 * Context:
1325 * Kernel context.
1326 */
1327int
1328qla2x00_lip_reset(scsi_qla_host_t *ha)
1329{
1330 int rval;
1331 mbx_cmd_t mc;
1332 mbx_cmd_t *mcp = &mc;
1333
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001334 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
Andrew Vasqueze4289242007-07-19 15:05:56 -07001336 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001337 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001338 mcp->mb[1] = BIT_6;
1339 mcp->mb[2] = 0;
1340 mcp->mb[3] = ha->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001341 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001343 mcp->mb[0] = MBC_LIP_RESET;
1344 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1345 if (HAS_EXTENDED_IDS(ha)) {
1346 mcp->mb[1] = 0x00ff;
1347 mcp->mb[10] = 0;
1348 mcp->out_mb |= MBX_10;
1349 } else {
1350 mcp->mb[1] = 0xff00;
1351 }
1352 mcp->mb[2] = ha->loop_reset_delay;
1353 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001356 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 mcp->flags = 0;
1358 rval = qla2x00_mailbox_command(ha, mcp);
1359
1360 if (rval != QLA_SUCCESS) {
1361 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001362 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001363 __func__, ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 } else {
1365 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001366 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 }
1368
1369 return rval;
1370}
1371
1372/*
1373 * qla2x00_send_sns
1374 * Send SNS command.
1375 *
1376 * Input:
1377 * ha = adapter block pointer.
1378 * sns = pointer for command.
1379 * cmd_size = command size.
1380 * buf_size = response/command size.
1381 * TARGET_QUEUE_LOCK must be released.
1382 * ADAPTER_STATE_LOCK must be released.
1383 *
1384 * Returns:
1385 * qla2x00 local function return status code.
1386 *
1387 * Context:
1388 * Kernel context.
1389 */
1390int
1391qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1392 uint16_t cmd_size, size_t buf_size)
1393{
1394 int rval;
1395 mbx_cmd_t mc;
1396 mbx_cmd_t *mcp = &mc;
1397
1398 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001399 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400
1401 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001402 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403
1404 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1405 mcp->mb[1] = cmd_size;
1406 mcp->mb[2] = MSW(sns_phys_address);
1407 mcp->mb[3] = LSW(sns_phys_address);
1408 mcp->mb[6] = MSW(MSD(sns_phys_address));
1409 mcp->mb[7] = LSW(MSD(sns_phys_address));
1410 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1411 mcp->in_mb = MBX_0|MBX_1;
1412 mcp->buf_size = buf_size;
1413 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1414 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1415 rval = qla2x00_mailbox_command(ha, mcp);
1416
1417 if (rval != QLA_SUCCESS) {
1418 /*EMPTY*/
1419 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001420 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001422 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 } else {
1424 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001425 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
1427
1428 return rval;
1429}
1430
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001431int
1432qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1433 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1434{
1435 int rval;
1436
1437 struct logio_entry_24xx *lg;
1438 dma_addr_t lg_dma;
1439 uint32_t iop[2];
1440
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001441 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001442
1443 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1444 if (lg == NULL) {
1445 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1446 __func__, ha->host_no));
1447 return QLA_MEMORY_ALLOC_FAILED;
1448 }
1449 memset(lg, 0, sizeof(struct logio_entry_24xx));
1450
1451 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1452 lg->entry_count = 1;
1453 lg->nport_handle = cpu_to_le16(loop_id);
1454 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1455 if (opt & BIT_0)
1456 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001457 if (opt & BIT_1)
1458 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001459 lg->port_id[0] = al_pa;
1460 lg->port_id[1] = area;
1461 lg->port_id[2] = domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001462 lg->vp_index = cpu_to_le16(ha->vp_idx);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001463 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1464 if (rval != QLA_SUCCESS) {
1465 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001466 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001467 } else if (lg->entry_status != 0) {
1468 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1469 "-- error status (%x).\n", __func__, ha->host_no,
1470 lg->entry_status));
1471 rval = QLA_FUNCTION_FAILED;
1472 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1473 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1474 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1475
1476 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1477 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1478 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1479 iop[1]));
1480
1481 switch (iop[0]) {
1482 case LSC_SCODE_PORTID_USED:
1483 mb[0] = MBS_PORT_ID_USED;
1484 mb[1] = LSW(iop[1]);
1485 break;
1486 case LSC_SCODE_NPORT_USED:
1487 mb[0] = MBS_LOOP_ID_USED;
1488 break;
1489 case LSC_SCODE_NOLINK:
1490 case LSC_SCODE_NOIOCB:
1491 case LSC_SCODE_NOXCB:
1492 case LSC_SCODE_CMD_FAILED:
1493 case LSC_SCODE_NOFABRIC:
1494 case LSC_SCODE_FW_NOT_READY:
1495 case LSC_SCODE_NOT_LOGGED_IN:
1496 case LSC_SCODE_NOPCB:
1497 case LSC_SCODE_ELS_REJECT:
1498 case LSC_SCODE_CMD_PARAM_ERR:
1499 case LSC_SCODE_NONPORT:
1500 case LSC_SCODE_LOGGED_IN:
1501 case LSC_SCODE_NOFLOGI_ACC:
1502 default:
1503 mb[0] = MBS_COMMAND_ERROR;
1504 break;
1505 }
1506 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001507 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001508
1509 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1510
1511 mb[0] = MBS_COMMAND_COMPLETE;
1512 mb[1] = 0;
1513 if (iop[0] & BIT_4) {
1514 if (iop[0] & BIT_8)
1515 mb[1] |= BIT_1;
1516 } else
1517 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001518
1519 /* Passback COS information. */
1520 mb[10] = 0;
1521 if (lg->io_parameter[7] || lg->io_parameter[8])
1522 mb[10] |= BIT_0; /* Class 2. */
1523 if (lg->io_parameter[9] || lg->io_parameter[10])
1524 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001525 }
1526
1527 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1528
1529 return rval;
1530}
1531
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532/*
1533 * qla2x00_login_fabric
1534 * Issue login fabric port mailbox command.
1535 *
1536 * Input:
1537 * ha = adapter block pointer.
1538 * loop_id = device loop ID.
1539 * domain = device domain.
1540 * area = device area.
1541 * al_pa = device AL_PA.
1542 * status = pointer for return status.
1543 * opt = command options.
1544 * TARGET_QUEUE_LOCK must be released.
1545 * ADAPTER_STATE_LOCK must be released.
1546 *
1547 * Returns:
1548 * qla2x00 local function return status code.
1549 *
1550 * Context:
1551 * Kernel context.
1552 */
1553int
1554qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1555 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1556{
1557 int rval;
1558 mbx_cmd_t mc;
1559 mbx_cmd_t *mcp = &mc;
1560
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001561 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1564 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1565 if (HAS_EXTENDED_IDS(ha)) {
1566 mcp->mb[1] = loop_id;
1567 mcp->mb[10] = opt;
1568 mcp->out_mb |= MBX_10;
1569 } else {
1570 mcp->mb[1] = (loop_id << 8) | opt;
1571 }
1572 mcp->mb[2] = domain;
1573 mcp->mb[3] = area << 8 | al_pa;
1574
1575 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1576 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1577 mcp->flags = 0;
1578 rval = qla2x00_mailbox_command(ha, mcp);
1579
1580 /* Return mailbox statuses. */
1581 if (mb != NULL) {
1582 mb[0] = mcp->mb[0];
1583 mb[1] = mcp->mb[1];
1584 mb[2] = mcp->mb[2];
1585 mb[6] = mcp->mb[6];
1586 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001587 /* COS retrieved from Get-Port-Database mailbox command. */
1588 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 }
1590
1591 if (rval != QLA_SUCCESS) {
1592 /* RLU tmp code: need to change main mailbox_command function to
1593 * return ok even when the mailbox completion value is not
1594 * SUCCESS. The caller needs to be responsible to interpret
1595 * the return values of this mailbox command if we're not
1596 * to change too much of the existing code.
1597 */
1598 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1599 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1600 mcp->mb[0] == 0x4006)
1601 rval = QLA_SUCCESS;
1602
1603 /*EMPTY*/
1604 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1605 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001606 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 } else {
1608 /*EMPTY*/
1609 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001610 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 }
1612
1613 return rval;
1614}
1615
1616/*
1617 * qla2x00_login_local_device
1618 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001619 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 * Input:
1621 * ha = adapter block pointer.
1622 * loop_id = device loop ID.
1623 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001624 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 * Returns:
1626 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001627 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 * Context:
1629 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001630 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 */
1632int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001633qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 uint16_t *mb_ret, uint8_t opt)
1635{
1636 int rval;
1637 mbx_cmd_t mc;
1638 mbx_cmd_t *mcp = &mc;
1639
Andrew Vasqueze4289242007-07-19 15:05:56 -07001640 if (IS_FWI2_CAPABLE(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001641 return qla24xx_login_fabric(ha, fcport->loop_id,
1642 fcport->d_id.b.domain, fcport->d_id.b.area,
1643 fcport->d_id.b.al_pa, mb_ret, opt);
1644
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001645 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
1647 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1648 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001649 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001651 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 mcp->mb[2] = opt;
1653 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1654 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1655 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1656 mcp->flags = 0;
1657 rval = qla2x00_mailbox_command(ha, mcp);
1658
1659 /* Return mailbox statuses. */
1660 if (mb_ret != NULL) {
1661 mb_ret[0] = mcp->mb[0];
1662 mb_ret[1] = mcp->mb[1];
1663 mb_ret[6] = mcp->mb[6];
1664 mb_ret[7] = mcp->mb[7];
1665 }
1666
1667 if (rval != QLA_SUCCESS) {
1668 /* AV tmp code: need to change main mailbox_command function to
1669 * return ok even when the mailbox completion value is not
1670 * SUCCESS. The caller needs to be responsible to interpret
1671 * the return values of this mailbox command if we're not
1672 * to change too much of the existing code.
1673 */
1674 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1675 rval = QLA_SUCCESS;
1676
1677 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1678 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001679 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1681 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001682 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 } else {
1684 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001685 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 }
1687
1688 return (rval);
1689}
1690
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001691int
1692qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1693 uint8_t area, uint8_t al_pa)
1694{
1695 int rval;
1696 struct logio_entry_24xx *lg;
1697 dma_addr_t lg_dma;
1698
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001699 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001700
1701 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1702 if (lg == NULL) {
1703 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1704 __func__, ha->host_no));
1705 return QLA_MEMORY_ALLOC_FAILED;
1706 }
1707 memset(lg, 0, sizeof(struct logio_entry_24xx));
1708
1709 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1710 lg->entry_count = 1;
1711 lg->nport_handle = cpu_to_le16(loop_id);
1712 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001713 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001714 lg->port_id[0] = al_pa;
1715 lg->port_id[1] = area;
1716 lg->port_id[2] = domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001717 lg->vp_index = cpu_to_le16(ha->vp_idx);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001718 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1719 if (rval != QLA_SUCCESS) {
1720 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001721 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001722 } else if (lg->entry_status != 0) {
1723 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1724 "-- error status (%x).\n", __func__, ha->host_no,
1725 lg->entry_status));
1726 rval = QLA_FUNCTION_FAILED;
1727 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1728 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1729 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1730 ha->host_no, le16_to_cpu(lg->comp_status),
1731 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001732 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001733 } else {
1734 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001735 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001736 }
1737
1738 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1739
1740 return rval;
1741}
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743/*
1744 * qla2x00_fabric_logout
1745 * Issue logout fabric port mailbox command.
1746 *
1747 * Input:
1748 * ha = adapter block pointer.
1749 * loop_id = device loop ID.
1750 * TARGET_QUEUE_LOCK must be released.
1751 * ADAPTER_STATE_LOCK must be released.
1752 *
1753 * Returns:
1754 * qla2x00 local function return status code.
1755 *
1756 * Context:
1757 * Kernel context.
1758 */
1759int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001760qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1761 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762{
1763 int rval;
1764 mbx_cmd_t mc;
1765 mbx_cmd_t *mcp = &mc;
1766
1767 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001768 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
1770 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1771 mcp->out_mb = MBX_1|MBX_0;
1772 if (HAS_EXTENDED_IDS(ha)) {
1773 mcp->mb[1] = loop_id;
1774 mcp->mb[10] = 0;
1775 mcp->out_mb |= MBX_10;
1776 } else {
1777 mcp->mb[1] = loop_id << 8;
1778 }
1779
1780 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001781 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 mcp->flags = 0;
1783 rval = qla2x00_mailbox_command(ha, mcp);
1784
1785 if (rval != QLA_SUCCESS) {
1786 /*EMPTY*/
1787 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001788 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 } else {
1790 /*EMPTY*/
1791 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001792 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 }
1794
1795 return rval;
1796}
1797
1798/*
1799 * qla2x00_full_login_lip
1800 * Issue full login LIP mailbox command.
1801 *
1802 * Input:
1803 * ha = adapter block pointer.
1804 * TARGET_QUEUE_LOCK must be released.
1805 * ADAPTER_STATE_LOCK must be released.
1806 *
1807 * Returns:
1808 * qla2x00 local function return status code.
1809 *
1810 * Context:
1811 * Kernel context.
1812 */
1813int
1814qla2x00_full_login_lip(scsi_qla_host_t *ha)
1815{
1816 int rval;
1817 mbx_cmd_t mc;
1818 mbx_cmd_t *mcp = &mc;
1819
1820 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001821 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001824 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001825 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 mcp->mb[3] = 0;
1827 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1828 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001829 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 mcp->flags = 0;
1831 rval = qla2x00_mailbox_command(ha, mcp);
1832
1833 if (rval != QLA_SUCCESS) {
1834 /*EMPTY*/
1835 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001836 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 } else {
1838 /*EMPTY*/
1839 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001840 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 }
1842
1843 return rval;
1844}
1845
1846/*
1847 * qla2x00_get_id_list
1848 *
1849 * Input:
1850 * ha = adapter block pointer.
1851 *
1852 * Returns:
1853 * qla2x00 local function return status code.
1854 *
1855 * Context:
1856 * Kernel context.
1857 */
1858int
1859qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1860 uint16_t *entries)
1861{
1862 int rval;
1863 mbx_cmd_t mc;
1864 mbx_cmd_t *mcp = &mc;
1865
1866 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001867 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
1869 if (id_list == NULL)
1870 return QLA_FUNCTION_FAILED;
1871
1872 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001873 mcp->out_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001874 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001875 mcp->mb[2] = MSW(id_list_dma);
1876 mcp->mb[3] = LSW(id_list_dma);
1877 mcp->mb[6] = MSW(MSD(id_list_dma));
1878 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001879 mcp->mb[8] = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001880 mcp->mb[9] = ha->vp_idx;
1881 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001882 } else {
1883 mcp->mb[1] = MSW(id_list_dma);
1884 mcp->mb[2] = LSW(id_list_dma);
1885 mcp->mb[3] = MSW(MSD(id_list_dma));
1886 mcp->mb[6] = LSW(MSD(id_list_dma));
1887 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1888 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001890 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 mcp->flags = 0;
1892 rval = qla2x00_mailbox_command(ha, mcp);
1893
1894 if (rval != QLA_SUCCESS) {
1895 /*EMPTY*/
1896 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001897 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 } else {
1899 *entries = mcp->mb[1];
1900 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001901 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 }
1903
1904 return rval;
1905}
1906
1907/*
1908 * qla2x00_get_resource_cnts
1909 * Get current firmware resource counts.
1910 *
1911 * Input:
1912 * ha = adapter block pointer.
1913 *
1914 * Returns:
1915 * qla2x00 local function return status code.
1916 *
1917 * Context:
1918 * Kernel context.
1919 */
1920int
1921qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001922 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1923 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924{
1925 int rval;
1926 mbx_cmd_t mc;
1927 mbx_cmd_t *mcp = &mc;
1928
1929 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1930
1931 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1932 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001933 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 -07001934 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 mcp->flags = 0;
1936 rval = qla2x00_mailbox_command(ha, mcp);
1937
1938 if (rval != QLA_SUCCESS) {
1939 /*EMPTY*/
1940 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001941 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 } else {
1943 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001944 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001945 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001946 mcp->mb[10], mcp->mb[11]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
1948 if (cur_xchg_cnt)
1949 *cur_xchg_cnt = mcp->mb[3];
1950 if (orig_xchg_cnt)
1951 *orig_xchg_cnt = mcp->mb[6];
1952 if (cur_iocb_cnt)
1953 *cur_iocb_cnt = mcp->mb[7];
1954 if (orig_iocb_cnt)
1955 *orig_iocb_cnt = mcp->mb[10];
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001956 if (max_npiv_vports)
1957 *max_npiv_vports = mcp->mb[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
1959
1960 return (rval);
1961}
1962
1963#if defined(QL_DEBUG_LEVEL_3)
1964/*
1965 * qla2x00_get_fcal_position_map
1966 * Get FCAL (LILP) position map using mailbox command
1967 *
1968 * Input:
1969 * ha = adapter state pointer.
1970 * pos_map = buffer pointer (can be NULL).
1971 *
1972 * Returns:
1973 * qla2x00 local function return status code.
1974 *
1975 * Context:
1976 * Kernel context.
1977 */
1978int
1979qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1980{
1981 int rval;
1982 mbx_cmd_t mc;
1983 mbx_cmd_t *mcp = &mc;
1984 char *pmap;
1985 dma_addr_t pmap_dma;
1986
1987 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1988 if (pmap == NULL) {
1989 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1990 __func__, ha->host_no));
1991 return QLA_MEMORY_ALLOC_FAILED;
1992 }
1993 memset(pmap, 0, FCAL_MAP_SIZE);
1994
1995 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1996 mcp->mb[2] = MSW(pmap_dma);
1997 mcp->mb[3] = LSW(pmap_dma);
1998 mcp->mb[6] = MSW(MSD(pmap_dma));
1999 mcp->mb[7] = LSW(MSD(pmap_dma));
2000 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2001 mcp->in_mb = MBX_1|MBX_0;
2002 mcp->buf_size = FCAL_MAP_SIZE;
2003 mcp->flags = MBX_DMA_IN;
2004 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2005 rval = qla2x00_mailbox_command(ha, mcp);
2006
2007 if (rval == QLA_SUCCESS) {
2008 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2009 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2010 mcp->mb[1], (unsigned)pmap[0]));
2011 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2012
2013 if (pos_map)
2014 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2015 }
2016 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2017
2018 if (rval != QLA_SUCCESS) {
2019 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2020 ha->host_no, rval));
2021 } else {
2022 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2023 }
2024
2025 return rval;
2026}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002027#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002028
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002029/*
2030 * qla2x00_get_link_status
2031 *
2032 * Input:
2033 * ha = adapter block pointer.
2034 * loop_id = device loop ID.
2035 * ret_buf = pointer to link status return buffer.
2036 *
2037 * Returns:
2038 * 0 = success.
2039 * BIT_0 = mem alloc error.
2040 * BIT_1 = mailbox error.
2041 */
2042int
2043qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002044 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002045{
2046 int rval;
2047 mbx_cmd_t mc;
2048 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002049 uint32_t *siter, *diter, dwords;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002050
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002051 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002052
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002053 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002054 mcp->mb[2] = MSW(stats_dma);
2055 mcp->mb[3] = LSW(stats_dma);
2056 mcp->mb[6] = MSW(MSD(stats_dma));
2057 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002058 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2059 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002060 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002061 mcp->mb[1] = loop_id;
2062 mcp->mb[4] = 0;
2063 mcp->mb[10] = 0;
2064 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2065 mcp->in_mb |= MBX_1;
2066 } else if (HAS_EXTENDED_IDS(ha)) {
2067 mcp->mb[1] = loop_id;
2068 mcp->mb[10] = 0;
2069 mcp->out_mb |= MBX_10|MBX_1;
2070 } else {
2071 mcp->mb[1] = loop_id << 8;
2072 mcp->out_mb |= MBX_1;
2073 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002074 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002075 mcp->flags = IOCTL_CMD;
2076 rval = qla2x00_mailbox_command(ha, mcp);
2077
2078 if (rval == QLA_SUCCESS) {
2079 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2080 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002081 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002082 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002083 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002084 /* Copy over data -- firmware data is LE. */
2085 dwords = offsetof(struct link_statistics, unused1) / 4;
2086 siter = diter = &stats->link_fail_cnt;
2087 while (dwords--)
2088 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002089 }
2090 } else {
2091 /* Failed. */
2092 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002093 ha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002094 }
2095
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002096 return rval;
2097}
2098
2099int
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002100qla24xx_get_isp_stats(scsi_qla_host_t *ha, struct link_statistics *stats,
2101 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002102{
2103 int rval;
2104 mbx_cmd_t mc;
2105 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002106 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002107
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002108 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002109
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002110 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002111 mcp->mb[2] = MSW(stats_dma);
2112 mcp->mb[3] = LSW(stats_dma);
2113 mcp->mb[6] = MSW(MSD(stats_dma));
2114 mcp->mb[7] = LSW(MSD(stats_dma));
2115 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2116 mcp->mb[9] = ha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002117 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002118 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 -07002119 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002120 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002121 mcp->flags = IOCTL_CMD;
2122 rval = qla2x00_mailbox_command(ha, mcp);
2123
2124 if (rval == QLA_SUCCESS) {
2125 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2126 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2127 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002128 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002129 } else {
2130 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002131 dwords = sizeof(struct link_statistics) / 4;
2132 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002133 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002134 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002135 }
2136 } else {
2137 /* Failed. */
2138 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2139 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002140 }
2141
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002142 return rval;
2143}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002144
2145int
2146qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2147{
2148 int rval;
2149 fc_port_t *fcport;
2150 unsigned long flags = 0;
2151
2152 struct abort_entry_24xx *abt;
2153 dma_addr_t abt_dma;
2154 uint32_t handle;
2155
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002156 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002157
2158 fcport = sp->fcport;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002159
2160 spin_lock_irqsave(&ha->hardware_lock, flags);
2161 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2162 if (ha->outstanding_cmds[handle] == sp)
2163 break;
2164 }
2165 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2166 if (handle == MAX_OUTSTANDING_COMMANDS) {
2167 /* Command not found. */
2168 return QLA_FUNCTION_FAILED;
2169 }
2170
2171 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2172 if (abt == NULL) {
2173 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2174 __func__, ha->host_no));
2175 return QLA_MEMORY_ALLOC_FAILED;
2176 }
2177 memset(abt, 0, sizeof(struct abort_entry_24xx));
2178
2179 abt->entry_type = ABORT_IOCB_TYPE;
2180 abt->entry_count = 1;
2181 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2182 abt->handle_to_abort = handle;
2183 abt->port_id[0] = fcport->d_id.b.al_pa;
2184 abt->port_id[1] = fcport->d_id.b.area;
2185 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002186 abt->vp_index = fcport->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002187 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2188 if (rval != QLA_SUCCESS) {
2189 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002190 __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002191 } else if (abt->entry_status != 0) {
2192 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2193 "-- error status (%x).\n", __func__, ha->host_no,
2194 abt->entry_status));
2195 rval = QLA_FUNCTION_FAILED;
2196 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2197 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2198 "-- completion status (%x).\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002199 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002200 rval = QLA_FUNCTION_FAILED;
2201 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002202 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002203 sp->flags |= SRB_ABORT_PENDING;
2204 }
2205
2206 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2207
2208 return rval;
2209}
2210
2211struct tsk_mgmt_cmd {
2212 union {
2213 struct tsk_mgmt_entry tsk;
2214 struct sts_entry_24xx sts;
2215 } p;
2216};
2217
Andrew Vasquez523ec772008-04-03 13:13:24 -07002218static int
2219__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2220 unsigned int l)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002221{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002222 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002223 struct tsk_mgmt_cmd *tsk;
2224 dma_addr_t tsk_dma;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002225 scsi_qla_host_t *ha, *pha;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002226
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002227 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002228
2229 ha = fcport->ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002230 pha = to_qla_parent(ha);
2231 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002232 if (tsk == NULL) {
2233 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2234 "IOCB.\n", __func__, ha->host_no));
2235 return QLA_MEMORY_ALLOC_FAILED;
2236 }
2237 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2238
2239 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2240 tsk->p.tsk.entry_count = 1;
2241 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002242 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002243 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002244 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2245 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2246 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002247 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002248 if (type == TCF_LUN_RESET) {
2249 int_to_scsilun(l, &tsk->p.tsk.lun);
2250 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2251 sizeof(tsk->p.tsk.lun));
2252 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002253
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002254 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2255 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002256 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2257 "(%x).\n", __func__, ha->host_no, name, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002258 } else if (tsk->p.sts.entry_status != 0) {
2259 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2260 "-- error status (%x).\n", __func__, ha->host_no,
2261 tsk->p.sts.entry_status));
2262 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002263 } else if (tsk->p.sts.comp_status !=
2264 __constant_cpu_to_le16(CS_COMPLETE)) {
2265 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2266 "-- completion status (%x).\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002267 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002268 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002269 }
2270
2271 /* Issue marker IOCB. */
Andrew Vasquez523ec772008-04-03 13:13:24 -07002272 rval2 = qla2x00_marker(ha, fcport->loop_id, l,
2273 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2274 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002275 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Andrew Vasquez523ec772008-04-03 13:13:24 -07002276 "(%x).\n", __func__, ha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002277 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002278 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002279 }
2280
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002281 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002282
2283 return rval;
2284}
2285
Andrew Vasquez523ec772008-04-03 13:13:24 -07002286int
2287qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2288{
2289 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2290}
2291
2292int
2293qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2294{
2295 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2296}
2297
Adrian Bunka824ebb2008-01-17 09:02:15 -08002298#if 0
2299
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002300int
2301qla2x00_system_error(scsi_qla_host_t *ha)
2302{
2303 int rval;
2304 mbx_cmd_t mc;
2305 mbx_cmd_t *mcp = &mc;
2306
Andrew Vasqueze4289242007-07-19 15:05:56 -07002307 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002308 return QLA_FUNCTION_FAILED;
2309
2310 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2311
2312 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2313 mcp->out_mb = MBX_0;
2314 mcp->in_mb = MBX_0;
2315 mcp->tov = 5;
2316 mcp->flags = 0;
2317 rval = qla2x00_mailbox_command(ha, mcp);
2318
2319 if (rval != QLA_SUCCESS) {
2320 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2321 ha->host_no, rval));
2322 } else {
2323 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2324 }
2325
2326 return rval;
2327}
2328
Adrian Bunka824ebb2008-01-17 09:02:15 -08002329#endif /* 0 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002330
2331/**
2332 * qla2x00_set_serdes_params() -
2333 * @ha: HA context
2334 *
2335 * Returns
2336 */
2337int
2338qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2339 uint16_t sw_em_2g, uint16_t sw_em_4g)
2340{
2341 int rval;
2342 mbx_cmd_t mc;
2343 mbx_cmd_t *mcp = &mc;
2344
2345 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2346
2347 mcp->mb[0] = MBC_SERDES_PARAMS;
2348 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002349 mcp->mb[2] = sw_em_1g | BIT_15;
2350 mcp->mb[3] = sw_em_2g | BIT_15;
2351 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002352 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2353 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002354 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002355 mcp->flags = 0;
2356 rval = qla2x00_mailbox_command(ha, mcp);
2357
2358 if (rval != QLA_SUCCESS) {
2359 /*EMPTY*/
2360 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2361 ha->host_no, rval, mcp->mb[0]));
2362 } else {
2363 /*EMPTY*/
2364 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2365 }
2366
2367 return rval;
2368}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002369
2370int
2371qla2x00_stop_firmware(scsi_qla_host_t *ha)
2372{
2373 int rval;
2374 mbx_cmd_t mc;
2375 mbx_cmd_t *mcp = &mc;
2376
Andrew Vasqueze4289242007-07-19 15:05:56 -07002377 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002378 return QLA_FUNCTION_FAILED;
2379
2380 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2381
2382 mcp->mb[0] = MBC_STOP_FIRMWARE;
2383 mcp->out_mb = MBX_0;
2384 mcp->in_mb = MBX_0;
2385 mcp->tov = 5;
2386 mcp->flags = 0;
2387 rval = qla2x00_mailbox_command(ha, mcp);
2388
2389 if (rval != QLA_SUCCESS) {
2390 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2391 ha->host_no, rval));
2392 } else {
2393 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2394 }
2395
2396 return rval;
2397}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002398
2399int
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002400qla2x00_enable_eft_trace(scsi_qla_host_t *ha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002401 uint16_t buffers)
2402{
2403 int rval;
2404 mbx_cmd_t mc;
2405 mbx_cmd_t *mcp = &mc;
2406
Andrew Vasqueze4289242007-07-19 15:05:56 -07002407 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002408 return QLA_FUNCTION_FAILED;
2409
2410 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2411
2412 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002413 mcp->mb[1] = TC_EFT_ENABLE;
2414 mcp->mb[2] = LSW(eft_dma);
2415 mcp->mb[3] = MSW(eft_dma);
2416 mcp->mb[4] = LSW(MSD(eft_dma));
2417 mcp->mb[5] = MSW(MSD(eft_dma));
2418 mcp->mb[6] = buffers;
2419 mcp->mb[7] = TC_AEN_DISABLE;
2420 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 -07002421 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002422 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002423 mcp->flags = 0;
2424 rval = qla2x00_mailbox_command(ha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002425 if (rval != QLA_SUCCESS) {
2426 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2427 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2428 } else {
2429 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2430 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002431
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002432 return rval;
2433}
2434
2435int
2436qla2x00_disable_eft_trace(scsi_qla_host_t *ha)
2437{
2438 int rval;
2439 mbx_cmd_t mc;
2440 mbx_cmd_t *mcp = &mc;
2441
2442 if (!IS_FWI2_CAPABLE(ha))
2443 return QLA_FUNCTION_FAILED;
2444
2445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2446
2447 mcp->mb[0] = MBC_TRACE_CONTROL;
2448 mcp->mb[1] = TC_EFT_DISABLE;
2449 mcp->out_mb = MBX_1|MBX_0;
2450 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002451 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002452 mcp->flags = 0;
2453 rval = qla2x00_mailbox_command(ha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002454 if (rval != QLA_SUCCESS) {
2455 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2456 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2457 } else {
2458 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2459 }
2460
2461 return rval;
2462}
2463
Andrew Vasquez88729e52006-06-23 16:10:50 -07002464int
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002465qla2x00_enable_fce_trace(scsi_qla_host_t *ha, dma_addr_t fce_dma,
2466 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2467{
2468 int rval;
2469 mbx_cmd_t mc;
2470 mbx_cmd_t *mcp = &mc;
2471
2472 if (!IS_QLA25XX(ha))
2473 return QLA_FUNCTION_FAILED;
2474
2475 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2476
2477 mcp->mb[0] = MBC_TRACE_CONTROL;
2478 mcp->mb[1] = TC_FCE_ENABLE;
2479 mcp->mb[2] = LSW(fce_dma);
2480 mcp->mb[3] = MSW(fce_dma);
2481 mcp->mb[4] = LSW(MSD(fce_dma));
2482 mcp->mb[5] = MSW(MSD(fce_dma));
2483 mcp->mb[6] = buffers;
2484 mcp->mb[7] = TC_AEN_DISABLE;
2485 mcp->mb[8] = 0;
2486 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2487 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2488 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2489 MBX_1|MBX_0;
2490 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002491 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002492 mcp->flags = 0;
2493 rval = qla2x00_mailbox_command(ha, mcp);
2494 if (rval != QLA_SUCCESS) {
2495 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2496 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2497 } else {
2498 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2499
2500 if (mb)
2501 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2502 if (dwords)
2503 *dwords = mcp->mb[6];
2504 }
2505
2506 return rval;
2507}
2508
2509int
2510qla2x00_disable_fce_trace(scsi_qla_host_t *ha, uint64_t *wr, uint64_t *rd)
2511{
2512 int rval;
2513 mbx_cmd_t mc;
2514 mbx_cmd_t *mcp = &mc;
2515
2516 if (!IS_FWI2_CAPABLE(ha))
2517 return QLA_FUNCTION_FAILED;
2518
2519 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2520
2521 mcp->mb[0] = MBC_TRACE_CONTROL;
2522 mcp->mb[1] = TC_FCE_DISABLE;
2523 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2524 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2525 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2526 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002527 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002528 mcp->flags = 0;
2529 rval = qla2x00_mailbox_command(ha, mcp);
2530 if (rval != QLA_SUCCESS) {
2531 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2532 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2533 } else {
2534 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2535
2536 if (wr)
2537 *wr = (uint64_t) mcp->mb[5] << 48 |
2538 (uint64_t) mcp->mb[4] << 32 |
2539 (uint64_t) mcp->mb[3] << 16 |
2540 (uint64_t) mcp->mb[2];
2541 if (rd)
2542 *rd = (uint64_t) mcp->mb[9] << 48 |
2543 (uint64_t) mcp->mb[8] << 32 |
2544 (uint64_t) mcp->mb[7] << 16 |
2545 (uint64_t) mcp->mb[6];
2546 }
2547
2548 return rval;
2549}
2550
2551int
Andrew Vasquez88729e52006-06-23 16:10:50 -07002552qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2553 uint16_t off, uint16_t count)
2554{
2555 int rval;
2556 mbx_cmd_t mc;
2557 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002558
Andrew Vasqueze4289242007-07-19 15:05:56 -07002559 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002560 return QLA_FUNCTION_FAILED;
2561
2562 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2563
2564 mcp->mb[0] = MBC_READ_SFP;
2565 mcp->mb[1] = addr;
2566 mcp->mb[2] = MSW(sfp_dma);
2567 mcp->mb[3] = LSW(sfp_dma);
2568 mcp->mb[6] = MSW(MSD(sfp_dma));
2569 mcp->mb[7] = LSW(MSD(sfp_dma));
2570 mcp->mb[8] = count;
2571 mcp->mb[9] = off;
2572 mcp->mb[10] = 0;
2573 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2574 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002575 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002576 mcp->flags = 0;
2577 rval = qla2x00_mailbox_command(ha, mcp);
2578
2579 if (rval != QLA_SUCCESS) {
2580 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2581 ha->host_no, rval, mcp->mb[0]));
2582 } else {
2583 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2584 }
2585
2586 return rval;
2587}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002588
2589int
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002590qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2591 uint16_t port_speed, uint16_t *mb)
2592{
2593 int rval;
2594 mbx_cmd_t mc;
2595 mbx_cmd_t *mcp = &mc;
2596
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002597 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002598 return QLA_FUNCTION_FAILED;
2599
2600 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2601
2602 mcp->mb[0] = MBC_PORT_PARAMS;
2603 mcp->mb[1] = loop_id;
2604 mcp->mb[2] = BIT_0;
2605 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2606 mcp->mb[4] = mcp->mb[5] = 0;
2607 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2608 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002609 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002610 mcp->flags = 0;
2611 rval = qla2x00_mailbox_command(ha, mcp);
2612
2613 /* Return mailbox statuses. */
2614 if (mb != NULL) {
2615 mb[0] = mcp->mb[0];
2616 mb[1] = mcp->mb[1];
2617 mb[3] = mcp->mb[3];
2618 mb[4] = mcp->mb[4];
2619 mb[5] = mcp->mb[5];
2620 }
2621
2622 if (rval != QLA_SUCCESS) {
2623 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2624 ha->host_no, rval));
2625 } else {
2626 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2627 }
2628
2629 return rval;
2630}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002631
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002632void
2633qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2634 struct vp_rpt_id_entry_24xx *rptid_entry)
2635{
2636 uint8_t vp_idx;
2637 scsi_qla_host_t *vha;
2638
2639 if (rptid_entry->entry_status != 0)
2640 return;
2641 if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
2642 return;
2643
2644 if (rptid_entry->format == 0) {
2645 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2646 " number of VPs acquired %d\n", __func__, ha->host_no,
2647 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2648 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2649 rptid_entry->port_id[2], rptid_entry->port_id[1],
2650 rptid_entry->port_id[0]));
2651 } else if (rptid_entry->format == 1) {
2652 vp_idx = LSB(rptid_entry->vp_idx);
2653 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2654 "- status %d - "
2655 "with port id %02x%02x%02x\n",__func__,ha->host_no,
2656 vp_idx, MSB(rptid_entry->vp_idx),
2657 rptid_entry->port_id[2], rptid_entry->port_id[1],
2658 rptid_entry->port_id[0]));
2659 if (vp_idx == 0)
2660 return;
2661
2662 if (MSB(rptid_entry->vp_idx) == 1)
2663 return;
2664
2665 list_for_each_entry(vha, &ha->vp_list, vp_list)
2666 if (vp_idx == vha->vp_idx)
2667 break;
2668
2669 if (!vha)
2670 return;
2671
2672 vha->d_id.b.domain = rptid_entry->port_id[2];
2673 vha->d_id.b.area = rptid_entry->port_id[1];
2674 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2675
2676 /*
2677 * Cannot configure here as we are still sitting on the
2678 * response queue. Handle it in dpc context.
2679 */
2680 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2681 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2682
2683 wake_up_process(ha->dpc_thread);
2684 }
2685}
2686
2687/*
2688 * qla24xx_modify_vp_config
2689 * Change VP configuration for vha
2690 *
2691 * Input:
2692 * vha = adapter block pointer.
2693 *
2694 * Returns:
2695 * qla2xxx local function return status code.
2696 *
2697 * Context:
2698 * Kernel context.
2699 */
2700int
2701qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2702{
2703 int rval;
2704 struct vp_config_entry_24xx *vpmod;
2705 dma_addr_t vpmod_dma;
2706 scsi_qla_host_t *pha;
2707
2708 /* This can be called by the parent */
2709 pha = to_qla_parent(vha);
2710
2711 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2712 if (!vpmod) {
2713 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2714 "IOCB.\n", __func__, pha->host_no));
2715 return QLA_MEMORY_ALLOC_FAILED;
2716 }
2717
2718 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2719 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2720 vpmod->entry_count = 1;
2721 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2722 vpmod->vp_count = 1;
2723 vpmod->vp_index1 = vha->vp_idx;
2724 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2725 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2726 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2727 vpmod->entry_count = 1;
2728
2729 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2730 if (rval != QLA_SUCCESS) {
2731 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2732 "(%x).\n", __func__, pha->host_no, rval));
2733 } else if (vpmod->comp_status != 0) {
2734 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2735 "-- error status (%x).\n", __func__, pha->host_no,
2736 vpmod->comp_status));
2737 rval = QLA_FUNCTION_FAILED;
2738 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2739 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2740 "-- completion status (%x).\n", __func__, pha->host_no,
2741 le16_to_cpu(vpmod->comp_status)));
2742 rval = QLA_FUNCTION_FAILED;
2743 } else {
2744 /* EMPTY */
2745 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2746 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2747 }
2748 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2749
2750 return rval;
2751}
2752
2753/*
2754 * qla24xx_control_vp
2755 * Enable a virtual port for given host
2756 *
2757 * Input:
2758 * ha = adapter block pointer.
2759 * vhba = virtual adapter (unused)
2760 * index = index number for enabled VP
2761 *
2762 * Returns:
2763 * qla2xxx local function return status code.
2764 *
2765 * Context:
2766 * Kernel context.
2767 */
2768int
2769qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2770{
2771 int rval;
2772 int map, pos;
2773 struct vp_ctrl_entry_24xx *vce;
2774 dma_addr_t vce_dma;
2775 scsi_qla_host_t *ha = vha->parent;
2776 int vp_index = vha->vp_idx;
2777
2778 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2779 ha->host_no, vp_index));
2780
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002781 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002782 return QLA_PARAMETER_ERROR;
2783
2784 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2785 if (!vce) {
2786 DEBUG2_3(printk("%s(%ld): "
2787 "failed to allocate VP Control IOCB.\n", __func__,
2788 ha->host_no));
2789 return QLA_MEMORY_ALLOC_FAILED;
2790 }
2791 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2792
2793 vce->entry_type = VP_CTRL_IOCB_TYPE;
2794 vce->entry_count = 1;
2795 vce->command = cpu_to_le16(cmd);
2796 vce->vp_count = __constant_cpu_to_le16(1);
2797
2798 /* index map in firmware starts with 1; decrement index
2799 * this is ok as we never use index 0
2800 */
2801 map = (vp_index - 1) / 8;
2802 pos = (vp_index - 1) & 7;
2803 down(&ha->vport_sem);
2804 vce->vp_idx_map[map] |= 1 << pos;
2805 up(&ha->vport_sem);
2806
2807 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2808 if (rval != QLA_SUCCESS) {
2809 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2810 "(%x).\n", __func__, ha->host_no, rval));
2811 printk("%s(%ld): failed to issue VP control IOCB"
2812 "(%x).\n", __func__, ha->host_no, rval);
2813 } else if (vce->entry_status != 0) {
2814 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2815 "-- error status (%x).\n", __func__, ha->host_no,
2816 vce->entry_status));
2817 printk("%s(%ld): failed to complete IOCB "
2818 "-- error status (%x).\n", __func__, ha->host_no,
2819 vce->entry_status);
2820 rval = QLA_FUNCTION_FAILED;
2821 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2822 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2823 "-- completion status (%x).\n", __func__, ha->host_no,
2824 le16_to_cpu(vce->comp_status)));
2825 printk("%s(%ld): failed to complete IOCB "
2826 "-- completion status (%x).\n", __func__, ha->host_no,
2827 le16_to_cpu(vce->comp_status));
2828 rval = QLA_FUNCTION_FAILED;
2829 } else {
2830 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2831 }
2832
2833 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2834
2835 return rval;
2836}
2837
2838/*
2839 * qla2x00_send_change_request
2840 * Receive or disable RSCN request from fabric controller
2841 *
2842 * Input:
2843 * ha = adapter block pointer
2844 * format = registration format:
2845 * 0 - Reserved
2846 * 1 - Fabric detected registration
2847 * 2 - N_port detected registration
2848 * 3 - Full registration
2849 * FF - clear registration
2850 * vp_idx = Virtual port index
2851 *
2852 * Returns:
2853 * qla2x00 local function return status code.
2854 *
2855 * Context:
2856 * Kernel Context
2857 */
2858
2859int
2860qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2861 uint16_t vp_idx)
2862{
2863 int rval;
2864 mbx_cmd_t mc;
2865 mbx_cmd_t *mcp = &mc;
2866
2867 /*
2868 * This command is implicitly executed by firmware during login for the
2869 * physical hosts
2870 */
2871 if (vp_idx == 0)
2872 return QLA_FUNCTION_FAILED;
2873
2874 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2875 mcp->mb[1] = format;
2876 mcp->mb[9] = vp_idx;
2877 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2878 mcp->in_mb = MBX_0|MBX_1;
2879 mcp->tov = MBX_TOV_SECONDS;
2880 mcp->flags = 0;
2881 rval = qla2x00_mailbox_command(ha, mcp);
2882
2883 if (rval == QLA_SUCCESS) {
2884 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2885 rval = BIT_1;
2886 }
2887 } else
2888 rval = BIT_1;
2889
2890 return rval;
2891}
Andrew Vasquez338c9162007-09-20 14:07:33 -07002892
2893int
2894qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2895 uint32_t size)
2896{
2897 int rval;
2898 mbx_cmd_t mc;
2899 mbx_cmd_t *mcp = &mc;
2900
2901 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2902
2903 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2904 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2905 mcp->mb[8] = MSW(addr);
2906 mcp->out_mb = MBX_8|MBX_0;
2907 } else {
2908 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2909 mcp->out_mb = MBX_0;
2910 }
2911 mcp->mb[1] = LSW(addr);
2912 mcp->mb[2] = MSW(req_dma);
2913 mcp->mb[3] = LSW(req_dma);
2914 mcp->mb[6] = MSW(MSD(req_dma));
2915 mcp->mb[7] = LSW(MSD(req_dma));
2916 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2917 if (IS_FWI2_CAPABLE(ha)) {
2918 mcp->mb[4] = MSW(size);
2919 mcp->mb[5] = LSW(size);
2920 mcp->out_mb |= MBX_5|MBX_4;
2921 } else {
2922 mcp->mb[4] = LSW(size);
2923 mcp->out_mb |= MBX_4;
2924 }
2925
2926 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002927 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07002928 mcp->flags = 0;
2929 rval = qla2x00_mailbox_command(ha, mcp);
2930
2931 if (rval != QLA_SUCCESS) {
2932 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2933 ha->host_no, rval, mcp->mb[0]));
2934 } else {
2935 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2936 }
2937
2938 return rval;
2939}