powerpc: Compile fixes for chrp/nvram.c
[linux-2.6/x86.git] / drivers / scsi / qla2xxx / qla_mbx.c
blob13e1c9047079e8fcfd2ef808f1ba93d1fbef13e9
1 /*
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
6 * (www.qlogic.com)
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
19 #include "qla_def.h"
21 #include <linux/delay.h>
22 #include <scsi/scsi_transport_fc.h>
24 static void
25 qla2x00_mbx_sem_timeout(unsigned long data)
27 struct semaphore *sem_ptr = (struct semaphore *)data;
29 DEBUG11(printk("qla2x00_sem_timeout: entered.\n");)
31 if (sem_ptr != NULL) {
32 up(sem_ptr);
35 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)
39 * qla2x00_mailbox_command
40 * Issue mailbox command and waits for completion.
42 * Input:
43 * ha = adapter block pointer.
44 * mcp = driver internal mbx struct pointer.
46 * Output:
47 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
49 * Returns:
50 * 0 : QLA_SUCCESS = cmd performed success
51 * 1 : QLA_FUNCTION_FAILED (error encountered)
52 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
54 * Context:
55 * Kernel context.
57 static int
58 qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
60 int rval;
61 unsigned long flags = 0;
62 device_reg_t __iomem *reg = ha->iobase;
63 struct timer_list tmp_intr_timer;
64 uint8_t abort_active;
65 uint8_t io_lock_on = ha->flags.init_done;
66 uint16_t command;
67 uint16_t *iptr;
68 uint16_t __iomem *optr;
69 uint32_t cnt;
70 uint32_t mboxes;
71 unsigned long mbx_flags = 0;
72 unsigned long wait_time;
74 rval = QLA_SUCCESS;
75 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
77 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
80 * Wait for active mailbox commands to finish by waiting at most tov
81 * seconds. This is to serialize actual issuing of mailbox cmds during
82 * non ISP abort time.
84 if (!abort_active) {
85 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
86 /* Timeout occurred. Return error. */
87 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
88 "Exiting.\n", __func__, ha->host_no);)
89 return QLA_FUNCTION_TIMEOUT;
93 ha->flags.mbox_busy = 1;
94 /* Save mailbox command for debug */
95 ha->mcp = mcp;
97 /* Try to get mailbox register access */
98 if (!abort_active)
99 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
101 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
102 ha->host_no, mcp->mb[0]);)
104 spin_lock_irqsave(&ha->hardware_lock, flags);
106 /* Load mailbox registers. */
107 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
108 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
109 else
110 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
112 iptr = mcp->mb;
113 command = mcp->mb[0];
114 mboxes = mcp->out_mb;
116 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
117 if (IS_QLA2200(ha) && cnt == 8)
118 optr =
119 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
120 if (mboxes & BIT_0)
121 WRT_REG_WORD(optr, *iptr);
123 mboxes >>= 1;
124 optr++;
125 iptr++;
128 #if defined(QL_DEBUG_LEVEL_1)
129 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
130 __func__, ha->host_no);
131 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
132 printk("\n");
133 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
134 printk("\n");
135 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
136 printk("\n");
137 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
138 qla2x00_dump_regs(ha);
139 #endif
141 /* Issue set host interrupt command to send cmd out. */
142 ha->flags.mbox_int = 0;
143 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
145 /* Unlock mbx registers and wait for interrupt */
146 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
147 "jiffies=%lx.\n", __func__, ha->host_no, jiffies);)
149 /* Wait for mbx cmd completion until timeout */
151 if (!abort_active && io_lock_on) {
152 /* sleep on completion semaphore */
153 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
154 __func__, ha->host_no);)
156 init_timer(&tmp_intr_timer);
157 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
158 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
159 tmp_intr_timer.function =
160 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
162 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
163 ha->host_no);)
164 add_timer(&tmp_intr_timer);
166 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
167 "time=0x%lx.\n", __func__, ha->host_no, jiffies);)
169 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
171 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
172 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
173 else
174 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
175 spin_unlock_irqrestore(&ha->hardware_lock, flags);
177 if (!abort_active)
178 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
180 /* Wait for either the timer to expire
181 * or the mbox completion interrupt
183 down(&ha->mbx_intr_sem);
185 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
186 ha->host_no, jiffies);)
187 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
189 /* delete the timer */
190 del_timer(&tmp_intr_timer);
191 } else {
192 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
193 ha->host_no, command);)
195 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
196 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
197 else
198 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
200 if (!abort_active)
201 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
203 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
204 while (!ha->flags.mbox_int) {
205 if (time_after(jiffies, wait_time))
206 break;
208 /* Check for pending interrupts. */
209 qla2x00_poll(ha);
211 udelay(10); /* v4.27 */
212 } /* while */
215 if (!abort_active)
216 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
218 /* Check whether we timed out */
219 if (ha->flags.mbox_int) {
220 uint16_t *iptr2;
222 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
223 ha->host_no, command);)
225 /* Got interrupt. Clear the flag. */
226 ha->flags.mbox_int = 0;
227 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
229 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
230 rval = QLA_FUNCTION_FAILED;
232 /* Load return mailbox registers. */
233 iptr2 = mcp->mb;
234 iptr = (uint16_t *)&ha->mailbox_out[0];
235 mboxes = mcp->in_mb;
236 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
237 if (mboxes & BIT_0)
238 *iptr2 = *iptr;
240 mboxes >>= 1;
241 iptr2++;
242 iptr++;
244 } else {
246 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
247 defined(QL_DEBUG_LEVEL_11)
248 uint16_t mb0;
249 uint32_t ictrl;
251 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
252 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
253 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
254 } else {
255 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
256 ictrl = RD_REG_WORD(&reg->isp.ictrl);
258 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
259 __func__, ha->host_no, command);
260 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
261 ha->host_no, ictrl, jiffies);
262 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
263 ha->host_no, mb0);
264 qla2x00_dump_regs(ha);
265 #endif
267 rval = QLA_FUNCTION_TIMEOUT;
270 if (!abort_active)
271 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
273 ha->flags.mbox_busy = 0;
275 /* Clean up */
276 ha->mcp = NULL;
278 if (!abort_active) {
279 DEBUG11(printk("%s(%ld): checking for additional resp "
280 "interrupt.\n", __func__, ha->host_no);)
282 /* polling mode for non isp_abort commands. */
283 qla2x00_poll(ha);
286 if (rval == QLA_FUNCTION_TIMEOUT &&
287 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
288 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
289 /* not in dpc. schedule it for dpc to take over. */
290 DEBUG(printk("%s(%ld): timeout schedule "
291 "isp_abort_needed.\n", __func__, ha->host_no);)
292 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
293 "isp_abort_needed.\n", __func__, ha->host_no);)
294 qla_printk(KERN_WARNING, ha,
295 "Mailbox command timeout occured. Scheduling ISP "
296 "abort.\n");
297 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
298 if (ha->dpc_wait && !ha->dpc_active)
299 up(ha->dpc_wait);
301 } else if (!abort_active) {
302 /* call abort directly since we are in the DPC thread */
303 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
304 __func__, ha->host_no);)
305 DEBUG2_3_11(printk("%s(%ld): timeout calling "
306 "abort_isp\n", __func__, ha->host_no);)
307 qla_printk(KERN_WARNING, ha,
308 "Mailbox command timeout occured. Issuing ISP "
309 "abort.\n");
311 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
312 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
313 if (qla2x00_abort_isp(ha)) {
314 /* Failed. retry later. */
315 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
317 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
318 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
319 ha->host_no);)
320 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
321 __func__, ha->host_no);)
325 /* Allow next mbx cmd to come in. */
326 if (!abort_active)
327 up(&ha->mbx_cmd_sem);
329 if (rval) {
330 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
331 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
332 mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
333 } else {
334 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
337 return rval;
341 * qla2x00_load_ram
342 * Load adapter RAM using DMA.
344 * Input:
345 * ha = adapter block pointer.
347 * Returns:
348 * qla2x00 local function return status code.
350 * Context:
351 * Kernel context.
354 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint16_t risc_addr,
355 uint16_t risc_code_size)
357 int rval;
358 mbx_cmd_t mc;
359 mbx_cmd_t *mcp = &mc;
360 uint32_t req_len;
361 dma_addr_t nml_dma;
362 uint32_t nml_len;
363 uint32_t normalized;
365 DEBUG11(printk("qla2x00_load_ram(%ld): entered.\n",
366 ha->host_no);)
368 req_len = risc_code_size;
369 nml_dma = 0;
370 nml_len = 0;
372 normalized = qla2x00_normalize_dma_addr(&req_dma, &req_len, &nml_dma,
373 &nml_len);
375 /* Load first segment */
376 mcp->mb[0] = MBC_LOAD_RISC_RAM;
377 mcp->mb[1] = risc_addr;
378 mcp->mb[2] = MSW(req_dma);
379 mcp->mb[3] = LSW(req_dma);
380 mcp->mb[4] = (uint16_t)req_len;
381 mcp->mb[6] = MSW(MSD(req_dma));
382 mcp->mb[7] = LSW(MSD(req_dma));
383 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
384 mcp->in_mb = MBX_0;
385 mcp->tov = 30;
386 mcp->flags = 0;
387 rval = qla2x00_mailbox_command(ha, mcp);
389 /* Load second segment - if necessary */
390 if (normalized && (rval == QLA_SUCCESS)) {
391 mcp->mb[0] = MBC_LOAD_RISC_RAM;
392 mcp->mb[1] = risc_addr + (uint16_t)req_len;
393 mcp->mb[2] = MSW(nml_dma);
394 mcp->mb[3] = LSW(nml_dma);
395 mcp->mb[4] = (uint16_t)nml_len;
396 mcp->mb[6] = MSW(MSD(nml_dma));
397 mcp->mb[7] = LSW(MSD(nml_dma));
398 mcp->out_mb = MBX_7|MBX_6|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
399 mcp->in_mb = MBX_0;
400 mcp->tov = 30;
401 mcp->flags = 0;
402 rval = qla2x00_mailbox_command(ha, mcp);
405 if (rval == QLA_SUCCESS) {
406 /* Empty */
407 DEBUG11(printk("qla2x00_load_ram(%ld): done.\n", ha->host_no);)
408 } else {
409 /* Empty */
410 DEBUG2_3_11(printk("qla2x00_load_ram(%ld): failed. rval=%x "
411 "mb[0]=%x.\n", ha->host_no, rval, mcp->mb[0]);)
413 return rval;
417 * qla2x00_load_ram_ext
418 * Load adapter extended RAM using DMA.
420 * Input:
421 * ha = adapter block pointer.
423 * Returns:
424 * qla2x00 local function return status code.
426 * Context:
427 * Kernel context.
430 qla2x00_load_ram_ext(scsi_qla_host_t *ha, dma_addr_t req_dma,
431 uint32_t risc_addr, uint32_t risc_code_size)
433 int rval;
434 mbx_cmd_t mc;
435 mbx_cmd_t *mcp = &mc;
437 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
439 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
440 mcp->mb[1] = LSW(risc_addr);
441 mcp->mb[2] = MSW(req_dma);
442 mcp->mb[3] = LSW(req_dma);
443 mcp->mb[6] = MSW(MSD(req_dma));
444 mcp->mb[7] = LSW(MSD(req_dma));
445 mcp->mb[8] = MSW(risc_addr);
446 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
447 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
448 mcp->mb[4] = MSW(risc_code_size);
449 mcp->mb[5] = LSW(risc_code_size);
450 mcp->out_mb |= MBX_5|MBX_4;
451 } else {
452 mcp->mb[4] = LSW(risc_code_size);
453 mcp->out_mb |= MBX_4;
456 mcp->in_mb = MBX_0;
457 mcp->tov = 30;
458 mcp->flags = 0;
459 rval = qla2x00_mailbox_command(ha, mcp);
461 if (rval != QLA_SUCCESS) {
462 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
463 ha->host_no, rval, mcp->mb[0]));
464 } else {
465 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
468 return rval;
472 * qla2x00_execute_fw
473 * Start adapter firmware.
475 * Input:
476 * ha = adapter block pointer.
477 * TARGET_QUEUE_LOCK must be released.
478 * ADAPTER_STATE_LOCK must be released.
480 * Returns:
481 * qla2x00 local function return status code.
483 * Context:
484 * Kernel context.
487 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
489 int rval;
490 mbx_cmd_t mc;
491 mbx_cmd_t *mcp = &mc;
493 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
495 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
496 mcp->out_mb = MBX_0;
497 mcp->in_mb = MBX_0;
498 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
499 mcp->mb[1] = MSW(risc_addr);
500 mcp->mb[2] = LSW(risc_addr);
501 mcp->mb[3] = 0;
502 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
503 mcp->in_mb |= MBX_1;
504 } else {
505 mcp->mb[1] = LSW(risc_addr);
506 mcp->out_mb |= MBX_1;
507 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
508 mcp->mb[2] = 0;
509 mcp->out_mb |= MBX_2;
513 mcp->tov = 30;
514 mcp->flags = 0;
515 rval = qla2x00_mailbox_command(ha, mcp);
517 if (rval != QLA_SUCCESS) {
518 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
519 ha->host_no, rval, mcp->mb[0]));
520 } else {
521 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
522 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
523 __func__, ha->host_no, mcp->mb[1]);)
524 } else {
525 DEBUG11(printk("%s(%ld): done.\n", __func__,
526 ha->host_no);)
530 return rval;
534 * qla2x00_get_fw_version
535 * Get firmware version.
537 * Input:
538 * ha: adapter state pointer.
539 * major: pointer for major number.
540 * minor: pointer for minor number.
541 * subminor: pointer for subminor number.
543 * Returns:
544 * qla2x00 local function return status code.
546 * Context:
547 * Kernel context.
549 void
550 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
551 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
553 int rval;
554 mbx_cmd_t mc;
555 mbx_cmd_t *mcp = &mc;
557 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
559 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
560 mcp->out_mb = MBX_0;
561 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
562 mcp->flags = 0;
563 mcp->tov = 30;
564 rval = qla2x00_mailbox_command(ha, mcp);
566 /* Return mailbox data. */
567 *major = mcp->mb[1];
568 *minor = mcp->mb[2];
569 *subminor = mcp->mb[3];
570 *attributes = mcp->mb[6];
571 if (IS_QLA2100(ha) || IS_QLA2200(ha))
572 *memory = 0x1FFFF; /* Defaults to 128KB. */
573 else
574 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
576 if (rval != QLA_SUCCESS) {
577 /*EMPTY*/
578 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
579 ha->host_no, rval));
580 } else {
581 /*EMPTY*/
582 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
587 * qla2x00_get_fw_options
588 * Set firmware options.
590 * Input:
591 * ha = adapter block pointer.
592 * fwopt = pointer for firmware options.
594 * Returns:
595 * qla2x00 local function return status code.
597 * Context:
598 * Kernel context.
601 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
603 int rval;
604 mbx_cmd_t mc;
605 mbx_cmd_t *mcp = &mc;
607 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
609 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
610 mcp->out_mb = MBX_0;
611 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
612 mcp->tov = 30;
613 mcp->flags = 0;
614 rval = qla2x00_mailbox_command(ha, mcp);
616 if (rval != QLA_SUCCESS) {
617 /*EMPTY*/
618 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
619 ha->host_no, rval));
620 } else {
621 fwopts[0] = mcp->mb[0];
622 fwopts[1] = mcp->mb[1];
623 fwopts[2] = mcp->mb[2];
624 fwopts[3] = mcp->mb[3];
626 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
629 return rval;
634 * qla2x00_set_fw_options
635 * Set firmware options.
637 * Input:
638 * ha = adapter block pointer.
639 * fwopt = pointer for firmware options.
641 * Returns:
642 * qla2x00 local function return status code.
644 * Context:
645 * Kernel context.
648 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
650 int rval;
651 mbx_cmd_t mc;
652 mbx_cmd_t *mcp = &mc;
654 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
656 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
657 mcp->mb[1] = fwopts[1];
658 mcp->mb[2] = fwopts[2];
659 mcp->mb[3] = fwopts[3];
660 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
661 mcp->in_mb = MBX_0;
662 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
663 mcp->in_mb |= MBX_1;
664 } else {
665 mcp->mb[10] = fwopts[10];
666 mcp->mb[11] = fwopts[11];
667 mcp->mb[12] = 0; /* Undocumented, but used */
668 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
670 mcp->tov = 30;
671 mcp->flags = 0;
672 rval = qla2x00_mailbox_command(ha, mcp);
674 fwopts[0] = mcp->mb[0];
676 if (rval != QLA_SUCCESS) {
677 /*EMPTY*/
678 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
679 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
680 } else {
681 /*EMPTY*/
682 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
685 return rval;
689 * qla2x00_mbx_reg_test
690 * Mailbox register wrap test.
692 * Input:
693 * ha = adapter block pointer.
694 * TARGET_QUEUE_LOCK must be released.
695 * ADAPTER_STATE_LOCK must be released.
697 * Returns:
698 * qla2x00 local function return status code.
700 * Context:
701 * Kernel context.
704 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
706 int rval;
707 mbx_cmd_t mc;
708 mbx_cmd_t *mcp = &mc;
710 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
712 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
713 mcp->mb[1] = 0xAAAA;
714 mcp->mb[2] = 0x5555;
715 mcp->mb[3] = 0xAA55;
716 mcp->mb[4] = 0x55AA;
717 mcp->mb[5] = 0xA5A5;
718 mcp->mb[6] = 0x5A5A;
719 mcp->mb[7] = 0x2525;
720 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
721 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
722 mcp->tov = 30;
723 mcp->flags = 0;
724 rval = qla2x00_mailbox_command(ha, mcp);
726 if (rval == QLA_SUCCESS) {
727 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
728 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
729 rval = QLA_FUNCTION_FAILED;
730 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
731 mcp->mb[7] != 0x2525)
732 rval = QLA_FUNCTION_FAILED;
735 if (rval != QLA_SUCCESS) {
736 /*EMPTY*/
737 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
738 ha->host_no, rval);)
739 } else {
740 /*EMPTY*/
741 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
742 ha->host_no);)
745 return rval;
749 * qla2x00_verify_checksum
750 * Verify firmware checksum.
752 * Input:
753 * ha = adapter block pointer.
754 * TARGET_QUEUE_LOCK must be released.
755 * ADAPTER_STATE_LOCK must be released.
757 * Returns:
758 * qla2x00 local function return status code.
760 * Context:
761 * Kernel context.
764 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
766 int rval;
767 mbx_cmd_t mc;
768 mbx_cmd_t *mcp = &mc;
770 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
772 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
773 mcp->out_mb = MBX_0;
774 mcp->in_mb = MBX_0;
775 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
776 mcp->mb[1] = MSW(risc_addr);
777 mcp->mb[2] = LSW(risc_addr);
778 mcp->out_mb |= MBX_2|MBX_1;
779 mcp->in_mb |= MBX_2|MBX_1;
780 } else {
781 mcp->mb[1] = LSW(risc_addr);
782 mcp->out_mb |= MBX_1;
783 mcp->in_mb |= MBX_1;
786 mcp->tov = 30;
787 mcp->flags = 0;
788 rval = qla2x00_mailbox_command(ha, mcp);
790 if (rval != QLA_SUCCESS) {
791 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
792 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
793 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));)
794 } else {
795 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
798 return rval;
802 * qla2x00_issue_iocb
803 * Issue IOCB using mailbox command
805 * Input:
806 * ha = adapter state pointer.
807 * buffer = buffer pointer.
808 * phys_addr = physical address of buffer.
809 * size = size of buffer.
810 * TARGET_QUEUE_LOCK must be released.
811 * ADAPTER_STATE_LOCK must be released.
813 * Returns:
814 * qla2x00 local function return status code.
816 * Context:
817 * Kernel context.
820 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
821 size_t size)
823 int rval;
824 mbx_cmd_t mc;
825 mbx_cmd_t *mcp = &mc;
827 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
828 mcp->mb[1] = 0;
829 mcp->mb[2] = MSW(phys_addr);
830 mcp->mb[3] = LSW(phys_addr);
831 mcp->mb[6] = MSW(MSD(phys_addr));
832 mcp->mb[7] = LSW(MSD(phys_addr));
833 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
834 mcp->in_mb = MBX_2|MBX_0;
835 mcp->tov = 30;
836 mcp->flags = 0;
837 rval = qla2x00_mailbox_command(ha, mcp);
839 if (rval != QLA_SUCCESS) {
840 /*EMPTY*/
841 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
842 ha->host_no, rval);)
843 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
844 ha->host_no, rval);)
845 } else {
846 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
848 /* Mask reserved bits. */
849 sts_entry->entry_status &=
850 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RF_MASK_24XX :RF_MASK;
853 return rval;
857 * qla2x00_abort_command
858 * Abort command aborts a specified IOCB.
860 * Input:
861 * ha = adapter block pointer.
862 * sp = SB structure pointer.
864 * Returns:
865 * qla2x00 local function return status code.
867 * Context:
868 * Kernel context.
871 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
873 unsigned long flags = 0;
874 fc_port_t *fcport;
875 int rval;
876 uint32_t handle;
877 mbx_cmd_t mc;
878 mbx_cmd_t *mcp = &mc;
880 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
882 fcport = sp->fcport;
883 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
884 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
885 return 1;
888 spin_lock_irqsave(&ha->hardware_lock, flags);
889 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
890 if (ha->outstanding_cmds[handle] == sp)
891 break;
893 spin_unlock_irqrestore(&ha->hardware_lock, flags);
895 if (handle == MAX_OUTSTANDING_COMMANDS) {
896 /* command not found */
897 return QLA_FUNCTION_FAILED;
900 mcp->mb[0] = MBC_ABORT_COMMAND;
901 if (HAS_EXTENDED_IDS(ha))
902 mcp->mb[1] = fcport->loop_id;
903 else
904 mcp->mb[1] = fcport->loop_id << 8;
905 mcp->mb[2] = (uint16_t)handle;
906 mcp->mb[3] = (uint16_t)(handle >> 16);
907 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
908 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
909 mcp->in_mb = MBX_0;
910 mcp->tov = 30;
911 mcp->flags = 0;
912 rval = qla2x00_mailbox_command(ha, mcp);
914 if (rval != QLA_SUCCESS) {
915 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
916 ha->host_no, rval);)
917 } else {
918 sp->flags |= SRB_ABORT_PENDING;
919 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
920 ha->host_no);)
923 return rval;
926 #if USE_ABORT_TGT
928 * qla2x00_abort_target
929 * Issue abort target mailbox command.
931 * Input:
932 * ha = adapter block pointer.
934 * Returns:
935 * qla2x00 local function return status code.
937 * Context:
938 * Kernel context.
941 qla2x00_abort_target(fc_port_t *fcport)
943 int rval;
944 mbx_cmd_t mc;
945 mbx_cmd_t *mcp = &mc;
946 scsi_qla_host_t *ha;
948 if (fcport == NULL)
949 return 0;
951 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
953 ha = fcport->ha;
954 mcp->mb[0] = MBC_ABORT_TARGET;
955 mcp->out_mb = MBX_2|MBX_1|MBX_0;
956 if (HAS_EXTENDED_IDS(ha)) {
957 mcp->mb[1] = fcport->loop_id;
958 mcp->mb[10] = 0;
959 mcp->out_mb |= MBX_10;
960 } else {
961 mcp->mb[1] = fcport->loop_id << 8;
963 mcp->mb[2] = ha->loop_reset_delay;
965 mcp->in_mb = MBX_0;
966 mcp->tov = 30;
967 mcp->flags = 0;
968 rval = qla2x00_mailbox_command(ha, mcp);
970 /* Issue marker command. */
971 ha->marker_needed = 1;
973 if (rval != QLA_SUCCESS) {
974 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
975 ha->host_no, rval);)
976 } else {
977 /*EMPTY*/
978 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
979 ha->host_no);)
982 return rval;
984 #endif
987 * qla2x00_get_adapter_id
988 * Get adapter ID and topology.
990 * Input:
991 * ha = adapter block pointer.
992 * id = pointer for loop ID.
993 * al_pa = pointer for AL_PA.
994 * area = pointer for area.
995 * domain = pointer for domain.
996 * top = pointer for topology.
997 * TARGET_QUEUE_LOCK must be released.
998 * ADAPTER_STATE_LOCK must be released.
1000 * Returns:
1001 * qla2x00 local function return status code.
1003 * Context:
1004 * Kernel context.
1007 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
1008 uint8_t *area, uint8_t *domain, uint16_t *top)
1010 int rval;
1011 mbx_cmd_t mc;
1012 mbx_cmd_t *mcp = &mc;
1014 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
1015 ha->host_no);)
1017 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
1018 mcp->out_mb = MBX_0;
1019 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1020 mcp->tov = 30;
1021 mcp->flags = 0;
1022 rval = qla2x00_mailbox_command(ha, mcp);
1024 /* Return data. */
1025 *id = mcp->mb[1];
1026 *al_pa = LSB(mcp->mb[2]);
1027 *area = MSB(mcp->mb[2]);
1028 *domain = LSB(mcp->mb[3]);
1029 *top = mcp->mb[6];
1031 if (rval != QLA_SUCCESS) {
1032 /*EMPTY*/
1033 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
1034 ha->host_no, rval);)
1035 } else {
1036 /*EMPTY*/
1037 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
1038 ha->host_no);)
1041 return rval;
1045 * qla2x00_get_retry_cnt
1046 * Get current firmware login retry count and delay.
1048 * Input:
1049 * ha = adapter block pointer.
1050 * retry_cnt = pointer to login retry count.
1051 * tov = pointer to login timeout value.
1053 * Returns:
1054 * qla2x00 local function return status code.
1056 * Context:
1057 * Kernel context.
1060 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
1061 uint16_t *r_a_tov)
1063 int rval;
1064 uint16_t ratov;
1065 mbx_cmd_t mc;
1066 mbx_cmd_t *mcp = &mc;
1068 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
1069 ha->host_no);)
1071 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1072 mcp->out_mb = MBX_0;
1073 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1074 mcp->tov = 30;
1075 mcp->flags = 0;
1076 rval = qla2x00_mailbox_command(ha, mcp);
1078 if (rval != QLA_SUCCESS) {
1079 /*EMPTY*/
1080 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
1081 ha->host_no, mcp->mb[0]);)
1082 } else {
1083 /* Convert returned data and check our values. */
1084 *r_a_tov = mcp->mb[3] / 2;
1085 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1086 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1087 /* Update to the larger values */
1088 *retry_cnt = (uint8_t)mcp->mb[1];
1089 *tov = ratov;
1092 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
1093 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
1096 return rval;
1100 * qla2x00_init_firmware
1101 * Initialize adapter firmware.
1103 * Input:
1104 * ha = adapter block pointer.
1105 * dptr = Initialization control block pointer.
1106 * size = size of initialization control block.
1107 * TARGET_QUEUE_LOCK must be released.
1108 * ADAPTER_STATE_LOCK must be released.
1110 * Returns:
1111 * qla2x00 local function return status code.
1113 * Context:
1114 * Kernel context.
1117 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1119 int rval;
1120 mbx_cmd_t mc;
1121 mbx_cmd_t *mcp = &mc;
1123 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1124 ha->host_no);)
1126 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1127 mcp->mb[2] = MSW(ha->init_cb_dma);
1128 mcp->mb[3] = LSW(ha->init_cb_dma);
1129 mcp->mb[4] = 0;
1130 mcp->mb[5] = 0;
1131 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1132 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1133 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1134 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1135 mcp->buf_size = size;
1136 mcp->flags = MBX_DMA_OUT;
1137 mcp->tov = 30;
1138 rval = qla2x00_mailbox_command(ha, mcp);
1140 if (rval != QLA_SUCCESS) {
1141 /*EMPTY*/
1142 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1143 "mb0=%x.\n",
1144 ha->host_no, rval, mcp->mb[0]);)
1145 } else {
1146 /*EMPTY*/
1147 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1148 ha->host_no);)
1151 return rval;
1155 * qla2x00_get_port_database
1156 * Issue normal/enhanced get port database mailbox command
1157 * and copy device name as necessary.
1159 * Input:
1160 * ha = adapter state pointer.
1161 * dev = structure pointer.
1162 * opt = enhanced cmd option byte.
1164 * Returns:
1165 * qla2x00 local function return status code.
1167 * Context:
1168 * Kernel context.
1171 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1173 int rval;
1174 mbx_cmd_t mc;
1175 mbx_cmd_t *mcp = &mc;
1176 port_database_t *pd;
1177 struct port_database_24xx *pd24;
1178 dma_addr_t pd_dma;
1180 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1182 pd24 = NULL;
1183 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1184 if (pd == NULL) {
1185 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1186 "structure.\n", __func__, ha->host_no));
1187 return QLA_MEMORY_ALLOC_FAILED;
1189 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1191 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1192 if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA25XX(ha))
1193 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1194 mcp->mb[2] = MSW(pd_dma);
1195 mcp->mb[3] = LSW(pd_dma);
1196 mcp->mb[6] = MSW(MSD(pd_dma));
1197 mcp->mb[7] = LSW(MSD(pd_dma));
1198 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1199 mcp->in_mb = MBX_0;
1200 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1201 mcp->mb[1] = fcport->loop_id;
1202 mcp->mb[10] = opt;
1203 mcp->out_mb |= MBX_10|MBX_1;
1204 mcp->in_mb |= MBX_1;
1205 } else if (HAS_EXTENDED_IDS(ha)) {
1206 mcp->mb[1] = fcport->loop_id;
1207 mcp->mb[10] = opt;
1208 mcp->out_mb |= MBX_10|MBX_1;
1209 } else {
1210 mcp->mb[1] = fcport->loop_id << 8 | opt;
1211 mcp->out_mb |= MBX_1;
1213 mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
1214 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
1215 mcp->flags = MBX_DMA_IN;
1216 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1217 rval = qla2x00_mailbox_command(ha, mcp);
1218 if (rval != QLA_SUCCESS)
1219 goto gpd_error_out;
1221 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1222 pd24 = (struct port_database_24xx *) pd;
1224 /* Check for logged in state. */
1225 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1226 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1227 DEBUG2(printk("%s(%ld): Unable to verify "
1228 "login-state (%x/%x) for loop_id %x\n",
1229 __func__, ha->host_no,
1230 pd24->current_login_state,
1231 pd24->last_login_state, fcport->loop_id));
1232 rval = QLA_FUNCTION_FAILED;
1233 goto gpd_error_out;
1236 /* Names are little-endian. */
1237 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1238 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1240 /* Get port_id of device. */
1241 fcport->d_id.b.domain = pd24->port_id[0];
1242 fcport->d_id.b.area = pd24->port_id[1];
1243 fcport->d_id.b.al_pa = pd24->port_id[2];
1244 fcport->d_id.b.rsvd_1 = 0;
1246 /* If not target must be initiator or unknown type. */
1247 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1248 fcport->port_type = FCT_INITIATOR;
1249 else
1250 fcport->port_type = FCT_TARGET;
1251 } else {
1252 /* Check for logged in state. */
1253 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1254 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1255 rval = QLA_FUNCTION_FAILED;
1256 goto gpd_error_out;
1259 /* Names are little-endian. */
1260 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1261 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1263 /* Get port_id of device. */
1264 fcport->d_id.b.domain = pd->port_id[0];
1265 fcport->d_id.b.area = pd->port_id[3];
1266 fcport->d_id.b.al_pa = pd->port_id[2];
1267 fcport->d_id.b.rsvd_1 = 0;
1269 /* Check for device require authentication. */
1270 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1271 (fcport->flags &= ~FCF_AUTH_REQ);
1273 /* If not target must be initiator or unknown type. */
1274 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1275 fcport->port_type = FCT_INITIATOR;
1276 else
1277 fcport->port_type = FCT_TARGET;
1279 /* Passback COS information. */
1280 fcport->supported_classes = (pd->options & BIT_4) ?
1281 FC_COS_CLASS2: FC_COS_CLASS3;
1284 gpd_error_out:
1285 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1287 if (rval != QLA_SUCCESS) {
1288 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1289 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1290 } else {
1291 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1294 return rval;
1298 * qla2x00_get_firmware_state
1299 * Get adapter firmware state.
1301 * Input:
1302 * ha = adapter block pointer.
1303 * dptr = pointer for firmware state.
1304 * TARGET_QUEUE_LOCK must be released.
1305 * ADAPTER_STATE_LOCK must be released.
1307 * Returns:
1308 * qla2x00 local function return status code.
1310 * Context:
1311 * Kernel context.
1314 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1316 int rval;
1317 mbx_cmd_t mc;
1318 mbx_cmd_t *mcp = &mc;
1320 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1321 ha->host_no);)
1323 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1324 mcp->out_mb = MBX_0;
1325 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1326 mcp->tov = 30;
1327 mcp->flags = 0;
1328 rval = qla2x00_mailbox_command(ha, mcp);
1330 /* Return firmware state. */
1331 *dptr = mcp->mb[1];
1333 if (rval != QLA_SUCCESS) {
1334 /*EMPTY*/
1335 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1336 "failed=%x.\n", ha->host_no, rval);)
1337 } else {
1338 /*EMPTY*/
1339 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1340 ha->host_no);)
1343 return rval;
1347 * qla2x00_get_port_name
1348 * Issue get port name mailbox command.
1349 * Returned name is in big endian format.
1351 * Input:
1352 * ha = adapter block pointer.
1353 * loop_id = loop ID of device.
1354 * name = pointer for name.
1355 * TARGET_QUEUE_LOCK must be released.
1356 * ADAPTER_STATE_LOCK must be released.
1358 * Returns:
1359 * qla2x00 local function return status code.
1361 * Context:
1362 * Kernel context.
1365 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1366 uint8_t opt)
1368 int rval;
1369 mbx_cmd_t mc;
1370 mbx_cmd_t *mcp = &mc;
1372 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1373 ha->host_no);)
1375 mcp->mb[0] = MBC_GET_PORT_NAME;
1376 mcp->out_mb = MBX_1|MBX_0;
1377 if (HAS_EXTENDED_IDS(ha)) {
1378 mcp->mb[1] = loop_id;
1379 mcp->mb[10] = opt;
1380 mcp->out_mb |= MBX_10;
1381 } else {
1382 mcp->mb[1] = loop_id << 8 | opt;
1385 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1386 mcp->tov = 30;
1387 mcp->flags = 0;
1388 rval = qla2x00_mailbox_command(ha, mcp);
1390 if (rval != QLA_SUCCESS) {
1391 /*EMPTY*/
1392 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1393 ha->host_no, rval);)
1394 } else {
1395 if (name != NULL) {
1396 /* This function returns name in big endian. */
1397 name[0] = LSB(mcp->mb[2]);
1398 name[1] = MSB(mcp->mb[2]);
1399 name[2] = LSB(mcp->mb[3]);
1400 name[3] = MSB(mcp->mb[3]);
1401 name[4] = LSB(mcp->mb[6]);
1402 name[5] = MSB(mcp->mb[6]);
1403 name[6] = LSB(mcp->mb[7]);
1404 name[7] = MSB(mcp->mb[7]);
1407 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1408 ha->host_no);)
1411 return rval;
1415 * qla2x00_lip_reset
1416 * Issue LIP reset mailbox command.
1418 * Input:
1419 * ha = adapter block pointer.
1420 * TARGET_QUEUE_LOCK must be released.
1421 * ADAPTER_STATE_LOCK must be released.
1423 * Returns:
1424 * qla2x00 local function return status code.
1426 * Context:
1427 * Kernel context.
1430 qla2x00_lip_reset(scsi_qla_host_t *ha)
1432 int rval;
1433 mbx_cmd_t mc;
1434 mbx_cmd_t *mcp = &mc;
1436 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1438 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1439 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1440 mcp->mb[1] = BIT_0;
1441 mcp->mb[2] = 0xff;
1442 mcp->mb[3] = 0;
1443 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1444 } else {
1445 mcp->mb[0] = MBC_LIP_RESET;
1446 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1447 if (HAS_EXTENDED_IDS(ha)) {
1448 mcp->mb[1] = 0x00ff;
1449 mcp->mb[10] = 0;
1450 mcp->out_mb |= MBX_10;
1451 } else {
1452 mcp->mb[1] = 0xff00;
1454 mcp->mb[2] = ha->loop_reset_delay;
1455 mcp->mb[3] = 0;
1457 mcp->in_mb = MBX_0;
1458 mcp->tov = 30;
1459 mcp->flags = 0;
1460 rval = qla2x00_mailbox_command(ha, mcp);
1462 if (rval != QLA_SUCCESS) {
1463 /*EMPTY*/
1464 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1465 __func__, ha->host_no, rval);)
1466 } else {
1467 /*EMPTY*/
1468 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1471 return rval;
1475 * qla2x00_send_sns
1476 * Send SNS command.
1478 * Input:
1479 * ha = adapter block pointer.
1480 * sns = pointer for command.
1481 * cmd_size = command size.
1482 * buf_size = response/command size.
1483 * TARGET_QUEUE_LOCK must be released.
1484 * ADAPTER_STATE_LOCK must be released.
1486 * Returns:
1487 * qla2x00 local function return status code.
1489 * Context:
1490 * Kernel context.
1493 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1494 uint16_t cmd_size, size_t buf_size)
1496 int rval;
1497 mbx_cmd_t mc;
1498 mbx_cmd_t *mcp = &mc;
1500 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1501 ha->host_no);)
1503 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1504 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1506 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1507 mcp->mb[1] = cmd_size;
1508 mcp->mb[2] = MSW(sns_phys_address);
1509 mcp->mb[3] = LSW(sns_phys_address);
1510 mcp->mb[6] = MSW(MSD(sns_phys_address));
1511 mcp->mb[7] = LSW(MSD(sns_phys_address));
1512 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1513 mcp->in_mb = MBX_0|MBX_1;
1514 mcp->buf_size = buf_size;
1515 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1516 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1517 rval = qla2x00_mailbox_command(ha, mcp);
1519 if (rval != QLA_SUCCESS) {
1520 /*EMPTY*/
1521 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1522 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1523 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1524 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1525 } else {
1526 /*EMPTY*/
1527 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1530 return rval;
1534 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1535 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1537 int rval;
1539 struct logio_entry_24xx *lg;
1540 dma_addr_t lg_dma;
1541 uint32_t iop[2];
1543 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1545 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1546 if (lg == NULL) {
1547 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1548 __func__, ha->host_no));
1549 return QLA_MEMORY_ALLOC_FAILED;
1551 memset(lg, 0, sizeof(struct logio_entry_24xx));
1553 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1554 lg->entry_count = 1;
1555 lg->nport_handle = cpu_to_le16(loop_id);
1556 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1557 if (opt & BIT_0)
1558 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1559 lg->port_id[0] = al_pa;
1560 lg->port_id[1] = area;
1561 lg->port_id[2] = domain;
1562 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1563 if (rval != QLA_SUCCESS) {
1564 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1565 "(%x).\n", __func__, ha->host_no, rval);)
1566 } else if (lg->entry_status != 0) {
1567 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1568 "-- error status (%x).\n", __func__, ha->host_no,
1569 lg->entry_status));
1570 rval = QLA_FUNCTION_FAILED;
1571 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1572 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1573 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1575 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1576 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1577 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1578 iop[1]));
1580 switch (iop[0]) {
1581 case LSC_SCODE_PORTID_USED:
1582 mb[0] = MBS_PORT_ID_USED;
1583 mb[1] = LSW(iop[1]);
1584 break;
1585 case LSC_SCODE_NPORT_USED:
1586 mb[0] = MBS_LOOP_ID_USED;
1587 break;
1588 case LSC_SCODE_NOLINK:
1589 case LSC_SCODE_NOIOCB:
1590 case LSC_SCODE_NOXCB:
1591 case LSC_SCODE_CMD_FAILED:
1592 case LSC_SCODE_NOFABRIC:
1593 case LSC_SCODE_FW_NOT_READY:
1594 case LSC_SCODE_NOT_LOGGED_IN:
1595 case LSC_SCODE_NOPCB:
1596 case LSC_SCODE_ELS_REJECT:
1597 case LSC_SCODE_CMD_PARAM_ERR:
1598 case LSC_SCODE_NONPORT:
1599 case LSC_SCODE_LOGGED_IN:
1600 case LSC_SCODE_NOFLOGI_ACC:
1601 default:
1602 mb[0] = MBS_COMMAND_ERROR;
1603 break;
1605 } else {
1606 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1608 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1610 mb[0] = MBS_COMMAND_COMPLETE;
1611 mb[1] = 0;
1612 if (iop[0] & BIT_4) {
1613 if (iop[0] & BIT_8)
1614 mb[1] |= BIT_1;
1615 } else
1616 mb[1] = BIT_0;
1618 /* Passback COS information. */
1619 mb[10] = 0;
1620 if (lg->io_parameter[7] || lg->io_parameter[8])
1621 mb[10] |= BIT_0; /* Class 2. */
1622 if (lg->io_parameter[9] || lg->io_parameter[10])
1623 mb[10] |= BIT_1; /* Class 3. */
1626 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1628 return rval;
1632 * qla2x00_login_fabric
1633 * Issue login fabric port mailbox command.
1635 * Input:
1636 * ha = adapter block pointer.
1637 * loop_id = device loop ID.
1638 * domain = device domain.
1639 * area = device area.
1640 * al_pa = device AL_PA.
1641 * status = pointer for return status.
1642 * opt = command options.
1643 * TARGET_QUEUE_LOCK must be released.
1644 * ADAPTER_STATE_LOCK must be released.
1646 * Returns:
1647 * qla2x00 local function return status code.
1649 * Context:
1650 * Kernel context.
1653 qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1654 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1656 int rval;
1657 mbx_cmd_t mc;
1658 mbx_cmd_t *mcp = &mc;
1660 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
1662 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1663 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1664 if (HAS_EXTENDED_IDS(ha)) {
1665 mcp->mb[1] = loop_id;
1666 mcp->mb[10] = opt;
1667 mcp->out_mb |= MBX_10;
1668 } else {
1669 mcp->mb[1] = (loop_id << 8) | opt;
1671 mcp->mb[2] = domain;
1672 mcp->mb[3] = area << 8 | al_pa;
1674 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1675 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1676 mcp->flags = 0;
1677 rval = qla2x00_mailbox_command(ha, mcp);
1679 /* Return mailbox statuses. */
1680 if (mb != NULL) {
1681 mb[0] = mcp->mb[0];
1682 mb[1] = mcp->mb[1];
1683 mb[2] = mcp->mb[2];
1684 mb[6] = mcp->mb[6];
1685 mb[7] = mcp->mb[7];
1686 /* COS retrieved from Get-Port-Database mailbox command. */
1687 mb[10] = 0;
1690 if (rval != QLA_SUCCESS) {
1691 /* RLU tmp code: need to change main mailbox_command function to
1692 * return ok even when the mailbox completion value is not
1693 * SUCCESS. The caller needs to be responsible to interpret
1694 * the return values of this mailbox command if we're not
1695 * to change too much of the existing code.
1697 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1698 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1699 mcp->mb[0] == 0x4006)
1700 rval = QLA_SUCCESS;
1702 /*EMPTY*/
1703 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1704 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1705 mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
1706 } else {
1707 /*EMPTY*/
1708 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1709 ha->host_no);)
1712 return rval;
1716 * qla2x00_login_local_device
1717 * Issue login loop port mailbox command.
1719 * Input:
1720 * ha = adapter block pointer.
1721 * loop_id = device loop ID.
1722 * opt = command options.
1724 * Returns:
1725 * Return status code.
1727 * Context:
1728 * Kernel context.
1732 qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
1733 uint16_t *mb_ret, uint8_t opt)
1735 int rval;
1736 mbx_cmd_t mc;
1737 mbx_cmd_t *mcp = &mc;
1739 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1741 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1742 if (HAS_EXTENDED_IDS(ha))
1743 mcp->mb[1] = loop_id;
1744 else
1745 mcp->mb[1] = loop_id << 8;
1746 mcp->mb[2] = opt;
1747 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1748 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1749 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1750 mcp->flags = 0;
1751 rval = qla2x00_mailbox_command(ha, mcp);
1753 /* Return mailbox statuses. */
1754 if (mb_ret != NULL) {
1755 mb_ret[0] = mcp->mb[0];
1756 mb_ret[1] = mcp->mb[1];
1757 mb_ret[6] = mcp->mb[6];
1758 mb_ret[7] = mcp->mb[7];
1761 if (rval != QLA_SUCCESS) {
1762 /* AV tmp code: need to change main mailbox_command function to
1763 * return ok even when the mailbox completion value is not
1764 * SUCCESS. The caller needs to be responsible to interpret
1765 * the return values of this mailbox command if we're not
1766 * to change too much of the existing code.
1768 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1769 rval = QLA_SUCCESS;
1771 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1772 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1773 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1774 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1775 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1776 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1777 } else {
1778 /*EMPTY*/
1779 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1782 return (rval);
1786 qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1787 uint8_t area, uint8_t al_pa)
1789 int rval;
1790 struct logio_entry_24xx *lg;
1791 dma_addr_t lg_dma;
1793 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1795 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1796 if (lg == NULL) {
1797 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1798 __func__, ha->host_no));
1799 return QLA_MEMORY_ALLOC_FAILED;
1801 memset(lg, 0, sizeof(struct logio_entry_24xx));
1803 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1804 lg->entry_count = 1;
1805 lg->nport_handle = cpu_to_le16(loop_id);
1806 lg->control_flags =
1807 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO);
1808 lg->port_id[0] = al_pa;
1809 lg->port_id[1] = area;
1810 lg->port_id[2] = domain;
1811 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1812 if (rval != QLA_SUCCESS) {
1813 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1814 "(%x).\n", __func__, ha->host_no, rval);)
1815 } else if (lg->entry_status != 0) {
1816 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1817 "-- error status (%x).\n", __func__, ha->host_no,
1818 lg->entry_status));
1819 rval = QLA_FUNCTION_FAILED;
1820 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1821 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1822 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1823 ha->host_no, le16_to_cpu(lg->comp_status),
1824 le32_to_cpu(lg->io_parameter[0]),
1825 le32_to_cpu(lg->io_parameter[1]));)
1826 } else {
1827 /*EMPTY*/
1828 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1831 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1833 return rval;
1837 * qla2x00_fabric_logout
1838 * Issue logout fabric port mailbox command.
1840 * Input:
1841 * ha = adapter block pointer.
1842 * loop_id = device loop ID.
1843 * TARGET_QUEUE_LOCK must be released.
1844 * ADAPTER_STATE_LOCK must be released.
1846 * Returns:
1847 * qla2x00 local function return status code.
1849 * Context:
1850 * Kernel context.
1853 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1854 uint8_t area, uint8_t al_pa)
1856 int rval;
1857 mbx_cmd_t mc;
1858 mbx_cmd_t *mcp = &mc;
1860 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1861 ha->host_no);)
1863 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1864 mcp->out_mb = MBX_1|MBX_0;
1865 if (HAS_EXTENDED_IDS(ha)) {
1866 mcp->mb[1] = loop_id;
1867 mcp->mb[10] = 0;
1868 mcp->out_mb |= MBX_10;
1869 } else {
1870 mcp->mb[1] = loop_id << 8;
1873 mcp->in_mb = MBX_1|MBX_0;
1874 mcp->tov = 30;
1875 mcp->flags = 0;
1876 rval = qla2x00_mailbox_command(ha, mcp);
1878 if (rval != QLA_SUCCESS) {
1879 /*EMPTY*/
1880 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1881 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
1882 } else {
1883 /*EMPTY*/
1884 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1885 ha->host_no);)
1888 return rval;
1892 * qla2x00_full_login_lip
1893 * Issue full login LIP mailbox command.
1895 * Input:
1896 * ha = adapter block pointer.
1897 * TARGET_QUEUE_LOCK must be released.
1898 * ADAPTER_STATE_LOCK must be released.
1900 * Returns:
1901 * qla2x00 local function return status code.
1903 * Context:
1904 * Kernel context.
1907 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1909 int rval;
1910 mbx_cmd_t mc;
1911 mbx_cmd_t *mcp = &mc;
1913 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1914 ha->host_no);)
1916 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1917 mcp->mb[1] = 0;
1918 mcp->mb[2] = 0xff;
1919 mcp->mb[3] = 0;
1920 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1921 mcp->in_mb = MBX_0;
1922 mcp->tov = 30;
1923 mcp->flags = 0;
1924 rval = qla2x00_mailbox_command(ha, mcp);
1926 if (rval != QLA_SUCCESS) {
1927 /*EMPTY*/
1928 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1929 ha->host_no, rval);)
1930 } else {
1931 /*EMPTY*/
1932 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1933 ha->host_no);)
1936 return rval;
1940 * qla2x00_get_id_list
1942 * Input:
1943 * ha = adapter block pointer.
1945 * Returns:
1946 * qla2x00 local function return status code.
1948 * Context:
1949 * Kernel context.
1952 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1953 uint16_t *entries)
1955 int rval;
1956 mbx_cmd_t mc;
1957 mbx_cmd_t *mcp = &mc;
1959 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1960 ha->host_no);)
1962 if (id_list == NULL)
1963 return QLA_FUNCTION_FAILED;
1965 mcp->mb[0] = MBC_GET_ID_LIST;
1966 mcp->out_mb = MBX_0;
1967 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1968 mcp->mb[2] = MSW(id_list_dma);
1969 mcp->mb[3] = LSW(id_list_dma);
1970 mcp->mb[6] = MSW(MSD(id_list_dma));
1971 mcp->mb[7] = LSW(MSD(id_list_dma));
1972 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2;
1973 } else {
1974 mcp->mb[1] = MSW(id_list_dma);
1975 mcp->mb[2] = LSW(id_list_dma);
1976 mcp->mb[3] = MSW(MSD(id_list_dma));
1977 mcp->mb[6] = LSW(MSD(id_list_dma));
1978 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1980 mcp->in_mb = MBX_1|MBX_0;
1981 mcp->tov = 30;
1982 mcp->flags = 0;
1983 rval = qla2x00_mailbox_command(ha, mcp);
1985 if (rval != QLA_SUCCESS) {
1986 /*EMPTY*/
1987 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1988 ha->host_no, rval);)
1989 } else {
1990 *entries = mcp->mb[1];
1991 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1992 ha->host_no);)
1995 return rval;
1999 * qla2x00_get_resource_cnts
2000 * Get current firmware resource counts.
2002 * Input:
2003 * ha = adapter block pointer.
2005 * Returns:
2006 * qla2x00 local function return status code.
2008 * Context:
2009 * Kernel context.
2012 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
2013 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
2015 int rval;
2016 mbx_cmd_t mc;
2017 mbx_cmd_t *mcp = &mc;
2019 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2021 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2022 mcp->out_mb = MBX_0;
2023 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2024 mcp->tov = 30;
2025 mcp->flags = 0;
2026 rval = qla2x00_mailbox_command(ha, mcp);
2028 if (rval != QLA_SUCCESS) {
2029 /*EMPTY*/
2030 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
2031 ha->host_no, mcp->mb[0]);)
2032 } else {
2033 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
2034 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
2035 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
2036 mcp->mb[10]));
2038 if (cur_xchg_cnt)
2039 *cur_xchg_cnt = mcp->mb[3];
2040 if (orig_xchg_cnt)
2041 *orig_xchg_cnt = mcp->mb[6];
2042 if (cur_iocb_cnt)
2043 *cur_iocb_cnt = mcp->mb[7];
2044 if (orig_iocb_cnt)
2045 *orig_iocb_cnt = mcp->mb[10];
2048 return (rval);
2051 #if defined(QL_DEBUG_LEVEL_3)
2053 * qla2x00_get_fcal_position_map
2054 * Get FCAL (LILP) position map using mailbox command
2056 * Input:
2057 * ha = adapter state pointer.
2058 * pos_map = buffer pointer (can be NULL).
2060 * Returns:
2061 * qla2x00 local function return status code.
2063 * Context:
2064 * Kernel context.
2067 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
2069 int rval;
2070 mbx_cmd_t mc;
2071 mbx_cmd_t *mcp = &mc;
2072 char *pmap;
2073 dma_addr_t pmap_dma;
2075 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
2076 if (pmap == NULL) {
2077 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
2078 __func__, ha->host_no));
2079 return QLA_MEMORY_ALLOC_FAILED;
2081 memset(pmap, 0, FCAL_MAP_SIZE);
2083 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2084 mcp->mb[2] = MSW(pmap_dma);
2085 mcp->mb[3] = LSW(pmap_dma);
2086 mcp->mb[6] = MSW(MSD(pmap_dma));
2087 mcp->mb[7] = LSW(MSD(pmap_dma));
2088 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2089 mcp->in_mb = MBX_1|MBX_0;
2090 mcp->buf_size = FCAL_MAP_SIZE;
2091 mcp->flags = MBX_DMA_IN;
2092 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2093 rval = qla2x00_mailbox_command(ha, mcp);
2095 if (rval == QLA_SUCCESS) {
2096 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2097 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2098 mcp->mb[1], (unsigned)pmap[0]));
2099 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2101 if (pos_map)
2102 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2104 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2106 if (rval != QLA_SUCCESS) {
2107 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2108 ha->host_no, rval));
2109 } else {
2110 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2113 return rval;
2116 uint8_t
2117 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2118 uint16_t *status)
2120 int rval;
2121 mbx_cmd_t mc;
2122 mbx_cmd_t *mcp = &mc;
2123 uint32_t *sbuf, *siter;
2124 dma_addr_t sbuf_dma;
2126 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2128 if (dwords > (DMA_POOL_SIZE / 4)) {
2129 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2130 "(max %d).\n", __func__, ha->host_no, dwords,
2131 DMA_POOL_SIZE / 4));
2132 return BIT_0;
2134 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2135 if (sbuf == NULL) {
2136 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2137 __func__, ha->host_no));
2138 return BIT_0;
2140 memset(sbuf, 0, DMA_POOL_SIZE);
2142 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2143 mcp->mb[2] = MSW(sbuf_dma);
2144 mcp->mb[3] = LSW(sbuf_dma);
2145 mcp->mb[6] = MSW(MSD(sbuf_dma));
2146 mcp->mb[7] = LSW(MSD(sbuf_dma));
2147 mcp->mb[8] = dwords;
2148 mcp->mb[10] = 0;
2149 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2150 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2151 mcp->tov = 30;
2152 mcp->flags = IOCTL_CMD;
2153 rval = qla2x00_mailbox_command(ha, mcp);
2155 if (rval == QLA_SUCCESS) {
2156 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2157 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2158 __func__, ha->host_no, mcp->mb[0]));
2159 status[0] = mcp->mb[0];
2160 rval = BIT_1;
2161 } else {
2162 /* Copy over data -- firmware data is LE. */
2163 siter = sbuf;
2164 while (dwords--)
2165 *dwbuf++ = le32_to_cpu(*siter++);
2167 } else {
2168 /* Failed. */
2169 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2170 ha->host_no, rval));
2171 rval = BIT_1;
2174 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2176 return rval;
2178 #endif
2181 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2183 int rval;
2184 fc_port_t *fcport;
2185 unsigned long flags = 0;
2187 struct abort_entry_24xx *abt;
2188 dma_addr_t abt_dma;
2189 uint32_t handle;
2191 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2193 fcport = sp->fcport;
2194 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
2195 atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2196 return QLA_FUNCTION_FAILED;
2199 spin_lock_irqsave(&ha->hardware_lock, flags);
2200 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2201 if (ha->outstanding_cmds[handle] == sp)
2202 break;
2204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2205 if (handle == MAX_OUTSTANDING_COMMANDS) {
2206 /* Command not found. */
2207 return QLA_FUNCTION_FAILED;
2210 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2211 if (abt == NULL) {
2212 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2213 __func__, ha->host_no));
2214 return QLA_MEMORY_ALLOC_FAILED;
2216 memset(abt, 0, sizeof(struct abort_entry_24xx));
2218 abt->entry_type = ABORT_IOCB_TYPE;
2219 abt->entry_count = 1;
2220 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2221 abt->handle_to_abort = handle;
2222 abt->port_id[0] = fcport->d_id.b.al_pa;
2223 abt->port_id[1] = fcport->d_id.b.area;
2224 abt->port_id[2] = fcport->d_id.b.domain;
2225 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2226 if (rval != QLA_SUCCESS) {
2227 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2228 __func__, ha->host_no, rval);)
2229 } else if (abt->entry_status != 0) {
2230 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2231 "-- error status (%x).\n", __func__, ha->host_no,
2232 abt->entry_status));
2233 rval = QLA_FUNCTION_FAILED;
2234 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2235 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2236 "-- completion status (%x).\n", __func__, ha->host_no,
2237 le16_to_cpu(abt->nport_handle));)
2238 rval = QLA_FUNCTION_FAILED;
2239 } else {
2240 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2241 sp->flags |= SRB_ABORT_PENDING;
2244 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2246 return rval;
2249 struct tsk_mgmt_cmd {
2250 union {
2251 struct tsk_mgmt_entry tsk;
2252 struct sts_entry_24xx sts;
2253 } p;
2257 qla24xx_abort_target(fc_port_t *fcport)
2259 int rval;
2260 struct tsk_mgmt_cmd *tsk;
2261 dma_addr_t tsk_dma;
2262 scsi_qla_host_t *ha;
2264 if (fcport == NULL)
2265 return 0;
2267 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
2269 ha = fcport->ha;
2270 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2271 if (tsk == NULL) {
2272 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2273 "IOCB.\n", __func__, ha->host_no));
2274 return QLA_MEMORY_ALLOC_FAILED;
2276 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2278 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2279 tsk->p.tsk.entry_count = 1;
2280 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2281 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2282 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2283 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2284 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2285 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2286 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2287 if (rval != QLA_SUCCESS) {
2288 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2289 "(%x).\n", __func__, ha->host_no, rval);)
2290 goto atarget_done;
2291 } else if (tsk->p.sts.entry_status != 0) {
2292 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2293 "-- error status (%x).\n", __func__, ha->host_no,
2294 tsk->p.sts.entry_status));
2295 rval = QLA_FUNCTION_FAILED;
2296 goto atarget_done;
2297 } else if (tsk->p.sts.comp_status !=
2298 __constant_cpu_to_le16(CS_COMPLETE)) {
2299 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2300 "-- completion status (%x).\n", __func__,
2301 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));)
2302 rval = QLA_FUNCTION_FAILED;
2303 goto atarget_done;
2306 /* Issue marker IOCB. */
2307 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2308 if (rval != QLA_SUCCESS) {
2309 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2310 "(%x).\n", __func__, ha->host_no, rval);)
2311 } else {
2312 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2315 atarget_done:
2316 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2318 return rval;
2322 qla2x00_system_error(scsi_qla_host_t *ha)
2324 int rval;
2325 mbx_cmd_t mc;
2326 mbx_cmd_t *mcp = &mc;
2328 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
2329 return QLA_FUNCTION_FAILED;
2331 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2333 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2334 mcp->out_mb = MBX_0;
2335 mcp->in_mb = MBX_0;
2336 mcp->tov = 5;
2337 mcp->flags = 0;
2338 rval = qla2x00_mailbox_command(ha, mcp);
2340 if (rval != QLA_SUCCESS) {
2341 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2342 ha->host_no, rval));
2343 } else {
2344 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2347 return rval;
2351 * qla2x00_get_serdes_params() -
2352 * @ha: HA context
2354 * Returns
2357 qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2358 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2360 int rval;
2361 mbx_cmd_t mc;
2362 mbx_cmd_t *mcp = &mc;
2364 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2366 mcp->mb[0] = MBC_SERDES_PARAMS;
2367 mcp->mb[1] = 0;
2368 mcp->out_mb = MBX_1|MBX_0;
2369 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2370 mcp->tov = 30;
2371 mcp->flags = 0;
2372 rval = qla2x00_mailbox_command(ha, mcp);
2374 if (rval != QLA_SUCCESS) {
2375 /*EMPTY*/
2376 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2377 ha->host_no, rval, mcp->mb[0]));
2378 } else {
2379 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2381 if (sw_em_1g)
2382 *sw_em_1g = mcp->mb[2];
2383 if (sw_em_2g)
2384 *sw_em_2g = mcp->mb[3];
2385 if (sw_em_4g)
2386 *sw_em_4g = mcp->mb[4];
2389 return rval;
2393 * qla2x00_set_serdes_params() -
2394 * @ha: HA context
2396 * Returns
2399 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2400 uint16_t sw_em_2g, uint16_t sw_em_4g)
2402 int rval;
2403 mbx_cmd_t mc;
2404 mbx_cmd_t *mcp = &mc;
2406 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2408 mcp->mb[0] = MBC_SERDES_PARAMS;
2409 mcp->mb[1] = BIT_0;
2410 mcp->mb[2] = sw_em_1g;
2411 mcp->mb[3] = sw_em_2g;
2412 mcp->mb[4] = sw_em_4g;
2413 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2414 mcp->in_mb = MBX_0;
2415 mcp->tov = 30;
2416 mcp->flags = 0;
2417 rval = qla2x00_mailbox_command(ha, mcp);
2419 if (rval != QLA_SUCCESS) {
2420 /*EMPTY*/
2421 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2422 ha->host_no, rval, mcp->mb[0]));
2423 } else {
2424 /*EMPTY*/
2425 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2428 return rval;
2432 qla2x00_stop_firmware(scsi_qla_host_t *ha)
2434 int rval;
2435 mbx_cmd_t mc;
2436 mbx_cmd_t *mcp = &mc;
2438 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
2439 return QLA_FUNCTION_FAILED;
2441 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2443 mcp->mb[0] = MBC_STOP_FIRMWARE;
2444 mcp->out_mb = MBX_0;
2445 mcp->in_mb = MBX_0;
2446 mcp->tov = 5;
2447 mcp->flags = 0;
2448 rval = qla2x00_mailbox_command(ha, mcp);
2450 if (rval != QLA_SUCCESS) {
2451 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2452 ha->host_no, rval));
2453 } else {
2454 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2457 return rval;