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