blob: 0fc165288f88785e30fbf4367db1378147cee119 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 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
11static void
12qla2x00_mbx_sem_timeout(unsigned long data)
13{
14 struct semaphore *sem_ptr = (struct semaphore *)data;
15
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070016 DEBUG11(printk("qla2x00_sem_timeout: entered.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18 if (sem_ptr != NULL) {
19 up(sem_ptr);
20 }
21
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070022 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n"));
Linus Torvalds1da177e2005-04-16 15:20:36 -070023}
24
25/*
26 * qla2x00_mailbox_command
27 * Issue mailbox command and waits for completion.
28 *
29 * Input:
30 * ha = adapter block pointer.
31 * mcp = driver internal mbx struct pointer.
32 *
33 * Output:
34 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
35 *
36 * Returns:
37 * 0 : QLA_SUCCESS = cmd performed success
38 * 1 : QLA_FUNCTION_FAILED (error encountered)
39 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
40 *
41 * Context:
42 * Kernel context.
43 */
44static int
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070045qla2x00_mailbox_command(scsi_qla_host_t *pvha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 int rval;
48 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070049 device_reg_t __iomem *reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 struct timer_list tmp_intr_timer;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070051 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070052 uint8_t io_lock_on;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 uint16_t command;
54 uint16_t *iptr;
55 uint16_t __iomem *optr;
56 uint32_t cnt;
57 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 unsigned long wait_time;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070059 scsi_qla_host_t *ha = to_qla_parent(pvha);
60
61 reg = ha->iobase;
62 io_lock_on = ha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 rval = QLA_SUCCESS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070065 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070067 DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070070 * Wait for active mailbox commands to finish by waiting at most tov
71 * seconds. This is to serialize actual issuing of mailbox cmds during
72 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 */
74 if (!abort_active) {
75 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
76 /* Timeout occurred. Return error. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070077 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070078 "Exiting.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 return QLA_FUNCTION_TIMEOUT;
80 }
81 }
82
83 ha->flags.mbox_busy = 1;
84 /* Save mailbox command for debug */
85 ha->mcp = mcp;
86
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070087 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070088 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 spin_lock_irqsave(&ha->hardware_lock, flags);
91
92 /* Load mailbox registers. */
Andrew Vasqueze4289242007-07-19 15:05:56 -070093 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070094 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
95 else
96 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98 iptr = mcp->mb;
99 command = mcp->mb[0];
100 mboxes = mcp->out_mb;
101
102 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
103 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700104 optr =
105 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if (mboxes & BIT_0)
107 WRT_REG_WORD(optr, *iptr);
108
109 mboxes >>= 1;
110 optr++;
111 iptr++;
112 }
113
114#if defined(QL_DEBUG_LEVEL_1)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700115 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
116 __func__, ha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
118 printk("\n");
119 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
120 printk("\n");
121 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
122 printk("\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700123 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 qla2x00_dump_regs(ha);
125#endif
126
127 /* Issue set host interrupt command to send cmd out. */
128 ha->flags.mbox_int = 0;
129 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
130
131 /* Unlock mbx registers and wait for interrupt */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700132 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700133 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 /* Wait for mbx cmd completion until timeout */
136
137 if (!abort_active && io_lock_on) {
138 /* sleep on completion semaphore */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700139 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700140 __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142 init_timer(&tmp_intr_timer);
143 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
144 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
145 tmp_intr_timer.function =
146 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
147
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700148 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700149 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 add_timer(&tmp_intr_timer);
151
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700152 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700153 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
156
Andrew Vasqueze4289242007-07-19 15:05:56 -0700157 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700158 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
159 else
160 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 spin_unlock_irqrestore(&ha->hardware_lock, flags);
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* Wait for either the timer to expire
164 * or the mbox completion interrupt
165 */
166 down(&ha->mbx_intr_sem);
167
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700168 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700169 ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
171
172 /* delete the timer */
173 del_timer(&tmp_intr_timer);
174 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700175 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700176 ha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Andrew Vasqueze4289242007-07-19 15:05:56 -0700178 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700179 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
180 else
181 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
185 while (!ha->flags.mbox_int) {
186 if (time_after(jiffies, wait_time))
187 break;
188
189 /* Check for pending interrupts. */
190 qla2x00_poll(ha);
191
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800192 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
193 !ha->flags.mbox_int)
194 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 } /* while */
196 }
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 /* Check whether we timed out */
199 if (ha->flags.mbox_int) {
200 uint16_t *iptr2;
201
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700202 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700203 ha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205 /* Got interrupt. Clear the flag. */
206 ha->flags.mbox_int = 0;
207 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
208
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400209 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 /* Load return mailbox registers. */
213 iptr2 = mcp->mb;
214 iptr = (uint16_t *)&ha->mailbox_out[0];
215 mboxes = mcp->in_mb;
216 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
217 if (mboxes & BIT_0)
218 *iptr2 = *iptr;
219
220 mboxes >>= 1;
221 iptr2++;
222 iptr++;
223 }
224 } else {
225
226#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
227 defined(QL_DEBUG_LEVEL_11)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700228 uint16_t mb0;
229 uint32_t ictrl;
230
Andrew Vasqueze4289242007-07-19 15:05:56 -0700231 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700232 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
233 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
234 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700235 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700236 ictrl = RD_REG_WORD(&reg->isp.ictrl);
237 }
238 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
239 __func__, ha->host_no, command);
240 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
241 ha->host_no, ictrl, jiffies);
242 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
243 ha->host_no, mb0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 qla2x00_dump_regs(ha);
245#endif
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 rval = QLA_FUNCTION_TIMEOUT;
248 }
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 ha->flags.mbox_busy = 0;
251
252 /* Clean up */
253 ha->mcp = NULL;
254
Andrew Vasqueza3a63d52007-10-19 15:59:14 -0700255 if (abort_active || !io_lock_on) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700256 DEBUG11(printk("%s(%ld): checking for additional resp "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700257 "interrupt.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 /* polling mode for non isp_abort commands. */
260 qla2x00_poll(ha);
261 }
262
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700263 if (rval == QLA_FUNCTION_TIMEOUT &&
264 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
266 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700267 DEBUG(printk("%s(%ld): timeout schedule "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700268 "isp_abort_needed.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700269 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700270 "isp_abort_needed.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 qla_printk(KERN_WARNING, ha,
272 "Mailbox command timeout occured. Scheduling ISP "
273 "abort.\n");
274 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100275 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700278 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700279 __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700280 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700281 "abort_isp\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 qla_printk(KERN_WARNING, ha,
283 "Mailbox command timeout occured. Issuing ISP "
284 "abort.\n");
285
286 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
287 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
288 if (qla2x00_abort_isp(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700289 /* Failed. retry later. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
291 }
292 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700293 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700294 ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700295 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700296 __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 }
298 }
299
300 /* Allow next mbx cmd to come in. */
301 if (!abort_active)
302 up(&ha->mbx_cmd_sem);
303
304 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700305 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
306 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700307 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700309 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 }
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return rval;
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315int
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800316qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
317 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 int rval;
320 mbx_cmd_t mc;
321 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
323 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
324
Andrew Vasqueze4289242007-07-19 15:05:56 -0700325 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800326 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
327 mcp->mb[8] = MSW(risc_addr);
328 mcp->out_mb = MBX_8|MBX_0;
329 } else {
330 mcp->mb[0] = MBC_LOAD_RISC_RAM;
331 mcp->out_mb = MBX_0;
332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 mcp->mb[1] = LSW(risc_addr);
334 mcp->mb[2] = MSW(req_dma);
335 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 mcp->mb[6] = MSW(MSD(req_dma));
337 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800338 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700339 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700340 mcp->mb[4] = MSW(risc_code_size);
341 mcp->mb[5] = LSW(risc_code_size);
342 mcp->out_mb |= MBX_5|MBX_4;
343 } else {
344 mcp->mb[4] = LSW(risc_code_size);
345 mcp->out_mb |= MBX_4;
346 }
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 mcp->in_mb = MBX_0;
349 mcp->tov = 30;
350 mcp->flags = 0;
351 rval = qla2x00_mailbox_command(ha, mcp);
352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700354 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
355 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
358 }
359
360 return rval;
361}
362
363/*
364 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700365 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 *
367 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700368 * ha = adapter block pointer.
369 * TARGET_QUEUE_LOCK must be released.
370 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 *
372 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700373 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 *
375 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700376 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 */
378int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700379qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
381 int rval;
382 mbx_cmd_t mc;
383 mbx_cmd_t *mcp = &mc;
384
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700385 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700388 mcp->out_mb = MBX_0;
389 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700390 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700391 mcp->mb[1] = MSW(risc_addr);
392 mcp->mb[2] = LSW(risc_addr);
393 mcp->mb[3] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700394 mcp->mb[4] = 0;
395 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700396 mcp->in_mb |= MBX_1;
397 } else {
398 mcp->mb[1] = LSW(risc_addr);
399 mcp->out_mb |= MBX_1;
400 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
401 mcp->mb[2] = 0;
402 mcp->out_mb |= MBX_2;
403 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 mcp->tov = 30;
407 mcp->flags = 0;
408 rval = qla2x00_mailbox_command(ha, mcp);
409
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700410 if (rval != QLA_SUCCESS) {
411 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
412 ha->host_no, rval, mcp->mb[0]));
413 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700414 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700415 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700416 __func__, ha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700417 } else {
418 DEBUG11(printk("%s(%ld): done.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700419 ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700420 }
421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 return rval;
424}
425
426/*
427 * qla2x00_get_fw_version
428 * Get firmware version.
429 *
430 * Input:
431 * ha: adapter state pointer.
432 * major: pointer for major number.
433 * minor: pointer for minor number.
434 * subminor: pointer for subminor number.
435 *
436 * Returns:
437 * qla2x00 local function return status code.
438 *
439 * Context:
440 * Kernel context.
441 */
442void
443qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
444 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
445{
446 int rval;
447 mbx_cmd_t mc;
448 mbx_cmd_t *mcp = &mc;
449
450 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
451
452 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
453 mcp->out_mb = MBX_0;
454 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
455 mcp->flags = 0;
456 mcp->tov = 30;
457 rval = qla2x00_mailbox_command(ha, mcp);
458
459 /* Return mailbox data. */
460 *major = mcp->mb[1];
461 *minor = mcp->mb[2];
462 *subminor = mcp->mb[3];
463 *attributes = mcp->mb[6];
464 if (IS_QLA2100(ha) || IS_QLA2200(ha))
465 *memory = 0x1FFFF; /* Defaults to 128KB. */
466 else
467 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
468
469 if (rval != QLA_SUCCESS) {
470 /*EMPTY*/
471 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
472 ha->host_no, rval));
473 } else {
474 /*EMPTY*/
475 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
476 }
477}
478
479/*
480 * qla2x00_get_fw_options
481 * Set firmware options.
482 *
483 * Input:
484 * ha = adapter block pointer.
485 * fwopt = pointer for firmware options.
486 *
487 * Returns:
488 * qla2x00 local function return status code.
489 *
490 * Context:
491 * Kernel context.
492 */
493int
494qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
495{
496 int rval;
497 mbx_cmd_t mc;
498 mbx_cmd_t *mcp = &mc;
499
500 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
501
502 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
503 mcp->out_mb = MBX_0;
504 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
505 mcp->tov = 30;
506 mcp->flags = 0;
507 rval = qla2x00_mailbox_command(ha, mcp);
508
509 if (rval != QLA_SUCCESS) {
510 /*EMPTY*/
511 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
512 ha->host_no, rval));
513 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700514 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 fwopts[1] = mcp->mb[1];
516 fwopts[2] = mcp->mb[2];
517 fwopts[3] = mcp->mb[3];
518
519 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
520 }
521
522 return rval;
523}
524
525
526/*
527 * qla2x00_set_fw_options
528 * Set firmware options.
529 *
530 * Input:
531 * ha = adapter block pointer.
532 * fwopt = pointer for firmware options.
533 *
534 * Returns:
535 * qla2x00 local function return status code.
536 *
537 * Context:
538 * Kernel context.
539 */
540int
541qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
542{
543 int rval;
544 mbx_cmd_t mc;
545 mbx_cmd_t *mcp = &mc;
546
547 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
548
549 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
550 mcp->mb[1] = fwopts[1];
551 mcp->mb[2] = fwopts[2];
552 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700553 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700555 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700556 mcp->in_mb |= MBX_1;
557 } else {
558 mcp->mb[10] = fwopts[10];
559 mcp->mb[11] = fwopts[11];
560 mcp->mb[12] = 0; /* Undocumented, but used */
561 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
562 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 mcp->tov = 30;
564 mcp->flags = 0;
565 rval = qla2x00_mailbox_command(ha, mcp);
566
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700567 fwopts[0] = mcp->mb[0];
568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (rval != QLA_SUCCESS) {
570 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700571 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
572 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 } else {
574 /*EMPTY*/
575 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
576 }
577
578 return rval;
579}
580
581/*
582 * qla2x00_mbx_reg_test
583 * Mailbox register wrap test.
584 *
585 * Input:
586 * ha = adapter block pointer.
587 * TARGET_QUEUE_LOCK must be released.
588 * ADAPTER_STATE_LOCK must be released.
589 *
590 * Returns:
591 * qla2x00 local function return status code.
592 *
593 * Context:
594 * Kernel context.
595 */
596int
597qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
598{
599 int rval;
600 mbx_cmd_t mc;
601 mbx_cmd_t *mcp = &mc;
602
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700603 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
606 mcp->mb[1] = 0xAAAA;
607 mcp->mb[2] = 0x5555;
608 mcp->mb[3] = 0xAA55;
609 mcp->mb[4] = 0x55AA;
610 mcp->mb[5] = 0xA5A5;
611 mcp->mb[6] = 0x5A5A;
612 mcp->mb[7] = 0x2525;
613 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
614 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
615 mcp->tov = 30;
616 mcp->flags = 0;
617 rval = qla2x00_mailbox_command(ha, mcp);
618
619 if (rval == QLA_SUCCESS) {
620 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
621 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
622 rval = QLA_FUNCTION_FAILED;
623 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
624 mcp->mb[7] != 0x2525)
625 rval = QLA_FUNCTION_FAILED;
626 }
627
628 if (rval != QLA_SUCCESS) {
629 /*EMPTY*/
630 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700631 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 } else {
633 /*EMPTY*/
634 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700635 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 }
637
638 return rval;
639}
640
641/*
642 * qla2x00_verify_checksum
643 * Verify firmware checksum.
644 *
645 * Input:
646 * ha = adapter block pointer.
647 * TARGET_QUEUE_LOCK must be released.
648 * ADAPTER_STATE_LOCK must be released.
649 *
650 * Returns:
651 * qla2x00 local function return status code.
652 *
653 * Context:
654 * Kernel context.
655 */
656int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700657qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
659 int rval;
660 mbx_cmd_t mc;
661 mbx_cmd_t *mcp = &mc;
662
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700663 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700666 mcp->out_mb = MBX_0;
667 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700668 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700669 mcp->mb[1] = MSW(risc_addr);
670 mcp->mb[2] = LSW(risc_addr);
671 mcp->out_mb |= MBX_2|MBX_1;
672 mcp->in_mb |= MBX_2|MBX_1;
673 } else {
674 mcp->mb[1] = LSW(risc_addr);
675 mcp->out_mb |= MBX_1;
676 mcp->in_mb |= MBX_1;
677 }
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 mcp->tov = 30;
680 mcp->flags = 0;
681 rval = qla2x00_mailbox_command(ha, mcp);
682
683 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700684 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
Andrew Vasqueze4289242007-07-19 15:05:56 -0700685 ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
686 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700688 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690
691 return rval;
692}
693
694/*
695 * qla2x00_issue_iocb
696 * Issue IOCB using mailbox command
697 *
698 * Input:
699 * ha = adapter state pointer.
700 * buffer = buffer pointer.
701 * phys_addr = physical address of buffer.
702 * size = size of buffer.
703 * TARGET_QUEUE_LOCK must be released.
704 * ADAPTER_STATE_LOCK must be released.
705 *
706 * Returns:
707 * qla2x00 local function return status code.
708 *
709 * Context:
710 * Kernel context.
711 */
712int
713qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
714 size_t size)
715{
716 int rval;
717 mbx_cmd_t mc;
718 mbx_cmd_t *mcp = &mc;
719
720 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
721 mcp->mb[1] = 0;
722 mcp->mb[2] = MSW(phys_addr);
723 mcp->mb[3] = LSW(phys_addr);
724 mcp->mb[6] = MSW(MSD(phys_addr));
725 mcp->mb[7] = LSW(MSD(phys_addr));
726 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
727 mcp->in_mb = MBX_2|MBX_0;
728 mcp->tov = 30;
729 mcp->flags = 0;
730 rval = qla2x00_mailbox_command(ha, mcp);
731
732 if (rval != QLA_SUCCESS) {
733 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700734 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700735 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700736 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700737 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700739 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
740
741 /* Mask reserved bits. */
742 sts_entry->entry_status &=
Andrew Vasqueze4289242007-07-19 15:05:56 -0700743 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 }
745
746 return rval;
747}
748
749/*
750 * qla2x00_abort_command
751 * Abort command aborts a specified IOCB.
752 *
753 * Input:
754 * ha = adapter block pointer.
755 * sp = SB structure pointer.
756 *
757 * Returns:
758 * qla2x00 local function return status code.
759 *
760 * Context:
761 * Kernel context.
762 */
763int
764qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
765{
766 unsigned long flags = 0;
767 fc_port_t *fcport;
768 int rval;
769 uint32_t handle;
770 mbx_cmd_t mc;
771 mbx_cmd_t *mcp = &mc;
772
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700773 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
bdf79622005-04-17 15:06:53 -0500775 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 spin_lock_irqsave(&ha->hardware_lock, flags);
778 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
779 if (ha->outstanding_cmds[handle] == sp)
780 break;
781 }
782 spin_unlock_irqrestore(&ha->hardware_lock, flags);
783
784 if (handle == MAX_OUTSTANDING_COMMANDS) {
785 /* command not found */
786 return QLA_FUNCTION_FAILED;
787 }
788
789 mcp->mb[0] = MBC_ABORT_COMMAND;
790 if (HAS_EXTENDED_IDS(ha))
791 mcp->mb[1] = fcport->loop_id;
792 else
793 mcp->mb[1] = fcport->loop_id << 8;
794 mcp->mb[2] = (uint16_t)handle;
795 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500796 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
798 mcp->in_mb = MBX_0;
799 mcp->tov = 30;
800 mcp->flags = 0;
801 rval = qla2x00_mailbox_command(ha, mcp);
802
803 if (rval != QLA_SUCCESS) {
804 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700805 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 } else {
807 sp->flags |= SRB_ABORT_PENDING;
808 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700809 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811
812 return rval;
813}
814
815#if USE_ABORT_TGT
816/*
817 * qla2x00_abort_target
818 * Issue abort target mailbox command.
819 *
820 * Input:
821 * ha = adapter block pointer.
822 *
823 * Returns:
824 * qla2x00 local function return status code.
825 *
826 * Context:
827 * Kernel context.
828 */
829int
830qla2x00_abort_target(fc_port_t *fcport)
831{
832 int rval;
833 mbx_cmd_t mc;
834 mbx_cmd_t *mcp = &mc;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700835 scsi_qla_host_t *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700837 if (fcport == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700840 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700841
842 ha = fcport->ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 mcp->mb[0] = MBC_ABORT_TARGET;
844 mcp->out_mb = MBX_2|MBX_1|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700845 if (HAS_EXTENDED_IDS(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 mcp->mb[1] = fcport->loop_id;
847 mcp->mb[10] = 0;
848 mcp->out_mb |= MBX_10;
849 } else {
850 mcp->mb[1] = fcport->loop_id << 8;
851 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700852 mcp->mb[2] = ha->loop_reset_delay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 mcp->in_mb = MBX_0;
855 mcp->tov = 30;
856 mcp->flags = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700857 rval = qla2x00_mailbox_command(ha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 /* Issue marker command. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700860 ha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861
862 if (rval != QLA_SUCCESS) {
863 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700864 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 } else {
866 /*EMPTY*/
867 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700868 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870
871 return rval;
872}
873#endif
874
875/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 * qla2x00_get_adapter_id
877 * Get adapter ID and topology.
878 *
879 * Input:
880 * ha = adapter block pointer.
881 * id = pointer for loop ID.
882 * al_pa = pointer for AL_PA.
883 * area = pointer for area.
884 * domain = pointer for domain.
885 * top = pointer for topology.
886 * TARGET_QUEUE_LOCK must be released.
887 * ADAPTER_STATE_LOCK must be released.
888 *
889 * Returns:
890 * qla2x00 local function return status code.
891 *
892 * Context:
893 * Kernel context.
894 */
895int
896qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700897 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 int rval;
900 mbx_cmd_t mc;
901 mbx_cmd_t *mcp = &mc;
902
903 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700904 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
906 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700907 mcp->mb[9] = ha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800908 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700909 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 mcp->tov = 30;
911 mcp->flags = 0;
912 rval = qla2x00_mailbox_command(ha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800913 if (mcp->mb[0] == MBS_COMMAND_ERROR)
914 rval = QLA_COMMAND_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Return data. */
917 *id = mcp->mb[1];
918 *al_pa = LSB(mcp->mb[2]);
919 *area = MSB(mcp->mb[2]);
920 *domain = LSB(mcp->mb[3]);
921 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700922 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 if (rval != QLA_SUCCESS) {
925 /*EMPTY*/
926 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700927 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 } else {
929 /*EMPTY*/
930 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700931 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933
934 return rval;
935}
936
937/*
938 * qla2x00_get_retry_cnt
939 * Get current firmware login retry count and delay.
940 *
941 * Input:
942 * ha = adapter block pointer.
943 * retry_cnt = pointer to login retry count.
944 * tov = pointer to login timeout value.
945 *
946 * Returns:
947 * qla2x00 local function return status code.
948 *
949 * Context:
950 * Kernel context.
951 */
952int
953qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
954 uint16_t *r_a_tov)
955{
956 int rval;
957 uint16_t ratov;
958 mbx_cmd_t mc;
959 mbx_cmd_t *mcp = &mc;
960
961 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700962 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
964 mcp->mb[0] = MBC_GET_RETRY_COUNT;
965 mcp->out_mb = MBX_0;
966 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
967 mcp->tov = 30;
968 mcp->flags = 0;
969 rval = qla2x00_mailbox_command(ha, mcp);
970
971 if (rval != QLA_SUCCESS) {
972 /*EMPTY*/
973 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700974 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 } else {
976 /* Convert returned data and check our values. */
977 *r_a_tov = mcp->mb[3] / 2;
978 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
979 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
980 /* Update to the larger values */
981 *retry_cnt = (uint8_t)mcp->mb[1];
982 *tov = ratov;
983 }
984
985 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700986 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 }
988
989 return rval;
990}
991
992/*
993 * qla2x00_init_firmware
994 * Initialize adapter firmware.
995 *
996 * Input:
997 * ha = adapter block pointer.
998 * dptr = Initialization control block pointer.
999 * size = size of initialization control block.
1000 * TARGET_QUEUE_LOCK must be released.
1001 * ADAPTER_STATE_LOCK must be released.
1002 *
1003 * Returns:
1004 * qla2x00 local function return status code.
1005 *
1006 * Context:
1007 * Kernel context.
1008 */
1009int
1010qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1011{
1012 int rval;
1013 mbx_cmd_t mc;
1014 mbx_cmd_t *mcp = &mc;
1015
1016 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001017 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001019 if (ha->flags.npiv_supported)
1020 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1021 else
1022 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 mcp->mb[2] = MSW(ha->init_cb_dma);
1025 mcp->mb[3] = LSW(ha->init_cb_dma);
1026 mcp->mb[4] = 0;
1027 mcp->mb[5] = 0;
1028 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1029 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1030 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1031 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1032 mcp->buf_size = size;
1033 mcp->flags = MBX_DMA_OUT;
1034 mcp->tov = 30;
1035 rval = qla2x00_mailbox_command(ha, mcp);
1036
1037 if (rval != QLA_SUCCESS) {
1038 /*EMPTY*/
1039 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1040 "mb0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001041 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 } else {
1043 /*EMPTY*/
1044 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001045 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047
1048 return rval;
1049}
1050
1051/*
1052 * qla2x00_get_port_database
1053 * Issue normal/enhanced get port database mailbox command
1054 * and copy device name as necessary.
1055 *
1056 * Input:
1057 * ha = adapter state pointer.
1058 * dev = structure pointer.
1059 * opt = enhanced cmd option byte.
1060 *
1061 * Returns:
1062 * qla2x00 local function return status code.
1063 *
1064 * Context:
1065 * Kernel context.
1066 */
1067int
1068qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1069{
1070 int rval;
1071 mbx_cmd_t mc;
1072 mbx_cmd_t *mcp = &mc;
1073 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001074 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 dma_addr_t pd_dma;
1076
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001077 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001079 pd24 = NULL;
1080 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001082 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1083 "structure.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 return QLA_MEMORY_ALLOC_FAILED;
1085 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001086 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001088 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001089 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 mcp->mb[2] = MSW(pd_dma);
1092 mcp->mb[3] = LSW(pd_dma);
1093 mcp->mb[6] = MSW(MSD(pd_dma));
1094 mcp->mb[7] = LSW(MSD(pd_dma));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001095 mcp->mb[9] = ha->vp_idx;
1096 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001098 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001099 mcp->mb[1] = fcport->loop_id;
1100 mcp->mb[10] = opt;
1101 mcp->out_mb |= MBX_10|MBX_1;
1102 mcp->in_mb |= MBX_1;
1103 } else if (HAS_EXTENDED_IDS(ha)) {
1104 mcp->mb[1] = fcport->loop_id;
1105 mcp->mb[10] = opt;
1106 mcp->out_mb |= MBX_10|MBX_1;
1107 } else {
1108 mcp->mb[1] = fcport->loop_id << 8 | opt;
1109 mcp->out_mb |= MBX_1;
1110 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001111 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1112 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 mcp->flags = MBX_DMA_IN;
1114 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1115 rval = qla2x00_mailbox_command(ha, mcp);
1116 if (rval != QLA_SUCCESS)
1117 goto gpd_error_out;
1118
Andrew Vasqueze4289242007-07-19 15:05:56 -07001119 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001120 pd24 = (struct port_database_24xx *) pd;
1121
1122 /* Check for logged in state. */
1123 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1124 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1125 DEBUG2(printk("%s(%ld): Unable to verify "
1126 "login-state (%x/%x) for loop_id %x\n",
1127 __func__, ha->host_no,
1128 pd24->current_login_state,
1129 pd24->last_login_state, fcport->loop_id));
1130 rval = QLA_FUNCTION_FAILED;
1131 goto gpd_error_out;
1132 }
1133
1134 /* Names are little-endian. */
1135 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1136 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1137
1138 /* Get port_id of device. */
1139 fcport->d_id.b.domain = pd24->port_id[0];
1140 fcport->d_id.b.area = pd24->port_id[1];
1141 fcport->d_id.b.al_pa = pd24->port_id[2];
1142 fcport->d_id.b.rsvd_1 = 0;
1143
1144 /* If not target must be initiator or unknown type. */
1145 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1146 fcport->port_type = FCT_INITIATOR;
1147 else
1148 fcport->port_type = FCT_TARGET;
1149 } else {
1150 /* Check for logged in state. */
1151 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1152 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1153 rval = QLA_FUNCTION_FAILED;
1154 goto gpd_error_out;
1155 }
1156
1157 /* Names are little-endian. */
1158 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1159 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1160
1161 /* Get port_id of device. */
1162 fcport->d_id.b.domain = pd->port_id[0];
1163 fcport->d_id.b.area = pd->port_id[3];
1164 fcport->d_id.b.al_pa = pd->port_id[2];
1165 fcport->d_id.b.rsvd_1 = 0;
1166
1167 /* Check for device require authentication. */
1168 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1169 (fcport->flags &= ~FCF_AUTH_REQ);
1170
1171 /* If not target must be initiator or unknown type. */
1172 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1173 fcport->port_type = FCT_INITIATOR;
1174 else
1175 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001176
1177 /* Passback COS information. */
1178 fcport->supported_classes = (pd->options & BIT_4) ?
1179 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 }
1181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182gpd_error_out:
1183 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1184
1185 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001186 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1187 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001189 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 }
1191
1192 return rval;
1193}
1194
1195/*
1196 * qla2x00_get_firmware_state
1197 * Get adapter firmware state.
1198 *
1199 * Input:
1200 * ha = adapter block pointer.
1201 * dptr = pointer for firmware state.
1202 * TARGET_QUEUE_LOCK must be released.
1203 * ADAPTER_STATE_LOCK must be released.
1204 *
1205 * Returns:
1206 * qla2x00 local function return status code.
1207 *
1208 * Context:
1209 * Kernel context.
1210 */
1211int
1212qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1213{
1214 int rval;
1215 mbx_cmd_t mc;
1216 mbx_cmd_t *mcp = &mc;
1217
1218 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001219 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220
1221 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1222 mcp->out_mb = MBX_0;
1223 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1224 mcp->tov = 30;
1225 mcp->flags = 0;
1226 rval = qla2x00_mailbox_command(ha, mcp);
1227
1228 /* Return firmware state. */
1229 *dptr = mcp->mb[1];
1230
1231 if (rval != QLA_SUCCESS) {
1232 /*EMPTY*/
1233 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001234 "failed=%x.\n", ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 } else {
1236 /*EMPTY*/
1237 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001238 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 }
1240
1241 return rval;
1242}
1243
1244/*
1245 * qla2x00_get_port_name
1246 * Issue get port name mailbox command.
1247 * Returned name is in big endian format.
1248 *
1249 * Input:
1250 * ha = adapter block pointer.
1251 * loop_id = loop ID of device.
1252 * name = pointer for name.
1253 * TARGET_QUEUE_LOCK must be released.
1254 * ADAPTER_STATE_LOCK must be released.
1255 *
1256 * Returns:
1257 * qla2x00 local function return status code.
1258 *
1259 * Context:
1260 * Kernel context.
1261 */
1262int
1263qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1264 uint8_t opt)
1265{
1266 int rval;
1267 mbx_cmd_t mc;
1268 mbx_cmd_t *mcp = &mc;
1269
1270 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001271 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 mcp->mb[0] = MBC_GET_PORT_NAME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001274 mcp->mb[9] = ha->vp_idx;
1275 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 if (HAS_EXTENDED_IDS(ha)) {
1277 mcp->mb[1] = loop_id;
1278 mcp->mb[10] = opt;
1279 mcp->out_mb |= MBX_10;
1280 } else {
1281 mcp->mb[1] = loop_id << 8 | opt;
1282 }
1283
1284 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1285 mcp->tov = 30;
1286 mcp->flags = 0;
1287 rval = qla2x00_mailbox_command(ha, mcp);
1288
1289 if (rval != QLA_SUCCESS) {
1290 /*EMPTY*/
1291 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001292 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 } else {
1294 if (name != NULL) {
1295 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001296 name[0] = MSB(mcp->mb[2]);
1297 name[1] = LSB(mcp->mb[2]);
1298 name[2] = MSB(mcp->mb[3]);
1299 name[3] = LSB(mcp->mb[3]);
1300 name[4] = MSB(mcp->mb[6]);
1301 name[5] = LSB(mcp->mb[6]);
1302 name[6] = MSB(mcp->mb[7]);
1303 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 }
1305
1306 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001307 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 }
1309
1310 return rval;
1311}
1312
1313/*
1314 * qla2x00_lip_reset
1315 * Issue LIP reset mailbox command.
1316 *
1317 * Input:
1318 * ha = adapter block pointer.
1319 * TARGET_QUEUE_LOCK must be released.
1320 * ADAPTER_STATE_LOCK must be released.
1321 *
1322 * Returns:
1323 * qla2x00 local function return status code.
1324 *
1325 * Context:
1326 * Kernel context.
1327 */
1328int
1329qla2x00_lip_reset(scsi_qla_host_t *ha)
1330{
1331 int rval;
1332 mbx_cmd_t mc;
1333 mbx_cmd_t *mcp = &mc;
1334
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001335 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336
Andrew Vasqueze4289242007-07-19 15:05:56 -07001337 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001338 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001339 mcp->mb[1] = BIT_6;
1340 mcp->mb[2] = 0;
1341 mcp->mb[3] = ha->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001342 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001344 mcp->mb[0] = MBC_LIP_RESET;
1345 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1346 if (HAS_EXTENDED_IDS(ha)) {
1347 mcp->mb[1] = 0x00ff;
1348 mcp->mb[10] = 0;
1349 mcp->out_mb |= MBX_10;
1350 } else {
1351 mcp->mb[1] = 0xff00;
1352 }
1353 mcp->mb[2] = ha->loop_reset_delay;
1354 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 mcp->in_mb = MBX_0;
1357 mcp->tov = 30;
1358 mcp->flags = 0;
1359 rval = qla2x00_mailbox_command(ha, mcp);
1360
1361 if (rval != QLA_SUCCESS) {
1362 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001363 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001364 __func__, ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 } else {
1366 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001367 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
1369
1370 return rval;
1371}
1372
1373/*
1374 * qla2x00_send_sns
1375 * Send SNS command.
1376 *
1377 * Input:
1378 * ha = adapter block pointer.
1379 * sns = pointer for command.
1380 * cmd_size = command size.
1381 * buf_size = response/command size.
1382 * TARGET_QUEUE_LOCK must be released.
1383 * ADAPTER_STATE_LOCK must be released.
1384 *
1385 * Returns:
1386 * qla2x00 local function return status code.
1387 *
1388 * Context:
1389 * Kernel context.
1390 */
1391int
1392qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1393 uint16_t cmd_size, size_t buf_size)
1394{
1395 int rval;
1396 mbx_cmd_t mc;
1397 mbx_cmd_t *mcp = &mc;
1398
1399 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001400 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
1402 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001403 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1406 mcp->mb[1] = cmd_size;
1407 mcp->mb[2] = MSW(sns_phys_address);
1408 mcp->mb[3] = LSW(sns_phys_address);
1409 mcp->mb[6] = MSW(MSD(sns_phys_address));
1410 mcp->mb[7] = LSW(MSD(sns_phys_address));
1411 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1412 mcp->in_mb = MBX_0|MBX_1;
1413 mcp->buf_size = buf_size;
1414 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1415 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1416 rval = qla2x00_mailbox_command(ha, mcp);
1417
1418 if (rval != QLA_SUCCESS) {
1419 /*EMPTY*/
1420 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001421 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001423 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 } else {
1425 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001426 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428
1429 return rval;
1430}
1431
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001432int
1433qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1434 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1435{
1436 int rval;
1437
1438 struct logio_entry_24xx *lg;
1439 dma_addr_t lg_dma;
1440 uint32_t iop[2];
1441
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001442 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001443
1444 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1445 if (lg == NULL) {
1446 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1447 __func__, ha->host_no));
1448 return QLA_MEMORY_ALLOC_FAILED;
1449 }
1450 memset(lg, 0, sizeof(struct logio_entry_24xx));
1451
1452 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1453 lg->entry_count = 1;
1454 lg->nport_handle = cpu_to_le16(loop_id);
1455 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1456 if (opt & BIT_0)
1457 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001458 if (opt & BIT_1)
1459 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001460 lg->port_id[0] = al_pa;
1461 lg->port_id[1] = area;
1462 lg->port_id[2] = domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001463 lg->vp_index = cpu_to_le16(ha->vp_idx);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001464 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1465 if (rval != QLA_SUCCESS) {
1466 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001467 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001468 } else if (lg->entry_status != 0) {
1469 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1470 "-- error status (%x).\n", __func__, ha->host_no,
1471 lg->entry_status));
1472 rval = QLA_FUNCTION_FAILED;
1473 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1474 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1475 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1476
1477 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1478 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1479 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1480 iop[1]));
1481
1482 switch (iop[0]) {
1483 case LSC_SCODE_PORTID_USED:
1484 mb[0] = MBS_PORT_ID_USED;
1485 mb[1] = LSW(iop[1]);
1486 break;
1487 case LSC_SCODE_NPORT_USED:
1488 mb[0] = MBS_LOOP_ID_USED;
1489 break;
1490 case LSC_SCODE_NOLINK:
1491 case LSC_SCODE_NOIOCB:
1492 case LSC_SCODE_NOXCB:
1493 case LSC_SCODE_CMD_FAILED:
1494 case LSC_SCODE_NOFABRIC:
1495 case LSC_SCODE_FW_NOT_READY:
1496 case LSC_SCODE_NOT_LOGGED_IN:
1497 case LSC_SCODE_NOPCB:
1498 case LSC_SCODE_ELS_REJECT:
1499 case LSC_SCODE_CMD_PARAM_ERR:
1500 case LSC_SCODE_NONPORT:
1501 case LSC_SCODE_LOGGED_IN:
1502 case LSC_SCODE_NOFLOGI_ACC:
1503 default:
1504 mb[0] = MBS_COMMAND_ERROR;
1505 break;
1506 }
1507 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001508 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001509
1510 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1511
1512 mb[0] = MBS_COMMAND_COMPLETE;
1513 mb[1] = 0;
1514 if (iop[0] & BIT_4) {
1515 if (iop[0] & BIT_8)
1516 mb[1] |= BIT_1;
1517 } else
1518 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001519
1520 /* Passback COS information. */
1521 mb[10] = 0;
1522 if (lg->io_parameter[7] || lg->io_parameter[8])
1523 mb[10] |= BIT_0; /* Class 2. */
1524 if (lg->io_parameter[9] || lg->io_parameter[10])
1525 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001526 }
1527
1528 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1529
1530 return rval;
1531}
1532
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533/*
1534 * qla2x00_login_fabric
1535 * Issue login fabric port mailbox command.
1536 *
1537 * Input:
1538 * ha = adapter block pointer.
1539 * loop_id = device loop ID.
1540 * domain = device domain.
1541 * area = device area.
1542 * al_pa = device AL_PA.
1543 * status = pointer for return status.
1544 * opt = command options.
1545 * TARGET_QUEUE_LOCK must be released.
1546 * ADAPTER_STATE_LOCK must be released.
1547 *
1548 * Returns:
1549 * qla2x00 local function return status code.
1550 *
1551 * Context:
1552 * Kernel context.
1553 */
1554int
1555qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1556 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1557{
1558 int rval;
1559 mbx_cmd_t mc;
1560 mbx_cmd_t *mcp = &mc;
1561
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001562 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1565 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1566 if (HAS_EXTENDED_IDS(ha)) {
1567 mcp->mb[1] = loop_id;
1568 mcp->mb[10] = opt;
1569 mcp->out_mb |= MBX_10;
1570 } else {
1571 mcp->mb[1] = (loop_id << 8) | opt;
1572 }
1573 mcp->mb[2] = domain;
1574 mcp->mb[3] = area << 8 | al_pa;
1575
1576 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1577 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1578 mcp->flags = 0;
1579 rval = qla2x00_mailbox_command(ha, mcp);
1580
1581 /* Return mailbox statuses. */
1582 if (mb != NULL) {
1583 mb[0] = mcp->mb[0];
1584 mb[1] = mcp->mb[1];
1585 mb[2] = mcp->mb[2];
1586 mb[6] = mcp->mb[6];
1587 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001588 /* COS retrieved from Get-Port-Database mailbox command. */
1589 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
1591
1592 if (rval != QLA_SUCCESS) {
1593 /* RLU tmp code: need to change main mailbox_command function to
1594 * return ok even when the mailbox completion value is not
1595 * SUCCESS. The caller needs to be responsible to interpret
1596 * the return values of this mailbox command if we're not
1597 * to change too much of the existing code.
1598 */
1599 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1600 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1601 mcp->mb[0] == 0x4006)
1602 rval = QLA_SUCCESS;
1603
1604 /*EMPTY*/
1605 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1606 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001607 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 } else {
1609 /*EMPTY*/
1610 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001611 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 }
1613
1614 return rval;
1615}
1616
1617/*
1618 * qla2x00_login_local_device
1619 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001620 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 * Input:
1622 * ha = adapter block pointer.
1623 * loop_id = device loop ID.
1624 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001625 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 * Returns:
1627 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001628 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 * Context:
1630 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001631 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 */
1633int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001634qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 uint16_t *mb_ret, uint8_t opt)
1636{
1637 int rval;
1638 mbx_cmd_t mc;
1639 mbx_cmd_t *mcp = &mc;
1640
Andrew Vasqueze4289242007-07-19 15:05:56 -07001641 if (IS_FWI2_CAPABLE(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001642 return qla24xx_login_fabric(ha, fcport->loop_id,
1643 fcport->d_id.b.domain, fcport->d_id.b.area,
1644 fcport->d_id.b.al_pa, mb_ret, opt);
1645
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001646 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1649 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001650 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001652 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 mcp->mb[2] = opt;
1654 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1655 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1656 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1657 mcp->flags = 0;
1658 rval = qla2x00_mailbox_command(ha, mcp);
1659
1660 /* Return mailbox statuses. */
1661 if (mb_ret != NULL) {
1662 mb_ret[0] = mcp->mb[0];
1663 mb_ret[1] = mcp->mb[1];
1664 mb_ret[6] = mcp->mb[6];
1665 mb_ret[7] = mcp->mb[7];
1666 }
1667
1668 if (rval != QLA_SUCCESS) {
1669 /* AV tmp code: need to change main mailbox_command function to
1670 * return ok even when the mailbox completion value is not
1671 * SUCCESS. The caller needs to be responsible to interpret
1672 * the return values of this mailbox command if we're not
1673 * to change too much of the existing code.
1674 */
1675 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1676 rval = QLA_SUCCESS;
1677
1678 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1679 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001680 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1682 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001683 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 } else {
1685 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001686 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 }
1688
1689 return (rval);
1690}
1691
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001692int
1693qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1694 uint8_t area, uint8_t al_pa)
1695{
1696 int rval;
1697 struct logio_entry_24xx *lg;
1698 dma_addr_t lg_dma;
1699
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001700 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001701
1702 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1703 if (lg == NULL) {
1704 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1705 __func__, ha->host_no));
1706 return QLA_MEMORY_ALLOC_FAILED;
1707 }
1708 memset(lg, 0, sizeof(struct logio_entry_24xx));
1709
1710 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1711 lg->entry_count = 1;
1712 lg->nport_handle = cpu_to_le16(loop_id);
1713 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001714 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001715 lg->port_id[0] = al_pa;
1716 lg->port_id[1] = area;
1717 lg->port_id[2] = domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001718 lg->vp_index = cpu_to_le16(ha->vp_idx);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001719 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1720 if (rval != QLA_SUCCESS) {
1721 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001722 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001723 } else if (lg->entry_status != 0) {
1724 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1725 "-- error status (%x).\n", __func__, ha->host_no,
1726 lg->entry_status));
1727 rval = QLA_FUNCTION_FAILED;
1728 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1729 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1730 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1731 ha->host_no, le16_to_cpu(lg->comp_status),
1732 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001733 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001734 } else {
1735 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001736 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001737 }
1738
1739 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1740
1741 return rval;
1742}
1743
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744/*
1745 * qla2x00_fabric_logout
1746 * Issue logout fabric port mailbox command.
1747 *
1748 * Input:
1749 * ha = adapter block pointer.
1750 * loop_id = device loop ID.
1751 * TARGET_QUEUE_LOCK must be released.
1752 * ADAPTER_STATE_LOCK must be released.
1753 *
1754 * Returns:
1755 * qla2x00 local function return status code.
1756 *
1757 * Context:
1758 * Kernel context.
1759 */
1760int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001761qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1762 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763{
1764 int rval;
1765 mbx_cmd_t mc;
1766 mbx_cmd_t *mcp = &mc;
1767
1768 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001769 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1772 mcp->out_mb = MBX_1|MBX_0;
1773 if (HAS_EXTENDED_IDS(ha)) {
1774 mcp->mb[1] = loop_id;
1775 mcp->mb[10] = 0;
1776 mcp->out_mb |= MBX_10;
1777 } else {
1778 mcp->mb[1] = loop_id << 8;
1779 }
1780
1781 mcp->in_mb = MBX_1|MBX_0;
1782 mcp->tov = 30;
1783 mcp->flags = 0;
1784 rval = qla2x00_mailbox_command(ha, mcp);
1785
1786 if (rval != QLA_SUCCESS) {
1787 /*EMPTY*/
1788 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001789 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 } else {
1791 /*EMPTY*/
1792 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001793 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 }
1795
1796 return rval;
1797}
1798
1799/*
1800 * qla2x00_full_login_lip
1801 * Issue full login LIP mailbox command.
1802 *
1803 * Input:
1804 * ha = adapter block pointer.
1805 * TARGET_QUEUE_LOCK must be released.
1806 * ADAPTER_STATE_LOCK must be released.
1807 *
1808 * Returns:
1809 * qla2x00 local function return status code.
1810 *
1811 * Context:
1812 * Kernel context.
1813 */
1814int
1815qla2x00_full_login_lip(scsi_qla_host_t *ha)
1816{
1817 int rval;
1818 mbx_cmd_t mc;
1819 mbx_cmd_t *mcp = &mc;
1820
1821 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001822 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823
1824 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001825 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001826 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 mcp->mb[3] = 0;
1828 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1829 mcp->in_mb = MBX_0;
1830 mcp->tov = 30;
1831 mcp->flags = 0;
1832 rval = qla2x00_mailbox_command(ha, mcp);
1833
1834 if (rval != QLA_SUCCESS) {
1835 /*EMPTY*/
1836 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001837 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 } else {
1839 /*EMPTY*/
1840 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001841 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 }
1843
1844 return rval;
1845}
1846
1847/*
1848 * qla2x00_get_id_list
1849 *
1850 * Input:
1851 * ha = adapter block pointer.
1852 *
1853 * Returns:
1854 * qla2x00 local function return status code.
1855 *
1856 * Context:
1857 * Kernel context.
1858 */
1859int
1860qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1861 uint16_t *entries)
1862{
1863 int rval;
1864 mbx_cmd_t mc;
1865 mbx_cmd_t *mcp = &mc;
1866
1867 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001868 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 if (id_list == NULL)
1871 return QLA_FUNCTION_FAILED;
1872
1873 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001874 mcp->out_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001875 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001876 mcp->mb[2] = MSW(id_list_dma);
1877 mcp->mb[3] = LSW(id_list_dma);
1878 mcp->mb[6] = MSW(MSD(id_list_dma));
1879 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001880 mcp->mb[8] = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001881 mcp->mb[9] = ha->vp_idx;
1882 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001883 } else {
1884 mcp->mb[1] = MSW(id_list_dma);
1885 mcp->mb[2] = LSW(id_list_dma);
1886 mcp->mb[3] = MSW(MSD(id_list_dma));
1887 mcp->mb[6] = LSW(MSD(id_list_dma));
1888 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1889 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 mcp->in_mb = MBX_1|MBX_0;
1891 mcp->tov = 30;
1892 mcp->flags = 0;
1893 rval = qla2x00_mailbox_command(ha, mcp);
1894
1895 if (rval != QLA_SUCCESS) {
1896 /*EMPTY*/
1897 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001898 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 } else {
1900 *entries = mcp->mb[1];
1901 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001902 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 }
1904
1905 return rval;
1906}
1907
1908/*
1909 * qla2x00_get_resource_cnts
1910 * Get current firmware resource counts.
1911 *
1912 * Input:
1913 * ha = adapter block pointer.
1914 *
1915 * Returns:
1916 * qla2x00 local function return status code.
1917 *
1918 * Context:
1919 * Kernel context.
1920 */
1921int
1922qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001923 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1924 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925{
1926 int rval;
1927 mbx_cmd_t mc;
1928 mbx_cmd_t *mcp = &mc;
1929
1930 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1931
1932 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1933 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001934 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 mcp->tov = 30;
1936 mcp->flags = 0;
1937 rval = qla2x00_mailbox_command(ha, mcp);
1938
1939 if (rval != QLA_SUCCESS) {
1940 /*EMPTY*/
1941 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001942 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 } else {
1944 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001945 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001946 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001947 mcp->mb[10], mcp->mb[11]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 if (cur_xchg_cnt)
1950 *cur_xchg_cnt = mcp->mb[3];
1951 if (orig_xchg_cnt)
1952 *orig_xchg_cnt = mcp->mb[6];
1953 if (cur_iocb_cnt)
1954 *cur_iocb_cnt = mcp->mb[7];
1955 if (orig_iocb_cnt)
1956 *orig_iocb_cnt = mcp->mb[10];
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001957 if (max_npiv_vports)
1958 *max_npiv_vports = mcp->mb[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
1960
1961 return (rval);
1962}
1963
1964#if defined(QL_DEBUG_LEVEL_3)
1965/*
1966 * qla2x00_get_fcal_position_map
1967 * Get FCAL (LILP) position map using mailbox command
1968 *
1969 * Input:
1970 * ha = adapter state pointer.
1971 * pos_map = buffer pointer (can be NULL).
1972 *
1973 * Returns:
1974 * qla2x00 local function return status code.
1975 *
1976 * Context:
1977 * Kernel context.
1978 */
1979int
1980qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1981{
1982 int rval;
1983 mbx_cmd_t mc;
1984 mbx_cmd_t *mcp = &mc;
1985 char *pmap;
1986 dma_addr_t pmap_dma;
1987
1988 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1989 if (pmap == NULL) {
1990 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1991 __func__, ha->host_no));
1992 return QLA_MEMORY_ALLOC_FAILED;
1993 }
1994 memset(pmap, 0, FCAL_MAP_SIZE);
1995
1996 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1997 mcp->mb[2] = MSW(pmap_dma);
1998 mcp->mb[3] = LSW(pmap_dma);
1999 mcp->mb[6] = MSW(MSD(pmap_dma));
2000 mcp->mb[7] = LSW(MSD(pmap_dma));
2001 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2002 mcp->in_mb = MBX_1|MBX_0;
2003 mcp->buf_size = FCAL_MAP_SIZE;
2004 mcp->flags = MBX_DMA_IN;
2005 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2006 rval = qla2x00_mailbox_command(ha, mcp);
2007
2008 if (rval == QLA_SUCCESS) {
2009 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2010 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2011 mcp->mb[1], (unsigned)pmap[0]));
2012 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2013
2014 if (pos_map)
2015 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2016 }
2017 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2018
2019 if (rval != QLA_SUCCESS) {
2020 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2021 ha->host_no, rval));
2022 } else {
2023 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2024 }
2025
2026 return rval;
2027}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002028#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002029
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002030/*
2031 * qla2x00_get_link_status
2032 *
2033 * Input:
2034 * ha = adapter block pointer.
2035 * loop_id = device loop ID.
2036 * ret_buf = pointer to link status return buffer.
2037 *
2038 * Returns:
2039 * 0 = success.
2040 * BIT_0 = mem alloc error.
2041 * BIT_1 = mailbox error.
2042 */
2043int
2044qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002045 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002046{
2047 int rval;
2048 mbx_cmd_t mc;
2049 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002050 uint32_t *siter, *diter, dwords;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002051
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002052 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002053
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002054 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002055 mcp->mb[2] = MSW(stats_dma);
2056 mcp->mb[3] = LSW(stats_dma);
2057 mcp->mb[6] = MSW(MSD(stats_dma));
2058 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002059 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2060 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002061 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002062 mcp->mb[1] = loop_id;
2063 mcp->mb[4] = 0;
2064 mcp->mb[10] = 0;
2065 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2066 mcp->in_mb |= MBX_1;
2067 } else if (HAS_EXTENDED_IDS(ha)) {
2068 mcp->mb[1] = loop_id;
2069 mcp->mb[10] = 0;
2070 mcp->out_mb |= MBX_10|MBX_1;
2071 } else {
2072 mcp->mb[1] = loop_id << 8;
2073 mcp->out_mb |= MBX_1;
2074 }
2075 mcp->tov = 30;
2076 mcp->flags = IOCTL_CMD;
2077 rval = qla2x00_mailbox_command(ha, mcp);
2078
2079 if (rval == QLA_SUCCESS) {
2080 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2081 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002082 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002083 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002084 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002085 /* Copy over data -- firmware data is LE. */
2086 dwords = offsetof(struct link_statistics, unused1) / 4;
2087 siter = diter = &stats->link_fail_cnt;
2088 while (dwords--)
2089 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002090 }
2091 } else {
2092 /* Failed. */
2093 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002094 ha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002095 }
2096
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002097 return rval;
2098}
2099
2100int
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002101qla24xx_get_isp_stats(scsi_qla_host_t *ha, struct link_statistics *stats,
2102 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002103{
2104 int rval;
2105 mbx_cmd_t mc;
2106 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002107 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002108
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002109 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002110
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002111 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002112 mcp->mb[2] = MSW(stats_dma);
2113 mcp->mb[3] = LSW(stats_dma);
2114 mcp->mb[6] = MSW(MSD(stats_dma));
2115 mcp->mb[7] = LSW(MSD(stats_dma));
2116 mcp->mb[8] = sizeof(struct link_statistics) / 4;
2117 mcp->mb[9] = ha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002118 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002119 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 -07002120 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2121 mcp->tov = 30;
2122 mcp->flags = IOCTL_CMD;
2123 rval = qla2x00_mailbox_command(ha, mcp);
2124
2125 if (rval == QLA_SUCCESS) {
2126 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2127 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2128 __func__, ha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002129 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002130 } else {
2131 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002132 dwords = sizeof(struct link_statistics) / 4;
2133 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002134 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002135 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002136 }
2137 } else {
2138 /* Failed. */
2139 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2140 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002141 }
2142
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002143 return rval;
2144}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002145
2146int
2147qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2148{
2149 int rval;
2150 fc_port_t *fcport;
2151 unsigned long flags = 0;
2152
2153 struct abort_entry_24xx *abt;
2154 dma_addr_t abt_dma;
2155 uint32_t handle;
2156
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002157 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002158
2159 fcport = sp->fcport;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002160
2161 spin_lock_irqsave(&ha->hardware_lock, flags);
2162 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2163 if (ha->outstanding_cmds[handle] == sp)
2164 break;
2165 }
2166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2167 if (handle == MAX_OUTSTANDING_COMMANDS) {
2168 /* Command not found. */
2169 return QLA_FUNCTION_FAILED;
2170 }
2171
2172 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2173 if (abt == NULL) {
2174 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2175 __func__, ha->host_no));
2176 return QLA_MEMORY_ALLOC_FAILED;
2177 }
2178 memset(abt, 0, sizeof(struct abort_entry_24xx));
2179
2180 abt->entry_type = ABORT_IOCB_TYPE;
2181 abt->entry_count = 1;
2182 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2183 abt->handle_to_abort = handle;
2184 abt->port_id[0] = fcport->d_id.b.al_pa;
2185 abt->port_id[1] = fcport->d_id.b.area;
2186 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002187 abt->vp_index = fcport->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002188 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2189 if (rval != QLA_SUCCESS) {
2190 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002191 __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002192 } else if (abt->entry_status != 0) {
2193 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2194 "-- error status (%x).\n", __func__, ha->host_no,
2195 abt->entry_status));
2196 rval = QLA_FUNCTION_FAILED;
2197 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2198 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2199 "-- completion status (%x).\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002200 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002201 rval = QLA_FUNCTION_FAILED;
2202 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002203 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002204 sp->flags |= SRB_ABORT_PENDING;
2205 }
2206
2207 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2208
2209 return rval;
2210}
2211
2212struct tsk_mgmt_cmd {
2213 union {
2214 struct tsk_mgmt_entry tsk;
2215 struct sts_entry_24xx sts;
2216 } p;
2217};
2218
2219int
2220qla24xx_abort_target(fc_port_t *fcport)
2221{
2222 int rval;
2223 struct tsk_mgmt_cmd *tsk;
2224 dma_addr_t tsk_dma;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002225 scsi_qla_host_t *ha, *pha;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002226
2227 if (fcport == NULL)
2228 return 0;
2229
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002230 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002231
2232 ha = fcport->ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002233 pha = to_qla_parent(ha);
2234 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002235 if (tsk == NULL) {
2236 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2237 "IOCB.\n", __func__, ha->host_no));
2238 return QLA_MEMORY_ALLOC_FAILED;
2239 }
2240 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2241
2242 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2243 tsk->p.tsk.entry_count = 1;
2244 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2245 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2246 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2247 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2248 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2249 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002250 tsk->p.tsk.vp_index = fcport->vp_idx;
2251
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002252 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2253 if (rval != QLA_SUCCESS) {
2254 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002255 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002256 goto atarget_done;
2257 } else if (tsk->p.sts.entry_status != 0) {
2258 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2259 "-- error status (%x).\n", __func__, ha->host_no,
2260 tsk->p.sts.entry_status));
2261 rval = QLA_FUNCTION_FAILED;
2262 goto atarget_done;
2263 } else if (tsk->p.sts.comp_status !=
2264 __constant_cpu_to_le16(CS_COMPLETE)) {
2265 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2266 "-- completion status (%x).\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002267 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002268 rval = QLA_FUNCTION_FAILED;
2269 goto atarget_done;
2270 }
2271
2272 /* Issue marker IOCB. */
2273 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2274 if (rval != QLA_SUCCESS) {
2275 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002276 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002277 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002278 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002279 }
2280
2281atarget_done:
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002282 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283
2284 return rval;
2285}
2286
2287int
2288qla2x00_system_error(scsi_qla_host_t *ha)
2289{
2290 int rval;
2291 mbx_cmd_t mc;
2292 mbx_cmd_t *mcp = &mc;
2293
Andrew Vasqueze4289242007-07-19 15:05:56 -07002294 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002295 return QLA_FUNCTION_FAILED;
2296
2297 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2298
2299 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2300 mcp->out_mb = MBX_0;
2301 mcp->in_mb = MBX_0;
2302 mcp->tov = 5;
2303 mcp->flags = 0;
2304 rval = qla2x00_mailbox_command(ha, mcp);
2305
2306 if (rval != QLA_SUCCESS) {
2307 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2308 ha->host_no, rval));
2309 } else {
2310 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2311 }
2312
2313 return rval;
2314}
2315
2316/**
2317 * qla2x00_get_serdes_params() -
2318 * @ha: HA context
2319 *
2320 * Returns
2321 */
2322int
2323qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2324 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2325{
2326 int rval;
2327 mbx_cmd_t mc;
2328 mbx_cmd_t *mcp = &mc;
2329
2330 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2331
2332 mcp->mb[0] = MBC_SERDES_PARAMS;
2333 mcp->mb[1] = 0;
2334 mcp->out_mb = MBX_1|MBX_0;
2335 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2336 mcp->tov = 30;
2337 mcp->flags = 0;
2338 rval = qla2x00_mailbox_command(ha, mcp);
2339
2340 if (rval != QLA_SUCCESS) {
2341 /*EMPTY*/
2342 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2343 ha->host_no, rval, mcp->mb[0]));
2344 } else {
2345 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2346
2347 if (sw_em_1g)
2348 *sw_em_1g = mcp->mb[2];
2349 if (sw_em_2g)
2350 *sw_em_2g = mcp->mb[3];
2351 if (sw_em_4g)
2352 *sw_em_4g = mcp->mb[4];
2353 }
2354
2355 return rval;
2356}
2357
2358/**
2359 * qla2x00_set_serdes_params() -
2360 * @ha: HA context
2361 *
2362 * Returns
2363 */
2364int
2365qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2366 uint16_t sw_em_2g, uint16_t sw_em_4g)
2367{
2368 int rval;
2369 mbx_cmd_t mc;
2370 mbx_cmd_t *mcp = &mc;
2371
2372 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2373
2374 mcp->mb[0] = MBC_SERDES_PARAMS;
2375 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002376 mcp->mb[2] = sw_em_1g | BIT_15;
2377 mcp->mb[3] = sw_em_2g | BIT_15;
2378 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002379 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2380 mcp->in_mb = MBX_0;
2381 mcp->tov = 30;
2382 mcp->flags = 0;
2383 rval = qla2x00_mailbox_command(ha, mcp);
2384
2385 if (rval != QLA_SUCCESS) {
2386 /*EMPTY*/
2387 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2388 ha->host_no, rval, mcp->mb[0]));
2389 } else {
2390 /*EMPTY*/
2391 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2392 }
2393
2394 return rval;
2395}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002396
2397int
2398qla2x00_stop_firmware(scsi_qla_host_t *ha)
2399{
2400 int rval;
2401 mbx_cmd_t mc;
2402 mbx_cmd_t *mcp = &mc;
2403
Andrew Vasqueze4289242007-07-19 15:05:56 -07002404 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002405 return QLA_FUNCTION_FAILED;
2406
2407 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2408
2409 mcp->mb[0] = MBC_STOP_FIRMWARE;
2410 mcp->out_mb = MBX_0;
2411 mcp->in_mb = MBX_0;
2412 mcp->tov = 5;
2413 mcp->flags = 0;
2414 rval = qla2x00_mailbox_command(ha, mcp);
2415
2416 if (rval != QLA_SUCCESS) {
2417 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2418 ha->host_no, rval));
2419 } else {
2420 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2421 }
2422
2423 return rval;
2424}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002425
2426int
2427qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2428 uint16_t buffers)
2429{
2430 int rval;
2431 mbx_cmd_t mc;
2432 mbx_cmd_t *mcp = &mc;
2433
Andrew Vasqueze4289242007-07-19 15:05:56 -07002434 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002435 return QLA_FUNCTION_FAILED;
2436
2437 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2438
2439 mcp->mb[0] = MBC_TRACE_CONTROL;
2440 mcp->mb[1] = ctrl;
2441 mcp->out_mb = MBX_1|MBX_0;
2442 mcp->in_mb = MBX_1|MBX_0;
2443 if (ctrl == TC_ENABLE) {
2444 mcp->mb[2] = LSW(eft_dma);
2445 mcp->mb[3] = MSW(eft_dma);
2446 mcp->mb[4] = LSW(MSD(eft_dma));
2447 mcp->mb[5] = MSW(MSD(eft_dma));
2448 mcp->mb[6] = buffers;
Andrew Vasquez87b23802006-12-13 19:20:25 -08002449 mcp->mb[7] = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002450 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2451 }
2452 mcp->tov = 30;
2453 mcp->flags = 0;
2454 rval = qla2x00_mailbox_command(ha, mcp);
2455
2456 if (rval != QLA_SUCCESS) {
2457 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2458 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2459 } else {
2460 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2461 }
2462
2463 return rval;
2464}
2465
Andrew Vasquez88729e52006-06-23 16:10:50 -07002466int
2467qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2468 uint16_t off, uint16_t count)
2469{
2470 int rval;
2471 mbx_cmd_t mc;
2472 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002473
Andrew Vasqueze4289242007-07-19 15:05:56 -07002474 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002475 return QLA_FUNCTION_FAILED;
2476
2477 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2478
2479 mcp->mb[0] = MBC_READ_SFP;
2480 mcp->mb[1] = addr;
2481 mcp->mb[2] = MSW(sfp_dma);
2482 mcp->mb[3] = LSW(sfp_dma);
2483 mcp->mb[6] = MSW(MSD(sfp_dma));
2484 mcp->mb[7] = LSW(MSD(sfp_dma));
2485 mcp->mb[8] = count;
2486 mcp->mb[9] = off;
2487 mcp->mb[10] = 0;
2488 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2489 mcp->in_mb = MBX_0;
2490 mcp->tov = 30;
2491 mcp->flags = 0;
2492 rval = qla2x00_mailbox_command(ha, mcp);
2493
2494 if (rval != QLA_SUCCESS) {
2495 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2496 ha->host_no, rval, mcp->mb[0]));
2497 } else {
2498 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2499 }
2500
2501 return rval;
2502}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002503
2504int
2505qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2506 uint16_t *port_speed, uint16_t *mb)
2507{
2508 int rval;
2509 mbx_cmd_t mc;
2510 mbx_cmd_t *mcp = &mc;
2511
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002512 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002513 return QLA_FUNCTION_FAILED;
2514
2515 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2516
2517 mcp->mb[0] = MBC_PORT_PARAMS;
2518 mcp->mb[1] = loop_id;
2519 mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0;
2520 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2521 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2522 mcp->tov = 30;
2523 mcp->flags = 0;
2524 rval = qla2x00_mailbox_command(ha, mcp);
2525
2526 /* Return mailbox statuses. */
2527 if (mb != NULL) {
2528 mb[0] = mcp->mb[0];
2529 mb[1] = mcp->mb[1];
2530 mb[3] = mcp->mb[3];
2531 mb[4] = mcp->mb[4];
2532 mb[5] = mcp->mb[5];
2533 }
2534
2535 if (rval != QLA_SUCCESS) {
2536 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2537 ha->host_no, rval));
2538 } else {
2539 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2540 if (port_speed)
2541 *port_speed = mcp->mb[3];
2542 }
2543
2544 return rval;
2545}
2546
2547int
2548qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2549 uint16_t port_speed, uint16_t *mb)
2550{
2551 int rval;
2552 mbx_cmd_t mc;
2553 mbx_cmd_t *mcp = &mc;
2554
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002555 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002556 return QLA_FUNCTION_FAILED;
2557
2558 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2559
2560 mcp->mb[0] = MBC_PORT_PARAMS;
2561 mcp->mb[1] = loop_id;
2562 mcp->mb[2] = BIT_0;
2563 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2564 mcp->mb[4] = mcp->mb[5] = 0;
2565 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2566 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2567 mcp->tov = 30;
2568 mcp->flags = 0;
2569 rval = qla2x00_mailbox_command(ha, mcp);
2570
2571 /* Return mailbox statuses. */
2572 if (mb != NULL) {
2573 mb[0] = mcp->mb[0];
2574 mb[1] = mcp->mb[1];
2575 mb[3] = mcp->mb[3];
2576 mb[4] = mcp->mb[4];
2577 mb[5] = mcp->mb[5];
2578 }
2579
2580 if (rval != QLA_SUCCESS) {
2581 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2582 ha->host_no, rval));
2583 } else {
2584 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2585 }
2586
2587 return rval;
2588}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002589
2590/*
2591 * qla24xx_get_vp_database
2592 * Get the VP's database for all configured ports.
2593 *
2594 * Input:
2595 * ha = adapter block pointer.
2596 * size = size of initialization control block.
2597 *
2598 * Returns:
2599 * qla2x00 local function return status code.
2600 *
2601 * Context:
2602 * Kernel context.
2603 */
2604int
2605qla24xx_get_vp_database(scsi_qla_host_t *ha, uint16_t size)
2606{
2607 int rval;
2608 mbx_cmd_t mc;
2609 mbx_cmd_t *mcp = &mc;
2610
2611 DEBUG11(printk("scsi(%ld):%s - entered.\n",
2612 ha->host_no, __func__));
2613
2614 mcp->mb[0] = MBC_MID_GET_VP_DATABASE;
2615 mcp->mb[2] = MSW(ha->init_cb_dma);
2616 mcp->mb[3] = LSW(ha->init_cb_dma);
2617 mcp->mb[4] = 0;
2618 mcp->mb[5] = 0;
2619 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2620 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2621 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2622 mcp->in_mb = MBX_1|MBX_0;
2623 mcp->buf_size = size;
2624 mcp->flags = MBX_DMA_OUT;
2625 mcp->tov = MBX_TOV_SECONDS;
2626 rval = qla2x00_mailbox_command(ha, mcp);
2627
2628 if (rval != QLA_SUCCESS) {
2629 /*EMPTY*/
2630 DEBUG2_3_11(printk("%s(%ld): failed=%x "
2631 "mb0=%x.\n",
2632 __func__, ha->host_no, rval, mcp->mb[0]));
2633 } else {
2634 /*EMPTY*/
2635 DEBUG11(printk("%s(%ld): done.\n",
2636 __func__, ha->host_no));
2637 }
2638
2639 return rval;
2640}
2641
2642int
2643qla24xx_get_vp_entry(scsi_qla_host_t *ha, uint16_t size, int vp_id)
2644{
2645 int rval;
2646 mbx_cmd_t mc;
2647 mbx_cmd_t *mcp = &mc;
2648
2649 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2650
2651 mcp->mb[0] = MBC_MID_GET_VP_ENTRY;
2652 mcp->mb[2] = MSW(ha->init_cb_dma);
2653 mcp->mb[3] = LSW(ha->init_cb_dma);
2654 mcp->mb[4] = 0;
2655 mcp->mb[5] = 0;
2656 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2657 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2658 mcp->mb[9] = vp_id;
2659 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2660 mcp->in_mb = MBX_0;
2661 mcp->buf_size = size;
2662 mcp->flags = MBX_DMA_OUT;
2663 mcp->tov = 30;
2664 rval = qla2x00_mailbox_command(ha, mcp);
2665
2666 if (rval != QLA_SUCCESS) {
2667 /*EMPTY*/
2668 DEBUG2_3_11(printk("qla24xx_get_vp_entry(%ld): failed=%x "
2669 "mb0=%x.\n",
2670 ha->host_no, rval, mcp->mb[0]));
2671 } else {
2672 /*EMPTY*/
2673 DEBUG11(printk("qla24xx_get_vp_entry(%ld): done.\n",
2674 ha->host_no));
2675 }
2676
2677 return rval;
2678}
2679
2680void
2681qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2682 struct vp_rpt_id_entry_24xx *rptid_entry)
2683{
2684 uint8_t vp_idx;
2685 scsi_qla_host_t *vha;
2686
2687 if (rptid_entry->entry_status != 0)
2688 return;
2689 if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
2690 return;
2691
2692 if (rptid_entry->format == 0) {
2693 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2694 " number of VPs acquired %d\n", __func__, ha->host_no,
2695 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2696 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2697 rptid_entry->port_id[2], rptid_entry->port_id[1],
2698 rptid_entry->port_id[0]));
2699 } else if (rptid_entry->format == 1) {
2700 vp_idx = LSB(rptid_entry->vp_idx);
2701 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2702 "- status %d - "
2703 "with port id %02x%02x%02x\n",__func__,ha->host_no,
2704 vp_idx, MSB(rptid_entry->vp_idx),
2705 rptid_entry->port_id[2], rptid_entry->port_id[1],
2706 rptid_entry->port_id[0]));
2707 if (vp_idx == 0)
2708 return;
2709
2710 if (MSB(rptid_entry->vp_idx) == 1)
2711 return;
2712
2713 list_for_each_entry(vha, &ha->vp_list, vp_list)
2714 if (vp_idx == vha->vp_idx)
2715 break;
2716
2717 if (!vha)
2718 return;
2719
2720 vha->d_id.b.domain = rptid_entry->port_id[2];
2721 vha->d_id.b.area = rptid_entry->port_id[1];
2722 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2723
2724 /*
2725 * Cannot configure here as we are still sitting on the
2726 * response queue. Handle it in dpc context.
2727 */
2728 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2729 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2730
2731 wake_up_process(ha->dpc_thread);
2732 }
2733}
2734
2735/*
2736 * qla24xx_modify_vp_config
2737 * Change VP configuration for vha
2738 *
2739 * Input:
2740 * vha = adapter block pointer.
2741 *
2742 * Returns:
2743 * qla2xxx local function return status code.
2744 *
2745 * Context:
2746 * Kernel context.
2747 */
2748int
2749qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2750{
2751 int rval;
2752 struct vp_config_entry_24xx *vpmod;
2753 dma_addr_t vpmod_dma;
2754 scsi_qla_host_t *pha;
2755
2756 /* This can be called by the parent */
2757 pha = to_qla_parent(vha);
2758
2759 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2760 if (!vpmod) {
2761 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2762 "IOCB.\n", __func__, pha->host_no));
2763 return QLA_MEMORY_ALLOC_FAILED;
2764 }
2765
2766 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2767 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2768 vpmod->entry_count = 1;
2769 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2770 vpmod->vp_count = 1;
2771 vpmod->vp_index1 = vha->vp_idx;
2772 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2773 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2774 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2775 vpmod->entry_count = 1;
2776
2777 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2778 if (rval != QLA_SUCCESS) {
2779 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2780 "(%x).\n", __func__, pha->host_no, rval));
2781 } else if (vpmod->comp_status != 0) {
2782 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2783 "-- error status (%x).\n", __func__, pha->host_no,
2784 vpmod->comp_status));
2785 rval = QLA_FUNCTION_FAILED;
2786 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2787 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2788 "-- completion status (%x).\n", __func__, pha->host_no,
2789 le16_to_cpu(vpmod->comp_status)));
2790 rval = QLA_FUNCTION_FAILED;
2791 } else {
2792 /* EMPTY */
2793 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2794 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2795 }
2796 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2797
2798 return rval;
2799}
2800
2801/*
2802 * qla24xx_control_vp
2803 * Enable a virtual port for given host
2804 *
2805 * Input:
2806 * ha = adapter block pointer.
2807 * vhba = virtual adapter (unused)
2808 * index = index number for enabled VP
2809 *
2810 * Returns:
2811 * qla2xxx local function return status code.
2812 *
2813 * Context:
2814 * Kernel context.
2815 */
2816int
2817qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2818{
2819 int rval;
2820 int map, pos;
2821 struct vp_ctrl_entry_24xx *vce;
2822 dma_addr_t vce_dma;
2823 scsi_qla_host_t *ha = vha->parent;
2824 int vp_index = vha->vp_idx;
2825
2826 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2827 ha->host_no, vp_index));
2828
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002829 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002830 return QLA_PARAMETER_ERROR;
2831
2832 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2833 if (!vce) {
2834 DEBUG2_3(printk("%s(%ld): "
2835 "failed to allocate VP Control IOCB.\n", __func__,
2836 ha->host_no));
2837 return QLA_MEMORY_ALLOC_FAILED;
2838 }
2839 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2840
2841 vce->entry_type = VP_CTRL_IOCB_TYPE;
2842 vce->entry_count = 1;
2843 vce->command = cpu_to_le16(cmd);
2844 vce->vp_count = __constant_cpu_to_le16(1);
2845
2846 /* index map in firmware starts with 1; decrement index
2847 * this is ok as we never use index 0
2848 */
2849 map = (vp_index - 1) / 8;
2850 pos = (vp_index - 1) & 7;
2851 down(&ha->vport_sem);
2852 vce->vp_idx_map[map] |= 1 << pos;
2853 up(&ha->vport_sem);
2854
2855 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2856 if (rval != QLA_SUCCESS) {
2857 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2858 "(%x).\n", __func__, ha->host_no, rval));
2859 printk("%s(%ld): failed to issue VP control IOCB"
2860 "(%x).\n", __func__, ha->host_no, rval);
2861 } else if (vce->entry_status != 0) {
2862 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2863 "-- error status (%x).\n", __func__, ha->host_no,
2864 vce->entry_status));
2865 printk("%s(%ld): failed to complete IOCB "
2866 "-- error status (%x).\n", __func__, ha->host_no,
2867 vce->entry_status);
2868 rval = QLA_FUNCTION_FAILED;
2869 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2870 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2871 "-- completion status (%x).\n", __func__, ha->host_no,
2872 le16_to_cpu(vce->comp_status)));
2873 printk("%s(%ld): failed to complete IOCB "
2874 "-- completion status (%x).\n", __func__, ha->host_no,
2875 le16_to_cpu(vce->comp_status));
2876 rval = QLA_FUNCTION_FAILED;
2877 } else {
2878 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2879 }
2880
2881 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2882
2883 return rval;
2884}
2885
2886/*
2887 * qla2x00_send_change_request
2888 * Receive or disable RSCN request from fabric controller
2889 *
2890 * Input:
2891 * ha = adapter block pointer
2892 * format = registration format:
2893 * 0 - Reserved
2894 * 1 - Fabric detected registration
2895 * 2 - N_port detected registration
2896 * 3 - Full registration
2897 * FF - clear registration
2898 * vp_idx = Virtual port index
2899 *
2900 * Returns:
2901 * qla2x00 local function return status code.
2902 *
2903 * Context:
2904 * Kernel Context
2905 */
2906
2907int
2908qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2909 uint16_t vp_idx)
2910{
2911 int rval;
2912 mbx_cmd_t mc;
2913 mbx_cmd_t *mcp = &mc;
2914
2915 /*
2916 * This command is implicitly executed by firmware during login for the
2917 * physical hosts
2918 */
2919 if (vp_idx == 0)
2920 return QLA_FUNCTION_FAILED;
2921
2922 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2923 mcp->mb[1] = format;
2924 mcp->mb[9] = vp_idx;
2925 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2926 mcp->in_mb = MBX_0|MBX_1;
2927 mcp->tov = MBX_TOV_SECONDS;
2928 mcp->flags = 0;
2929 rval = qla2x00_mailbox_command(ha, mcp);
2930
2931 if (rval == QLA_SUCCESS) {
2932 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2933 rval = BIT_1;
2934 }
2935 } else
2936 rval = BIT_1;
2937
2938 return rval;
2939}
Andrew Vasquez338c9162007-09-20 14:07:33 -07002940
2941int
2942qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2943 uint32_t size)
2944{
2945 int rval;
2946 mbx_cmd_t mc;
2947 mbx_cmd_t *mcp = &mc;
2948
2949 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2950
2951 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2952 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2953 mcp->mb[8] = MSW(addr);
2954 mcp->out_mb = MBX_8|MBX_0;
2955 } else {
2956 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2957 mcp->out_mb = MBX_0;
2958 }
2959 mcp->mb[1] = LSW(addr);
2960 mcp->mb[2] = MSW(req_dma);
2961 mcp->mb[3] = LSW(req_dma);
2962 mcp->mb[6] = MSW(MSD(req_dma));
2963 mcp->mb[7] = LSW(MSD(req_dma));
2964 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
2965 if (IS_FWI2_CAPABLE(ha)) {
2966 mcp->mb[4] = MSW(size);
2967 mcp->mb[5] = LSW(size);
2968 mcp->out_mb |= MBX_5|MBX_4;
2969 } else {
2970 mcp->mb[4] = LSW(size);
2971 mcp->out_mb |= MBX_4;
2972 }
2973
2974 mcp->in_mb = MBX_0;
2975 mcp->tov = 30;
2976 mcp->flags = 0;
2977 rval = qla2x00_mailbox_command(ha, mcp);
2978
2979 if (rval != QLA_SUCCESS) {
2980 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
2981 ha->host_no, rval, mcp->mb[0]));
2982 } else {
2983 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2984 }
2985
2986 return rval;
2987}