fs: use kmem_cache_zalloc instead
[pv_ops_mirror.git] / drivers / scsi / qla2xxx / qla_mbx.c
blobc53ec67c47f4df600445f960ad503040248650e0
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
9 #include <linux/delay.h>
11 static void
12 qla2x00_mbx_sem_timeout(unsigned long data)
14 struct semaphore *sem_ptr = (struct semaphore *)data;
16 DEBUG11(printk("qla2x00_sem_timeout: entered.\n"));
18 if (sem_ptr != NULL) {
19 up(sem_ptr);
22 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n"));
26 * qla2x00_mailbox_command
27 * Issue mailbox command and waits for completion.
29 * Input:
30 * ha = adapter block pointer.
31 * mcp = driver internal mbx struct pointer.
33 * Output:
34 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
36 * Returns:
37 * 0 : QLA_SUCCESS = cmd performed success
38 * 1 : QLA_FUNCTION_FAILED (error encountered)
39 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
41 * Context:
42 * Kernel context.
44 static int
45 qla2x00_mailbox_command(scsi_qla_host_t *pvha, mbx_cmd_t *mcp)
47 int rval;
48 unsigned long flags = 0;
49 device_reg_t __iomem *reg;
50 struct timer_list tmp_intr_timer;
51 uint8_t abort_active;
52 uint8_t io_lock_on;
53 uint16_t command;
54 uint16_t *iptr;
55 uint16_t __iomem *optr;
56 uint32_t cnt;
57 uint32_t mboxes;
58 unsigned long wait_time;
59 scsi_qla_host_t *ha = to_qla_parent(pvha);
61 reg = ha->iobase;
62 io_lock_on = ha->flags.init_done;
64 rval = QLA_SUCCESS;
65 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
67 DEBUG11(printk("%s(%ld): entered.\n", __func__, pvha->host_no));
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.
74 if (!abort_active) {
75 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
76 /* Timeout occurred. Return error. */
77 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
78 "Exiting.\n", __func__, ha->host_no));
79 return QLA_FUNCTION_TIMEOUT;
83 ha->flags.mbox_busy = 1;
84 /* Save mailbox command for debug */
85 ha->mcp = mcp;
87 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
88 ha->host_no, mcp->mb[0]));
90 spin_lock_irqsave(&ha->hardware_lock, flags);
92 /* Load mailbox registers. */
93 if (IS_FWI2_CAPABLE(ha))
94 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
95 else
96 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
98 iptr = mcp->mb;
99 command = mcp->mb[0];
100 mboxes = mcp->out_mb;
102 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
103 if (IS_QLA2200(ha) && cnt == 8)
104 optr =
105 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
106 if (mboxes & BIT_0)
107 WRT_REG_WORD(optr, *iptr);
109 mboxes >>= 1;
110 optr++;
111 iptr++;
114 #if defined(QL_DEBUG_LEVEL_1)
115 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
116 __func__, ha->host_no);
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");
123 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
124 qla2x00_dump_regs(ha);
125 #endif
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);
131 /* Unlock mbx registers and wait for interrupt */
132 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
133 "jiffies=%lx.\n", __func__, ha->host_no, jiffies));
135 /* Wait for mbx cmd completion until timeout */
137 if (!abort_active && io_lock_on) {
138 /* sleep on completion semaphore */
139 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
140 __func__, ha->host_no));
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;
148 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
149 ha->host_no));
150 add_timer(&tmp_intr_timer);
152 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
153 "time=0x%lx.\n", __func__, ha->host_no, jiffies));
155 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
157 if (IS_FWI2_CAPABLE(ha))
158 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
159 else
160 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
161 spin_unlock_irqrestore(&ha->hardware_lock, flags);
163 /* Wait for either the timer to expire
164 * or the mbox completion interrupt
166 down(&ha->mbx_intr_sem);
168 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
169 ha->host_no, jiffies));
170 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
172 /* delete the timer */
173 del_timer(&tmp_intr_timer);
174 } else {
175 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
176 ha->host_no, command));
178 if (IS_FWI2_CAPABLE(ha))
179 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
180 else
181 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
182 spin_unlock_irqrestore(&ha->hardware_lock, flags);
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;
189 /* Check for pending interrupts. */
190 qla2x00_poll(ha);
192 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
193 !ha->flags.mbox_int)
194 msleep(10);
195 } /* while */
198 /* Check whether we timed out */
199 if (ha->flags.mbox_int) {
200 uint16_t *iptr2;
202 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
203 ha->host_no, command));
205 /* Got interrupt. Clear the flag. */
206 ha->flags.mbox_int = 0;
207 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
209 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
210 rval = QLA_FUNCTION_FAILED;
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;
220 mboxes >>= 1;
221 iptr2++;
222 iptr++;
224 } else {
226 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
227 defined(QL_DEBUG_LEVEL_11)
228 uint16_t mb0;
229 uint32_t ictrl;
231 if (IS_FWI2_CAPABLE(ha)) {
232 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
233 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
234 } else {
235 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
236 ictrl = RD_REG_WORD(&reg->isp.ictrl);
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);
244 qla2x00_dump_regs(ha);
245 #endif
247 rval = QLA_FUNCTION_TIMEOUT;
250 ha->flags.mbox_busy = 0;
252 /* Clean up */
253 ha->mcp = NULL;
255 if (!abort_active) {
256 DEBUG11(printk("%s(%ld): checking for additional resp "
257 "interrupt.\n", __func__, ha->host_no));
259 /* polling mode for non isp_abort commands. */
260 qla2x00_poll(ha);
263 if (rval == QLA_FUNCTION_TIMEOUT &&
264 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
265 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
266 /* not in dpc. schedule it for dpc to take over. */
267 DEBUG(printk("%s(%ld): timeout schedule "
268 "isp_abort_needed.\n", __func__, ha->host_no));
269 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
270 "isp_abort_needed.\n", __func__, ha->host_no));
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);
275 qla2xxx_wake_dpc(ha);
276 } else if (!abort_active) {
277 /* call abort directly since we are in the DPC thread */
278 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
279 __func__, ha->host_no));
280 DEBUG2_3_11(printk("%s(%ld): timeout calling "
281 "abort_isp\n", __func__, ha->host_no));
282 qla_printk(KERN_WARNING, ha,
283 "Mailbox command timeout occured. Issuing ISP "
284 "abort.\n");
286 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
287 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
288 if (qla2x00_abort_isp(ha)) {
289 /* Failed. retry later. */
290 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
292 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
293 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
294 ha->host_no));
295 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
296 __func__, ha->host_no));
300 /* Allow next mbx cmd to come in. */
301 if (!abort_active)
302 up(&ha->mbx_cmd_sem);
304 if (rval) {
305 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
306 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
307 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
308 } else {
309 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
312 return rval;
316 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
317 uint32_t risc_code_size)
319 int rval;
320 mbx_cmd_t mc;
321 mbx_cmd_t *mcp = &mc;
323 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
325 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
326 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
327 mcp->mb[8] = MSW(risc_addr);
328 mcp->out_mb = MBX_8|MBX_0;
329 } else {
330 mcp->mb[0] = MBC_LOAD_RISC_RAM;
331 mcp->out_mb = MBX_0;
333 mcp->mb[1] = LSW(risc_addr);
334 mcp->mb[2] = MSW(req_dma);
335 mcp->mb[3] = LSW(req_dma);
336 mcp->mb[6] = MSW(MSD(req_dma));
337 mcp->mb[7] = LSW(MSD(req_dma));
338 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
339 if (IS_FWI2_CAPABLE(ha)) {
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;
348 mcp->in_mb = MBX_0;
349 mcp->tov = 30;
350 mcp->flags = 0;
351 rval = qla2x00_mailbox_command(ha, mcp);
353 if (rval != QLA_SUCCESS) {
354 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
355 ha->host_no, rval, mcp->mb[0]));
356 } else {
357 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
360 return rval;
364 * qla2x00_execute_fw
365 * Start adapter firmware.
367 * Input:
368 * ha = adapter block pointer.
369 * TARGET_QUEUE_LOCK must be released.
370 * ADAPTER_STATE_LOCK must be released.
372 * Returns:
373 * qla2x00 local function return status code.
375 * Context:
376 * Kernel context.
379 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
381 int rval;
382 mbx_cmd_t mc;
383 mbx_cmd_t *mcp = &mc;
385 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
387 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
388 mcp->out_mb = MBX_0;
389 mcp->in_mb = MBX_0;
390 if (IS_FWI2_CAPABLE(ha)) {
391 mcp->mb[1] = MSW(risc_addr);
392 mcp->mb[2] = LSW(risc_addr);
393 mcp->mb[3] = 0;
394 mcp->mb[4] = 0;
395 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
396 mcp->in_mb |= MBX_1;
397 } else {
398 mcp->mb[1] = LSW(risc_addr);
399 mcp->out_mb |= MBX_1;
400 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
401 mcp->mb[2] = 0;
402 mcp->out_mb |= MBX_2;
406 mcp->tov = 30;
407 mcp->flags = 0;
408 rval = qla2x00_mailbox_command(ha, mcp);
410 if (rval != QLA_SUCCESS) {
411 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
412 ha->host_no, rval, mcp->mb[0]));
413 } else {
414 if (IS_FWI2_CAPABLE(ha)) {
415 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
416 __func__, ha->host_no, mcp->mb[1]));
417 } else {
418 DEBUG11(printk("%s(%ld): done.\n", __func__,
419 ha->host_no));
423 return rval;
427 * qla2x00_get_fw_version
428 * Get firmware version.
430 * Input:
431 * ha: adapter state pointer.
432 * major: pointer for major number.
433 * minor: pointer for minor number.
434 * subminor: pointer for subminor number.
436 * Returns:
437 * qla2x00 local function return status code.
439 * Context:
440 * Kernel context.
442 void
443 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
444 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
446 int rval;
447 mbx_cmd_t mc;
448 mbx_cmd_t *mcp = &mc;
450 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
452 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
453 mcp->out_mb = MBX_0;
454 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
455 mcp->flags = 0;
456 mcp->tov = 30;
457 rval = qla2x00_mailbox_command(ha, mcp);
459 /* Return mailbox data. */
460 *major = mcp->mb[1];
461 *minor = mcp->mb[2];
462 *subminor = mcp->mb[3];
463 *attributes = mcp->mb[6];
464 if (IS_QLA2100(ha) || IS_QLA2200(ha))
465 *memory = 0x1FFFF; /* Defaults to 128KB. */
466 else
467 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
469 if (rval != QLA_SUCCESS) {
470 /*EMPTY*/
471 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
472 ha->host_no, rval));
473 } else {
474 /*EMPTY*/
475 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
480 * qla2x00_get_fw_options
481 * Set firmware options.
483 * Input:
484 * ha = adapter block pointer.
485 * fwopt = pointer for firmware options.
487 * Returns:
488 * qla2x00 local function return status code.
490 * Context:
491 * Kernel context.
494 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
496 int rval;
497 mbx_cmd_t mc;
498 mbx_cmd_t *mcp = &mc;
500 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
502 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
503 mcp->out_mb = MBX_0;
504 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
505 mcp->tov = 30;
506 mcp->flags = 0;
507 rval = qla2x00_mailbox_command(ha, mcp);
509 if (rval != QLA_SUCCESS) {
510 /*EMPTY*/
511 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
512 ha->host_no, rval));
513 } else {
514 fwopts[0] = mcp->mb[0];
515 fwopts[1] = mcp->mb[1];
516 fwopts[2] = mcp->mb[2];
517 fwopts[3] = mcp->mb[3];
519 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
522 return rval;
527 * qla2x00_set_fw_options
528 * Set firmware options.
530 * Input:
531 * ha = adapter block pointer.
532 * fwopt = pointer for firmware options.
534 * Returns:
535 * qla2x00 local function return status code.
537 * Context:
538 * Kernel context.
541 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
543 int rval;
544 mbx_cmd_t mc;
545 mbx_cmd_t *mcp = &mc;
547 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
549 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
550 mcp->mb[1] = fwopts[1];
551 mcp->mb[2] = fwopts[2];
552 mcp->mb[3] = fwopts[3];
553 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
554 mcp->in_mb = MBX_0;
555 if (IS_FWI2_CAPABLE(ha)) {
556 mcp->in_mb |= MBX_1;
557 } else {
558 mcp->mb[10] = fwopts[10];
559 mcp->mb[11] = fwopts[11];
560 mcp->mb[12] = 0; /* Undocumented, but used */
561 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
563 mcp->tov = 30;
564 mcp->flags = 0;
565 rval = qla2x00_mailbox_command(ha, mcp);
567 fwopts[0] = mcp->mb[0];
569 if (rval != QLA_SUCCESS) {
570 /*EMPTY*/
571 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
572 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
573 } else {
574 /*EMPTY*/
575 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
578 return rval;
582 * qla2x00_mbx_reg_test
583 * Mailbox register wrap test.
585 * Input:
586 * ha = adapter block pointer.
587 * TARGET_QUEUE_LOCK must be released.
588 * ADAPTER_STATE_LOCK must be released.
590 * Returns:
591 * qla2x00 local function return status code.
593 * Context:
594 * Kernel context.
597 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
599 int rval;
600 mbx_cmd_t mc;
601 mbx_cmd_t *mcp = &mc;
603 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no));
605 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
606 mcp->mb[1] = 0xAAAA;
607 mcp->mb[2] = 0x5555;
608 mcp->mb[3] = 0xAA55;
609 mcp->mb[4] = 0x55AA;
610 mcp->mb[5] = 0xA5A5;
611 mcp->mb[6] = 0x5A5A;
612 mcp->mb[7] = 0x2525;
613 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
614 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
615 mcp->tov = 30;
616 mcp->flags = 0;
617 rval = qla2x00_mailbox_command(ha, mcp);
619 if (rval == QLA_SUCCESS) {
620 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
621 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
622 rval = QLA_FUNCTION_FAILED;
623 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
624 mcp->mb[7] != 0x2525)
625 rval = QLA_FUNCTION_FAILED;
628 if (rval != QLA_SUCCESS) {
629 /*EMPTY*/
630 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
631 ha->host_no, rval));
632 } else {
633 /*EMPTY*/
634 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
635 ha->host_no));
638 return rval;
642 * qla2x00_verify_checksum
643 * Verify firmware checksum.
645 * Input:
646 * ha = adapter block pointer.
647 * TARGET_QUEUE_LOCK must be released.
648 * ADAPTER_STATE_LOCK must be released.
650 * Returns:
651 * qla2x00 local function return status code.
653 * Context:
654 * Kernel context.
657 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
659 int rval;
660 mbx_cmd_t mc;
661 mbx_cmd_t *mcp = &mc;
663 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
665 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
666 mcp->out_mb = MBX_0;
667 mcp->in_mb = MBX_0;
668 if (IS_FWI2_CAPABLE(ha)) {
669 mcp->mb[1] = MSW(risc_addr);
670 mcp->mb[2] = LSW(risc_addr);
671 mcp->out_mb |= MBX_2|MBX_1;
672 mcp->in_mb |= MBX_2|MBX_1;
673 } else {
674 mcp->mb[1] = LSW(risc_addr);
675 mcp->out_mb |= MBX_1;
676 mcp->in_mb |= MBX_1;
679 mcp->tov = 30;
680 mcp->flags = 0;
681 rval = qla2x00_mailbox_command(ha, mcp);
683 if (rval != QLA_SUCCESS) {
684 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
685 ha->host_no, rval, IS_FWI2_CAPABLE(ha) ?
686 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
687 } else {
688 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
691 return rval;
695 * qla2x00_issue_iocb
696 * Issue IOCB using mailbox command
698 * Input:
699 * ha = adapter state pointer.
700 * buffer = buffer pointer.
701 * phys_addr = physical address of buffer.
702 * size = size of buffer.
703 * TARGET_QUEUE_LOCK must be released.
704 * ADAPTER_STATE_LOCK must be released.
706 * Returns:
707 * qla2x00 local function return status code.
709 * Context:
710 * Kernel context.
713 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
714 size_t size)
716 int rval;
717 mbx_cmd_t mc;
718 mbx_cmd_t *mcp = &mc;
720 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
721 mcp->mb[1] = 0;
722 mcp->mb[2] = MSW(phys_addr);
723 mcp->mb[3] = LSW(phys_addr);
724 mcp->mb[6] = MSW(MSD(phys_addr));
725 mcp->mb[7] = LSW(MSD(phys_addr));
726 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
727 mcp->in_mb = MBX_2|MBX_0;
728 mcp->tov = 30;
729 mcp->flags = 0;
730 rval = qla2x00_mailbox_command(ha, mcp);
732 if (rval != QLA_SUCCESS) {
733 /*EMPTY*/
734 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
735 ha->host_no, rval));
736 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
737 ha->host_no, rval));
738 } else {
739 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
741 /* Mask reserved bits. */
742 sts_entry->entry_status &=
743 IS_FWI2_CAPABLE(ha) ? RF_MASK_24XX :RF_MASK;
746 return rval;
750 * qla2x00_abort_command
751 * Abort command aborts a specified IOCB.
753 * Input:
754 * ha = adapter block pointer.
755 * sp = SB structure pointer.
757 * Returns:
758 * qla2x00 local function return status code.
760 * Context:
761 * Kernel context.
764 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
766 unsigned long flags = 0;
767 fc_port_t *fcport;
768 int rval;
769 uint32_t handle;
770 mbx_cmd_t mc;
771 mbx_cmd_t *mcp = &mc;
773 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no));
775 fcport = sp->fcport;
777 spin_lock_irqsave(&ha->hardware_lock, flags);
778 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
779 if (ha->outstanding_cmds[handle] == sp)
780 break;
782 spin_unlock_irqrestore(&ha->hardware_lock, flags);
784 if (handle == MAX_OUTSTANDING_COMMANDS) {
785 /* command not found */
786 return QLA_FUNCTION_FAILED;
789 mcp->mb[0] = MBC_ABORT_COMMAND;
790 if (HAS_EXTENDED_IDS(ha))
791 mcp->mb[1] = fcport->loop_id;
792 else
793 mcp->mb[1] = fcport->loop_id << 8;
794 mcp->mb[2] = (uint16_t)handle;
795 mcp->mb[3] = (uint16_t)(handle >> 16);
796 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
797 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
798 mcp->in_mb = MBX_0;
799 mcp->tov = 30;
800 mcp->flags = 0;
801 rval = qla2x00_mailbox_command(ha, mcp);
803 if (rval != QLA_SUCCESS) {
804 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
805 ha->host_no, rval));
806 } else {
807 sp->flags |= SRB_ABORT_PENDING;
808 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
809 ha->host_no));
812 return rval;
815 #if USE_ABORT_TGT
817 * qla2x00_abort_target
818 * Issue abort target mailbox command.
820 * Input:
821 * ha = adapter block pointer.
823 * Returns:
824 * qla2x00 local function return status code.
826 * Context:
827 * Kernel context.
830 qla2x00_abort_target(fc_port_t *fcport)
832 int rval;
833 mbx_cmd_t mc;
834 mbx_cmd_t *mcp = &mc;
835 scsi_qla_host_t *ha;
837 if (fcport == NULL)
838 return 0;
840 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
842 ha = fcport->ha;
843 mcp->mb[0] = MBC_ABORT_TARGET;
844 mcp->out_mb = MBX_2|MBX_1|MBX_0;
845 if (HAS_EXTENDED_IDS(ha)) {
846 mcp->mb[1] = fcport->loop_id;
847 mcp->mb[10] = 0;
848 mcp->out_mb |= MBX_10;
849 } else {
850 mcp->mb[1] = fcport->loop_id << 8;
852 mcp->mb[2] = ha->loop_reset_delay;
854 mcp->in_mb = MBX_0;
855 mcp->tov = 30;
856 mcp->flags = 0;
857 rval = qla2x00_mailbox_command(ha, mcp);
859 /* Issue marker command. */
860 ha->marker_needed = 1;
862 if (rval != QLA_SUCCESS) {
863 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
864 ha->host_no, rval));
865 } else {
866 /*EMPTY*/
867 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
868 ha->host_no));
871 return rval;
873 #endif
876 * qla2x00_get_adapter_id
877 * Get adapter ID and topology.
879 * Input:
880 * ha = adapter block pointer.
881 * id = pointer for loop ID.
882 * al_pa = pointer for AL_PA.
883 * area = pointer for area.
884 * domain = pointer for domain.
885 * top = pointer for topology.
886 * TARGET_QUEUE_LOCK must be released.
887 * ADAPTER_STATE_LOCK must be released.
889 * Returns:
890 * qla2x00 local function return status code.
892 * Context:
893 * Kernel context.
896 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
897 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
899 int rval;
900 mbx_cmd_t mc;
901 mbx_cmd_t *mcp = &mc;
903 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
904 ha->host_no));
906 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
907 mcp->mb[9] = ha->vp_idx;
908 mcp->out_mb = MBX_0;
909 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
910 mcp->tov = 30;
911 mcp->flags = 0;
912 rval = qla2x00_mailbox_command(ha, mcp);
913 if (mcp->mb[0] == MBS_COMMAND_ERROR)
914 rval = QLA_COMMAND_ERROR;
916 /* Return data. */
917 *id = mcp->mb[1];
918 *al_pa = LSB(mcp->mb[2]);
919 *area = MSB(mcp->mb[2]);
920 *domain = LSB(mcp->mb[3]);
921 *top = mcp->mb[6];
922 *sw_cap = mcp->mb[7];
924 if (rval != QLA_SUCCESS) {
925 /*EMPTY*/
926 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
927 ha->host_no, rval));
928 } else {
929 /*EMPTY*/
930 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
931 ha->host_no));
934 return rval;
938 * qla2x00_get_retry_cnt
939 * Get current firmware login retry count and delay.
941 * Input:
942 * ha = adapter block pointer.
943 * retry_cnt = pointer to login retry count.
944 * tov = pointer to login timeout value.
946 * Returns:
947 * qla2x00 local function return status code.
949 * Context:
950 * Kernel context.
953 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
954 uint16_t *r_a_tov)
956 int rval;
957 uint16_t ratov;
958 mbx_cmd_t mc;
959 mbx_cmd_t *mcp = &mc;
961 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
962 ha->host_no));
964 mcp->mb[0] = MBC_GET_RETRY_COUNT;
965 mcp->out_mb = MBX_0;
966 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
967 mcp->tov = 30;
968 mcp->flags = 0;
969 rval = qla2x00_mailbox_command(ha, mcp);
971 if (rval != QLA_SUCCESS) {
972 /*EMPTY*/
973 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
974 ha->host_no, mcp->mb[0]));
975 } else {
976 /* Convert returned data and check our values. */
977 *r_a_tov = mcp->mb[3] / 2;
978 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
979 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
980 /* Update to the larger values */
981 *retry_cnt = (uint8_t)mcp->mb[1];
982 *tov = ratov;
985 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
986 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov));
989 return rval;
993 * qla2x00_init_firmware
994 * Initialize adapter firmware.
996 * Input:
997 * ha = adapter block pointer.
998 * dptr = Initialization control block pointer.
999 * size = size of initialization control block.
1000 * TARGET_QUEUE_LOCK must be released.
1001 * ADAPTER_STATE_LOCK must be released.
1003 * Returns:
1004 * qla2x00 local function return status code.
1006 * Context:
1007 * Kernel context.
1010 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1012 int rval;
1013 mbx_cmd_t mc;
1014 mbx_cmd_t *mcp = &mc;
1016 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1017 ha->host_no));
1019 if (ha->flags.npiv_supported)
1020 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1021 else
1022 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1024 mcp->mb[2] = MSW(ha->init_cb_dma);
1025 mcp->mb[3] = LSW(ha->init_cb_dma);
1026 mcp->mb[4] = 0;
1027 mcp->mb[5] = 0;
1028 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1029 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1030 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1031 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1032 mcp->buf_size = size;
1033 mcp->flags = MBX_DMA_OUT;
1034 mcp->tov = 30;
1035 rval = qla2x00_mailbox_command(ha, mcp);
1037 if (rval != QLA_SUCCESS) {
1038 /*EMPTY*/
1039 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1040 "mb0=%x.\n",
1041 ha->host_no, rval, mcp->mb[0]));
1042 } else {
1043 /*EMPTY*/
1044 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1045 ha->host_no));
1048 return rval;
1052 * qla2x00_get_port_database
1053 * Issue normal/enhanced get port database mailbox command
1054 * and copy device name as necessary.
1056 * Input:
1057 * ha = adapter state pointer.
1058 * dev = structure pointer.
1059 * opt = enhanced cmd option byte.
1061 * Returns:
1062 * qla2x00 local function return status code.
1064 * Context:
1065 * Kernel context.
1068 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1070 int rval;
1071 mbx_cmd_t mc;
1072 mbx_cmd_t *mcp = &mc;
1073 port_database_t *pd;
1074 struct port_database_24xx *pd24;
1075 dma_addr_t pd_dma;
1077 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1079 pd24 = NULL;
1080 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1081 if (pd == NULL) {
1082 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1083 "structure.\n", __func__, ha->host_no));
1084 return QLA_MEMORY_ALLOC_FAILED;
1086 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1088 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1089 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1090 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1091 mcp->mb[2] = MSW(pd_dma);
1092 mcp->mb[3] = LSW(pd_dma);
1093 mcp->mb[6] = MSW(MSD(pd_dma));
1094 mcp->mb[7] = LSW(MSD(pd_dma));
1095 mcp->mb[9] = ha->vp_idx;
1096 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1097 mcp->in_mb = MBX_0;
1098 if (IS_FWI2_CAPABLE(ha)) {
1099 mcp->mb[1] = fcport->loop_id;
1100 mcp->mb[10] = opt;
1101 mcp->out_mb |= MBX_10|MBX_1;
1102 mcp->in_mb |= MBX_1;
1103 } else if (HAS_EXTENDED_IDS(ha)) {
1104 mcp->mb[1] = fcport->loop_id;
1105 mcp->mb[10] = opt;
1106 mcp->out_mb |= MBX_10|MBX_1;
1107 } else {
1108 mcp->mb[1] = fcport->loop_id << 8 | opt;
1109 mcp->out_mb |= MBX_1;
1111 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1112 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1113 mcp->flags = MBX_DMA_IN;
1114 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1115 rval = qla2x00_mailbox_command(ha, mcp);
1116 if (rval != QLA_SUCCESS)
1117 goto gpd_error_out;
1119 if (IS_FWI2_CAPABLE(ha)) {
1120 pd24 = (struct port_database_24xx *) pd;
1122 /* Check for logged in state. */
1123 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1124 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1125 DEBUG2(printk("%s(%ld): Unable to verify "
1126 "login-state (%x/%x) for loop_id %x\n",
1127 __func__, ha->host_no,
1128 pd24->current_login_state,
1129 pd24->last_login_state, fcport->loop_id));
1130 rval = QLA_FUNCTION_FAILED;
1131 goto gpd_error_out;
1134 /* Names are little-endian. */
1135 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1136 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1138 /* Get port_id of device. */
1139 fcport->d_id.b.domain = pd24->port_id[0];
1140 fcport->d_id.b.area = pd24->port_id[1];
1141 fcport->d_id.b.al_pa = pd24->port_id[2];
1142 fcport->d_id.b.rsvd_1 = 0;
1144 /* If not target must be initiator or unknown type. */
1145 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1146 fcport->port_type = FCT_INITIATOR;
1147 else
1148 fcport->port_type = FCT_TARGET;
1149 } else {
1150 /* Check for logged in state. */
1151 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1152 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1153 rval = QLA_FUNCTION_FAILED;
1154 goto gpd_error_out;
1157 /* Names are little-endian. */
1158 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1159 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1161 /* Get port_id of device. */
1162 fcport->d_id.b.domain = pd->port_id[0];
1163 fcport->d_id.b.area = pd->port_id[3];
1164 fcport->d_id.b.al_pa = pd->port_id[2];
1165 fcport->d_id.b.rsvd_1 = 0;
1167 /* Check for device require authentication. */
1168 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1169 (fcport->flags &= ~FCF_AUTH_REQ);
1171 /* If not target must be initiator or unknown type. */
1172 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1173 fcport->port_type = FCT_INITIATOR;
1174 else
1175 fcport->port_type = FCT_TARGET;
1177 /* Passback COS information. */
1178 fcport->supported_classes = (pd->options & BIT_4) ?
1179 FC_COS_CLASS2: FC_COS_CLASS3;
1182 gpd_error_out:
1183 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1185 if (rval != QLA_SUCCESS) {
1186 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1187 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1188 } else {
1189 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1192 return rval;
1196 * qla2x00_get_firmware_state
1197 * Get adapter firmware state.
1199 * Input:
1200 * ha = adapter block pointer.
1201 * dptr = pointer for firmware state.
1202 * TARGET_QUEUE_LOCK must be released.
1203 * ADAPTER_STATE_LOCK must be released.
1205 * Returns:
1206 * qla2x00 local function return status code.
1208 * Context:
1209 * Kernel context.
1212 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1214 int rval;
1215 mbx_cmd_t mc;
1216 mbx_cmd_t *mcp = &mc;
1218 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1219 ha->host_no));
1221 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1222 mcp->out_mb = MBX_0;
1223 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1224 mcp->tov = 30;
1225 mcp->flags = 0;
1226 rval = qla2x00_mailbox_command(ha, mcp);
1228 /* Return firmware state. */
1229 *dptr = mcp->mb[1];
1231 if (rval != QLA_SUCCESS) {
1232 /*EMPTY*/
1233 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1234 "failed=%x.\n", ha->host_no, rval));
1235 } else {
1236 /*EMPTY*/
1237 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1238 ha->host_no));
1241 return rval;
1245 * qla2x00_get_port_name
1246 * Issue get port name mailbox command.
1247 * Returned name is in big endian format.
1249 * Input:
1250 * ha = adapter block pointer.
1251 * loop_id = loop ID of device.
1252 * name = pointer for name.
1253 * TARGET_QUEUE_LOCK must be released.
1254 * ADAPTER_STATE_LOCK must be released.
1256 * Returns:
1257 * qla2x00 local function return status code.
1259 * Context:
1260 * Kernel context.
1263 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1264 uint8_t opt)
1266 int rval;
1267 mbx_cmd_t mc;
1268 mbx_cmd_t *mcp = &mc;
1270 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1271 ha->host_no));
1273 mcp->mb[0] = MBC_GET_PORT_NAME;
1274 mcp->mb[9] = ha->vp_idx;
1275 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1276 if (HAS_EXTENDED_IDS(ha)) {
1277 mcp->mb[1] = loop_id;
1278 mcp->mb[10] = opt;
1279 mcp->out_mb |= MBX_10;
1280 } else {
1281 mcp->mb[1] = loop_id << 8 | opt;
1284 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1285 mcp->tov = 30;
1286 mcp->flags = 0;
1287 rval = qla2x00_mailbox_command(ha, mcp);
1289 if (rval != QLA_SUCCESS) {
1290 /*EMPTY*/
1291 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1292 ha->host_no, rval));
1293 } else {
1294 if (name != NULL) {
1295 /* This function returns name in big endian. */
1296 name[0] = MSB(mcp->mb[2]);
1297 name[1] = LSB(mcp->mb[2]);
1298 name[2] = MSB(mcp->mb[3]);
1299 name[3] = LSB(mcp->mb[3]);
1300 name[4] = MSB(mcp->mb[6]);
1301 name[5] = LSB(mcp->mb[6]);
1302 name[6] = MSB(mcp->mb[7]);
1303 name[7] = LSB(mcp->mb[7]);
1306 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1307 ha->host_no));
1310 return rval;
1314 * qla2x00_lip_reset
1315 * Issue LIP reset mailbox command.
1317 * Input:
1318 * ha = adapter block pointer.
1319 * TARGET_QUEUE_LOCK must be released.
1320 * ADAPTER_STATE_LOCK must be released.
1322 * Returns:
1323 * qla2x00 local function return status code.
1325 * Context:
1326 * Kernel context.
1329 qla2x00_lip_reset(scsi_qla_host_t *ha)
1331 int rval;
1332 mbx_cmd_t mc;
1333 mbx_cmd_t *mcp = &mc;
1335 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1337 if (IS_FWI2_CAPABLE(ha)) {
1338 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1339 mcp->mb[1] = BIT_6;
1340 mcp->mb[2] = 0;
1341 mcp->mb[3] = ha->loop_reset_delay;
1342 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1343 } else {
1344 mcp->mb[0] = MBC_LIP_RESET;
1345 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1346 if (HAS_EXTENDED_IDS(ha)) {
1347 mcp->mb[1] = 0x00ff;
1348 mcp->mb[10] = 0;
1349 mcp->out_mb |= MBX_10;
1350 } else {
1351 mcp->mb[1] = 0xff00;
1353 mcp->mb[2] = ha->loop_reset_delay;
1354 mcp->mb[3] = 0;
1356 mcp->in_mb = MBX_0;
1357 mcp->tov = 30;
1358 mcp->flags = 0;
1359 rval = qla2x00_mailbox_command(ha, mcp);
1361 if (rval != QLA_SUCCESS) {
1362 /*EMPTY*/
1363 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1364 __func__, ha->host_no, rval));
1365 } else {
1366 /*EMPTY*/
1367 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1370 return rval;
1374 * qla2x00_send_sns
1375 * Send SNS command.
1377 * Input:
1378 * ha = adapter block pointer.
1379 * sns = pointer for command.
1380 * cmd_size = command size.
1381 * buf_size = response/command size.
1382 * TARGET_QUEUE_LOCK must be released.
1383 * ADAPTER_STATE_LOCK must be released.
1385 * Returns:
1386 * qla2x00 local function return status code.
1388 * Context:
1389 * Kernel context.
1392 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1393 uint16_t cmd_size, size_t buf_size)
1395 int rval;
1396 mbx_cmd_t mc;
1397 mbx_cmd_t *mcp = &mc;
1399 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1400 ha->host_no));
1402 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1403 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov));
1405 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1406 mcp->mb[1] = cmd_size;
1407 mcp->mb[2] = MSW(sns_phys_address);
1408 mcp->mb[3] = LSW(sns_phys_address);
1409 mcp->mb[6] = MSW(MSD(sns_phys_address));
1410 mcp->mb[7] = LSW(MSD(sns_phys_address));
1411 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1412 mcp->in_mb = MBX_0|MBX_1;
1413 mcp->buf_size = buf_size;
1414 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1415 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1416 rval = qla2x00_mailbox_command(ha, mcp);
1418 if (rval != QLA_SUCCESS) {
1419 /*EMPTY*/
1420 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1421 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1422 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1423 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1424 } else {
1425 /*EMPTY*/
1426 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no));
1429 return rval;
1433 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1434 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1436 int rval;
1438 struct logio_entry_24xx *lg;
1439 dma_addr_t lg_dma;
1440 uint32_t iop[2];
1442 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1444 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1445 if (lg == NULL) {
1446 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1447 __func__, ha->host_no));
1448 return QLA_MEMORY_ALLOC_FAILED;
1450 memset(lg, 0, sizeof(struct logio_entry_24xx));
1452 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1453 lg->entry_count = 1;
1454 lg->nport_handle = cpu_to_le16(loop_id);
1455 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1456 if (opt & BIT_0)
1457 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1458 if (opt & BIT_1)
1459 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
1460 lg->port_id[0] = al_pa;
1461 lg->port_id[1] = area;
1462 lg->port_id[2] = domain;
1463 lg->vp_index = cpu_to_le16(ha->vp_idx);
1464 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1465 if (rval != QLA_SUCCESS) {
1466 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1467 "(%x).\n", __func__, ha->host_no, rval));
1468 } else if (lg->entry_status != 0) {
1469 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1470 "-- error status (%x).\n", __func__, ha->host_no,
1471 lg->entry_status));
1472 rval = QLA_FUNCTION_FAILED;
1473 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1474 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1475 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1477 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1478 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1479 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1480 iop[1]));
1482 switch (iop[0]) {
1483 case LSC_SCODE_PORTID_USED:
1484 mb[0] = MBS_PORT_ID_USED;
1485 mb[1] = LSW(iop[1]);
1486 break;
1487 case LSC_SCODE_NPORT_USED:
1488 mb[0] = MBS_LOOP_ID_USED;
1489 break;
1490 case LSC_SCODE_NOLINK:
1491 case LSC_SCODE_NOIOCB:
1492 case LSC_SCODE_NOXCB:
1493 case LSC_SCODE_CMD_FAILED:
1494 case LSC_SCODE_NOFABRIC:
1495 case LSC_SCODE_FW_NOT_READY:
1496 case LSC_SCODE_NOT_LOGGED_IN:
1497 case LSC_SCODE_NOPCB:
1498 case LSC_SCODE_ELS_REJECT:
1499 case LSC_SCODE_CMD_PARAM_ERR:
1500 case LSC_SCODE_NONPORT:
1501 case LSC_SCODE_LOGGED_IN:
1502 case LSC_SCODE_NOFLOGI_ACC:
1503 default:
1504 mb[0] = MBS_COMMAND_ERROR;
1505 break;
1507 } else {
1508 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1510 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1512 mb[0] = MBS_COMMAND_COMPLETE;
1513 mb[1] = 0;
1514 if (iop[0] & BIT_4) {
1515 if (iop[0] & BIT_8)
1516 mb[1] |= BIT_1;
1517 } else
1518 mb[1] = BIT_0;
1520 /* Passback COS information. */
1521 mb[10] = 0;
1522 if (lg->io_parameter[7] || lg->io_parameter[8])
1523 mb[10] |= BIT_0; /* Class 2. */
1524 if (lg->io_parameter[9] || lg->io_parameter[10])
1525 mb[10] |= BIT_1; /* Class 3. */
1528 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1530 return rval;
1534 * qla2x00_login_fabric
1535 * Issue login fabric port mailbox command.
1537 * Input:
1538 * ha = adapter block pointer.
1539 * loop_id = device loop ID.
1540 * domain = device domain.
1541 * area = device area.
1542 * al_pa = device AL_PA.
1543 * status = pointer for return status.
1544 * opt = command options.
1545 * TARGET_QUEUE_LOCK must be released.
1546 * ADAPTER_STATE_LOCK must be released.
1548 * Returns:
1549 * qla2x00 local function return status code.
1551 * Context:
1552 * Kernel context.
1555 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1556 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1558 int rval;
1559 mbx_cmd_t mc;
1560 mbx_cmd_t *mcp = &mc;
1562 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no));
1564 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1565 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1566 if (HAS_EXTENDED_IDS(ha)) {
1567 mcp->mb[1] = loop_id;
1568 mcp->mb[10] = opt;
1569 mcp->out_mb |= MBX_10;
1570 } else {
1571 mcp->mb[1] = (loop_id << 8) | opt;
1573 mcp->mb[2] = domain;
1574 mcp->mb[3] = area << 8 | al_pa;
1576 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1577 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1578 mcp->flags = 0;
1579 rval = qla2x00_mailbox_command(ha, mcp);
1581 /* Return mailbox statuses. */
1582 if (mb != NULL) {
1583 mb[0] = mcp->mb[0];
1584 mb[1] = mcp->mb[1];
1585 mb[2] = mcp->mb[2];
1586 mb[6] = mcp->mb[6];
1587 mb[7] = mcp->mb[7];
1588 /* COS retrieved from Get-Port-Database mailbox command. */
1589 mb[10] = 0;
1592 if (rval != QLA_SUCCESS) {
1593 /* RLU tmp code: need to change main mailbox_command function to
1594 * return ok even when the mailbox completion value is not
1595 * SUCCESS. The caller needs to be responsible to interpret
1596 * the return values of this mailbox command if we're not
1597 * to change too much of the existing code.
1599 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1600 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1601 mcp->mb[0] == 0x4006)
1602 rval = QLA_SUCCESS;
1604 /*EMPTY*/
1605 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1606 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1607 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
1608 } else {
1609 /*EMPTY*/
1610 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1611 ha->host_no));
1614 return rval;
1618 * qla2x00_login_local_device
1619 * Issue login loop port mailbox command.
1621 * Input:
1622 * ha = adapter block pointer.
1623 * loop_id = device loop ID.
1624 * opt = command options.
1626 * Returns:
1627 * Return status code.
1629 * Context:
1630 * Kernel context.
1634 qla2x00_login_local_device(scsi_qla_host_t *ha, fc_port_t *fcport,
1635 uint16_t *mb_ret, uint8_t opt)
1637 int rval;
1638 mbx_cmd_t mc;
1639 mbx_cmd_t *mcp = &mc;
1641 if (IS_FWI2_CAPABLE(ha))
1642 return qla24xx_login_fabric(ha, fcport->loop_id,
1643 fcport->d_id.b.domain, fcport->d_id.b.area,
1644 fcport->d_id.b.al_pa, mb_ret, opt);
1646 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1648 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1649 if (HAS_EXTENDED_IDS(ha))
1650 mcp->mb[1] = fcport->loop_id;
1651 else
1652 mcp->mb[1] = fcport->loop_id << 8;
1653 mcp->mb[2] = opt;
1654 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1655 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1656 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1657 mcp->flags = 0;
1658 rval = qla2x00_mailbox_command(ha, mcp);
1660 /* Return mailbox statuses. */
1661 if (mb_ret != NULL) {
1662 mb_ret[0] = mcp->mb[0];
1663 mb_ret[1] = mcp->mb[1];
1664 mb_ret[6] = mcp->mb[6];
1665 mb_ret[7] = mcp->mb[7];
1668 if (rval != QLA_SUCCESS) {
1669 /* AV tmp code: need to change main mailbox_command function to
1670 * return ok even when the mailbox completion value is not
1671 * SUCCESS. The caller needs to be responsible to interpret
1672 * the return values of this mailbox command if we're not
1673 * to change too much of the existing code.
1675 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1676 rval = QLA_SUCCESS;
1678 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1679 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1680 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1681 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1682 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1683 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
1684 } else {
1685 /*EMPTY*/
1686 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no));
1689 return (rval);
1693 qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1694 uint8_t area, uint8_t al_pa)
1696 int rval;
1697 struct logio_entry_24xx *lg;
1698 dma_addr_t lg_dma;
1700 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1702 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1703 if (lg == NULL) {
1704 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1705 __func__, ha->host_no));
1706 return QLA_MEMORY_ALLOC_FAILED;
1708 memset(lg, 0, sizeof(struct logio_entry_24xx));
1710 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1711 lg->entry_count = 1;
1712 lg->nport_handle = cpu_to_le16(loop_id);
1713 lg->control_flags =
1714 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1715 lg->port_id[0] = al_pa;
1716 lg->port_id[1] = area;
1717 lg->port_id[2] = domain;
1718 lg->vp_index = cpu_to_le16(ha->vp_idx);
1719 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1720 if (rval != QLA_SUCCESS) {
1721 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1722 "(%x).\n", __func__, ha->host_no, rval));
1723 } else if (lg->entry_status != 0) {
1724 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1725 "-- error status (%x).\n", __func__, ha->host_no,
1726 lg->entry_status));
1727 rval = QLA_FUNCTION_FAILED;
1728 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1729 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1730 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1731 ha->host_no, le16_to_cpu(lg->comp_status),
1732 le32_to_cpu(lg->io_parameter[0]),
1733 le32_to_cpu(lg->io_parameter[1])));
1734 } else {
1735 /*EMPTY*/
1736 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1739 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1741 return rval;
1745 * qla2x00_fabric_logout
1746 * Issue logout fabric port mailbox command.
1748 * Input:
1749 * ha = adapter block pointer.
1750 * loop_id = device loop ID.
1751 * TARGET_QUEUE_LOCK must be released.
1752 * ADAPTER_STATE_LOCK must be released.
1754 * Returns:
1755 * qla2x00 local function return status code.
1757 * Context:
1758 * Kernel context.
1761 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1762 uint8_t area, uint8_t al_pa)
1764 int rval;
1765 mbx_cmd_t mc;
1766 mbx_cmd_t *mcp = &mc;
1768 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1769 ha->host_no));
1771 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1772 mcp->out_mb = MBX_1|MBX_0;
1773 if (HAS_EXTENDED_IDS(ha)) {
1774 mcp->mb[1] = loop_id;
1775 mcp->mb[10] = 0;
1776 mcp->out_mb |= MBX_10;
1777 } else {
1778 mcp->mb[1] = loop_id << 8;
1781 mcp->in_mb = MBX_1|MBX_0;
1782 mcp->tov = 30;
1783 mcp->flags = 0;
1784 rval = qla2x00_mailbox_command(ha, mcp);
1786 if (rval != QLA_SUCCESS) {
1787 /*EMPTY*/
1788 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1789 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]));
1790 } else {
1791 /*EMPTY*/
1792 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1793 ha->host_no));
1796 return rval;
1800 * qla2x00_full_login_lip
1801 * Issue full login LIP mailbox command.
1803 * Input:
1804 * ha = adapter block pointer.
1805 * TARGET_QUEUE_LOCK must be released.
1806 * ADAPTER_STATE_LOCK must be released.
1808 * Returns:
1809 * qla2x00 local function return status code.
1811 * Context:
1812 * Kernel context.
1815 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1817 int rval;
1818 mbx_cmd_t mc;
1819 mbx_cmd_t *mcp = &mc;
1821 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1822 ha->host_no));
1824 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1825 mcp->mb[1] = IS_FWI2_CAPABLE(ha) ? BIT_3: 0;
1826 mcp->mb[2] = 0;
1827 mcp->mb[3] = 0;
1828 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1829 mcp->in_mb = MBX_0;
1830 mcp->tov = 30;
1831 mcp->flags = 0;
1832 rval = qla2x00_mailbox_command(ha, mcp);
1834 if (rval != QLA_SUCCESS) {
1835 /*EMPTY*/
1836 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1837 ha->host_no, rval));
1838 } else {
1839 /*EMPTY*/
1840 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1841 ha->host_no));
1844 return rval;
1848 * qla2x00_get_id_list
1850 * Input:
1851 * ha = adapter block pointer.
1853 * Returns:
1854 * qla2x00 local function return status code.
1856 * Context:
1857 * Kernel context.
1860 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1861 uint16_t *entries)
1863 int rval;
1864 mbx_cmd_t mc;
1865 mbx_cmd_t *mcp = &mc;
1867 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1868 ha->host_no));
1870 if (id_list == NULL)
1871 return QLA_FUNCTION_FAILED;
1873 mcp->mb[0] = MBC_GET_ID_LIST;
1874 mcp->out_mb = MBX_0;
1875 if (IS_FWI2_CAPABLE(ha)) {
1876 mcp->mb[2] = MSW(id_list_dma);
1877 mcp->mb[3] = LSW(id_list_dma);
1878 mcp->mb[6] = MSW(MSD(id_list_dma));
1879 mcp->mb[7] = LSW(MSD(id_list_dma));
1880 mcp->mb[8] = 0;
1881 mcp->mb[9] = ha->vp_idx;
1882 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1883 } else {
1884 mcp->mb[1] = MSW(id_list_dma);
1885 mcp->mb[2] = LSW(id_list_dma);
1886 mcp->mb[3] = MSW(MSD(id_list_dma));
1887 mcp->mb[6] = LSW(MSD(id_list_dma));
1888 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1890 mcp->in_mb = MBX_1|MBX_0;
1891 mcp->tov = 30;
1892 mcp->flags = 0;
1893 rval = qla2x00_mailbox_command(ha, mcp);
1895 if (rval != QLA_SUCCESS) {
1896 /*EMPTY*/
1897 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1898 ha->host_no, rval));
1899 } else {
1900 *entries = mcp->mb[1];
1901 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1902 ha->host_no));
1905 return rval;
1909 * qla2x00_get_resource_cnts
1910 * Get current firmware resource counts.
1912 * Input:
1913 * ha = adapter block pointer.
1915 * Returns:
1916 * qla2x00 local function return status code.
1918 * Context:
1919 * Kernel context.
1922 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1923 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1924 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
1926 int rval;
1927 mbx_cmd_t mc;
1928 mbx_cmd_t *mcp = &mc;
1930 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1932 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1933 mcp->out_mb = MBX_0;
1934 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1935 mcp->tov = 30;
1936 mcp->flags = 0;
1937 rval = qla2x00_mailbox_command(ha, mcp);
1939 if (rval != QLA_SUCCESS) {
1940 /*EMPTY*/
1941 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1942 ha->host_no, mcp->mb[0]));
1943 } else {
1944 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1945 "mb7=%x mb10=%x mb11=%x.\n", __func__, ha->host_no,
1946 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1947 mcp->mb[10], mcp->mb[11]));
1949 if (cur_xchg_cnt)
1950 *cur_xchg_cnt = mcp->mb[3];
1951 if (orig_xchg_cnt)
1952 *orig_xchg_cnt = mcp->mb[6];
1953 if (cur_iocb_cnt)
1954 *cur_iocb_cnt = mcp->mb[7];
1955 if (orig_iocb_cnt)
1956 *orig_iocb_cnt = mcp->mb[10];
1957 if (max_npiv_vports)
1958 *max_npiv_vports = mcp->mb[11];
1961 return (rval);
1964 #if defined(QL_DEBUG_LEVEL_3)
1966 * qla2x00_get_fcal_position_map
1967 * Get FCAL (LILP) position map using mailbox command
1969 * Input:
1970 * ha = adapter state pointer.
1971 * pos_map = buffer pointer (can be NULL).
1973 * Returns:
1974 * qla2x00 local function return status code.
1976 * Context:
1977 * Kernel context.
1980 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1982 int rval;
1983 mbx_cmd_t mc;
1984 mbx_cmd_t *mcp = &mc;
1985 char *pmap;
1986 dma_addr_t pmap_dma;
1988 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1989 if (pmap == NULL) {
1990 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1991 __func__, ha->host_no));
1992 return QLA_MEMORY_ALLOC_FAILED;
1994 memset(pmap, 0, FCAL_MAP_SIZE);
1996 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1997 mcp->mb[2] = MSW(pmap_dma);
1998 mcp->mb[3] = LSW(pmap_dma);
1999 mcp->mb[6] = MSW(MSD(pmap_dma));
2000 mcp->mb[7] = LSW(MSD(pmap_dma));
2001 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2002 mcp->in_mb = MBX_1|MBX_0;
2003 mcp->buf_size = FCAL_MAP_SIZE;
2004 mcp->flags = MBX_DMA_IN;
2005 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2006 rval = qla2x00_mailbox_command(ha, mcp);
2008 if (rval == QLA_SUCCESS) {
2009 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2010 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2011 mcp->mb[1], (unsigned)pmap[0]));
2012 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2014 if (pos_map)
2015 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2017 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2019 if (rval != QLA_SUCCESS) {
2020 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2021 ha->host_no, rval));
2022 } else {
2023 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2026 return rval;
2028 #endif
2031 * qla2x00_get_link_status
2033 * Input:
2034 * ha = adapter block pointer.
2035 * loop_id = device loop ID.
2036 * ret_buf = pointer to link status return buffer.
2038 * Returns:
2039 * 0 = success.
2040 * BIT_0 = mem alloc error.
2041 * BIT_1 = mailbox error.
2044 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2045 link_stat_t *ret_buf, uint16_t *status)
2047 int rval;
2048 mbx_cmd_t mc;
2049 mbx_cmd_t *mcp = &mc;
2050 link_stat_t *stat_buf;
2051 dma_addr_t stat_buf_dma;
2053 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2055 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2056 if (stat_buf == NULL) {
2057 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2058 __func__, ha->host_no));
2059 return BIT_0;
2061 memset(stat_buf, 0, sizeof(link_stat_t));
2063 mcp->mb[0] = MBC_GET_LINK_STATUS;
2064 mcp->mb[2] = MSW(stat_buf_dma);
2065 mcp->mb[3] = LSW(stat_buf_dma);
2066 mcp->mb[6] = MSW(MSD(stat_buf_dma));
2067 mcp->mb[7] = LSW(MSD(stat_buf_dma));
2068 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2069 mcp->in_mb = MBX_0;
2070 if (IS_FWI2_CAPABLE(ha)) {
2071 mcp->mb[1] = loop_id;
2072 mcp->mb[4] = 0;
2073 mcp->mb[10] = 0;
2074 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2075 mcp->in_mb |= MBX_1;
2076 } else if (HAS_EXTENDED_IDS(ha)) {
2077 mcp->mb[1] = loop_id;
2078 mcp->mb[10] = 0;
2079 mcp->out_mb |= MBX_10|MBX_1;
2080 } else {
2081 mcp->mb[1] = loop_id << 8;
2082 mcp->out_mb |= MBX_1;
2084 mcp->tov = 30;
2085 mcp->flags = IOCTL_CMD;
2086 rval = qla2x00_mailbox_command(ha, mcp);
2088 if (rval == QLA_SUCCESS) {
2089 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2090 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2091 __func__, ha->host_no, mcp->mb[0]));
2092 status[0] = mcp->mb[0];
2093 rval = BIT_1;
2094 } else {
2095 /* copy over data -- firmware data is LE. */
2096 ret_buf->link_fail_cnt =
2097 le32_to_cpu(stat_buf->link_fail_cnt);
2098 ret_buf->loss_sync_cnt =
2099 le32_to_cpu(stat_buf->loss_sync_cnt);
2100 ret_buf->loss_sig_cnt =
2101 le32_to_cpu(stat_buf->loss_sig_cnt);
2102 ret_buf->prim_seq_err_cnt =
2103 le32_to_cpu(stat_buf->prim_seq_err_cnt);
2104 ret_buf->inval_xmit_word_cnt =
2105 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
2106 ret_buf->inval_crc_cnt =
2107 le32_to_cpu(stat_buf->inval_crc_cnt);
2109 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2110 "loss_sync=%d loss_sig=%d seq_err=%d "
2111 "inval_xmt_word=%d inval_crc=%d.\n", __func__,
2112 ha->host_no, stat_buf->link_fail_cnt,
2113 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2114 stat_buf->prim_seq_err_cnt,
2115 stat_buf->inval_xmit_word_cnt,
2116 stat_buf->inval_crc_cnt));
2118 } else {
2119 /* Failed. */
2120 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2121 ha->host_no, rval));
2122 rval = BIT_1;
2125 dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
2127 return rval;
2131 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2132 uint16_t *status)
2134 int rval;
2135 mbx_cmd_t mc;
2136 mbx_cmd_t *mcp = &mc;
2137 uint32_t *sbuf, *siter;
2138 dma_addr_t sbuf_dma;
2140 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2142 if (dwords > (DMA_POOL_SIZE / 4)) {
2143 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2144 "(max %d).\n", __func__, ha->host_no, dwords,
2145 DMA_POOL_SIZE / 4));
2146 return BIT_0;
2148 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2149 if (sbuf == NULL) {
2150 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2151 __func__, ha->host_no));
2152 return BIT_0;
2154 memset(sbuf, 0, DMA_POOL_SIZE);
2156 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2157 mcp->mb[2] = MSW(sbuf_dma);
2158 mcp->mb[3] = LSW(sbuf_dma);
2159 mcp->mb[6] = MSW(MSD(sbuf_dma));
2160 mcp->mb[7] = LSW(MSD(sbuf_dma));
2161 mcp->mb[8] = dwords;
2162 mcp->mb[10] = 0;
2163 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2164 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2165 mcp->tov = 30;
2166 mcp->flags = IOCTL_CMD;
2167 rval = qla2x00_mailbox_command(ha, mcp);
2169 if (rval == QLA_SUCCESS) {
2170 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2171 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2172 __func__, ha->host_no, mcp->mb[0]));
2173 status[0] = mcp->mb[0];
2174 rval = BIT_1;
2175 } else {
2176 /* Copy over data -- firmware data is LE. */
2177 siter = sbuf;
2178 while (dwords--)
2179 *dwbuf++ = le32_to_cpu(*siter++);
2181 } else {
2182 /* Failed. */
2183 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2184 ha->host_no, rval));
2185 rval = BIT_1;
2188 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2190 return rval;
2194 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2196 int rval;
2197 fc_port_t *fcport;
2198 unsigned long flags = 0;
2200 struct abort_entry_24xx *abt;
2201 dma_addr_t abt_dma;
2202 uint32_t handle;
2204 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2206 fcport = sp->fcport;
2208 spin_lock_irqsave(&ha->hardware_lock, flags);
2209 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2210 if (ha->outstanding_cmds[handle] == sp)
2211 break;
2213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2214 if (handle == MAX_OUTSTANDING_COMMANDS) {
2215 /* Command not found. */
2216 return QLA_FUNCTION_FAILED;
2219 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2220 if (abt == NULL) {
2221 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2222 __func__, ha->host_no));
2223 return QLA_MEMORY_ALLOC_FAILED;
2225 memset(abt, 0, sizeof(struct abort_entry_24xx));
2227 abt->entry_type = ABORT_IOCB_TYPE;
2228 abt->entry_count = 1;
2229 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2230 abt->handle_to_abort = handle;
2231 abt->port_id[0] = fcport->d_id.b.al_pa;
2232 abt->port_id[1] = fcport->d_id.b.area;
2233 abt->port_id[2] = fcport->d_id.b.domain;
2234 abt->vp_index = fcport->vp_idx;
2235 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2236 if (rval != QLA_SUCCESS) {
2237 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2238 __func__, ha->host_no, rval));
2239 } else if (abt->entry_status != 0) {
2240 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2241 "-- error status (%x).\n", __func__, ha->host_no,
2242 abt->entry_status));
2243 rval = QLA_FUNCTION_FAILED;
2244 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2245 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2246 "-- completion status (%x).\n", __func__, ha->host_no,
2247 le16_to_cpu(abt->nport_handle)));
2248 rval = QLA_FUNCTION_FAILED;
2249 } else {
2250 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2251 sp->flags |= SRB_ABORT_PENDING;
2254 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2256 return rval;
2259 struct tsk_mgmt_cmd {
2260 union {
2261 struct tsk_mgmt_entry tsk;
2262 struct sts_entry_24xx sts;
2263 } p;
2267 qla24xx_abort_target(fc_port_t *fcport)
2269 int rval;
2270 struct tsk_mgmt_cmd *tsk;
2271 dma_addr_t tsk_dma;
2272 scsi_qla_host_t *ha, *pha;
2274 if (fcport == NULL)
2275 return 0;
2277 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no));
2279 ha = fcport->ha;
2280 pha = to_qla_parent(ha);
2281 tsk = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2282 if (tsk == NULL) {
2283 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2284 "IOCB.\n", __func__, ha->host_no));
2285 return QLA_MEMORY_ALLOC_FAILED;
2287 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2289 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2290 tsk->p.tsk.entry_count = 1;
2291 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2292 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2293 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2294 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2295 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2296 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2297 tsk->p.tsk.vp_index = fcport->vp_idx;
2299 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2300 if (rval != QLA_SUCCESS) {
2301 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2302 "(%x).\n", __func__, ha->host_no, rval));
2303 goto atarget_done;
2304 } else if (tsk->p.sts.entry_status != 0) {
2305 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2306 "-- error status (%x).\n", __func__, ha->host_no,
2307 tsk->p.sts.entry_status));
2308 rval = QLA_FUNCTION_FAILED;
2309 goto atarget_done;
2310 } else if (tsk->p.sts.comp_status !=
2311 __constant_cpu_to_le16(CS_COMPLETE)) {
2312 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2313 "-- completion status (%x).\n", __func__,
2314 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
2315 rval = QLA_FUNCTION_FAILED;
2316 goto atarget_done;
2319 /* Issue marker IOCB. */
2320 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2321 if (rval != QLA_SUCCESS) {
2322 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2323 "(%x).\n", __func__, ha->host_no, rval));
2324 } else {
2325 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2328 atarget_done:
2329 dma_pool_free(pha->s_dma_pool, tsk, tsk_dma);
2331 return rval;
2335 qla2x00_system_error(scsi_qla_host_t *ha)
2337 int rval;
2338 mbx_cmd_t mc;
2339 mbx_cmd_t *mcp = &mc;
2341 if (!IS_FWI2_CAPABLE(ha))
2342 return QLA_FUNCTION_FAILED;
2344 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2346 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2347 mcp->out_mb = MBX_0;
2348 mcp->in_mb = MBX_0;
2349 mcp->tov = 5;
2350 mcp->flags = 0;
2351 rval = qla2x00_mailbox_command(ha, mcp);
2353 if (rval != QLA_SUCCESS) {
2354 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2355 ha->host_no, rval));
2356 } else {
2357 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2360 return rval;
2364 * qla2x00_get_serdes_params() -
2365 * @ha: HA context
2367 * Returns
2370 qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2371 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2373 int rval;
2374 mbx_cmd_t mc;
2375 mbx_cmd_t *mcp = &mc;
2377 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2379 mcp->mb[0] = MBC_SERDES_PARAMS;
2380 mcp->mb[1] = 0;
2381 mcp->out_mb = MBX_1|MBX_0;
2382 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2383 mcp->tov = 30;
2384 mcp->flags = 0;
2385 rval = qla2x00_mailbox_command(ha, mcp);
2387 if (rval != QLA_SUCCESS) {
2388 /*EMPTY*/
2389 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2390 ha->host_no, rval, mcp->mb[0]));
2391 } else {
2392 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2394 if (sw_em_1g)
2395 *sw_em_1g = mcp->mb[2];
2396 if (sw_em_2g)
2397 *sw_em_2g = mcp->mb[3];
2398 if (sw_em_4g)
2399 *sw_em_4g = mcp->mb[4];
2402 return rval;
2406 * qla2x00_set_serdes_params() -
2407 * @ha: HA context
2409 * Returns
2412 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2413 uint16_t sw_em_2g, uint16_t sw_em_4g)
2415 int rval;
2416 mbx_cmd_t mc;
2417 mbx_cmd_t *mcp = &mc;
2419 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2421 mcp->mb[0] = MBC_SERDES_PARAMS;
2422 mcp->mb[1] = BIT_0;
2423 mcp->mb[2] = sw_em_1g | BIT_15;
2424 mcp->mb[3] = sw_em_2g | BIT_15;
2425 mcp->mb[4] = sw_em_4g | BIT_15;
2426 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2427 mcp->in_mb = MBX_0;
2428 mcp->tov = 30;
2429 mcp->flags = 0;
2430 rval = qla2x00_mailbox_command(ha, mcp);
2432 if (rval != QLA_SUCCESS) {
2433 /*EMPTY*/
2434 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2435 ha->host_no, rval, mcp->mb[0]));
2436 } else {
2437 /*EMPTY*/
2438 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2441 return rval;
2445 qla2x00_stop_firmware(scsi_qla_host_t *ha)
2447 int rval;
2448 mbx_cmd_t mc;
2449 mbx_cmd_t *mcp = &mc;
2451 if (!IS_FWI2_CAPABLE(ha))
2452 return QLA_FUNCTION_FAILED;
2454 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2456 mcp->mb[0] = MBC_STOP_FIRMWARE;
2457 mcp->out_mb = MBX_0;
2458 mcp->in_mb = MBX_0;
2459 mcp->tov = 5;
2460 mcp->flags = 0;
2461 rval = qla2x00_mailbox_command(ha, mcp);
2463 if (rval != QLA_SUCCESS) {
2464 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2465 ha->host_no, rval));
2466 } else {
2467 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2470 return rval;
2474 qla2x00_trace_control(scsi_qla_host_t *ha, uint16_t ctrl, dma_addr_t eft_dma,
2475 uint16_t buffers)
2477 int rval;
2478 mbx_cmd_t mc;
2479 mbx_cmd_t *mcp = &mc;
2481 if (!IS_FWI2_CAPABLE(ha))
2482 return QLA_FUNCTION_FAILED;
2484 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2486 mcp->mb[0] = MBC_TRACE_CONTROL;
2487 mcp->mb[1] = ctrl;
2488 mcp->out_mb = MBX_1|MBX_0;
2489 mcp->in_mb = MBX_1|MBX_0;
2490 if (ctrl == TC_ENABLE) {
2491 mcp->mb[2] = LSW(eft_dma);
2492 mcp->mb[3] = MSW(eft_dma);
2493 mcp->mb[4] = LSW(MSD(eft_dma));
2494 mcp->mb[5] = MSW(MSD(eft_dma));
2495 mcp->mb[6] = buffers;
2496 mcp->mb[7] = 0;
2497 mcp->out_mb |= MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2;
2499 mcp->tov = 30;
2500 mcp->flags = 0;
2501 rval = qla2x00_mailbox_command(ha, mcp);
2503 if (rval != QLA_SUCCESS) {
2504 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
2505 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
2506 } else {
2507 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2510 return rval;
2514 qla2x00_read_sfp(scsi_qla_host_t *ha, dma_addr_t sfp_dma, uint16_t addr,
2515 uint16_t off, uint16_t count)
2517 int rval;
2518 mbx_cmd_t mc;
2519 mbx_cmd_t *mcp = &mc;
2521 if (!IS_FWI2_CAPABLE(ha))
2522 return QLA_FUNCTION_FAILED;
2524 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2526 mcp->mb[0] = MBC_READ_SFP;
2527 mcp->mb[1] = addr;
2528 mcp->mb[2] = MSW(sfp_dma);
2529 mcp->mb[3] = LSW(sfp_dma);
2530 mcp->mb[6] = MSW(MSD(sfp_dma));
2531 mcp->mb[7] = LSW(MSD(sfp_dma));
2532 mcp->mb[8] = count;
2533 mcp->mb[9] = off;
2534 mcp->mb[10] = 0;
2535 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2536 mcp->in_mb = MBX_0;
2537 mcp->tov = 30;
2538 mcp->flags = 0;
2539 rval = qla2x00_mailbox_command(ha, mcp);
2541 if (rval != QLA_SUCCESS) {
2542 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2543 ha->host_no, rval, mcp->mb[0]));
2544 } else {
2545 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2548 return rval;
2552 qla2x00_get_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2553 uint16_t *port_speed, uint16_t *mb)
2555 int rval;
2556 mbx_cmd_t mc;
2557 mbx_cmd_t *mcp = &mc;
2559 if (!IS_IIDMA_CAPABLE(ha))
2560 return QLA_FUNCTION_FAILED;
2562 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2564 mcp->mb[0] = MBC_PORT_PARAMS;
2565 mcp->mb[1] = loop_id;
2566 mcp->mb[2] = mcp->mb[3] = mcp->mb[4] = mcp->mb[5] = 0;
2567 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2568 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2569 mcp->tov = 30;
2570 mcp->flags = 0;
2571 rval = qla2x00_mailbox_command(ha, mcp);
2573 /* Return mailbox statuses. */
2574 if (mb != NULL) {
2575 mb[0] = mcp->mb[0];
2576 mb[1] = mcp->mb[1];
2577 mb[3] = mcp->mb[3];
2578 mb[4] = mcp->mb[4];
2579 mb[5] = mcp->mb[5];
2582 if (rval != QLA_SUCCESS) {
2583 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2584 ha->host_no, rval));
2585 } else {
2586 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2587 if (port_speed)
2588 *port_speed = mcp->mb[3];
2591 return rval;
2595 qla2x00_set_idma_speed(scsi_qla_host_t *ha, uint16_t loop_id,
2596 uint16_t port_speed, uint16_t *mb)
2598 int rval;
2599 mbx_cmd_t mc;
2600 mbx_cmd_t *mcp = &mc;
2602 if (!IS_IIDMA_CAPABLE(ha))
2603 return QLA_FUNCTION_FAILED;
2605 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2607 mcp->mb[0] = MBC_PORT_PARAMS;
2608 mcp->mb[1] = loop_id;
2609 mcp->mb[2] = BIT_0;
2610 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2611 mcp->mb[4] = mcp->mb[5] = 0;
2612 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2613 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2614 mcp->tov = 30;
2615 mcp->flags = 0;
2616 rval = qla2x00_mailbox_command(ha, mcp);
2618 /* Return mailbox statuses. */
2619 if (mb != NULL) {
2620 mb[0] = mcp->mb[0];
2621 mb[1] = mcp->mb[1];
2622 mb[3] = mcp->mb[3];
2623 mb[4] = mcp->mb[4];
2624 mb[5] = mcp->mb[5];
2627 if (rval != QLA_SUCCESS) {
2628 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2629 ha->host_no, rval));
2630 } else {
2631 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2634 return rval;
2638 * qla24xx_get_vp_database
2639 * Get the VP's database for all configured ports.
2641 * Input:
2642 * ha = adapter block pointer.
2643 * size = size of initialization control block.
2645 * Returns:
2646 * qla2x00 local function return status code.
2648 * Context:
2649 * Kernel context.
2652 qla24xx_get_vp_database(scsi_qla_host_t *ha, uint16_t size)
2654 int rval;
2655 mbx_cmd_t mc;
2656 mbx_cmd_t *mcp = &mc;
2658 DEBUG11(printk("scsi(%ld):%s - entered.\n",
2659 ha->host_no, __func__));
2661 mcp->mb[0] = MBC_MID_GET_VP_DATABASE;
2662 mcp->mb[2] = MSW(ha->init_cb_dma);
2663 mcp->mb[3] = LSW(ha->init_cb_dma);
2664 mcp->mb[4] = 0;
2665 mcp->mb[5] = 0;
2666 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2667 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2668 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2669 mcp->in_mb = MBX_1|MBX_0;
2670 mcp->buf_size = size;
2671 mcp->flags = MBX_DMA_OUT;
2672 mcp->tov = MBX_TOV_SECONDS;
2673 rval = qla2x00_mailbox_command(ha, mcp);
2675 if (rval != QLA_SUCCESS) {
2676 /*EMPTY*/
2677 DEBUG2_3_11(printk("%s(%ld): failed=%x "
2678 "mb0=%x.\n",
2679 __func__, ha->host_no, rval, mcp->mb[0]));
2680 } else {
2681 /*EMPTY*/
2682 DEBUG11(printk("%s(%ld): done.\n",
2683 __func__, ha->host_no));
2686 return rval;
2690 qla24xx_get_vp_entry(scsi_qla_host_t *ha, uint16_t size, int vp_id)
2692 int rval;
2693 mbx_cmd_t mc;
2694 mbx_cmd_t *mcp = &mc;
2696 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2698 mcp->mb[0] = MBC_MID_GET_VP_ENTRY;
2699 mcp->mb[2] = MSW(ha->init_cb_dma);
2700 mcp->mb[3] = LSW(ha->init_cb_dma);
2701 mcp->mb[4] = 0;
2702 mcp->mb[5] = 0;
2703 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
2704 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
2705 mcp->mb[9] = vp_id;
2706 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2707 mcp->in_mb = MBX_0;
2708 mcp->buf_size = size;
2709 mcp->flags = MBX_DMA_OUT;
2710 mcp->tov = 30;
2711 rval = qla2x00_mailbox_command(ha, mcp);
2713 if (rval != QLA_SUCCESS) {
2714 /*EMPTY*/
2715 DEBUG2_3_11(printk("qla24xx_get_vp_entry(%ld): failed=%x "
2716 "mb0=%x.\n",
2717 ha->host_no, rval, mcp->mb[0]));
2718 } else {
2719 /*EMPTY*/
2720 DEBUG11(printk("qla24xx_get_vp_entry(%ld): done.\n",
2721 ha->host_no));
2724 return rval;
2727 void
2728 qla24xx_report_id_acquisition(scsi_qla_host_t *ha,
2729 struct vp_rpt_id_entry_24xx *rptid_entry)
2731 uint8_t vp_idx;
2732 scsi_qla_host_t *vha;
2734 if (rptid_entry->entry_status != 0)
2735 return;
2736 if (rptid_entry->entry_status != __constant_cpu_to_le16(CS_COMPLETE))
2737 return;
2739 if (rptid_entry->format == 0) {
2740 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
2741 " number of VPs acquired %d\n", __func__, ha->host_no,
2742 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2743 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2744 rptid_entry->port_id[2], rptid_entry->port_id[1],
2745 rptid_entry->port_id[0]));
2746 } else if (rptid_entry->format == 1) {
2747 vp_idx = LSB(rptid_entry->vp_idx);
2748 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2749 "- status %d - "
2750 "with port id %02x%02x%02x\n",__func__,ha->host_no,
2751 vp_idx, MSB(rptid_entry->vp_idx),
2752 rptid_entry->port_id[2], rptid_entry->port_id[1],
2753 rptid_entry->port_id[0]));
2754 if (vp_idx == 0)
2755 return;
2757 if (MSB(rptid_entry->vp_idx) == 1)
2758 return;
2760 list_for_each_entry(vha, &ha->vp_list, vp_list)
2761 if (vp_idx == vha->vp_idx)
2762 break;
2764 if (!vha)
2765 return;
2767 vha->d_id.b.domain = rptid_entry->port_id[2];
2768 vha->d_id.b.area = rptid_entry->port_id[1];
2769 vha->d_id.b.al_pa = rptid_entry->port_id[0];
2772 * Cannot configure here as we are still sitting on the
2773 * response queue. Handle it in dpc context.
2775 set_bit(VP_IDX_ACQUIRED, &vha->vp_flags);
2776 set_bit(VP_DPC_NEEDED, &ha->dpc_flags);
2778 wake_up_process(ha->dpc_thread);
2783 * qla24xx_modify_vp_config
2784 * Change VP configuration for vha
2786 * Input:
2787 * vha = adapter block pointer.
2789 * Returns:
2790 * qla2xxx local function return status code.
2792 * Context:
2793 * Kernel context.
2796 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2798 int rval;
2799 struct vp_config_entry_24xx *vpmod;
2800 dma_addr_t vpmod_dma;
2801 scsi_qla_host_t *pha;
2803 /* This can be called by the parent */
2804 pha = to_qla_parent(vha);
2806 vpmod = dma_pool_alloc(pha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
2807 if (!vpmod) {
2808 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
2809 "IOCB.\n", __func__, pha->host_no));
2810 return QLA_MEMORY_ALLOC_FAILED;
2813 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2814 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2815 vpmod->entry_count = 1;
2816 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2817 vpmod->vp_count = 1;
2818 vpmod->vp_index1 = vha->vp_idx;
2819 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2820 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2821 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2822 vpmod->entry_count = 1;
2824 rval = qla2x00_issue_iocb(pha, vpmod, vpmod_dma, 0);
2825 if (rval != QLA_SUCCESS) {
2826 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
2827 "(%x).\n", __func__, pha->host_no, rval));
2828 } else if (vpmod->comp_status != 0) {
2829 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2830 "-- error status (%x).\n", __func__, pha->host_no,
2831 vpmod->comp_status));
2832 rval = QLA_FUNCTION_FAILED;
2833 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2834 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2835 "-- completion status (%x).\n", __func__, pha->host_no,
2836 le16_to_cpu(vpmod->comp_status)));
2837 rval = QLA_FUNCTION_FAILED;
2838 } else {
2839 /* EMPTY */
2840 DEBUG11(printk("%s(%ld): done.\n", __func__, pha->host_no));
2841 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2843 dma_pool_free(pha->s_dma_pool, vpmod, vpmod_dma);
2845 return rval;
2849 * qla24xx_control_vp
2850 * Enable a virtual port for given host
2852 * Input:
2853 * ha = adapter block pointer.
2854 * vhba = virtual adapter (unused)
2855 * index = index number for enabled VP
2857 * Returns:
2858 * qla2xxx local function return status code.
2860 * Context:
2861 * Kernel context.
2864 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2866 int rval;
2867 int map, pos;
2868 struct vp_ctrl_entry_24xx *vce;
2869 dma_addr_t vce_dma;
2870 scsi_qla_host_t *ha = vha->parent;
2871 int vp_index = vha->vp_idx;
2873 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
2874 ha->host_no, vp_index));
2876 if (vp_index == 0 || vp_index >= MAX_MULTI_ID_LOOP)
2877 return QLA_PARAMETER_ERROR;
2879 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2880 if (!vce) {
2881 DEBUG2_3(printk("%s(%ld): "
2882 "failed to allocate VP Control IOCB.\n", __func__,
2883 ha->host_no));
2884 return QLA_MEMORY_ALLOC_FAILED;
2886 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2888 vce->entry_type = VP_CTRL_IOCB_TYPE;
2889 vce->entry_count = 1;
2890 vce->command = cpu_to_le16(cmd);
2891 vce->vp_count = __constant_cpu_to_le16(1);
2893 /* index map in firmware starts with 1; decrement index
2894 * this is ok as we never use index 0
2896 map = (vp_index - 1) / 8;
2897 pos = (vp_index - 1) & 7;
2898 down(&ha->vport_sem);
2899 vce->vp_idx_map[map] |= 1 << pos;
2900 up(&ha->vport_sem);
2902 rval = qla2x00_issue_iocb(ha, vce, vce_dma, 0);
2903 if (rval != QLA_SUCCESS) {
2904 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
2905 "(%x).\n", __func__, ha->host_no, rval));
2906 printk("%s(%ld): failed to issue VP control IOCB"
2907 "(%x).\n", __func__, ha->host_no, rval);
2908 } else if (vce->entry_status != 0) {
2909 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2910 "-- error status (%x).\n", __func__, ha->host_no,
2911 vce->entry_status));
2912 printk("%s(%ld): failed to complete IOCB "
2913 "-- error status (%x).\n", __func__, ha->host_no,
2914 vce->entry_status);
2915 rval = QLA_FUNCTION_FAILED;
2916 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2917 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2918 "-- completion status (%x).\n", __func__, ha->host_no,
2919 le16_to_cpu(vce->comp_status)));
2920 printk("%s(%ld): failed to complete IOCB "
2921 "-- completion status (%x).\n", __func__, ha->host_no,
2922 le16_to_cpu(vce->comp_status));
2923 rval = QLA_FUNCTION_FAILED;
2924 } else {
2925 DEBUG2(printk("%s(%ld): done.\n", __func__, ha->host_no));
2928 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2930 return rval;
2934 * qla2x00_send_change_request
2935 * Receive or disable RSCN request from fabric controller
2937 * Input:
2938 * ha = adapter block pointer
2939 * format = registration format:
2940 * 0 - Reserved
2941 * 1 - Fabric detected registration
2942 * 2 - N_port detected registration
2943 * 3 - Full registration
2944 * FF - clear registration
2945 * vp_idx = Virtual port index
2947 * Returns:
2948 * qla2x00 local function return status code.
2950 * Context:
2951 * Kernel Context
2955 qla2x00_send_change_request(scsi_qla_host_t *ha, uint16_t format,
2956 uint16_t vp_idx)
2958 int rval;
2959 mbx_cmd_t mc;
2960 mbx_cmd_t *mcp = &mc;
2963 * This command is implicitly executed by firmware during login for the
2964 * physical hosts
2966 if (vp_idx == 0)
2967 return QLA_FUNCTION_FAILED;
2969 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2970 mcp->mb[1] = format;
2971 mcp->mb[9] = vp_idx;
2972 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2973 mcp->in_mb = MBX_0|MBX_1;
2974 mcp->tov = MBX_TOV_SECONDS;
2975 mcp->flags = 0;
2976 rval = qla2x00_mailbox_command(ha, mcp);
2978 if (rval == QLA_SUCCESS) {
2979 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2980 rval = BIT_1;
2982 } else
2983 rval = BIT_1;
2985 return rval;
2989 qla2x00_dump_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t addr,
2990 uint32_t size)
2992 int rval;
2993 mbx_cmd_t mc;
2994 mbx_cmd_t *mcp = &mc;
2996 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2998 if (MSW(addr) || IS_FWI2_CAPABLE(ha)) {
2999 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3000 mcp->mb[8] = MSW(addr);
3001 mcp->out_mb = MBX_8|MBX_0;
3002 } else {
3003 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3004 mcp->out_mb = MBX_0;
3006 mcp->mb[1] = LSW(addr);
3007 mcp->mb[2] = MSW(req_dma);
3008 mcp->mb[3] = LSW(req_dma);
3009 mcp->mb[6] = MSW(MSD(req_dma));
3010 mcp->mb[7] = LSW(MSD(req_dma));
3011 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3012 if (IS_FWI2_CAPABLE(ha)) {
3013 mcp->mb[4] = MSW(size);
3014 mcp->mb[5] = LSW(size);
3015 mcp->out_mb |= MBX_5|MBX_4;
3016 } else {
3017 mcp->mb[4] = LSW(size);
3018 mcp->out_mb |= MBX_4;
3021 mcp->in_mb = MBX_0;
3022 mcp->tov = 30;
3023 mcp->flags = 0;
3024 rval = qla2x00_mailbox_command(ha, mcp);
3026 if (rval != QLA_SUCCESS) {
3027 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3028 ha->host_no, rval, mcp->mb[0]));
3029 } else {
3030 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
3033 return rval;