blob: afe7310213cc8797c1d4e32d71524d15820a17c0 [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
45qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
46{
47 int rval;
48 unsigned long flags = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070049 device_reg_t __iomem *reg = ha->iobase;
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 uint8_t io_lock_on = ha->flags.init_done;
53 uint16_t command;
54 uint16_t *iptr;
55 uint16_t __iomem *optr;
56 uint32_t cnt;
57 uint32_t mboxes;
58 unsigned long mbx_flags = 0;
59 unsigned long wait_time;
60
61 rval = QLA_SUCCESS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070062 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070064 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070065
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070067 * Wait for active mailbox commands to finish by waiting at most tov
68 * seconds. This is to serialize actual issuing of mailbox cmds during
69 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 */
71 if (!abort_active) {
72 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
73 /* Timeout occurred. Return error. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070074 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070075 "Exiting.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return QLA_FUNCTION_TIMEOUT;
77 }
78 }
79
80 ha->flags.mbox_busy = 1;
81 /* Save mailbox command for debug */
82 ha->mcp = mcp;
83
84 /* Try to get mailbox register access */
85 if (!abort_active)
86 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
87
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070088 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -070089 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91 spin_lock_irqsave(&ha->hardware_lock, flags);
92
93 /* Load mailbox registers. */
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -080094 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070095 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
96 else
97 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 iptr = mcp->mb;
100 command = mcp->mb[0];
101 mboxes = mcp->out_mb;
102
103 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
104 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700105 optr =
106 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 if (mboxes & BIT_0)
108 WRT_REG_WORD(optr, *iptr);
109
110 mboxes >>= 1;
111 optr++;
112 iptr++;
113 }
114
115#if defined(QL_DEBUG_LEVEL_1)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700116 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
117 __func__, ha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
119 printk("\n");
120 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
121 printk("\n");
122 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
123 printk("\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700124 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 qla2x00_dump_regs(ha);
126#endif
127
128 /* Issue set host interrupt command to send cmd out. */
129 ha->flags.mbox_int = 0;
130 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
131
132 /* Unlock mbx registers and wait for interrupt */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700133 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700134 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* Wait for mbx cmd completion until timeout */
137
138 if (!abort_active && io_lock_on) {
139 /* sleep on completion semaphore */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700140 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700141 __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 init_timer(&tmp_intr_timer);
144 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
145 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
146 tmp_intr_timer.function =
147 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
148
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700149 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700150 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 add_timer(&tmp_intr_timer);
152
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700153 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700154 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
157
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800158 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700159 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
160 else
161 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
163
164 if (!abort_active)
165 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
166
167 /* Wait for either the timer to expire
168 * or the mbox completion interrupt
169 */
170 down(&ha->mbx_intr_sem);
171
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700172 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700173 ha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
175
176 /* delete the timer */
177 del_timer(&tmp_intr_timer);
178 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700179 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700180 ha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800182 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700183 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
184 else
185 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 spin_unlock_irqrestore(&ha->hardware_lock, flags);
187 if (!abort_active)
188 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
189
190 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
191 while (!ha->flags.mbox_int) {
192 if (time_after(jiffies, wait_time))
193 break;
194
195 /* Check for pending interrupts. */
196 qla2x00_poll(ha);
197
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800198 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
199 !ha->flags.mbox_int)
200 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 } /* while */
202 }
203
204 if (!abort_active)
205 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
206
207 /* Check whether we timed out */
208 if (ha->flags.mbox_int) {
209 uint16_t *iptr2;
210
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700211 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700212 ha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 /* Got interrupt. Clear the flag. */
215 ha->flags.mbox_int = 0;
216 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
217
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400218 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 /* Load return mailbox registers. */
222 iptr2 = mcp->mb;
223 iptr = (uint16_t *)&ha->mailbox_out[0];
224 mboxes = mcp->in_mb;
225 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
226 if (mboxes & BIT_0)
227 *iptr2 = *iptr;
228
229 mboxes >>= 1;
230 iptr2++;
231 iptr++;
232 }
233 } else {
234
235#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
236 defined(QL_DEBUG_LEVEL_11)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700237 uint16_t mb0;
238 uint32_t ictrl;
239
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800240 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700241 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
242 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
243 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700244 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700245 ictrl = RD_REG_WORD(&reg->isp.ictrl);
246 }
247 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
248 __func__, ha->host_no, command);
249 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
250 ha->host_no, ictrl, jiffies);
251 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
252 ha->host_no, mb0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 qla2x00_dump_regs(ha);
254#endif
255
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 rval = QLA_FUNCTION_TIMEOUT;
257 }
258
259 if (!abort_active)
260 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
261
262 ha->flags.mbox_busy = 0;
263
264 /* Clean up */
265 ha->mcp = NULL;
266
267 if (!abort_active) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700268 DEBUG11(printk("%s(%ld): checking for additional resp "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700269 "interrupt.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
271 /* polling mode for non isp_abort commands. */
272 qla2x00_poll(ha);
273 }
274
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700275 if (rval == QLA_FUNCTION_TIMEOUT &&
276 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
278 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700279 DEBUG(printk("%s(%ld): timeout schedule "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700280 "isp_abort_needed.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700281 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700282 "isp_abort_needed.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 qla_printk(KERN_WARNING, ha,
284 "Mailbox command timeout occured. Scheduling ISP "
285 "abort.\n");
286 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Christoph Hellwig39a11242006-02-14 18:46:22 +0100287 qla2xxx_wake_dpc(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700290 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700291 __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700292 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700293 "abort_isp\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 qla_printk(KERN_WARNING, ha,
295 "Mailbox command timeout occured. Issuing ISP "
296 "abort.\n");
297
298 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
299 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
300 if (qla2x00_abort_isp(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700301 /* Failed. retry later. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
303 }
304 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700305 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700306 ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700307 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700308 __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 }
310 }
311
312 /* Allow next mbx cmd to come in. */
313 if (!abort_active)
314 up(&ha->mbx_cmd_sem);
315
316 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700317 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
318 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700319 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 return rval;
325}
326
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327int
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800328qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
329 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 int rval;
332 mbx_cmd_t mc;
333 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
336
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800337 if (MSW(risc_addr) || IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800338 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
339 mcp->mb[8] = MSW(risc_addr);
340 mcp->out_mb = MBX_8|MBX_0;
341 } else {
342 mcp->mb[0] = MBC_LOAD_RISC_RAM;
343 mcp->out_mb = MBX_0;
344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 mcp->mb[1] = LSW(risc_addr);
346 mcp->mb[2] = MSW(req_dma);
347 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 mcp->mb[6] = MSW(MSD(req_dma));
349 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800350 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800351 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700352 mcp->mb[4] = MSW(risc_code_size);
353 mcp->mb[5] = LSW(risc_code_size);
354 mcp->out_mb |= MBX_5|MBX_4;
355 } else {
356 mcp->mb[4] = LSW(risc_code_size);
357 mcp->out_mb |= MBX_4;
358 }
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 mcp->in_mb = MBX_0;
361 mcp->tov = 30;
362 mcp->flags = 0;
363 rval = qla2x00_mailbox_command(ha, mcp);
364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700366 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
367 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
370 }
371
372 return rval;
373}
374
375/*
376 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700377 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 *
379 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700380 * ha = adapter block pointer.
381 * TARGET_QUEUE_LOCK must be released.
382 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 *
384 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700385 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 *
387 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700388 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 */
390int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700391qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
393 int rval;
394 mbx_cmd_t mc;
395 mbx_cmd_t *mcp = &mc;
396
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700397 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700400 mcp->out_mb = MBX_0;
401 mcp->in_mb = MBX_0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800402 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700403 mcp->mb[1] = MSW(risc_addr);
404 mcp->mb[2] = LSW(risc_addr);
405 mcp->mb[3] = 0;
406 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
407 mcp->in_mb |= MBX_1;
408 } else {
409 mcp->mb[1] = LSW(risc_addr);
410 mcp->out_mb |= MBX_1;
411 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
412 mcp->mb[2] = 0;
413 mcp->out_mb |= MBX_2;
414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 mcp->tov = 30;
418 mcp->flags = 0;
419 rval = qla2x00_mailbox_command(ha, mcp);
420
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700421 if (rval != QLA_SUCCESS) {
422 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
423 ha->host_no, rval, mcp->mb[0]));
424 } else {
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800425 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700426 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700427 __func__, ha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700428 } else {
429 DEBUG11(printk("%s(%ld): done.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700430 ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700431 }
432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434 return rval;
435}
436
437/*
438 * qla2x00_get_fw_version
439 * Get firmware version.
440 *
441 * Input:
442 * ha: adapter state pointer.
443 * major: pointer for major number.
444 * minor: pointer for minor number.
445 * subminor: pointer for subminor number.
446 *
447 * Returns:
448 * qla2x00 local function return status code.
449 *
450 * Context:
451 * Kernel context.
452 */
453void
454qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
455 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
456{
457 int rval;
458 mbx_cmd_t mc;
459 mbx_cmd_t *mcp = &mc;
460
461 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
462
463 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
464 mcp->out_mb = MBX_0;
465 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
466 mcp->flags = 0;
467 mcp->tov = 30;
468 rval = qla2x00_mailbox_command(ha, mcp);
469
470 /* Return mailbox data. */
471 *major = mcp->mb[1];
472 *minor = mcp->mb[2];
473 *subminor = mcp->mb[3];
474 *attributes = mcp->mb[6];
475 if (IS_QLA2100(ha) || IS_QLA2200(ha))
476 *memory = 0x1FFFF; /* Defaults to 128KB. */
477 else
478 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
479
480 if (rval != QLA_SUCCESS) {
481 /*EMPTY*/
482 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
483 ha->host_no, rval));
484 } else {
485 /*EMPTY*/
486 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
487 }
488}
489
490/*
491 * qla2x00_get_fw_options
492 * Set firmware options.
493 *
494 * Input:
495 * ha = adapter block pointer.
496 * fwopt = pointer for firmware options.
497 *
498 * Returns:
499 * qla2x00 local function return status code.
500 *
501 * Context:
502 * Kernel context.
503 */
504int
505qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
506{
507 int rval;
508 mbx_cmd_t mc;
509 mbx_cmd_t *mcp = &mc;
510
511 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
512
513 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
514 mcp->out_mb = MBX_0;
515 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
516 mcp->tov = 30;
517 mcp->flags = 0;
518 rval = qla2x00_mailbox_command(ha, mcp);
519
520 if (rval != QLA_SUCCESS) {
521 /*EMPTY*/
522 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
523 ha->host_no, rval));
524 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700525 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 fwopts[1] = mcp->mb[1];
527 fwopts[2] = mcp->mb[2];
528 fwopts[3] = mcp->mb[3];
529
530 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
531 }
532
533 return rval;
534}
535
536
537/*
538 * qla2x00_set_fw_options
539 * Set firmware options.
540 *
541 * Input:
542 * ha = adapter block pointer.
543 * fwopt = pointer for firmware options.
544 *
545 * Returns:
546 * qla2x00 local function return status code.
547 *
548 * Context:
549 * Kernel context.
550 */
551int
552qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
553{
554 int rval;
555 mbx_cmd_t mc;
556 mbx_cmd_t *mcp = &mc;
557
558 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
559
560 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
561 mcp->mb[1] = fwopts[1];
562 mcp->mb[2] = fwopts[2];
563 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700564 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 mcp->in_mb = MBX_0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800566 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700567 mcp->in_mb |= MBX_1;
568 } else {
569 mcp->mb[10] = fwopts[10];
570 mcp->mb[11] = fwopts[11];
571 mcp->mb[12] = 0; /* Undocumented, but used */
572 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 mcp->tov = 30;
575 mcp->flags = 0;
576 rval = qla2x00_mailbox_command(ha, mcp);
577
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700578 fwopts[0] = mcp->mb[0];
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 if (rval != QLA_SUCCESS) {
581 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700582 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
583 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 } else {
585 /*EMPTY*/
586 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
587 }
588
589 return rval;
590}
591
592/*
593 * qla2x00_mbx_reg_test
594 * Mailbox register wrap test.
595 *
596 * Input:
597 * ha = adapter block pointer.
598 * TARGET_QUEUE_LOCK must be released.
599 * ADAPTER_STATE_LOCK must be released.
600 *
601 * Returns:
602 * qla2x00 local function return status code.
603 *
604 * Context:
605 * Kernel context.
606 */
607int
608qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
609{
610 int rval;
611 mbx_cmd_t mc;
612 mbx_cmd_t *mcp = &mc;
613
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700614 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
617 mcp->mb[1] = 0xAAAA;
618 mcp->mb[2] = 0x5555;
619 mcp->mb[3] = 0xAA55;
620 mcp->mb[4] = 0x55AA;
621 mcp->mb[5] = 0xA5A5;
622 mcp->mb[6] = 0x5A5A;
623 mcp->mb[7] = 0x2525;
624 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
625 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
626 mcp->tov = 30;
627 mcp->flags = 0;
628 rval = qla2x00_mailbox_command(ha, mcp);
629
630 if (rval == QLA_SUCCESS) {
631 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
632 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
633 rval = QLA_FUNCTION_FAILED;
634 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
635 mcp->mb[7] != 0x2525)
636 rval = QLA_FUNCTION_FAILED;
637 }
638
639 if (rval != QLA_SUCCESS) {
640 /*EMPTY*/
641 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700642 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 } else {
644 /*EMPTY*/
645 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700646 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648
649 return rval;
650}
651
652/*
653 * qla2x00_verify_checksum
654 * Verify firmware checksum.
655 *
656 * Input:
657 * ha = adapter block pointer.
658 * TARGET_QUEUE_LOCK must be released.
659 * ADAPTER_STATE_LOCK must be released.
660 *
661 * Returns:
662 * qla2x00 local function return status code.
663 *
664 * Context:
665 * Kernel context.
666 */
667int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700668qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669{
670 int rval;
671 mbx_cmd_t mc;
672 mbx_cmd_t *mcp = &mc;
673
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700674 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700677 mcp->out_mb = MBX_0;
678 mcp->in_mb = MBX_0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800679 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700680 mcp->mb[1] = MSW(risc_addr);
681 mcp->mb[2] = LSW(risc_addr);
682 mcp->out_mb |= MBX_2|MBX_1;
683 mcp->in_mb |= MBX_2|MBX_1;
684 } else {
685 mcp->mb[1] = LSW(risc_addr);
686 mcp->out_mb |= MBX_1;
687 mcp->in_mb |= MBX_1;
688 }
689
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 mcp->tov = 30;
691 mcp->flags = 0;
692 rval = qla2x00_mailbox_command(ha, mcp);
693
694 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700695 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800696 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700697 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700699 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701
702 return rval;
703}
704
705/*
706 * qla2x00_issue_iocb
707 * Issue IOCB using mailbox command
708 *
709 * Input:
710 * ha = adapter state pointer.
711 * buffer = buffer pointer.
712 * phys_addr = physical address of buffer.
713 * size = size of buffer.
714 * TARGET_QUEUE_LOCK must be released.
715 * ADAPTER_STATE_LOCK must be released.
716 *
717 * Returns:
718 * qla2x00 local function return status code.
719 *
720 * Context:
721 * Kernel context.
722 */
723int
724qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
725 size_t size)
726{
727 int rval;
728 mbx_cmd_t mc;
729 mbx_cmd_t *mcp = &mc;
730
731 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
732 mcp->mb[1] = 0;
733 mcp->mb[2] = MSW(phys_addr);
734 mcp->mb[3] = LSW(phys_addr);
735 mcp->mb[6] = MSW(MSD(phys_addr));
736 mcp->mb[7] = LSW(MSD(phys_addr));
737 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
738 mcp->in_mb = MBX_2|MBX_0;
739 mcp->tov = 30;
740 mcp->flags = 0;
741 rval = qla2x00_mailbox_command(ha, mcp);
742
743 if (rval != QLA_SUCCESS) {
744 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700745 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700746 ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700747 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700748 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700750 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
751
752 /* Mask reserved bits. */
753 sts_entry->entry_status &=
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -0800754 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RF_MASK_24XX :RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 }
756
757 return rval;
758}
759
760/*
761 * qla2x00_abort_command
762 * Abort command aborts a specified IOCB.
763 *
764 * Input:
765 * ha = adapter block pointer.
766 * sp = SB structure pointer.
767 *
768 * Returns:
769 * qla2x00 local function return status code.
770 *
771 * Context:
772 * Kernel context.
773 */
774int
775qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
776{
777 unsigned long flags = 0;
778 fc_port_t *fcport;
779 int rval;
780 uint32_t handle;
781 mbx_cmd_t mc;
782 mbx_cmd_t *mcp = &mc;
783
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700784 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785
bdf79622005-04-17 15:06:53 -0500786 fcport = sp->fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 spin_lock_irqsave(&ha->hardware_lock, flags);
789 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
790 if (ha->outstanding_cmds[handle] == sp)
791 break;
792 }
793 spin_unlock_irqrestore(&ha->hardware_lock, flags);
794
795 if (handle == MAX_OUTSTANDING_COMMANDS) {
796 /* command not found */
797 return QLA_FUNCTION_FAILED;
798 }
799
800 mcp->mb[0] = MBC_ABORT_COMMAND;
801 if (HAS_EXTENDED_IDS(ha))
802 mcp->mb[1] = fcport->loop_id;
803 else
804 mcp->mb[1] = fcport->loop_id << 8;
805 mcp->mb[2] = (uint16_t)handle;
806 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500807 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
809 mcp->in_mb = MBX_0;
810 mcp->tov = 30;
811 mcp->flags = 0;
812 rval = qla2x00_mailbox_command(ha, mcp);
813
814 if (rval != QLA_SUCCESS) {
815 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700816 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 } else {
818 sp->flags |= SRB_ABORT_PENDING;
819 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700820 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 }
822
823 return rval;
824}
825
826#if USE_ABORT_TGT
827/*
828 * qla2x00_abort_target
829 * Issue abort target mailbox command.
830 *
831 * Input:
832 * ha = adapter block pointer.
833 *
834 * Returns:
835 * qla2x00 local function return status code.
836 *
837 * Context:
838 * Kernel context.
839 */
840int
841qla2x00_abort_target(fc_port_t *fcport)
842{
843 int rval;
844 mbx_cmd_t mc;
845 mbx_cmd_t *mcp = &mc;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700846 scsi_qla_host_t *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700848 if (fcport == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700851 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700852
853 ha = fcport->ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 mcp->mb[0] = MBC_ABORT_TARGET;
855 mcp->out_mb = MBX_2|MBX_1|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700856 if (HAS_EXTENDED_IDS(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 mcp->mb[1] = fcport->loop_id;
858 mcp->mb[10] = 0;
859 mcp->out_mb |= MBX_10;
860 } else {
861 mcp->mb[1] = fcport->loop_id << 8;
862 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700863 mcp->mb[2] = ha->loop_reset_delay;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 mcp->in_mb = MBX_0;
866 mcp->tov = 30;
867 mcp->flags = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700868 rval = qla2x00_mailbox_command(ha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
870 /* Issue marker command. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700871 ha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 if (rval != QLA_SUCCESS) {
874 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700875 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 } else {
877 /*EMPTY*/
878 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700879 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 }
881
882 return rval;
883}
884#endif
885
886/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 * qla2x00_get_adapter_id
888 * Get adapter ID and topology.
889 *
890 * Input:
891 * ha = adapter block pointer.
892 * id = pointer for loop ID.
893 * al_pa = pointer for AL_PA.
894 * area = pointer for area.
895 * domain = pointer for domain.
896 * top = pointer for topology.
897 * TARGET_QUEUE_LOCK must be released.
898 * ADAPTER_STATE_LOCK must be released.
899 *
900 * Returns:
901 * qla2x00 local function return status code.
902 *
903 * Context:
904 * Kernel context.
905 */
906int
907qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
908 uint8_t *area, uint8_t *domain, uint16_t *top)
909{
910 int rval;
911 mbx_cmd_t mc;
912 mbx_cmd_t *mcp = &mc;
913
914 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700915 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
918 mcp->out_mb = MBX_0;
919 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
920 mcp->tov = 30;
921 mcp->flags = 0;
922 rval = qla2x00_mailbox_command(ha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800923 if (mcp->mb[0] == MBS_COMMAND_ERROR)
924 rval = QLA_COMMAND_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /* Return data. */
927 *id = mcp->mb[1];
928 *al_pa = LSB(mcp->mb[2]);
929 *area = MSB(mcp->mb[2]);
930 *domain = LSB(mcp->mb[3]);
931 *top = mcp->mb[6];
932
933 if (rval != QLA_SUCCESS) {
934 /*EMPTY*/
935 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700936 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 } else {
938 /*EMPTY*/
939 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700940 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 }
942
943 return rval;
944}
945
946/*
947 * qla2x00_get_retry_cnt
948 * Get current firmware login retry count and delay.
949 *
950 * Input:
951 * ha = adapter block pointer.
952 * retry_cnt = pointer to login retry count.
953 * tov = pointer to login timeout value.
954 *
955 * Returns:
956 * qla2x00 local function return status code.
957 *
958 * Context:
959 * Kernel context.
960 */
961int
962qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
963 uint16_t *r_a_tov)
964{
965 int rval;
966 uint16_t ratov;
967 mbx_cmd_t mc;
968 mbx_cmd_t *mcp = &mc;
969
970 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700971 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 mcp->mb[0] = MBC_GET_RETRY_COUNT;
974 mcp->out_mb = MBX_0;
975 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
976 mcp->tov = 30;
977 mcp->flags = 0;
978 rval = qla2x00_mailbox_command(ha, mcp);
979
980 if (rval != QLA_SUCCESS) {
981 /*EMPTY*/
982 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700983 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 } else {
985 /* Convert returned data and check our values. */
986 *r_a_tov = mcp->mb[3] / 2;
987 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
988 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
989 /* Update to the larger values */
990 *retry_cnt = (uint8_t)mcp->mb[1];
991 *tov = ratov;
992 }
993
994 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700995 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 }
997
998 return rval;
999}
1000
1001/*
1002 * qla2x00_init_firmware
1003 * Initialize adapter firmware.
1004 *
1005 * Input:
1006 * ha = adapter block pointer.
1007 * dptr = Initialization control block pointer.
1008 * size = size of initialization control block.
1009 * TARGET_QUEUE_LOCK must be released.
1010 * ADAPTER_STATE_LOCK must be released.
1011 *
1012 * Returns:
1013 * qla2x00 local function return status code.
1014 *
1015 * Context:
1016 * Kernel context.
1017 */
1018int
1019qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1020{
1021 int rval;
1022 mbx_cmd_t mc;
1023 mbx_cmd_t *mcp = &mc;
1024
1025 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001026 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027
1028 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1029 mcp->mb[2] = MSW(ha->init_cb_dma);
1030 mcp->mb[3] = LSW(ha->init_cb_dma);
1031 mcp->mb[4] = 0;
1032 mcp->mb[5] = 0;
1033 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1034 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1035 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1036 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1037 mcp->buf_size = size;
1038 mcp->flags = MBX_DMA_OUT;
1039 mcp->tov = 30;
1040 rval = qla2x00_mailbox_command(ha, mcp);
1041
1042 if (rval != QLA_SUCCESS) {
1043 /*EMPTY*/
1044 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1045 "mb0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001046 ha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 } else {
1048 /*EMPTY*/
1049 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001050 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 }
1052
1053 return rval;
1054}
1055
1056/*
1057 * qla2x00_get_port_database
1058 * Issue normal/enhanced get port database mailbox command
1059 * and copy device name as necessary.
1060 *
1061 * Input:
1062 * ha = adapter state pointer.
1063 * dev = structure pointer.
1064 * opt = enhanced cmd option byte.
1065 *
1066 * Returns:
1067 * qla2x00 local function return status code.
1068 *
1069 * Context:
1070 * Kernel context.
1071 */
1072int
1073qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1074{
1075 int rval;
1076 mbx_cmd_t mc;
1077 mbx_cmd_t *mcp = &mc;
1078 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001079 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 dma_addr_t pd_dma;
1081
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001082 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001084 pd24 = NULL;
1085 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001087 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1088 "structure.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 return QLA_MEMORY_ALLOC_FAILED;
1090 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001091 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001093 mcp->mb[0] = MBC_GET_PORT_DATABASE;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001094 if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA54XX(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 mcp->mb[2] = MSW(pd_dma);
1097 mcp->mb[3] = LSW(pd_dma);
1098 mcp->mb[6] = MSW(MSD(pd_dma));
1099 mcp->mb[7] = LSW(MSD(pd_dma));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001100 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 mcp->in_mb = MBX_0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001102 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001103 mcp->mb[1] = fcport->loop_id;
1104 mcp->mb[10] = opt;
1105 mcp->out_mb |= MBX_10|MBX_1;
1106 mcp->in_mb |= MBX_1;
1107 } else if (HAS_EXTENDED_IDS(ha)) {
1108 mcp->mb[1] = fcport->loop_id;
1109 mcp->mb[10] = opt;
1110 mcp->out_mb |= MBX_10|MBX_1;
1111 } else {
1112 mcp->mb[1] = fcport->loop_id << 8 | opt;
1113 mcp->out_mb |= MBX_1;
1114 }
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001115 mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001116 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 mcp->flags = MBX_DMA_IN;
1118 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1119 rval = qla2x00_mailbox_command(ha, mcp);
1120 if (rval != QLA_SUCCESS)
1121 goto gpd_error_out;
1122
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001123 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001124 pd24 = (struct port_database_24xx *) pd;
1125
1126 /* Check for logged in state. */
1127 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1128 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1129 DEBUG2(printk("%s(%ld): Unable to verify "
1130 "login-state (%x/%x) for loop_id %x\n",
1131 __func__, ha->host_no,
1132 pd24->current_login_state,
1133 pd24->last_login_state, fcport->loop_id));
1134 rval = QLA_FUNCTION_FAILED;
1135 goto gpd_error_out;
1136 }
1137
1138 /* Names are little-endian. */
1139 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1140 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1141
1142 /* Get port_id of device. */
1143 fcport->d_id.b.domain = pd24->port_id[0];
1144 fcport->d_id.b.area = pd24->port_id[1];
1145 fcport->d_id.b.al_pa = pd24->port_id[2];
1146 fcport->d_id.b.rsvd_1 = 0;
1147
1148 /* If not target must be initiator or unknown type. */
1149 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1150 fcport->port_type = FCT_INITIATOR;
1151 else
1152 fcport->port_type = FCT_TARGET;
1153 } else {
1154 /* Check for logged in state. */
1155 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1156 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1157 rval = QLA_FUNCTION_FAILED;
1158 goto gpd_error_out;
1159 }
1160
1161 /* Names are little-endian. */
1162 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1163 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1164
1165 /* Get port_id of device. */
1166 fcport->d_id.b.domain = pd->port_id[0];
1167 fcport->d_id.b.area = pd->port_id[3];
1168 fcport->d_id.b.al_pa = pd->port_id[2];
1169 fcport->d_id.b.rsvd_1 = 0;
1170
1171 /* Check for device require authentication. */
1172 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1173 (fcport->flags &= ~FCF_AUTH_REQ);
1174
1175 /* If not target must be initiator or unknown type. */
1176 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1177 fcport->port_type = FCT_INITIATOR;
1178 else
1179 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001180
1181 /* Passback COS information. */
1182 fcport->supported_classes = (pd->options & BIT_4) ?
1183 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186gpd_error_out:
1187 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1188
1189 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001190 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1191 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001193 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 }
1195
1196 return rval;
1197}
1198
1199/*
1200 * qla2x00_get_firmware_state
1201 * Get adapter firmware state.
1202 *
1203 * Input:
1204 * ha = adapter block pointer.
1205 * dptr = pointer for firmware state.
1206 * TARGET_QUEUE_LOCK must be released.
1207 * ADAPTER_STATE_LOCK must be released.
1208 *
1209 * Returns:
1210 * qla2x00 local function return status code.
1211 *
1212 * Context:
1213 * Kernel context.
1214 */
1215int
1216qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1217{
1218 int rval;
1219 mbx_cmd_t mc;
1220 mbx_cmd_t *mcp = &mc;
1221
1222 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001223 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1226 mcp->out_mb = MBX_0;
1227 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1228 mcp->tov = 30;
1229 mcp->flags = 0;
1230 rval = qla2x00_mailbox_command(ha, mcp);
1231
1232 /* Return firmware state. */
1233 *dptr = mcp->mb[1];
1234
1235 if (rval != QLA_SUCCESS) {
1236 /*EMPTY*/
1237 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001238 "failed=%x.\n", ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 } else {
1240 /*EMPTY*/
1241 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001242 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 }
1244
1245 return rval;
1246}
1247
1248/*
1249 * qla2x00_get_port_name
1250 * Issue get port name mailbox command.
1251 * Returned name is in big endian format.
1252 *
1253 * Input:
1254 * ha = adapter block pointer.
1255 * loop_id = loop ID of device.
1256 * name = pointer for name.
1257 * TARGET_QUEUE_LOCK must be released.
1258 * ADAPTER_STATE_LOCK must be released.
1259 *
1260 * Returns:
1261 * qla2x00 local function return status code.
1262 *
1263 * Context:
1264 * Kernel context.
1265 */
1266int
1267qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1268 uint8_t opt)
1269{
1270 int rval;
1271 mbx_cmd_t mc;
1272 mbx_cmd_t *mcp = &mc;
1273
1274 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001275 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 mcp->mb[0] = MBC_GET_PORT_NAME;
1278 mcp->out_mb = MBX_1|MBX_0;
1279 if (HAS_EXTENDED_IDS(ha)) {
1280 mcp->mb[1] = loop_id;
1281 mcp->mb[10] = opt;
1282 mcp->out_mb |= MBX_10;
1283 } else {
1284 mcp->mb[1] = loop_id << 8 | opt;
1285 }
1286
1287 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1288 mcp->tov = 30;
1289 mcp->flags = 0;
1290 rval = qla2x00_mailbox_command(ha, mcp);
1291
1292 if (rval != QLA_SUCCESS) {
1293 /*EMPTY*/
1294 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001295 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 } else {
1297 if (name != NULL) {
1298 /* This function returns name in big endian. */
1299 name[0] = LSB(mcp->mb[2]);
1300 name[1] = MSB(mcp->mb[2]);
1301 name[2] = LSB(mcp->mb[3]);
1302 name[3] = MSB(mcp->mb[3]);
1303 name[4] = LSB(mcp->mb[6]);
1304 name[5] = MSB(mcp->mb[6]);
1305 name[6] = LSB(mcp->mb[7]);
1306 name[7] = MSB(mcp->mb[7]);
1307 }
1308
1309 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001310 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312
1313 return rval;
1314}
1315
1316/*
1317 * qla2x00_lip_reset
1318 * Issue LIP reset mailbox command.
1319 *
1320 * Input:
1321 * ha = adapter block pointer.
1322 * TARGET_QUEUE_LOCK must be released.
1323 * ADAPTER_STATE_LOCK must be released.
1324 *
1325 * Returns:
1326 * qla2x00 local function return status code.
1327 *
1328 * Context:
1329 * Kernel context.
1330 */
1331int
1332qla2x00_lip_reset(scsi_qla_host_t *ha)
1333{
1334 int rval;
1335 mbx_cmd_t mc;
1336 mbx_cmd_t *mcp = &mc;
1337
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001338 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001341 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1342 mcp->mb[1] = BIT_0;
1343 mcp->mb[2] = 0xff;
1344 mcp->mb[3] = 0;
1345 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001347 mcp->mb[0] = MBC_LIP_RESET;
1348 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1349 if (HAS_EXTENDED_IDS(ha)) {
1350 mcp->mb[1] = 0x00ff;
1351 mcp->mb[10] = 0;
1352 mcp->out_mb |= MBX_10;
1353 } else {
1354 mcp->mb[1] = 0xff00;
1355 }
1356 mcp->mb[2] = ha->loop_reset_delay;
1357 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 mcp->in_mb = MBX_0;
1360 mcp->tov = 30;
1361 mcp->flags = 0;
1362 rval = qla2x00_mailbox_command(ha, mcp);
1363
1364 if (rval != QLA_SUCCESS) {
1365 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001366 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001367 __func__, ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 } else {
1369 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001370 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
1372
1373 return rval;
1374}
1375
1376/*
1377 * qla2x00_send_sns
1378 * Send SNS command.
1379 *
1380 * Input:
1381 * ha = adapter block pointer.
1382 * sns = pointer for command.
1383 * cmd_size = command size.
1384 * buf_size = response/command size.
1385 * TARGET_QUEUE_LOCK must be released.
1386 * ADAPTER_STATE_LOCK must be released.
1387 *
1388 * Returns:
1389 * qla2x00 local function return status code.
1390 *
1391 * Context:
1392 * Kernel context.
1393 */
1394int
1395qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1396 uint16_t cmd_size, size_t buf_size)
1397{
1398 int rval;
1399 mbx_cmd_t mc;
1400 mbx_cmd_t *mcp = &mc;
1401
1402 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001403 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404
1405 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001406 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
1408 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1409 mcp->mb[1] = cmd_size;
1410 mcp->mb[2] = MSW(sns_phys_address);
1411 mcp->mb[3] = LSW(sns_phys_address);
1412 mcp->mb[6] = MSW(MSD(sns_phys_address));
1413 mcp->mb[7] = LSW(MSD(sns_phys_address));
1414 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1415 mcp->in_mb = MBX_0|MBX_1;
1416 mcp->buf_size = buf_size;
1417 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1418 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1419 rval = qla2x00_mailbox_command(ha, mcp);
1420
1421 if (rval != QLA_SUCCESS) {
1422 /*EMPTY*/
1423 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001424 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001426 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 } else {
1428 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001429 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431
1432 return rval;
1433}
1434
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001435int
1436qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1437 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1438{
1439 int rval;
1440
1441 struct logio_entry_24xx *lg;
1442 dma_addr_t lg_dma;
1443 uint32_t iop[2];
1444
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001446
1447 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1448 if (lg == NULL) {
1449 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1450 __func__, ha->host_no));
1451 return QLA_MEMORY_ALLOC_FAILED;
1452 }
1453 memset(lg, 0, sizeof(struct logio_entry_24xx));
1454
1455 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1456 lg->entry_count = 1;
1457 lg->nport_handle = cpu_to_le16(loop_id);
1458 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1459 if (opt & BIT_0)
1460 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001461 if (opt & BIT_1)
1462 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001463 lg->port_id[0] = al_pa;
1464 lg->port_id[1] = area;
1465 lg->port_id[2] = domain;
1466 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1467 if (rval != QLA_SUCCESS) {
1468 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001469 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001470 } else if (lg->entry_status != 0) {
1471 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1472 "-- error status (%x).\n", __func__, ha->host_no,
1473 lg->entry_status));
1474 rval = QLA_FUNCTION_FAILED;
1475 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1476 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1477 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1478
1479 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1480 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1481 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1482 iop[1]));
1483
1484 switch (iop[0]) {
1485 case LSC_SCODE_PORTID_USED:
1486 mb[0] = MBS_PORT_ID_USED;
1487 mb[1] = LSW(iop[1]);
1488 break;
1489 case LSC_SCODE_NPORT_USED:
1490 mb[0] = MBS_LOOP_ID_USED;
1491 break;
1492 case LSC_SCODE_NOLINK:
1493 case LSC_SCODE_NOIOCB:
1494 case LSC_SCODE_NOXCB:
1495 case LSC_SCODE_CMD_FAILED:
1496 case LSC_SCODE_NOFABRIC:
1497 case LSC_SCODE_FW_NOT_READY:
1498 case LSC_SCODE_NOT_LOGGED_IN:
1499 case LSC_SCODE_NOPCB:
1500 case LSC_SCODE_ELS_REJECT:
1501 case LSC_SCODE_CMD_PARAM_ERR:
1502 case LSC_SCODE_NONPORT:
1503 case LSC_SCODE_LOGGED_IN:
1504 case LSC_SCODE_NOFLOGI_ACC:
1505 default:
1506 mb[0] = MBS_COMMAND_ERROR;
1507 break;
1508 }
1509 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001510 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001511
1512 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1513
1514 mb[0] = MBS_COMMAND_COMPLETE;
1515 mb[1] = 0;
1516 if (iop[0] & BIT_4) {
1517 if (iop[0] & BIT_8)
1518 mb[1] |= BIT_1;
1519 } else
1520 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001521
1522 /* Passback COS information. */
1523 mb[10] = 0;
1524 if (lg->io_parameter[7] || lg->io_parameter[8])
1525 mb[10] |= BIT_0; /* Class 2. */
1526 if (lg->io_parameter[9] || lg->io_parameter[10])
1527 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001528 }
1529
1530 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1531
1532 return rval;
1533}
1534
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535/*
1536 * qla2x00_login_fabric
1537 * Issue login fabric port mailbox command.
1538 *
1539 * Input:
1540 * ha = adapter block pointer.
1541 * loop_id = device loop ID.
1542 * domain = device domain.
1543 * area = device area.
1544 * al_pa = device AL_PA.
1545 * status = pointer for return status.
1546 * opt = command options.
1547 * TARGET_QUEUE_LOCK must be released.
1548 * ADAPTER_STATE_LOCK must be released.
1549 *
1550 * Returns:
1551 * qla2x00 local function return status code.
1552 *
1553 * Context:
1554 * Kernel context.
1555 */
1556int
1557qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1558 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1559{
1560 int rval;
1561 mbx_cmd_t mc;
1562 mbx_cmd_t *mcp = &mc;
1563
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001564 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1567 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1568 if (HAS_EXTENDED_IDS(ha)) {
1569 mcp->mb[1] = loop_id;
1570 mcp->mb[10] = opt;
1571 mcp->out_mb |= MBX_10;
1572 } else {
1573 mcp->mb[1] = (loop_id << 8) | opt;
1574 }
1575 mcp->mb[2] = domain;
1576 mcp->mb[3] = area << 8 | al_pa;
1577
1578 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1579 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1580 mcp->flags = 0;
1581 rval = qla2x00_mailbox_command(ha, mcp);
1582
1583 /* Return mailbox statuses. */
1584 if (mb != NULL) {
1585 mb[0] = mcp->mb[0];
1586 mb[1] = mcp->mb[1];
1587 mb[2] = mcp->mb[2];
1588 mb[6] = mcp->mb[6];
1589 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001590 /* COS retrieved from Get-Port-Database mailbox command. */
1591 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 }
1593
1594 if (rval != QLA_SUCCESS) {
1595 /* RLU tmp code: need to change main mailbox_command function to
1596 * return ok even when the mailbox completion value is not
1597 * SUCCESS. The caller needs to be responsible to interpret
1598 * the return values of this mailbox command if we're not
1599 * to change too much of the existing code.
1600 */
1601 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1602 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1603 mcp->mb[0] == 0x4006)
1604 rval = QLA_SUCCESS;
1605
1606 /*EMPTY*/
1607 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1608 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001609 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 } else {
1611 /*EMPTY*/
1612 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001613 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 }
1615
1616 return rval;
1617}
1618
1619/*
1620 * qla2x00_login_local_device
1621 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001622 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 * Input:
1624 * ha = adapter block pointer.
1625 * loop_id = device loop ID.
1626 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001627 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 * Returns:
1629 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001630 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 * Context:
1632 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001633 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 */
1635int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001636qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 uint16_t *mb_ret, uint8_t opt)
1638{
1639 int rval;
1640 mbx_cmd_t mc;
1641 mbx_cmd_t *mcp = &mc;
1642
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001643 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
1644 return qla24xx_login_fabric(ha, fcport->loop_id,
1645 fcport->d_id.b.domain, fcport->d_id.b.area,
1646 fcport->d_id.b.al_pa, mb_ret, opt);
1647
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001648 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1651 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001652 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001654 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 mcp->mb[2] = opt;
1656 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1657 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1658 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1659 mcp->flags = 0;
1660 rval = qla2x00_mailbox_command(ha, mcp);
1661
1662 /* Return mailbox statuses. */
1663 if (mb_ret != NULL) {
1664 mb_ret[0] = mcp->mb[0];
1665 mb_ret[1] = mcp->mb[1];
1666 mb_ret[6] = mcp->mb[6];
1667 mb_ret[7] = mcp->mb[7];
1668 }
1669
1670 if (rval != QLA_SUCCESS) {
1671 /* AV tmp code: need to change main mailbox_command function to
1672 * return ok even when the mailbox completion value is not
1673 * SUCCESS. The caller needs to be responsible to interpret
1674 * the return values of this mailbox command if we're not
1675 * to change too much of the existing code.
1676 */
1677 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1678 rval = QLA_SUCCESS;
1679
1680 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1681 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001682 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1684 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001685 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 } else {
1687 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001688 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 }
1690
1691 return (rval);
1692}
1693
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001694int
1695qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1696 uint8_t area, uint8_t al_pa)
1697{
1698 int rval;
1699 struct logio_entry_24xx *lg;
1700 dma_addr_t lg_dma;
1701
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001702 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001703
1704 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1705 if (lg == NULL) {
1706 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1707 __func__, ha->host_no));
1708 return QLA_MEMORY_ALLOC_FAILED;
1709 }
1710 memset(lg, 0, sizeof(struct logio_entry_24xx));
1711
1712 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1713 lg->entry_count = 1;
1714 lg->nport_handle = cpu_to_le16(loop_id);
1715 lg->control_flags =
1716 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO);
1717 lg->port_id[0] = al_pa;
1718 lg->port_id[1] = area;
1719 lg->port_id[2] = domain;
1720 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1721 if (rval != QLA_SUCCESS) {
1722 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001723 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001724 } else if (lg->entry_status != 0) {
1725 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1726 "-- error status (%x).\n", __func__, ha->host_no,
1727 lg->entry_status));
1728 rval = QLA_FUNCTION_FAILED;
1729 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1730 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1731 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1732 ha->host_no, le16_to_cpu(lg->comp_status),
1733 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001734 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001735 } else {
1736 /*EMPTY*/
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001737 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001738 }
1739
1740 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1741
1742 return rval;
1743}
1744
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745/*
1746 * qla2x00_fabric_logout
1747 * Issue logout fabric port mailbox command.
1748 *
1749 * Input:
1750 * ha = adapter block pointer.
1751 * loop_id = device loop ID.
1752 * TARGET_QUEUE_LOCK must be released.
1753 * ADAPTER_STATE_LOCK must be released.
1754 *
1755 * Returns:
1756 * qla2x00 local function return status code.
1757 *
1758 * Context:
1759 * Kernel context.
1760 */
1761int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001762qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1763 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
1765 int rval;
1766 mbx_cmd_t mc;
1767 mbx_cmd_t *mcp = &mc;
1768
1769 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001770 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1773 mcp->out_mb = MBX_1|MBX_0;
1774 if (HAS_EXTENDED_IDS(ha)) {
1775 mcp->mb[1] = loop_id;
1776 mcp->mb[10] = 0;
1777 mcp->out_mb |= MBX_10;
1778 } else {
1779 mcp->mb[1] = loop_id << 8;
1780 }
1781
1782 mcp->in_mb = MBX_1|MBX_0;
1783 mcp->tov = 30;
1784 mcp->flags = 0;
1785 rval = qla2x00_mailbox_command(ha, mcp);
1786
1787 if (rval != QLA_SUCCESS) {
1788 /*EMPTY*/
1789 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001790 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 } else {
1792 /*EMPTY*/
1793 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001794 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 }
1796
1797 return rval;
1798}
1799
1800/*
1801 * qla2x00_full_login_lip
1802 * Issue full login LIP mailbox command.
1803 *
1804 * Input:
1805 * ha = adapter block pointer.
1806 * TARGET_QUEUE_LOCK must be released.
1807 * ADAPTER_STATE_LOCK must be released.
1808 *
1809 * Returns:
1810 * qla2x00 local function return status code.
1811 *
1812 * Context:
1813 * Kernel context.
1814 */
1815int
1816qla2x00_full_login_lip(scsi_qla_host_t *ha)
1817{
1818 int rval;
1819 mbx_cmd_t mc;
1820 mbx_cmd_t *mcp = &mc;
1821
1822 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001823 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824
1825 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1826 mcp->mb[1] = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001827 mcp->mb[2] = 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 mcp->mb[3] = 0;
1829 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1830 mcp->in_mb = MBX_0;
1831 mcp->tov = 30;
1832 mcp->flags = 0;
1833 rval = qla2x00_mailbox_command(ha, mcp);
1834
1835 if (rval != QLA_SUCCESS) {
1836 /*EMPTY*/
1837 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001838 ha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 } else {
1840 /*EMPTY*/
1841 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001842 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 }
1844
1845 return rval;
1846}
1847
1848/*
1849 * qla2x00_get_id_list
1850 *
1851 * Input:
1852 * ha = adapter block pointer.
1853 *
1854 * Returns:
1855 * qla2x00 local function return status code.
1856 *
1857 * Context:
1858 * Kernel context.
1859 */
1860int
1861qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1862 uint16_t *entries)
1863{
1864 int rval;
1865 mbx_cmd_t mc;
1866 mbx_cmd_t *mcp = &mc;
1867
1868 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001869 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 if (id_list == NULL)
1872 return QLA_FUNCTION_FAILED;
1873
1874 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001875 mcp->out_mb = MBX_0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001876 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001877 mcp->mb[2] = MSW(id_list_dma);
1878 mcp->mb[3] = LSW(id_list_dma);
1879 mcp->mb[6] = MSW(MSD(id_list_dma));
1880 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001881 mcp->mb[8] = 0;
1882 mcp->out_mb |= 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,
1923 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
1924{
1925 int rval;
1926 mbx_cmd_t mc;
1927 mbx_cmd_t *mcp = &mc;
1928
1929 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1930
1931 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1932 mcp->out_mb = MBX_0;
1933 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1934 mcp->tov = 30;
1935 mcp->flags = 0;
1936 rval = qla2x00_mailbox_command(ha, mcp);
1937
1938 if (rval != QLA_SUCCESS) {
1939 /*EMPTY*/
1940 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001941 ha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 } else {
1943 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1944 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001945 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 mcp->mb[10]));
1947
1948 if (cur_xchg_cnt)
1949 *cur_xchg_cnt = mcp->mb[3];
1950 if (orig_xchg_cnt)
1951 *orig_xchg_cnt = mcp->mb[6];
1952 if (cur_iocb_cnt)
1953 *cur_iocb_cnt = mcp->mb[7];
1954 if (orig_iocb_cnt)
1955 *orig_iocb_cnt = mcp->mb[10];
1956 }
1957
1958 return (rval);
1959}
1960
1961#if defined(QL_DEBUG_LEVEL_3)
1962/*
1963 * qla2x00_get_fcal_position_map
1964 * Get FCAL (LILP) position map using mailbox command
1965 *
1966 * Input:
1967 * ha = adapter state pointer.
1968 * pos_map = buffer pointer (can be NULL).
1969 *
1970 * Returns:
1971 * qla2x00 local function return status code.
1972 *
1973 * Context:
1974 * Kernel context.
1975 */
1976int
1977qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1978{
1979 int rval;
1980 mbx_cmd_t mc;
1981 mbx_cmd_t *mcp = &mc;
1982 char *pmap;
1983 dma_addr_t pmap_dma;
1984
1985 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1986 if (pmap == NULL) {
1987 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1988 __func__, ha->host_no));
1989 return QLA_MEMORY_ALLOC_FAILED;
1990 }
1991 memset(pmap, 0, FCAL_MAP_SIZE);
1992
1993 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1994 mcp->mb[2] = MSW(pmap_dma);
1995 mcp->mb[3] = LSW(pmap_dma);
1996 mcp->mb[6] = MSW(MSD(pmap_dma));
1997 mcp->mb[7] = LSW(MSD(pmap_dma));
1998 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1999 mcp->in_mb = MBX_1|MBX_0;
2000 mcp->buf_size = FCAL_MAP_SIZE;
2001 mcp->flags = MBX_DMA_IN;
2002 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2003 rval = qla2x00_mailbox_command(ha, mcp);
2004
2005 if (rval == QLA_SUCCESS) {
2006 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2007 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2008 mcp->mb[1], (unsigned)pmap[0]));
2009 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2010
2011 if (pos_map)
2012 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2013 }
2014 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2015
2016 if (rval != QLA_SUCCESS) {
2017 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2018 ha->host_no, rval));
2019 } else {
2020 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2021 }
2022
2023 return rval;
2024}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002025#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002026
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002027/*
2028 * qla2x00_get_link_status
2029 *
2030 * Input:
2031 * ha = adapter block pointer.
2032 * loop_id = device loop ID.
2033 * ret_buf = pointer to link status return buffer.
2034 *
2035 * Returns:
2036 * 0 = success.
2037 * BIT_0 = mem alloc error.
2038 * BIT_1 = mailbox error.
2039 */
2040int
2041qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2042 link_stat_t *ret_buf, uint16_t *status)
2043{
2044 int rval;
2045 mbx_cmd_t mc;
2046 mbx_cmd_t *mcp = &mc;
2047 link_stat_t *stat_buf;
2048 dma_addr_t stat_buf_dma;
2049
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002050 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002051
2052 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2053 if (stat_buf == NULL) {
2054 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2055 __func__, ha->host_no));
2056 return BIT_0;
2057 }
2058 memset(stat_buf, 0, sizeof(link_stat_t));
2059
2060 mcp->mb[0] = MBC_GET_LINK_STATUS;
2061 mcp->mb[2] = MSW(stat_buf_dma);
2062 mcp->mb[3] = LSW(stat_buf_dma);
2063 mcp->mb[6] = MSW(MSD(stat_buf_dma));
2064 mcp->mb[7] = LSW(MSD(stat_buf_dma));
2065 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2066 mcp->in_mb = MBX_0;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002067 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002068 mcp->mb[1] = loop_id;
2069 mcp->mb[4] = 0;
2070 mcp->mb[10] = 0;
2071 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2072 mcp->in_mb |= MBX_1;
2073 } else if (HAS_EXTENDED_IDS(ha)) {
2074 mcp->mb[1] = loop_id;
2075 mcp->mb[10] = 0;
2076 mcp->out_mb |= MBX_10|MBX_1;
2077 } else {
2078 mcp->mb[1] = loop_id << 8;
2079 mcp->out_mb |= MBX_1;
2080 }
2081 mcp->tov = 30;
2082 mcp->flags = IOCTL_CMD;
2083 rval = qla2x00_mailbox_command(ha, mcp);
2084
2085 if (rval == QLA_SUCCESS) {
2086 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2087 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002088 __func__, ha->host_no, mcp->mb[0]));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002089 status[0] = mcp->mb[0];
2090 rval = BIT_1;
2091 } else {
2092 /* copy over data -- firmware data is LE. */
2093 ret_buf->link_fail_cnt =
2094 le32_to_cpu(stat_buf->link_fail_cnt);
2095 ret_buf->loss_sync_cnt =
2096 le32_to_cpu(stat_buf->loss_sync_cnt);
2097 ret_buf->loss_sig_cnt =
2098 le32_to_cpu(stat_buf->loss_sig_cnt);
2099 ret_buf->prim_seq_err_cnt =
2100 le32_to_cpu(stat_buf->prim_seq_err_cnt);
2101 ret_buf->inval_xmit_word_cnt =
2102 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
2103 ret_buf->inval_crc_cnt =
2104 le32_to_cpu(stat_buf->inval_crc_cnt);
2105
2106 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2107 "loss_sync=%d loss_sig=%d seq_err=%d "
2108 "inval_xmt_word=%d inval_crc=%d.\n", __func__,
2109 ha->host_no, stat_buf->link_fail_cnt,
2110 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2111 stat_buf->prim_seq_err_cnt,
2112 stat_buf->inval_xmit_word_cnt,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002113 stat_buf->inval_crc_cnt));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002114 }
2115 } else {
2116 /* Failed. */
2117 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002118 ha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002119 rval = BIT_1;
2120 }
2121
2122 dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
2123
2124 return rval;
2125}
2126
2127int
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002128qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2129 uint16_t *status)
2130{
2131 int rval;
2132 mbx_cmd_t mc;
2133 mbx_cmd_t *mcp = &mc;
2134 uint32_t *sbuf, *siter;
2135 dma_addr_t sbuf_dma;
2136
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002137 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002138
2139 if (dwords > (DMA_POOL_SIZE / 4)) {
2140 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2141 "(max %d).\n", __func__, ha->host_no, dwords,
2142 DMA_POOL_SIZE / 4));
2143 return BIT_0;
2144 }
2145 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2146 if (sbuf == NULL) {
2147 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2148 __func__, ha->host_no));
2149 return BIT_0;
2150 }
2151 memset(sbuf, 0, DMA_POOL_SIZE);
2152
2153 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2154 mcp->mb[2] = MSW(sbuf_dma);
2155 mcp->mb[3] = LSW(sbuf_dma);
2156 mcp->mb[6] = MSW(MSD(sbuf_dma));
2157 mcp->mb[7] = LSW(MSD(sbuf_dma));
2158 mcp->mb[8] = dwords;
2159 mcp->mb[10] = 0;
2160 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2161 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2162 mcp->tov = 30;
2163 mcp->flags = IOCTL_CMD;
2164 rval = qla2x00_mailbox_command(ha, mcp);
2165
2166 if (rval == QLA_SUCCESS) {
2167 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2168 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2169 __func__, ha->host_no, mcp->mb[0]));
2170 status[0] = mcp->mb[0];
2171 rval = BIT_1;
2172 } else {
2173 /* Copy over data -- firmware data is LE. */
2174 siter = sbuf;
2175 while (dwords--)
2176 *dwbuf++ = le32_to_cpu(*siter++);
2177 }
2178 } else {
2179 /* Failed. */
2180 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2181 ha->host_no, rval));
2182 rval = BIT_1;
2183 }
2184
2185 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2186
2187 return rval;
2188}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002189
2190int
2191qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2192{
2193 int rval;
2194 fc_port_t *fcport;
2195 unsigned long flags = 0;
2196
2197 struct abort_entry_24xx *abt;
2198 dma_addr_t abt_dma;
2199 uint32_t handle;
2200
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002201 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002202
2203 fcport = sp->fcport;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002204
2205 spin_lock_irqsave(&ha->hardware_lock, flags);
2206 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2207 if (ha->outstanding_cmds[handle] == sp)
2208 break;
2209 }
2210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2211 if (handle == MAX_OUTSTANDING_COMMANDS) {
2212 /* Command not found. */
2213 return QLA_FUNCTION_FAILED;
2214 }
2215
2216 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2217 if (abt == NULL) {
2218 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2219 __func__, ha->host_no));
2220 return QLA_MEMORY_ALLOC_FAILED;
2221 }
2222 memset(abt, 0, sizeof(struct abort_entry_24xx));
2223
2224 abt->entry_type = ABORT_IOCB_TYPE;
2225 abt->entry_count = 1;
2226 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2227 abt->handle_to_abort = handle;
2228 abt->port_id[0] = fcport->d_id.b.al_pa;
2229 abt->port_id[1] = fcport->d_id.b.area;
2230 abt->port_id[2] = fcport->d_id.b.domain;
2231 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2232 if (rval != QLA_SUCCESS) {
2233 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002234 __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002235 } else if (abt->entry_status != 0) {
2236 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2237 "-- error status (%x).\n", __func__, ha->host_no,
2238 abt->entry_status));
2239 rval = QLA_FUNCTION_FAILED;
2240 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2241 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2242 "-- completion status (%x).\n", __func__, ha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002243 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002244 rval = QLA_FUNCTION_FAILED;
2245 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002246 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002247 sp->flags |= SRB_ABORT_PENDING;
2248 }
2249
2250 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2251
2252 return rval;
2253}
2254
2255struct tsk_mgmt_cmd {
2256 union {
2257 struct tsk_mgmt_entry tsk;
2258 struct sts_entry_24xx sts;
2259 } p;
2260};
2261
2262int
2263qla24xx_abort_target(fc_port_t *fcport)
2264{
2265 int rval;
2266 struct tsk_mgmt_cmd *tsk;
2267 dma_addr_t tsk_dma;
2268 scsi_qla_host_t *ha;
2269
2270 if (fcport == NULL)
2271 return 0;
2272
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002273 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002274
2275 ha = fcport->ha;
2276 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2277 if (tsk == NULL) {
2278 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2279 "IOCB.\n", __func__, ha->host_no));
2280 return QLA_MEMORY_ALLOC_FAILED;
2281 }
2282 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2283
2284 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2285 tsk->p.tsk.entry_count = 1;
2286 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2287 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2288 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2289 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2290 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2291 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2292 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2293 if (rval != QLA_SUCCESS) {
2294 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002295 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002296 goto atarget_done;
2297 } else if (tsk->p.sts.entry_status != 0) {
2298 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2299 "-- error status (%x).\n", __func__, ha->host_no,
2300 tsk->p.sts.entry_status));
2301 rval = QLA_FUNCTION_FAILED;
2302 goto atarget_done;
2303 } else if (tsk->p.sts.comp_status !=
2304 __constant_cpu_to_le16(CS_COMPLETE)) {
2305 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2306 "-- completion status (%x).\n", __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002307 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002308 rval = QLA_FUNCTION_FAILED;
2309 goto atarget_done;
2310 }
2311
2312 /* Issue marker IOCB. */
2313 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2314 if (rval != QLA_SUCCESS) {
2315 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002316 "(%x).\n", __func__, ha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002317 } else {
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002318 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002319 }
2320
2321atarget_done:
2322 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2323
2324 return rval;
2325}
2326
2327int
2328qla2x00_system_error(scsi_qla_host_t *ha)
2329{
2330 int rval;
2331 mbx_cmd_t mc;
2332 mbx_cmd_t *mcp = &mc;
2333
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002334 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002335 return QLA_FUNCTION_FAILED;
2336
2337 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2338
2339 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2340 mcp->out_mb = MBX_0;
2341 mcp->in_mb = MBX_0;
2342 mcp->tov = 5;
2343 mcp->flags = 0;
2344 rval = qla2x00_mailbox_command(ha, mcp);
2345
2346 if (rval != QLA_SUCCESS) {
2347 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2348 ha->host_no, rval));
2349 } else {
2350 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2351 }
2352
2353 return rval;
2354}
2355
2356/**
2357 * qla2x00_get_serdes_params() -
2358 * @ha: HA context
2359 *
2360 * Returns
2361 */
2362int
2363qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2364 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2365{
2366 int rval;
2367 mbx_cmd_t mc;
2368 mbx_cmd_t *mcp = &mc;
2369
2370 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2371
2372 mcp->mb[0] = MBC_SERDES_PARAMS;
2373 mcp->mb[1] = 0;
2374 mcp->out_mb = MBX_1|MBX_0;
2375 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2376 mcp->tov = 30;
2377 mcp->flags = 0;
2378 rval = qla2x00_mailbox_command(ha, mcp);
2379
2380 if (rval != QLA_SUCCESS) {
2381 /*EMPTY*/
2382 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2383 ha->host_no, rval, mcp->mb[0]));
2384 } else {
2385 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2386
2387 if (sw_em_1g)
2388 *sw_em_1g = mcp->mb[2];
2389 if (sw_em_2g)
2390 *sw_em_2g = mcp->mb[3];
2391 if (sw_em_4g)
2392 *sw_em_4g = mcp->mb[4];
2393 }
2394
2395 return rval;
2396}
2397
2398/**
2399 * qla2x00_set_serdes_params() -
2400 * @ha: HA context
2401 *
2402 * Returns
2403 */
2404int
2405qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2406 uint16_t sw_em_2g, uint16_t sw_em_4g)
2407{
2408 int rval;
2409 mbx_cmd_t mc;
2410 mbx_cmd_t *mcp = &mc;
2411
2412 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2413
2414 mcp->mb[0] = MBC_SERDES_PARAMS;
2415 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002416 mcp->mb[2] = sw_em_1g | BIT_15;
2417 mcp->mb[3] = sw_em_2g | BIT_15;
2418 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002419 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2420 mcp->in_mb = MBX_0;
2421 mcp->tov = 30;
2422 mcp->flags = 0;
2423 rval = qla2x00_mailbox_command(ha, mcp);
2424
2425 if (rval != QLA_SUCCESS) {
2426 /*EMPTY*/
2427 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2428 ha->host_no, rval, mcp->mb[0]));
2429 } else {
2430 /*EMPTY*/
2431 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2432 }
2433
2434 return rval;
2435}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002436
2437int
2438qla2x00_stop_firmware(scsi_qla_host_t *ha)
2439{
2440 int rval;
2441 mbx_cmd_t mc;
2442 mbx_cmd_t *mcp = &mc;
2443
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08002444 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002445 return QLA_FUNCTION_FAILED;
2446
2447 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2448
2449 mcp->mb[0] = MBC_STOP_FIRMWARE;
2450 mcp->out_mb = MBX_0;
2451 mcp->in_mb = MBX_0;
2452 mcp->tov = 5;
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.\n", __func__,
2458 ha->host_no, rval));
2459 } else {
2460 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2461 }
2462
2463 return rval;
2464}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002465
2466int
2467qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2468 uint16_t buffers)
2469{
2470 int rval;
2471 mbx_cmd_t mc;
2472 mbx_cmd_t *mcp = &mc;
2473
2474 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2475 return QLA_FUNCTION_FAILED;
2476
2477 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2478
2479 mcp->mb[0] = MBC_TRACE_CONTROL;
2480 mcp->mb[1] = ctrl;
2481 mcp->out_mb = MBX_1|MBX_0;
2482 mcp->in_mb = MBX_1|MBX_0;
2483 if (ctrl == TC_ENABLE) {
2484 mcp->mb[2] = LSW(eft_dma);
2485 mcp->mb[3] = MSW(eft_dma);
2486 mcp->mb[4] = LSW(MSD(eft_dma));
2487 mcp->mb[5] = MSW(MSD(eft_dma));
2488 mcp->mb[6] = buffers;
Andrew Vasquez87b23802006-12-13 19:20:25 -08002489 mcp->mb[7] = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002490 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2491 }
2492 mcp->tov = 30;
2493 mcp->flags = 0;
2494 rval = qla2x00_mailbox_command(ha, mcp);
2495
2496 if (rval != QLA_SUCCESS) {
2497 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2498 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2499 } else {
2500 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2501 }
2502
2503 return rval;
2504}
2505
Andrew Vasquez88729e52006-06-23 16:10:50 -07002506int
2507qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2508 uint16_t off, uint16_t count)
2509{
2510 int rval;
2511 mbx_cmd_t mc;
2512 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002513
Andrew Vasquez88729e52006-06-23 16:10:50 -07002514 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2515 return QLA_FUNCTION_FAILED;
2516
2517 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2518
2519 mcp->mb[0] = MBC_READ_SFP;
2520 mcp->mb[1] = addr;
2521 mcp->mb[2] = MSW(sfp_dma);
2522 mcp->mb[3] = LSW(sfp_dma);
2523 mcp->mb[6] = MSW(MSD(sfp_dma));
2524 mcp->mb[7] = LSW(MSD(sfp_dma));
2525 mcp->mb[8] = count;
2526 mcp->mb[9] = off;
2527 mcp->mb[10] = 0;
2528 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2529 mcp->in_mb = MBX_0;
2530 mcp->tov = 30;
2531 mcp->flags = 0;
2532 rval = qla2x00_mailbox_command(ha, mcp);
2533
2534 if (rval != QLA_SUCCESS) {
2535 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2536 ha->host_no, rval, mcp->mb[0]));
2537 } else {
2538 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2539 }
2540
2541 return rval;
2542}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002543
2544int
2545qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2546 uint16_t *port_speed, uint16_t *mb)
2547{
2548 int rval;
2549 mbx_cmd_t mc;
2550 mbx_cmd_t *mcp = &mc;
2551
2552 if (!IS_QLA24XX(ha))
2553 return QLA_FUNCTION_FAILED;
2554
2555 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2556
2557 mcp->mb[0] = MBC_PORT_PARAMS;
2558 mcp->mb[1] = loop_id;
2559 mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0;
2560 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2561 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2562 mcp->tov = 30;
2563 mcp->flags = 0;
2564 rval = qla2x00_mailbox_command(ha, mcp);
2565
2566 /* Return mailbox statuses. */
2567 if (mb != NULL) {
2568 mb[0] = mcp->mb[0];
2569 mb[1] = mcp->mb[1];
2570 mb[3] = mcp->mb[3];
2571 mb[4] = mcp->mb[4];
2572 mb[5] = mcp->mb[5];
2573 }
2574
2575 if (rval != QLA_SUCCESS) {
2576 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2577 ha->host_no, rval));
2578 } else {
2579 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2580 if (port_speed)
2581 *port_speed = mcp->mb[3];
2582 }
2583
2584 return rval;
2585}
2586
2587int
2588qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2589 uint16_t port_speed, uint16_t *mb)
2590{
2591 int rval;
2592 mbx_cmd_t mc;
2593 mbx_cmd_t *mcp = &mc;
2594
2595 if (!IS_QLA24XX(ha))
2596 return QLA_FUNCTION_FAILED;
2597
2598 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2599
2600 mcp->mb[0] = MBC_PORT_PARAMS;
2601 mcp->mb[1] = loop_id;
2602 mcp->mb[2] = BIT_0;
2603 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2604 mcp->mb[4] = mcp->mb[5] = 0;
2605 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2606 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2607 mcp->tov = 30;
2608 mcp->flags = 0;
2609 rval = qla2x00_mailbox_command(ha, mcp);
2610
2611 /* Return mailbox statuses. */
2612 if (mb != NULL) {
2613 mb[0] = mcp->mb[0];
2614 mb[1] = mcp->mb[1];
2615 mb[3] = mcp->mb[3];
2616 mb[4] = mcp->mb[4];
2617 mb[5] = mcp->mb[5];
2618 }
2619
2620 if (rval != QLA_SUCCESS) {
2621 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2622 ha->host_no, rval));
2623 } else {
2624 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2625 }
2626
2627 return rval;
2628}