blob: 7d0a8a4c77196ea302262dcfc2d61f0d6d8931b2 [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
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700685qla2x00_issue_iocb_timeout(scsi_qla_host_t *ha, void *buffer,
686 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687{
688 int rval;
689 mbx_cmd_t mc;
690 mbx_cmd_t *mcp = &mc;
691
692 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
693 mcp->mb[1] = 0;
694 mcp->mb[2] = MSW(phys_addr);
695 mcp->mb[3] = LSW(phys_addr);
696 mcp->mb[6] = MSW(MSD(phys_addr));
697 mcp->mb[7] = LSW(MSD(phys_addr));
698 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
699 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700700 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 mcp->flags = 0;
702 rval = qla2x00_mailbox_command(ha, mcp);
703
704 if (rval != QLA_SUCCESS) {
705 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700706 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700707 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700708 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700709 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700711 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
712
713 /* Mask reserved bits. */
714 sts_entry->entry_status &=
Andrew Vasqueze4289242007-07-19 15:05:56 -0700715 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 }
717
718 return rval;
719}
720
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700721int
722qla2x00_issue_iocb(scsi_qla_host_t *ha, void *buffer, dma_addr_t phys_addr,
723 size_t size)
724{
725 return qla2x00_issue_iocb_timeout(ha, buffer, phys_addr, size,
726 MBX_TOV_SECONDS);
727}
728
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729/*
730 * qla2x00_abort_command
731 * Abort command aborts a specified IOCB.
732 *
733 * Input:
734 * ha = adapter block pointer.
735 * sp = SB structure pointer.
736 *
737 * Returns:
738 * qla2x00 local function return status code.
739 *
740 * Context:
741 * Kernel context.
742 */
743int
744qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
745{
746 unsigned long flags = 0;
747 fc_port_t *fcport;
748 int rval;
749 uint32_t handle;
750 mbx_cmd_t mc;
751 mbx_cmd_t *mcp = &mc;
752
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700753 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
bdf79622005-04-17 15:06:53 -0500755 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 spin_lock_irqsave(&ha->hardware_lock, flags);
758 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
759 if (ha->outstanding_cmds[handle] == sp)
760 break;
761 }
762 spin_unlock_irqrestore(&ha->hardware_lock, flags);
763
764 if (handle == MAX_OUTSTANDING_COMMANDS) {
765 /* command not found */
766 return QLA_FUNCTION_FAILED;
767 }
768
769 mcp->mb[0] = MBC_ABORT_COMMAND;
770 if (HAS_EXTENDED_IDS(ha))
771 mcp->mb[1] = fcport->loop_id;
772 else
773 mcp->mb[1] = fcport->loop_id << 8;
774 mcp->mb[2] = (uint16_t)handle;
775 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500776 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
778 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700779 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 mcp->flags = 0;
781 rval = qla2x00_mailbox_command(ha, mcp);
782
783 if (rval != QLA_SUCCESS) {
784 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700785 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 } else {
787 sp->flags |= SRB_ABORT_PENDING;
788 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700789 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 }
791
792 return rval;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700796qla2x00_abort_target(struct fc_port *fcport, unsigned int l)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700798 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 mbx_cmd_t mc;
800 mbx_cmd_t *mcp = &mc;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700801 scsi_qla_host_t *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700803 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700804
Andrew Vasquez523ec772008-04-03 13:13:24 -0700805 l = l;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700806 ha = fcport->ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700808 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700809 if (HAS_EXTENDED_IDS(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 mcp->mb[1] = fcport->loop_id;
811 mcp->mb[10] = 0;
812 mcp->out_mb |= MBX_10;
813 } else {
814 mcp->mb[1] = fcport->loop_id << 8;
815 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700816 mcp->mb[2] = ha->loop_reset_delay;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700817 mcp->mb[9] = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818
819 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700820 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 mcp->flags = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700822 rval = qla2x00_mailbox_command(ha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700824 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700825 ha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700826 }
827
828 /* Issue marker IOCB. */
829 rval2 = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
830 if (rval2 != QLA_SUCCESS) {
831 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
832 "(%x).\n", __func__, ha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 } else {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700834 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
835 }
836
837 return rval;
838}
839
840int
841qla2x00_lun_reset(struct fc_port *fcport, unsigned int l)
842{
843 int rval, rval2;
844 mbx_cmd_t mc;
845 mbx_cmd_t *mcp = &mc;
846 scsi_qla_host_t *ha;
847
848 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
849
850 ha = fcport->ha;
851 mcp->mb[0] = MBC_LUN_RESET;
852 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
853 if (HAS_EXTENDED_IDS(ha))
854 mcp->mb[1] = fcport->loop_id;
855 else
856 mcp->mb[1] = fcport->loop_id << 8;
857 mcp->mb[2] = l;
858 mcp->mb[3] = 0;
859 mcp->mb[9] = ha->vp_idx;
860
861 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700862 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700863 mcp->flags = 0;
864 rval = qla2x00_mailbox_command(ha, mcp);
865 if (rval != QLA_SUCCESS) {
866 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
867 ha->host_no, rval));
868 }
869
870 /* Issue marker IOCB. */
871 rval2 = qla2x00_marker(ha, fcport->loop_id, l, MK_SYNC_ID_LUN);
872 if (rval2 != QLA_SUCCESS) {
873 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
874 "(%x).\n", __func__, ha->host_no, rval2));
875 } else {
876 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 }
878
879 return rval;
880}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 * qla2x00_get_adapter_id
884 * Get adapter ID and topology.
885 *
886 * Input:
887 * ha = adapter block pointer.
888 * id = pointer for loop ID.
889 * al_pa = pointer for AL_PA.
890 * area = pointer for area.
891 * domain = pointer for domain.
892 * top = pointer for topology.
893 * TARGET_QUEUE_LOCK must be released.
894 * ADAPTER_STATE_LOCK must be released.
895 *
896 * Returns:
897 * qla2x00 local function return status code.
898 *
899 * Context:
900 * Kernel context.
901 */
902int
903qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700904 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
906 int rval;
907 mbx_cmd_t mc;
908 mbx_cmd_t *mcp = &mc;
909
910 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700911 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700914 mcp->mb[9] = ha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800915 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700916 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700917 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 mcp->flags = 0;
919 rval = qla2x00_mailbox_command(ha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800920 if (mcp->mb[0] == MBS_COMMAND_ERROR)
921 rval = QLA_COMMAND_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922
923 /* Return data. */
924 *id = mcp->mb[1];
925 *al_pa = LSB(mcp->mb[2]);
926 *area = MSB(mcp->mb[2]);
927 *domain = LSB(mcp->mb[3]);
928 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700929 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 if (rval != QLA_SUCCESS) {
932 /*EMPTY*/
933 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700934 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 } else {
936 /*EMPTY*/
937 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700938 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 }
940
941 return rval;
942}
943
944/*
945 * qla2x00_get_retry_cnt
946 * Get current firmware login retry count and delay.
947 *
948 * Input:
949 * ha = adapter block pointer.
950 * retry_cnt = pointer to login retry count.
951 * tov = pointer to login timeout value.
952 *
953 * Returns:
954 * qla2x00 local function return status code.
955 *
956 * Context:
957 * Kernel context.
958 */
959int
960qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
961 uint16_t *r_a_tov)
962{
963 int rval;
964 uint16_t ratov;
965 mbx_cmd_t mc;
966 mbx_cmd_t *mcp = &mc;
967
968 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700969 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 mcp->mb[0] = MBC_GET_RETRY_COUNT;
972 mcp->out_mb = MBX_0;
973 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700974 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 mcp->flags = 0;
976 rval = qla2x00_mailbox_command(ha, mcp);
977
978 if (rval != QLA_SUCCESS) {
979 /*EMPTY*/
980 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700981 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 } else {
983 /* Convert returned data and check our values. */
984 *r_a_tov = mcp->mb[3] / 2;
985 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
986 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
987 /* Update to the larger values */
988 *retry_cnt = (uint8_t)mcp->mb[1];
989 *tov = ratov;
990 }
991
992 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700993 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995
996 return rval;
997}
998
999/*
1000 * qla2x00_init_firmware
1001 * Initialize adapter firmware.
1002 *
1003 * Input:
1004 * ha = adapter block pointer.
1005 * dptr = Initialization control block pointer.
1006 * size = size of initialization control block.
1007 * TARGET_QUEUE_LOCK must be released.
1008 * ADAPTER_STATE_LOCK must be released.
1009 *
1010 * Returns:
1011 * qla2x00 local function return status code.
1012 *
1013 * Context:
1014 * Kernel context.
1015 */
1016int
1017qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1018{
1019 int rval;
1020 mbx_cmd_t mc;
1021 mbx_cmd_t *mcp = &mc;
1022
1023 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001024 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001026 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001027 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1028 else
1029 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 mcp->mb[2] = MSW(ha->init_cb_dma);
1032 mcp->mb[3] = LSW(ha->init_cb_dma);
1033 mcp->mb[4] = 0;
1034 mcp->mb[5] = 0;
1035 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1036 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1037 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1038 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1039 mcp->buf_size = size;
1040 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001041 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 rval = qla2x00_mailbox_command(ha, mcp);
1043
1044 if (rval != QLA_SUCCESS) {
1045 /*EMPTY*/
1046 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1047 "mb0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001048 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 } else {
1050 /*EMPTY*/
1051 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001052 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
1054
1055 return rval;
1056}
1057
1058/*
1059 * qla2x00_get_port_database
1060 * Issue normal/enhanced get port database mailbox command
1061 * and copy device name as necessary.
1062 *
1063 * Input:
1064 * ha = adapter state pointer.
1065 * dev = structure pointer.
1066 * opt = enhanced cmd option byte.
1067 *
1068 * Returns:
1069 * qla2x00 local function return status code.
1070 *
1071 * Context:
1072 * Kernel context.
1073 */
1074int
1075qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1076{
1077 int rval;
1078 mbx_cmd_t mc;
1079 mbx_cmd_t *mcp = &mc;
1080 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001081 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 dma_addr_t pd_dma;
1083
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001084 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001086 pd24 = NULL;
1087 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001089 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1090 "structure.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 return QLA_MEMORY_ALLOC_FAILED;
1092 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001093 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001095 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001096 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 mcp->mb[2] = MSW(pd_dma);
1099 mcp->mb[3] = LSW(pd_dma);
1100 mcp->mb[6] = MSW(MSD(pd_dma));
1101 mcp->mb[7] = LSW(MSD(pd_dma));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001102 mcp->mb[9] = ha->vp_idx;
1103 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001105 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001106 mcp->mb[1] = fcport->loop_id;
1107 mcp->mb[10] = opt;
1108 mcp->out_mb |= MBX_10|MBX_1;
1109 mcp->in_mb |= MBX_1;
1110 } else if (HAS_EXTENDED_IDS(ha)) {
1111 mcp->mb[1] = fcport->loop_id;
1112 mcp->mb[10] = opt;
1113 mcp->out_mb |= MBX_10|MBX_1;
1114 } else {
1115 mcp->mb[1] = fcport->loop_id << 8 | opt;
1116 mcp->out_mb |= MBX_1;
1117 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001118 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1119 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 mcp->flags = MBX_DMA_IN;
1121 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1122 rval = qla2x00_mailbox_command(ha, mcp);
1123 if (rval != QLA_SUCCESS)
1124 goto gpd_error_out;
1125
Andrew Vasqueze4289242007-07-19 15:05:56 -07001126 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001127 pd24 = (struct port_database_24xx *) pd;
1128
1129 /* Check for logged in state. */
1130 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1131 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1132 DEBUG2(printk("%s(%ld): Unable to verify "
1133 "login-state (%x/%x) for loop_id %x\n",
1134 __func__, ha->host_no,
1135 pd24->current_login_state,
1136 pd24->last_login_state, fcport->loop_id));
1137 rval = QLA_FUNCTION_FAILED;
1138 goto gpd_error_out;
1139 }
1140
1141 /* Names are little-endian. */
1142 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1143 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1144
1145 /* Get port_id of device. */
1146 fcport->d_id.b.domain = pd24->port_id[0];
1147 fcport->d_id.b.area = pd24->port_id[1];
1148 fcport->d_id.b.al_pa = pd24->port_id[2];
1149 fcport->d_id.b.rsvd_1 = 0;
1150
1151 /* If not target must be initiator or unknown type. */
1152 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1153 fcport->port_type = FCT_INITIATOR;
1154 else
1155 fcport->port_type = FCT_TARGET;
1156 } else {
1157 /* Check for logged in state. */
1158 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1159 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1160 rval = QLA_FUNCTION_FAILED;
1161 goto gpd_error_out;
1162 }
1163
1164 /* Names are little-endian. */
1165 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1166 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1167
1168 /* Get port_id of device. */
1169 fcport->d_id.b.domain = pd->port_id[0];
1170 fcport->d_id.b.area = pd->port_id[3];
1171 fcport->d_id.b.al_pa = pd->port_id[2];
1172 fcport->d_id.b.rsvd_1 = 0;
1173
1174 /* Check for device require authentication. */
1175 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1176 (fcport->flags &= ~FCF_AUTH_REQ);
1177
1178 /* If not target must be initiator or unknown type. */
1179 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1180 fcport->port_type = FCT_INITIATOR;
1181 else
1182 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001183
1184 /* Passback COS information. */
1185 fcport->supported_classes = (pd->options & BIT_4) ?
1186 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
1188
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189gpd_error_out:
1190 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1191
1192 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001193 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1194 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001196 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 }
1198
1199 return rval;
1200}
1201
1202/*
1203 * qla2x00_get_firmware_state
1204 * Get adapter firmware state.
1205 *
1206 * Input:
1207 * ha = adapter block pointer.
1208 * dptr = pointer for firmware state.
1209 * TARGET_QUEUE_LOCK must be released.
1210 * ADAPTER_STATE_LOCK must be released.
1211 *
1212 * Returns:
1213 * qla2x00 local function return status code.
1214 *
1215 * Context:
1216 * Kernel context.
1217 */
1218int
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001219qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220{
1221 int rval;
1222 mbx_cmd_t mc;
1223 mbx_cmd_t *mcp = &mc;
1224
1225 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001226 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
1228 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1229 mcp->out_mb = MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001230 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001231 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 mcp->flags = 0;
1233 rval = qla2x00_mailbox_command(ha, mcp);
1234
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001235 /* Return firmware states. */
1236 states[0] = mcp->mb[1];
1237 states[1] = mcp->mb[2];
1238 states[2] = mcp->mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
1240 if (rval != QLA_SUCCESS) {
1241 /*EMPTY*/
1242 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001243 "failed=%x.\n", ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 } else {
1245 /*EMPTY*/
1246 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001247 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
1249
1250 return rval;
1251}
1252
1253/*
1254 * qla2x00_get_port_name
1255 * Issue get port name mailbox command.
1256 * Returned name is in big endian format.
1257 *
1258 * Input:
1259 * ha = adapter block pointer.
1260 * loop_id = loop ID of device.
1261 * name = pointer for name.
1262 * TARGET_QUEUE_LOCK must be released.
1263 * ADAPTER_STATE_LOCK must be released.
1264 *
1265 * Returns:
1266 * qla2x00 local function return status code.
1267 *
1268 * Context:
1269 * Kernel context.
1270 */
1271int
1272qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1273 uint8_t opt)
1274{
1275 int rval;
1276 mbx_cmd_t mc;
1277 mbx_cmd_t *mcp = &mc;
1278
1279 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001280 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 mcp->mb[0] = MBC_GET_PORT_NAME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001283 mcp->mb[9] = ha->vp_idx;
1284 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 if (HAS_EXTENDED_IDS(ha)) {
1286 mcp->mb[1] = loop_id;
1287 mcp->mb[10] = opt;
1288 mcp->out_mb |= MBX_10;
1289 } else {
1290 mcp->mb[1] = loop_id << 8 | opt;
1291 }
1292
1293 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001294 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 mcp->flags = 0;
1296 rval = qla2x00_mailbox_command(ha, mcp);
1297
1298 if (rval != QLA_SUCCESS) {
1299 /*EMPTY*/
1300 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001301 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 } else {
1303 if (name != NULL) {
1304 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001305 name[0] = MSB(mcp->mb[2]);
1306 name[1] = LSB(mcp->mb[2]);
1307 name[2] = MSB(mcp->mb[3]);
1308 name[3] = LSB(mcp->mb[3]);
1309 name[4] = MSB(mcp->mb[6]);
1310 name[5] = LSB(mcp->mb[6]);
1311 name[6] = MSB(mcp->mb[7]);
1312 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 }
1314
1315 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001316 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
1318
1319 return rval;
1320}
1321
1322/*
1323 * qla2x00_lip_reset
1324 * Issue LIP reset mailbox command.
1325 *
1326 * Input:
1327 * ha = adapter block pointer.
1328 * TARGET_QUEUE_LOCK must be released.
1329 * ADAPTER_STATE_LOCK must be released.
1330 *
1331 * Returns:
1332 * qla2x00 local function return status code.
1333 *
1334 * Context:
1335 * Kernel context.
1336 */
1337int
1338qla2x00_lip_reset(scsi_qla_host_t *ha)
1339{
1340 int rval;
1341 mbx_cmd_t mc;
1342 mbx_cmd_t *mcp = &mc;
1343
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001344 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Andrew Vasqueze4289242007-07-19 15:05:56 -07001346 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001347 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001348 mcp->mb[1] = BIT_6;
1349 mcp->mb[2] = 0;
1350 mcp->mb[3] = ha->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001351 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001353 mcp->mb[0] = MBC_LIP_RESET;
1354 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1355 if (HAS_EXTENDED_IDS(ha)) {
1356 mcp->mb[1] = 0x00ff;
1357 mcp->mb[10] = 0;
1358 mcp->out_mb |= MBX_10;
1359 } else {
1360 mcp->mb[1] = 0xff00;
1361 }
1362 mcp->mb[2] = ha->loop_reset_delay;
1363 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001366 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 mcp->flags = 0;
1368 rval = qla2x00_mailbox_command(ha, mcp);
1369
1370 if (rval != QLA_SUCCESS) {
1371 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001372 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001373 __func__, ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 } else {
1375 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001376 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 }
1378
1379 return rval;
1380}
1381
1382/*
1383 * qla2x00_send_sns
1384 * Send SNS command.
1385 *
1386 * Input:
1387 * ha = adapter block pointer.
1388 * sns = pointer for command.
1389 * cmd_size = command size.
1390 * buf_size = response/command size.
1391 * TARGET_QUEUE_LOCK must be released.
1392 * ADAPTER_STATE_LOCK must be released.
1393 *
1394 * Returns:
1395 * qla2x00 local function return status code.
1396 *
1397 * Context:
1398 * Kernel context.
1399 */
1400int
1401qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1402 uint16_t cmd_size, size_t buf_size)
1403{
1404 int rval;
1405 mbx_cmd_t mc;
1406 mbx_cmd_t *mcp = &mc;
1407
1408 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001409 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410
1411 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001412 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
1414 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1415 mcp->mb[1] = cmd_size;
1416 mcp->mb[2] = MSW(sns_phys_address);
1417 mcp->mb[3] = LSW(sns_phys_address);
1418 mcp->mb[6] = MSW(MSD(sns_phys_address));
1419 mcp->mb[7] = LSW(MSD(sns_phys_address));
1420 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1421 mcp->in_mb = MBX_0|MBX_1;
1422 mcp->buf_size = buf_size;
1423 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1424 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1425 rval = qla2x00_mailbox_command(ha, mcp);
1426
1427 if (rval != QLA_SUCCESS) {
1428 /*EMPTY*/
1429 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001430 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001432 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 } else {
1434 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001435 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 }
1437
1438 return rval;
1439}
1440
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001441int
1442qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1443 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1444{
1445 int rval;
1446
1447 struct logio_entry_24xx *lg;
1448 dma_addr_t lg_dma;
1449 uint32_t iop[2];
1450
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001451 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001452
1453 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1454 if (lg == NULL) {
1455 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1456 __func__, ha->host_no));
1457 return QLA_MEMORY_ALLOC_FAILED;
1458 }
1459 memset(lg, 0, sizeof(struct logio_entry_24xx));
1460
1461 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1462 lg->entry_count = 1;
1463 lg->nport_handle = cpu_to_le16(loop_id);
1464 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1465 if (opt & BIT_0)
1466 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001467 if (opt & BIT_1)
1468 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001469 lg->port_id[0] = al_pa;
1470 lg->port_id[1] = area;
1471 lg->port_id[2] = domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001472 lg->vp_index = cpu_to_le16(ha->vp_idx);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001473 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1474 if (rval != QLA_SUCCESS) {
1475 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001476 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001477 } else if (lg->entry_status != 0) {
1478 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1479 "-- error status (%x).\n", __func__, ha->host_no,
1480 lg->entry_status));
1481 rval = QLA_FUNCTION_FAILED;
1482 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1483 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1484 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1485
1486 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1487 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1488 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1489 iop[1]));
1490
1491 switch (iop[0]) {
1492 case LSC_SCODE_PORTID_USED:
1493 mb[0] = MBS_PORT_ID_USED;
1494 mb[1] = LSW(iop[1]);
1495 break;
1496 case LSC_SCODE_NPORT_USED:
1497 mb[0] = MBS_LOOP_ID_USED;
1498 break;
1499 case LSC_SCODE_NOLINK:
1500 case LSC_SCODE_NOIOCB:
1501 case LSC_SCODE_NOXCB:
1502 case LSC_SCODE_CMD_FAILED:
1503 case LSC_SCODE_NOFABRIC:
1504 case LSC_SCODE_FW_NOT_READY:
1505 case LSC_SCODE_NOT_LOGGED_IN:
1506 case LSC_SCODE_NOPCB:
1507 case LSC_SCODE_ELS_REJECT:
1508 case LSC_SCODE_CMD_PARAM_ERR:
1509 case LSC_SCODE_NONPORT:
1510 case LSC_SCODE_LOGGED_IN:
1511 case LSC_SCODE_NOFLOGI_ACC:
1512 default:
1513 mb[0] = MBS_COMMAND_ERROR;
1514 break;
1515 }
1516 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001517 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001518
1519 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1520
1521 mb[0] = MBS_COMMAND_COMPLETE;
1522 mb[1] = 0;
1523 if (iop[0] & BIT_4) {
1524 if (iop[0] & BIT_8)
1525 mb[1] |= BIT_1;
1526 } else
1527 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001528
1529 /* Passback COS information. */
1530 mb[10] = 0;
1531 if (lg->io_parameter[7] || lg->io_parameter[8])
1532 mb[10] |= BIT_0; /* Class 2. */
1533 if (lg->io_parameter[9] || lg->io_parameter[10])
1534 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001535 }
1536
1537 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1538
1539 return rval;
1540}
1541
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542/*
1543 * qla2x00_login_fabric
1544 * Issue login fabric port mailbox command.
1545 *
1546 * Input:
1547 * ha = adapter block pointer.
1548 * loop_id = device loop ID.
1549 * domain = device domain.
1550 * area = device area.
1551 * al_pa = device AL_PA.
1552 * status = pointer for return status.
1553 * opt = command options.
1554 * TARGET_QUEUE_LOCK must be released.
1555 * ADAPTER_STATE_LOCK must be released.
1556 *
1557 * Returns:
1558 * qla2x00 local function return status code.
1559 *
1560 * Context:
1561 * Kernel context.
1562 */
1563int
1564qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1565 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1566{
1567 int rval;
1568 mbx_cmd_t mc;
1569 mbx_cmd_t *mcp = &mc;
1570
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001571 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1574 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1575 if (HAS_EXTENDED_IDS(ha)) {
1576 mcp->mb[1] = loop_id;
1577 mcp->mb[10] = opt;
1578 mcp->out_mb |= MBX_10;
1579 } else {
1580 mcp->mb[1] = (loop_id << 8) | opt;
1581 }
1582 mcp->mb[2] = domain;
1583 mcp->mb[3] = area << 8 | al_pa;
1584
1585 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1586 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1587 mcp->flags = 0;
1588 rval = qla2x00_mailbox_command(ha, mcp);
1589
1590 /* Return mailbox statuses. */
1591 if (mb != NULL) {
1592 mb[0] = mcp->mb[0];
1593 mb[1] = mcp->mb[1];
1594 mb[2] = mcp->mb[2];
1595 mb[6] = mcp->mb[6];
1596 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001597 /* COS retrieved from Get-Port-Database mailbox command. */
1598 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 }
1600
1601 if (rval != QLA_SUCCESS) {
1602 /* RLU tmp code: need to change main mailbox_command function to
1603 * return ok even when the mailbox completion value is not
1604 * SUCCESS. The caller needs to be responsible to interpret
1605 * the return values of this mailbox command if we're not
1606 * to change too much of the existing code.
1607 */
1608 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1609 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1610 mcp->mb[0] == 0x4006)
1611 rval = QLA_SUCCESS;
1612
1613 /*EMPTY*/
1614 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1615 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001616 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 } else {
1618 /*EMPTY*/
1619 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001620 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 }
1622
1623 return rval;
1624}
1625
1626/*
1627 * qla2x00_login_local_device
1628 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001629 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 * Input:
1631 * ha = adapter block pointer.
1632 * loop_id = device loop ID.
1633 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001634 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 * Returns:
1636 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001637 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 * Context:
1639 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001640 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 */
1642int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001643qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 uint16_t *mb_ret, uint8_t opt)
1645{
1646 int rval;
1647 mbx_cmd_t mc;
1648 mbx_cmd_t *mcp = &mc;
1649
Andrew Vasqueze4289242007-07-19 15:05:56 -07001650 if (IS_FWI2_CAPABLE(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001651 return qla24xx_login_fabric(ha, fcport->loop_id,
1652 fcport->d_id.b.domain, fcport->d_id.b.area,
1653 fcport->d_id.b.al_pa, mb_ret, opt);
1654
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001655 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
1657 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1658 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001659 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001661 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 mcp->mb[2] = opt;
1663 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1664 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1665 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1666 mcp->flags = 0;
1667 rval = qla2x00_mailbox_command(ha, mcp);
1668
1669 /* Return mailbox statuses. */
1670 if (mb_ret != NULL) {
1671 mb_ret[0] = mcp->mb[0];
1672 mb_ret[1] = mcp->mb[1];
1673 mb_ret[6] = mcp->mb[6];
1674 mb_ret[7] = mcp->mb[7];
1675 }
1676
1677 if (rval != QLA_SUCCESS) {
1678 /* AV tmp code: need to change main mailbox_command function to
1679 * return ok even when the mailbox completion value is not
1680 * SUCCESS. The caller needs to be responsible to interpret
1681 * the return values of this mailbox command if we're not
1682 * to change too much of the existing code.
1683 */
1684 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1685 rval = QLA_SUCCESS;
1686
1687 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1688 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001689 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1691 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001692 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 } else {
1694 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001695 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 }
1697
1698 return (rval);
1699}
1700
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001701int
1702qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1703 uint8_t area, uint8_t al_pa)
1704{
1705 int rval;
1706 struct logio_entry_24xx *lg;
1707 dma_addr_t lg_dma;
1708
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001709 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001710
1711 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1712 if (lg == NULL) {
1713 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1714 __func__, ha->host_no));
1715 return QLA_MEMORY_ALLOC_FAILED;
1716 }
1717 memset(lg, 0, sizeof(struct logio_entry_24xx));
1718
1719 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1720 lg->entry_count = 1;
1721 lg->nport_handle = cpu_to_le16(loop_id);
1722 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001723 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001724 lg->port_id[0] = al_pa;
1725 lg->port_id[1] = area;
1726 lg->port_id[2] = domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001727 lg->vp_index = cpu_to_le16(ha->vp_idx);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001728 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1729 if (rval != QLA_SUCCESS) {
1730 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001731 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001732 } else if (lg->entry_status != 0) {
1733 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1734 "-- error status (%x).\n", __func__, ha->host_no,
1735 lg->entry_status));
1736 rval = QLA_FUNCTION_FAILED;
1737 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1738 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1739 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1740 ha->host_no, le16_to_cpu(lg->comp_status),
1741 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001742 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001743 } else {
1744 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001745 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001746 }
1747
1748 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1749
1750 return rval;
1751}
1752
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753/*
1754 * qla2x00_fabric_logout
1755 * Issue logout fabric port mailbox command.
1756 *
1757 * Input:
1758 * ha = adapter block pointer.
1759 * loop_id = device loop ID.
1760 * TARGET_QUEUE_LOCK must be released.
1761 * ADAPTER_STATE_LOCK must be released.
1762 *
1763 * Returns:
1764 * qla2x00 local function return status code.
1765 *
1766 * Context:
1767 * Kernel context.
1768 */
1769int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001770qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1771 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772{
1773 int rval;
1774 mbx_cmd_t mc;
1775 mbx_cmd_t *mcp = &mc;
1776
1777 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001778 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
1780 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1781 mcp->out_mb = MBX_1|MBX_0;
1782 if (HAS_EXTENDED_IDS(ha)) {
1783 mcp->mb[1] = loop_id;
1784 mcp->mb[10] = 0;
1785 mcp->out_mb |= MBX_10;
1786 } else {
1787 mcp->mb[1] = loop_id << 8;
1788 }
1789
1790 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001791 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 mcp->flags = 0;
1793 rval = qla2x00_mailbox_command(ha, mcp);
1794
1795 if (rval != QLA_SUCCESS) {
1796 /*EMPTY*/
1797 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001798 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 } else {
1800 /*EMPTY*/
1801 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001802 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 }
1804
1805 return rval;
1806}
1807
1808/*
1809 * qla2x00_full_login_lip
1810 * Issue full login LIP mailbox command.
1811 *
1812 * Input:
1813 * ha = adapter block pointer.
1814 * TARGET_QUEUE_LOCK must be released.
1815 * ADAPTER_STATE_LOCK must be released.
1816 *
1817 * Returns:
1818 * qla2x00 local function return status code.
1819 *
1820 * Context:
1821 * Kernel context.
1822 */
1823int
1824qla2x00_full_login_lip(scsi_qla_host_t *ha)
1825{
1826 int rval;
1827 mbx_cmd_t mc;
1828 mbx_cmd_t *mcp = &mc;
1829
1830 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001831 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
1833 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001834 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001835 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 mcp->mb[3] = 0;
1837 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1838 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001839 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 mcp->flags = 0;
1841 rval = qla2x00_mailbox_command(ha, mcp);
1842
1843 if (rval != QLA_SUCCESS) {
1844 /*EMPTY*/
1845 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001846 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 } else {
1848 /*EMPTY*/
1849 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001850 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 }
1852
1853 return rval;
1854}
1855
1856/*
1857 * qla2x00_get_id_list
1858 *
1859 * Input:
1860 * ha = adapter block pointer.
1861 *
1862 * Returns:
1863 * qla2x00 local function return status code.
1864 *
1865 * Context:
1866 * Kernel context.
1867 */
1868int
1869qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1870 uint16_t *entries)
1871{
1872 int rval;
1873 mbx_cmd_t mc;
1874 mbx_cmd_t *mcp = &mc;
1875
1876 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001877 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 if (id_list == NULL)
1880 return QLA_FUNCTION_FAILED;
1881
1882 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001883 mcp->out_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001884 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001885 mcp->mb[2] = MSW(id_list_dma);
1886 mcp->mb[3] = LSW(id_list_dma);
1887 mcp->mb[6] = MSW(MSD(id_list_dma));
1888 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001889 mcp->mb[8] = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001890 mcp->mb[9] = ha->vp_idx;
1891 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001892 } else {
1893 mcp->mb[1] = MSW(id_list_dma);
1894 mcp->mb[2] = LSW(id_list_dma);
1895 mcp->mb[3] = MSW(MSD(id_list_dma));
1896 mcp->mb[6] = LSW(MSD(id_list_dma));
1897 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1898 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001900 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 mcp->flags = 0;
1902 rval = qla2x00_mailbox_command(ha, mcp);
1903
1904 if (rval != QLA_SUCCESS) {
1905 /*EMPTY*/
1906 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001907 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 } else {
1909 *entries = mcp->mb[1];
1910 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001911 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 }
1913
1914 return rval;
1915}
1916
1917/*
1918 * qla2x00_get_resource_cnts
1919 * Get current firmware resource counts.
1920 *
1921 * Input:
1922 * ha = adapter block pointer.
1923 *
1924 * Returns:
1925 * qla2x00 local function return status code.
1926 *
1927 * Context:
1928 * Kernel context.
1929 */
1930int
1931qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001932 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1933 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
1935 int rval;
1936 mbx_cmd_t mc;
1937 mbx_cmd_t *mcp = &mc;
1938
1939 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1940
1941 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1942 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001943 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 -07001944 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 mcp->flags = 0;
1946 rval = qla2x00_mailbox_command(ha, mcp);
1947
1948 if (rval != QLA_SUCCESS) {
1949 /*EMPTY*/
1950 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001951 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 } else {
1953 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001954 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001955 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001956 mcp->mb[10], mcp->mb[11]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
1958 if (cur_xchg_cnt)
1959 *cur_xchg_cnt = mcp->mb[3];
1960 if (orig_xchg_cnt)
1961 *orig_xchg_cnt = mcp->mb[6];
1962 if (cur_iocb_cnt)
1963 *cur_iocb_cnt = mcp->mb[7];
1964 if (orig_iocb_cnt)
1965 *orig_iocb_cnt = mcp->mb[10];
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001966 if (max_npiv_vports)
1967 *max_npiv_vports = mcp->mb[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
1969
1970 return (rval);
1971}
1972
1973#if defined(QL_DEBUG_LEVEL_3)
1974/*
1975 * qla2x00_get_fcal_position_map
1976 * Get FCAL (LILP) position map using mailbox command
1977 *
1978 * Input:
1979 * ha = adapter state pointer.
1980 * pos_map = buffer pointer (can be NULL).
1981 *
1982 * Returns:
1983 * qla2x00 local function return status code.
1984 *
1985 * Context:
1986 * Kernel context.
1987 */
1988int
1989qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1990{
1991 int rval;
1992 mbx_cmd_t mc;
1993 mbx_cmd_t *mcp = &mc;
1994 char *pmap;
1995 dma_addr_t pmap_dma;
1996
1997 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1998 if (pmap == NULL) {
1999 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2000 __func__, ha->host_no));
2001 return QLA_MEMORY_ALLOC_FAILED;
2002 }
2003 memset(pmap, 0, FCAL_MAP_SIZE);
2004
2005 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2006 mcp->mb[2] = MSW(pmap_dma);
2007 mcp->mb[3] = LSW(pmap_dma);
2008 mcp->mb[6] = MSW(MSD(pmap_dma));
2009 mcp->mb[7] = LSW(MSD(pmap_dma));
2010 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2011 mcp->in_mb = MBX_1|MBX_0;
2012 mcp->buf_size = FCAL_MAP_SIZE;
2013 mcp->flags = MBX_DMA_IN;
2014 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2015 rval = qla2x00_mailbox_command(ha, mcp);
2016
2017 if (rval == QLA_SUCCESS) {
2018 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2019 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2020 mcp->mb[1], (unsigned)pmap[0]));
2021 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2022
2023 if (pos_map)
2024 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2025 }
2026 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2027
2028 if (rval != QLA_SUCCESS) {
2029 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2030 ha->host_no, rval));
2031 } else {
2032 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2033 }
2034
2035 return rval;
2036}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002037#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002038
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002039/*
2040 * qla2x00_get_link_status
2041 *
2042 * Input:
2043 * ha = adapter block pointer.
2044 * loop_id = device loop ID.
2045 * ret_buf = pointer to link status return buffer.
2046 *
2047 * Returns:
2048 * 0 = success.
2049 * BIT_0 = mem alloc error.
2050 * BIT_1 = mailbox error.
2051 */
2052int
2053qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002054 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002055{
2056 int rval;
2057 mbx_cmd_t mc;
2058 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002059 uint32_t *siter, *diter, dwords;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002060
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002061 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002062
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002063 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002064 mcp->mb[2] = MSW(stats_dma);
2065 mcp->mb[3] = LSW(stats_dma);
2066 mcp->mb[6] = MSW(MSD(stats_dma));
2067 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002068 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2069 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002070 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002071 mcp->mb[1] = loop_id;
2072 mcp->mb[4] = 0;
2073 mcp->mb[10] = 0;
2074 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2075 mcp->in_mb |= MBX_1;
2076 } else if (HAS_EXTENDED_IDS(ha)) {
2077 mcp->mb[1] = loop_id;
2078 mcp->mb[10] = 0;
2079 mcp->out_mb |= MBX_10|MBX_1;
2080 } else {
2081 mcp->mb[1] = loop_id << 8;
2082 mcp->out_mb |= MBX_1;
2083 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002084 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002085 mcp->flags = IOCTL_CMD;
2086 rval = qla2x00_mailbox_command(ha, mcp);
2087
2088 if (rval == QLA_SUCCESS) {
2089 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2090 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002091 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002092 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002093 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002094 /* Copy over data -- firmware data is LE. */
2095 dwords = offsetof(struct link_statistics, unused1) / 4;
2096 siter = diter = &stats->link_fail_cnt;
2097 while (dwords--)
2098 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002099 }
2100 } else {
2101 /* Failed. */
2102 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002103 ha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002104 }
2105
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002106 return rval;
2107}
2108
2109int
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002110qla24xx_get_isp_stats(scsi_qla_host_t *ha, struct link_statistics *stats,
2111 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002112{
2113 int rval;
2114 mbx_cmd_t mc;
2115 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002116 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002117
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002118 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002119
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002120 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002121 mcp->mb[2] = MSW(stats_dma);
2122 mcp->mb[3] = LSW(stats_dma);
2123 mcp->mb[6] = MSW(MSD(stats_dma));
2124 mcp->mb[7] = LSW(MSD(stats_dma));
2125 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2126 mcp->mb[9] = ha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002127 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002128 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 -07002129 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002130 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002131 mcp->flags = IOCTL_CMD;
2132 rval = qla2x00_mailbox_command(ha, mcp);
2133
2134 if (rval == QLA_SUCCESS) {
2135 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2136 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2137 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002138 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002139 } else {
2140 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002141 dwords = sizeof(struct link_statistics) / 4;
2142 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002143 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002144 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002145 }
2146 } else {
2147 /* Failed. */
2148 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2149 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002150 }
2151
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002152 return rval;
2153}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002154
2155int
2156qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2157{
2158 int rval;
2159 fc_port_t *fcport;
2160 unsigned long flags = 0;
2161
2162 struct abort_entry_24xx *abt;
2163 dma_addr_t abt_dma;
2164 uint32_t handle;
2165
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002166 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002167
2168 fcport = sp->fcport;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002169
2170 spin_lock_irqsave(&ha->hardware_lock, flags);
2171 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2172 if (ha->outstanding_cmds[handle] == sp)
2173 break;
2174 }
2175 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2176 if (handle == MAX_OUTSTANDING_COMMANDS) {
2177 /* Command not found. */
2178 return QLA_FUNCTION_FAILED;
2179 }
2180
2181 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2182 if (abt == NULL) {
2183 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2184 __func__, ha->host_no));
2185 return QLA_MEMORY_ALLOC_FAILED;
2186 }
2187 memset(abt, 0, sizeof(struct abort_entry_24xx));
2188
2189 abt->entry_type = ABORT_IOCB_TYPE;
2190 abt->entry_count = 1;
2191 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2192 abt->handle_to_abort = handle;
2193 abt->port_id[0] = fcport->d_id.b.al_pa;
2194 abt->port_id[1] = fcport->d_id.b.area;
2195 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002196 abt->vp_index = fcport->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002197 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2198 if (rval != QLA_SUCCESS) {
2199 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002200 __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002201 } else if (abt->entry_status != 0) {
2202 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2203 "-- error status (%x).\n", __func__, ha->host_no,
2204 abt->entry_status));
2205 rval = QLA_FUNCTION_FAILED;
2206 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2207 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2208 "-- completion status (%x).\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002209 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002210 rval = QLA_FUNCTION_FAILED;
2211 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002212 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002213 sp->flags |= SRB_ABORT_PENDING;
2214 }
2215
2216 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2217
2218 return rval;
2219}
2220
2221struct tsk_mgmt_cmd {
2222 union {
2223 struct tsk_mgmt_entry tsk;
2224 struct sts_entry_24xx sts;
2225 } p;
2226};
2227
Andrew Vasquez523ec772008-04-03 13:13:24 -07002228static int
2229__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2230 unsigned int l)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002231{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002232 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002233 struct tsk_mgmt_cmd *tsk;
2234 dma_addr_t tsk_dma;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002235 scsi_qla_host_t *ha, *pha;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002236
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002237 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002238
2239 ha = fcport->ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002240 pha = to_qla_parent(ha);
2241 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002242 if (tsk == NULL) {
2243 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2244 "IOCB.\n", __func__, ha->host_no));
2245 return QLA_MEMORY_ALLOC_FAILED;
2246 }
2247 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2248
2249 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2250 tsk->p.tsk.entry_count = 1;
2251 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002252 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002253 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002254 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2255 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2256 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002257 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002258 if (type == TCF_LUN_RESET) {
2259 int_to_scsilun(l, &tsk->p.tsk.lun);
2260 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2261 sizeof(tsk->p.tsk.lun));
2262 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002263
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002264 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2265 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002266 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
2267 "(%x).\n", __func__, ha->host_no, name, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002268 } else if (tsk->p.sts.entry_status != 0) {
2269 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2270 "-- error status (%x).\n", __func__, ha->host_no,
2271 tsk->p.sts.entry_status));
2272 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002273 } else if (tsk->p.sts.comp_status !=
2274 __constant_cpu_to_le16(CS_COMPLETE)) {
2275 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2276 "-- completion status (%x).\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002277 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002278 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002279 }
2280
2281 /* Issue marker IOCB. */
Andrew Vasquez523ec772008-04-03 13:13:24 -07002282 rval2 = qla2x00_marker(ha, fcport->loop_id, l,
2283 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2284 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002285 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Andrew Vasquez523ec772008-04-03 13:13:24 -07002286 "(%x).\n", __func__, ha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002287 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002288 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002289 }
2290
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002291 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002292
2293 return rval;
2294}
2295
Andrew Vasquez523ec772008-04-03 13:13:24 -07002296int
2297qla24xx_abort_target(struct fc_port *fcport, unsigned int l)
2298{
2299 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l);
2300}
2301
2302int
2303qla24xx_lun_reset(struct fc_port *fcport, unsigned int l)
2304{
2305 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l);
2306}
2307
Adrian Bunka824ebb2008-01-17 09:02:15 -08002308#if 0
2309
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002310int
2311qla2x00_system_error(scsi_qla_host_t *ha)
2312{
2313 int rval;
2314 mbx_cmd_t mc;
2315 mbx_cmd_t *mcp = &mc;
2316
Andrew Vasqueze4289242007-07-19 15:05:56 -07002317 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002318 return QLA_FUNCTION_FAILED;
2319
2320 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2321
2322 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2323 mcp->out_mb = MBX_0;
2324 mcp->in_mb = MBX_0;
2325 mcp->tov = 5;
2326 mcp->flags = 0;
2327 rval = qla2x00_mailbox_command(ha, mcp);
2328
2329 if (rval != QLA_SUCCESS) {
2330 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2331 ha->host_no, rval));
2332 } else {
2333 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2334 }
2335
2336 return rval;
2337}
2338
Adrian Bunka824ebb2008-01-17 09:02:15 -08002339#endif /* 0 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002340
2341/**
2342 * qla2x00_set_serdes_params() -
2343 * @ha: HA context
2344 *
2345 * Returns
2346 */
2347int
2348qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2349 uint16_t sw_em_2g, uint16_t sw_em_4g)
2350{
2351 int rval;
2352 mbx_cmd_t mc;
2353 mbx_cmd_t *mcp = &mc;
2354
2355 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2356
2357 mcp->mb[0] = MBC_SERDES_PARAMS;
2358 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002359 mcp->mb[2] = sw_em_1g | BIT_15;
2360 mcp->mb[3] = sw_em_2g | BIT_15;
2361 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002362 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2363 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002364 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002365 mcp->flags = 0;
2366 rval = qla2x00_mailbox_command(ha, mcp);
2367
2368 if (rval != QLA_SUCCESS) {
2369 /*EMPTY*/
2370 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2371 ha->host_no, rval, mcp->mb[0]));
2372 } else {
2373 /*EMPTY*/
2374 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2375 }
2376
2377 return rval;
2378}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002379
2380int
2381qla2x00_stop_firmware(scsi_qla_host_t *ha)
2382{
2383 int rval;
2384 mbx_cmd_t mc;
2385 mbx_cmd_t *mcp = &mc;
2386
Andrew Vasqueze4289242007-07-19 15:05:56 -07002387 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002388 return QLA_FUNCTION_FAILED;
2389
2390 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2391
2392 mcp->mb[0] = MBC_STOP_FIRMWARE;
2393 mcp->out_mb = MBX_0;
2394 mcp->in_mb = MBX_0;
2395 mcp->tov = 5;
2396 mcp->flags = 0;
2397 rval = qla2x00_mailbox_command(ha, mcp);
2398
2399 if (rval != QLA_SUCCESS) {
2400 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2401 ha->host_no, rval));
2402 } else {
2403 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2404 }
2405
2406 return rval;
2407}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002408
2409int
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002410qla2x00_enable_eft_trace(scsi_qla_host_t *ha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002411 uint16_t buffers)
2412{
2413 int rval;
2414 mbx_cmd_t mc;
2415 mbx_cmd_t *mcp = &mc;
2416
Andrew Vasqueze4289242007-07-19 15:05:56 -07002417 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002418 return QLA_FUNCTION_FAILED;
2419
2420 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2421
2422 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002423 mcp->mb[1] = TC_EFT_ENABLE;
2424 mcp->mb[2] = LSW(eft_dma);
2425 mcp->mb[3] = MSW(eft_dma);
2426 mcp->mb[4] = LSW(MSD(eft_dma));
2427 mcp->mb[5] = MSW(MSD(eft_dma));
2428 mcp->mb[6] = buffers;
2429 mcp->mb[7] = TC_AEN_DISABLE;
2430 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 -07002431 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002432 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002433 mcp->flags = 0;
2434 rval = qla2x00_mailbox_command(ha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002435 if (rval != QLA_SUCCESS) {
2436 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2437 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2438 } else {
2439 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2440 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002441
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002442 return rval;
2443}
2444
2445int
2446qla2x00_disable_eft_trace(scsi_qla_host_t *ha)
2447{
2448 int rval;
2449 mbx_cmd_t mc;
2450 mbx_cmd_t *mcp = &mc;
2451
2452 if (!IS_FWI2_CAPABLE(ha))
2453 return QLA_FUNCTION_FAILED;
2454
2455 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2456
2457 mcp->mb[0] = MBC_TRACE_CONTROL;
2458 mcp->mb[1] = TC_EFT_DISABLE;
2459 mcp->out_mb = MBX_1|MBX_0;
2460 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002461 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002462 mcp->flags = 0;
2463 rval = qla2x00_mailbox_command(ha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002464 if (rval != QLA_SUCCESS) {
2465 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2466 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2467 } else {
2468 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2469 }
2470
2471 return rval;
2472}
2473
Andrew Vasquez88729e52006-06-23 16:10:50 -07002474int
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002475qla2x00_enable_fce_trace(scsi_qla_host_t *ha, dma_addr_t fce_dma,
2476 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2477{
2478 int rval;
2479 mbx_cmd_t mc;
2480 mbx_cmd_t *mcp = &mc;
2481
2482 if (!IS_QLA25XX(ha))
2483 return QLA_FUNCTION_FAILED;
2484
2485 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2486
2487 mcp->mb[0] = MBC_TRACE_CONTROL;
2488 mcp->mb[1] = TC_FCE_ENABLE;
2489 mcp->mb[2] = LSW(fce_dma);
2490 mcp->mb[3] = MSW(fce_dma);
2491 mcp->mb[4] = LSW(MSD(fce_dma));
2492 mcp->mb[5] = MSW(MSD(fce_dma));
2493 mcp->mb[6] = buffers;
2494 mcp->mb[7] = TC_AEN_DISABLE;
2495 mcp->mb[8] = 0;
2496 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2497 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2498 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2499 MBX_1|MBX_0;
2500 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002501 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002502 mcp->flags = 0;
2503 rval = qla2x00_mailbox_command(ha, mcp);
2504 if (rval != QLA_SUCCESS) {
2505 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2506 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2507 } else {
2508 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2509
2510 if (mb)
2511 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2512 if (dwords)
2513 *dwords = mcp->mb[6];
2514 }
2515
2516 return rval;
2517}
2518
2519int
2520qla2x00_disable_fce_trace(scsi_qla_host_t *ha, uint64_t *wr, uint64_t *rd)
2521{
2522 int rval;
2523 mbx_cmd_t mc;
2524 mbx_cmd_t *mcp = &mc;
2525
2526 if (!IS_FWI2_CAPABLE(ha))
2527 return QLA_FUNCTION_FAILED;
2528
2529 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2530
2531 mcp->mb[0] = MBC_TRACE_CONTROL;
2532 mcp->mb[1] = TC_FCE_DISABLE;
2533 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2534 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2535 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2536 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002537 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002538 mcp->flags = 0;
2539 rval = qla2x00_mailbox_command(ha, mcp);
2540 if (rval != QLA_SUCCESS) {
2541 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2542 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2543 } else {
2544 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2545
2546 if (wr)
2547 *wr = (uint64_t) mcp->mb[5] << 48 |
2548 (uint64_t) mcp->mb[4] << 32 |
2549 (uint64_t) mcp->mb[3] << 16 |
2550 (uint64_t) mcp->mb[2];
2551 if (rd)
2552 *rd = (uint64_t) mcp->mb[9] << 48 |
2553 (uint64_t) mcp->mb[8] << 32 |
2554 (uint64_t) mcp->mb[7] << 16 |
2555 (uint64_t) mcp->mb[6];
2556 }
2557
2558 return rval;
2559}
2560
2561int
Andrew Vasquez88729e52006-06-23 16:10:50 -07002562qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2563 uint16_t off, uint16_t count)
2564{
2565 int rval;
2566 mbx_cmd_t mc;
2567 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002568
Andrew Vasqueze4289242007-07-19 15:05:56 -07002569 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002570 return QLA_FUNCTION_FAILED;
2571
2572 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2573
2574 mcp->mb[0] = MBC_READ_SFP;
2575 mcp->mb[1] = addr;
2576 mcp->mb[2] = MSW(sfp_dma);
2577 mcp->mb[3] = LSW(sfp_dma);
2578 mcp->mb[6] = MSW(MSD(sfp_dma));
2579 mcp->mb[7] = LSW(MSD(sfp_dma));
2580 mcp->mb[8] = count;
2581 mcp->mb[9] = off;
2582 mcp->mb[10] = 0;
2583 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2584 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002585 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002586 mcp->flags = 0;
2587 rval = qla2x00_mailbox_command(ha, mcp);
2588
2589 if (rval != QLA_SUCCESS) {
2590 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2591 ha->host_no, rval, mcp->mb[0]));
2592 } else {
2593 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2594 }
2595
2596 return rval;
2597}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002598
2599int
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002600qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2601 uint16_t port_speed, uint16_t *mb)
2602{
2603 int rval;
2604 mbx_cmd_t mc;
2605 mbx_cmd_t *mcp = &mc;
2606
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002607 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002608 return QLA_FUNCTION_FAILED;
2609
2610 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2611
2612 mcp->mb[0] = MBC_PORT_PARAMS;
2613 mcp->mb[1] = loop_id;
2614 mcp->mb[2] = BIT_0;
2615 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2616 mcp->mb[4] = mcp->mb[5] = 0;
2617 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2618 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002619 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002620 mcp->flags = 0;
2621 rval = qla2x00_mailbox_command(ha, mcp);
2622
2623 /* Return mailbox statuses. */
2624 if (mb != NULL) {
2625 mb[0] = mcp->mb[0];
2626 mb[1] = mcp->mb[1];
2627 mb[3] = mcp->mb[3];
2628 mb[4] = mcp->mb[4];
2629 mb[5] = mcp->mb[5];
2630 }
2631
2632 if (rval != QLA_SUCCESS) {
2633 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2634 ha->host_no, rval));
2635 } else {
2636 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2637 }
2638
2639 return rval;
2640}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002641
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002642void
2643qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2644 struct vp_rpt_id_entry_24xx *rptid_entry)
2645{
2646 uint8_t vp_idx;
2647 scsi_qla_host_t *vha;
2648
2649 if (rptid_entry->entry_status != 0)
2650 return;
2651 if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
2652 return;
2653
2654 if (rptid_entry->format == 0) {
2655 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2656 " number of VPs acquired %d\n", __func__, ha->host_no,
2657 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2658 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2659 rptid_entry->port_id[2], rptid_entry->port_id[1],
2660 rptid_entry->port_id[0]));
2661 } else if (rptid_entry->format == 1) {
2662 vp_idx = LSB(rptid_entry->vp_idx);
2663 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2664 "- status %d - "
2665 "with port id %02x%02x%02x\n",__func__,ha->host_no,
2666 vp_idx, MSB(rptid_entry->vp_idx),
2667 rptid_entry->port_id[2], rptid_entry->port_id[1],
2668 rptid_entry->port_id[0]));
2669 if (vp_idx == 0)
2670 return;
2671
2672 if (MSB(rptid_entry->vp_idx) == 1)
2673 return;
2674
2675 list_for_each_entry(vha, &ha->vp_list, vp_list)
2676 if (vp_idx == vha->vp_idx)
2677 break;
2678
2679 if (!vha)
2680 return;
2681
2682 vha->d_id.b.domain = rptid_entry->port_id[2];
2683 vha->d_id.b.area = rptid_entry->port_id[1];
2684 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2685
2686 /*
2687 * Cannot configure here as we are still sitting on the
2688 * response queue. Handle it in dpc context.
2689 */
2690 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2691 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2692
2693 wake_up_process(ha->dpc_thread);
2694 }
2695}
2696
2697/*
2698 * qla24xx_modify_vp_config
2699 * Change VP configuration for vha
2700 *
2701 * Input:
2702 * vha = adapter block pointer.
2703 *
2704 * Returns:
2705 * qla2xxx local function return status code.
2706 *
2707 * Context:
2708 * Kernel context.
2709 */
2710int
2711qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2712{
2713 int rval;
2714 struct vp_config_entry_24xx *vpmod;
2715 dma_addr_t vpmod_dma;
2716 scsi_qla_host_t *pha;
2717
2718 /* This can be called by the parent */
2719 pha = to_qla_parent(vha);
2720
2721 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2722 if (!vpmod) {
2723 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2724 "IOCB.\n", __func__, pha->host_no));
2725 return QLA_MEMORY_ALLOC_FAILED;
2726 }
2727
2728 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2729 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2730 vpmod->entry_count = 1;
2731 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2732 vpmod->vp_count = 1;
2733 vpmod->vp_index1 = vha->vp_idx;
2734 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2735 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2736 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2737 vpmod->entry_count = 1;
2738
2739 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2740 if (rval != QLA_SUCCESS) {
2741 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2742 "(%x).\n", __func__, pha->host_no, rval));
2743 } else if (vpmod->comp_status != 0) {
2744 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2745 "-- error status (%x).\n", __func__, pha->host_no,
2746 vpmod->comp_status));
2747 rval = QLA_FUNCTION_FAILED;
2748 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2749 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2750 "-- completion status (%x).\n", __func__, pha->host_no,
2751 le16_to_cpu(vpmod->comp_status)));
2752 rval = QLA_FUNCTION_FAILED;
2753 } else {
2754 /* EMPTY */
2755 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2756 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2757 }
2758 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2759
2760 return rval;
2761}
2762
2763/*
2764 * qla24xx_control_vp
2765 * Enable a virtual port for given host
2766 *
2767 * Input:
2768 * ha = adapter block pointer.
2769 * vhba = virtual adapter (unused)
2770 * index = index number for enabled VP
2771 *
2772 * Returns:
2773 * qla2xxx local function return status code.
2774 *
2775 * Context:
2776 * Kernel context.
2777 */
2778int
2779qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2780{
2781 int rval;
2782 int map, pos;
2783 struct vp_ctrl_entry_24xx *vce;
2784 dma_addr_t vce_dma;
2785 scsi_qla_host_t *ha = vha->parent;
2786 int vp_index = vha->vp_idx;
2787
2788 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2789 ha->host_no, vp_index));
2790
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002791 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002792 return QLA_PARAMETER_ERROR;
2793
2794 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2795 if (!vce) {
2796 DEBUG2_3(printk("%s(%ld): "
2797 "failed to allocate VP Control IOCB.\n", __func__,
2798 ha->host_no));
2799 return QLA_MEMORY_ALLOC_FAILED;
2800 }
2801 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2802
2803 vce->entry_type = VP_CTRL_IOCB_TYPE;
2804 vce->entry_count = 1;
2805 vce->command = cpu_to_le16(cmd);
2806 vce->vp_count = __constant_cpu_to_le16(1);
2807
2808 /* index map in firmware starts with 1; decrement index
2809 * this is ok as we never use index 0
2810 */
2811 map = (vp_index - 1) / 8;
2812 pos = (vp_index - 1) & 7;
2813 down(&ha->vport_sem);
2814 vce->vp_idx_map[map] |= 1 << pos;
2815 up(&ha->vport_sem);
2816
2817 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2818 if (rval != QLA_SUCCESS) {
2819 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2820 "(%x).\n", __func__, ha->host_no, rval));
2821 printk("%s(%ld): failed to issue VP control IOCB"
2822 "(%x).\n", __func__, ha->host_no, rval);
2823 } else if (vce->entry_status != 0) {
2824 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2825 "-- error status (%x).\n", __func__, ha->host_no,
2826 vce->entry_status));
2827 printk("%s(%ld): failed to complete IOCB "
2828 "-- error status (%x).\n", __func__, ha->host_no,
2829 vce->entry_status);
2830 rval = QLA_FUNCTION_FAILED;
2831 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2832 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2833 "-- completion status (%x).\n", __func__, ha->host_no,
2834 le16_to_cpu(vce->comp_status)));
2835 printk("%s(%ld): failed to complete IOCB "
2836 "-- completion status (%x).\n", __func__, ha->host_no,
2837 le16_to_cpu(vce->comp_status));
2838 rval = QLA_FUNCTION_FAILED;
2839 } else {
2840 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2841 }
2842
2843 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2844
2845 return rval;
2846}
2847
2848/*
2849 * qla2x00_send_change_request
2850 * Receive or disable RSCN request from fabric controller
2851 *
2852 * Input:
2853 * ha = adapter block pointer
2854 * format = registration format:
2855 * 0 - Reserved
2856 * 1 - Fabric detected registration
2857 * 2 - N_port detected registration
2858 * 3 - Full registration
2859 * FF - clear registration
2860 * vp_idx = Virtual port index
2861 *
2862 * Returns:
2863 * qla2x00 local function return status code.
2864 *
2865 * Context:
2866 * Kernel Context
2867 */
2868
2869int
2870qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2871 uint16_t vp_idx)
2872{
2873 int rval;
2874 mbx_cmd_t mc;
2875 mbx_cmd_t *mcp = &mc;
2876
2877 /*
2878 * This command is implicitly executed by firmware during login for the
2879 * physical hosts
2880 */
2881 if (vp_idx == 0)
2882 return QLA_FUNCTION_FAILED;
2883
2884 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2885 mcp->mb[1] = format;
2886 mcp->mb[9] = vp_idx;
2887 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2888 mcp->in_mb = MBX_0|MBX_1;
2889 mcp->tov = MBX_TOV_SECONDS;
2890 mcp->flags = 0;
2891 rval = qla2x00_mailbox_command(ha, mcp);
2892
2893 if (rval == QLA_SUCCESS) {
2894 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2895 rval = BIT_1;
2896 }
2897 } else
2898 rval = BIT_1;
2899
2900 return rval;
2901}
Andrew Vasquez338c9162007-09-20 14:07:33 -07002902
2903int
2904qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2905 uint32_t size)
2906{
2907 int rval;
2908 mbx_cmd_t mc;
2909 mbx_cmd_t *mcp = &mc;
2910
2911 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2912
2913 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2914 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2915 mcp->mb[8] = MSW(addr);
2916 mcp->out_mb = MBX_8|MBX_0;
2917 } else {
2918 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2919 mcp->out_mb = MBX_0;
2920 }
2921 mcp->mb[1] = LSW(addr);
2922 mcp->mb[2] = MSW(req_dma);
2923 mcp->mb[3] = LSW(req_dma);
2924 mcp->mb[6] = MSW(MSD(req_dma));
2925 mcp->mb[7] = LSW(MSD(req_dma));
2926 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2927 if (IS_FWI2_CAPABLE(ha)) {
2928 mcp->mb[4] = MSW(size);
2929 mcp->mb[5] = LSW(size);
2930 mcp->out_mb |= MBX_5|MBX_4;
2931 } else {
2932 mcp->mb[4] = LSW(size);
2933 mcp->out_mb |= MBX_4;
2934 }
2935
2936 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002937 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07002938 mcp->flags = 0;
2939 rval = qla2x00_mailbox_command(ha, mcp);
2940
2941 if (rval != QLA_SUCCESS) {
2942 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2943 ha->host_no, rval, mcp->mb[0]));
2944 } else {
2945 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2946 }
2947
2948 return rval;
2949}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002950
2951/* 84XX Support **************************************************************/
2952
2953struct cs84xx_mgmt_cmd {
2954 union {
2955 struct verify_chip_entry_84xx req;
2956 struct verify_chip_rsp_84xx rsp;
2957 } p;
2958};
2959
2960int
2961qla84xx_verify_chip(struct scsi_qla_host *ha, uint16_t *status)
2962{
2963 int rval, retry;
2964 struct cs84xx_mgmt_cmd *mn;
2965 dma_addr_t mn_dma;
2966 uint16_t options;
2967 unsigned long flags;
2968
2969 DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2970
2971 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
2972 if (mn == NULL) {
2973 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
2974 "IOCB.\n", __func__, ha->host_no));
2975 return QLA_MEMORY_ALLOC_FAILED;
2976 }
2977
2978 /* Force Update? */
2979 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
2980 /* Diagnostic firmware? */
2981 /* options |= MENLO_DIAG_FW; */
2982 /* We update the firmware with only one data sequence. */
2983 options |= VCO_END_OF_DATA;
2984
2985 retry = 0;
2986 do {
2987 memset(mn, 0, sizeof(*mn));
2988 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
2989 mn->p.req.entry_count = 1;
2990 mn->p.req.options = cpu_to_le16(options);
2991
2992 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
2993 ha->host_no));
2994 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
2995 sizeof(*mn)));
2996
2997 rval = qla2x00_issue_iocb_timeout(ha, mn, mn_dma, 0, 120);
2998 if (rval != QLA_SUCCESS) {
2999 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
3000 "IOCB (%x).\n", __func__, ha->host_no, rval));
3001 goto verify_done;
3002 }
3003
3004 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
3005 ha->host_no));
3006 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3007 sizeof(*mn)));
3008
3009 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3010 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3011 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3012 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
3013 ha->host_no, status[0], status[1]));
3014
3015 if (status[0] != CS_COMPLETE) {
3016 rval = QLA_FUNCTION_FAILED;
3017 if (!(options & VCO_DONT_UPDATE_FW)) {
3018 DEBUG2_16(printk("%s(%ld): Firmware update "
3019 "failed. Retrying without update "
3020 "firmware.\n", __func__, ha->host_no));
3021 options |= VCO_DONT_UPDATE_FW;
3022 options &= ~VCO_FORCE_UPDATE;
3023 retry = 1;
3024 }
3025 } else {
3026 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
3027 __func__, ha->host_no,
3028 le32_to_cpu(mn->p.rsp.fw_ver)));
3029
3030 /* NOTE: we only update OP firmware. */
3031 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3032 ha->cs84xx->op_fw_version =
3033 le32_to_cpu(mn->p.rsp.fw_ver);
3034 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3035 flags);
3036 }
3037 } while (retry);
3038
3039verify_done:
3040 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3041
3042 if (rval != QLA_SUCCESS) {
3043 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
3044 ha->host_no, rval));
3045 } else {
3046 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3047 }
3048
3049 return rval;
3050}