blob: a10d41bf8f260cc78043872b8437bc0f4e660269 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/delay.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
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
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080032qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 int rval;
35 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070036 device_reg_t __iomem *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070037 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070038 uint8_t io_lock_on;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 uint16_t command;
40 uint16_t *iptr;
41 uint16_t __iomem *optr;
42 uint32_t cnt;
43 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080045 struct qla_hw_data *ha = vha->hw;
46 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070047
Seokmann Jub9b12f72009-03-24 09:08:18 -070048 if (ha->pdev->error_state > pci_channel_io_frozen)
49 return QLA_FUNCTION_TIMEOUT;
50
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070051 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080052 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080055 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080057 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070060 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080064 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
71 ha->flags.mbox_busy = 1;
72 /* Save mailbox command for debug */
73 ha->mcp = mcp;
74
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070075 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080076 base_vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 spin_lock_irqsave(&ha->hardware_lock, flags);
79
80 /* Load mailbox registers. */
Andrew Vasqueze4289242007-07-19 15:05:56 -070081 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070082 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
83 else
84 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
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)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070092 optr =
93 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 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)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700103 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800104 __func__, base_vha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 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");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800111 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
112 optr);
113 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#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 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700121 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800122 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* Wait for mbx cmd completion until timeout */
125
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800126 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
128
Andrew Vasqueze4289242007-07-19 15:05:56 -0700129 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700130 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
131 else
132 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
134
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800135 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700140 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800141 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Andrew Vasqueze4289242007-07-19 15:05:56 -0700143 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700144 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
145 else
146 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
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. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800155 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800157 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
158 !ha->flags.mbox_int)
159 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 } /* while */
161 }
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* Check whether we timed out */
164 if (ha->flags.mbox_int) {
165 uint16_t *iptr2;
166
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700167 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800168 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* Got interrupt. Clear the flag. */
171 ha->flags.mbox_int = 0;
172 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
173
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400174 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
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)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700193 uint16_t mb0;
194 uint32_t ictrl;
195
Andrew Vasqueze4289242007-07-19 15:05:56 -0700196 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700197 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
198 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
199 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700200 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700201 ictrl = RD_REG_WORD(&reg->isp.ictrl);
202 }
203 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800204 __func__, base_vha->host_no, command);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700205 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800206 base_vha->host_no, ictrl, jiffies);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700207 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800208 base_vha->host_no, mb0);
209 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#endif
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 rval = QLA_FUNCTION_TIMEOUT;
213 }
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 ha->flags.mbox_busy = 0;
216
217 /* Clean up */
218 ha->mcp = NULL;
219
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800220 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700221 DEBUG11(printk("%s(%ld): checking for additional resp "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800222 "interrupt.\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800225 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700228 if (rval == QLA_FUNCTION_TIMEOUT &&
229 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
231 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700232 DEBUG(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 "isp_abort_needed.\n", __func__,
234 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700235 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800236 "isp_abort_needed.\n", __func__,
237 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 qla_printk(KERN_WARNING, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700239 "Mailbox command timeout occurred. Scheduling ISP "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 "abort.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800241 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
242 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700245 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800246 __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700247 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800248 "abort_isp\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 qla_printk(KERN_WARNING, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700250 "Mailbox command timeout occurred. Issuing ISP "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 "abort.\n");
252
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800253 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)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700256 /* Failed. retry later. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800257 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800259 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700260 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800261 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700262 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800263 __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265 }
266
267 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800268 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700271 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800272 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700273 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800275 DEBUG11(printk("%s(%ld): done.\n", __func__,
276 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 }
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 return rval;
280}
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800283qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800284 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800287 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 mbx_cmd_t mc;
289 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800291 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Andrew Vasqueze4289242007-07-19 15:05:56 -0700293 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800294 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 mcp->mb[1] = LSW(risc_addr);
302 mcp->mb[2] = MSW(req_dma);
303 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 mcp->mb[6] = MSW(MSD(req_dma));
305 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800306 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700307 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700308 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700317 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800319 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700322 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800323 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800325 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327
328 return rval;
329}
330
331/*
332 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700333 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 *
335 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700336 * ha = adapter block pointer.
337 * TARGET_QUEUE_LOCK must be released.
338 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 *
340 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700341 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700344 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 */
346int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800347qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800350 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 mbx_cmd_t mc;
352 mbx_cmd_t *mcp = &mc;
353
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800354 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700357 mcp->out_mb = MBX_0;
358 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700359 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700360 mcp->mb[1] = MSW(risc_addr);
361 mcp->mb[2] = LSW(risc_addr);
362 mcp->mb[3] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700363 mcp->mb[4] = 0;
364 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700365 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
Ravi Anandb93480e2008-04-03 13:13:25 -0700375 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800377 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700379 if (rval != QLA_SUCCESS) {
380 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800381 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700382 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700383 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700384 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800385 __func__, vha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700386 } else {
387 DEBUG11(printk("%s(%ld): done.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800388 vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700389 }
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
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 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700411int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800412qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800413 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700414 uint32_t *mpi_caps, uint8_t *phy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 int rval;
417 mbx_cmd_t mc;
418 mbx_cmd_t *mcp = &mc;
419
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800420 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
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;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800425 if (IS_QLA81XX(vha->hw))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700426 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700428 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800429 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700430 if (rval != QLA_SUCCESS)
431 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433 /* Return mailbox data. */
434 *major = mcp->mb[1];
435 *minor = mcp->mb[2];
436 *subminor = mcp->mb[3];
437 *attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800438 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 *memory = 0x1FFFF; /* Defaults to 128KB. */
440 else
441 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800442 if (IS_QLA81XX(vha->hw)) {
Andrew Vasquez55a96152009-03-24 09:08:03 -0700443 mpi[0] = mcp->mb[10] & 0xff;
444 mpi[1] = mcp->mb[11] >> 8;
445 mpi[2] = mcp->mb[11] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800446 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
Andrew Vasquez55a96152009-03-24 09:08:03 -0700447 phy[0] = mcp->mb[8] & 0xff;
448 phy[1] = mcp->mb[9] >> 8;
449 phy[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800450 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700451failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 if (rval != QLA_SUCCESS) {
453 /*EMPTY*/
454 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800455 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 } else {
457 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800458 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700460 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
463/*
464 * qla2x00_get_fw_options
465 * Set firmware options.
466 *
467 * Input:
468 * ha = adapter block pointer.
469 * fwopt = pointer for firmware options.
470 *
471 * Returns:
472 * qla2x00 local function return status code.
473 *
474 * Context:
475 * Kernel context.
476 */
477int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800478qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
480 int rval;
481 mbx_cmd_t mc;
482 mbx_cmd_t *mcp = &mc;
483
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800484 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
487 mcp->out_mb = MBX_0;
488 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700489 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800491 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 if (rval != QLA_SUCCESS) {
494 /*EMPTY*/
495 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800496 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700498 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 fwopts[1] = mcp->mb[1];
500 fwopts[2] = mcp->mb[2];
501 fwopts[3] = mcp->mb[3];
502
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800503 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 }
505
506 return rval;
507}
508
509
510/*
511 * qla2x00_set_fw_options
512 * Set firmware options.
513 *
514 * Input:
515 * ha = adapter block pointer.
516 * fwopt = pointer for firmware options.
517 *
518 * Returns:
519 * qla2x00 local function return status code.
520 *
521 * Context:
522 * Kernel context.
523 */
524int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800525qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
527 int rval;
528 mbx_cmd_t mc;
529 mbx_cmd_t *mcp = &mc;
530
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800531 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
534 mcp->mb[1] = fwopts[1];
535 mcp->mb[2] = fwopts[2];
536 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700537 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800539 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700540 mcp->in_mb |= MBX_1;
541 } else {
542 mcp->mb[10] = fwopts[10];
543 mcp->mb[11] = fwopts[11];
544 mcp->mb[12] = 0; /* Undocumented, but used */
545 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
546 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700547 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800549 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700551 fwopts[0] = mcp->mb[0];
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (rval != QLA_SUCCESS) {
554 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700555 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800556 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 } else {
558 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800559 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
562 return rval;
563}
564
565/*
566 * qla2x00_mbx_reg_test
567 * Mailbox register wrap test.
568 *
569 * Input:
570 * ha = adapter block pointer.
571 * TARGET_QUEUE_LOCK must be released.
572 * ADAPTER_STATE_LOCK must be released.
573 *
574 * Returns:
575 * qla2x00 local function return status code.
576 *
577 * Context:
578 * Kernel context.
579 */
580int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800581qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 int rval;
584 mbx_cmd_t mc;
585 mbx_cmd_t *mcp = &mc;
586
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800587 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
590 mcp->mb[1] = 0xAAAA;
591 mcp->mb[2] = 0x5555;
592 mcp->mb[3] = 0xAA55;
593 mcp->mb[4] = 0x55AA;
594 mcp->mb[5] = 0xA5A5;
595 mcp->mb[6] = 0x5A5A;
596 mcp->mb[7] = 0x2525;
597 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
598 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700599 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800601 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 if (rval == QLA_SUCCESS) {
604 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
605 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
606 rval = QLA_FUNCTION_FAILED;
607 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
608 mcp->mb[7] != 0x2525)
609 rval = QLA_FUNCTION_FAILED;
610 }
611
612 if (rval != QLA_SUCCESS) {
613 /*EMPTY*/
614 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800615 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 } else {
617 /*EMPTY*/
618 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800619 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
622 return rval;
623}
624
625/*
626 * qla2x00_verify_checksum
627 * Verify firmware checksum.
628 *
629 * Input:
630 * ha = adapter block pointer.
631 * TARGET_QUEUE_LOCK must be released.
632 * ADAPTER_STATE_LOCK must be released.
633 *
634 * Returns:
635 * qla2x00 local function return status code.
636 *
637 * Context:
638 * Kernel context.
639 */
640int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800641qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642{
643 int rval;
644 mbx_cmd_t mc;
645 mbx_cmd_t *mcp = &mc;
646
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800647 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700650 mcp->out_mb = MBX_0;
651 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800652 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700653 mcp->mb[1] = MSW(risc_addr);
654 mcp->mb[2] = LSW(risc_addr);
655 mcp->out_mb |= MBX_2|MBX_1;
656 mcp->in_mb |= MBX_2|MBX_1;
657 } else {
658 mcp->mb[1] = LSW(risc_addr);
659 mcp->out_mb |= MBX_1;
660 mcp->in_mb |= MBX_1;
661 }
662
Ravi Anandb93480e2008-04-03 13:13:25 -0700663 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800665 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
667 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700668 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800669 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
Andrew Vasqueze4289242007-07-19 15:05:56 -0700670 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800672 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 return rval;
676}
677
678/*
679 * qla2x00_issue_iocb
680 * Issue IOCB using mailbox command
681 *
682 * Input:
683 * ha = adapter state pointer.
684 * buffer = buffer pointer.
685 * phys_addr = physical address of buffer.
686 * size = size of buffer.
687 * TARGET_QUEUE_LOCK must be released.
688 * ADAPTER_STATE_LOCK must be released.
689 *
690 * Returns:
691 * qla2x00 local function return status code.
692 *
693 * Context:
694 * Kernel context.
695 */
Adrian Bunk3b8117b2008-04-24 15:21:28 -0700696static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800697qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700698 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699{
700 int rval;
701 mbx_cmd_t mc;
702 mbx_cmd_t *mcp = &mc;
703
704 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
705 mcp->mb[1] = 0;
706 mcp->mb[2] = MSW(phys_addr);
707 mcp->mb[3] = LSW(phys_addr);
708 mcp->mb[6] = MSW(MSD(phys_addr));
709 mcp->mb[7] = LSW(MSD(phys_addr));
710 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
711 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700712 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800714 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 if (rval != QLA_SUCCESS) {
717 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700718 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800719 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700721 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
722
723 /* Mask reserved bits. */
724 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800725 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 }
727
728 return rval;
729}
730
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700731int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800732qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700733 size_t size)
734{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800735 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700736 MBX_TOV_SECONDS);
737}
738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739/*
740 * qla2x00_abort_command
741 * Abort command aborts a specified IOCB.
742 *
743 * Input:
744 * ha = adapter block pointer.
745 * sp = SB structure pointer.
746 *
747 * Returns:
748 * qla2x00 local function return status code.
749 *
750 * Context:
751 * Kernel context.
752 */
753int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700754qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755{
756 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 mbx_cmd_t mc;
760 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700761 fc_port_t *fcport = sp->fcport;
762 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800763 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700764 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800766 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700768 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800770 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 break;
772 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700773 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
775 if (handle == MAX_OUTSTANDING_COMMANDS) {
776 /* command not found */
777 return QLA_FUNCTION_FAILED;
778 }
779
780 mcp->mb[0] = MBC_ABORT_COMMAND;
781 if (HAS_EXTENDED_IDS(ha))
782 mcp->mb[1] = fcport->loop_id;
783 else
784 mcp->mb[1] = fcport->loop_id << 8;
785 mcp->mb[2] = (uint16_t)handle;
786 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500787 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
789 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700790 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800792 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (rval != QLA_SUCCESS) {
795 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800796 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800799 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801
802 return rval;
803}
804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700806qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700808 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 mbx_cmd_t mc;
810 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800811 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800812 struct req_que *req;
813 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800815 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700816
Andrew Vasquez523ec772008-04-03 13:13:24 -0700817 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800818 vha = fcport->vha;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700819 req = vha->hw->req_q_map[tag];
820 rsp = vha->hw->rsp_q_map[tag];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700822 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800823 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 mcp->mb[1] = fcport->loop_id;
825 mcp->mb[10] = 0;
826 mcp->out_mb |= MBX_10;
827 } else {
828 mcp->mb[1] = fcport->loop_id << 8;
829 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800830 mcp->mb[2] = vha->hw->loop_reset_delay;
831 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700834 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800836 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700838 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800839 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700840 }
841
842 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800843 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
844 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700845 if (rval2 != QLA_SUCCESS) {
846 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800847 "(%x).\n", __func__, vha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800849 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700850 }
851
852 return rval;
853}
854
855int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700856qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700857{
858 int rval, rval2;
859 mbx_cmd_t mc;
860 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800861 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800862 struct req_que *req;
863 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700864
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800865 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700866
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800867 vha = fcport->vha;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700868 req = vha->hw->req_q_map[tag];
869 rsp = vha->hw->rsp_q_map[tag];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700870 mcp->mb[0] = MBC_LUN_RESET;
871 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800872 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700873 mcp->mb[1] = fcport->loop_id;
874 else
875 mcp->mb[1] = fcport->loop_id << 8;
876 mcp->mb[2] = l;
877 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800878 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700879
880 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700881 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700882 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800883 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700884 if (rval != QLA_SUCCESS) {
885 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800886 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700887 }
888
889 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800890 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
891 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700892 if (rval2 != QLA_SUCCESS) {
893 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800894 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700895 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800896 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 }
898
899 return rval;
900}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 * qla2x00_get_adapter_id
904 * Get adapter ID and topology.
905 *
906 * Input:
907 * ha = adapter block pointer.
908 * id = pointer for loop ID.
909 * al_pa = pointer for AL_PA.
910 * area = pointer for area.
911 * domain = pointer for domain.
912 * top = pointer for topology.
913 * TARGET_QUEUE_LOCK must be released.
914 * ADAPTER_STATE_LOCK must be released.
915 *
916 * Returns:
917 * qla2x00 local function return status code.
918 *
919 * Context:
920 * Kernel context.
921 */
922int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800923qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700924 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
926 int rval;
927 mbx_cmd_t mc;
928 mbx_cmd_t *mcp = &mc;
929
930 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800931 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800934 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800935 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700936 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquezbad70012009-04-06 22:33:38 -0700937 if (IS_QLA81XX(vha->hw))
938 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -0700939 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800941 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800942 if (mcp->mb[0] == MBS_COMMAND_ERROR)
943 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700944 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
945 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 /* Return data. */
948 *id = mcp->mb[1];
949 *al_pa = LSB(mcp->mb[2]);
950 *area = MSB(mcp->mb[2]);
951 *domain = LSB(mcp->mb[3]);
952 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700953 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954
955 if (rval != QLA_SUCCESS) {
956 /*EMPTY*/
957 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800961 vha->host_no));
Andrew Vasquezbad70012009-04-06 22:33:38 -0700962
963 if (IS_QLA81XX(vha->hw)) {
964 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
965 vha->fcoe_fcf_idx = mcp->mb[10];
966 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
967 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
968 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
969 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
970 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
971 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
972 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 }
974
975 return rval;
976}
977
978/*
979 * qla2x00_get_retry_cnt
980 * Get current firmware login retry count and delay.
981 *
982 * Input:
983 * ha = adapter block pointer.
984 * retry_cnt = pointer to login retry count.
985 * tov = pointer to login timeout value.
986 *
987 * Returns:
988 * qla2x00 local function return status code.
989 *
990 * Context:
991 * Kernel context.
992 */
993int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800994qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 uint16_t *r_a_tov)
996{
997 int rval;
998 uint16_t ratov;
999 mbx_cmd_t mc;
1000 mbx_cmd_t *mcp = &mc;
1001
1002 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001003 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1006 mcp->out_mb = MBX_0;
1007 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001008 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001010 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 if (rval != QLA_SUCCESS) {
1013 /*EMPTY*/
1014 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001015 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 } else {
1017 /* Convert returned data and check our values. */
1018 *r_a_tov = mcp->mb[3] / 2;
1019 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1020 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1021 /* Update to the larger values */
1022 *retry_cnt = (uint8_t)mcp->mb[1];
1023 *tov = ratov;
1024 }
1025
1026 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001027 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
1029
1030 return rval;
1031}
1032
1033/*
1034 * qla2x00_init_firmware
1035 * Initialize adapter firmware.
1036 *
1037 * Input:
1038 * ha = adapter block pointer.
1039 * dptr = Initialization control block pointer.
1040 * size = size of initialization control block.
1041 * TARGET_QUEUE_LOCK must be released.
1042 * ADAPTER_STATE_LOCK must be released.
1043 *
1044 * Returns:
1045 * qla2x00 local function return status code.
1046 *
1047 * Context:
1048 * Kernel context.
1049 */
1050int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001051qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052{
1053 int rval;
1054 mbx_cmd_t mc;
1055 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001056 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001059 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001061 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001062 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1063 else
1064 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1065
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001066 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 mcp->mb[2] = MSW(ha->init_cb_dma);
1068 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1070 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001071 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1072 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1073 mcp->mb[1] = BIT_0;
1074 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1075 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1076 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1077 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1078 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1079 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1080 }
1081 mcp->in_mb = MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 mcp->buf_size = size;
1083 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001084 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001085 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 if (rval != QLA_SUCCESS) {
1088 /*EMPTY*/
1089 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1090 "mb0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001091 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 } else {
1093 /*EMPTY*/
1094 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001095 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 }
1097
1098 return rval;
1099}
1100
1101/*
1102 * qla2x00_get_port_database
1103 * Issue normal/enhanced get port database mailbox command
1104 * and copy device name as necessary.
1105 *
1106 * Input:
1107 * ha = adapter state pointer.
1108 * dev = structure pointer.
1109 * opt = enhanced cmd option byte.
1110 *
1111 * Returns:
1112 * qla2x00 local function return status code.
1113 *
1114 * Context:
1115 * Kernel context.
1116 */
1117int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001118qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119{
1120 int rval;
1121 mbx_cmd_t mc;
1122 mbx_cmd_t *mcp = &mc;
1123 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001124 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001126 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001128 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001130 pd24 = NULL;
1131 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001133 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001134 "structure.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 return QLA_MEMORY_ALLOC_FAILED;
1136 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001137 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001139 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001140 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 mcp->mb[2] = MSW(pd_dma);
1143 mcp->mb[3] = LSW(pd_dma);
1144 mcp->mb[6] = MSW(MSD(pd_dma));
1145 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001146 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001147 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001149 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001150 mcp->mb[1] = fcport->loop_id;
1151 mcp->mb[10] = opt;
1152 mcp->out_mb |= MBX_10|MBX_1;
1153 mcp->in_mb |= MBX_1;
1154 } else if (HAS_EXTENDED_IDS(ha)) {
1155 mcp->mb[1] = fcport->loop_id;
1156 mcp->mb[10] = opt;
1157 mcp->out_mb |= MBX_10|MBX_1;
1158 } else {
1159 mcp->mb[1] = fcport->loop_id << 8 | opt;
1160 mcp->out_mb |= MBX_1;
1161 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001162 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1163 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 mcp->flags = MBX_DMA_IN;
1165 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001166 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 if (rval != QLA_SUCCESS)
1168 goto gpd_error_out;
1169
Andrew Vasqueze4289242007-07-19 15:05:56 -07001170 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001171 pd24 = (struct port_database_24xx *) pd;
1172
1173 /* Check for logged in state. */
1174 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1175 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1176 DEBUG2(printk("%s(%ld): Unable to verify "
1177 "login-state (%x/%x) for loop_id %x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178 __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001179 pd24->current_login_state,
1180 pd24->last_login_state, fcport->loop_id));
1181 rval = QLA_FUNCTION_FAILED;
1182 goto gpd_error_out;
1183 }
1184
1185 /* Names are little-endian. */
1186 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1187 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1188
1189 /* Get port_id of device. */
1190 fcport->d_id.b.domain = pd24->port_id[0];
1191 fcport->d_id.b.area = pd24->port_id[1];
1192 fcport->d_id.b.al_pa = pd24->port_id[2];
1193 fcport->d_id.b.rsvd_1 = 0;
1194
1195 /* If not target must be initiator or unknown type. */
1196 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1197 fcport->port_type = FCT_INITIATOR;
1198 else
1199 fcport->port_type = FCT_TARGET;
1200 } else {
1201 /* Check for logged in state. */
1202 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1203 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1204 rval = QLA_FUNCTION_FAILED;
1205 goto gpd_error_out;
1206 }
1207
1208 /* Names are little-endian. */
1209 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1210 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1211
1212 /* Get port_id of device. */
1213 fcport->d_id.b.domain = pd->port_id[0];
1214 fcport->d_id.b.area = pd->port_id[3];
1215 fcport->d_id.b.al_pa = pd->port_id[2];
1216 fcport->d_id.b.rsvd_1 = 0;
1217
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001218 /* If not target must be initiator or unknown type. */
1219 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1220 fcport->port_type = FCT_INITIATOR;
1221 else
1222 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001223
1224 /* Passback COS information. */
1225 fcport->supported_classes = (pd->options & BIT_4) ?
1226 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 }
1228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229gpd_error_out:
1230 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1231
1232 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001233 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001234 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001236 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 }
1238
1239 return rval;
1240}
1241
1242/*
1243 * qla2x00_get_firmware_state
1244 * Get adapter firmware state.
1245 *
1246 * Input:
1247 * ha = adapter block pointer.
1248 * dptr = pointer for firmware state.
1249 * TARGET_QUEUE_LOCK must be released.
1250 * ADAPTER_STATE_LOCK must be released.
1251 *
1252 * Returns:
1253 * qla2x00 local function return status code.
1254 *
1255 * Context:
1256 * Kernel context.
1257 */
1258int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001259qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
1261 int rval;
1262 mbx_cmd_t mc;
1263 mbx_cmd_t *mcp = &mc;
1264
1265 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001266 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1269 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001270 if (IS_FWI2_CAPABLE(vha->hw))
1271 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1272 else
1273 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001274 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001276 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001278 /* Return firmware states. */
1279 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001280 if (IS_FWI2_CAPABLE(vha->hw)) {
1281 states[1] = mcp->mb[2];
1282 states[2] = mcp->mb[3];
1283 states[3] = mcp->mb[4];
1284 states[4] = mcp->mb[5];
1285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 if (rval != QLA_SUCCESS) {
1288 /*EMPTY*/
1289 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001290 "failed=%x.\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 } else {
1292 /*EMPTY*/
1293 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001294 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 }
1296
1297 return rval;
1298}
1299
1300/*
1301 * qla2x00_get_port_name
1302 * Issue get port name mailbox command.
1303 * Returned name is in big endian format.
1304 *
1305 * Input:
1306 * ha = adapter block pointer.
1307 * loop_id = loop ID of device.
1308 * name = pointer for name.
1309 * TARGET_QUEUE_LOCK must be released.
1310 * ADAPTER_STATE_LOCK must be released.
1311 *
1312 * Returns:
1313 * qla2x00 local function return status code.
1314 *
1315 * Context:
1316 * Kernel context.
1317 */
1318int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001319qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 uint8_t opt)
1321{
1322 int rval;
1323 mbx_cmd_t mc;
1324 mbx_cmd_t *mcp = &mc;
1325
1326 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001327 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001330 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001331 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001332 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 mcp->mb[1] = loop_id;
1334 mcp->mb[10] = opt;
1335 mcp->out_mb |= MBX_10;
1336 } else {
1337 mcp->mb[1] = loop_id << 8 | opt;
1338 }
1339
1340 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001341 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001343 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 if (rval != QLA_SUCCESS) {
1346 /*EMPTY*/
1347 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001348 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 } else {
1350 if (name != NULL) {
1351 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001352 name[0] = MSB(mcp->mb[2]);
1353 name[1] = LSB(mcp->mb[2]);
1354 name[2] = MSB(mcp->mb[3]);
1355 name[3] = LSB(mcp->mb[3]);
1356 name[4] = MSB(mcp->mb[6]);
1357 name[5] = LSB(mcp->mb[6]);
1358 name[6] = MSB(mcp->mb[7]);
1359 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 }
1361
1362 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001363 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
1365
1366 return rval;
1367}
1368
1369/*
1370 * qla2x00_lip_reset
1371 * Issue LIP reset mailbox command.
1372 *
1373 * Input:
1374 * ha = adapter block pointer.
1375 * TARGET_QUEUE_LOCK must be released.
1376 * ADAPTER_STATE_LOCK must be released.
1377 *
1378 * Returns:
1379 * qla2x00 local function return status code.
1380 *
1381 * Context:
1382 * Kernel context.
1383 */
1384int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001385qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
1387 int rval;
1388 mbx_cmd_t mc;
1389 mbx_cmd_t *mcp = &mc;
1390
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001391 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001393 if (IS_QLA81XX(vha->hw)) {
1394 /* Logout across all FCFs. */
1395 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1396 mcp->mb[1] = BIT_1;
1397 mcp->mb[2] = 0;
1398 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1399 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001400 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001401 mcp->mb[1] = BIT_6;
1402 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001403 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001404 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001406 mcp->mb[0] = MBC_LIP_RESET;
1407 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001408 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001409 mcp->mb[1] = 0x00ff;
1410 mcp->mb[10] = 0;
1411 mcp->out_mb |= MBX_10;
1412 } else {
1413 mcp->mb[1] = 0xff00;
1414 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001415 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001416 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001419 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001421 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
1423 if (rval != QLA_SUCCESS) {
1424 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001425 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001426 __func__, vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 } else {
1428 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001429 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431
1432 return rval;
1433}
1434
1435/*
1436 * qla2x00_send_sns
1437 * Send SNS command.
1438 *
1439 * Input:
1440 * ha = adapter block pointer.
1441 * sns = pointer for command.
1442 * cmd_size = command size.
1443 * buf_size = response/command size.
1444 * TARGET_QUEUE_LOCK must be released.
1445 * ADAPTER_STATE_LOCK must be released.
1446 *
1447 * Returns:
1448 * qla2x00 local function return status code.
1449 *
1450 * Context:
1451 * Kernel context.
1452 */
1453int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001454qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 uint16_t cmd_size, size_t buf_size)
1456{
1457 int rval;
1458 mbx_cmd_t mc;
1459 mbx_cmd_t *mcp = &mc;
1460
1461 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001462 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001465 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1466 mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1469 mcp->mb[1] = cmd_size;
1470 mcp->mb[2] = MSW(sns_phys_address);
1471 mcp->mb[3] = LSW(sns_phys_address);
1472 mcp->mb[6] = MSW(MSD(sns_phys_address));
1473 mcp->mb[7] = LSW(MSD(sns_phys_address));
1474 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1475 mcp->in_mb = MBX_0|MBX_1;
1476 mcp->buf_size = buf_size;
1477 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001478 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1479 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 if (rval != QLA_SUCCESS) {
1482 /*EMPTY*/
1483 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001484 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001486 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 } else {
1488 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001489 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 }
1491
1492 return rval;
1493}
1494
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001495int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001496qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001497 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1498{
1499 int rval;
1500
1501 struct logio_entry_24xx *lg;
1502 dma_addr_t lg_dma;
1503 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001504 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001505 struct req_que *req;
1506 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001507
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001508 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001509
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001510 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001511 req = ha->req_q_map[0];
1512 else
1513 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001514 rsp = req->rsp;
1515
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001516 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1517 if (lg == NULL) {
1518 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001519 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001520 return QLA_MEMORY_ALLOC_FAILED;
1521 }
1522 memset(lg, 0, sizeof(struct logio_entry_24xx));
1523
1524 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1525 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001526 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001527 lg->nport_handle = cpu_to_le16(loop_id);
1528 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1529 if (opt & BIT_0)
1530 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001531 if (opt & BIT_1)
1532 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001533 lg->port_id[0] = al_pa;
1534 lg->port_id[1] = area;
1535 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001536 lg->vp_index = vha->vp_idx;
1537 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001538 if (rval != QLA_SUCCESS) {
1539 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001540 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001541 } else if (lg->entry_status != 0) {
1542 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001543 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001544 lg->entry_status));
1545 rval = QLA_FUNCTION_FAILED;
1546 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1547 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1548 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1549
1550 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1551 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001552 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001553 iop[1]));
1554
1555 switch (iop[0]) {
1556 case LSC_SCODE_PORTID_USED:
1557 mb[0] = MBS_PORT_ID_USED;
1558 mb[1] = LSW(iop[1]);
1559 break;
1560 case LSC_SCODE_NPORT_USED:
1561 mb[0] = MBS_LOOP_ID_USED;
1562 break;
1563 case LSC_SCODE_NOLINK:
1564 case LSC_SCODE_NOIOCB:
1565 case LSC_SCODE_NOXCB:
1566 case LSC_SCODE_CMD_FAILED:
1567 case LSC_SCODE_NOFABRIC:
1568 case LSC_SCODE_FW_NOT_READY:
1569 case LSC_SCODE_NOT_LOGGED_IN:
1570 case LSC_SCODE_NOPCB:
1571 case LSC_SCODE_ELS_REJECT:
1572 case LSC_SCODE_CMD_PARAM_ERR:
1573 case LSC_SCODE_NONPORT:
1574 case LSC_SCODE_LOGGED_IN:
1575 case LSC_SCODE_NOFLOGI_ACC:
1576 default:
1577 mb[0] = MBS_COMMAND_ERROR;
1578 break;
1579 }
1580 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001581 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001582
1583 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1584
1585 mb[0] = MBS_COMMAND_COMPLETE;
1586 mb[1] = 0;
1587 if (iop[0] & BIT_4) {
1588 if (iop[0] & BIT_8)
1589 mb[1] |= BIT_1;
1590 } else
1591 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001592
1593 /* Passback COS information. */
1594 mb[10] = 0;
1595 if (lg->io_parameter[7] || lg->io_parameter[8])
1596 mb[10] |= BIT_0; /* Class 2. */
1597 if (lg->io_parameter[9] || lg->io_parameter[10])
1598 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001599 }
1600
1601 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1602
1603 return rval;
1604}
1605
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606/*
1607 * qla2x00_login_fabric
1608 * Issue login fabric port mailbox command.
1609 *
1610 * Input:
1611 * ha = adapter block pointer.
1612 * loop_id = device loop ID.
1613 * domain = device domain.
1614 * area = device area.
1615 * al_pa = device AL_PA.
1616 * status = pointer for return status.
1617 * opt = command options.
1618 * TARGET_QUEUE_LOCK must be released.
1619 * ADAPTER_STATE_LOCK must be released.
1620 *
1621 * Returns:
1622 * qla2x00 local function return status code.
1623 *
1624 * Context:
1625 * Kernel context.
1626 */
1627int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001628qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1630{
1631 int rval;
1632 mbx_cmd_t mc;
1633 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001634 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001636 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1639 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1640 if (HAS_EXTENDED_IDS(ha)) {
1641 mcp->mb[1] = loop_id;
1642 mcp->mb[10] = opt;
1643 mcp->out_mb |= MBX_10;
1644 } else {
1645 mcp->mb[1] = (loop_id << 8) | opt;
1646 }
1647 mcp->mb[2] = domain;
1648 mcp->mb[3] = area << 8 | al_pa;
1649
1650 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1651 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1652 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001653 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 /* Return mailbox statuses. */
1656 if (mb != NULL) {
1657 mb[0] = mcp->mb[0];
1658 mb[1] = mcp->mb[1];
1659 mb[2] = mcp->mb[2];
1660 mb[6] = mcp->mb[6];
1661 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001662 /* COS retrieved from Get-Port-Database mailbox command. */
1663 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 }
1665
1666 if (rval != QLA_SUCCESS) {
1667 /* RLU tmp code: need to change main mailbox_command function to
1668 * return ok even when the mailbox completion value is not
1669 * SUCCESS. The caller needs to be responsible to interpret
1670 * the return values of this mailbox command if we're not
1671 * to change too much of the existing code.
1672 */
1673 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1674 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1675 mcp->mb[0] == 0x4006)
1676 rval = QLA_SUCCESS;
1677
1678 /*EMPTY*/
1679 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001680 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001681 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 } else {
1683 /*EMPTY*/
1684 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001685 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 }
1687
1688 return rval;
1689}
1690
1691/*
1692 * qla2x00_login_local_device
1693 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001694 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 * Input:
1696 * ha = adapter block pointer.
1697 * loop_id = device loop ID.
1698 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001699 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 * Returns:
1701 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001702 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 * Context:
1704 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001705 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 */
1707int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001708qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 uint16_t *mb_ret, uint8_t opt)
1710{
1711 int rval;
1712 mbx_cmd_t mc;
1713 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001714 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Andrew Vasqueze4289242007-07-19 15:05:56 -07001716 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001717 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001718 fcport->d_id.b.domain, fcport->d_id.b.area,
1719 fcport->d_id.b.al_pa, mb_ret, opt);
1720
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001721 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
1723 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1724 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001725 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001727 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 mcp->mb[2] = opt;
1729 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1730 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1731 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1732 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001733 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 /* Return mailbox statuses. */
1736 if (mb_ret != NULL) {
1737 mb_ret[0] = mcp->mb[0];
1738 mb_ret[1] = mcp->mb[1];
1739 mb_ret[6] = mcp->mb[6];
1740 mb_ret[7] = mcp->mb[7];
1741 }
1742
1743 if (rval != QLA_SUCCESS) {
1744 /* AV tmp code: need to change main mailbox_command function to
1745 * return ok even when the mailbox completion value is not
1746 * SUCCESS. The caller needs to be responsible to interpret
1747 * the return values of this mailbox command if we're not
1748 * to change too much of the existing code.
1749 */
1750 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1751 rval = QLA_SUCCESS;
1752
1753 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001754 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001755 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001757 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001758 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 } else {
1760 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001761 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763
1764 return (rval);
1765}
1766
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001767int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001768qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001769 uint8_t area, uint8_t al_pa)
1770{
1771 int rval;
1772 struct logio_entry_24xx *lg;
1773 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001774 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001775 struct req_que *req;
1776 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001777
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001778 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001779
1780 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1781 if (lg == NULL) {
1782 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001783 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001784 return QLA_MEMORY_ALLOC_FAILED;
1785 }
1786 memset(lg, 0, sizeof(struct logio_entry_24xx));
1787
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001788 if (ql2xmaxqueues > 1)
1789 req = ha->req_q_map[0];
1790 else
1791 req = vha->req;
1792 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001793 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1794 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001795 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001796 lg->nport_handle = cpu_to_le16(loop_id);
1797 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001798 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001799 lg->port_id[0] = al_pa;
1800 lg->port_id[1] = area;
1801 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001802 lg->vp_index = vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001803
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001804 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001805 if (rval != QLA_SUCCESS) {
1806 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001807 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001808 } else if (lg->entry_status != 0) {
1809 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001810 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001811 lg->entry_status));
1812 rval = QLA_FUNCTION_FAILED;
1813 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001814 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001815 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001816 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001817 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001818 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001819 } else {
1820 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001821 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001822 }
1823
1824 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1825
1826 return rval;
1827}
1828
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829/*
1830 * qla2x00_fabric_logout
1831 * Issue logout fabric port mailbox command.
1832 *
1833 * Input:
1834 * ha = adapter block pointer.
1835 * loop_id = device loop ID.
1836 * TARGET_QUEUE_LOCK must be released.
1837 * ADAPTER_STATE_LOCK must be released.
1838 *
1839 * Returns:
1840 * qla2x00 local function return status code.
1841 *
1842 * Context:
1843 * Kernel context.
1844 */
1845int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001846qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001847 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848{
1849 int rval;
1850 mbx_cmd_t mc;
1851 mbx_cmd_t *mcp = &mc;
1852
1853 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001854 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855
1856 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1857 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001858 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 mcp->mb[1] = loop_id;
1860 mcp->mb[10] = 0;
1861 mcp->out_mb |= MBX_10;
1862 } else {
1863 mcp->mb[1] = loop_id << 8;
1864 }
1865
1866 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001867 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001869 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
1871 if (rval != QLA_SUCCESS) {
1872 /*EMPTY*/
1873 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001874 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 } else {
1876 /*EMPTY*/
1877 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001878 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 }
1880
1881 return rval;
1882}
1883
1884/*
1885 * qla2x00_full_login_lip
1886 * Issue full login LIP mailbox command.
1887 *
1888 * Input:
1889 * ha = adapter block pointer.
1890 * TARGET_QUEUE_LOCK must be released.
1891 * ADAPTER_STATE_LOCK must be released.
1892 *
1893 * Returns:
1894 * qla2x00 local function return status code.
1895 *
1896 * Context:
1897 * Kernel context.
1898 */
1899int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001900qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901{
1902 int rval;
1903 mbx_cmd_t mc;
1904 mbx_cmd_t *mcp = &mc;
1905
1906 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001907 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001910 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001911 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 mcp->mb[3] = 0;
1913 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1914 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001915 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001917 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
1919 if (rval != QLA_SUCCESS) {
1920 /*EMPTY*/
1921 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001922 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 } else {
1924 /*EMPTY*/
1925 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001926 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
1928
1929 return rval;
1930}
1931
1932/*
1933 * qla2x00_get_id_list
1934 *
1935 * Input:
1936 * ha = adapter block pointer.
1937 *
1938 * Returns:
1939 * qla2x00 local function return status code.
1940 *
1941 * Context:
1942 * Kernel context.
1943 */
1944int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001945qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 uint16_t *entries)
1947{
1948 int rval;
1949 mbx_cmd_t mc;
1950 mbx_cmd_t *mcp = &mc;
1951
1952 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001953 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
1955 if (id_list == NULL)
1956 return QLA_FUNCTION_FAILED;
1957
1958 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001959 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001960 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001961 mcp->mb[2] = MSW(id_list_dma);
1962 mcp->mb[3] = LSW(id_list_dma);
1963 mcp->mb[6] = MSW(MSD(id_list_dma));
1964 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001965 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001966 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001967 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001968 } else {
1969 mcp->mb[1] = MSW(id_list_dma);
1970 mcp->mb[2] = LSW(id_list_dma);
1971 mcp->mb[3] = MSW(MSD(id_list_dma));
1972 mcp->mb[6] = LSW(MSD(id_list_dma));
1973 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001976 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001978 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 if (rval != QLA_SUCCESS) {
1981 /*EMPTY*/
1982 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001983 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 } else {
1985 *entries = mcp->mb[1];
1986 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001987 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
1989
1990 return rval;
1991}
1992
1993/*
1994 * qla2x00_get_resource_cnts
1995 * Get current firmware resource counts.
1996 *
1997 * Input:
1998 * ha = adapter block pointer.
1999 *
2000 * Returns:
2001 * qla2x00 local function return status code.
2002 *
2003 * Context:
2004 * Kernel context.
2005 */
2006int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002007qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002008 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002009 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
2011 int rval;
2012 mbx_cmd_t mc;
2013 mbx_cmd_t *mcp = &mc;
2014
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002015 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2018 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002019 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002020 if (IS_QLA81XX(vha->hw))
2021 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002022 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002024 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
2026 if (rval != QLA_SUCCESS) {
2027 /*EMPTY*/
2028 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002029 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 } else {
2031 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002032 "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
2033 vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
2034 mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
2035 mcp->mb[12]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
2037 if (cur_xchg_cnt)
2038 *cur_xchg_cnt = mcp->mb[3];
2039 if (orig_xchg_cnt)
2040 *orig_xchg_cnt = mcp->mb[6];
2041 if (cur_iocb_cnt)
2042 *cur_iocb_cnt = mcp->mb[7];
2043 if (orig_iocb_cnt)
2044 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002045 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002046 *max_npiv_vports = mcp->mb[11];
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002047 if (IS_QLA81XX(vha->hw) && max_fcfs)
2048 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 }
2050
2051 return (rval);
2052}
2053
2054#if defined(QL_DEBUG_LEVEL_3)
2055/*
2056 * qla2x00_get_fcal_position_map
2057 * Get FCAL (LILP) position map using mailbox command
2058 *
2059 * Input:
2060 * ha = adapter state pointer.
2061 * pos_map = buffer pointer (can be NULL).
2062 *
2063 * Returns:
2064 * qla2x00 local function return status code.
2065 *
2066 * Context:
2067 * Kernel context.
2068 */
2069int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002070qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071{
2072 int rval;
2073 mbx_cmd_t mc;
2074 mbx_cmd_t *mcp = &mc;
2075 char *pmap;
2076 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002077 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078
Andrew Vasquez4b892582008-09-11 21:22:48 -07002079 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 if (pmap == NULL) {
2081 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002082 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 return QLA_MEMORY_ALLOC_FAILED;
2084 }
2085 memset(pmap, 0, FCAL_MAP_SIZE);
2086
2087 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2088 mcp->mb[2] = MSW(pmap_dma);
2089 mcp->mb[3] = LSW(pmap_dma);
2090 mcp->mb[6] = MSW(MSD(pmap_dma));
2091 mcp->mb[7] = LSW(MSD(pmap_dma));
2092 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2093 mcp->in_mb = MBX_1|MBX_0;
2094 mcp->buf_size = FCAL_MAP_SIZE;
2095 mcp->flags = MBX_DMA_IN;
2096 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002097 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 if (rval == QLA_SUCCESS) {
2100 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002101 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 mcp->mb[1], (unsigned)pmap[0]));
2103 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2104
2105 if (pos_map)
2106 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2107 }
2108 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2109
2110 if (rval != QLA_SUCCESS) {
2111 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002112 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002114 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 }
2116
2117 return rval;
2118}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002119#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002120
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002121/*
2122 * qla2x00_get_link_status
2123 *
2124 * Input:
2125 * ha = adapter block pointer.
2126 * loop_id = device loop ID.
2127 * ret_buf = pointer to link status return buffer.
2128 *
2129 * Returns:
2130 * 0 = success.
2131 * BIT_0 = mem alloc error.
2132 * BIT_1 = mailbox error.
2133 */
2134int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002135qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002136 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002137{
2138 int rval;
2139 mbx_cmd_t mc;
2140 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002141 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002142 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002143
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002144 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002145
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002146 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002147 mcp->mb[2] = MSW(stats_dma);
2148 mcp->mb[3] = LSW(stats_dma);
2149 mcp->mb[6] = MSW(MSD(stats_dma));
2150 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002151 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2152 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002153 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002154 mcp->mb[1] = loop_id;
2155 mcp->mb[4] = 0;
2156 mcp->mb[10] = 0;
2157 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2158 mcp->in_mb |= MBX_1;
2159 } else if (HAS_EXTENDED_IDS(ha)) {
2160 mcp->mb[1] = loop_id;
2161 mcp->mb[10] = 0;
2162 mcp->out_mb |= MBX_10|MBX_1;
2163 } else {
2164 mcp->mb[1] = loop_id << 8;
2165 mcp->out_mb |= MBX_1;
2166 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002167 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002168 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002169 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002170
2171 if (rval == QLA_SUCCESS) {
2172 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2173 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002174 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002175 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002176 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002177 /* Copy over data -- firmware data is LE. */
2178 dwords = offsetof(struct link_statistics, unused1) / 4;
2179 siter = diter = &stats->link_fail_cnt;
2180 while (dwords--)
2181 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002182 }
2183 } else {
2184 /* Failed. */
2185 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002186 vha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002187 }
2188
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002189 return rval;
2190}
2191
2192int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002193qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002194 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002195{
2196 int rval;
2197 mbx_cmd_t mc;
2198 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002199 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002200
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002201 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002202
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002203 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002204 mcp->mb[2] = MSW(stats_dma);
2205 mcp->mb[3] = LSW(stats_dma);
2206 mcp->mb[6] = MSW(MSD(stats_dma));
2207 mcp->mb[7] = LSW(MSD(stats_dma));
2208 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002209 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002210 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002211 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002212 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002213 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002214 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002215 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002216
2217 if (rval == QLA_SUCCESS) {
2218 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2219 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002220 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002221 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002222 } else {
2223 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002224 dwords = sizeof(struct link_statistics) / 4;
2225 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002226 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002227 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002228 }
2229 } else {
2230 /* Failed. */
2231 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002232 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002233 }
2234
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002235 return rval;
2236}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002237
2238int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002239qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002240{
2241 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002242 unsigned long flags = 0;
2243
2244 struct abort_entry_24xx *abt;
2245 dma_addr_t abt_dma;
2246 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002247 fc_port_t *fcport = sp->fcport;
2248 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002249 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002250 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002251
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002252 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002253
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002254 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002255 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002256 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002257 break;
2258 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002259 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002260 if (handle == MAX_OUTSTANDING_COMMANDS) {
2261 /* Command not found. */
2262 return QLA_FUNCTION_FAILED;
2263 }
2264
2265 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2266 if (abt == NULL) {
2267 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002268 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002269 return QLA_MEMORY_ALLOC_FAILED;
2270 }
2271 memset(abt, 0, sizeof(struct abort_entry_24xx));
2272
2273 abt->entry_type = ABORT_IOCB_TYPE;
2274 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002275 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002276 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2277 abt->handle_to_abort = handle;
2278 abt->port_id[0] = fcport->d_id.b.al_pa;
2279 abt->port_id[1] = fcport->d_id.b.area;
2280 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002281 abt->vp_index = fcport->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002282
2283 abt->req_que_no = cpu_to_le16(req->id);
2284
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002285 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002286 if (rval != QLA_SUCCESS) {
2287 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002288 __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002289 } else if (abt->entry_status != 0) {
2290 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002291 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002292 abt->entry_status));
2293 rval = QLA_FUNCTION_FAILED;
2294 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2295 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002296 "-- completion status (%x).\n", __func__, vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002297 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002298 rval = QLA_FUNCTION_FAILED;
2299 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002300 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002301 }
2302
2303 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2304
2305 return rval;
2306}
2307
2308struct tsk_mgmt_cmd {
2309 union {
2310 struct tsk_mgmt_entry tsk;
2311 struct sts_entry_24xx sts;
2312 } p;
2313};
2314
Andrew Vasquez523ec772008-04-03 13:13:24 -07002315static int
2316__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002317 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002318{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002319 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002320 struct tsk_mgmt_cmd *tsk;
2321 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002322 scsi_qla_host_t *vha;
2323 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002324 struct req_que *req;
2325 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002326
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08002327 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002328
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002329 vha = fcport->vha;
2330 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002331 req = vha->req;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002332 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002333 rsp = ha->rsp_q_map[tag + 1];
2334 else
2335 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002336 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002337 if (tsk == NULL) {
2338 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002339 "IOCB.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002340 return QLA_MEMORY_ALLOC_FAILED;
2341 }
2342 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2343
2344 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2345 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002346 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002347 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002348 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002349 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002350 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2351 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2352 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002353 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002354 if (type == TCF_LUN_RESET) {
2355 int_to_scsilun(l, &tsk->p.tsk.lun);
2356 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2357 sizeof(tsk->p.tsk.lun));
2358 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002359
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002360 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002361 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002362 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002363 "(%x).\n", __func__, vha->host_no, name, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002364 } else if (tsk->p.sts.entry_status != 0) {
2365 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002366 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002367 tsk->p.sts.entry_status));
2368 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002369 } else if (tsk->p.sts.comp_status !=
2370 __constant_cpu_to_le16(CS_COMPLETE)) {
2371 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2372 "-- completion status (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002373 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002374 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002375 }
2376
2377 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002378 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002379 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2380 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002381 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002382 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002383 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002384 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002385 }
2386
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002387 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002388
2389 return rval;
2390}
2391
Andrew Vasquez523ec772008-04-03 13:13:24 -07002392int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002393qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002394{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002395 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002396}
2397
2398int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002399qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002400{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002401 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002402}
2403
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002404int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002405qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002406{
2407 int rval;
2408 mbx_cmd_t mc;
2409 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002410 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002411
Andrew Vasquez68af0812008-05-12 22:21:13 -07002412 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002413 return QLA_FUNCTION_FAILED;
2414
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002415 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002416
2417 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2418 mcp->out_mb = MBX_0;
2419 mcp->in_mb = MBX_0;
2420 mcp->tov = 5;
2421 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002422 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002423
2424 if (rval != QLA_SUCCESS) {
2425 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002426 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002427 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002428 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002429 }
2430
2431 return rval;
2432}
2433
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002434/**
2435 * qla2x00_set_serdes_params() -
2436 * @ha: HA context
2437 *
2438 * Returns
2439 */
2440int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002441qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002442 uint16_t sw_em_2g, uint16_t sw_em_4g)
2443{
2444 int rval;
2445 mbx_cmd_t mc;
2446 mbx_cmd_t *mcp = &mc;
2447
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002448 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002449
2450 mcp->mb[0] = MBC_SERDES_PARAMS;
2451 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002452 mcp->mb[2] = sw_em_1g | BIT_15;
2453 mcp->mb[3] = sw_em_2g | BIT_15;
2454 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002455 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2456 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002457 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002458 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002459 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002460
2461 if (rval != QLA_SUCCESS) {
2462 /*EMPTY*/
2463 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002464 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002465 } else {
2466 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002467 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002468 }
2469
2470 return rval;
2471}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002472
2473int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002474qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002475{
2476 int rval;
2477 mbx_cmd_t mc;
2478 mbx_cmd_t *mcp = &mc;
2479
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002480 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002481 return QLA_FUNCTION_FAILED;
2482
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002483 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002484
2485 mcp->mb[0] = MBC_STOP_FIRMWARE;
2486 mcp->out_mb = MBX_0;
2487 mcp->in_mb = MBX_0;
2488 mcp->tov = 5;
2489 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002490 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002491
2492 if (rval != QLA_SUCCESS) {
2493 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002494 vha->host_no, rval));
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07002495 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2496 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002497 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002498 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002499 }
2500
2501 return rval;
2502}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002503
2504int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002505qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002506 uint16_t buffers)
2507{
2508 int rval;
2509 mbx_cmd_t mc;
2510 mbx_cmd_t *mcp = &mc;
2511
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002512 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002513 return QLA_FUNCTION_FAILED;
2514
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002515 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002516
2517 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002518 mcp->mb[1] = TC_EFT_ENABLE;
2519 mcp->mb[2] = LSW(eft_dma);
2520 mcp->mb[3] = MSW(eft_dma);
2521 mcp->mb[4] = LSW(MSD(eft_dma));
2522 mcp->mb[5] = MSW(MSD(eft_dma));
2523 mcp->mb[6] = buffers;
2524 mcp->mb[7] = TC_AEN_DISABLE;
2525 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002526 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002527 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002528 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002529 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002530 if (rval != QLA_SUCCESS) {
2531 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002532 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002533 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002534 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002535 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002536
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002537 return rval;
2538}
2539
2540int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002541qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002542{
2543 int rval;
2544 mbx_cmd_t mc;
2545 mbx_cmd_t *mcp = &mc;
2546
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002547 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002548 return QLA_FUNCTION_FAILED;
2549
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002550 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002551
2552 mcp->mb[0] = MBC_TRACE_CONTROL;
2553 mcp->mb[1] = TC_EFT_DISABLE;
2554 mcp->out_mb = MBX_1|MBX_0;
2555 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002556 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002557 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002558 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002559 if (rval != QLA_SUCCESS) {
2560 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002561 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002562 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002563 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002564 }
2565
2566 return rval;
2567}
2568
Andrew Vasquez88729e52006-06-23 16:10:50 -07002569int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002570qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002571 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2572{
2573 int rval;
2574 mbx_cmd_t mc;
2575 mbx_cmd_t *mcp = &mc;
2576
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002577 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002578 return QLA_FUNCTION_FAILED;
2579
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002580 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002581
2582 mcp->mb[0] = MBC_TRACE_CONTROL;
2583 mcp->mb[1] = TC_FCE_ENABLE;
2584 mcp->mb[2] = LSW(fce_dma);
2585 mcp->mb[3] = MSW(fce_dma);
2586 mcp->mb[4] = LSW(MSD(fce_dma));
2587 mcp->mb[5] = MSW(MSD(fce_dma));
2588 mcp->mb[6] = buffers;
2589 mcp->mb[7] = TC_AEN_DISABLE;
2590 mcp->mb[8] = 0;
2591 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2592 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2593 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2594 MBX_1|MBX_0;
2595 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002596 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002597 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002598 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002599 if (rval != QLA_SUCCESS) {
2600 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002601 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002602 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002603 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002604
2605 if (mb)
2606 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2607 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002608 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002609 }
2610
2611 return rval;
2612}
2613
2614int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002615qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002616{
2617 int rval;
2618 mbx_cmd_t mc;
2619 mbx_cmd_t *mcp = &mc;
2620
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002621 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002622 return QLA_FUNCTION_FAILED;
2623
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002624 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002625
2626 mcp->mb[0] = MBC_TRACE_CONTROL;
2627 mcp->mb[1] = TC_FCE_DISABLE;
2628 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2629 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2630 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2631 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002632 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002633 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002634 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002635 if (rval != QLA_SUCCESS) {
2636 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002637 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002638 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002639 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002640
2641 if (wr)
2642 *wr = (uint64_t) mcp->mb[5] << 48 |
2643 (uint64_t) mcp->mb[4] << 32 |
2644 (uint64_t) mcp->mb[3] << 16 |
2645 (uint64_t) mcp->mb[2];
2646 if (rd)
2647 *rd = (uint64_t) mcp->mb[9] << 48 |
2648 (uint64_t) mcp->mb[8] << 32 |
2649 (uint64_t) mcp->mb[7] << 16 |
2650 (uint64_t) mcp->mb[6];
2651 }
2652
2653 return rval;
2654}
2655
2656int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002657qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
Andrew Vasquez88729e52006-06-23 16:10:50 -07002658 uint16_t off, uint16_t count)
2659{
2660 int rval;
2661 mbx_cmd_t mc;
2662 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002663
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002664 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002665 return QLA_FUNCTION_FAILED;
2666
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002667 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002668
2669 mcp->mb[0] = MBC_READ_SFP;
2670 mcp->mb[1] = addr;
2671 mcp->mb[2] = MSW(sfp_dma);
2672 mcp->mb[3] = LSW(sfp_dma);
2673 mcp->mb[6] = MSW(MSD(sfp_dma));
2674 mcp->mb[7] = LSW(MSD(sfp_dma));
2675 mcp->mb[8] = count;
2676 mcp->mb[9] = off;
2677 mcp->mb[10] = 0;
2678 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2679 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002680 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002681 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002682 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez88729e52006-06-23 16:10:50 -07002683
2684 if (rval != QLA_SUCCESS) {
2685 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002686 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002687 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002688 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002689 }
2690
2691 return rval;
2692}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002693
2694int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002695qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002696 uint16_t port_speed, uint16_t *mb)
2697{
2698 int rval;
2699 mbx_cmd_t mc;
2700 mbx_cmd_t *mcp = &mc;
2701
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002702 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002703 return QLA_FUNCTION_FAILED;
2704
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002705 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002706
2707 mcp->mb[0] = MBC_PORT_PARAMS;
2708 mcp->mb[1] = loop_id;
2709 mcp->mb[2] = BIT_0;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002710 if (IS_QLA81XX(vha->hw))
2711 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2712 else
2713 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2714 mcp->mb[9] = vha->vp_idx;
2715 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2716 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002717 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002718 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002719 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002720
2721 /* Return mailbox statuses. */
2722 if (mb != NULL) {
2723 mb[0] = mcp->mb[0];
2724 mb[1] = mcp->mb[1];
2725 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002726 }
2727
2728 if (rval != QLA_SUCCESS) {
2729 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002730 vha->host_no, rval));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002731 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002732 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002733 }
2734
2735 return rval;
2736}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002737
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002738void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002739qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002740 struct vp_rpt_id_entry_24xx *rptid_entry)
2741{
2742 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07002743 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002744 struct qla_hw_data *ha = vha->hw;
2745 scsi_qla_host_t *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002746 scsi_qla_host_t *tvp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002747
2748 if (rptid_entry->entry_status != 0)
2749 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002750
2751 if (rptid_entry->format == 0) {
2752 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002753 " number of VPs acquired %d\n", __func__, vha->host_no,
Andrew Vasquez09ccbcc2009-08-04 23:38:21 -07002754 MSB(le16_to_cpu(rptid_entry->vp_count)),
2755 LSB(le16_to_cpu(rptid_entry->vp_count))));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002756 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2757 rptid_entry->port_id[2], rptid_entry->port_id[1],
2758 rptid_entry->port_id[0]));
2759 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07002760 vp_idx = LSB(stat);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002761 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2762 "- status %d - "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002763 "with port id %02x%02x%02x\n", __func__, vha->host_no,
Seokmann Juc6852c42008-04-24 15:21:29 -07002764 vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002765 rptid_entry->port_id[2], rptid_entry->port_id[1],
2766 rptid_entry->port_id[0]));
2767 if (vp_idx == 0)
2768 return;
2769
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002770 if (MSB(stat) == 1) {
2771 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2772 "VP[%d].\n", vha->host_no, vp_idx));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002773 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002774 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002775
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002776 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002777 if (vp_idx == vp->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002778 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002779 if (!vp)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002780 return;
2781
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002782 vp->d_id.b.domain = rptid_entry->port_id[2];
2783 vp->d_id.b.area = rptid_entry->port_id[1];
2784 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002785
2786 /*
2787 * Cannot configure here as we are still sitting on the
2788 * response queue. Handle it in dpc context.
2789 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002790 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2791 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002792
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002793 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002794 }
2795}
2796
2797/*
2798 * qla24xx_modify_vp_config
2799 * Change VP configuration for vha
2800 *
2801 * Input:
2802 * vha = adapter block pointer.
2803 *
2804 * Returns:
2805 * qla2xxx local function return status code.
2806 *
2807 * Context:
2808 * Kernel context.
2809 */
2810int
2811qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2812{
2813 int rval;
2814 struct vp_config_entry_24xx *vpmod;
2815 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002816 struct qla_hw_data *ha = vha->hw;
2817 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818
2819 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002820
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002821 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002822 if (!vpmod) {
2823 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002824 "IOCB.\n", __func__, vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002825 return QLA_MEMORY_ALLOC_FAILED;
2826 }
2827
2828 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2829 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2830 vpmod->entry_count = 1;
2831 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2832 vpmod->vp_count = 1;
2833 vpmod->vp_index1 = vha->vp_idx;
2834 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2835 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2836 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2837 vpmod->entry_count = 1;
2838
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002839 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002840 if (rval != QLA_SUCCESS) {
2841 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002842 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002843 } else if (vpmod->comp_status != 0) {
2844 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002845 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002846 vpmod->comp_status));
2847 rval = QLA_FUNCTION_FAILED;
2848 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2849 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002850 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002851 le16_to_cpu(vpmod->comp_status)));
2852 rval = QLA_FUNCTION_FAILED;
2853 } else {
2854 /* EMPTY */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002855 DEBUG11(printk("%s(%ld): done.\n", __func__,
2856 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002857 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2858 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002859 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002860
2861 return rval;
2862}
2863
2864/*
2865 * qla24xx_control_vp
2866 * Enable a virtual port for given host
2867 *
2868 * Input:
2869 * ha = adapter block pointer.
2870 * vhba = virtual adapter (unused)
2871 * index = index number for enabled VP
2872 *
2873 * Returns:
2874 * qla2xxx local function return status code.
2875 *
2876 * Context:
2877 * Kernel context.
2878 */
2879int
2880qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2881{
2882 int rval;
2883 int map, pos;
2884 struct vp_ctrl_entry_24xx *vce;
2885 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002886 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002887 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002888 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002889
2890 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002891 vha->host_no, vp_index));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002892
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002893 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002894 return QLA_PARAMETER_ERROR;
2895
2896 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2897 if (!vce) {
2898 DEBUG2_3(printk("%s(%ld): "
2899 "failed to allocate VP Control IOCB.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002900 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002901 return QLA_MEMORY_ALLOC_FAILED;
2902 }
2903 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2904
2905 vce->entry_type = VP_CTRL_IOCB_TYPE;
2906 vce->entry_count = 1;
2907 vce->command = cpu_to_le16(cmd);
2908 vce->vp_count = __constant_cpu_to_le16(1);
2909
2910 /* index map in firmware starts with 1; decrement index
2911 * this is ok as we never use index 0
2912 */
2913 map = (vp_index - 1) / 8;
2914 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002915 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002916 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002917 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002918
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002919 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002920 if (rval != QLA_SUCCESS) {
2921 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002922 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002923 printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002924 "(%x).\n", __func__, base_vha->host_no, rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002925 } else if (vce->entry_status != 0) {
2926 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002927 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002928 vce->entry_status));
2929 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002930 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002931 vce->entry_status);
2932 rval = QLA_FUNCTION_FAILED;
2933 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2934 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002935 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002936 le16_to_cpu(vce->comp_status)));
2937 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002938 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002939 le16_to_cpu(vce->comp_status));
2940 rval = QLA_FUNCTION_FAILED;
2941 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002942 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002943 }
2944
2945 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2946
2947 return rval;
2948}
2949
2950/*
2951 * qla2x00_send_change_request
2952 * Receive or disable RSCN request from fabric controller
2953 *
2954 * Input:
2955 * ha = adapter block pointer
2956 * format = registration format:
2957 * 0 - Reserved
2958 * 1 - Fabric detected registration
2959 * 2 - N_port detected registration
2960 * 3 - Full registration
2961 * FF - clear registration
2962 * vp_idx = Virtual port index
2963 *
2964 * Returns:
2965 * qla2x00 local function return status code.
2966 *
2967 * Context:
2968 * Kernel Context
2969 */
2970
2971int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002972qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002973 uint16_t vp_idx)
2974{
2975 int rval;
2976 mbx_cmd_t mc;
2977 mbx_cmd_t *mcp = &mc;
2978
2979 /*
2980 * This command is implicitly executed by firmware during login for the
2981 * physical hosts
2982 */
2983 if (vp_idx == 0)
2984 return QLA_FUNCTION_FAILED;
2985
2986 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2987 mcp->mb[1] = format;
2988 mcp->mb[9] = vp_idx;
2989 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2990 mcp->in_mb = MBX_0|MBX_1;
2991 mcp->tov = MBX_TOV_SECONDS;
2992 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002993 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002994
2995 if (rval == QLA_SUCCESS) {
2996 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2997 rval = BIT_1;
2998 }
2999 } else
3000 rval = BIT_1;
3001
3002 return rval;
3003}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003004
3005int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003006qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003007 uint32_t size)
3008{
3009 int rval;
3010 mbx_cmd_t mc;
3011 mbx_cmd_t *mcp = &mc;
3012
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003013 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003014
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003015 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003016 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3017 mcp->mb[8] = MSW(addr);
3018 mcp->out_mb = MBX_8|MBX_0;
3019 } else {
3020 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3021 mcp->out_mb = MBX_0;
3022 }
3023 mcp->mb[1] = LSW(addr);
3024 mcp->mb[2] = MSW(req_dma);
3025 mcp->mb[3] = LSW(req_dma);
3026 mcp->mb[6] = MSW(MSD(req_dma));
3027 mcp->mb[7] = LSW(MSD(req_dma));
3028 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003029 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003030 mcp->mb[4] = MSW(size);
3031 mcp->mb[5] = LSW(size);
3032 mcp->out_mb |= MBX_5|MBX_4;
3033 } else {
3034 mcp->mb[4] = LSW(size);
3035 mcp->out_mb |= MBX_4;
3036 }
3037
3038 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003039 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003040 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003041 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003042
3043 if (rval != QLA_SUCCESS) {
3044 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003045 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003046 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003047 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003048 }
3049
3050 return rval;
3051}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003052
3053/* 84XX Support **************************************************************/
3054
3055struct cs84xx_mgmt_cmd {
3056 union {
3057 struct verify_chip_entry_84xx req;
3058 struct verify_chip_rsp_84xx rsp;
3059 } p;
3060};
3061
3062int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003063qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003064{
3065 int rval, retry;
3066 struct cs84xx_mgmt_cmd *mn;
3067 dma_addr_t mn_dma;
3068 uint16_t options;
3069 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003070 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003071
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003072 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003073
3074 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3075 if (mn == NULL) {
3076 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003077 "IOCB.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003078 return QLA_MEMORY_ALLOC_FAILED;
3079 }
3080
3081 /* Force Update? */
3082 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3083 /* Diagnostic firmware? */
3084 /* options |= MENLO_DIAG_FW; */
3085 /* We update the firmware with only one data sequence. */
3086 options |= VCO_END_OF_DATA;
3087
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003088 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003089 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003090 memset(mn, 0, sizeof(*mn));
3091 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3092 mn->p.req.entry_count = 1;
3093 mn->p.req.options = cpu_to_le16(options);
3094
3095 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003096 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003097 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3098 sizeof(*mn)));
3099
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003100 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003101 if (rval != QLA_SUCCESS) {
3102 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003103 "IOCB (%x).\n", __func__, vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003104 goto verify_done;
3105 }
3106
3107 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003108 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003109 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3110 sizeof(*mn)));
3111
3112 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3113 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3114 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3115 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003116 vha->host_no, status[0], status[1]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003117
3118 if (status[0] != CS_COMPLETE) {
3119 rval = QLA_FUNCTION_FAILED;
3120 if (!(options & VCO_DONT_UPDATE_FW)) {
3121 DEBUG2_16(printk("%s(%ld): Firmware update "
3122 "failed. Retrying without update "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003123 "firmware.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003124 options |= VCO_DONT_UPDATE_FW;
3125 options &= ~VCO_FORCE_UPDATE;
3126 retry = 1;
3127 }
3128 } else {
3129 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003130 __func__, vha->host_no,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003131 le32_to_cpu(mn->p.rsp.fw_ver)));
3132
3133 /* NOTE: we only update OP firmware. */
3134 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3135 ha->cs84xx->op_fw_version =
3136 le32_to_cpu(mn->p.rsp.fw_ver);
3137 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3138 flags);
3139 }
3140 } while (retry);
3141
3142verify_done:
3143 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3144
3145 if (rval != QLA_SUCCESS) {
3146 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003147 vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003148 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003149 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003150 }
3151
3152 return rval;
3153}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003154
3155int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003156qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003157{
3158 int rval;
3159 unsigned long flags;
3160 mbx_cmd_t mc;
3161 mbx_cmd_t *mcp = &mc;
3162 struct device_reg_25xxmq __iomem *reg;
3163 struct qla_hw_data *ha = vha->hw;
3164
3165 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003166 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003167 mcp->mb[2] = MSW(LSD(req->dma));
3168 mcp->mb[3] = LSW(LSD(req->dma));
3169 mcp->mb[6] = MSW(MSD(req->dma));
3170 mcp->mb[7] = LSW(MSD(req->dma));
3171 mcp->mb[5] = req->length;
3172 if (req->rsp)
3173 mcp->mb[10] = req->rsp->id;
3174 mcp->mb[12] = req->qos;
3175 mcp->mb[11] = req->vp_idx;
3176 mcp->mb[13] = req->rid;
3177
3178 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3179 QLA_QUE_PAGE * req->id);
3180
3181 mcp->mb[4] = req->id;
3182 /* que in ptr index */
3183 mcp->mb[8] = 0;
3184 /* que out ptr index */
3185 mcp->mb[9] = 0;
3186 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3187 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3188 mcp->in_mb = MBX_0;
3189 mcp->flags = MBX_DMA_OUT;
3190 mcp->tov = 60;
3191
3192 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003193 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003194 WRT_REG_DWORD(&reg->req_q_in, 0);
3195 WRT_REG_DWORD(&reg->req_q_out, 0);
3196 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003197 req->req_q_in = &reg->req_q_in;
3198 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3200
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003201 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003202 if (rval != QLA_SUCCESS)
3203 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3204 __func__, vha->host_no, rval, mcp->mb[0]));
3205 return rval;
3206}
3207
3208int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003209qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003210{
3211 int rval;
3212 unsigned long flags;
3213 mbx_cmd_t mc;
3214 mbx_cmd_t *mcp = &mc;
3215 struct device_reg_25xxmq __iomem *reg;
3216 struct qla_hw_data *ha = vha->hw;
3217
3218 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003219 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003220 mcp->mb[2] = MSW(LSD(rsp->dma));
3221 mcp->mb[3] = LSW(LSD(rsp->dma));
3222 mcp->mb[6] = MSW(MSD(rsp->dma));
3223 mcp->mb[7] = LSW(MSD(rsp->dma));
3224 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003225 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003226 mcp->mb[13] = rsp->rid;
3227
3228 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3229 QLA_QUE_PAGE * rsp->id);
3230
3231 mcp->mb[4] = rsp->id;
3232 /* que in ptr index */
3233 mcp->mb[8] = 0;
3234 /* que out ptr index */
3235 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003236 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003237 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3238 mcp->in_mb = MBX_0;
3239 mcp->flags = MBX_DMA_OUT;
3240 mcp->tov = 60;
3241
3242 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003243 if (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003244 WRT_REG_DWORD(&reg->rsp_q_out, 0);
3245 WRT_REG_DWORD(&reg->rsp_q_in, 0);
3246 }
3247
3248 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3249
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003250 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003251 if (rval != QLA_SUCCESS)
3252 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3253 "mb0=%x.\n", __func__,
3254 vha->host_no, rval, mcp->mb[0]));
3255 return rval;
3256}
3257
Andrew Vasquez8a659572009-02-08 20:50:12 -08003258int
3259qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3260{
3261 int rval;
3262 mbx_cmd_t mc;
3263 mbx_cmd_t *mcp = &mc;
3264
3265 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3266
3267 mcp->mb[0] = MBC_IDC_ACK;
3268 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3269 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3270 mcp->in_mb = MBX_0;
3271 mcp->tov = MBX_TOV_SECONDS;
3272 mcp->flags = 0;
3273 rval = qla2x00_mailbox_command(vha, mcp);
3274
3275 if (rval != QLA_SUCCESS) {
3276 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3277 vha->host_no, rval, mcp->mb[0]));
3278 } else {
3279 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3280 }
3281
3282 return rval;
3283}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003284
3285int
3286qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3287{
3288 int rval;
3289 mbx_cmd_t mc;
3290 mbx_cmd_t *mcp = &mc;
3291
3292 if (!IS_QLA81XX(vha->hw))
3293 return QLA_FUNCTION_FAILED;
3294
3295 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3296
3297 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3298 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3299 mcp->out_mb = MBX_1|MBX_0;
3300 mcp->in_mb = MBX_1|MBX_0;
3301 mcp->tov = MBX_TOV_SECONDS;
3302 mcp->flags = 0;
3303 rval = qla2x00_mailbox_command(vha, mcp);
3304
3305 if (rval != QLA_SUCCESS) {
3306 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3307 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3308 } else {
3309 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3310 *sector_size = mcp->mb[1];
3311 }
3312
3313 return rval;
3314}
3315
3316int
3317qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3318{
3319 int rval;
3320 mbx_cmd_t mc;
3321 mbx_cmd_t *mcp = &mc;
3322
3323 if (!IS_QLA81XX(vha->hw))
3324 return QLA_FUNCTION_FAILED;
3325
3326 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3327
3328 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3329 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3330 FAC_OPT_CMD_WRITE_PROTECT;
3331 mcp->out_mb = MBX_1|MBX_0;
3332 mcp->in_mb = MBX_1|MBX_0;
3333 mcp->tov = MBX_TOV_SECONDS;
3334 mcp->flags = 0;
3335 rval = qla2x00_mailbox_command(vha, mcp);
3336
3337 if (rval != QLA_SUCCESS) {
3338 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3339 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3340 } else {
3341 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3342 }
3343
3344 return rval;
3345}
3346
3347int
3348qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3349{
3350 int rval;
3351 mbx_cmd_t mc;
3352 mbx_cmd_t *mcp = &mc;
3353
3354 if (!IS_QLA81XX(vha->hw))
3355 return QLA_FUNCTION_FAILED;
3356
3357 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3358
3359 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3360 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3361 mcp->mb[2] = LSW(start);
3362 mcp->mb[3] = MSW(start);
3363 mcp->mb[4] = LSW(finish);
3364 mcp->mb[5] = MSW(finish);
3365 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3366 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3367 mcp->tov = MBX_TOV_SECONDS;
3368 mcp->flags = 0;
3369 rval = qla2x00_mailbox_command(vha, mcp);
3370
3371 if (rval != QLA_SUCCESS) {
3372 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3373 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3374 mcp->mb[1], mcp->mb[2]));
3375 } else {
3376 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3377 }
3378
3379 return rval;
3380}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003381
3382int
3383qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3384{
3385 int rval = 0;
3386 mbx_cmd_t mc;
3387 mbx_cmd_t *mcp = &mc;
3388
3389 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3390
3391 mcp->mb[0] = MBC_RESTART_MPI_FW;
3392 mcp->out_mb = MBX_0;
3393 mcp->in_mb = MBX_0|MBX_1;
3394 mcp->tov = MBX_TOV_SECONDS;
3395 mcp->flags = 0;
3396 rval = qla2x00_mailbox_command(vha, mcp);
3397
3398 if (rval != QLA_SUCCESS) {
3399 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3400 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3401 } else {
3402 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3403 }
3404
3405 return rval;
3406}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003407
3408int
3409qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3410 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3411{
3412 int rval;
3413 mbx_cmd_t mc;
3414 mbx_cmd_t *mcp = &mc;
3415
3416 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3417
3418 mcp->mb[0] = MBC_READ_SFP;
3419 mcp->mb[1] = dev;
3420 mcp->mb[2] = MSW(sfp_dma);
3421 mcp->mb[3] = LSW(sfp_dma);
3422 mcp->mb[6] = MSW(MSD(sfp_dma));
3423 mcp->mb[7] = LSW(MSD(sfp_dma));
3424 mcp->mb[8] = len;
3425 mcp->mb[9] = adr;
3426 mcp->mb[10] = opt;
3427 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3428 mcp->in_mb = MBX_0;
3429 mcp->tov = MBX_TOV_SECONDS;
3430 mcp->flags = 0;
3431 rval = qla2x00_mailbox_command(vha, mcp);
3432
3433 if (opt & BIT_0)
3434 if (sfp)
3435 *sfp = mcp->mb[8];
3436
3437 if (rval != QLA_SUCCESS) {
3438 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3439 vha->host_no, rval, mcp->mb[0]));
3440 } else {
Andrew Vasquez76403352009-04-06 22:33:39 -07003441 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003442 }
3443
3444 return rval;
3445}
3446
3447int
3448qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3449 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3450{
3451 int rval;
3452 mbx_cmd_t mc;
3453 mbx_cmd_t *mcp = &mc;
3454
3455 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3456
3457 if (opt & BIT_0)
3458 if (sfp)
3459 len = *sfp;
3460
3461 mcp->mb[0] = MBC_WRITE_SFP;
3462 mcp->mb[1] = dev;
3463 mcp->mb[2] = MSW(sfp_dma);
3464 mcp->mb[3] = LSW(sfp_dma);
3465 mcp->mb[6] = MSW(MSD(sfp_dma));
3466 mcp->mb[7] = LSW(MSD(sfp_dma));
3467 mcp->mb[8] = len;
3468 mcp->mb[9] = adr;
3469 mcp->mb[10] = opt;
3470 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3471 mcp->in_mb = MBX_0;
3472 mcp->tov = MBX_TOV_SECONDS;
3473 mcp->flags = 0;
3474 rval = qla2x00_mailbox_command(vha, mcp);
3475
3476 if (rval != QLA_SUCCESS) {
3477 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3478 vha->host_no, rval, mcp->mb[0]));
3479 } else {
3480 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3481 }
3482
3483 return rval;
3484}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003485
3486int
3487qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3488 uint16_t size_in_bytes, uint16_t *actual_size)
3489{
3490 int rval;
3491 mbx_cmd_t mc;
3492 mbx_cmd_t *mcp = &mc;
3493
3494 if (!IS_QLA81XX(vha->hw))
3495 return QLA_FUNCTION_FAILED;
3496
3497 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3498
3499 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3500 mcp->mb[2] = MSW(stats_dma);
3501 mcp->mb[3] = LSW(stats_dma);
3502 mcp->mb[6] = MSW(MSD(stats_dma));
3503 mcp->mb[7] = LSW(MSD(stats_dma));
3504 mcp->mb[8] = size_in_bytes >> 2;
3505 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3506 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3507 mcp->tov = MBX_TOV_SECONDS;
3508 mcp->flags = 0;
3509 rval = qla2x00_mailbox_command(vha, mcp);
3510
3511 if (rval != QLA_SUCCESS) {
3512 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3513 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3514 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3515 } else {
3516 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3517
3518 *actual_size = mcp->mb[2] << 2;
3519 }
3520
3521 return rval;
3522}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003523
3524int
3525qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3526 uint16_t size)
3527{
3528 int rval;
3529 mbx_cmd_t mc;
3530 mbx_cmd_t *mcp = &mc;
3531
3532 if (!IS_QLA81XX(vha->hw))
3533 return QLA_FUNCTION_FAILED;
3534
3535 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3536
3537 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3538 mcp->mb[1] = 0;
3539 mcp->mb[2] = MSW(tlv_dma);
3540 mcp->mb[3] = LSW(tlv_dma);
3541 mcp->mb[6] = MSW(MSD(tlv_dma));
3542 mcp->mb[7] = LSW(MSD(tlv_dma));
3543 mcp->mb[8] = size;
3544 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3545 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3546 mcp->tov = MBX_TOV_SECONDS;
3547 mcp->flags = 0;
3548 rval = qla2x00_mailbox_command(vha, mcp);
3549
3550 if (rval != QLA_SUCCESS) {
3551 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3552 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3553 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3554 } else {
3555 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3556 }
3557
3558 return rval;
3559}
Andrew Vasquez18e75552009-06-03 09:55:30 -07003560
3561int
3562qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3563{
3564 int rval;
3565 mbx_cmd_t mc;
3566 mbx_cmd_t *mcp = &mc;
3567
3568 if (!IS_FWI2_CAPABLE(vha->hw))
3569 return QLA_FUNCTION_FAILED;
3570
3571 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3572
3573 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3574 mcp->mb[1] = LSW(risc_addr);
3575 mcp->mb[8] = MSW(risc_addr);
3576 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3577 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3578 mcp->tov = 30;
3579 mcp->flags = 0;
3580 rval = qla2x00_mailbox_command(vha, mcp);
3581 if (rval != QLA_SUCCESS) {
3582 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3583 vha->host_no, rval, mcp->mb[0]));
3584 } else {
3585 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3586 *data = mcp->mb[3] << 16 | mcp->mb[2];
3587 }
3588
3589 return rval;
3590}
3591
3592int
3593qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3594{
3595 int rval;
3596 mbx_cmd_t mc;
3597 mbx_cmd_t *mcp = &mc;
3598
3599 if (!IS_FWI2_CAPABLE(vha->hw))
3600 return QLA_FUNCTION_FAILED;
3601
3602 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3603
3604 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3605 mcp->mb[1] = LSW(risc_addr);
3606 mcp->mb[2] = LSW(data);
3607 mcp->mb[3] = MSW(data);
3608 mcp->mb[8] = MSW(risc_addr);
3609 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3610 mcp->in_mb = MBX_0;
3611 mcp->tov = 30;
3612 mcp->flags = 0;
3613 rval = qla2x00_mailbox_command(vha, mcp);
3614 if (rval != QLA_SUCCESS) {
3615 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3616 vha->host_no, rval, mcp->mb[0]));
3617 } else {
3618 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3619 }
3620
3621 return rval;
3622}