]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/scsi/qla2xxx/qla_mbx.c
[SCSI] qla2xxx: Sparse cleanups in qla_mid.c
[net-next-2.6.git] / drivers / scsi / qla2xxx / qla_mbx.c
CommitLineData
1da177e4 1/*
fa90c54f
AV
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
1da177e4 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
1da177e4
LT
6 */
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
744f11fd 16 DEBUG11(printk("qla2x00_sem_timeout: entered.\n"));
1da177e4
LT
17
18 if (sem_ptr != NULL) {
19 up(sem_ptr);
20 }
21
744f11fd 22 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n"));
1da177e4
LT
23}
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
2c3dfe3f 45qla2x00_mailbox_command(scsi_qla_host_t *pvha, mbx_cmd_t *mcp)
1da177e4
LT
46{
47 int rval;
48 unsigned long flags = 0;
2c3dfe3f 49 device_reg_t __iomem *reg;
1da177e4 50 struct timer_list tmp_intr_timer;
1c7c6357 51 uint8_t abort_active;
2c3dfe3f 52 uint8_t io_lock_on;
1da177e4
LT
53 uint16_t command;
54 uint16_t *iptr;
55 uint16_t __iomem *optr;
56 uint32_t cnt;
57 uint32_t mboxes;
1da177e4 58 unsigned long wait_time;
2c3dfe3f
SJ
59 scsi_qla_host_t *ha = to_qla_parent(pvha);
60
61 reg = ha->iobase;
62 io_lock_on = ha->flags.init_done;
1da177e4
LT
63
64 rval = QLA_SUCCESS;
1c7c6357
AV
65 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
66
2c3dfe3f 67 DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
1da177e4 68
1da177e4 69 /*
1c7c6357
AV
70 * Wait for active mailbox commands to finish by waiting at most tov
71 * seconds. This is to serialize actual issuing of mailbox cmds during
72 * non ISP abort time.
1da177e4
LT
73 */
74 if (!abort_active) {
75 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
76 /* Timeout occurred. Return error. */
1c7c6357 77 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
744f11fd 78 "Exiting.\n", __func__, ha->host_no));
1da177e4
LT
79 return QLA_FUNCTION_TIMEOUT;
80 }
81 }
82
83 ha->flags.mbox_busy = 1;
84 /* Save mailbox command for debug */
85 ha->mcp = mcp;
86
1c7c6357 87 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
744f11fd 88 ha->host_no, mcp->mb[0]));
1da177e4
LT
89
90 spin_lock_irqsave(&ha->hardware_lock, flags);
91
92 /* Load mailbox registers. */
e428924c 93 if (IS_FWI2_CAPABLE(ha))
1c7c6357
AV
94 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
95 else
96 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
1da177e4
LT
97
98 iptr = mcp->mb;
99 command = mcp->mb[0];
100 mboxes = mcp->out_mb;
101
102 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
103 if (IS_QLA2200(ha) && cnt == 8)
1c7c6357
AV
104 optr =
105 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
1da177e4
LT
106 if (mboxes & BIT_0)
107 WRT_REG_WORD(optr, *iptr);
108
109 mboxes >>= 1;
110 optr++;
111 iptr++;
112 }
113
114#if defined(QL_DEBUG_LEVEL_1)
1c7c6357
AV
115 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
116 __func__, ha->host_no);
1da177e4
LT
117 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
118 printk("\n");
119 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
120 printk("\n");
121 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
122 printk("\n");
1c7c6357 123 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
1da177e4
LT
124 qla2x00_dump_regs(ha);
125#endif
126
127 /* Issue set host interrupt command to send cmd out. */
128 ha->flags.mbox_int = 0;
129 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
130
131 /* Unlock mbx registers and wait for interrupt */
1c7c6357 132 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
744f11fd 133 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
1da177e4
LT
134
135 /* Wait for mbx cmd completion until timeout */
136
137 if (!abort_active && io_lock_on) {
138 /* sleep on completion semaphore */
1c7c6357 139 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
744f11fd 140 __func__, ha->host_no));
1da177e4
LT
141
142 init_timer(&tmp_intr_timer);
143 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
144 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
145 tmp_intr_timer.function =
146 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
147
1c7c6357 148 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
744f11fd 149 ha->host_no));
1da177e4
LT
150 add_timer(&tmp_intr_timer);
151
1c7c6357 152 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
744f11fd 153 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
1da177e4
LT
154
155 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
156
e428924c 157 if (IS_FWI2_CAPABLE(ha))
1c7c6357
AV
158 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
159 else
160 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
1da177e4
LT
161 spin_unlock_irqrestore(&ha->hardware_lock, flags);
162
1da177e4
LT
163 /* Wait for either the timer to expire
164 * or the mbox completion interrupt
165 */
166 down(&ha->mbx_intr_sem);
167
1c7c6357 168 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
744f11fd 169 ha->host_no, jiffies));
1da177e4
LT
170 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
171
172 /* delete the timer */
173 del_timer(&tmp_intr_timer);
174 } else {
1c7c6357 175 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
744f11fd 176 ha->host_no, command));
1da177e4 177
e428924c 178 if (IS_FWI2_CAPABLE(ha))
1c7c6357
AV
179 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
180 else
181 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
1da177e4 182 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1da177e4
LT
183
184 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
185 while (!ha->flags.mbox_int) {
186 if (time_after(jiffies, wait_time))
187 break;
188
189 /* Check for pending interrupts. */
190 qla2x00_poll(ha);
191
59989831
AV
192 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
193 !ha->flags.mbox_int)
194 msleep(10);
1da177e4
LT
195 } /* while */
196 }
197
1da177e4
LT
198 /* Check whether we timed out */
199 if (ha->flags.mbox_int) {
200 uint16_t *iptr2;
201
1c7c6357 202 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
744f11fd 203 ha->host_no, command));
1da177e4
LT
204
205 /* Got interrupt. Clear the flag. */
206 ha->flags.mbox_int = 0;
207 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
208
354d6b21 209 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
1da177e4 210 rval = QLA_FUNCTION_FAILED;
1da177e4
LT
211
212 /* Load return mailbox registers. */
213 iptr2 = mcp->mb;
214 iptr = (uint16_t *)&ha->mailbox_out[0];
215 mboxes = mcp->in_mb;
216 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
217 if (mboxes & BIT_0)
218 *iptr2 = *iptr;
219
220 mboxes >>= 1;
221 iptr2++;
222 iptr++;
223 }
224 } else {
225
226#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
227 defined(QL_DEBUG_LEVEL_11)
1c7c6357
AV
228 uint16_t mb0;
229 uint32_t ictrl;
230
e428924c 231 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
232 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
233 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
234 } else {
cca5335c 235 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
1c7c6357
AV
236 ictrl = RD_REG_WORD(&reg->isp.ictrl);
237 }
238 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
239 __func__, ha->host_no, command);
240 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
241 ha->host_no, ictrl, jiffies);
242 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
243 ha->host_no, mb0);
1da177e4
LT
244 qla2x00_dump_regs(ha);
245#endif
246
1da177e4
LT
247 rval = QLA_FUNCTION_TIMEOUT;
248 }
249
1da177e4
LT
250 ha->flags.mbox_busy = 0;
251
252 /* Clean up */
253 ha->mcp = NULL;
254
255 if (!abort_active) {
1c7c6357 256 DEBUG11(printk("%s(%ld): checking for additional resp "
744f11fd 257 "interrupt.\n", __func__, ha->host_no));
1da177e4
LT
258
259 /* polling mode for non isp_abort commands. */
260 qla2x00_poll(ha);
261 }
262
1c7c6357
AV
263 if (rval == QLA_FUNCTION_TIMEOUT &&
264 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
1da177e4
LT
265 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
266 /* not in dpc. schedule it for dpc to take over. */
1c7c6357 267 DEBUG(printk("%s(%ld): timeout schedule "
744f11fd 268 "isp_abort_needed.\n", __func__, ha->host_no));
1c7c6357 269 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
744f11fd 270 "isp_abort_needed.\n", __func__, ha->host_no));
1da177e4
LT
271 qla_printk(KERN_WARNING, ha,
272 "Mailbox command timeout occured. Scheduling ISP "
273 "abort.\n");
274 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
39a11240 275 qla2xxx_wake_dpc(ha);
1da177e4 276 } else if (!abort_active) {
1da177e4 277 /* call abort directly since we are in the DPC thread */
1c7c6357 278 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
744f11fd 279 __func__, ha->host_no));
1c7c6357 280 DEBUG2_3_11(printk("%s(%ld): timeout calling "
744f11fd 281 "abort_isp\n", __func__, ha->host_no));
1da177e4
LT
282 qla_printk(KERN_WARNING, ha,
283 "Mailbox command timeout occured. Issuing ISP "
284 "abort.\n");
285
286 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
287 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
288 if (qla2x00_abort_isp(ha)) {
1c7c6357 289 /* Failed. retry later. */
1da177e4
LT
290 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
291 }
292 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1c7c6357 293 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
744f11fd 294 ha->host_no));
1c7c6357 295 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
744f11fd 296 __func__, ha->host_no));
1da177e4
LT
297 }
298 }
299
300 /* Allow next mbx cmd to come in. */
301 if (!abort_active)
302 up(&ha->mbx_cmd_sem);
303
304 if (rval) {
1c7c6357
AV
305 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
306 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
744f11fd 307 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
1da177e4 308 } else {
744f11fd 309 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1da177e4
LT
310 }
311
1da177e4
LT
312 return rval;
313}
314
1da177e4 315int
590f98e5
AV
316qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
317 uint32_t risc_code_size)
1da177e4
LT
318{
319 int rval;
320 mbx_cmd_t mc;
321 mbx_cmd_t *mcp = &mc;
1da177e4 322
590f98e5 323 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4 324
e428924c 325 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
590f98e5
AV
326 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
327 mcp->mb[8] = MSW(risc_addr);
328 mcp->out_mb = MBX_8|MBX_0;
1da177e4 329 } else {
590f98e5
AV
330 mcp->mb[0] = MBC_LOAD_RISC_RAM;
331 mcp->out_mb = MBX_0;
1da177e4 332 }
1da177e4
LT
333 mcp->mb[1] = LSW(risc_addr);
334 mcp->mb[2] = MSW(req_dma);
335 mcp->mb[3] = LSW(req_dma);
1da177e4
LT
336 mcp->mb[6] = MSW(MSD(req_dma));
337 mcp->mb[7] = LSW(MSD(req_dma));
590f98e5 338 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
e428924c 339 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
340 mcp->mb[4] = MSW(risc_code_size);
341 mcp->mb[5] = LSW(risc_code_size);
342 mcp->out_mb |= MBX_5|MBX_4;
343 } else {
344 mcp->mb[4] = LSW(risc_code_size);
345 mcp->out_mb |= MBX_4;
346 }
347
1da177e4
LT
348 mcp->in_mb = MBX_0;
349 mcp->tov = 30;
350 mcp->flags = 0;
351 rval = qla2x00_mailbox_command(ha, mcp);
352
1da177e4 353 if (rval != QLA_SUCCESS) {
1c7c6357
AV
354 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
355 ha->host_no, rval, mcp->mb[0]));
1da177e4 356 } else {
1da177e4
LT
357 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
358 }
359
360 return rval;
361}
362
363/*
364 * qla2x00_execute_fw
1c7c6357 365 * Start adapter firmware.
1da177e4
LT
366 *
367 * Input:
1c7c6357
AV
368 * ha = adapter block pointer.
369 * TARGET_QUEUE_LOCK must be released.
370 * ADAPTER_STATE_LOCK must be released.
1da177e4
LT
371 *
372 * Returns:
1c7c6357 373 * qla2x00 local function return status code.
1da177e4
LT
374 *
375 * Context:
1c7c6357 376 * Kernel context.
1da177e4
LT
377 */
378int
1c7c6357 379qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
1da177e4
LT
380{
381 int rval;
382 mbx_cmd_t mc;
383 mbx_cmd_t *mcp = &mc;
384
744f11fd 385 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4
LT
386
387 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
1c7c6357
AV
388 mcp->out_mb = MBX_0;
389 mcp->in_mb = MBX_0;
e428924c 390 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
391 mcp->mb[1] = MSW(risc_addr);
392 mcp->mb[2] = LSW(risc_addr);
393 mcp->mb[3] = 0;
394 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
395 mcp->in_mb |= MBX_1;
396 } else {
397 mcp->mb[1] = LSW(risc_addr);
398 mcp->out_mb |= MBX_1;
399 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
400 mcp->mb[2] = 0;
401 mcp->out_mb |= MBX_2;
402 }
1da177e4
LT
403 }
404
1da177e4
LT
405 mcp->tov = 30;
406 mcp->flags = 0;
407 rval = qla2x00_mailbox_command(ha, mcp);
408
1c7c6357
AV
409 if (rval != QLA_SUCCESS) {
410 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
411 ha->host_no, rval, mcp->mb[0]));
412 } else {
e428924c 413 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357 414 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
744f11fd 415 __func__, ha->host_no, mcp->mb[1]));
1c7c6357
AV
416 } else {
417 DEBUG11(printk("%s(%ld): done.\n", __func__,
744f11fd 418 ha->host_no));
1c7c6357
AV
419 }
420 }
1da177e4
LT
421
422 return rval;
423}
424
425/*
426 * qla2x00_get_fw_version
427 * Get firmware version.
428 *
429 * Input:
430 * ha: adapter state pointer.
431 * major: pointer for major number.
432 * minor: pointer for minor number.
433 * subminor: pointer for subminor number.
434 *
435 * Returns:
436 * qla2x00 local function return status code.
437 *
438 * Context:
439 * Kernel context.
440 */
441void
442qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
443 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
444{
445 int rval;
446 mbx_cmd_t mc;
447 mbx_cmd_t *mcp = &mc;
448
449 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
450
451 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
452 mcp->out_mb = MBX_0;
453 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
454 mcp->flags = 0;
455 mcp->tov = 30;
456 rval = qla2x00_mailbox_command(ha, mcp);
457
458 /* Return mailbox data. */
459 *major = mcp->mb[1];
460 *minor = mcp->mb[2];
461 *subminor = mcp->mb[3];
462 *attributes = mcp->mb[6];
463 if (IS_QLA2100(ha) || IS_QLA2200(ha))
464 *memory = 0x1FFFF; /* Defaults to 128KB. */
465 else
466 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
467
468 if (rval != QLA_SUCCESS) {
469 /*EMPTY*/
470 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
471 ha->host_no, rval));
472 } else {
473 /*EMPTY*/
474 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
475 }
476}
477
478/*
479 * qla2x00_get_fw_options
480 * Set firmware options.
481 *
482 * Input:
483 * ha = adapter block pointer.
484 * fwopt = pointer for firmware options.
485 *
486 * Returns:
487 * qla2x00 local function return status code.
488 *
489 * Context:
490 * Kernel context.
491 */
492int
493qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
494{
495 int rval;
496 mbx_cmd_t mc;
497 mbx_cmd_t *mcp = &mc;
498
499 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
500
501 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
502 mcp->out_mb = MBX_0;
503 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
504 mcp->tov = 30;
505 mcp->flags = 0;
506 rval = qla2x00_mailbox_command(ha, mcp);
507
508 if (rval != QLA_SUCCESS) {
509 /*EMPTY*/
510 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
511 ha->host_no, rval));
512 } else {
1c7c6357 513 fwopts[0] = mcp->mb[0];
1da177e4
LT
514 fwopts[1] = mcp->mb[1];
515 fwopts[2] = mcp->mb[2];
516 fwopts[3] = mcp->mb[3];
517
518 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
519 }
520
521 return rval;
522}
523
524
525/*
526 * qla2x00_set_fw_options
527 * Set firmware options.
528 *
529 * Input:
530 * ha = adapter block pointer.
531 * fwopt = pointer for firmware options.
532 *
533 * Returns:
534 * qla2x00 local function return status code.
535 *
536 * Context:
537 * Kernel context.
538 */
539int
540qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
541{
542 int rval;
543 mbx_cmd_t mc;
544 mbx_cmd_t *mcp = &mc;
545
546 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
547
548 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
549 mcp->mb[1] = fwopts[1];
550 mcp->mb[2] = fwopts[2];
551 mcp->mb[3] = fwopts[3];
1c7c6357 552 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1da177e4 553 mcp->in_mb = MBX_0;
e428924c 554 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
555 mcp->in_mb |= MBX_1;
556 } else {
557 mcp->mb[10] = fwopts[10];
558 mcp->mb[11] = fwopts[11];
559 mcp->mb[12] = 0; /* Undocumented, but used */
560 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
561 }
1da177e4
LT
562 mcp->tov = 30;
563 mcp->flags = 0;
564 rval = qla2x00_mailbox_command(ha, mcp);
565
1c7c6357
AV
566 fwopts[0] = mcp->mb[0];
567
1da177e4
LT
568 if (rval != QLA_SUCCESS) {
569 /*EMPTY*/
1c7c6357
AV
570 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
571 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1da177e4
LT
572 } else {
573 /*EMPTY*/
574 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
575 }
576
577 return rval;
578}
579
580/*
581 * qla2x00_mbx_reg_test
582 * Mailbox register wrap test.
583 *
584 * Input:
585 * ha = adapter block pointer.
586 * TARGET_QUEUE_LOCK must be released.
587 * ADAPTER_STATE_LOCK must be released.
588 *
589 * Returns:
590 * qla2x00 local function return status code.
591 *
592 * Context:
593 * Kernel context.
594 */
595int
596qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
597{
598 int rval;
599 mbx_cmd_t mc;
600 mbx_cmd_t *mcp = &mc;
601
744f11fd 602 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
1da177e4
LT
603
604 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
605 mcp->mb[1] = 0xAAAA;
606 mcp->mb[2] = 0x5555;
607 mcp->mb[3] = 0xAA55;
608 mcp->mb[4] = 0x55AA;
609 mcp->mb[5] = 0xA5A5;
610 mcp->mb[6] = 0x5A5A;
611 mcp->mb[7] = 0x2525;
612 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
613 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
614 mcp->tov = 30;
615 mcp->flags = 0;
616 rval = qla2x00_mailbox_command(ha, mcp);
617
618 if (rval == QLA_SUCCESS) {
619 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
620 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
621 rval = QLA_FUNCTION_FAILED;
622 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
623 mcp->mb[7] != 0x2525)
624 rval = QLA_FUNCTION_FAILED;
625 }
626
627 if (rval != QLA_SUCCESS) {
628 /*EMPTY*/
629 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
744f11fd 630 ha->host_no, rval));
1da177e4
LT
631 } else {
632 /*EMPTY*/
633 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
744f11fd 634 ha->host_no));
1da177e4
LT
635 }
636
637 return rval;
638}
639
640/*
641 * qla2x00_verify_checksum
642 * Verify firmware checksum.
643 *
644 * Input:
645 * ha = adapter block pointer.
646 * TARGET_QUEUE_LOCK must be released.
647 * ADAPTER_STATE_LOCK must be released.
648 *
649 * Returns:
650 * qla2x00 local function return status code.
651 *
652 * Context:
653 * Kernel context.
654 */
655int
1c7c6357 656qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
1da177e4
LT
657{
658 int rval;
659 mbx_cmd_t mc;
660 mbx_cmd_t *mcp = &mc;
661
744f11fd 662 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4
LT
663
664 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
1c7c6357
AV
665 mcp->out_mb = MBX_0;
666 mcp->in_mb = MBX_0;
e428924c 667 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
668 mcp->mb[1] = MSW(risc_addr);
669 mcp->mb[2] = LSW(risc_addr);
670 mcp->out_mb |= MBX_2|MBX_1;
671 mcp->in_mb |= MBX_2|MBX_1;
672 } else {
673 mcp->mb[1] = LSW(risc_addr);
674 mcp->out_mb |= MBX_1;
675 mcp->in_mb |= MBX_1;
676 }
677
1da177e4
LT
678 mcp->tov = 30;
679 mcp->flags = 0;
680 rval = qla2x00_mailbox_command(ha, mcp);
681
682 if (rval != QLA_SUCCESS) {
1c7c6357 683 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
e428924c
AV
684 ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
685 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
1da177e4 686 } else {
744f11fd 687 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1da177e4
LT
688 }
689
690 return rval;
691}
692
693/*
694 * qla2x00_issue_iocb
695 * Issue IOCB using mailbox command
696 *
697 * Input:
698 * ha = adapter state pointer.
699 * buffer = buffer pointer.
700 * phys_addr = physical address of buffer.
701 * size = size of buffer.
702 * TARGET_QUEUE_LOCK must be released.
703 * ADAPTER_STATE_LOCK must be released.
704 *
705 * Returns:
706 * qla2x00 local function return status code.
707 *
708 * Context:
709 * Kernel context.
710 */
711int
712qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
713 size_t size)
714{
715 int rval;
716 mbx_cmd_t mc;
717 mbx_cmd_t *mcp = &mc;
718
719 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
720 mcp->mb[1] = 0;
721 mcp->mb[2] = MSW(phys_addr);
722 mcp->mb[3] = LSW(phys_addr);
723 mcp->mb[6] = MSW(MSD(phys_addr));
724 mcp->mb[7] = LSW(MSD(phys_addr));
725 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
726 mcp->in_mb = MBX_2|MBX_0;
727 mcp->tov = 30;
728 mcp->flags = 0;
729 rval = qla2x00_mailbox_command(ha, mcp);
730
731 if (rval != QLA_SUCCESS) {
732 /*EMPTY*/
1c7c6357 733 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
744f11fd 734 ha->host_no, rval));
1c7c6357 735 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
744f11fd 736 ha->host_no, rval));
1da177e4 737 } else {
8c958a99
AV
738 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
739
740 /* Mask reserved bits. */
741 sts_entry->entry_status &=
e428924c 742 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
1da177e4
LT
743 }
744
745 return rval;
746}
747
748/*
749 * qla2x00_abort_command
750 * Abort command aborts a specified IOCB.
751 *
752 * Input:
753 * ha = adapter block pointer.
754 * sp = SB structure pointer.
755 *
756 * Returns:
757 * qla2x00 local function return status code.
758 *
759 * Context:
760 * Kernel context.
761 */
762int
763qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
764{
765 unsigned long flags = 0;
766 fc_port_t *fcport;
767 int rval;
768 uint32_t handle;
769 mbx_cmd_t mc;
770 mbx_cmd_t *mcp = &mc;
771
744f11fd 772 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
1da177e4 773
bdf79621 774 fcport = sp->fcport;
1da177e4
LT
775
776 spin_lock_irqsave(&ha->hardware_lock, flags);
777 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
778 if (ha->outstanding_cmds[handle] == sp)
779 break;
780 }
781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
782
783 if (handle == MAX_OUTSTANDING_COMMANDS) {
784 /* command not found */
785 return QLA_FUNCTION_FAILED;
786 }
787
788 mcp->mb[0] = MBC_ABORT_COMMAND;
789 if (HAS_EXTENDED_IDS(ha))
790 mcp->mb[1] = fcport->loop_id;
791 else
792 mcp->mb[1] = fcport->loop_id << 8;
793 mcp->mb[2] = (uint16_t)handle;
794 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79621 795 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
1da177e4
LT
796 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
797 mcp->in_mb = MBX_0;
798 mcp->tov = 30;
799 mcp->flags = 0;
800 rval = qla2x00_mailbox_command(ha, mcp);
801
802 if (rval != QLA_SUCCESS) {
803 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
744f11fd 804 ha->host_no, rval));
1da177e4
LT
805 } else {
806 sp->flags |= SRB_ABORT_PENDING;
807 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
744f11fd 808 ha->host_no));
1da177e4
LT
809 }
810
811 return rval;
812}
813
814#if USE_ABORT_TGT
815/*
816 * qla2x00_abort_target
817 * Issue abort target mailbox command.
818 *
819 * Input:
820 * ha = adapter block pointer.
821 *
822 * Returns:
823 * qla2x00 local function return status code.
824 *
825 * Context:
826 * Kernel context.
827 */
828int
829qla2x00_abort_target(fc_port_t *fcport)
830{
831 int rval;
832 mbx_cmd_t mc;
833 mbx_cmd_t *mcp = &mc;
1c7c6357 834 scsi_qla_host_t *ha;
1da177e4 835
1c7c6357 836 if (fcport == NULL)
1da177e4 837 return 0;
1da177e4 838
744f11fd 839 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
1c7c6357
AV
840
841 ha = fcport->ha;
1da177e4
LT
842 mcp->mb[0] = MBC_ABORT_TARGET;
843 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1c7c6357 844 if (HAS_EXTENDED_IDS(ha)) {
1da177e4
LT
845 mcp->mb[1] = fcport->loop_id;
846 mcp->mb[10] = 0;
847 mcp->out_mb |= MBX_10;
848 } else {
849 mcp->mb[1] = fcport->loop_id << 8;
850 }
1c7c6357 851 mcp->mb[2] = ha->loop_reset_delay;
1da177e4
LT
852
853 mcp->in_mb = MBX_0;
854 mcp->tov = 30;
855 mcp->flags = 0;
1c7c6357 856 rval = qla2x00_mailbox_command(ha, mcp);
1da177e4
LT
857
858 /* Issue marker command. */
1c7c6357 859 ha->marker_needed = 1;
1da177e4
LT
860
861 if (rval != QLA_SUCCESS) {
862 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
744f11fd 863 ha->host_no, rval));
1da177e4
LT
864 } else {
865 /*EMPTY*/
866 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
744f11fd 867 ha->host_no));
1da177e4
LT
868 }
869
870 return rval;
871}
872#endif
873
1da177e4
LT
874/*
875 * qla2x00_get_adapter_id
876 * Get adapter ID and topology.
877 *
878 * Input:
879 * ha = adapter block pointer.
880 * id = pointer for loop ID.
881 * al_pa = pointer for AL_PA.
882 * area = pointer for area.
883 * domain = pointer for domain.
884 * top = pointer for topology.
885 * TARGET_QUEUE_LOCK must be released.
886 * ADAPTER_STATE_LOCK must be released.
887 *
888 * Returns:
889 * qla2x00 local function return status code.
890 *
891 * Context:
892 * Kernel context.
893 */
894int
895qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
2c3dfe3f 896 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
1da177e4
LT
897{
898 int rval;
899 mbx_cmd_t mc;
900 mbx_cmd_t *mcp = &mc;
901
902 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
744f11fd 903 ha->host_no));
1da177e4
LT
904
905 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
2c3dfe3f 906 mcp->mb[9] = ha->vp_idx;
1da177e4 907 mcp->out_mb = MBX_0;
2c3dfe3f 908 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1da177e4
LT
909 mcp->tov = 30;
910 mcp->flags = 0;
911 rval = qla2x00_mailbox_command(ha, mcp);
33135aa2
RA
912 if (mcp->mb[0] == MBS_COMMAND_ERROR)
913 rval = QLA_COMMAND_ERROR;
1da177e4
LT
914
915 /* Return data. */
916 *id = mcp->mb[1];
917 *al_pa = LSB(mcp->mb[2]);
918 *area = MSB(mcp->mb[2]);
919 *domain = LSB(mcp->mb[3]);
920 *top = mcp->mb[6];
2c3dfe3f 921 *sw_cap = mcp->mb[7];
1da177e4
LT
922
923 if (rval != QLA_SUCCESS) {
924 /*EMPTY*/
925 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
744f11fd 926 ha->host_no, rval));
1da177e4
LT
927 } else {
928 /*EMPTY*/
929 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
744f11fd 930 ha->host_no));
1da177e4
LT
931 }
932
933 return rval;
934}
935
936/*
937 * qla2x00_get_retry_cnt
938 * Get current firmware login retry count and delay.
939 *
940 * Input:
941 * ha = adapter block pointer.
942 * retry_cnt = pointer to login retry count.
943 * tov = pointer to login timeout value.
944 *
945 * Returns:
946 * qla2x00 local function return status code.
947 *
948 * Context:
949 * Kernel context.
950 */
951int
952qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
953 uint16_t *r_a_tov)
954{
955 int rval;
956 uint16_t ratov;
957 mbx_cmd_t mc;
958 mbx_cmd_t *mcp = &mc;
959
960 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
744f11fd 961 ha->host_no));
1da177e4
LT
962
963 mcp->mb[0] = MBC_GET_RETRY_COUNT;
964 mcp->out_mb = MBX_0;
965 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
966 mcp->tov = 30;
967 mcp->flags = 0;
968 rval = qla2x00_mailbox_command(ha, mcp);
969
970 if (rval != QLA_SUCCESS) {
971 /*EMPTY*/
972 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
744f11fd 973 ha->host_no, mcp->mb[0]));
1da177e4
LT
974 } else {
975 /* Convert returned data and check our values. */
976 *r_a_tov = mcp->mb[3] / 2;
977 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
978 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
979 /* Update to the larger values */
980 *retry_cnt = (uint8_t)mcp->mb[1];
981 *tov = ratov;
982 }
983
984 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
744f11fd 985 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
1da177e4
LT
986 }
987
988 return rval;
989}
990
991/*
992 * qla2x00_init_firmware
993 * Initialize adapter firmware.
994 *
995 * Input:
996 * ha = adapter block pointer.
997 * dptr = Initialization control block pointer.
998 * size = size of initialization control block.
999 * TARGET_QUEUE_LOCK must be released.
1000 * ADAPTER_STATE_LOCK must be released.
1001 *
1002 * Returns:
1003 * qla2x00 local function return status code.
1004 *
1005 * Context:
1006 * Kernel context.
1007 */
1008int
1009qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1010{
1011 int rval;
1012 mbx_cmd_t mc;
1013 mbx_cmd_t *mcp = &mc;
1014
1015 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
744f11fd 1016 ha->host_no));
1da177e4 1017
2c3dfe3f
SJ
1018 if (ha->flags.npiv_supported)
1019 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1020 else
1021 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1022
1da177e4
LT
1023 mcp->mb[2] = MSW(ha->init_cb_dma);
1024 mcp->mb[3] = LSW(ha->init_cb_dma);
1025 mcp->mb[4] = 0;
1026 mcp->mb[5] = 0;
1027 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1028 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1029 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1030 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1031 mcp->buf_size = size;
1032 mcp->flags = MBX_DMA_OUT;
1033 mcp->tov = 30;
1034 rval = qla2x00_mailbox_command(ha, mcp);
1035
1036 if (rval != QLA_SUCCESS) {
1037 /*EMPTY*/
1038 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1039 "mb0=%x.\n",
744f11fd 1040 ha->host_no, rval, mcp->mb[0]));
1da177e4
LT
1041 } else {
1042 /*EMPTY*/
1043 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
744f11fd 1044 ha->host_no));
1da177e4
LT
1045 }
1046
1047 return rval;
1048}
1049
1050/*
1051 * qla2x00_get_port_database
1052 * Issue normal/enhanced get port database mailbox command
1053 * and copy device name as necessary.
1054 *
1055 * Input:
1056 * ha = adapter state pointer.
1057 * dev = structure pointer.
1058 * opt = enhanced cmd option byte.
1059 *
1060 * Returns:
1061 * qla2x00 local function return status code.
1062 *
1063 * Context:
1064 * Kernel context.
1065 */
1066int
1067qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1068{
1069 int rval;
1070 mbx_cmd_t mc;
1071 mbx_cmd_t *mcp = &mc;
1072 port_database_t *pd;
1c7c6357 1073 struct port_database_24xx *pd24;
1da177e4
LT
1074 dma_addr_t pd_dma;
1075
744f11fd 1076 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4 1077
1c7c6357
AV
1078 pd24 = NULL;
1079 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1da177e4 1080 if (pd == NULL) {
1c7c6357
AV
1081 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1082 "structure.\n", __func__, ha->host_no));
1da177e4
LT
1083 return QLA_MEMORY_ALLOC_FAILED;
1084 }
1c7c6357 1085 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1da177e4 1086
1c7c6357 1087 mcp->mb[0] = MBC_GET_PORT_DATABASE;
e428924c 1088 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1da177e4 1089 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1da177e4
LT
1090 mcp->mb[2] = MSW(pd_dma);
1091 mcp->mb[3] = LSW(pd_dma);
1092 mcp->mb[6] = MSW(MSD(pd_dma));
1093 mcp->mb[7] = LSW(MSD(pd_dma));
2c3dfe3f
SJ
1094 mcp->mb[9] = ha->vp_idx;
1095 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1da177e4 1096 mcp->in_mb = MBX_0;
e428924c 1097 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
1098 mcp->mb[1] = fcport->loop_id;
1099 mcp->mb[10] = opt;
1100 mcp->out_mb |= MBX_10|MBX_1;
1101 mcp->in_mb |= MBX_1;
1102 } else if (HAS_EXTENDED_IDS(ha)) {
1103 mcp->mb[1] = fcport->loop_id;
1104 mcp->mb[10] = opt;
1105 mcp->out_mb |= MBX_10|MBX_1;
1106 } else {
1107 mcp->mb[1] = fcport->loop_id << 8 | opt;
1108 mcp->out_mb |= MBX_1;
1109 }
e428924c
AV
1110 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1111 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1da177e4
LT
1112 mcp->flags = MBX_DMA_IN;
1113 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1114 rval = qla2x00_mailbox_command(ha, mcp);
1115 if (rval != QLA_SUCCESS)
1116 goto gpd_error_out;
1117
e428924c 1118 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
1119 pd24 = (struct port_database_24xx *) pd;
1120
1121 /* Check for logged in state. */
1122 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1123 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1124 DEBUG2(printk("%s(%ld): Unable to verify "
1125 "login-state (%x/%x) for loop_id %x\n",
1126 __func__, ha->host_no,
1127 pd24->current_login_state,
1128 pd24->last_login_state, fcport->loop_id));
1129 rval = QLA_FUNCTION_FAILED;
1130 goto gpd_error_out;
1131 }
1da177e4 1132
1c7c6357
AV
1133 /* Names are little-endian. */
1134 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1135 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1136
1137 /* Get port_id of device. */
1138 fcport->d_id.b.domain = pd24->port_id[0];
1139 fcport->d_id.b.area = pd24->port_id[1];
1140 fcport->d_id.b.al_pa = pd24->port_id[2];
1141 fcport->d_id.b.rsvd_1 = 0;
1142
1143 /* If not target must be initiator or unknown type. */
1144 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1145 fcport->port_type = FCT_INITIATOR;
1146 else
1147 fcport->port_type = FCT_TARGET;
1148 } else {
1149 /* Check for logged in state. */
1150 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1151 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1152 rval = QLA_FUNCTION_FAILED;
1153 goto gpd_error_out;
1154 }
1da177e4 1155
1c7c6357
AV
1156 /* Names are little-endian. */
1157 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1158 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1159
1160 /* Get port_id of device. */
1161 fcport->d_id.b.domain = pd->port_id[0];
1162 fcport->d_id.b.area = pd->port_id[3];
1163 fcport->d_id.b.al_pa = pd->port_id[2];
1164 fcport->d_id.b.rsvd_1 = 0;
1165
1166 /* Check for device require authentication. */
1167 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1168 (fcport->flags &= ~FCF_AUTH_REQ);
1169
1170 /* If not target must be initiator or unknown type. */
1171 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1172 fcport->port_type = FCT_INITIATOR;
1173 else
1174 fcport->port_type = FCT_TARGET;
ad3e0eda
AV
1175
1176 /* Passback COS information. */
1177 fcport->supported_classes = (pd->options & BIT_4) ?
1178 FC_COS_CLASS2: FC_COS_CLASS3;
1c7c6357 1179 }
1da177e4
LT
1180
1181gpd_error_out:
1182 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1183
1184 if (rval != QLA_SUCCESS) {
1c7c6357
AV
1185 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1186 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1da177e4 1187 } else {
1c7c6357 1188 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1da177e4
LT
1189 }
1190
1191 return rval;
1192}
1193
1194/*
1195 * qla2x00_get_firmware_state
1196 * Get adapter firmware state.
1197 *
1198 * Input:
1199 * ha = adapter block pointer.
1200 * dptr = pointer for firmware state.
1201 * TARGET_QUEUE_LOCK must be released.
1202 * ADAPTER_STATE_LOCK must be released.
1203 *
1204 * Returns:
1205 * qla2x00 local function return status code.
1206 *
1207 * Context:
1208 * Kernel context.
1209 */
1210int
1211qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1212{
1213 int rval;
1214 mbx_cmd_t mc;
1215 mbx_cmd_t *mcp = &mc;
1216
1217 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
744f11fd 1218 ha->host_no));
1da177e4
LT
1219
1220 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1221 mcp->out_mb = MBX_0;
1222 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1223 mcp->tov = 30;
1224 mcp->flags = 0;
1225 rval = qla2x00_mailbox_command(ha, mcp);
1226
1227 /* Return firmware state. */
1228 *dptr = mcp->mb[1];
1229
1230 if (rval != QLA_SUCCESS) {
1231 /*EMPTY*/
1232 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
744f11fd 1233 "failed=%x.\n", ha->host_no, rval));
1da177e4
LT
1234 } else {
1235 /*EMPTY*/
1236 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
744f11fd 1237 ha->host_no));
1da177e4
LT
1238 }
1239
1240 return rval;
1241}
1242
1243/*
1244 * qla2x00_get_port_name
1245 * Issue get port name mailbox command.
1246 * Returned name is in big endian format.
1247 *
1248 * Input:
1249 * ha = adapter block pointer.
1250 * loop_id = loop ID of device.
1251 * name = pointer for name.
1252 * TARGET_QUEUE_LOCK must be released.
1253 * ADAPTER_STATE_LOCK must be released.
1254 *
1255 * Returns:
1256 * qla2x00 local function return status code.
1257 *
1258 * Context:
1259 * Kernel context.
1260 */
1261int
1262qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1263 uint8_t opt)
1264{
1265 int rval;
1266 mbx_cmd_t mc;
1267 mbx_cmd_t *mcp = &mc;
1268
1269 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
744f11fd 1270 ha->host_no));
1da177e4
LT
1271
1272 mcp->mb[0] = MBC_GET_PORT_NAME;
2c3dfe3f
SJ
1273 mcp->mb[9] = ha->vp_idx;
1274 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1da177e4
LT
1275 if (HAS_EXTENDED_IDS(ha)) {
1276 mcp->mb[1] = loop_id;
1277 mcp->mb[10] = opt;
1278 mcp->out_mb |= MBX_10;
1279 } else {
1280 mcp->mb[1] = loop_id << 8 | opt;
1281 }
1282
1283 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1284 mcp->tov = 30;
1285 mcp->flags = 0;
1286 rval = qla2x00_mailbox_command(ha, mcp);
1287
1288 if (rval != QLA_SUCCESS) {
1289 /*EMPTY*/
1290 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
744f11fd 1291 ha->host_no, rval));
1da177e4
LT
1292 } else {
1293 if (name != NULL) {
1294 /* This function returns name in big endian. */
1196ae02
RL
1295 name[0] = MSB(mcp->mb[2]);
1296 name[1] = LSB(mcp->mb[2]);
1297 name[2] = MSB(mcp->mb[3]);
1298 name[3] = LSB(mcp->mb[3]);
1299 name[4] = MSB(mcp->mb[6]);
1300 name[5] = LSB(mcp->mb[6]);
1301 name[6] = MSB(mcp->mb[7]);
1302 name[7] = LSB(mcp->mb[7]);
1da177e4
LT
1303 }
1304
1305 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
744f11fd 1306 ha->host_no));
1da177e4
LT
1307 }
1308
1309 return rval;
1310}
1311
1312/*
1313 * qla2x00_lip_reset
1314 * Issue LIP reset mailbox command.
1315 *
1316 * Input:
1317 * ha = adapter block pointer.
1318 * TARGET_QUEUE_LOCK must be released.
1319 * ADAPTER_STATE_LOCK must be released.
1320 *
1321 * Returns:
1322 * qla2x00 local function return status code.
1323 *
1324 * Context:
1325 * Kernel context.
1326 */
1327int
1328qla2x00_lip_reset(scsi_qla_host_t *ha)
1329{
1330 int rval;
1331 mbx_cmd_t mc;
1332 mbx_cmd_t *mcp = &mc;
1333
744f11fd 1334 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4 1335
e428924c 1336 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357 1337 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
0c8c39af
AV
1338 mcp->mb[1] = BIT_6;
1339 mcp->mb[2] = 0;
1340 mcp->mb[3] = ha->loop_reset_delay;
1c7c6357 1341 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1da177e4 1342 } else {
1c7c6357
AV
1343 mcp->mb[0] = MBC_LIP_RESET;
1344 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1345 if (HAS_EXTENDED_IDS(ha)) {
1346 mcp->mb[1] = 0x00ff;
1347 mcp->mb[10] = 0;
1348 mcp->out_mb |= MBX_10;
1349 } else {
1350 mcp->mb[1] = 0xff00;
1351 }
1352 mcp->mb[2] = ha->loop_reset_delay;
1353 mcp->mb[3] = 0;
1da177e4 1354 }
1da177e4
LT
1355 mcp->in_mb = MBX_0;
1356 mcp->tov = 30;
1357 mcp->flags = 0;
1358 rval = qla2x00_mailbox_command(ha, mcp);
1359
1360 if (rval != QLA_SUCCESS) {
1361 /*EMPTY*/
1c7c6357 1362 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
744f11fd 1363 __func__, ha->host_no, rval));
1da177e4
LT
1364 } else {
1365 /*EMPTY*/
744f11fd 1366 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1da177e4
LT
1367 }
1368
1369 return rval;
1370}
1371
1372/*
1373 * qla2x00_send_sns
1374 * Send SNS command.
1375 *
1376 * Input:
1377 * ha = adapter block pointer.
1378 * sns = pointer for command.
1379 * cmd_size = command size.
1380 * buf_size = response/command size.
1381 * TARGET_QUEUE_LOCK must be released.
1382 * ADAPTER_STATE_LOCK must be released.
1383 *
1384 * Returns:
1385 * qla2x00 local function return status code.
1386 *
1387 * Context:
1388 * Kernel context.
1389 */
1390int
1391qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1392 uint16_t cmd_size, size_t buf_size)
1393{
1394 int rval;
1395 mbx_cmd_t mc;
1396 mbx_cmd_t *mcp = &mc;
1397
1398 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
744f11fd 1399 ha->host_no));
1da177e4
LT
1400
1401 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
744f11fd 1402 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
1da177e4
LT
1403
1404 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1405 mcp->mb[1] = cmd_size;
1406 mcp->mb[2] = MSW(sns_phys_address);
1407 mcp->mb[3] = LSW(sns_phys_address);
1408 mcp->mb[6] = MSW(MSD(sns_phys_address));
1409 mcp->mb[7] = LSW(MSD(sns_phys_address));
1410 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1411 mcp->in_mb = MBX_0|MBX_1;
1412 mcp->buf_size = buf_size;
1413 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1414 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1415 rval = qla2x00_mailbox_command(ha, mcp);
1416
1417 if (rval != QLA_SUCCESS) {
1418 /*EMPTY*/
1419 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
744f11fd 1420 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1da177e4 1421 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
744f11fd 1422 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1da177e4
LT
1423 } else {
1424 /*EMPTY*/
744f11fd 1425 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
1da177e4
LT
1426 }
1427
1428 return rval;
1429}
1430
1c7c6357
AV
1431int
1432qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1433 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1434{
1435 int rval;
1436
1437 struct logio_entry_24xx *lg;
1438 dma_addr_t lg_dma;
1439 uint32_t iop[2];
1440
744f11fd 1441 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1c7c6357
AV
1442
1443 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1444 if (lg == NULL) {
1445 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1446 __func__, ha->host_no));
1447 return QLA_MEMORY_ALLOC_FAILED;
1448 }
1449 memset(lg, 0, sizeof(struct logio_entry_24xx));
1450
1451 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1452 lg->entry_count = 1;
1453 lg->nport_handle = cpu_to_le16(loop_id);
1454 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1455 if (opt & BIT_0)
1456 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
8baa51a6
AV
1457 if (opt & BIT_1)
1458 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1c7c6357
AV
1459 lg->port_id[0] = al_pa;
1460 lg->port_id[1] = area;
1461 lg->port_id[2] = domain;
2c3dfe3f 1462 lg->vp_index = cpu_to_le16(ha->vp_idx);
1c7c6357
AV
1463 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1464 if (rval != QLA_SUCCESS) {
1465 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
744f11fd 1466 "(%x).\n", __func__, ha->host_no, rval));
1c7c6357
AV
1467 } else if (lg->entry_status != 0) {
1468 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1469 "-- error status (%x).\n", __func__, ha->host_no,
1470 lg->entry_status));
1471 rval = QLA_FUNCTION_FAILED;
1472 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1473 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1474 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1475
1476 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1477 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1478 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1479 iop[1]));
1480
1481 switch (iop[0]) {
1482 case LSC_SCODE_PORTID_USED:
1483 mb[0] = MBS_PORT_ID_USED;
1484 mb[1] = LSW(iop[1]);
1485 break;
1486 case LSC_SCODE_NPORT_USED:
1487 mb[0] = MBS_LOOP_ID_USED;
1488 break;
1489 case LSC_SCODE_NOLINK:
1490 case LSC_SCODE_NOIOCB:
1491 case LSC_SCODE_NOXCB:
1492 case LSC_SCODE_CMD_FAILED:
1493 case LSC_SCODE_NOFABRIC:
1494 case LSC_SCODE_FW_NOT_READY:
1495 case LSC_SCODE_NOT_LOGGED_IN:
1496 case LSC_SCODE_NOPCB:
1497 case LSC_SCODE_ELS_REJECT:
1498 case LSC_SCODE_CMD_PARAM_ERR:
1499 case LSC_SCODE_NONPORT:
1500 case LSC_SCODE_LOGGED_IN:
1501 case LSC_SCODE_NOFLOGI_ACC:
1502 default:
1503 mb[0] = MBS_COMMAND_ERROR;
1504 break;
1505 }
1506 } else {
744f11fd 1507 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1c7c6357
AV
1508
1509 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1510
1511 mb[0] = MBS_COMMAND_COMPLETE;
1512 mb[1] = 0;
1513 if (iop[0] & BIT_4) {
1514 if (iop[0] & BIT_8)
1515 mb[1] |= BIT_1;
1516 } else
1517 mb[1] = BIT_0;
ad3e0eda
AV
1518
1519 /* Passback COS information. */
1520 mb[10] = 0;
1521 if (lg->io_parameter[7] || lg->io_parameter[8])
1522 mb[10] |= BIT_0; /* Class 2. */
1523 if (lg->io_parameter[9] || lg->io_parameter[10])
1524 mb[10] |= BIT_1; /* Class 3. */
1c7c6357
AV
1525 }
1526
1527 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1528
1529 return rval;
1530}
1531
1da177e4
LT
1532/*
1533 * qla2x00_login_fabric
1534 * Issue login fabric port mailbox command.
1535 *
1536 * Input:
1537 * ha = adapter block pointer.
1538 * loop_id = device loop ID.
1539 * domain = device domain.
1540 * area = device area.
1541 * al_pa = device AL_PA.
1542 * status = pointer for return status.
1543 * opt = command options.
1544 * TARGET_QUEUE_LOCK must be released.
1545 * ADAPTER_STATE_LOCK must be released.
1546 *
1547 * Returns:
1548 * qla2x00 local function return status code.
1549 *
1550 * Context:
1551 * Kernel context.
1552 */
1553int
1554qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1555 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1556{
1557 int rval;
1558 mbx_cmd_t mc;
1559 mbx_cmd_t *mcp = &mc;
1560
744f11fd 1561 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
1da177e4
LT
1562
1563 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1564 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1565 if (HAS_EXTENDED_IDS(ha)) {
1566 mcp->mb[1] = loop_id;
1567 mcp->mb[10] = opt;
1568 mcp->out_mb |= MBX_10;
1569 } else {
1570 mcp->mb[1] = (loop_id << 8) | opt;
1571 }
1572 mcp->mb[2] = domain;
1573 mcp->mb[3] = area << 8 | al_pa;
1574
1575 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1576 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1577 mcp->flags = 0;
1578 rval = qla2x00_mailbox_command(ha, mcp);
1579
1580 /* Return mailbox statuses. */
1581 if (mb != NULL) {
1582 mb[0] = mcp->mb[0];
1583 mb[1] = mcp->mb[1];
1584 mb[2] = mcp->mb[2];
1585 mb[6] = mcp->mb[6];
1586 mb[7] = mcp->mb[7];
ad3e0eda
AV
1587 /* COS retrieved from Get-Port-Database mailbox command. */
1588 mb[10] = 0;
1da177e4
LT
1589 }
1590
1591 if (rval != QLA_SUCCESS) {
1592 /* RLU tmp code: need to change main mailbox_command function to
1593 * return ok even when the mailbox completion value is not
1594 * SUCCESS. The caller needs to be responsible to interpret
1595 * the return values of this mailbox command if we're not
1596 * to change too much of the existing code.
1597 */
1598 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1599 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1600 mcp->mb[0] == 0x4006)
1601 rval = QLA_SUCCESS;
1602
1603 /*EMPTY*/
1604 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1605 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
744f11fd 1606 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1da177e4
LT
1607 } else {
1608 /*EMPTY*/
1609 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
744f11fd 1610 ha->host_no));
1da177e4
LT
1611 }
1612
1613 return rval;
1614}
1615
1616/*
1617 * qla2x00_login_local_device
1618 * Issue login loop port mailbox command.
fa2a1ce5 1619 *
1da177e4
LT
1620 * Input:
1621 * ha = adapter block pointer.
1622 * loop_id = device loop ID.
1623 * opt = command options.
fa2a1ce5 1624 *
1da177e4
LT
1625 * Returns:
1626 * Return status code.
fa2a1ce5 1627 *
1da177e4
LT
1628 * Context:
1629 * Kernel context.
fa2a1ce5 1630 *
1da177e4
LT
1631 */
1632int
9a52a57c 1633qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1da177e4
LT
1634 uint16_t *mb_ret, uint8_t opt)
1635{
1636 int rval;
1637 mbx_cmd_t mc;
1638 mbx_cmd_t *mcp = &mc;
1639
e428924c 1640 if (IS_FWI2_CAPABLE(ha))
9a52a57c
AV
1641 return qla24xx_login_fabric(ha, fcport->loop_id,
1642 fcport->d_id.b.domain, fcport->d_id.b.area,
1643 fcport->d_id.b.al_pa, mb_ret, opt);
1644
744f11fd 1645 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4
LT
1646
1647 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1648 if (HAS_EXTENDED_IDS(ha))
9a52a57c 1649 mcp->mb[1] = fcport->loop_id;
1da177e4 1650 else
9a52a57c 1651 mcp->mb[1] = fcport->loop_id << 8;
1da177e4
LT
1652 mcp->mb[2] = opt;
1653 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1654 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1655 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1656 mcp->flags = 0;
1657 rval = qla2x00_mailbox_command(ha, mcp);
1658
1659 /* Return mailbox statuses. */
1660 if (mb_ret != NULL) {
1661 mb_ret[0] = mcp->mb[0];
1662 mb_ret[1] = mcp->mb[1];
1663 mb_ret[6] = mcp->mb[6];
1664 mb_ret[7] = mcp->mb[7];
1665 }
1666
1667 if (rval != QLA_SUCCESS) {
1668 /* AV tmp code: need to change main mailbox_command function to
1669 * return ok even when the mailbox completion value is not
1670 * SUCCESS. The caller needs to be responsible to interpret
1671 * the return values of this mailbox command if we're not
1672 * to change too much of the existing code.
1673 */
1674 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1675 rval = QLA_SUCCESS;
1676
1677 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1678 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
744f11fd 1679 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1da177e4
LT
1680 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1681 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
744f11fd 1682 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1da177e4
LT
1683 } else {
1684 /*EMPTY*/
744f11fd 1685 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
1da177e4
LT
1686 }
1687
1688 return (rval);
1689}
1690
1c7c6357
AV
1691int
1692qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1693 uint8_t area, uint8_t al_pa)
1694{
1695 int rval;
1696 struct logio_entry_24xx *lg;
1697 dma_addr_t lg_dma;
1698
744f11fd 1699 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1c7c6357
AV
1700
1701 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1702 if (lg == NULL) {
1703 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1704 __func__, ha->host_no));
1705 return QLA_MEMORY_ALLOC_FAILED;
1706 }
1707 memset(lg, 0, sizeof(struct logio_entry_24xx));
1708
1709 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1710 lg->entry_count = 1;
1711 lg->nport_handle = cpu_to_le16(loop_id);
1712 lg->control_flags =
b1372bc9 1713 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1c7c6357
AV
1714 lg->port_id[0] = al_pa;
1715 lg->port_id[1] = area;
1716 lg->port_id[2] = domain;
2c3dfe3f 1717 lg->vp_index = cpu_to_le16(ha->vp_idx);
1c7c6357
AV
1718 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1719 if (rval != QLA_SUCCESS) {
1720 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
744f11fd 1721 "(%x).\n", __func__, ha->host_no, rval));
1c7c6357
AV
1722 } else if (lg->entry_status != 0) {
1723 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1724 "-- error status (%x).\n", __func__, ha->host_no,
1725 lg->entry_status));
1726 rval = QLA_FUNCTION_FAILED;
1727 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1728 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1729 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1730 ha->host_no, le16_to_cpu(lg->comp_status),
1731 le32_to_cpu(lg->io_parameter[0]),
744f11fd 1732 le32_to_cpu(lg->io_parameter[1])));
1c7c6357
AV
1733 } else {
1734 /*EMPTY*/
744f11fd 1735 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1c7c6357
AV
1736 }
1737
1738 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1739
1740 return rval;
1741}
1742
1da177e4
LT
1743/*
1744 * qla2x00_fabric_logout
1745 * Issue logout fabric port mailbox command.
1746 *
1747 * Input:
1748 * ha = adapter block pointer.
1749 * loop_id = device loop ID.
1750 * TARGET_QUEUE_LOCK must be released.
1751 * ADAPTER_STATE_LOCK must be released.
1752 *
1753 * Returns:
1754 * qla2x00 local function return status code.
1755 *
1756 * Context:
1757 * Kernel context.
1758 */
1759int
1c7c6357
AV
1760qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1761 uint8_t area, uint8_t al_pa)
1da177e4
LT
1762{
1763 int rval;
1764 mbx_cmd_t mc;
1765 mbx_cmd_t *mcp = &mc;
1766
1767 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
744f11fd 1768 ha->host_no));
1da177e4
LT
1769
1770 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1771 mcp->out_mb = MBX_1|MBX_0;
1772 if (HAS_EXTENDED_IDS(ha)) {
1773 mcp->mb[1] = loop_id;
1774 mcp->mb[10] = 0;
1775 mcp->out_mb |= MBX_10;
1776 } else {
1777 mcp->mb[1] = loop_id << 8;
1778 }
1779
1780 mcp->in_mb = MBX_1|MBX_0;
1781 mcp->tov = 30;
1782 mcp->flags = 0;
1783 rval = qla2x00_mailbox_command(ha, mcp);
1784
1785 if (rval != QLA_SUCCESS) {
1786 /*EMPTY*/
1787 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
744f11fd 1788 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
1da177e4
LT
1789 } else {
1790 /*EMPTY*/
1791 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
744f11fd 1792 ha->host_no));
1da177e4
LT
1793 }
1794
1795 return rval;
1796}
1797
1798/*
1799 * qla2x00_full_login_lip
1800 * Issue full login LIP mailbox command.
1801 *
1802 * Input:
1803 * ha = adapter block pointer.
1804 * TARGET_QUEUE_LOCK must be released.
1805 * ADAPTER_STATE_LOCK must be released.
1806 *
1807 * Returns:
1808 * qla2x00 local function return status code.
1809 *
1810 * Context:
1811 * Kernel context.
1812 */
1813int
1814qla2x00_full_login_lip(scsi_qla_host_t *ha)
1815{
1816 int rval;
1817 mbx_cmd_t mc;
1818 mbx_cmd_t *mcp = &mc;
1819
1820 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
744f11fd 1821 ha->host_no));
1da177e4
LT
1822
1823 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
e428924c 1824 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
0c8c39af 1825 mcp->mb[2] = 0;
1da177e4
LT
1826 mcp->mb[3] = 0;
1827 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1828 mcp->in_mb = MBX_0;
1829 mcp->tov = 30;
1830 mcp->flags = 0;
1831 rval = qla2x00_mailbox_command(ha, mcp);
1832
1833 if (rval != QLA_SUCCESS) {
1834 /*EMPTY*/
1835 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
744f11fd 1836 ha->host_no, rval));
1da177e4
LT
1837 } else {
1838 /*EMPTY*/
1839 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
744f11fd 1840 ha->host_no));
1da177e4
LT
1841 }
1842
1843 return rval;
1844}
1845
1846/*
1847 * qla2x00_get_id_list
1848 *
1849 * Input:
1850 * ha = adapter block pointer.
1851 *
1852 * Returns:
1853 * qla2x00 local function return status code.
1854 *
1855 * Context:
1856 * Kernel context.
1857 */
1858int
1859qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1860 uint16_t *entries)
1861{
1862 int rval;
1863 mbx_cmd_t mc;
1864 mbx_cmd_t *mcp = &mc;
1865
1866 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
744f11fd 1867 ha->host_no));
1da177e4
LT
1868
1869 if (id_list == NULL)
1870 return QLA_FUNCTION_FAILED;
1871
1872 mcp->mb[0] = MBC_GET_ID_LIST;
1c7c6357 1873 mcp->out_mb = MBX_0;
e428924c 1874 if (IS_FWI2_CAPABLE(ha)) {
1c7c6357
AV
1875 mcp->mb[2] = MSW(id_list_dma);
1876 mcp->mb[3] = LSW(id_list_dma);
1877 mcp->mb[6] = MSW(MSD(id_list_dma));
1878 mcp->mb[7] = LSW(MSD(id_list_dma));
247ec457 1879 mcp->mb[8] = 0;
2c3dfe3f
SJ
1880 mcp->mb[9] = ha->vp_idx;
1881 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1c7c6357
AV
1882 } else {
1883 mcp->mb[1] = MSW(id_list_dma);
1884 mcp->mb[2] = LSW(id_list_dma);
1885 mcp->mb[3] = MSW(MSD(id_list_dma));
1886 mcp->mb[6] = LSW(MSD(id_list_dma));
1887 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1888 }
1da177e4
LT
1889 mcp->in_mb = MBX_1|MBX_0;
1890 mcp->tov = 30;
1891 mcp->flags = 0;
1892 rval = qla2x00_mailbox_command(ha, mcp);
1893
1894 if (rval != QLA_SUCCESS) {
1895 /*EMPTY*/
1896 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
744f11fd 1897 ha->host_no, rval));
1da177e4
LT
1898 } else {
1899 *entries = mcp->mb[1];
1900 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
744f11fd 1901 ha->host_no));
1da177e4
LT
1902 }
1903
1904 return rval;
1905}
1906
1907/*
1908 * qla2x00_get_resource_cnts
1909 * Get current firmware resource counts.
1910 *
1911 * Input:
1912 * ha = adapter block pointer.
1913 *
1914 * Returns:
1915 * qla2x00 local function return status code.
1916 *
1917 * Context:
1918 * Kernel context.
1919 */
1920int
1921qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
4d0ea247
SJ
1922 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1923 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1da177e4
LT
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;
4d0ea247 1933 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1da177e4
LT
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__,
744f11fd 1941 ha->host_no, mcp->mb[0]));
1da177e4
LT
1942 } else {
1943 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
4d0ea247 1944 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
fa2a1ce5 1945 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
4d0ea247 1946 mcp->mb[10], mcp->mb[11]));
1da177e4
LT
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];
4d0ea247
SJ
1956 if (max_npiv_vports)
1957 *max_npiv_vports = mcp->mb[11];
1da177e4
LT
1958 }
1959
1960 return (rval);
1961}
1962
1963#if defined(QL_DEBUG_LEVEL_3)
1964/*
1965 * qla2x00_get_fcal_position_map
1966 * Get FCAL (LILP) position map using mailbox command
1967 *
1968 * Input:
1969 * ha = adapter state pointer.
1970 * pos_map = buffer pointer (can be NULL).
1971 *
1972 * Returns:
1973 * qla2x00 local function return status code.
1974 *
1975 * Context:
1976 * Kernel context.
1977 */
1978int
1979qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1980{
1981 int rval;
1982 mbx_cmd_t mc;
1983 mbx_cmd_t *mcp = &mc;
1984 char *pmap;
1985 dma_addr_t pmap_dma;
1986
1987 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1988 if (pmap == NULL) {
1989 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1990 __func__, ha->host_no));
1991 return QLA_MEMORY_ALLOC_FAILED;
1992 }
1993 memset(pmap, 0, FCAL_MAP_SIZE);
1994
1995 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1996 mcp->mb[2] = MSW(pmap_dma);
1997 mcp->mb[3] = LSW(pmap_dma);
1998 mcp->mb[6] = MSW(MSD(pmap_dma));
1999 mcp->mb[7] = LSW(MSD(pmap_dma));
2000 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2001 mcp->in_mb = MBX_1|MBX_0;
2002 mcp->buf_size = FCAL_MAP_SIZE;
2003 mcp->flags = MBX_DMA_IN;
2004 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2005 rval = qla2x00_mailbox_command(ha, mcp);
2006
2007 if (rval == QLA_SUCCESS) {
2008 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2009 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2010 mcp->mb[1], (unsigned)pmap[0]));
2011 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2012
2013 if (pos_map)
2014 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2015 }
2016 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2017
2018 if (rval != QLA_SUCCESS) {
2019 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2020 ha->host_no, rval));
2021 } else {
2022 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2023 }
2024
2025 return rval;
2026}
392e2f65
AV
2027#endif
2028
2029/*
2030 * qla2x00_get_link_status
2031 *
2032 * Input:
2033 * ha = adapter block pointer.
2034 * loop_id = device loop ID.
2035 * ret_buf = pointer to link status return buffer.
2036 *
2037 * Returns:
2038 * 0 = success.
2039 * BIT_0 = mem alloc error.
2040 * BIT_1 = mailbox error.
2041 */
2042int
2043qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2044 link_stat_t *ret_buf, uint16_t *status)
2045{
2046 int rval;
2047 mbx_cmd_t mc;
2048 mbx_cmd_t *mcp = &mc;
2049 link_stat_t *stat_buf;
2050 dma_addr_t stat_buf_dma;
2051
744f11fd 2052 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
392e2f65
AV
2053
2054 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2055 if (stat_buf == NULL) {
2056 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2057 __func__, ha->host_no));
2058 return BIT_0;
2059 }
2060 memset(stat_buf, 0, sizeof(link_stat_t));
2061
2062 mcp->mb[0] = MBC_GET_LINK_STATUS;
2063 mcp->mb[2] = MSW(stat_buf_dma);
2064 mcp->mb[3] = LSW(stat_buf_dma);
2065 mcp->mb[6] = MSW(MSD(stat_buf_dma));
2066 mcp->mb[7] = LSW(MSD(stat_buf_dma));
2067 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2068 mcp->in_mb = MBX_0;
e428924c 2069 if (IS_FWI2_CAPABLE(ha)) {
392e2f65
AV
2070 mcp->mb[1] = loop_id;
2071 mcp->mb[4] = 0;
2072 mcp->mb[10] = 0;
2073 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2074 mcp->in_mb |= MBX_1;
2075 } else if (HAS_EXTENDED_IDS(ha)) {
2076 mcp->mb[1] = loop_id;
2077 mcp->mb[10] = 0;
2078 mcp->out_mb |= MBX_10|MBX_1;
2079 } else {
2080 mcp->mb[1] = loop_id << 8;
2081 mcp->out_mb |= MBX_1;
2082 }
2083 mcp->tov = 30;
2084 mcp->flags = IOCTL_CMD;
2085 rval = qla2x00_mailbox_command(ha, mcp);
2086
2087 if (rval == QLA_SUCCESS) {
2088 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2089 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
744f11fd 2090 __func__, ha->host_no, mcp->mb[0]));
392e2f65
AV
2091 status[0] = mcp->mb[0];
2092 rval = BIT_1;
2093 } else {
2094 /* copy over data -- firmware data is LE. */
2095 ret_buf->link_fail_cnt =
2096 le32_to_cpu(stat_buf->link_fail_cnt);
2097 ret_buf->loss_sync_cnt =
2098 le32_to_cpu(stat_buf->loss_sync_cnt);
2099 ret_buf->loss_sig_cnt =
2100 le32_to_cpu(stat_buf->loss_sig_cnt);
2101 ret_buf->prim_seq_err_cnt =
2102 le32_to_cpu(stat_buf->prim_seq_err_cnt);
2103 ret_buf->inval_xmit_word_cnt =
2104 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
2105 ret_buf->inval_crc_cnt =
2106 le32_to_cpu(stat_buf->inval_crc_cnt);
2107
2108 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2109 "loss_sync=%d loss_sig=%d seq_err=%d "
2110 "inval_xmt_word=%d inval_crc=%d.\n", __func__,
2111 ha->host_no, stat_buf->link_fail_cnt,
2112 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2113 stat_buf->prim_seq_err_cnt,
2114 stat_buf->inval_xmit_word_cnt,
744f11fd 2115 stat_buf->inval_crc_cnt));
392e2f65
AV
2116 }
2117 } else {
2118 /* Failed. */
2119 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
744f11fd 2120 ha->host_no, rval));
392e2f65
AV
2121 rval = BIT_1;
2122 }
2123
2124 dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
1c7c6357 2125
392e2f65
AV
2126 return rval;
2127}
2128
2129int
1c7c6357
AV
2130qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2131 uint16_t *status)
2132{
2133 int rval;
2134 mbx_cmd_t mc;
2135 mbx_cmd_t *mcp = &mc;
2136 uint32_t *sbuf, *siter;
2137 dma_addr_t sbuf_dma;
2138
744f11fd 2139 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1c7c6357
AV
2140
2141 if (dwords > (DMA_POOL_SIZE / 4)) {
2142 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2143 "(max %d).\n", __func__, ha->host_no, dwords,
2144 DMA_POOL_SIZE / 4));
2145 return BIT_0;
2146 }
2147 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2148 if (sbuf == NULL) {
2149 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2150 __func__, ha->host_no));
2151 return BIT_0;
2152 }
2153 memset(sbuf, 0, DMA_POOL_SIZE);
2154
2155 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2156 mcp->mb[2] = MSW(sbuf_dma);
2157 mcp->mb[3] = LSW(sbuf_dma);
2158 mcp->mb[6] = MSW(MSD(sbuf_dma));
2159 mcp->mb[7] = LSW(MSD(sbuf_dma));
2160 mcp->mb[8] = dwords;
2161 mcp->mb[10] = 0;
2162 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2163 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2164 mcp->tov = 30;
2165 mcp->flags = IOCTL_CMD;
2166 rval = qla2x00_mailbox_command(ha, mcp);
2167
2168 if (rval == QLA_SUCCESS) {
2169 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2170 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2171 __func__, ha->host_no, mcp->mb[0]));
2172 status[0] = mcp->mb[0];
2173 rval = BIT_1;
2174 } else {
2175 /* Copy over data -- firmware data is LE. */
2176 siter = sbuf;
2177 while (dwords--)
2178 *dwbuf++ = le32_to_cpu(*siter++);
2179 }
2180 } else {
2181 /* Failed. */
2182 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2183 ha->host_no, rval));
2184 rval = BIT_1;
2185 }
2186
2187 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2188
2189 return rval;
2190}
1c7c6357
AV
2191
2192int
2193qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2194{
2195 int rval;
2196 fc_port_t *fcport;
2197 unsigned long flags = 0;
2198
2199 struct abort_entry_24xx *abt;
2200 dma_addr_t abt_dma;
2201 uint32_t handle;
2202
744f11fd 2203 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1c7c6357
AV
2204
2205 fcport = sp->fcport;
1c7c6357
AV
2206
2207 spin_lock_irqsave(&ha->hardware_lock, flags);
2208 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2209 if (ha->outstanding_cmds[handle] == sp)
2210 break;
2211 }
2212 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2213 if (handle == MAX_OUTSTANDING_COMMANDS) {
2214 /* Command not found. */
2215 return QLA_FUNCTION_FAILED;
2216 }
2217
2218 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2219 if (abt == NULL) {
2220 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2221 __func__, ha->host_no));
2222 return QLA_MEMORY_ALLOC_FAILED;
2223 }
2224 memset(abt, 0, sizeof(struct abort_entry_24xx));
2225
2226 abt->entry_type = ABORT_IOCB_TYPE;
2227 abt->entry_count = 1;
2228 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2229 abt->handle_to_abort = handle;
2230 abt->port_id[0] = fcport->d_id.b.al_pa;
2231 abt->port_id[1] = fcport->d_id.b.area;
2232 abt->port_id[2] = fcport->d_id.b.domain;
2c3dfe3f 2233 abt->vp_index = fcport->vp_idx;
1c7c6357
AV
2234 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2235 if (rval != QLA_SUCCESS) {
2236 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
744f11fd 2237 __func__, ha->host_no, rval));
1c7c6357
AV
2238 } else if (abt->entry_status != 0) {
2239 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2240 "-- error status (%x).\n", __func__, ha->host_no,
2241 abt->entry_status));
2242 rval = QLA_FUNCTION_FAILED;
2243 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2244 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2245 "-- completion status (%x).\n", __func__, ha->host_no,
744f11fd 2246 le16_to_cpu(abt->nport_handle)));
1c7c6357
AV
2247 rval = QLA_FUNCTION_FAILED;
2248 } else {
744f11fd 2249 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1c7c6357
AV
2250 sp->flags |= SRB_ABORT_PENDING;
2251 }
2252
2253 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2254
2255 return rval;
2256}
2257
2258struct tsk_mgmt_cmd {
2259 union {
2260 struct tsk_mgmt_entry tsk;
2261 struct sts_entry_24xx sts;
2262 } p;
2263};
2264
2265int
2266qla24xx_abort_target(fc_port_t *fcport)
2267{
2268 int rval;
2269 struct tsk_mgmt_cmd *tsk;
2270 dma_addr_t tsk_dma;
2c3dfe3f 2271 scsi_qla_host_t *ha, *pha;
1c7c6357
AV
2272
2273 if (fcport == NULL)
2274 return 0;
2275
744f11fd 2276 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
1c7c6357
AV
2277
2278 ha = fcport->ha;
2c3dfe3f
SJ
2279 pha = to_qla_parent(ha);
2280 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
1c7c6357
AV
2281 if (tsk == NULL) {
2282 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2283 "IOCB.\n", __func__, ha->host_no));
2284 return QLA_MEMORY_ALLOC_FAILED;
2285 }
2286 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2287
2288 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2289 tsk->p.tsk.entry_count = 1;
2290 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2291 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2292 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2293 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2294 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2295 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2c3dfe3f
SJ
2296 tsk->p.tsk.vp_index = fcport->vp_idx;
2297
1c7c6357
AV
2298 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2299 if (rval != QLA_SUCCESS) {
2300 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
744f11fd 2301 "(%x).\n", __func__, ha->host_no, rval));
1c7c6357
AV
2302 goto atarget_done;
2303 } else if (tsk->p.sts.entry_status != 0) {
2304 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2305 "-- error status (%x).\n", __func__, ha->host_no,
2306 tsk->p.sts.entry_status));
2307 rval = QLA_FUNCTION_FAILED;
2308 goto atarget_done;
2309 } else if (tsk->p.sts.comp_status !=
2310 __constant_cpu_to_le16(CS_COMPLETE)) {
2311 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2312 "-- completion status (%x).\n", __func__,
744f11fd 2313 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
1c7c6357
AV
2314 rval = QLA_FUNCTION_FAILED;
2315 goto atarget_done;
2316 }
2317
2318 /* Issue marker IOCB. */
2319 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2320 if (rval != QLA_SUCCESS) {
2321 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
744f11fd 2322 "(%x).\n", __func__, ha->host_no, rval));
1c7c6357 2323 } else {
744f11fd 2324 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1c7c6357
AV
2325 }
2326
2327atarget_done:
2c3dfe3f 2328 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
1c7c6357
AV
2329
2330 return rval;
2331}
2332
2333int
2334qla2x00_system_error(scsi_qla_host_t *ha)
2335{
2336 int rval;
2337 mbx_cmd_t mc;
2338 mbx_cmd_t *mcp = &mc;
2339
e428924c 2340 if (!IS_FWI2_CAPABLE(ha))
1c7c6357
AV
2341 return QLA_FUNCTION_FAILED;
2342
2343 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2344
2345 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2346 mcp->out_mb = MBX_0;
2347 mcp->in_mb = MBX_0;
2348 mcp->tov = 5;
2349 mcp->flags = 0;
2350 rval = qla2x00_mailbox_command(ha, mcp);
2351
2352 if (rval != QLA_SUCCESS) {
2353 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2354 ha->host_no, rval));
2355 } else {
2356 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2357 }
2358
2359 return rval;
2360}
2361
2362/**
2363 * qla2x00_get_serdes_params() -
2364 * @ha: HA context
2365 *
2366 * Returns
2367 */
2368int
2369qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2370 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2371{
2372 int rval;
2373 mbx_cmd_t mc;
2374 mbx_cmd_t *mcp = &mc;
2375
2376 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2377
2378 mcp->mb[0] = MBC_SERDES_PARAMS;
2379 mcp->mb[1] = 0;
2380 mcp->out_mb = MBX_1|MBX_0;
2381 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2382 mcp->tov = 30;
2383 mcp->flags = 0;
2384 rval = qla2x00_mailbox_command(ha, mcp);
2385
2386 if (rval != QLA_SUCCESS) {
2387 /*EMPTY*/
2388 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2389 ha->host_no, rval, mcp->mb[0]));
2390 } else {
2391 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2392
2393 if (sw_em_1g)
2394 *sw_em_1g = mcp->mb[2];
2395 if (sw_em_2g)
2396 *sw_em_2g = mcp->mb[3];
2397 if (sw_em_4g)
2398 *sw_em_4g = mcp->mb[4];
2399 }
2400
2401 return rval;
2402}
2403
2404/**
2405 * qla2x00_set_serdes_params() -
2406 * @ha: HA context
2407 *
2408 * Returns
2409 */
2410int
2411qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2412 uint16_t sw_em_2g, uint16_t sw_em_4g)
2413{
2414 int rval;
2415 mbx_cmd_t mc;
2416 mbx_cmd_t *mcp = &mc;
2417
2418 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2419
2420 mcp->mb[0] = MBC_SERDES_PARAMS;
2421 mcp->mb[1] = BIT_0;
fdbc6833
AV
2422 mcp->mb[2] = sw_em_1g | BIT_15;
2423 mcp->mb[3] = sw_em_2g | BIT_15;
2424 mcp->mb[4] = sw_em_4g | BIT_15;
1c7c6357
AV
2425 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2426 mcp->in_mb = MBX_0;
2427 mcp->tov = 30;
2428 mcp->flags = 0;
2429 rval = qla2x00_mailbox_command(ha, mcp);
2430
2431 if (rval != QLA_SUCCESS) {
2432 /*EMPTY*/
2433 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2434 ha->host_no, rval, mcp->mb[0]));
2435 } else {
2436 /*EMPTY*/
2437 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2438 }
2439
2440 return rval;
2441}
f6ef3b18
AV
2442
2443int
2444qla2x00_stop_firmware(scsi_qla_host_t *ha)
2445{
2446 int rval;
2447 mbx_cmd_t mc;
2448 mbx_cmd_t *mcp = &mc;
2449
e428924c 2450 if (!IS_FWI2_CAPABLE(ha))
f6ef3b18
AV
2451 return QLA_FUNCTION_FAILED;
2452
2453 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2454
2455 mcp->mb[0] = MBC_STOP_FIRMWARE;
2456 mcp->out_mb = MBX_0;
2457 mcp->in_mb = MBX_0;
2458 mcp->tov = 5;
2459 mcp->flags = 0;
2460 rval = qla2x00_mailbox_command(ha, mcp);
2461
2462 if (rval != QLA_SUCCESS) {
2463 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2464 ha->host_no, rval));
2465 } else {
2466 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2467 }
2468
2469 return rval;
2470}
a7a167bf
AV
2471
2472int
2473qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2474 uint16_t buffers)
2475{
2476 int rval;
2477 mbx_cmd_t mc;
2478 mbx_cmd_t *mcp = &mc;
2479
e428924c 2480 if (!IS_FWI2_CAPABLE(ha))
a7a167bf
AV
2481 return QLA_FUNCTION_FAILED;
2482
2483 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2484
2485 mcp->mb[0] = MBC_TRACE_CONTROL;
2486 mcp->mb[1] = ctrl;
2487 mcp->out_mb = MBX_1|MBX_0;
2488 mcp->in_mb = MBX_1|MBX_0;
2489 if (ctrl == TC_ENABLE) {
2490 mcp->mb[2] = LSW(eft_dma);
2491 mcp->mb[3] = MSW(eft_dma);
2492 mcp->mb[4] = LSW(MSD(eft_dma));
2493 mcp->mb[5] = MSW(MSD(eft_dma));
2494 mcp->mb[6] = buffers;
87b2380f 2495 mcp->mb[7] = 0;
a7a167bf
AV
2496 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2497 }
2498 mcp->tov = 30;
2499 mcp->flags = 0;
2500 rval = qla2x00_mailbox_command(ha, mcp);
2501
2502 if (rval != QLA_SUCCESS) {
2503 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2504 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2505 } else {
2506 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2507 }
2508
2509 return rval;
2510}
2511
88729e53
AV
2512int
2513qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2514 uint16_t off, uint16_t count)
2515{
2516 int rval;
2517 mbx_cmd_t mc;
2518 mbx_cmd_t *mcp = &mc;
a7a167bf 2519
e428924c 2520 if (!IS_FWI2_CAPABLE(ha))
88729e53
AV
2521 return QLA_FUNCTION_FAILED;
2522
2523 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2524
2525 mcp->mb[0] = MBC_READ_SFP;
2526 mcp->mb[1] = addr;
2527 mcp->mb[2] = MSW(sfp_dma);
2528 mcp->mb[3] = LSW(sfp_dma);
2529 mcp->mb[6] = MSW(MSD(sfp_dma));
2530 mcp->mb[7] = LSW(MSD(sfp_dma));
2531 mcp->mb[8] = count;
2532 mcp->mb[9] = off;
2533 mcp->mb[10] = 0;
2534 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2535 mcp->in_mb = MBX_0;
2536 mcp->tov = 30;
2537 mcp->flags = 0;
2538 rval = qla2x00_mailbox_command(ha, mcp);
2539
2540 if (rval != QLA_SUCCESS) {
2541 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2542 ha->host_no, rval, mcp->mb[0]));
2543 } else {
2544 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2545 }
2546
2547 return rval;
2548}
d8b45213
AV
2549
2550int
2551qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2552 uint16_t *port_speed, uint16_t *mb)
2553{
2554 int rval;
2555 mbx_cmd_t mc;
2556 mbx_cmd_t *mcp = &mc;
2557
c76f2c01 2558 if (!IS_IIDMA_CAPABLE(ha))
d8b45213
AV
2559 return QLA_FUNCTION_FAILED;
2560
2561 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2562
2563 mcp->mb[0] = MBC_PORT_PARAMS;
2564 mcp->mb[1] = loop_id;
2565 mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0;
2566 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2567 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2568 mcp->tov = 30;
2569 mcp->flags = 0;
2570 rval = qla2x00_mailbox_command(ha, mcp);
2571
2572 /* Return mailbox statuses. */
2573 if (mb != NULL) {
2574 mb[0] = mcp->mb[0];
2575 mb[1] = mcp->mb[1];
2576 mb[3] = mcp->mb[3];
2577 mb[4] = mcp->mb[4];
2578 mb[5] = mcp->mb[5];
2579 }
2580
2581 if (rval != QLA_SUCCESS) {
2582 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2583 ha->host_no, rval));
2584 } else {
2585 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2586 if (port_speed)
2587 *port_speed = mcp->mb[3];
2588 }
2589
2590 return rval;
2591}
2592
2593int
2594qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2595 uint16_t port_speed, uint16_t *mb)
2596{
2597 int rval;
2598 mbx_cmd_t mc;
2599 mbx_cmd_t *mcp = &mc;
2600
c76f2c01 2601 if (!IS_IIDMA_CAPABLE(ha))
d8b45213
AV
2602 return QLA_FUNCTION_FAILED;
2603
2604 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2605
2606 mcp->mb[0] = MBC_PORT_PARAMS;
2607 mcp->mb[1] = loop_id;
2608 mcp->mb[2] = BIT_0;
2609 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2610 mcp->mb[4] = mcp->mb[5] = 0;
2611 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2612 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2613 mcp->tov = 30;
2614 mcp->flags = 0;
2615 rval = qla2x00_mailbox_command(ha, mcp);
2616
2617 /* Return mailbox statuses. */
2618 if (mb != NULL) {
2619 mb[0] = mcp->mb[0];
2620 mb[1] = mcp->mb[1];
2621 mb[3] = mcp->mb[3];
2622 mb[4] = mcp->mb[4];
2623 mb[5] = mcp->mb[5];
2624 }
2625
2626 if (rval != QLA_SUCCESS) {
2627 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2628 ha->host_no, rval));
2629 } else {
2630 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2631 }
2632
2633 return rval;
2634}
2c3dfe3f
SJ
2635
2636/*
2637 * qla24xx_get_vp_database
2638 * Get the VP's database for all configured ports.
2639 *
2640 * Input:
2641 * ha = adapter block pointer.
2642 * size = size of initialization control block.
2643 *
2644 * Returns:
2645 * qla2x00 local function return status code.
2646 *
2647 * Context:
2648 * Kernel context.
2649 */
2650int
2651qla24xx_get_vp_database(scsi_qla_host_t *ha, uint16_t size)
2652{
2653 int rval;
2654 mbx_cmd_t mc;
2655 mbx_cmd_t *mcp = &mc;
2656
2657 DEBUG11(printk("scsi(%ld):%s - entered.\n",
2658 ha->host_no, __func__));
2659
2660 mcp->mb[0] = MBC_MID_GET_VP_DATABASE;
2661 mcp->mb[2] = MSW(ha->init_cb_dma);
2662 mcp->mb[3] = LSW(ha->init_cb_dma);
2663 mcp->mb[4] = 0;
2664 mcp->mb[5] = 0;
2665 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2666 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2667 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2668 mcp->in_mb = MBX_1|MBX_0;
2669 mcp->buf_size = size;
2670 mcp->flags = MBX_DMA_OUT;
2671 mcp->tov = MBX_TOV_SECONDS;
2672 rval = qla2x00_mailbox_command(ha, mcp);
2673
2674 if (rval != QLA_SUCCESS) {
2675 /*EMPTY*/
2676 DEBUG2_3_11(printk("%s(%ld): failed=%x "
2677 "mb0=%x.\n",
2678 __func__, ha->host_no, rval, mcp->mb[0]));
2679 } else {
2680 /*EMPTY*/
2681 DEBUG11(printk("%s(%ld): done.\n",
2682 __func__, ha->host_no));
2683 }
2684
2685 return rval;
2686}
2687
2688int
2689qla24xx_get_vp_entry(scsi_qla_host_t *ha, uint16_t size, int vp_id)
2690{
2691 int rval;
2692 mbx_cmd_t mc;
2693 mbx_cmd_t *mcp = &mc;
2694
2695 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2696
2697 mcp->mb[0] = MBC_MID_GET_VP_ENTRY;
2698 mcp->mb[2] = MSW(ha->init_cb_dma);
2699 mcp->mb[3] = LSW(ha->init_cb_dma);
2700 mcp->mb[4] = 0;
2701 mcp->mb[5] = 0;
2702 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2703 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2704 mcp->mb[9] = vp_id;
2705 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2706 mcp->in_mb = MBX_0;
2707 mcp->buf_size = size;
2708 mcp->flags = MBX_DMA_OUT;
2709 mcp->tov = 30;
2710 rval = qla2x00_mailbox_command(ha, mcp);
2711
2712 if (rval != QLA_SUCCESS) {
2713 /*EMPTY*/
2714 DEBUG2_3_11(printk("qla24xx_get_vp_entry(%ld): failed=%x "
2715 "mb0=%x.\n",
2716 ha->host_no, rval, mcp->mb[0]));
2717 } else {
2718 /*EMPTY*/
2719 DEBUG11(printk("qla24xx_get_vp_entry(%ld): done.\n",
2720 ha->host_no));
2721 }
2722
2723 return rval;
2724}
2725
2726void
2727qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2728 struct vp_rpt_id_entry_24xx *rptid_entry)
2729{
2730 uint8_t vp_idx;
2731 scsi_qla_host_t *vha;
2732
2733 if (rptid_entry->entry_status != 0)
2734 return;
2735 if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
2736 return;
2737
2738 if (rptid_entry->format == 0) {
2739 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2740 " number of VPs acquired %d\n", __func__, ha->host_no,
2741 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2742 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2743 rptid_entry->port_id[2], rptid_entry->port_id[1],
2744 rptid_entry->port_id[0]));
2745 } else if (rptid_entry->format == 1) {
2746 vp_idx = LSB(rptid_entry->vp_idx);
2747 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2748 "- status %d - "
2749 "with port id %02x%02x%02x\n",__func__,ha->host_no,
2750 vp_idx, MSB(rptid_entry->vp_idx),
2751 rptid_entry->port_id[2], rptid_entry->port_id[1],
2752 rptid_entry->port_id[0]));
2753 if (vp_idx == 0)
2754 return;
2755
2756 if (MSB(rptid_entry->vp_idx) == 1)
2757 return;
2758
2759 list_for_each_entry(vha, &ha->vp_list, vp_list)
2760 if (vp_idx == vha->vp_idx)
2761 break;
2762
2763 if (!vha)
2764 return;
2765
2766 vha->d_id.b.domain = rptid_entry->port_id[2];
2767 vha->d_id.b.area = rptid_entry->port_id[1];
2768 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2769
2770 /*
2771 * Cannot configure here as we are still sitting on the
2772 * response queue. Handle it in dpc context.
2773 */
2774 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2775 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2776
2777 wake_up_process(ha->dpc_thread);
2778 }
2779}
2780
2781/*
2782 * qla24xx_modify_vp_config
2783 * Change VP configuration for vha
2784 *
2785 * Input:
2786 * vha = adapter block pointer.
2787 *
2788 * Returns:
2789 * qla2xxx local function return status code.
2790 *
2791 * Context:
2792 * Kernel context.
2793 */
2794int
2795qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2796{
2797 int rval;
2798 struct vp_config_entry_24xx *vpmod;
2799 dma_addr_t vpmod_dma;
2800 scsi_qla_host_t *pha;
2801
2802 /* This can be called by the parent */
2803 pha = to_qla_parent(vha);
2804
2805 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2806 if (!vpmod) {
2807 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2808 "IOCB.\n", __func__, pha->host_no));
2809 return QLA_MEMORY_ALLOC_FAILED;
2810 }
2811
2812 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2813 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2814 vpmod->entry_count = 1;
2815 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2816 vpmod->vp_count = 1;
2817 vpmod->vp_index1 = vha->vp_idx;
2818 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2819 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2820 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2821 vpmod->entry_count = 1;
2822
2823 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2824 if (rval != QLA_SUCCESS) {
2825 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2826 "(%x).\n", __func__, pha->host_no, rval));
2827 } else if (vpmod->comp_status != 0) {
2828 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2829 "-- error status (%x).\n", __func__, pha->host_no,
2830 vpmod->comp_status));
2831 rval = QLA_FUNCTION_FAILED;
2832 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2833 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2834 "-- completion status (%x).\n", __func__, pha->host_no,
2835 le16_to_cpu(vpmod->comp_status)));
2836 rval = QLA_FUNCTION_FAILED;
2837 } else {
2838 /* EMPTY */
2839 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2840 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2841 }
2842 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2843
2844 return rval;
2845}
2846
2847/*
2848 * qla24xx_control_vp
2849 * Enable a virtual port for given host
2850 *
2851 * Input:
2852 * ha = adapter block pointer.
2853 * vhba = virtual adapter (unused)
2854 * index = index number for enabled VP
2855 *
2856 * Returns:
2857 * qla2xxx local function return status code.
2858 *
2859 * Context:
2860 * Kernel context.
2861 */
2862int
2863qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2864{
2865 int rval;
2866 int map, pos;
2867 struct vp_ctrl_entry_24xx *vce;
2868 dma_addr_t vce_dma;
2869 scsi_qla_host_t *ha = vha->parent;
2870 int vp_index = vha->vp_idx;
2871
2872 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2873 ha->host_no, vp_index));
2874
2875 if (vp_index == 0 || vp_index >= MAX_MULTI_ID_LOOP)
2876 return QLA_PARAMETER_ERROR;
2877
2878 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2879 if (!vce) {
2880 DEBUG2_3(printk("%s(%ld): "
2881 "failed to allocate VP Control IOCB.\n", __func__,
2882 ha->host_no));
2883 return QLA_MEMORY_ALLOC_FAILED;
2884 }
2885 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2886
2887 vce->entry_type = VP_CTRL_IOCB_TYPE;
2888 vce->entry_count = 1;
2889 vce->command = cpu_to_le16(cmd);
2890 vce->vp_count = __constant_cpu_to_le16(1);
2891
2892 /* index map in firmware starts with 1; decrement index
2893 * this is ok as we never use index 0
2894 */
2895 map = (vp_index - 1) / 8;
2896 pos = (vp_index - 1) & 7;
2897 down(&ha->vport_sem);
2898 vce->vp_idx_map[map] |= 1 << pos;
2899 up(&ha->vport_sem);
2900
2901 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2902 if (rval != QLA_SUCCESS) {
2903 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2904 "(%x).\n", __func__, ha->host_no, rval));
2905 printk("%s(%ld): failed to issue VP control IOCB"
2906 "(%x).\n", __func__, ha->host_no, rval);
2907 } else if (vce->entry_status != 0) {
2908 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2909 "-- error status (%x).\n", __func__, ha->host_no,
2910 vce->entry_status));
2911 printk("%s(%ld): failed to complete IOCB "
2912 "-- error status (%x).\n", __func__, ha->host_no,
2913 vce->entry_status);
2914 rval = QLA_FUNCTION_FAILED;
2915 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2916 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2917 "-- completion status (%x).\n", __func__, ha->host_no,
2918 le16_to_cpu(vce->comp_status)));
2919 printk("%s(%ld): failed to complete IOCB "
2920 "-- completion status (%x).\n", __func__, ha->host_no,
2921 le16_to_cpu(vce->comp_status));
2922 rval = QLA_FUNCTION_FAILED;
2923 } else {
2924 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2925 }
2926
2927 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2928
2929 return rval;
2930}
2931
2932/*
2933 * qla2x00_send_change_request
2934 * Receive or disable RSCN request from fabric controller
2935 *
2936 * Input:
2937 * ha = adapter block pointer
2938 * format = registration format:
2939 * 0 - Reserved
2940 * 1 - Fabric detected registration
2941 * 2 - N_port detected registration
2942 * 3 - Full registration
2943 * FF - clear registration
2944 * vp_idx = Virtual port index
2945 *
2946 * Returns:
2947 * qla2x00 local function return status code.
2948 *
2949 * Context:
2950 * Kernel Context
2951 */
2952
2953int
2954qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2955 uint16_t vp_idx)
2956{
2957 int rval;
2958 mbx_cmd_t mc;
2959 mbx_cmd_t *mcp = &mc;
2960
2961 /*
2962 * This command is implicitly executed by firmware during login for the
2963 * physical hosts
2964 */
2965 if (vp_idx == 0)
2966 return QLA_FUNCTION_FAILED;
2967
2968 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2969 mcp->mb[1] = format;
2970 mcp->mb[9] = vp_idx;
2971 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2972 mcp->in_mb = MBX_0|MBX_1;
2973 mcp->tov = MBX_TOV_SECONDS;
2974 mcp->flags = 0;
2975 rval = qla2x00_mailbox_command(ha, mcp);
2976
2977 if (rval == QLA_SUCCESS) {
2978 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2979 rval = BIT_1;
2980 }
2981 } else
2982 rval = BIT_1;
2983
2984 return rval;
2985}
338c9161
AV
2986
2987int
2988qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2989 uint32_t size)
2990{
2991 int rval;
2992 mbx_cmd_t mc;
2993 mbx_cmd_t *mcp = &mc;
2994
2995 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2996
2997 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2998 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2999 mcp->mb[8] = MSW(addr);
3000 mcp->out_mb = MBX_8|MBX_0;
3001 } else {
3002 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3003 mcp->out_mb = MBX_0;
3004 }
3005 mcp->mb[1] = LSW(addr);
3006 mcp->mb[2] = MSW(req_dma);
3007 mcp->mb[3] = LSW(req_dma);
3008 mcp->mb[6] = MSW(MSD(req_dma));
3009 mcp->mb[7] = LSW(MSD(req_dma));
3010 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3011 if (IS_FWI2_CAPABLE(ha)) {
3012 mcp->mb[4] = MSW(size);
3013 mcp->mb[5] = LSW(size);
3014 mcp->out_mb |= MBX_5|MBX_4;
3015 } else {
3016 mcp->mb[4] = LSW(size);
3017 mcp->out_mb |= MBX_4;
3018 }
3019
3020 mcp->in_mb = MBX_0;
3021 mcp->tov = 30;
3022 mcp->flags = 0;
3023 rval = qla2x00_mailbox_command(ha, mcp);
3024
3025 if (rval != QLA_SUCCESS) {
3026 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3027 ha->host_no, rval, mcp->mb[0]));
3028 } else {
3029 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
3030 }
3031
3032 return rval;
3033}