diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/scsi/qla2xxx/qla_mbx.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/scsi/qla2xxx/qla_mbx.c')
-rw-r--r-- | drivers/scsi/qla2xxx/qla_mbx.c | 1950 |
1 files changed, 1950 insertions, 0 deletions
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c new file mode 100644 index 000000000000..c04fbcd75235 --- /dev/null +++ b/drivers/scsi/qla2xxx/qla_mbx.c | |||
@@ -0,0 +1,1950 @@ | |||
1 | /* | ||
2 | * QLOGIC LINUX SOFTWARE | ||
3 | * | ||
4 | * QLogic ISP2x00 device driver for Linux 2.6.x | ||
5 | * Copyright (C) 2003-2004 QLogic Corporation | ||
6 | * (www.qlogic.com) | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the | ||
10 | * Free Software Foundation; either version 2, or (at your option) any | ||
11 | * later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, but | ||
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | */ | ||
19 | #include "qla_def.h" | ||
20 | |||
21 | #include <linux/delay.h> | ||
22 | |||
23 | static void | ||
24 | qla2x00_mbx_sem_timeout(unsigned long data) | ||
25 | { | ||
26 | struct semaphore *sem_ptr = (struct semaphore *)data; | ||
27 | |||
28 | DEBUG11(printk("qla2x00_sem_timeout: entered.\n");) | ||
29 | |||
30 | if (sem_ptr != NULL) { | ||
31 | up(sem_ptr); | ||
32 | } | ||
33 | |||
34 | DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");) | ||
35 | } | ||
36 | |||
37 | /* | ||
38 | * qla2x00_mailbox_command | ||
39 | * Issue mailbox command and waits for completion. | ||
40 | * | ||
41 | * Input: | ||
42 | * ha = adapter block pointer. | ||
43 | * mcp = driver internal mbx struct pointer. | ||
44 | * | ||
45 | * Output: | ||
46 | * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data. | ||
47 | * | ||
48 | * Returns: | ||
49 | * 0 : QLA_SUCCESS = cmd performed success | ||
50 | * 1 : QLA_FUNCTION_FAILED (error encountered) | ||
51 | * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered) | ||
52 | * | ||
53 | * Context: | ||
54 | * Kernel context. | ||
55 | */ | ||
56 | static int | ||
57 | qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp) | ||
58 | { | ||
59 | int rval; | ||
60 | unsigned long flags = 0; | ||
61 | device_reg_t __iomem *reg = ha->iobase; | ||
62 | struct timer_list tmp_intr_timer; | ||
63 | uint8_t abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); | ||
64 | uint8_t io_lock_on = ha->flags.init_done; | ||
65 | uint16_t command; | ||
66 | uint16_t *iptr; | ||
67 | uint16_t __iomem *optr; | ||
68 | uint32_t cnt; | ||
69 | uint32_t mboxes; | ||
70 | unsigned long mbx_flags = 0; | ||
71 | unsigned long wait_time; | ||
72 | |||
73 | rval = QLA_SUCCESS; | ||
74 | |||
75 | DEBUG11(printk("qla2x00_mailbox_command(%ld): entered.\n", | ||
76 | ha->host_no);) | ||
77 | /* | ||
78 | * Wait for active mailbox commands to finish by waiting at most | ||
79 | * tov seconds. This is to serialize actual issuing of mailbox cmds | ||
80 | * during non ISP abort time. | ||
81 | */ | ||
82 | if (!abort_active) { | ||
83 | if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) { | ||
84 | /* Timeout occurred. Return error. */ | ||
85 | DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): cmd " | ||
86 | "access timeout. Exiting.\n", ha->host_no);) | ||
87 | return QLA_FUNCTION_TIMEOUT; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | ha->flags.mbox_busy = 1; | ||
92 | /* Save mailbox command for debug */ | ||
93 | ha->mcp = mcp; | ||
94 | |||
95 | /* Try to get mailbox register access */ | ||
96 | if (!abort_active) | ||
97 | spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags); | ||
98 | |||
99 | DEBUG11(printk("scsi%d: prepare to issue mbox cmd=0x%x.\n", | ||
100 | (int)ha->host_no, mcp->mb[0]);) | ||
101 | |||
102 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
103 | |||
104 | /* Load mailbox registers. */ | ||
105 | optr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 0); | ||
106 | |||
107 | iptr = mcp->mb; | ||
108 | command = mcp->mb[0]; | ||
109 | mboxes = mcp->out_mb; | ||
110 | |||
111 | for (cnt = 0; cnt < ha->mbx_count; cnt++) { | ||
112 | if (IS_QLA2200(ha) && cnt == 8) | ||
113 | optr = (uint16_t __iomem *)MAILBOX_REG(ha, reg, 8); | ||
114 | if (mboxes & BIT_0) | ||
115 | WRT_REG_WORD(optr, *iptr); | ||
116 | |||
117 | mboxes >>= 1; | ||
118 | optr++; | ||
119 | iptr++; | ||
120 | } | ||
121 | |||
122 | #if defined(QL_DEBUG_LEVEL_1) | ||
123 | printk("qla2x00_mailbox_command: Loaded MBX registers " | ||
124 | "(displayed in bytes) = \n"); | ||
125 | qla2x00_dump_buffer((uint8_t *)mcp->mb, 16); | ||
126 | printk("\n"); | ||
127 | qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16); | ||
128 | printk("\n"); | ||
129 | qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8); | ||
130 | printk("\n"); | ||
131 | printk("qla2x00_mailbox_command: I/O address = %lx.\n", | ||
132 | (u_long)optr); | ||
133 | qla2x00_dump_regs(ha); | ||
134 | #endif | ||
135 | |||
136 | /* Issue set host interrupt command to send cmd out. */ | ||
137 | ha->flags.mbox_int = 0; | ||
138 | clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); | ||
139 | |||
140 | /* Unlock mbx registers and wait for interrupt */ | ||
141 | |||
142 | DEBUG11(printk("qla2x00_mailbox_command: going to unlock irq & " | ||
143 | "waiting for interrupt. jiffies=%lx.\n", jiffies);) | ||
144 | |||
145 | /* Wait for mbx cmd completion until timeout */ | ||
146 | |||
147 | if (!abort_active && io_lock_on) { | ||
148 | /* sleep on completion semaphore */ | ||
149 | DEBUG11(printk("qla2x00_mailbox_command(%ld): " | ||
150 | "INTERRUPT MODE. Initializing timer.\n", | ||
151 | ha->host_no);) | ||
152 | |||
153 | init_timer(&tmp_intr_timer); | ||
154 | tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem; | ||
155 | tmp_intr_timer.expires = jiffies + mcp->tov * HZ; | ||
156 | tmp_intr_timer.function = | ||
157 | (void (*)(unsigned long))qla2x00_mbx_sem_timeout; | ||
158 | |||
159 | DEBUG11(printk("qla2x00_mailbox_command(%ld): " | ||
160 | "Adding timer.\n", ha->host_no);) | ||
161 | add_timer(&tmp_intr_timer); | ||
162 | |||
163 | DEBUG11(printk("qla2x00_mailbox_command: going to " | ||
164 | "unlock & sleep. time=0x%lx.\n", jiffies);) | ||
165 | |||
166 | set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); | ||
167 | |||
168 | WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT); | ||
169 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
170 | |||
171 | if (!abort_active) | ||
172 | spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags); | ||
173 | |||
174 | /* Wait for either the timer to expire | ||
175 | * or the mbox completion interrupt | ||
176 | */ | ||
177 | down(&ha->mbx_intr_sem); | ||
178 | |||
179 | DEBUG11(printk("qla2x00_mailbox_command:" | ||
180 | "waking up." | ||
181 | "time=0x%lx\n", jiffies);) | ||
182 | clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); | ||
183 | |||
184 | /* delete the timer */ | ||
185 | del_timer(&tmp_intr_timer); | ||
186 | } else { | ||
187 | |||
188 | DEBUG3_11(printk("qla2x00_mailbox_command(%ld): cmd=%x " | ||
189 | "POLLING MODE.\n", ha->host_no, command);) | ||
190 | |||
191 | WRT_REG_WORD(®->hccr, HCCR_SET_HOST_INT); | ||
192 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
193 | if (!abort_active) | ||
194 | spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags); | ||
195 | |||
196 | wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */ | ||
197 | while (!ha->flags.mbox_int) { | ||
198 | if (time_after(jiffies, wait_time)) | ||
199 | break; | ||
200 | |||
201 | /* Check for pending interrupts. */ | ||
202 | qla2x00_poll(ha); | ||
203 | |||
204 | udelay(10); /* v4.27 */ | ||
205 | } /* while */ | ||
206 | } | ||
207 | |||
208 | if (!abort_active) | ||
209 | spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags); | ||
210 | |||
211 | /* Check whether we timed out */ | ||
212 | if (ha->flags.mbox_int) { | ||
213 | uint16_t *iptr2; | ||
214 | |||
215 | DEBUG3_11(printk("qla2x00_mailbox_cmd: cmd %x completed.\n", | ||
216 | command);) | ||
217 | |||
218 | /* Got interrupt. Clear the flag. */ | ||
219 | ha->flags.mbox_int = 0; | ||
220 | clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); | ||
221 | |||
222 | if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) { | ||
223 | qla2x00_stats.mboxerr++; | ||
224 | rval = QLA_FUNCTION_FAILED; | ||
225 | } | ||
226 | |||
227 | /* Load return mailbox registers. */ | ||
228 | iptr2 = mcp->mb; | ||
229 | iptr = (uint16_t *)&ha->mailbox_out[0]; | ||
230 | mboxes = mcp->in_mb; | ||
231 | for (cnt = 0; cnt < ha->mbx_count; cnt++) { | ||
232 | if (mboxes & BIT_0) | ||
233 | *iptr2 = *iptr; | ||
234 | |||
235 | mboxes >>= 1; | ||
236 | iptr2++; | ||
237 | iptr++; | ||
238 | } | ||
239 | } else { | ||
240 | |||
241 | #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \ | ||
242 | defined(QL_DEBUG_LEVEL_11) | ||
243 | printk("qla2x00_mailbox_command(%ld): **** MB Command Timeout " | ||
244 | "for cmd %x ****\n", ha->host_no, command); | ||
245 | printk("qla2x00_mailbox_command: icontrol=%x jiffies=%lx\n", | ||
246 | RD_REG_WORD(®->ictrl), jiffies); | ||
247 | printk("qla2x00_mailbox_command: *** mailbox[0] = 0x%x ***\n", | ||
248 | RD_REG_WORD(optr)); | ||
249 | qla2x00_dump_regs(ha); | ||
250 | #endif | ||
251 | |||
252 | qla2x00_stats.mboxtout++; | ||
253 | ha->total_mbx_timeout++; | ||
254 | rval = QLA_FUNCTION_TIMEOUT; | ||
255 | } | ||
256 | |||
257 | if (!abort_active) | ||
258 | spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags); | ||
259 | |||
260 | ha->flags.mbox_busy = 0; | ||
261 | |||
262 | /* Clean up */ | ||
263 | ha->mcp = NULL; | ||
264 | |||
265 | if (!abort_active) { | ||
266 | DEBUG11(printk("qla2x00_mailbox_cmd: checking for additional " | ||
267 | "resp interrupt.\n");) | ||
268 | |||
269 | /* polling mode for non isp_abort commands. */ | ||
270 | qla2x00_poll(ha); | ||
271 | } | ||
272 | |||
273 | if (rval == QLA_FUNCTION_TIMEOUT) { | ||
274 | if (!io_lock_on || (mcp->flags & IOCTL_CMD)) { | ||
275 | /* not in dpc. schedule it for dpc to take over. */ | ||
276 | DEBUG(printk("qla2x00_mailbox_command(%ld): timeout " | ||
277 | "schedule isp_abort_needed.\n", | ||
278 | ha->host_no);) | ||
279 | DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): " | ||
280 | "timeout schedule isp_abort_needed.\n", | ||
281 | ha->host_no);) | ||
282 | qla_printk(KERN_WARNING, ha, | ||
283 | "Mailbox command timeout occured. Scheduling ISP " | ||
284 | "abort.\n"); | ||
285 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | ||
286 | if (ha->dpc_wait && !ha->dpc_active) | ||
287 | up(ha->dpc_wait); | ||
288 | |||
289 | } else if (!abort_active) { | ||
290 | |||
291 | /* call abort directly since we are in the DPC thread */ | ||
292 | DEBUG(printk("qla2x00_mailbox_command(%ld): timeout " | ||
293 | "calling abort_isp\n", ha->host_no);) | ||
294 | DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): " | ||
295 | "timeout calling abort_isp\n", ha->host_no);) | ||
296 | qla_printk(KERN_WARNING, ha, | ||
297 | "Mailbox command timeout occured. Issuing ISP " | ||
298 | "abort.\n"); | ||
299 | |||
300 | set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); | ||
301 | clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | ||
302 | if (qla2x00_abort_isp(ha)) { | ||
303 | /* failed. retry later. */ | ||
304 | set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags); | ||
305 | } | ||
306 | clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags); | ||
307 | |||
308 | DEBUG(printk("qla2x00_mailbox_command: finished " | ||
309 | "abort_isp\n");) | ||
310 | DEBUG2_3_11(printk("qla2x00_mailbox_command: finished " | ||
311 | "abort_isp\n");) | ||
312 | } | ||
313 | } | ||
314 | |||
315 | /* Allow next mbx cmd to come in. */ | ||
316 | if (!abort_active) | ||
317 | up(&ha->mbx_cmd_sem); | ||
318 | |||
319 | if (rval) { | ||
320 | DEBUG2_3_11(printk("qla2x00_mailbox_command(%ld): **** FAILED. " | ||
321 | "mbx0=%x, mbx1=%x, mbx2=%x, cmd=%x ****\n", | ||
322 | ha->host_no, mcp->mb[0], mcp->mb[1], mcp->mb[2], command);) | ||
323 | } else { | ||
324 | DEBUG11(printk("qla2x00_mailbox_command(%ld): done.\n", | ||
325 | ha->host_no);) | ||
326 | } | ||
327 | |||
328 | DEBUG11(printk("qla2x00_mailbox_command(%ld): exiting.\n", | ||
329 | ha->host_no);) | ||
330 | |||
331 | return rval; | ||
332 | } | ||
333 | |||
334 | /* | ||
335 | * qla2x00_load_ram | ||
336 | * Load adapter RAM using DMA. | ||
337 | * | ||
338 | * Input: | ||
339 | * ha = adapter block pointer. | ||
340 | * | ||
341 | * Returns: | ||
342 | * qla2x00 local function return status code. | ||
343 | * | ||
344 | * Context: | ||
345 | * Kernel context. | ||
346 | */ | ||
347 | int | ||
348 | qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr, | ||
349 | uint16_t risc_code_size) | ||
350 | { | ||
351 | int rval; | ||
352 | mbx_cmd_t mc; | ||
353 | mbx_cmd_t *mcp = &mc; | ||
354 | uint32_t req_len; | ||
355 | dma_addr_t nml_dma; | ||
356 | uint32_t nml_len; | ||
357 | uint32_t normalized; | ||
358 | |||
359 | DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n", | ||
360 | ha->host_no);) | ||
361 | |||
362 | req_len = risc_code_size; | ||
363 | nml_dma = 0; | ||
364 | nml_len = 0; | ||
365 | |||
366 | normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma, | ||
367 | &nml_len); | ||
368 | |||
369 | /* Load first segment */ | ||
370 | mcp->mb[0] = MBC_LOAD_RISC_RAM; | ||
371 | mcp->mb[1] = risc_addr; | ||
372 | mcp->mb[2] = MSW(req_dma); | ||
373 | mcp->mb[3] = LSW(req_dma); | ||
374 | mcp->mb[4] = (uint16_t)req_len; | ||
375 | mcp->mb[6] = MSW(MSD(req_dma)); | ||
376 | mcp->mb[7] = LSW(MSD(req_dma)); | ||
377 | mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
378 | mcp->in_mb = MBX_0; | ||
379 | mcp->tov = 30; | ||
380 | mcp->flags = 0; | ||
381 | rval = qla2x00_mailbox_command(ha, mcp); | ||
382 | |||
383 | /* Load second segment - if necessary */ | ||
384 | if (normalized && (rval == QLA_SUCCESS)) { | ||
385 | mcp->mb[0] = MBC_LOAD_RISC_RAM; | ||
386 | mcp->mb[1] = risc_addr + (uint16_t)req_len; | ||
387 | mcp->mb[2] = MSW(nml_dma); | ||
388 | mcp->mb[3] = LSW(nml_dma); | ||
389 | mcp->mb[4] = (uint16_t)nml_len; | ||
390 | mcp->mb[6] = MSW(MSD(nml_dma)); | ||
391 | mcp->mb[7] = LSW(MSD(nml_dma)); | ||
392 | mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
393 | mcp->in_mb = MBX_0; | ||
394 | mcp->tov = 30; | ||
395 | mcp->flags = 0; | ||
396 | rval = qla2x00_mailbox_command(ha, mcp); | ||
397 | } | ||
398 | |||
399 | if (rval == QLA_SUCCESS) { | ||
400 | /* Empty */ | ||
401 | DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);) | ||
402 | } else { | ||
403 | /* Empty */ | ||
404 | DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x " | ||
405 | "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);) | ||
406 | } | ||
407 | return rval; | ||
408 | } | ||
409 | |||
410 | /* | ||
411 | * qla2x00_load_ram_ext | ||
412 | * Load adapter extended RAM using DMA. | ||
413 | * | ||
414 | * Input: | ||
415 | * ha = adapter block pointer. | ||
416 | * | ||
417 | * Returns: | ||
418 | * qla2x00 local function return status code. | ||
419 | * | ||
420 | * Context: | ||
421 | * Kernel context. | ||
422 | */ | ||
423 | int | ||
424 | qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma, | ||
425 | uint32_t risc_addr, uint16_t risc_code_size) | ||
426 | { | ||
427 | int rval; | ||
428 | mbx_cmd_t mc; | ||
429 | mbx_cmd_t *mcp = &mc; | ||
430 | uint32_t req_len; | ||
431 | dma_addr_t nml_dma; | ||
432 | uint32_t nml_len; | ||
433 | uint32_t normalized; | ||
434 | |||
435 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); | ||
436 | |||
437 | req_len = risc_code_size; | ||
438 | nml_dma = 0; | ||
439 | nml_len = 0; | ||
440 | |||
441 | normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma, | ||
442 | &nml_len); | ||
443 | |||
444 | /* Load first segment */ | ||
445 | mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED; | ||
446 | mcp->mb[1] = LSW(risc_addr); | ||
447 | mcp->mb[2] = MSW(req_dma); | ||
448 | mcp->mb[3] = LSW(req_dma); | ||
449 | mcp->mb[4] = (uint16_t)req_len; | ||
450 | mcp->mb[6] = MSW(MSD(req_dma)); | ||
451 | mcp->mb[7] = LSW(MSD(req_dma)); | ||
452 | mcp->mb[8] = MSW(risc_addr); | ||
453 | mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
454 | mcp->in_mb = MBX_0; | ||
455 | mcp->tov = 30; | ||
456 | mcp->flags = 0; | ||
457 | rval = qla2x00_mailbox_command(ha, mcp); | ||
458 | |||
459 | /* Load second segment - if necessary */ | ||
460 | if (normalized && (rval == QLA_SUCCESS)) { | ||
461 | risc_addr += req_len; | ||
462 | mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED; | ||
463 | mcp->mb[1] = LSW(risc_addr); | ||
464 | mcp->mb[2] = MSW(nml_dma); | ||
465 | mcp->mb[3] = LSW(nml_dma); | ||
466 | mcp->mb[4] = (uint16_t)nml_len; | ||
467 | mcp->mb[6] = MSW(MSD(nml_dma)); | ||
468 | mcp->mb[7] = LSW(MSD(nml_dma)); | ||
469 | mcp->mb[8] = MSW(risc_addr); | ||
470 | mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
471 | mcp->in_mb = MBX_0; | ||
472 | mcp->tov = 30; | ||
473 | mcp->flags = 0; | ||
474 | rval = qla2x00_mailbox_command(ha, mcp); | ||
475 | } | ||
476 | |||
477 | if (rval != QLA_SUCCESS) { | ||
478 | /*EMPTY*/ | ||
479 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", | ||
480 | __func__, ha->host_no, rval, mcp->mb[0])); | ||
481 | } else { | ||
482 | /*EMPTY*/ | ||
483 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); | ||
484 | } | ||
485 | |||
486 | return rval; | ||
487 | } | ||
488 | |||
489 | /* | ||
490 | * qla2x00_execute_fw | ||
491 | * Start adapter firmware. | ||
492 | * | ||
493 | * Input: | ||
494 | * ha = adapter block pointer. | ||
495 | * TARGET_QUEUE_LOCK must be released. | ||
496 | * ADAPTER_STATE_LOCK must be released. | ||
497 | * | ||
498 | * Returns: | ||
499 | * qla2x00 local function return status code. | ||
500 | * | ||
501 | * Context: | ||
502 | * Kernel context. | ||
503 | */ | ||
504 | int | ||
505 | qla2x00_execute_fw(scsi_qla_host_t *ha) | ||
506 | { | ||
507 | int rval; | ||
508 | mbx_cmd_t mc; | ||
509 | mbx_cmd_t *mcp = &mc; | ||
510 | |||
511 | DEBUG11(printk("qla2x00_execute_fw(%ld): entered.\n", ha->host_no);) | ||
512 | |||
513 | mcp->mb[0] = MBC_EXECUTE_FIRMWARE; | ||
514 | mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart; | ||
515 | mcp->out_mb = MBX_1|MBX_0; | ||
516 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) { | ||
517 | mcp->mb[2] = 0; | ||
518 | mcp->out_mb |= MBX_2; | ||
519 | } | ||
520 | |||
521 | mcp->in_mb = MBX_0; | ||
522 | mcp->tov = 30; | ||
523 | mcp->flags = 0; | ||
524 | rval = qla2x00_mailbox_command(ha, mcp); | ||
525 | |||
526 | DEBUG11(printk("qla2x00_execute_fw(%ld): done.\n", ha->host_no);) | ||
527 | |||
528 | return rval; | ||
529 | } | ||
530 | |||
531 | /* | ||
532 | * qla2x00_get_fw_version | ||
533 | * Get firmware version. | ||
534 | * | ||
535 | * Input: | ||
536 | * ha: adapter state pointer. | ||
537 | * major: pointer for major number. | ||
538 | * minor: pointer for minor number. | ||
539 | * subminor: pointer for subminor number. | ||
540 | * | ||
541 | * Returns: | ||
542 | * qla2x00 local function return status code. | ||
543 | * | ||
544 | * Context: | ||
545 | * Kernel context. | ||
546 | */ | ||
547 | void | ||
548 | qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor, | ||
549 | uint16_t *subminor, uint16_t *attributes, uint32_t *memory) | ||
550 | { | ||
551 | int rval; | ||
552 | mbx_cmd_t mc; | ||
553 | mbx_cmd_t *mcp = &mc; | ||
554 | |||
555 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); | ||
556 | |||
557 | mcp->mb[0] = MBC_GET_FIRMWARE_VERSION; | ||
558 | mcp->out_mb = MBX_0; | ||
559 | mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
560 | mcp->flags = 0; | ||
561 | mcp->tov = 30; | ||
562 | rval = qla2x00_mailbox_command(ha, mcp); | ||
563 | |||
564 | /* Return mailbox data. */ | ||
565 | *major = mcp->mb[1]; | ||
566 | *minor = mcp->mb[2]; | ||
567 | *subminor = mcp->mb[3]; | ||
568 | *attributes = mcp->mb[6]; | ||
569 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) | ||
570 | *memory = 0x1FFFF; /* Defaults to 128KB. */ | ||
571 | else | ||
572 | *memory = (mcp->mb[5] << 16) | mcp->mb[4]; | ||
573 | |||
574 | if (rval != QLA_SUCCESS) { | ||
575 | /*EMPTY*/ | ||
576 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | ||
577 | ha->host_no, rval)); | ||
578 | } else { | ||
579 | /*EMPTY*/ | ||
580 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); | ||
581 | } | ||
582 | } | ||
583 | |||
584 | /* | ||
585 | * qla2x00_get_fw_options | ||
586 | * Set firmware options. | ||
587 | * | ||
588 | * Input: | ||
589 | * ha = adapter block pointer. | ||
590 | * fwopt = pointer for firmware options. | ||
591 | * | ||
592 | * Returns: | ||
593 | * qla2x00 local function return status code. | ||
594 | * | ||
595 | * Context: | ||
596 | * Kernel context. | ||
597 | */ | ||
598 | int | ||
599 | qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts) | ||
600 | { | ||
601 | int rval; | ||
602 | mbx_cmd_t mc; | ||
603 | mbx_cmd_t *mcp = &mc; | ||
604 | |||
605 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); | ||
606 | |||
607 | mcp->mb[0] = MBC_GET_FIRMWARE_OPTION; | ||
608 | mcp->out_mb = MBX_0; | ||
609 | mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0; | ||
610 | mcp->tov = 30; | ||
611 | mcp->flags = 0; | ||
612 | rval = qla2x00_mailbox_command(ha, mcp); | ||
613 | |||
614 | if (rval != QLA_SUCCESS) { | ||
615 | /*EMPTY*/ | ||
616 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | ||
617 | ha->host_no, rval)); | ||
618 | } else { | ||
619 | fwopts[1] = mcp->mb[1]; | ||
620 | fwopts[2] = mcp->mb[2]; | ||
621 | fwopts[3] = mcp->mb[3]; | ||
622 | |||
623 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); | ||
624 | } | ||
625 | |||
626 | return rval; | ||
627 | } | ||
628 | |||
629 | |||
630 | /* | ||
631 | * qla2x00_set_fw_options | ||
632 | * Set firmware options. | ||
633 | * | ||
634 | * Input: | ||
635 | * ha = adapter block pointer. | ||
636 | * fwopt = pointer for firmware options. | ||
637 | * | ||
638 | * Returns: | ||
639 | * qla2x00 local function return status code. | ||
640 | * | ||
641 | * Context: | ||
642 | * Kernel context. | ||
643 | */ | ||
644 | int | ||
645 | qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts) | ||
646 | { | ||
647 | int rval; | ||
648 | mbx_cmd_t mc; | ||
649 | mbx_cmd_t *mcp = &mc; | ||
650 | |||
651 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); | ||
652 | |||
653 | mcp->mb[0] = MBC_SET_FIRMWARE_OPTION; | ||
654 | mcp->mb[1] = fwopts[1]; | ||
655 | mcp->mb[2] = fwopts[2]; | ||
656 | mcp->mb[3] = fwopts[3]; | ||
657 | mcp->mb[10] = fwopts[10]; | ||
658 | mcp->mb[11] = fwopts[11]; | ||
659 | mcp->mb[12] = 0; /* Undocumented, but used */ | ||
660 | mcp->out_mb = MBX_12|MBX_11|MBX_10|MBX_3|MBX_2|MBX_1|MBX_0; | ||
661 | mcp->in_mb = MBX_0; | ||
662 | mcp->tov = 30; | ||
663 | mcp->flags = 0; | ||
664 | rval = qla2x00_mailbox_command(ha, mcp); | ||
665 | |||
666 | if (rval != QLA_SUCCESS) { | ||
667 | /*EMPTY*/ | ||
668 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | ||
669 | ha->host_no, rval)); | ||
670 | } else { | ||
671 | /*EMPTY*/ | ||
672 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); | ||
673 | } | ||
674 | |||
675 | return rval; | ||
676 | } | ||
677 | |||
678 | /* | ||
679 | * qla2x00_mbx_reg_test | ||
680 | * Mailbox register wrap test. | ||
681 | * | ||
682 | * Input: | ||
683 | * ha = adapter block pointer. | ||
684 | * TARGET_QUEUE_LOCK must be released. | ||
685 | * ADAPTER_STATE_LOCK must be released. | ||
686 | * | ||
687 | * Returns: | ||
688 | * qla2x00 local function return status code. | ||
689 | * | ||
690 | * Context: | ||
691 | * Kernel context. | ||
692 | */ | ||
693 | int | ||
694 | qla2x00_mbx_reg_test(scsi_qla_host_t *ha) | ||
695 | { | ||
696 | int rval; | ||
697 | mbx_cmd_t mc; | ||
698 | mbx_cmd_t *mcp = &mc; | ||
699 | |||
700 | DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);) | ||
701 | |||
702 | mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST; | ||
703 | mcp->mb[1] = 0xAAAA; | ||
704 | mcp->mb[2] = 0x5555; | ||
705 | mcp->mb[3] = 0xAA55; | ||
706 | mcp->mb[4] = 0x55AA; | ||
707 | mcp->mb[5] = 0xA5A5; | ||
708 | mcp->mb[6] = 0x5A5A; | ||
709 | mcp->mb[7] = 0x2525; | ||
710 | mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
711 | mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | ||
712 | mcp->tov = 30; | ||
713 | mcp->flags = 0; | ||
714 | rval = qla2x00_mailbox_command(ha, mcp); | ||
715 | |||
716 | if (rval == QLA_SUCCESS) { | ||
717 | if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 || | ||
718 | mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA) | ||
719 | rval = QLA_FUNCTION_FAILED; | ||
720 | if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A || | ||
721 | mcp->mb[7] != 0x2525) | ||
722 | rval = QLA_FUNCTION_FAILED; | ||
723 | } | ||
724 | |||
725 | if (rval != QLA_SUCCESS) { | ||
726 | /*EMPTY*/ | ||
727 | DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n", | ||
728 | ha->host_no, rval);) | ||
729 | } else { | ||
730 | /*EMPTY*/ | ||
731 | DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n", | ||
732 | ha->host_no);) | ||
733 | } | ||
734 | |||
735 | return rval; | ||
736 | } | ||
737 | |||
738 | /* | ||
739 | * qla2x00_verify_checksum | ||
740 | * Verify firmware checksum. | ||
741 | * | ||
742 | * Input: | ||
743 | * ha = adapter block pointer. | ||
744 | * TARGET_QUEUE_LOCK must be released. | ||
745 | * ADAPTER_STATE_LOCK must be released. | ||
746 | * | ||
747 | * Returns: | ||
748 | * qla2x00 local function return status code. | ||
749 | * | ||
750 | * Context: | ||
751 | * Kernel context. | ||
752 | */ | ||
753 | int | ||
754 | qla2x00_verify_checksum(scsi_qla_host_t *ha) | ||
755 | { | ||
756 | int rval; | ||
757 | mbx_cmd_t mc; | ||
758 | mbx_cmd_t *mcp = &mc; | ||
759 | |||
760 | DEBUG11(printk("qla2x00_verify_checksum(%ld): entered.\n", | ||
761 | ha->host_no);) | ||
762 | |||
763 | mcp->mb[0] = MBC_VERIFY_CHECKSUM; | ||
764 | mcp->mb[1] = *ha->brd_info->fw_info[0].fwstart; | ||
765 | mcp->out_mb = MBX_1|MBX_0; | ||
766 | mcp->in_mb = MBX_2|MBX_0; | ||
767 | mcp->tov = 30; | ||
768 | mcp->flags = 0; | ||
769 | rval = qla2x00_mailbox_command(ha, mcp); | ||
770 | |||
771 | if (rval != QLA_SUCCESS) { | ||
772 | /*EMPTY*/ | ||
773 | DEBUG2_3_11(printk("qla2x00_verify_checksum(%ld): failed=%x.\n", | ||
774 | ha->host_no, rval);) | ||
775 | } else { | ||
776 | /*EMPTY*/ | ||
777 | DEBUG11(printk("qla2x00_verify_checksum(%ld): done.\n", | ||
778 | ha->host_no);) | ||
779 | } | ||
780 | |||
781 | return rval; | ||
782 | } | ||
783 | |||
784 | /* | ||
785 | * qla2x00_issue_iocb | ||
786 | * Issue IOCB using mailbox command | ||
787 | * | ||
788 | * Input: | ||
789 | * ha = adapter state pointer. | ||
790 | * buffer = buffer pointer. | ||
791 | * phys_addr = physical address of buffer. | ||
792 | * size = size of buffer. | ||
793 | * TARGET_QUEUE_LOCK must be released. | ||
794 | * ADAPTER_STATE_LOCK must be released. | ||
795 | * | ||
796 | * Returns: | ||
797 | * qla2x00 local function return status code. | ||
798 | * | ||
799 | * Context: | ||
800 | * Kernel context. | ||
801 | */ | ||
802 | int | ||
803 | qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr, | ||
804 | size_t size) | ||
805 | { | ||
806 | int rval; | ||
807 | mbx_cmd_t mc; | ||
808 | mbx_cmd_t *mcp = &mc; | ||
809 | |||
810 | mcp->mb[0] = MBC_IOCB_COMMAND_A64; | ||
811 | mcp->mb[1] = 0; | ||
812 | mcp->mb[2] = MSW(phys_addr); | ||
813 | mcp->mb[3] = LSW(phys_addr); | ||
814 | mcp->mb[6] = MSW(MSD(phys_addr)); | ||
815 | mcp->mb[7] = LSW(MSD(phys_addr)); | ||
816 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
817 | mcp->in_mb = MBX_2|MBX_0; | ||
818 | mcp->tov = 30; | ||
819 | mcp->flags = 0; | ||
820 | rval = qla2x00_mailbox_command(ha, mcp); | ||
821 | |||
822 | if (rval != QLA_SUCCESS) { | ||
823 | /*EMPTY*/ | ||
824 | DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x", | ||
825 | ha->host_no,rval);) | ||
826 | DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x", | ||
827 | ha->host_no,rval);) | ||
828 | } else { | ||
829 | /*EMPTY*/ | ||
830 | } | ||
831 | |||
832 | return rval; | ||
833 | } | ||
834 | |||
835 | /* | ||
836 | * qla2x00_abort_command | ||
837 | * Abort command aborts a specified IOCB. | ||
838 | * | ||
839 | * Input: | ||
840 | * ha = adapter block pointer. | ||
841 | * sp = SB structure pointer. | ||
842 | * | ||
843 | * Returns: | ||
844 | * qla2x00 local function return status code. | ||
845 | * | ||
846 | * Context: | ||
847 | * Kernel context. | ||
848 | */ | ||
849 | int | ||
850 | qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp) | ||
851 | { | ||
852 | unsigned long flags = 0; | ||
853 | fc_port_t *fcport; | ||
854 | int rval; | ||
855 | uint32_t handle; | ||
856 | mbx_cmd_t mc; | ||
857 | mbx_cmd_t *mcp = &mc; | ||
858 | |||
859 | DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);) | ||
860 | |||
861 | fcport = sp->fclun->fcport; | ||
862 | |||
863 | if (atomic_read(&ha->loop_state) == LOOP_DOWN || | ||
864 | atomic_read(&fcport->state) == FCS_DEVICE_LOST) { | ||
865 | return 1; | ||
866 | } | ||
867 | |||
868 | spin_lock_irqsave(&ha->hardware_lock, flags); | ||
869 | for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) { | ||
870 | if (ha->outstanding_cmds[handle] == sp) | ||
871 | break; | ||
872 | } | ||
873 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | ||
874 | |||
875 | if (handle == MAX_OUTSTANDING_COMMANDS) { | ||
876 | /* command not found */ | ||
877 | return QLA_FUNCTION_FAILED; | ||
878 | } | ||
879 | |||
880 | mcp->mb[0] = MBC_ABORT_COMMAND; | ||
881 | if (HAS_EXTENDED_IDS(ha)) | ||
882 | mcp->mb[1] = fcport->loop_id; | ||
883 | else | ||
884 | mcp->mb[1] = fcport->loop_id << 8; | ||
885 | mcp->mb[2] = (uint16_t)handle; | ||
886 | mcp->mb[3] = (uint16_t)(handle >> 16); | ||
887 | mcp->mb[6] = (uint16_t)sp->fclun->lun; | ||
888 | mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
889 | mcp->in_mb = MBX_0; | ||
890 | mcp->tov = 30; | ||
891 | mcp->flags = 0; | ||
892 | rval = qla2x00_mailbox_command(ha, mcp); | ||
893 | |||
894 | if (rval != QLA_SUCCESS) { | ||
895 | DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n", | ||
896 | ha->host_no, rval);) | ||
897 | } else { | ||
898 | sp->flags |= SRB_ABORT_PENDING; | ||
899 | DEBUG11(printk("qla2x00_abort_command(%ld): done.\n", | ||
900 | ha->host_no);) | ||
901 | } | ||
902 | |||
903 | return rval; | ||
904 | } | ||
905 | |||
906 | #if USE_ABORT_TGT | ||
907 | /* | ||
908 | * qla2x00_abort_target | ||
909 | * Issue abort target mailbox command. | ||
910 | * | ||
911 | * Input: | ||
912 | * ha = adapter block pointer. | ||
913 | * | ||
914 | * Returns: | ||
915 | * qla2x00 local function return status code. | ||
916 | * | ||
917 | * Context: | ||
918 | * Kernel context. | ||
919 | */ | ||
920 | int | ||
921 | qla2x00_abort_target(fc_port_t *fcport) | ||
922 | { | ||
923 | int rval; | ||
924 | mbx_cmd_t mc; | ||
925 | mbx_cmd_t *mcp = &mc; | ||
926 | |||
927 | DEBUG11(printk("qla2x00_abort_target(%ld): entered.\n", | ||
928 | fcport->ha->host_no);) | ||
929 | |||
930 | if (fcport == NULL) { | ||
931 | /* no target to abort */ | ||
932 | return 0; | ||
933 | } | ||
934 | |||
935 | mcp->mb[0] = MBC_ABORT_TARGET; | ||
936 | mcp->out_mb = MBX_2|MBX_1|MBX_0; | ||
937 | if (HAS_EXTENDED_IDS(fcport->ha)) { | ||
938 | mcp->mb[1] = fcport->loop_id; | ||
939 | mcp->mb[10] = 0; | ||
940 | mcp->out_mb |= MBX_10; | ||
941 | } else { | ||
942 | mcp->mb[1] = fcport->loop_id << 8; | ||
943 | } | ||
944 | mcp->mb[2] = fcport->ha->loop_reset_delay; | ||
945 | |||
946 | mcp->in_mb = MBX_0; | ||
947 | mcp->tov = 30; | ||
948 | mcp->flags = 0; | ||
949 | rval = qla2x00_mailbox_command(fcport->ha, mcp); | ||
950 | |||
951 | /* Issue marker command. */ | ||
952 | fcport->ha->marker_needed = 1; | ||
953 | |||
954 | if (rval != QLA_SUCCESS) { | ||
955 | DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n", | ||
956 | fcport->ha->host_no, rval);) | ||
957 | } else { | ||
958 | /*EMPTY*/ | ||
959 | DEBUG11(printk("qla2x00_abort_target(%ld): done.\n", | ||
960 | fcport->ha->host_no);) | ||
961 | } | ||
962 | |||
963 | return rval; | ||
964 | } | ||
965 | #endif | ||
966 | |||
967 | /* | ||
968 | * qla2x00_target_reset | ||
969 | * Issue target reset mailbox command. | ||
970 | * | ||
971 | * Input: | ||
972 | * ha = adapter block pointer. | ||
973 | * TARGET_QUEUE_LOCK must be released. | ||
974 | * ADAPTER_STATE_LOCK must be released. | ||
975 | * | ||
976 | * Returns: | ||
977 | * qla2x00 local function return status code. | ||
978 | * | ||
979 | * Context: | ||
980 | * Kernel context. | ||
981 | */ | ||
982 | int | ||
983 | qla2x00_target_reset(scsi_qla_host_t *ha, uint16_t b, uint16_t t) | ||
984 | { | ||
985 | int rval; | ||
986 | mbx_cmd_t mc; | ||
987 | mbx_cmd_t *mcp = &mc; | ||
988 | os_tgt_t *tgt; | ||
989 | |||
990 | DEBUG11(printk("qla2x00_target_reset(%ld): entered.\n", ha->host_no);) | ||
991 | |||
992 | tgt = TGT_Q(ha, t); | ||
993 | if (tgt->fcport == NULL) { | ||
994 | /* no target to abort */ | ||
995 | return 0; | ||
996 | } | ||
997 | if (atomic_read(&tgt->fcport->state) != FCS_ONLINE) { | ||
998 | /* target not online */ | ||
999 | return 0; | ||
1000 | } | ||
1001 | |||
1002 | mcp->mb[0] = MBC_TARGET_RESET; | ||
1003 | if (HAS_EXTENDED_IDS(ha)) | ||
1004 | mcp->mb[1] = tgt->fcport->loop_id; | ||
1005 | else | ||
1006 | mcp->mb[1] = tgt->fcport->loop_id << 8; | ||
1007 | mcp->mb[2] = ha->loop_reset_delay; | ||
1008 | mcp->out_mb = MBX_2|MBX_1|MBX_0; | ||
1009 | mcp->in_mb = MBX_0; | ||
1010 | mcp->tov = 30; | ||
1011 | mcp->flags = 0; | ||
1012 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1013 | |||
1014 | if (rval != QLA_SUCCESS) { | ||
1015 | /*EMPTY*/ | ||
1016 | DEBUG2_3_11(printk("qla2x00_target_reset(%ld): failed=%x.\n", | ||
1017 | ha->host_no, rval);) | ||
1018 | } else { | ||
1019 | /*EMPTY*/ | ||
1020 | DEBUG11(printk("qla2x00_target_reset(%ld): done.\n", | ||
1021 | ha->host_no);) | ||
1022 | } | ||
1023 | |||
1024 | return rval; | ||
1025 | } | ||
1026 | |||
1027 | /* | ||
1028 | * qla2x00_get_adapter_id | ||
1029 | * Get adapter ID and topology. | ||
1030 | * | ||
1031 | * Input: | ||
1032 | * ha = adapter block pointer. | ||
1033 | * id = pointer for loop ID. | ||
1034 | * al_pa = pointer for AL_PA. | ||
1035 | * area = pointer for area. | ||
1036 | * domain = pointer for domain. | ||
1037 | * top = pointer for topology. | ||
1038 | * TARGET_QUEUE_LOCK must be released. | ||
1039 | * ADAPTER_STATE_LOCK must be released. | ||
1040 | * | ||
1041 | * Returns: | ||
1042 | * qla2x00 local function return status code. | ||
1043 | * | ||
1044 | * Context: | ||
1045 | * Kernel context. | ||
1046 | */ | ||
1047 | int | ||
1048 | qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa, | ||
1049 | uint8_t *area, uint8_t *domain, uint16_t *top) | ||
1050 | { | ||
1051 | int rval; | ||
1052 | mbx_cmd_t mc; | ||
1053 | mbx_cmd_t *mcp = &mc; | ||
1054 | |||
1055 | DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n", | ||
1056 | ha->host_no);) | ||
1057 | |||
1058 | mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID; | ||
1059 | mcp->out_mb = MBX_0; | ||
1060 | mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
1061 | mcp->tov = 30; | ||
1062 | mcp->flags = 0; | ||
1063 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1064 | |||
1065 | /* Return data. */ | ||
1066 | *id = mcp->mb[1]; | ||
1067 | *al_pa = LSB(mcp->mb[2]); | ||
1068 | *area = MSB(mcp->mb[2]); | ||
1069 | *domain = LSB(mcp->mb[3]); | ||
1070 | *top = mcp->mb[6]; | ||
1071 | |||
1072 | if (rval != QLA_SUCCESS) { | ||
1073 | /*EMPTY*/ | ||
1074 | DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n", | ||
1075 | ha->host_no, rval);) | ||
1076 | } else { | ||
1077 | /*EMPTY*/ | ||
1078 | DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n", | ||
1079 | ha->host_no);) | ||
1080 | } | ||
1081 | |||
1082 | return rval; | ||
1083 | } | ||
1084 | |||
1085 | /* | ||
1086 | * qla2x00_get_retry_cnt | ||
1087 | * Get current firmware login retry count and delay. | ||
1088 | * | ||
1089 | * Input: | ||
1090 | * ha = adapter block pointer. | ||
1091 | * retry_cnt = pointer to login retry count. | ||
1092 | * tov = pointer to login timeout value. | ||
1093 | * | ||
1094 | * Returns: | ||
1095 | * qla2x00 local function return status code. | ||
1096 | * | ||
1097 | * Context: | ||
1098 | * Kernel context. | ||
1099 | */ | ||
1100 | int | ||
1101 | qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov, | ||
1102 | uint16_t *r_a_tov) | ||
1103 | { | ||
1104 | int rval; | ||
1105 | uint16_t ratov; | ||
1106 | mbx_cmd_t mc; | ||
1107 | mbx_cmd_t *mcp = &mc; | ||
1108 | |||
1109 | DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n", | ||
1110 | ha->host_no);) | ||
1111 | |||
1112 | mcp->mb[0] = MBC_GET_RETRY_COUNT; | ||
1113 | mcp->out_mb = MBX_0; | ||
1114 | mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0; | ||
1115 | mcp->tov = 30; | ||
1116 | mcp->flags = 0; | ||
1117 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1118 | |||
1119 | if (rval != QLA_SUCCESS) { | ||
1120 | /*EMPTY*/ | ||
1121 | DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n", | ||
1122 | ha->host_no, mcp->mb[0]);) | ||
1123 | } else { | ||
1124 | /* Convert returned data and check our values. */ | ||
1125 | *r_a_tov = mcp->mb[3] / 2; | ||
1126 | ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */ | ||
1127 | if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) { | ||
1128 | /* Update to the larger values */ | ||
1129 | *retry_cnt = (uint8_t)mcp->mb[1]; | ||
1130 | *tov = ratov; | ||
1131 | } | ||
1132 | |||
1133 | DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d " | ||
1134 | "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);) | ||
1135 | } | ||
1136 | |||
1137 | return rval; | ||
1138 | } | ||
1139 | |||
1140 | /* | ||
1141 | * qla2x00_init_firmware | ||
1142 | * Initialize adapter firmware. | ||
1143 | * | ||
1144 | * Input: | ||
1145 | * ha = adapter block pointer. | ||
1146 | * dptr = Initialization control block pointer. | ||
1147 | * size = size of initialization control block. | ||
1148 | * TARGET_QUEUE_LOCK must be released. | ||
1149 | * ADAPTER_STATE_LOCK must be released. | ||
1150 | * | ||
1151 | * Returns: | ||
1152 | * qla2x00 local function return status code. | ||
1153 | * | ||
1154 | * Context: | ||
1155 | * Kernel context. | ||
1156 | */ | ||
1157 | int | ||
1158 | qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size) | ||
1159 | { | ||
1160 | int rval; | ||
1161 | mbx_cmd_t mc; | ||
1162 | mbx_cmd_t *mcp = &mc; | ||
1163 | |||
1164 | DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n", | ||
1165 | ha->host_no);) | ||
1166 | |||
1167 | mcp->mb[0] = MBC_INITIALIZE_FIRMWARE; | ||
1168 | mcp->mb[2] = MSW(ha->init_cb_dma); | ||
1169 | mcp->mb[3] = LSW(ha->init_cb_dma); | ||
1170 | mcp->mb[4] = 0; | ||
1171 | mcp->mb[5] = 0; | ||
1172 | mcp->mb[6] = MSW(MSD(ha->init_cb_dma)); | ||
1173 | mcp->mb[7] = LSW(MSD(ha->init_cb_dma)); | ||
1174 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; | ||
1175 | mcp->in_mb = MBX_5|MBX_4|MBX_0; | ||
1176 | mcp->buf_size = size; | ||
1177 | mcp->flags = MBX_DMA_OUT; | ||
1178 | mcp->tov = 30; | ||
1179 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1180 | |||
1181 | if (rval != QLA_SUCCESS) { | ||
1182 | /*EMPTY*/ | ||
1183 | DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x " | ||
1184 | "mb0=%x.\n", | ||
1185 | ha->host_no, rval, mcp->mb[0]);) | ||
1186 | } else { | ||
1187 | /*EMPTY*/ | ||
1188 | DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n", | ||
1189 | ha->host_no);) | ||
1190 | } | ||
1191 | |||
1192 | return rval; | ||
1193 | } | ||
1194 | |||
1195 | /* | ||
1196 | * qla2x00_get_port_database | ||
1197 | * Issue normal/enhanced get port database mailbox command | ||
1198 | * and copy device name as necessary. | ||
1199 | * | ||
1200 | * Input: | ||
1201 | * ha = adapter state pointer. | ||
1202 | * dev = structure pointer. | ||
1203 | * opt = enhanced cmd option byte. | ||
1204 | * | ||
1205 | * Returns: | ||
1206 | * qla2x00 local function return status code. | ||
1207 | * | ||
1208 | * Context: | ||
1209 | * Kernel context. | ||
1210 | */ | ||
1211 | int | ||
1212 | qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt) | ||
1213 | { | ||
1214 | int rval; | ||
1215 | mbx_cmd_t mc; | ||
1216 | mbx_cmd_t *mcp = &mc; | ||
1217 | port_database_t *pd; | ||
1218 | dma_addr_t pd_dma; | ||
1219 | |||
1220 | DEBUG11(printk("qla2x00_get_port_database(%ld): entered.\n", | ||
1221 | ha->host_no);) | ||
1222 | |||
1223 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pd_dma); | ||
1224 | if (pd == NULL) { | ||
1225 | DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): **** " | ||
1226 | "Mem Alloc Failed ****", ha->host_no);) | ||
1227 | return QLA_MEMORY_ALLOC_FAILED; | ||
1228 | } | ||
1229 | memset(pd, 0, PORT_DATABASE_SIZE); | ||
1230 | |||
1231 | if (opt != 0) | ||
1232 | mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE; | ||
1233 | else | ||
1234 | mcp->mb[0] = MBC_GET_PORT_DATABASE; | ||
1235 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
1236 | if (HAS_EXTENDED_IDS(ha)) { | ||
1237 | mcp->mb[1] = fcport->loop_id; | ||
1238 | mcp->mb[10] = opt; | ||
1239 | mcp->out_mb |= MBX_10; | ||
1240 | } else { | ||
1241 | mcp->mb[1] = fcport->loop_id << 8 | opt; | ||
1242 | } | ||
1243 | mcp->mb[2] = MSW(pd_dma); | ||
1244 | mcp->mb[3] = LSW(pd_dma); | ||
1245 | mcp->mb[6] = MSW(MSD(pd_dma)); | ||
1246 | mcp->mb[7] = LSW(MSD(pd_dma)); | ||
1247 | |||
1248 | mcp->in_mb = MBX_0; | ||
1249 | mcp->buf_size = PORT_DATABASE_SIZE; | ||
1250 | mcp->flags = MBX_DMA_IN; | ||
1251 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | ||
1252 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1253 | if (rval != QLA_SUCCESS) | ||
1254 | goto gpd_error_out; | ||
1255 | |||
1256 | /* Check for logged in state. */ | ||
1257 | if (pd->master_state != PD_STATE_PORT_LOGGED_IN && | ||
1258 | pd->slave_state != PD_STATE_PORT_LOGGED_IN) { | ||
1259 | rval = QLA_FUNCTION_FAILED; | ||
1260 | goto gpd_error_out; | ||
1261 | } | ||
1262 | |||
1263 | /* Names are little-endian. */ | ||
1264 | memcpy(fcport->node_name, pd->node_name, WWN_SIZE); | ||
1265 | memcpy(fcport->port_name, pd->port_name, WWN_SIZE); | ||
1266 | |||
1267 | /* Get port_id of device. */ | ||
1268 | fcport->d_id.b.al_pa = pd->port_id[2]; | ||
1269 | fcport->d_id.b.area = pd->port_id[3]; | ||
1270 | fcport->d_id.b.domain = pd->port_id[0]; | ||
1271 | fcport->d_id.b.rsvd_1 = 0; | ||
1272 | |||
1273 | /* Check for device require authentication. */ | ||
1274 | pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) : | ||
1275 | (fcport->flags &= ~FCF_AUTH_REQ); | ||
1276 | |||
1277 | /* If not target must be initiator or unknown type. */ | ||
1278 | if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) | ||
1279 | fcport->port_type = FCT_INITIATOR; | ||
1280 | else | ||
1281 | fcport->port_type = FCT_TARGET; | ||
1282 | |||
1283 | gpd_error_out: | ||
1284 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); | ||
1285 | |||
1286 | if (rval != QLA_SUCCESS) { | ||
1287 | /*EMPTY*/ | ||
1288 | DEBUG2_3_11(printk("qla2x00_get_port_database(%ld): " | ||
1289 | "failed=%x.\n", ha->host_no, rval);) | ||
1290 | } else { | ||
1291 | /*EMPTY*/ | ||
1292 | DEBUG11(printk("qla2x00_get_port_database(%ld): done.\n", | ||
1293 | ha->host_no);) | ||
1294 | } | ||
1295 | |||
1296 | return rval; | ||
1297 | } | ||
1298 | |||
1299 | /* | ||
1300 | * qla2x00_get_firmware_state | ||
1301 | * Get adapter firmware state. | ||
1302 | * | ||
1303 | * Input: | ||
1304 | * ha = adapter block pointer. | ||
1305 | * dptr = pointer for firmware state. | ||
1306 | * TARGET_QUEUE_LOCK must be released. | ||
1307 | * ADAPTER_STATE_LOCK must be released. | ||
1308 | * | ||
1309 | * Returns: | ||
1310 | * qla2x00 local function return status code. | ||
1311 | * | ||
1312 | * Context: | ||
1313 | * Kernel context. | ||
1314 | */ | ||
1315 | int | ||
1316 | qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr) | ||
1317 | { | ||
1318 | int rval; | ||
1319 | mbx_cmd_t mc; | ||
1320 | mbx_cmd_t *mcp = &mc; | ||
1321 | |||
1322 | DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n", | ||
1323 | ha->host_no);) | ||
1324 | |||
1325 | mcp->mb[0] = MBC_GET_FIRMWARE_STATE; | ||
1326 | mcp->out_mb = MBX_0; | ||
1327 | mcp->in_mb = MBX_2|MBX_1|MBX_0; | ||
1328 | mcp->tov = 30; | ||
1329 | mcp->flags = 0; | ||
1330 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1331 | |||
1332 | /* Return firmware state. */ | ||
1333 | *dptr = mcp->mb[1]; | ||
1334 | |||
1335 | if (rval != QLA_SUCCESS) { | ||
1336 | /*EMPTY*/ | ||
1337 | DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): " | ||
1338 | "failed=%x.\n", ha->host_no, rval);) | ||
1339 | } else { | ||
1340 | /*EMPTY*/ | ||
1341 | DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n", | ||
1342 | ha->host_no);) | ||
1343 | } | ||
1344 | |||
1345 | return rval; | ||
1346 | } | ||
1347 | |||
1348 | /* | ||
1349 | * qla2x00_get_port_name | ||
1350 | * Issue get port name mailbox command. | ||
1351 | * Returned name is in big endian format. | ||
1352 | * | ||
1353 | * Input: | ||
1354 | * ha = adapter block pointer. | ||
1355 | * loop_id = loop ID of device. | ||
1356 | * name = pointer for name. | ||
1357 | * TARGET_QUEUE_LOCK must be released. | ||
1358 | * ADAPTER_STATE_LOCK must be released. | ||
1359 | * | ||
1360 | * Returns: | ||
1361 | * qla2x00 local function return status code. | ||
1362 | * | ||
1363 | * Context: | ||
1364 | * Kernel context. | ||
1365 | */ | ||
1366 | int | ||
1367 | qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name, | ||
1368 | uint8_t opt) | ||
1369 | { | ||
1370 | int rval; | ||
1371 | mbx_cmd_t mc; | ||
1372 | mbx_cmd_t *mcp = &mc; | ||
1373 | |||
1374 | DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n", | ||
1375 | ha->host_no);) | ||
1376 | |||
1377 | mcp->mb[0] = MBC_GET_PORT_NAME; | ||
1378 | mcp->out_mb = MBX_1|MBX_0; | ||
1379 | if (HAS_EXTENDED_IDS(ha)) { | ||
1380 | mcp->mb[1] = loop_id; | ||
1381 | mcp->mb[10] = opt; | ||
1382 | mcp->out_mb |= MBX_10; | ||
1383 | } else { | ||
1384 | mcp->mb[1] = loop_id << 8 | opt; | ||
1385 | } | ||
1386 | |||
1387 | mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
1388 | mcp->tov = 30; | ||
1389 | mcp->flags = 0; | ||
1390 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1391 | |||
1392 | if (rval != QLA_SUCCESS) { | ||
1393 | /*EMPTY*/ | ||
1394 | DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n", | ||
1395 | ha->host_no, rval);) | ||
1396 | } else { | ||
1397 | if (name != NULL) { | ||
1398 | /* This function returns name in big endian. */ | ||
1399 | name[0] = LSB(mcp->mb[2]); | ||
1400 | name[1] = MSB(mcp->mb[2]); | ||
1401 | name[2] = LSB(mcp->mb[3]); | ||
1402 | name[3] = MSB(mcp->mb[3]); | ||
1403 | name[4] = LSB(mcp->mb[6]); | ||
1404 | name[5] = MSB(mcp->mb[6]); | ||
1405 | name[6] = LSB(mcp->mb[7]); | ||
1406 | name[7] = MSB(mcp->mb[7]); | ||
1407 | } | ||
1408 | |||
1409 | DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n", | ||
1410 | ha->host_no);) | ||
1411 | } | ||
1412 | |||
1413 | return rval; | ||
1414 | } | ||
1415 | |||
1416 | /* | ||
1417 | * qla2x00_lip_reset | ||
1418 | * Issue LIP reset mailbox command. | ||
1419 | * | ||
1420 | * Input: | ||
1421 | * ha = adapter block pointer. | ||
1422 | * TARGET_QUEUE_LOCK must be released. | ||
1423 | * ADAPTER_STATE_LOCK must be released. | ||
1424 | * | ||
1425 | * Returns: | ||
1426 | * qla2x00 local function return status code. | ||
1427 | * | ||
1428 | * Context: | ||
1429 | * Kernel context. | ||
1430 | */ | ||
1431 | int | ||
1432 | qla2x00_lip_reset(scsi_qla_host_t *ha) | ||
1433 | { | ||
1434 | int rval; | ||
1435 | mbx_cmd_t mc; | ||
1436 | mbx_cmd_t *mcp = &mc; | ||
1437 | |||
1438 | DEBUG11(printk("qla2x00_lip_reset(%ld): entered.\n", | ||
1439 | ha->host_no);) | ||
1440 | |||
1441 | mcp->mb[0] = MBC_LIP_RESET; | ||
1442 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; | ||
1443 | if (HAS_EXTENDED_IDS(ha)) { | ||
1444 | mcp->mb[1] = 0x00ff; | ||
1445 | mcp->mb[10] = 0; | ||
1446 | mcp->out_mb |= MBX_10; | ||
1447 | } else { | ||
1448 | mcp->mb[1] = 0xff00; | ||
1449 | } | ||
1450 | mcp->mb[2] = ha->loop_reset_delay; | ||
1451 | mcp->mb[3] = 0; | ||
1452 | |||
1453 | mcp->in_mb = MBX_0; | ||
1454 | mcp->tov = 30; | ||
1455 | mcp->flags = 0; | ||
1456 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1457 | |||
1458 | if (rval != QLA_SUCCESS) { | ||
1459 | /*EMPTY*/ | ||
1460 | DEBUG2_3_11(printk("qla2x00_lip_reset(%ld): failed=%x.\n", | ||
1461 | ha->host_no, rval);) | ||
1462 | } else { | ||
1463 | /*EMPTY*/ | ||
1464 | DEBUG11(printk("qla2x00_lip_reset(%ld): done.\n", ha->host_no);) | ||
1465 | } | ||
1466 | |||
1467 | return rval; | ||
1468 | } | ||
1469 | |||
1470 | /* | ||
1471 | * qla2x00_send_sns | ||
1472 | * Send SNS command. | ||
1473 | * | ||
1474 | * Input: | ||
1475 | * ha = adapter block pointer. | ||
1476 | * sns = pointer for command. | ||
1477 | * cmd_size = command size. | ||
1478 | * buf_size = response/command size. | ||
1479 | * TARGET_QUEUE_LOCK must be released. | ||
1480 | * ADAPTER_STATE_LOCK must be released. | ||
1481 | * | ||
1482 | * Returns: | ||
1483 | * qla2x00 local function return status code. | ||
1484 | * | ||
1485 | * Context: | ||
1486 | * Kernel context. | ||
1487 | */ | ||
1488 | int | ||
1489 | qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address, | ||
1490 | uint16_t cmd_size, size_t buf_size) | ||
1491 | { | ||
1492 | int rval; | ||
1493 | mbx_cmd_t mc; | ||
1494 | mbx_cmd_t *mcp = &mc; | ||
1495 | |||
1496 | DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n", | ||
1497 | ha->host_no);) | ||
1498 | |||
1499 | DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total " | ||
1500 | "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);) | ||
1501 | |||
1502 | mcp->mb[0] = MBC_SEND_SNS_COMMAND; | ||
1503 | mcp->mb[1] = cmd_size; | ||
1504 | mcp->mb[2] = MSW(sns_phys_address); | ||
1505 | mcp->mb[3] = LSW(sns_phys_address); | ||
1506 | mcp->mb[6] = MSW(MSD(sns_phys_address)); | ||
1507 | mcp->mb[7] = LSW(MSD(sns_phys_address)); | ||
1508 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
1509 | mcp->in_mb = MBX_0|MBX_1; | ||
1510 | mcp->buf_size = buf_size; | ||
1511 | mcp->flags = MBX_DMA_OUT|MBX_DMA_IN; | ||
1512 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | ||
1513 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1514 | |||
1515 | if (rval != QLA_SUCCESS) { | ||
1516 | /*EMPTY*/ | ||
1517 | DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " | ||
1518 | "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);) | ||
1519 | DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " | ||
1520 | "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);) | ||
1521 | } else { | ||
1522 | /*EMPTY*/ | ||
1523 | DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);) | ||
1524 | } | ||
1525 | |||
1526 | return rval; | ||
1527 | } | ||
1528 | |||
1529 | /* | ||
1530 | * qla2x00_login_fabric | ||
1531 | * Issue login fabric port mailbox command. | ||
1532 | * | ||
1533 | * Input: | ||
1534 | * ha = adapter block pointer. | ||
1535 | * loop_id = device loop ID. | ||
1536 | * domain = device domain. | ||
1537 | * area = device area. | ||
1538 | * al_pa = device AL_PA. | ||
1539 | * status = pointer for return status. | ||
1540 | * opt = command options. | ||
1541 | * TARGET_QUEUE_LOCK must be released. | ||
1542 | * ADAPTER_STATE_LOCK must be released. | ||
1543 | * | ||
1544 | * Returns: | ||
1545 | * qla2x00 local function return status code. | ||
1546 | * | ||
1547 | * Context: | ||
1548 | * Kernel context. | ||
1549 | */ | ||
1550 | int | ||
1551 | qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain, | ||
1552 | uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt) | ||
1553 | { | ||
1554 | int rval; | ||
1555 | mbx_cmd_t mc; | ||
1556 | mbx_cmd_t *mcp = &mc; | ||
1557 | |||
1558 | DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);) | ||
1559 | |||
1560 | mcp->mb[0] = MBC_LOGIN_FABRIC_PORT; | ||
1561 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; | ||
1562 | if (HAS_EXTENDED_IDS(ha)) { | ||
1563 | mcp->mb[1] = loop_id; | ||
1564 | mcp->mb[10] = opt; | ||
1565 | mcp->out_mb |= MBX_10; | ||
1566 | } else { | ||
1567 | mcp->mb[1] = (loop_id << 8) | opt; | ||
1568 | } | ||
1569 | mcp->mb[2] = domain; | ||
1570 | mcp->mb[3] = area << 8 | al_pa; | ||
1571 | |||
1572 | mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0; | ||
1573 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | ||
1574 | mcp->flags = 0; | ||
1575 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1576 | |||
1577 | /* Return mailbox statuses. */ | ||
1578 | if (mb != NULL) { | ||
1579 | mb[0] = mcp->mb[0]; | ||
1580 | mb[1] = mcp->mb[1]; | ||
1581 | mb[2] = mcp->mb[2]; | ||
1582 | mb[6] = mcp->mb[6]; | ||
1583 | mb[7] = mcp->mb[7]; | ||
1584 | } | ||
1585 | |||
1586 | if (rval != QLA_SUCCESS) { | ||
1587 | /* RLU tmp code: need to change main mailbox_command function to | ||
1588 | * return ok even when the mailbox completion value is not | ||
1589 | * SUCCESS. The caller needs to be responsible to interpret | ||
1590 | * the return values of this mailbox command if we're not | ||
1591 | * to change too much of the existing code. | ||
1592 | */ | ||
1593 | if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 || | ||
1594 | mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 || | ||
1595 | mcp->mb[0] == 0x4006) | ||
1596 | rval = QLA_SUCCESS; | ||
1597 | |||
1598 | /*EMPTY*/ | ||
1599 | DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x " | ||
1600 | "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval, | ||
1601 | mcp->mb[0], mcp->mb[1], mcp->mb[2]);) | ||
1602 | } else { | ||
1603 | /*EMPTY*/ | ||
1604 | DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n", | ||
1605 | ha->host_no);) | ||
1606 | } | ||
1607 | |||
1608 | return rval; | ||
1609 | } | ||
1610 | |||
1611 | /* | ||
1612 | * qla2x00_login_local_device | ||
1613 | * Issue login loop port mailbox command. | ||
1614 | * | ||
1615 | * Input: | ||
1616 | * ha = adapter block pointer. | ||
1617 | * loop_id = device loop ID. | ||
1618 | * opt = command options. | ||
1619 | * | ||
1620 | * Returns: | ||
1621 | * Return status code. | ||
1622 | * | ||
1623 | * Context: | ||
1624 | * Kernel context. | ||
1625 | * | ||
1626 | */ | ||
1627 | int | ||
1628 | qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id, | ||
1629 | uint16_t *mb_ret, uint8_t opt) | ||
1630 | { | ||
1631 | int rval; | ||
1632 | mbx_cmd_t mc; | ||
1633 | mbx_cmd_t *mcp = &mc; | ||
1634 | |||
1635 | DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);) | ||
1636 | |||
1637 | mcp->mb[0] = MBC_LOGIN_LOOP_PORT; | ||
1638 | if (HAS_EXTENDED_IDS(ha)) | ||
1639 | mcp->mb[1] = loop_id; | ||
1640 | else | ||
1641 | mcp->mb[1] = loop_id << 8; | ||
1642 | mcp->mb[2] = opt; | ||
1643 | mcp->out_mb = MBX_2|MBX_1|MBX_0; | ||
1644 | mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0; | ||
1645 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | ||
1646 | mcp->flags = 0; | ||
1647 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1648 | |||
1649 | /* Return mailbox statuses. */ | ||
1650 | if (mb_ret != NULL) { | ||
1651 | mb_ret[0] = mcp->mb[0]; | ||
1652 | mb_ret[1] = mcp->mb[1]; | ||
1653 | mb_ret[6] = mcp->mb[6]; | ||
1654 | mb_ret[7] = mcp->mb[7]; | ||
1655 | } | ||
1656 | |||
1657 | if (rval != QLA_SUCCESS) { | ||
1658 | /* AV tmp code: need to change main mailbox_command function to | ||
1659 | * return ok even when the mailbox completion value is not | ||
1660 | * SUCCESS. The caller needs to be responsible to interpret | ||
1661 | * the return values of this mailbox command if we're not | ||
1662 | * to change too much of the existing code. | ||
1663 | */ | ||
1664 | if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006) | ||
1665 | rval = QLA_SUCCESS; | ||
1666 | |||
1667 | DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " | ||
1668 | "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval, | ||
1669 | mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);) | ||
1670 | DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " | ||
1671 | "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval, | ||
1672 | mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);) | ||
1673 | } else { | ||
1674 | /*EMPTY*/ | ||
1675 | DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);) | ||
1676 | } | ||
1677 | |||
1678 | return (rval); | ||
1679 | } | ||
1680 | |||
1681 | /* | ||
1682 | * qla2x00_fabric_logout | ||
1683 | * Issue logout fabric port mailbox command. | ||
1684 | * | ||
1685 | * Input: | ||
1686 | * ha = adapter block pointer. | ||
1687 | * loop_id = device loop ID. | ||
1688 | * TARGET_QUEUE_LOCK must be released. | ||
1689 | * ADAPTER_STATE_LOCK must be released. | ||
1690 | * | ||
1691 | * Returns: | ||
1692 | * qla2x00 local function return status code. | ||
1693 | * | ||
1694 | * Context: | ||
1695 | * Kernel context. | ||
1696 | */ | ||
1697 | int | ||
1698 | qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id) | ||
1699 | { | ||
1700 | int rval; | ||
1701 | mbx_cmd_t mc; | ||
1702 | mbx_cmd_t *mcp = &mc; | ||
1703 | |||
1704 | DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n", | ||
1705 | ha->host_no);) | ||
1706 | |||
1707 | mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT; | ||
1708 | mcp->out_mb = MBX_1|MBX_0; | ||
1709 | if (HAS_EXTENDED_IDS(ha)) { | ||
1710 | mcp->mb[1] = loop_id; | ||
1711 | mcp->mb[10] = 0; | ||
1712 | mcp->out_mb |= MBX_10; | ||
1713 | } else { | ||
1714 | mcp->mb[1] = loop_id << 8; | ||
1715 | } | ||
1716 | |||
1717 | mcp->in_mb = MBX_1|MBX_0; | ||
1718 | mcp->tov = 30; | ||
1719 | mcp->flags = 0; | ||
1720 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1721 | |||
1722 | if (rval != QLA_SUCCESS) { | ||
1723 | /*EMPTY*/ | ||
1724 | DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x " | ||
1725 | "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);) | ||
1726 | } else { | ||
1727 | /*EMPTY*/ | ||
1728 | DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n", | ||
1729 | ha->host_no);) | ||
1730 | } | ||
1731 | |||
1732 | return rval; | ||
1733 | } | ||
1734 | |||
1735 | /* | ||
1736 | * qla2x00_full_login_lip | ||
1737 | * Issue full login LIP mailbox command. | ||
1738 | * | ||
1739 | * Input: | ||
1740 | * ha = adapter block pointer. | ||
1741 | * TARGET_QUEUE_LOCK must be released. | ||
1742 | * ADAPTER_STATE_LOCK must be released. | ||
1743 | * | ||
1744 | * Returns: | ||
1745 | * qla2x00 local function return status code. | ||
1746 | * | ||
1747 | * Context: | ||
1748 | * Kernel context. | ||
1749 | */ | ||
1750 | int | ||
1751 | qla2x00_full_login_lip(scsi_qla_host_t *ha) | ||
1752 | { | ||
1753 | int rval; | ||
1754 | mbx_cmd_t mc; | ||
1755 | mbx_cmd_t *mcp = &mc; | ||
1756 | |||
1757 | DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n", | ||
1758 | ha->host_no);) | ||
1759 | |||
1760 | mcp->mb[0] = MBC_LIP_FULL_LOGIN; | ||
1761 | mcp->mb[1] = 0; | ||
1762 | mcp->mb[2] = 0; | ||
1763 | mcp->mb[3] = 0; | ||
1764 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; | ||
1765 | mcp->in_mb = MBX_0; | ||
1766 | mcp->tov = 30; | ||
1767 | mcp->flags = 0; | ||
1768 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1769 | |||
1770 | if (rval != QLA_SUCCESS) { | ||
1771 | /*EMPTY*/ | ||
1772 | DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n", | ||
1773 | ha->instance, rval);) | ||
1774 | } else { | ||
1775 | /*EMPTY*/ | ||
1776 | DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n", | ||
1777 | ha->host_no);) | ||
1778 | } | ||
1779 | |||
1780 | return rval; | ||
1781 | } | ||
1782 | |||
1783 | /* | ||
1784 | * qla2x00_get_id_list | ||
1785 | * | ||
1786 | * Input: | ||
1787 | * ha = adapter block pointer. | ||
1788 | * | ||
1789 | * Returns: | ||
1790 | * qla2x00 local function return status code. | ||
1791 | * | ||
1792 | * Context: | ||
1793 | * Kernel context. | ||
1794 | */ | ||
1795 | int | ||
1796 | qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma, | ||
1797 | uint16_t *entries) | ||
1798 | { | ||
1799 | int rval; | ||
1800 | mbx_cmd_t mc; | ||
1801 | mbx_cmd_t *mcp = &mc; | ||
1802 | |||
1803 | DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n", | ||
1804 | ha->host_no);) | ||
1805 | |||
1806 | if (id_list == NULL) | ||
1807 | return QLA_FUNCTION_FAILED; | ||
1808 | |||
1809 | mcp->mb[0] = MBC_GET_ID_LIST; | ||
1810 | mcp->mb[1] = MSW(id_list_dma); | ||
1811 | mcp->mb[2] = LSW(id_list_dma); | ||
1812 | mcp->mb[3] = MSW(MSD(id_list_dma)); | ||
1813 | mcp->mb[6] = LSW(MSD(id_list_dma)); | ||
1814 | mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
1815 | mcp->in_mb = MBX_1|MBX_0; | ||
1816 | mcp->tov = 30; | ||
1817 | mcp->flags = 0; | ||
1818 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1819 | |||
1820 | if (rval != QLA_SUCCESS) { | ||
1821 | /*EMPTY*/ | ||
1822 | DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n", | ||
1823 | ha->host_no, rval);) | ||
1824 | } else { | ||
1825 | *entries = mcp->mb[1]; | ||
1826 | DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n", | ||
1827 | ha->host_no);) | ||
1828 | } | ||
1829 | |||
1830 | return rval; | ||
1831 | } | ||
1832 | |||
1833 | /* | ||
1834 | * qla2x00_get_resource_cnts | ||
1835 | * Get current firmware resource counts. | ||
1836 | * | ||
1837 | * Input: | ||
1838 | * ha = adapter block pointer. | ||
1839 | * | ||
1840 | * Returns: | ||
1841 | * qla2x00 local function return status code. | ||
1842 | * | ||
1843 | * Context: | ||
1844 | * Kernel context. | ||
1845 | */ | ||
1846 | int | ||
1847 | qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt, | ||
1848 | uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt) | ||
1849 | { | ||
1850 | int rval; | ||
1851 | mbx_cmd_t mc; | ||
1852 | mbx_cmd_t *mcp = &mc; | ||
1853 | |||
1854 | DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no)); | ||
1855 | |||
1856 | mcp->mb[0] = MBC_GET_RESOURCE_COUNTS; | ||
1857 | mcp->out_mb = MBX_0; | ||
1858 | mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | ||
1859 | mcp->tov = 30; | ||
1860 | mcp->flags = 0; | ||
1861 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1862 | |||
1863 | if (rval != QLA_SUCCESS) { | ||
1864 | /*EMPTY*/ | ||
1865 | DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__, | ||
1866 | ha->host_no, mcp->mb[0]);) | ||
1867 | } else { | ||
1868 | DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x " | ||
1869 | "mb7=%x mb10=%x.\n", __func__, ha->host_no, | ||
1870 | mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7], | ||
1871 | mcp->mb[10])); | ||
1872 | |||
1873 | if (cur_xchg_cnt) | ||
1874 | *cur_xchg_cnt = mcp->mb[3]; | ||
1875 | if (orig_xchg_cnt) | ||
1876 | *orig_xchg_cnt = mcp->mb[6]; | ||
1877 | if (cur_iocb_cnt) | ||
1878 | *cur_iocb_cnt = mcp->mb[7]; | ||
1879 | if (orig_iocb_cnt) | ||
1880 | *orig_iocb_cnt = mcp->mb[10]; | ||
1881 | } | ||
1882 | |||
1883 | return (rval); | ||
1884 | } | ||
1885 | |||
1886 | #if defined(QL_DEBUG_LEVEL_3) | ||
1887 | /* | ||
1888 | * qla2x00_get_fcal_position_map | ||
1889 | * Get FCAL (LILP) position map using mailbox command | ||
1890 | * | ||
1891 | * Input: | ||
1892 | * ha = adapter state pointer. | ||
1893 | * pos_map = buffer pointer (can be NULL). | ||
1894 | * | ||
1895 | * Returns: | ||
1896 | * qla2x00 local function return status code. | ||
1897 | * | ||
1898 | * Context: | ||
1899 | * Kernel context. | ||
1900 | */ | ||
1901 | int | ||
1902 | qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map) | ||
1903 | { | ||
1904 | int rval; | ||
1905 | mbx_cmd_t mc; | ||
1906 | mbx_cmd_t *mcp = &mc; | ||
1907 | char *pmap; | ||
1908 | dma_addr_t pmap_dma; | ||
1909 | |||
1910 | pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma); | ||
1911 | if (pmap == NULL) { | ||
1912 | DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****", | ||
1913 | __func__, ha->host_no)); | ||
1914 | return QLA_MEMORY_ALLOC_FAILED; | ||
1915 | } | ||
1916 | memset(pmap, 0, FCAL_MAP_SIZE); | ||
1917 | |||
1918 | mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP; | ||
1919 | mcp->mb[2] = MSW(pmap_dma); | ||
1920 | mcp->mb[3] = LSW(pmap_dma); | ||
1921 | mcp->mb[6] = MSW(MSD(pmap_dma)); | ||
1922 | mcp->mb[7] = LSW(MSD(pmap_dma)); | ||
1923 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; | ||
1924 | mcp->in_mb = MBX_1|MBX_0; | ||
1925 | mcp->buf_size = FCAL_MAP_SIZE; | ||
1926 | mcp->flags = MBX_DMA_IN; | ||
1927 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | ||
1928 | rval = qla2x00_mailbox_command(ha, mcp); | ||
1929 | |||
1930 | if (rval == QLA_SUCCESS) { | ||
1931 | DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map " | ||
1932 | "size (%x)\n", __func__, ha->host_no, mcp->mb[0], | ||
1933 | mcp->mb[1], (unsigned)pmap[0])); | ||
1934 | DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1)); | ||
1935 | |||
1936 | if (pos_map) | ||
1937 | memcpy(pos_map, pmap, FCAL_MAP_SIZE); | ||
1938 | } | ||
1939 | dma_pool_free(ha->s_dma_pool, pmap, pmap_dma); | ||
1940 | |||
1941 | if (rval != QLA_SUCCESS) { | ||
1942 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | ||
1943 | ha->host_no, rval)); | ||
1944 | } else { | ||
1945 | DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no)); | ||
1946 | } | ||
1947 | |||
1948 | return rval; | ||
1949 | } | ||
1950 | #endif | ||