[PATCH] ep93xx build fix
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / qla2xxx / qla_mbx.c
blobd6cb3bd1a29a4b0277e47c97287730a3b11255b5
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 *ha, mbx_cmd_t *mcp)
47 int rval;
48 unsigned long flags = 0;
49 device_reg_t __iomem *reg = ha->iobase;
50 struct timer_list tmp_intr_timer;
51 uint8_t abort_active;
52 uint8_t io_lock_on = ha->flags.init_done;
53 uint16_t command;
54 uint16_t *iptr;
55 uint16_t __iomem *optr;
56 uint32_t cnt;
57 uint32_t mboxes;
58 unsigned long mbx_flags = 0;
59 unsigned long wait_time;
61 rval = QLA_SUCCESS;
62 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
64 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
67 * Wait for active mailbox commands to finish by waiting at most tov
68 * seconds. This is to serialize actual issuing of mailbox cmds during
69 * non ISP abort time.
71 if (!abort_active) {
72 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
73 /* Timeout occurred. Return error. */
74 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
75 "Exiting.\n", __func__, ha->host_no);)
76 return QLA_FUNCTION_TIMEOUT;
80 ha->flags.mbox_busy = 1;
81 /* Save mailbox command for debug */
82 ha->mcp = mcp;
84 /* Try to get mailbox register access */
85 if (!abort_active)
86 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
88 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
89 ha->host_no, mcp->mb[0]);)
91 spin_lock_irqsave(&ha->hardware_lock, flags);
93 /* Load mailbox registers. */
94 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
95 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
96 else
97 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
99 iptr = mcp->mb;
100 command = mcp->mb[0];
101 mboxes = mcp->out_mb;
103 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
104 if (IS_QLA2200(ha) && cnt == 8)
105 optr =
106 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
107 if (mboxes & BIT_0)
108 WRT_REG_WORD(optr, *iptr);
110 mboxes >>= 1;
111 optr++;
112 iptr++;
115 #if defined(QL_DEBUG_LEVEL_1)
116 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
117 __func__, ha->host_no);
118 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
119 printk("\n");
120 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
121 printk("\n");
122 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
123 printk("\n");
124 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
125 qla2x00_dump_regs(ha);
126 #endif
128 /* Issue set host interrupt command to send cmd out. */
129 ha->flags.mbox_int = 0;
130 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
132 /* Unlock mbx registers and wait for interrupt */
133 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
134 "jiffies=%lx.\n", __func__, ha->host_no, jiffies);)
136 /* Wait for mbx cmd completion until timeout */
138 if (!abort_active && io_lock_on) {
139 /* sleep on completion semaphore */
140 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
141 __func__, ha->host_no);)
143 init_timer(&tmp_intr_timer);
144 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
145 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
146 tmp_intr_timer.function =
147 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
149 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
150 ha->host_no);)
151 add_timer(&tmp_intr_timer);
153 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
154 "time=0x%lx.\n", __func__, ha->host_no, jiffies);)
156 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
158 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
159 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
160 else
161 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
162 spin_unlock_irqrestore(&ha->hardware_lock, flags);
164 if (!abort_active)
165 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
167 /* Wait for either the timer to expire
168 * or the mbox completion interrupt
170 down(&ha->mbx_intr_sem);
172 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
173 ha->host_no, jiffies);)
174 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
176 /* delete the timer */
177 del_timer(&tmp_intr_timer);
178 } else {
179 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
180 ha->host_no, command);)
182 if (IS_QLA24XX(ha) || IS_QLA54XX(ha))
183 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
184 else
185 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
186 spin_unlock_irqrestore(&ha->hardware_lock, flags);
187 if (!abort_active)
188 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
190 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
191 while (!ha->flags.mbox_int) {
192 if (time_after(jiffies, wait_time))
193 break;
195 /* Check for pending interrupts. */
196 qla2x00_poll(ha);
198 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
199 !ha->flags.mbox_int)
200 msleep(10);
201 } /* while */
204 if (!abort_active)
205 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
207 /* Check whether we timed out */
208 if (ha->flags.mbox_int) {
209 uint16_t *iptr2;
211 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
212 ha->host_no, command);)
214 /* Got interrupt. Clear the flag. */
215 ha->flags.mbox_int = 0;
216 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
218 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
219 rval = QLA_FUNCTION_FAILED;
221 /* Load return mailbox registers. */
222 iptr2 = mcp->mb;
223 iptr = (uint16_t *)&ha->mailbox_out[0];
224 mboxes = mcp->in_mb;
225 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
226 if (mboxes & BIT_0)
227 *iptr2 = *iptr;
229 mboxes >>= 1;
230 iptr2++;
231 iptr++;
233 } else {
235 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
236 defined(QL_DEBUG_LEVEL_11)
237 uint16_t mb0;
238 uint32_t ictrl;
240 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
241 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
242 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
243 } else {
244 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
245 ictrl = RD_REG_WORD(&reg->isp.ictrl);
247 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
248 __func__, ha->host_no, command);
249 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
250 ha->host_no, ictrl, jiffies);
251 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
252 ha->host_no, mb0);
253 qla2x00_dump_regs(ha);
254 #endif
256 rval = QLA_FUNCTION_TIMEOUT;
259 if (!abort_active)
260 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
262 ha->flags.mbox_busy = 0;
264 /* Clean up */
265 ha->mcp = NULL;
267 if (!abort_active) {
268 DEBUG11(printk("%s(%ld): checking for additional resp "
269 "interrupt.\n", __func__, ha->host_no);)
271 /* polling mode for non isp_abort commands. */
272 qla2x00_poll(ha);
275 if (rval == QLA_FUNCTION_TIMEOUT &&
276 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
277 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
278 /* not in dpc. schedule it for dpc to take over. */
279 DEBUG(printk("%s(%ld): timeout schedule "
280 "isp_abort_needed.\n", __func__, ha->host_no);)
281 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
282 "isp_abort_needed.\n", __func__, ha->host_no);)
283 qla_printk(KERN_WARNING, ha,
284 "Mailbox command timeout occured. Scheduling ISP "
285 "abort.\n");
286 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
287 qla2xxx_wake_dpc(ha);
288 } else if (!abort_active) {
289 /* call abort directly since we are in the DPC thread */
290 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
291 __func__, ha->host_no);)
292 DEBUG2_3_11(printk("%s(%ld): timeout calling "
293 "abort_isp\n", __func__, ha->host_no);)
294 qla_printk(KERN_WARNING, ha,
295 "Mailbox command timeout occured. Issuing ISP "
296 "abort.\n");
298 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
299 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
300 if (qla2x00_abort_isp(ha)) {
301 /* Failed. retry later. */
302 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
304 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
305 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
306 ha->host_no);)
307 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
308 __func__, ha->host_no);)
312 /* Allow next mbx cmd to come in. */
313 if (!abort_active)
314 up(&ha->mbx_cmd_sem);
316 if (rval) {
317 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
318 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
319 mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
320 } else {
321 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
324 return rval;
328 qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
329 uint32_t risc_code_size)
331 int rval;
332 mbx_cmd_t mc;
333 mbx_cmd_t *mcp = &mc;
335 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
337 if (MSW(risc_addr) || IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
338 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
339 mcp->mb[8] = MSW(risc_addr);
340 mcp->out_mb = MBX_8|MBX_0;
341 } else {
342 mcp->mb[0] = MBC_LOAD_RISC_RAM;
343 mcp->out_mb = MBX_0;
345 mcp->mb[1] = LSW(risc_addr);
346 mcp->mb[2] = MSW(req_dma);
347 mcp->mb[3] = LSW(req_dma);
348 mcp->mb[6] = MSW(MSD(req_dma));
349 mcp->mb[7] = LSW(MSD(req_dma));
350 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
351 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
352 mcp->mb[4] = MSW(risc_code_size);
353 mcp->mb[5] = LSW(risc_code_size);
354 mcp->out_mb |= MBX_5|MBX_4;
355 } else {
356 mcp->mb[4] = LSW(risc_code_size);
357 mcp->out_mb |= MBX_4;
360 mcp->in_mb = MBX_0;
361 mcp->tov = 30;
362 mcp->flags = 0;
363 rval = qla2x00_mailbox_command(ha, mcp);
365 if (rval != QLA_SUCCESS) {
366 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
367 ha->host_no, rval, mcp->mb[0]));
368 } else {
369 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
372 return rval;
376 * qla2x00_execute_fw
377 * Start adapter firmware.
379 * Input:
380 * ha = adapter block pointer.
381 * TARGET_QUEUE_LOCK must be released.
382 * ADAPTER_STATE_LOCK must be released.
384 * Returns:
385 * qla2x00 local function return status code.
387 * Context:
388 * Kernel context.
391 qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
393 int rval;
394 mbx_cmd_t mc;
395 mbx_cmd_t *mcp = &mc;
397 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
399 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
400 mcp->out_mb = MBX_0;
401 mcp->in_mb = MBX_0;
402 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
403 mcp->mb[1] = MSW(risc_addr);
404 mcp->mb[2] = LSW(risc_addr);
405 mcp->mb[3] = 0;
406 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
407 mcp->in_mb |= MBX_1;
408 } else {
409 mcp->mb[1] = LSW(risc_addr);
410 mcp->out_mb |= MBX_1;
411 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
412 mcp->mb[2] = 0;
413 mcp->out_mb |= MBX_2;
417 mcp->tov = 30;
418 mcp->flags = 0;
419 rval = qla2x00_mailbox_command(ha, mcp);
421 if (rval != QLA_SUCCESS) {
422 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
423 ha->host_no, rval, mcp->mb[0]));
424 } else {
425 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
426 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
427 __func__, ha->host_no, mcp->mb[1]);)
428 } else {
429 DEBUG11(printk("%s(%ld): done.\n", __func__,
430 ha->host_no);)
434 return rval;
438 * qla2x00_get_fw_version
439 * Get firmware version.
441 * Input:
442 * ha: adapter state pointer.
443 * major: pointer for major number.
444 * minor: pointer for minor number.
445 * subminor: pointer for subminor number.
447 * Returns:
448 * qla2x00 local function return status code.
450 * Context:
451 * Kernel context.
453 void
454 qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
455 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
457 int rval;
458 mbx_cmd_t mc;
459 mbx_cmd_t *mcp = &mc;
461 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
463 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
464 mcp->out_mb = MBX_0;
465 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
466 mcp->flags = 0;
467 mcp->tov = 30;
468 rval = qla2x00_mailbox_command(ha, mcp);
470 /* Return mailbox data. */
471 *major = mcp->mb[1];
472 *minor = mcp->mb[2];
473 *subminor = mcp->mb[3];
474 *attributes = mcp->mb[6];
475 if (IS_QLA2100(ha) || IS_QLA2200(ha))
476 *memory = 0x1FFFF; /* Defaults to 128KB. */
477 else
478 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
480 if (rval != QLA_SUCCESS) {
481 /*EMPTY*/
482 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
483 ha->host_no, rval));
484 } else {
485 /*EMPTY*/
486 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
491 * qla2x00_get_fw_options
492 * Set firmware options.
494 * Input:
495 * ha = adapter block pointer.
496 * fwopt = pointer for firmware options.
498 * Returns:
499 * qla2x00 local function return status code.
501 * Context:
502 * Kernel context.
505 qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
507 int rval;
508 mbx_cmd_t mc;
509 mbx_cmd_t *mcp = &mc;
511 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
513 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
514 mcp->out_mb = MBX_0;
515 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
516 mcp->tov = 30;
517 mcp->flags = 0;
518 rval = qla2x00_mailbox_command(ha, mcp);
520 if (rval != QLA_SUCCESS) {
521 /*EMPTY*/
522 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
523 ha->host_no, rval));
524 } else {
525 fwopts[0] = mcp->mb[0];
526 fwopts[1] = mcp->mb[1];
527 fwopts[2] = mcp->mb[2];
528 fwopts[3] = mcp->mb[3];
530 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
533 return rval;
538 * qla2x00_set_fw_options
539 * Set firmware options.
541 * Input:
542 * ha = adapter block pointer.
543 * fwopt = pointer for firmware options.
545 * Returns:
546 * qla2x00 local function return status code.
548 * Context:
549 * Kernel context.
552 qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
554 int rval;
555 mbx_cmd_t mc;
556 mbx_cmd_t *mcp = &mc;
558 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
560 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
561 mcp->mb[1] = fwopts[1];
562 mcp->mb[2] = fwopts[2];
563 mcp->mb[3] = fwopts[3];
564 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
565 mcp->in_mb = MBX_0;
566 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
567 mcp->in_mb |= MBX_1;
568 } else {
569 mcp->mb[10] = fwopts[10];
570 mcp->mb[11] = fwopts[11];
571 mcp->mb[12] = 0; /* Undocumented, but used */
572 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
574 mcp->tov = 30;
575 mcp->flags = 0;
576 rval = qla2x00_mailbox_command(ha, mcp);
578 fwopts[0] = mcp->mb[0];
580 if (rval != QLA_SUCCESS) {
581 /*EMPTY*/
582 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
583 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
584 } else {
585 /*EMPTY*/
586 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
589 return rval;
593 * qla2x00_mbx_reg_test
594 * Mailbox register wrap test.
596 * Input:
597 * ha = adapter block pointer.
598 * TARGET_QUEUE_LOCK must be released.
599 * ADAPTER_STATE_LOCK must be released.
601 * Returns:
602 * qla2x00 local function return status code.
604 * Context:
605 * Kernel context.
608 qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
610 int rval;
611 mbx_cmd_t mc;
612 mbx_cmd_t *mcp = &mc;
614 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
616 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
617 mcp->mb[1] = 0xAAAA;
618 mcp->mb[2] = 0x5555;
619 mcp->mb[3] = 0xAA55;
620 mcp->mb[4] = 0x55AA;
621 mcp->mb[5] = 0xA5A5;
622 mcp->mb[6] = 0x5A5A;
623 mcp->mb[7] = 0x2525;
624 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
625 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
626 mcp->tov = 30;
627 mcp->flags = 0;
628 rval = qla2x00_mailbox_command(ha, mcp);
630 if (rval == QLA_SUCCESS) {
631 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
632 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
633 rval = QLA_FUNCTION_FAILED;
634 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
635 mcp->mb[7] != 0x2525)
636 rval = QLA_FUNCTION_FAILED;
639 if (rval != QLA_SUCCESS) {
640 /*EMPTY*/
641 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
642 ha->host_no, rval);)
643 } else {
644 /*EMPTY*/
645 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
646 ha->host_no);)
649 return rval;
653 * qla2x00_verify_checksum
654 * Verify firmware checksum.
656 * Input:
657 * ha = adapter block pointer.
658 * TARGET_QUEUE_LOCK must be released.
659 * ADAPTER_STATE_LOCK must be released.
661 * Returns:
662 * qla2x00 local function return status code.
664 * Context:
665 * Kernel context.
668 qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
670 int rval;
671 mbx_cmd_t mc;
672 mbx_cmd_t *mcp = &mc;
674 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
676 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
677 mcp->out_mb = MBX_0;
678 mcp->in_mb = MBX_0;
679 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
680 mcp->mb[1] = MSW(risc_addr);
681 mcp->mb[2] = LSW(risc_addr);
682 mcp->out_mb |= MBX_2|MBX_1;
683 mcp->in_mb |= MBX_2|MBX_1;
684 } else {
685 mcp->mb[1] = LSW(risc_addr);
686 mcp->out_mb |= MBX_1;
687 mcp->in_mb |= MBX_1;
690 mcp->tov = 30;
691 mcp->flags = 0;
692 rval = qla2x00_mailbox_command(ha, mcp);
694 if (rval != QLA_SUCCESS) {
695 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
696 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
697 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));)
698 } else {
699 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
702 return rval;
706 * qla2x00_issue_iocb
707 * Issue IOCB using mailbox command
709 * Input:
710 * ha = adapter state pointer.
711 * buffer = buffer pointer.
712 * phys_addr = physical address of buffer.
713 * size = size of buffer.
714 * TARGET_QUEUE_LOCK must be released.
715 * ADAPTER_STATE_LOCK must be released.
717 * Returns:
718 * qla2x00 local function return status code.
720 * Context:
721 * Kernel context.
724 qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
725 size_t size)
727 int rval;
728 mbx_cmd_t mc;
729 mbx_cmd_t *mcp = &mc;
731 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
732 mcp->mb[1] = 0;
733 mcp->mb[2] = MSW(phys_addr);
734 mcp->mb[3] = LSW(phys_addr);
735 mcp->mb[6] = MSW(MSD(phys_addr));
736 mcp->mb[7] = LSW(MSD(phys_addr));
737 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
738 mcp->in_mb = MBX_2|MBX_0;
739 mcp->tov = 30;
740 mcp->flags = 0;
741 rval = qla2x00_mailbox_command(ha, mcp);
743 if (rval != QLA_SUCCESS) {
744 /*EMPTY*/
745 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
746 ha->host_no, rval);)
747 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
748 ha->host_no, rval);)
749 } else {
750 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
752 /* Mask reserved bits. */
753 sts_entry->entry_status &=
754 IS_QLA24XX(ha) || IS_QLA54XX(ha) ? RF_MASK_24XX :RF_MASK;
757 return rval;
761 * qla2x00_abort_command
762 * Abort command aborts a specified IOCB.
764 * Input:
765 * ha = adapter block pointer.
766 * sp = SB structure pointer.
768 * Returns:
769 * qla2x00 local function return status code.
771 * Context:
772 * Kernel context.
775 qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
777 unsigned long flags = 0;
778 fc_port_t *fcport;
779 int rval;
780 uint32_t handle;
781 mbx_cmd_t mc;
782 mbx_cmd_t *mcp = &mc;
784 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
786 fcport = sp->fcport;
788 spin_lock_irqsave(&ha->hardware_lock, flags);
789 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
790 if (ha->outstanding_cmds[handle] == sp)
791 break;
793 spin_unlock_irqrestore(&ha->hardware_lock, flags);
795 if (handle == MAX_OUTSTANDING_COMMANDS) {
796 /* command not found */
797 return QLA_FUNCTION_FAILED;
800 mcp->mb[0] = MBC_ABORT_COMMAND;
801 if (HAS_EXTENDED_IDS(ha))
802 mcp->mb[1] = fcport->loop_id;
803 else
804 mcp->mb[1] = fcport->loop_id << 8;
805 mcp->mb[2] = (uint16_t)handle;
806 mcp->mb[3] = (uint16_t)(handle >> 16);
807 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
808 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
809 mcp->in_mb = MBX_0;
810 mcp->tov = 30;
811 mcp->flags = 0;
812 rval = qla2x00_mailbox_command(ha, mcp);
814 if (rval != QLA_SUCCESS) {
815 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
816 ha->host_no, rval);)
817 } else {
818 sp->flags |= SRB_ABORT_PENDING;
819 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
820 ha->host_no);)
823 return rval;
826 #if USE_ABORT_TGT
828 * qla2x00_abort_target
829 * Issue abort target mailbox command.
831 * Input:
832 * ha = adapter block pointer.
834 * Returns:
835 * qla2x00 local function return status code.
837 * Context:
838 * Kernel context.
841 qla2x00_abort_target(fc_port_t *fcport)
843 int rval;
844 mbx_cmd_t mc;
845 mbx_cmd_t *mcp = &mc;
846 scsi_qla_host_t *ha;
848 if (fcport == NULL)
849 return 0;
851 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
853 ha = fcport->ha;
854 mcp->mb[0] = MBC_ABORT_TARGET;
855 mcp->out_mb = MBX_2|MBX_1|MBX_0;
856 if (HAS_EXTENDED_IDS(ha)) {
857 mcp->mb[1] = fcport->loop_id;
858 mcp->mb[10] = 0;
859 mcp->out_mb |= MBX_10;
860 } else {
861 mcp->mb[1] = fcport->loop_id << 8;
863 mcp->mb[2] = ha->loop_reset_delay;
865 mcp->in_mb = MBX_0;
866 mcp->tov = 30;
867 mcp->flags = 0;
868 rval = qla2x00_mailbox_command(ha, mcp);
870 /* Issue marker command. */
871 ha->marker_needed = 1;
873 if (rval != QLA_SUCCESS) {
874 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
875 ha->host_no, rval);)
876 } else {
877 /*EMPTY*/
878 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
879 ha->host_no);)
882 return rval;
884 #endif
887 * qla2x00_get_adapter_id
888 * Get adapter ID and topology.
890 * Input:
891 * ha = adapter block pointer.
892 * id = pointer for loop ID.
893 * al_pa = pointer for AL_PA.
894 * area = pointer for area.
895 * domain = pointer for domain.
896 * top = pointer for topology.
897 * TARGET_QUEUE_LOCK must be released.
898 * ADAPTER_STATE_LOCK must be released.
900 * Returns:
901 * qla2x00 local function return status code.
903 * Context:
904 * Kernel context.
907 qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
908 uint8_t *area, uint8_t *domain, uint16_t *top)
910 int rval;
911 mbx_cmd_t mc;
912 mbx_cmd_t *mcp = &mc;
914 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
915 ha->host_no);)
917 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
918 mcp->out_mb = MBX_0;
919 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
920 mcp->tov = 30;
921 mcp->flags = 0;
922 rval = qla2x00_mailbox_command(ha, mcp);
923 if (mcp->mb[0] == MBS_COMMAND_ERROR)
924 rval = QLA_COMMAND_ERROR;
926 /* Return data. */
927 *id = mcp->mb[1];
928 *al_pa = LSB(mcp->mb[2]);
929 *area = MSB(mcp->mb[2]);
930 *domain = LSB(mcp->mb[3]);
931 *top = mcp->mb[6];
933 if (rval != QLA_SUCCESS) {
934 /*EMPTY*/
935 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
936 ha->host_no, rval);)
937 } else {
938 /*EMPTY*/
939 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
940 ha->host_no);)
943 return rval;
947 * qla2x00_get_retry_cnt
948 * Get current firmware login retry count and delay.
950 * Input:
951 * ha = adapter block pointer.
952 * retry_cnt = pointer to login retry count.
953 * tov = pointer to login timeout value.
955 * Returns:
956 * qla2x00 local function return status code.
958 * Context:
959 * Kernel context.
962 qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
963 uint16_t *r_a_tov)
965 int rval;
966 uint16_t ratov;
967 mbx_cmd_t mc;
968 mbx_cmd_t *mcp = &mc;
970 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
971 ha->host_no);)
973 mcp->mb[0] = MBC_GET_RETRY_COUNT;
974 mcp->out_mb = MBX_0;
975 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
976 mcp->tov = 30;
977 mcp->flags = 0;
978 rval = qla2x00_mailbox_command(ha, mcp);
980 if (rval != QLA_SUCCESS) {
981 /*EMPTY*/
982 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
983 ha->host_no, mcp->mb[0]);)
984 } else {
985 /* Convert returned data and check our values. */
986 *r_a_tov = mcp->mb[3] / 2;
987 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
988 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
989 /* Update to the larger values */
990 *retry_cnt = (uint8_t)mcp->mb[1];
991 *tov = ratov;
994 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
995 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
998 return rval;
1002 * qla2x00_init_firmware
1003 * Initialize adapter firmware.
1005 * Input:
1006 * ha = adapter block pointer.
1007 * dptr = Initialization control block pointer.
1008 * size = size of initialization control block.
1009 * TARGET_QUEUE_LOCK must be released.
1010 * ADAPTER_STATE_LOCK must be released.
1012 * Returns:
1013 * qla2x00 local function return status code.
1015 * Context:
1016 * Kernel context.
1019 qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1021 int rval;
1022 mbx_cmd_t mc;
1023 mbx_cmd_t *mcp = &mc;
1025 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1026 ha->host_no);)
1028 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1029 mcp->mb[2] = MSW(ha->init_cb_dma);
1030 mcp->mb[3] = LSW(ha->init_cb_dma);
1031 mcp->mb[4] = 0;
1032 mcp->mb[5] = 0;
1033 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1034 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1035 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1036 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1037 mcp->buf_size = size;
1038 mcp->flags = MBX_DMA_OUT;
1039 mcp->tov = 30;
1040 rval = qla2x00_mailbox_command(ha, mcp);
1042 if (rval != QLA_SUCCESS) {
1043 /*EMPTY*/
1044 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1045 "mb0=%x.\n",
1046 ha->host_no, rval, mcp->mb[0]);)
1047 } else {
1048 /*EMPTY*/
1049 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1050 ha->host_no);)
1053 return rval;
1057 * qla2x00_get_port_database
1058 * Issue normal/enhanced get port database mailbox command
1059 * and copy device name as necessary.
1061 * Input:
1062 * ha = adapter state pointer.
1063 * dev = structure pointer.
1064 * opt = enhanced cmd option byte.
1066 * Returns:
1067 * qla2x00 local function return status code.
1069 * Context:
1070 * Kernel context.
1073 qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1075 int rval;
1076 mbx_cmd_t mc;
1077 mbx_cmd_t *mcp = &mc;
1078 port_database_t *pd;
1079 struct port_database_24xx *pd24;
1080 dma_addr_t pd_dma;
1082 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1084 pd24 = NULL;
1085 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1086 if (pd == NULL) {
1087 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1088 "structure.\n", __func__, ha->host_no));
1089 return QLA_MEMORY_ALLOC_FAILED;
1091 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1093 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1094 if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA54XX(ha))
1095 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1096 mcp->mb[2] = MSW(pd_dma);
1097 mcp->mb[3] = LSW(pd_dma);
1098 mcp->mb[6] = MSW(MSD(pd_dma));
1099 mcp->mb[7] = LSW(MSD(pd_dma));
1100 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1101 mcp->in_mb = MBX_0;
1102 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1103 mcp->mb[1] = fcport->loop_id;
1104 mcp->mb[10] = opt;
1105 mcp->out_mb |= MBX_10|MBX_1;
1106 mcp->in_mb |= MBX_1;
1107 } else if (HAS_EXTENDED_IDS(ha)) {
1108 mcp->mb[1] = fcport->loop_id;
1109 mcp->mb[10] = opt;
1110 mcp->out_mb |= MBX_10|MBX_1;
1111 } else {
1112 mcp->mb[1] = fcport->loop_id << 8 | opt;
1113 mcp->out_mb |= MBX_1;
1115 mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA54XX(ha) ?
1116 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
1117 mcp->flags = MBX_DMA_IN;
1118 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1119 rval = qla2x00_mailbox_command(ha, mcp);
1120 if (rval != QLA_SUCCESS)
1121 goto gpd_error_out;
1123 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1124 pd24 = (struct port_database_24xx *) pd;
1126 /* Check for logged in state. */
1127 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1128 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1129 DEBUG2(printk("%s(%ld): Unable to verify "
1130 "login-state (%x/%x) for loop_id %x\n",
1131 __func__, ha->host_no,
1132 pd24->current_login_state,
1133 pd24->last_login_state, fcport->loop_id));
1134 rval = QLA_FUNCTION_FAILED;
1135 goto gpd_error_out;
1138 /* Names are little-endian. */
1139 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1140 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1142 /* Get port_id of device. */
1143 fcport->d_id.b.domain = pd24->port_id[0];
1144 fcport->d_id.b.area = pd24->port_id[1];
1145 fcport->d_id.b.al_pa = pd24->port_id[2];
1146 fcport->d_id.b.rsvd_1 = 0;
1148 /* If not target must be initiator or unknown type. */
1149 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1150 fcport->port_type = FCT_INITIATOR;
1151 else
1152 fcport->port_type = FCT_TARGET;
1153 } else {
1154 /* Check for logged in state. */
1155 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1156 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1157 rval = QLA_FUNCTION_FAILED;
1158 goto gpd_error_out;
1161 /* Names are little-endian. */
1162 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1163 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1165 /* Get port_id of device. */
1166 fcport->d_id.b.domain = pd->port_id[0];
1167 fcport->d_id.b.area = pd->port_id[3];
1168 fcport->d_id.b.al_pa = pd->port_id[2];
1169 fcport->d_id.b.rsvd_1 = 0;
1171 /* Check for device require authentication. */
1172 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1173 (fcport->flags &= ~FCF_AUTH_REQ);
1175 /* If not target must be initiator or unknown type. */
1176 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1177 fcport->port_type = FCT_INITIATOR;
1178 else
1179 fcport->port_type = FCT_TARGET;
1181 /* Passback COS information. */
1182 fcport->supported_classes = (pd->options & BIT_4) ?
1183 FC_COS_CLASS2: FC_COS_CLASS3;
1186 gpd_error_out:
1187 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1189 if (rval != QLA_SUCCESS) {
1190 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1191 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1192 } else {
1193 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1196 return rval;
1200 * qla2x00_get_firmware_state
1201 * Get adapter firmware state.
1203 * Input:
1204 * ha = adapter block pointer.
1205 * dptr = pointer for firmware state.
1206 * TARGET_QUEUE_LOCK must be released.
1207 * ADAPTER_STATE_LOCK must be released.
1209 * Returns:
1210 * qla2x00 local function return status code.
1212 * Context:
1213 * Kernel context.
1216 qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1218 int rval;
1219 mbx_cmd_t mc;
1220 mbx_cmd_t *mcp = &mc;
1222 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1223 ha->host_no);)
1225 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1226 mcp->out_mb = MBX_0;
1227 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1228 mcp->tov = 30;
1229 mcp->flags = 0;
1230 rval = qla2x00_mailbox_command(ha, mcp);
1232 /* Return firmware state. */
1233 *dptr = mcp->mb[1];
1235 if (rval != QLA_SUCCESS) {
1236 /*EMPTY*/
1237 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1238 "failed=%x.\n", ha->host_no, rval);)
1239 } else {
1240 /*EMPTY*/
1241 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1242 ha->host_no);)
1245 return rval;
1249 * qla2x00_get_port_name
1250 * Issue get port name mailbox command.
1251 * Returned name is in big endian format.
1253 * Input:
1254 * ha = adapter block pointer.
1255 * loop_id = loop ID of device.
1256 * name = pointer for name.
1257 * TARGET_QUEUE_LOCK must be released.
1258 * ADAPTER_STATE_LOCK must be released.
1260 * Returns:
1261 * qla2x00 local function return status code.
1263 * Context:
1264 * Kernel context.
1267 qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1268 uint8_t opt)
1270 int rval;
1271 mbx_cmd_t mc;
1272 mbx_cmd_t *mcp = &mc;
1274 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1275 ha->host_no);)
1277 mcp->mb[0] = MBC_GET_PORT_NAME;
1278 mcp->out_mb = MBX_1|MBX_0;
1279 if (HAS_EXTENDED_IDS(ha)) {
1280 mcp->mb[1] = loop_id;
1281 mcp->mb[10] = opt;
1282 mcp->out_mb |= MBX_10;
1283 } else {
1284 mcp->mb[1] = loop_id << 8 | opt;
1287 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1288 mcp->tov = 30;
1289 mcp->flags = 0;
1290 rval = qla2x00_mailbox_command(ha, mcp);
1292 if (rval != QLA_SUCCESS) {
1293 /*EMPTY*/
1294 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1295 ha->host_no, rval);)
1296 } else {
1297 if (name != NULL) {
1298 /* This function returns name in big endian. */
1299 name[0] = LSB(mcp->mb[2]);
1300 name[1] = MSB(mcp->mb[2]);
1301 name[2] = LSB(mcp->mb[3]);
1302 name[3] = MSB(mcp->mb[3]);
1303 name[4] = LSB(mcp->mb[6]);
1304 name[5] = MSB(mcp->mb[6]);
1305 name[6] = LSB(mcp->mb[7]);
1306 name[7] = MSB(mcp->mb[7]);
1309 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1310 ha->host_no);)
1313 return rval;
1317 * qla2x00_lip_reset
1318 * Issue LIP reset mailbox command.
1320 * Input:
1321 * ha = adapter block pointer.
1322 * TARGET_QUEUE_LOCK must be released.
1323 * ADAPTER_STATE_LOCK must be released.
1325 * Returns:
1326 * qla2x00 local function return status code.
1328 * Context:
1329 * Kernel context.
1332 qla2x00_lip_reset(scsi_qla_host_t *ha)
1334 int rval;
1335 mbx_cmd_t mc;
1336 mbx_cmd_t *mcp = &mc;
1338 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1340 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1341 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1342 mcp->mb[1] = BIT_0;
1343 mcp->mb[2] = 0xff;
1344 mcp->mb[3] = 0;
1345 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1346 } else {
1347 mcp->mb[0] = MBC_LIP_RESET;
1348 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1349 if (HAS_EXTENDED_IDS(ha)) {
1350 mcp->mb[1] = 0x00ff;
1351 mcp->mb[10] = 0;
1352 mcp->out_mb |= MBX_10;
1353 } else {
1354 mcp->mb[1] = 0xff00;
1356 mcp->mb[2] = ha->loop_reset_delay;
1357 mcp->mb[3] = 0;
1359 mcp->in_mb = MBX_0;
1360 mcp->tov = 30;
1361 mcp->flags = 0;
1362 rval = qla2x00_mailbox_command(ha, mcp);
1364 if (rval != QLA_SUCCESS) {
1365 /*EMPTY*/
1366 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1367 __func__, ha->host_no, rval);)
1368 } else {
1369 /*EMPTY*/
1370 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1373 return rval;
1377 * qla2x00_send_sns
1378 * Send SNS command.
1380 * Input:
1381 * ha = adapter block pointer.
1382 * sns = pointer for command.
1383 * cmd_size = command size.
1384 * buf_size = response/command size.
1385 * TARGET_QUEUE_LOCK must be released.
1386 * ADAPTER_STATE_LOCK must be released.
1388 * Returns:
1389 * qla2x00 local function return status code.
1391 * Context:
1392 * Kernel context.
1395 qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1396 uint16_t cmd_size, size_t buf_size)
1398 int rval;
1399 mbx_cmd_t mc;
1400 mbx_cmd_t *mcp = &mc;
1402 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1403 ha->host_no);)
1405 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1406 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1408 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1409 mcp->mb[1] = cmd_size;
1410 mcp->mb[2] = MSW(sns_phys_address);
1411 mcp->mb[3] = LSW(sns_phys_address);
1412 mcp->mb[6] = MSW(MSD(sns_phys_address));
1413 mcp->mb[7] = LSW(MSD(sns_phys_address));
1414 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1415 mcp->in_mb = MBX_0|MBX_1;
1416 mcp->buf_size = buf_size;
1417 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1418 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1419 rval = qla2x00_mailbox_command(ha, mcp);
1421 if (rval != QLA_SUCCESS) {
1422 /*EMPTY*/
1423 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1424 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1425 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1426 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1427 } else {
1428 /*EMPTY*/
1429 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1432 return rval;
1436 qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1437 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1439 int rval;
1441 struct logio_entry_24xx *lg;
1442 dma_addr_t lg_dma;
1443 uint32_t iop[2];
1445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1447 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1448 if (lg == NULL) {
1449 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1450 __func__, ha->host_no));
1451 return QLA_MEMORY_ALLOC_FAILED;
1453 memset(lg, 0, sizeof(struct logio_entry_24xx));
1455 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1456 lg->entry_count = 1;
1457 lg->nport_handle = cpu_to_le16(loop_id);
1458 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1459 if (opt & BIT_0)
1460 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1461 lg->port_id[0] = al_pa;
1462 lg->port_id[1] = area;
1463 lg->port_id[2] = domain;
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_QLA24XX(ha) || IS_QLA54XX(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_EXPL_LOGO);
1715 lg->port_id[0] = al_pa;
1716 lg->port_id[1] = area;
1717 lg->port_id[2] = domain;
1718 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1719 if (rval != QLA_SUCCESS) {
1720 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1721 "(%x).\n", __func__, ha->host_no, rval);)
1722 } else if (lg->entry_status != 0) {
1723 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1724 "-- error status (%x).\n", __func__, ha->host_no,
1725 lg->entry_status));
1726 rval = QLA_FUNCTION_FAILED;
1727 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1728 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1729 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1730 ha->host_no, le16_to_cpu(lg->comp_status),
1731 le32_to_cpu(lg->io_parameter[0]),
1732 le32_to_cpu(lg->io_parameter[1]));)
1733 } else {
1734 /*EMPTY*/
1735 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1738 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1740 return rval;
1744 * qla2x00_fabric_logout
1745 * Issue logout fabric port mailbox command.
1747 * Input:
1748 * ha = adapter block pointer.
1749 * loop_id = device loop ID.
1750 * TARGET_QUEUE_LOCK must be released.
1751 * ADAPTER_STATE_LOCK must be released.
1753 * Returns:
1754 * qla2x00 local function return status code.
1756 * Context:
1757 * Kernel context.
1760 qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1761 uint8_t area, uint8_t al_pa)
1763 int rval;
1764 mbx_cmd_t mc;
1765 mbx_cmd_t *mcp = &mc;
1767 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1768 ha->host_no);)
1770 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1771 mcp->out_mb = MBX_1|MBX_0;
1772 if (HAS_EXTENDED_IDS(ha)) {
1773 mcp->mb[1] = loop_id;
1774 mcp->mb[10] = 0;
1775 mcp->out_mb |= MBX_10;
1776 } else {
1777 mcp->mb[1] = loop_id << 8;
1780 mcp->in_mb = MBX_1|MBX_0;
1781 mcp->tov = 30;
1782 mcp->flags = 0;
1783 rval = qla2x00_mailbox_command(ha, mcp);
1785 if (rval != QLA_SUCCESS) {
1786 /*EMPTY*/
1787 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1788 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
1789 } else {
1790 /*EMPTY*/
1791 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1792 ha->host_no);)
1795 return rval;
1799 * qla2x00_full_login_lip
1800 * Issue full login LIP mailbox command.
1802 * Input:
1803 * ha = adapter block pointer.
1804 * TARGET_QUEUE_LOCK must be released.
1805 * ADAPTER_STATE_LOCK must be released.
1807 * Returns:
1808 * qla2x00 local function return status code.
1810 * Context:
1811 * Kernel context.
1814 qla2x00_full_login_lip(scsi_qla_host_t *ha)
1816 int rval;
1817 mbx_cmd_t mc;
1818 mbx_cmd_t *mcp = &mc;
1820 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1821 ha->host_no);)
1823 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1824 mcp->mb[1] = 0;
1825 mcp->mb[2] = 0xff;
1826 mcp->mb[3] = 0;
1827 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1828 mcp->in_mb = MBX_0;
1829 mcp->tov = 30;
1830 mcp->flags = 0;
1831 rval = qla2x00_mailbox_command(ha, mcp);
1833 if (rval != QLA_SUCCESS) {
1834 /*EMPTY*/
1835 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1836 ha->host_no, rval);)
1837 } else {
1838 /*EMPTY*/
1839 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1840 ha->host_no);)
1843 return rval;
1847 * qla2x00_get_id_list
1849 * Input:
1850 * ha = adapter block pointer.
1852 * Returns:
1853 * qla2x00 local function return status code.
1855 * Context:
1856 * Kernel context.
1859 qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1860 uint16_t *entries)
1862 int rval;
1863 mbx_cmd_t mc;
1864 mbx_cmd_t *mcp = &mc;
1866 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1867 ha->host_no);)
1869 if (id_list == NULL)
1870 return QLA_FUNCTION_FAILED;
1872 mcp->mb[0] = MBC_GET_ID_LIST;
1873 mcp->out_mb = MBX_0;
1874 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
1875 mcp->mb[2] = MSW(id_list_dma);
1876 mcp->mb[3] = LSW(id_list_dma);
1877 mcp->mb[6] = MSW(MSD(id_list_dma));
1878 mcp->mb[7] = LSW(MSD(id_list_dma));
1879 mcp->mb[8] = 0;
1880 mcp->out_mb |= MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
1881 } else {
1882 mcp->mb[1] = MSW(id_list_dma);
1883 mcp->mb[2] = LSW(id_list_dma);
1884 mcp->mb[3] = MSW(MSD(id_list_dma));
1885 mcp->mb[6] = LSW(MSD(id_list_dma));
1886 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1888 mcp->in_mb = MBX_1|MBX_0;
1889 mcp->tov = 30;
1890 mcp->flags = 0;
1891 rval = qla2x00_mailbox_command(ha, mcp);
1893 if (rval != QLA_SUCCESS) {
1894 /*EMPTY*/
1895 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1896 ha->host_no, rval);)
1897 } else {
1898 *entries = mcp->mb[1];
1899 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1900 ha->host_no);)
1903 return rval;
1907 * qla2x00_get_resource_cnts
1908 * Get current firmware resource counts.
1910 * Input:
1911 * ha = adapter block pointer.
1913 * Returns:
1914 * qla2x00 local function return status code.
1916 * Context:
1917 * Kernel context.
1920 qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1921 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
1923 int rval;
1924 mbx_cmd_t mc;
1925 mbx_cmd_t *mcp = &mc;
1927 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1929 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1930 mcp->out_mb = MBX_0;
1931 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1932 mcp->tov = 30;
1933 mcp->flags = 0;
1934 rval = qla2x00_mailbox_command(ha, mcp);
1936 if (rval != QLA_SUCCESS) {
1937 /*EMPTY*/
1938 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1939 ha->host_no, mcp->mb[0]);)
1940 } else {
1941 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1942 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
1943 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1944 mcp->mb[10]));
1946 if (cur_xchg_cnt)
1947 *cur_xchg_cnt = mcp->mb[3];
1948 if (orig_xchg_cnt)
1949 *orig_xchg_cnt = mcp->mb[6];
1950 if (cur_iocb_cnt)
1951 *cur_iocb_cnt = mcp->mb[7];
1952 if (orig_iocb_cnt)
1953 *orig_iocb_cnt = mcp->mb[10];
1956 return (rval);
1959 #if defined(QL_DEBUG_LEVEL_3)
1961 * qla2x00_get_fcal_position_map
1962 * Get FCAL (LILP) position map using mailbox command
1964 * Input:
1965 * ha = adapter state pointer.
1966 * pos_map = buffer pointer (can be NULL).
1968 * Returns:
1969 * qla2x00 local function return status code.
1971 * Context:
1972 * Kernel context.
1975 qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1977 int rval;
1978 mbx_cmd_t mc;
1979 mbx_cmd_t *mcp = &mc;
1980 char *pmap;
1981 dma_addr_t pmap_dma;
1983 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1984 if (pmap == NULL) {
1985 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1986 __func__, ha->host_no));
1987 return QLA_MEMORY_ALLOC_FAILED;
1989 memset(pmap, 0, FCAL_MAP_SIZE);
1991 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1992 mcp->mb[2] = MSW(pmap_dma);
1993 mcp->mb[3] = LSW(pmap_dma);
1994 mcp->mb[6] = MSW(MSD(pmap_dma));
1995 mcp->mb[7] = LSW(MSD(pmap_dma));
1996 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1997 mcp->in_mb = MBX_1|MBX_0;
1998 mcp->buf_size = FCAL_MAP_SIZE;
1999 mcp->flags = MBX_DMA_IN;
2000 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2001 rval = qla2x00_mailbox_command(ha, mcp);
2003 if (rval == QLA_SUCCESS) {
2004 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2005 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2006 mcp->mb[1], (unsigned)pmap[0]));
2007 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2009 if (pos_map)
2010 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2012 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2014 if (rval != QLA_SUCCESS) {
2015 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2016 ha->host_no, rval));
2017 } else {
2018 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2021 return rval;
2023 #endif
2026 * qla2x00_get_link_status
2028 * Input:
2029 * ha = adapter block pointer.
2030 * loop_id = device loop ID.
2031 * ret_buf = pointer to link status return buffer.
2033 * Returns:
2034 * 0 = success.
2035 * BIT_0 = mem alloc error.
2036 * BIT_1 = mailbox error.
2039 qla2x00_get_link_status(scsi_qla_host_t *ha, uint16_t loop_id,
2040 link_stat_t *ret_buf, uint16_t *status)
2042 int rval;
2043 mbx_cmd_t mc;
2044 mbx_cmd_t *mcp = &mc;
2045 link_stat_t *stat_buf;
2046 dma_addr_t stat_buf_dma;
2048 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2050 stat_buf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &stat_buf_dma);
2051 if (stat_buf == NULL) {
2052 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2053 __func__, ha->host_no));
2054 return BIT_0;
2056 memset(stat_buf, 0, sizeof(link_stat_t));
2058 mcp->mb[0] = MBC_GET_LINK_STATUS;
2059 mcp->mb[2] = MSW(stat_buf_dma);
2060 mcp->mb[3] = LSW(stat_buf_dma);
2061 mcp->mb[6] = MSW(MSD(stat_buf_dma));
2062 mcp->mb[7] = LSW(MSD(stat_buf_dma));
2063 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2064 mcp->in_mb = MBX_0;
2065 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
2066 mcp->mb[1] = loop_id;
2067 mcp->mb[4] = 0;
2068 mcp->mb[10] = 0;
2069 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2070 mcp->in_mb |= MBX_1;
2071 } else if (HAS_EXTENDED_IDS(ha)) {
2072 mcp->mb[1] = loop_id;
2073 mcp->mb[10] = 0;
2074 mcp->out_mb |= MBX_10|MBX_1;
2075 } else {
2076 mcp->mb[1] = loop_id << 8;
2077 mcp->out_mb |= MBX_1;
2079 mcp->tov = 30;
2080 mcp->flags = IOCTL_CMD;
2081 rval = qla2x00_mailbox_command(ha, mcp);
2083 if (rval == QLA_SUCCESS) {
2084 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2085 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2086 __func__, ha->host_no, mcp->mb[0]);)
2087 status[0] = mcp->mb[0];
2088 rval = BIT_1;
2089 } else {
2090 /* copy over data -- firmware data is LE. */
2091 ret_buf->link_fail_cnt =
2092 le32_to_cpu(stat_buf->link_fail_cnt);
2093 ret_buf->loss_sync_cnt =
2094 le32_to_cpu(stat_buf->loss_sync_cnt);
2095 ret_buf->loss_sig_cnt =
2096 le32_to_cpu(stat_buf->loss_sig_cnt);
2097 ret_buf->prim_seq_err_cnt =
2098 le32_to_cpu(stat_buf->prim_seq_err_cnt);
2099 ret_buf->inval_xmit_word_cnt =
2100 le32_to_cpu(stat_buf->inval_xmit_word_cnt);
2101 ret_buf->inval_crc_cnt =
2102 le32_to_cpu(stat_buf->inval_crc_cnt);
2104 DEBUG11(printk("%s(%ld): stat dump: fail_cnt=%d "
2105 "loss_sync=%d loss_sig=%d seq_err=%d "
2106 "inval_xmt_word=%d inval_crc=%d.\n", __func__,
2107 ha->host_no, stat_buf->link_fail_cnt,
2108 stat_buf->loss_sync_cnt, stat_buf->loss_sig_cnt,
2109 stat_buf->prim_seq_err_cnt,
2110 stat_buf->inval_xmit_word_cnt,
2111 stat_buf->inval_crc_cnt);)
2113 } else {
2114 /* Failed. */
2115 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2116 ha->host_no, rval);)
2117 rval = BIT_1;
2120 dma_pool_free(ha->s_dma_pool, stat_buf, stat_buf_dma);
2122 return rval;
2126 qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2127 uint16_t *status)
2129 int rval;
2130 mbx_cmd_t mc;
2131 mbx_cmd_t *mcp = &mc;
2132 uint32_t *sbuf, *siter;
2133 dma_addr_t sbuf_dma;
2135 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2137 if (dwords > (DMA_POOL_SIZE / 4)) {
2138 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2139 "(max %d).\n", __func__, ha->host_no, dwords,
2140 DMA_POOL_SIZE / 4));
2141 return BIT_0;
2143 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2144 if (sbuf == NULL) {
2145 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2146 __func__, ha->host_no));
2147 return BIT_0;
2149 memset(sbuf, 0, DMA_POOL_SIZE);
2151 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2152 mcp->mb[2] = MSW(sbuf_dma);
2153 mcp->mb[3] = LSW(sbuf_dma);
2154 mcp->mb[6] = MSW(MSD(sbuf_dma));
2155 mcp->mb[7] = LSW(MSD(sbuf_dma));
2156 mcp->mb[8] = dwords;
2157 mcp->mb[10] = 0;
2158 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2159 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2160 mcp->tov = 30;
2161 mcp->flags = IOCTL_CMD;
2162 rval = qla2x00_mailbox_command(ha, mcp);
2164 if (rval == QLA_SUCCESS) {
2165 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2166 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2167 __func__, ha->host_no, mcp->mb[0]));
2168 status[0] = mcp->mb[0];
2169 rval = BIT_1;
2170 } else {
2171 /* Copy over data -- firmware data is LE. */
2172 siter = sbuf;
2173 while (dwords--)
2174 *dwbuf++ = le32_to_cpu(*siter++);
2176 } else {
2177 /* Failed. */
2178 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2179 ha->host_no, rval));
2180 rval = BIT_1;
2183 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2185 return rval;
2189 qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2191 int rval;
2192 fc_port_t *fcport;
2193 unsigned long flags = 0;
2195 struct abort_entry_24xx *abt;
2196 dma_addr_t abt_dma;
2197 uint32_t handle;
2199 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2201 fcport = sp->fcport;
2203 spin_lock_irqsave(&ha->hardware_lock, flags);
2204 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2205 if (ha->outstanding_cmds[handle] == sp)
2206 break;
2208 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2209 if (handle == MAX_OUTSTANDING_COMMANDS) {
2210 /* Command not found. */
2211 return QLA_FUNCTION_FAILED;
2214 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2215 if (abt == NULL) {
2216 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2217 __func__, ha->host_no));
2218 return QLA_MEMORY_ALLOC_FAILED;
2220 memset(abt, 0, sizeof(struct abort_entry_24xx));
2222 abt->entry_type = ABORT_IOCB_TYPE;
2223 abt->entry_count = 1;
2224 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2225 abt->handle_to_abort = handle;
2226 abt->port_id[0] = fcport->d_id.b.al_pa;
2227 abt->port_id[1] = fcport->d_id.b.area;
2228 abt->port_id[2] = fcport->d_id.b.domain;
2229 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2230 if (rval != QLA_SUCCESS) {
2231 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2232 __func__, ha->host_no, rval);)
2233 } else if (abt->entry_status != 0) {
2234 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2235 "-- error status (%x).\n", __func__, ha->host_no,
2236 abt->entry_status));
2237 rval = QLA_FUNCTION_FAILED;
2238 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2239 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2240 "-- completion status (%x).\n", __func__, ha->host_no,
2241 le16_to_cpu(abt->nport_handle));)
2242 rval = QLA_FUNCTION_FAILED;
2243 } else {
2244 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2245 sp->flags |= SRB_ABORT_PENDING;
2248 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2250 return rval;
2253 struct tsk_mgmt_cmd {
2254 union {
2255 struct tsk_mgmt_entry tsk;
2256 struct sts_entry_24xx sts;
2257 } p;
2261 qla24xx_abort_target(fc_port_t *fcport)
2263 int rval;
2264 struct tsk_mgmt_cmd *tsk;
2265 dma_addr_t tsk_dma;
2266 scsi_qla_host_t *ha;
2268 if (fcport == NULL)
2269 return 0;
2271 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
2273 ha = fcport->ha;
2274 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2275 if (tsk == NULL) {
2276 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2277 "IOCB.\n", __func__, ha->host_no));
2278 return QLA_MEMORY_ALLOC_FAILED;
2280 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2282 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2283 tsk->p.tsk.entry_count = 1;
2284 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2285 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2286 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2287 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2288 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2289 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2290 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2291 if (rval != QLA_SUCCESS) {
2292 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2293 "(%x).\n", __func__, ha->host_no, rval);)
2294 goto atarget_done;
2295 } else if (tsk->p.sts.entry_status != 0) {
2296 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2297 "-- error status (%x).\n", __func__, ha->host_no,
2298 tsk->p.sts.entry_status));
2299 rval = QLA_FUNCTION_FAILED;
2300 goto atarget_done;
2301 } else if (tsk->p.sts.comp_status !=
2302 __constant_cpu_to_le16(CS_COMPLETE)) {
2303 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2304 "-- completion status (%x).\n", __func__,
2305 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));)
2306 rval = QLA_FUNCTION_FAILED;
2307 goto atarget_done;
2310 /* Issue marker IOCB. */
2311 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2312 if (rval != QLA_SUCCESS) {
2313 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2314 "(%x).\n", __func__, ha->host_no, rval);)
2315 } else {
2316 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2319 atarget_done:
2320 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2322 return rval;
2326 qla2x00_system_error(scsi_qla_host_t *ha)
2328 int rval;
2329 mbx_cmd_t mc;
2330 mbx_cmd_t *mcp = &mc;
2332 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2333 return QLA_FUNCTION_FAILED;
2335 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2337 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2338 mcp->out_mb = MBX_0;
2339 mcp->in_mb = MBX_0;
2340 mcp->tov = 5;
2341 mcp->flags = 0;
2342 rval = qla2x00_mailbox_command(ha, mcp);
2344 if (rval != QLA_SUCCESS) {
2345 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2346 ha->host_no, rval));
2347 } else {
2348 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2351 return rval;
2355 * qla2x00_get_serdes_params() -
2356 * @ha: HA context
2358 * Returns
2361 qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2362 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2364 int rval;
2365 mbx_cmd_t mc;
2366 mbx_cmd_t *mcp = &mc;
2368 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2370 mcp->mb[0] = MBC_SERDES_PARAMS;
2371 mcp->mb[1] = 0;
2372 mcp->out_mb = MBX_1|MBX_0;
2373 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2374 mcp->tov = 30;
2375 mcp->flags = 0;
2376 rval = qla2x00_mailbox_command(ha, mcp);
2378 if (rval != QLA_SUCCESS) {
2379 /*EMPTY*/
2380 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2381 ha->host_no, rval, mcp->mb[0]));
2382 } else {
2383 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2385 if (sw_em_1g)
2386 *sw_em_1g = mcp->mb[2];
2387 if (sw_em_2g)
2388 *sw_em_2g = mcp->mb[3];
2389 if (sw_em_4g)
2390 *sw_em_4g = mcp->mb[4];
2393 return rval;
2397 * qla2x00_set_serdes_params() -
2398 * @ha: HA context
2400 * Returns
2403 qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2404 uint16_t sw_em_2g, uint16_t sw_em_4g)
2406 int rval;
2407 mbx_cmd_t mc;
2408 mbx_cmd_t *mcp = &mc;
2410 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2412 mcp->mb[0] = MBC_SERDES_PARAMS;
2413 mcp->mb[1] = BIT_0;
2414 mcp->mb[2] = sw_em_1g | BIT_15;
2415 mcp->mb[3] = sw_em_2g | BIT_15;
2416 mcp->mb[4] = sw_em_4g | BIT_15;
2417 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2418 mcp->in_mb = MBX_0;
2419 mcp->tov = 30;
2420 mcp->flags = 0;
2421 rval = qla2x00_mailbox_command(ha, mcp);
2423 if (rval != QLA_SUCCESS) {
2424 /*EMPTY*/
2425 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2426 ha->host_no, rval, mcp->mb[0]));
2427 } else {
2428 /*EMPTY*/
2429 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2432 return rval;
2436 qla2x00_stop_firmware(scsi_qla_host_t *ha)
2438 int rval;
2439 mbx_cmd_t mc;
2440 mbx_cmd_t *mcp = &mc;
2442 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
2443 return QLA_FUNCTION_FAILED;
2445 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2447 mcp->mb[0] = MBC_STOP_FIRMWARE;
2448 mcp->out_mb = MBX_0;
2449 mcp->in_mb = MBX_0;
2450 mcp->tov = 5;
2451 mcp->flags = 0;
2452 rval = qla2x00_mailbox_command(ha, mcp);
2454 if (rval != QLA_SUCCESS) {
2455 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2456 ha->host_no, rval));
2457 } else {
2458 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2461 return rval;