blob: 2f39e309393992525a8b3da790ad6443ea10bab0 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090010#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13/*
14 * qla2x00_mailbox_command
15 * Issue mailbox command and waits for completion.
16 *
17 * Input:
18 * ha = adapter block pointer.
19 * mcp = driver internal mbx struct pointer.
20 *
21 * Output:
22 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
23 *
24 * Returns:
25 * 0 : QLA_SUCCESS = cmd performed success
26 * 1 : QLA_FUNCTION_FAILED (error encountered)
27 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
28 *
29 * Context:
30 * Kernel context.
31 */
32static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080033qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070034{
35 int rval;
36 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070037 device_reg_t __iomem *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070038 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070039 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -070040 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 uint16_t *iptr;
42 uint16_t __iomem *optr;
43 uint32_t cnt;
44 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080046 struct qla_hw_data *ha = vha->hw;
47 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070048
Seokmann Jub9b12f72009-03-24 09:08:18 -070049 if (ha->pdev->error_state > pci_channel_io_frozen)
50 return QLA_FUNCTION_TIMEOUT;
51
Giridhar Malavalia9083012010-04-12 17:59:55 -070052 if (vha->device_flags & DFLG_DEV_FAILED) {
53 DEBUG2_3_11(qla_printk(KERN_WARNING, ha,
54 "%s(%ld): Device in failed state, "
55 "timeout MBX Exiting.\n",
56 __func__, base_vha->host_no));
57 return QLA_FUNCTION_TIMEOUT;
58 }
59
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070060 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080061 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
63 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080064 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070067
Andrew Vasquez85880802009-12-15 21:29:46 -080068 if (ha->flags.pci_channel_io_perm_failure) {
69 DEBUG(printk("%s(%ld): Perm failure on EEH, timeout MBX "
70 "Exiting.\n", __func__, vha->host_no));
71 return QLA_FUNCTION_TIMEOUT;
72 }
73
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070075 * Wait for active mailbox commands to finish by waiting at most tov
76 * seconds. This is to serialize actual issuing of mailbox cmds during
77 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080079 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
80 /* Timeout occurred. Return error. */
81 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
82 "Exiting.\n", __func__, base_vha->host_no));
83 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -070086 if (IS_QLA82XX(ha) && ha->flags.fw_hung) {
87 /* Setting Link-Down error */
88 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
89 rval = QLA_FUNCTION_FAILED;
90 goto premature_exit;
91 }
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 ha->flags.mbox_busy = 1;
94 /* Save mailbox command for debug */
95 ha->mcp = mcp;
96
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070097 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080098 base_vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
100 spin_lock_irqsave(&ha->hardware_lock, flags);
101
102 /* Load mailbox registers. */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700103 if (IS_QLA82XX(ha))
104 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
105 else if (IS_FWI2_CAPABLE(ha) && !IS_QLA82XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700106 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
107 else
108 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110 iptr = mcp->mb;
111 command = mcp->mb[0];
112 mboxes = mcp->out_mb;
113
114 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
115 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700116 optr =
117 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 if (mboxes & BIT_0)
119 WRT_REG_WORD(optr, *iptr);
120
121 mboxes >>= 1;
122 optr++;
123 iptr++;
124 }
125
126#if defined(QL_DEBUG_LEVEL_1)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700127 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800128 __func__, base_vha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
130 printk("\n");
131 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
132 printk("\n");
133 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
134 printk("\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800135 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
136 optr);
137 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138#endif
139
140 /* Issue set host interrupt command to send cmd out. */
141 ha->flags.mbox_int = 0;
142 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
143
144 /* Unlock mbx registers and wait for interrupt */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700145 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800146 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* Wait for mbx cmd completion until timeout */
149
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800150 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
152
Giridhar Malavalia9083012010-04-12 17:59:55 -0700153 if (IS_QLA82XX(ha)) {
154 if (RD_REG_DWORD(&reg->isp82.hint) &
155 HINT_MBX_INT_PENDING) {
156 spin_unlock_irqrestore(&ha->hardware_lock,
157 flags);
158 DEBUG2_3_11(printk(KERN_INFO
159 "%s(%ld): Pending Mailbox timeout. "
160 "Exiting.\n", __func__, base_vha->host_no));
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700161 rval = QLA_FUNCTION_TIMEOUT;
162 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700163 }
164 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
165 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700166 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
167 else
168 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 spin_unlock_irqrestore(&ha->hardware_lock, flags);
170
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800171 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700176 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800177 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Giridhar Malavalia9083012010-04-12 17:59:55 -0700179 if (IS_QLA82XX(ha)) {
180 if (RD_REG_DWORD(&reg->isp82.hint) &
181 HINT_MBX_INT_PENDING) {
182 spin_unlock_irqrestore(&ha->hardware_lock,
183 flags);
184 DEBUG2_3_11(printk(KERN_INFO
185 "%s(%ld): Pending Mailbox timeout. "
186 "Exiting.\n", __func__, base_vha->host_no));
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700187 rval = QLA_FUNCTION_TIMEOUT;
188 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700189 }
190 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
191 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700192 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
193 else
194 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
198 while (!ha->flags.mbox_int) {
199 if (time_after(jiffies, wait_time))
200 break;
201
202 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800203 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Andrew Vasquez85880802009-12-15 21:29:46 -0800205 if (!ha->flags.mbox_int &&
206 !(IS_QLA2200(ha) &&
207 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800208 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 } /* while */
Andrew Vasquez85880802009-12-15 21:29:46 -0800210 DEBUG17(qla_printk(KERN_WARNING, ha,
211 "Waited %d sec\n",
212 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 /* Check whether we timed out */
216 if (ha->flags.mbox_int) {
217 uint16_t *iptr2;
218
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700219 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800220 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 /* Got interrupt. Clear the flag. */
223 ha->flags.mbox_int = 0;
224 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
225
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700226 if (IS_QLA82XX(ha) && ha->flags.fw_hung) {
227 ha->flags.mbox_busy = 0;
228 /* Setting Link-Down error */
229 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
230 ha->mcp = NULL;
231 rval = QLA_FUNCTION_FAILED;
232 goto premature_exit;
233 }
234
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400235 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 /* Load return mailbox registers. */
239 iptr2 = mcp->mb;
240 iptr = (uint16_t *)&ha->mailbox_out[0];
241 mboxes = mcp->in_mb;
242 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
243 if (mboxes & BIT_0)
244 *iptr2 = *iptr;
245
246 mboxes >>= 1;
247 iptr2++;
248 iptr++;
249 }
250 } else {
251
252#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
253 defined(QL_DEBUG_LEVEL_11)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700254 uint16_t mb0;
255 uint32_t ictrl;
256
Andrew Vasqueze4289242007-07-19 15:05:56 -0700257 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700258 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
259 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
260 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700261 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700262 ictrl = RD_REG_WORD(&reg->isp.ictrl);
263 }
264 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800265 __func__, base_vha->host_no, command);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700266 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800267 base_vha->host_no, ictrl, jiffies);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700268 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800269 base_vha->host_no, mb0);
270 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271#endif
272
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 rval = QLA_FUNCTION_TIMEOUT;
274 }
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 ha->flags.mbox_busy = 0;
277
278 /* Clean up */
279 ha->mcp = NULL;
280
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800281 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700282 DEBUG11(printk("%s(%ld): checking for additional resp "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800283 "interrupt.\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800286 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 }
288
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700289 if (rval == QLA_FUNCTION_TIMEOUT &&
290 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800291 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
292 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700294 DEBUG(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800295 "isp_abort_needed.\n", __func__,
296 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700297 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800298 "isp_abort_needed.\n", __func__,
299 base_vha->host_no));
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700300
301 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
302 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
303 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
304
305 qla_printk(KERN_WARNING, ha,
306 "Mailbox command timeout occured. "
307 "Scheduling ISP " "abort. eeh_busy: 0x%x\n",
308 ha->flags.eeh_busy);
309 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
310 qla2xxx_wake_dpc(vha);
311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700314 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800315 __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700316 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800317 "abort_isp\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700319 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
320 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
321 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
322
323 qla_printk(KERN_WARNING, ha,
324 "Mailbox command timeout occured. "
325 "Issuing ISP abort.\n");
326
327 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
328 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
329 if (ha->isp_ops->abort_isp(vha)) {
330 /* Failed. retry later. */
331 set_bit(ISP_ABORT_NEEDED,
332 &vha->dpc_flags);
333 }
334 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
335 DEBUG(printk("%s(%ld): finished abort_isp\n",
336 __func__, vha->host_no));
337 DEBUG2_3_11(printk(
338 "%s(%ld): finished abort_isp\n",
339 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342 }
343
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700344premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800346 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700349 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800350 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700351 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800353 DEBUG11(printk("%s(%ld): done.\n", __func__,
354 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 return rval;
358}
359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800361qla2x00_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 -0800362 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
364 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800365 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 mbx_cmd_t mc;
367 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800369 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Andrew Vasqueze4289242007-07-19 15:05:56 -0700371 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800372 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
373 mcp->mb[8] = MSW(risc_addr);
374 mcp->out_mb = MBX_8|MBX_0;
375 } else {
376 mcp->mb[0] = MBC_LOAD_RISC_RAM;
377 mcp->out_mb = MBX_0;
378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 mcp->mb[1] = LSW(risc_addr);
380 mcp->mb[2] = MSW(req_dma);
381 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 mcp->mb[6] = MSW(MSD(req_dma));
383 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800384 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700385 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700386 mcp->mb[4] = MSW(risc_code_size);
387 mcp->mb[5] = LSW(risc_code_size);
388 mcp->out_mb |= MBX_5|MBX_4;
389 } else {
390 mcp->mb[4] = LSW(risc_code_size);
391 mcp->out_mb |= MBX_4;
392 }
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700395 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800397 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700400 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800401 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800403 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 }
405
406 return rval;
407}
408
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700409#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410/*
411 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700412 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 *
414 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700415 * ha = adapter block pointer.
416 * TARGET_QUEUE_LOCK must be released.
417 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 *
419 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700420 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 *
422 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700423 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 */
425int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800426qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427{
428 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800429 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 mbx_cmd_t mc;
431 mbx_cmd_t *mcp = &mc;
432
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800433 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700436 mcp->out_mb = MBX_0;
437 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700438 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700439 mcp->mb[1] = MSW(risc_addr);
440 mcp->mb[2] = LSW(risc_addr);
441 mcp->mb[3] = 0;
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700442 if (IS_QLA81XX(ha)) {
443 struct nvram_81xx *nv = ha->nvram;
444 mcp->mb[4] = (nv->enhanced_features &
445 EXTENDED_BB_CREDITS);
446 } else
447 mcp->mb[4] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700448 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700449 mcp->in_mb |= MBX_1;
450 } else {
451 mcp->mb[1] = LSW(risc_addr);
452 mcp->out_mb |= MBX_1;
453 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
454 mcp->mb[2] = 0;
455 mcp->out_mb |= MBX_2;
456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458
Ravi Anandb93480e2008-04-03 13:13:25 -0700459 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800461 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700463 if (rval != QLA_SUCCESS) {
464 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800465 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700466 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700467 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700468 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800469 __func__, vha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700470 } else {
471 DEBUG11(printk("%s(%ld): done.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800472 vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700473 }
474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 return rval;
477}
478
479/*
480 * qla2x00_get_fw_version
481 * Get firmware version.
482 *
483 * Input:
484 * ha: adapter state pointer.
485 * major: pointer for major number.
486 * minor: pointer for minor number.
487 * subminor: pointer for subminor number.
488 *
489 * Returns:
490 * qla2x00 local function return status code.
491 *
492 * Context:
493 * Kernel context.
494 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700495int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800496qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800497 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700498 uint32_t *mpi_caps, uint8_t *phy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
500 int rval;
501 mbx_cmd_t mc;
502 mbx_cmd_t *mcp = &mc;
503
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800504 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
507 mcp->out_mb = MBX_0;
508 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800509 if (IS_QLA81XX(vha->hw))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700510 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700512 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800513 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700514 if (rval != QLA_SUCCESS)
515 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 /* Return mailbox data. */
518 *major = mcp->mb[1];
519 *minor = mcp->mb[2];
520 *subminor = mcp->mb[3];
521 *attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800522 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 *memory = 0x1FFFF; /* Defaults to 128KB. */
524 else
525 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800526 if (IS_QLA81XX(vha->hw)) {
Andrew Vasquez55a96152009-03-24 09:08:03 -0700527 mpi[0] = mcp->mb[10] & 0xff;
528 mpi[1] = mcp->mb[11] >> 8;
529 mpi[2] = mcp->mb[11] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800530 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
Andrew Vasquez55a96152009-03-24 09:08:03 -0700531 phy[0] = mcp->mb[8] & 0xff;
532 phy[1] = mcp->mb[9] >> 8;
533 phy[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800534 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700535failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 if (rval != QLA_SUCCESS) {
537 /*EMPTY*/
538 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800539 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 } else {
541 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800542 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700544 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545}
546
547/*
548 * qla2x00_get_fw_options
549 * Set firmware options.
550 *
551 * Input:
552 * ha = adapter block pointer.
553 * fwopt = pointer for firmware options.
554 *
555 * Returns:
556 * qla2x00 local function return status code.
557 *
558 * Context:
559 * Kernel context.
560 */
561int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800562qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
564 int rval;
565 mbx_cmd_t mc;
566 mbx_cmd_t *mcp = &mc;
567
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800568 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
571 mcp->out_mb = MBX_0;
572 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700573 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800575 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
577 if (rval != QLA_SUCCESS) {
578 /*EMPTY*/
579 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800580 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700582 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 fwopts[1] = mcp->mb[1];
584 fwopts[2] = mcp->mb[2];
585 fwopts[3] = mcp->mb[3];
586
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800587 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 }
589
590 return rval;
591}
592
593
594/*
595 * qla2x00_set_fw_options
596 * Set firmware options.
597 *
598 * Input:
599 * ha = adapter block pointer.
600 * fwopt = pointer for firmware options.
601 *
602 * Returns:
603 * qla2x00 local function return status code.
604 *
605 * Context:
606 * Kernel context.
607 */
608int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800609qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
611 int rval;
612 mbx_cmd_t mc;
613 mbx_cmd_t *mcp = &mc;
614
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800615 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
618 mcp->mb[1] = fwopts[1];
619 mcp->mb[2] = fwopts[2];
620 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700621 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800623 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700624 mcp->in_mb |= MBX_1;
625 } else {
626 mcp->mb[10] = fwopts[10];
627 mcp->mb[11] = fwopts[11];
628 mcp->mb[12] = 0; /* Undocumented, but used */
629 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
630 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700631 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800633 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700635 fwopts[0] = mcp->mb[0];
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if (rval != QLA_SUCCESS) {
638 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700639 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800640 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 } else {
642 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800643 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645
646 return rval;
647}
648
649/*
650 * qla2x00_mbx_reg_test
651 * Mailbox register wrap test.
652 *
653 * Input:
654 * ha = adapter block pointer.
655 * TARGET_QUEUE_LOCK must be released.
656 * ADAPTER_STATE_LOCK must be released.
657 *
658 * Returns:
659 * qla2x00 local function return status code.
660 *
661 * Context:
662 * Kernel context.
663 */
664int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800665qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666{
667 int rval;
668 mbx_cmd_t mc;
669 mbx_cmd_t *mcp = &mc;
670
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800671 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
674 mcp->mb[1] = 0xAAAA;
675 mcp->mb[2] = 0x5555;
676 mcp->mb[3] = 0xAA55;
677 mcp->mb[4] = 0x55AA;
678 mcp->mb[5] = 0xA5A5;
679 mcp->mb[6] = 0x5A5A;
680 mcp->mb[7] = 0x2525;
681 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
682 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 -0700683 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800685 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 if (rval == QLA_SUCCESS) {
688 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
689 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
690 rval = QLA_FUNCTION_FAILED;
691 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
692 mcp->mb[7] != 0x2525)
693 rval = QLA_FUNCTION_FAILED;
694 }
695
696 if (rval != QLA_SUCCESS) {
697 /*EMPTY*/
698 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800699 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 } else {
701 /*EMPTY*/
702 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800703 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 }
705
706 return rval;
707}
708
709/*
710 * qla2x00_verify_checksum
711 * Verify firmware checksum.
712 *
713 * Input:
714 * ha = adapter block pointer.
715 * TARGET_QUEUE_LOCK must be released.
716 * ADAPTER_STATE_LOCK must be released.
717 *
718 * Returns:
719 * qla2x00 local function return status code.
720 *
721 * Context:
722 * Kernel context.
723 */
724int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800725qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726{
727 int rval;
728 mbx_cmd_t mc;
729 mbx_cmd_t *mcp = &mc;
730
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800731 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732
733 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700734 mcp->out_mb = MBX_0;
735 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800736 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700737 mcp->mb[1] = MSW(risc_addr);
738 mcp->mb[2] = LSW(risc_addr);
739 mcp->out_mb |= MBX_2|MBX_1;
740 mcp->in_mb |= MBX_2|MBX_1;
741 } else {
742 mcp->mb[1] = LSW(risc_addr);
743 mcp->out_mb |= MBX_1;
744 mcp->in_mb |= MBX_1;
745 }
746
Ravi Anandb93480e2008-04-03 13:13:25 -0700747 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800749 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700752 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800753 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
Andrew Vasqueze4289242007-07-19 15:05:56 -0700754 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800756 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758
759 return rval;
760}
761
762/*
763 * qla2x00_issue_iocb
764 * Issue IOCB using mailbox command
765 *
766 * Input:
767 * ha = adapter state pointer.
768 * buffer = buffer pointer.
769 * phys_addr = physical address of buffer.
770 * size = size of buffer.
771 * TARGET_QUEUE_LOCK must be released.
772 * ADAPTER_STATE_LOCK must be released.
773 *
774 * Returns:
775 * qla2x00 local function return status code.
776 *
777 * Context:
778 * Kernel context.
779 */
Giridhar Malavali6e980162010-03-19 17:03:58 -0700780int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800781qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700782 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783{
784 int rval;
785 mbx_cmd_t mc;
786 mbx_cmd_t *mcp = &mc;
787
788 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
789 mcp->mb[1] = 0;
790 mcp->mb[2] = MSW(phys_addr);
791 mcp->mb[3] = LSW(phys_addr);
792 mcp->mb[6] = MSW(MSD(phys_addr));
793 mcp->mb[7] = LSW(MSD(phys_addr));
794 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
795 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700796 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800798 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 if (rval != QLA_SUCCESS) {
801 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700802 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800803 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700805 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
806
807 /* Mask reserved bits. */
808 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800809 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811
812 return rval;
813}
814
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700815int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800816qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700817 size_t size)
818{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800819 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700820 MBX_TOV_SECONDS);
821}
822
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823/*
824 * qla2x00_abort_command
825 * Abort command aborts a specified IOCB.
826 *
827 * Input:
828 * ha = adapter block pointer.
829 * sp = SB structure pointer.
830 *
831 * Returns:
832 * qla2x00 local function return status code.
833 *
834 * Context:
835 * Kernel context.
836 */
837int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700838qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839{
840 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800842 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 mbx_cmd_t mc;
844 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700845 fc_port_t *fcport = sp->fcport;
846 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800847 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700848 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800850 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700852 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800854 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 break;
856 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700857 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
859 if (handle == MAX_OUTSTANDING_COMMANDS) {
860 /* command not found */
861 return QLA_FUNCTION_FAILED;
862 }
863
864 mcp->mb[0] = MBC_ABORT_COMMAND;
865 if (HAS_EXTENDED_IDS(ha))
866 mcp->mb[1] = fcport->loop_id;
867 else
868 mcp->mb[1] = fcport->loop_id << 8;
869 mcp->mb[2] = (uint16_t)handle;
870 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500871 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
873 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700874 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800876 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
878 if (rval != QLA_SUCCESS) {
879 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800880 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800883 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 }
885
886 return rval;
887}
888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700890qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700892 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 mbx_cmd_t mc;
894 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800896 struct req_que *req;
897 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800899 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700900
Andrew Vasquez523ec772008-04-03 13:13:24 -0700901 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800902 vha = fcport->vha;
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700903 req = vha->hw->req_q_map[0];
904 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700906 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800907 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 mcp->mb[1] = fcport->loop_id;
909 mcp->mb[10] = 0;
910 mcp->out_mb |= MBX_10;
911 } else {
912 mcp->mb[1] = fcport->loop_id << 8;
913 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800914 mcp->mb[2] = vha->hw->loop_reset_delay;
915 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
917 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700918 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800920 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700922 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800923 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700924 }
925
926 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800927 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
928 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700929 if (rval2 != QLA_SUCCESS) {
930 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800931 "(%x).\n", __func__, vha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800933 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700934 }
935
936 return rval;
937}
938
939int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700940qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700941{
942 int rval, rval2;
943 mbx_cmd_t mc;
944 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800945 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800946 struct req_que *req;
947 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700948
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800949 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700950
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800951 vha = fcport->vha;
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700952 req = vha->hw->req_q_map[0];
953 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700954 mcp->mb[0] = MBC_LUN_RESET;
955 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800956 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700957 mcp->mb[1] = fcport->loop_id;
958 else
959 mcp->mb[1] = fcport->loop_id << 8;
960 mcp->mb[2] = l;
961 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800962 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700963
964 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700965 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700966 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800967 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700968 if (rval != QLA_SUCCESS) {
969 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800970 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700971 }
972
973 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800974 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
975 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700976 if (rval2 != QLA_SUCCESS) {
977 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800978 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700979 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800980 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
982
983 return rval;
984}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 * qla2x00_get_adapter_id
988 * Get adapter ID and topology.
989 *
990 * Input:
991 * ha = adapter block pointer.
992 * id = pointer for loop ID.
993 * al_pa = pointer for AL_PA.
994 * area = pointer for area.
995 * domain = pointer for domain.
996 * top = pointer for topology.
997 * TARGET_QUEUE_LOCK must be released.
998 * ADAPTER_STATE_LOCK must be released.
999 *
1000 * Returns:
1001 * qla2x00 local function return status code.
1002 *
1003 * Context:
1004 * Kernel context.
1005 */
1006int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001007qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001008 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
1010 int rval;
1011 mbx_cmd_t mc;
1012 mbx_cmd_t *mcp = &mc;
1013
1014 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001015 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
1017 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001018 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001019 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001020 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001021 if (IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001022 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -07001023 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001025 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001026 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1027 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001028 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1029 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
1031 /* Return data. */
1032 *id = mcp->mb[1];
1033 *al_pa = LSB(mcp->mb[2]);
1034 *area = MSB(mcp->mb[2]);
1035 *domain = LSB(mcp->mb[3]);
1036 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001037 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 if (rval != QLA_SUCCESS) {
1040 /*EMPTY*/
1041 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001042 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001045 vha->host_no));
Andrew Vasquezbad70012009-04-06 22:33:38 -07001046
Giridhar Malavalia9083012010-04-12 17:59:55 -07001047 if (IS_QLA8XXX_TYPE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001048 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1049 vha->fcoe_fcf_idx = mcp->mb[10];
1050 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1051 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1052 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1053 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1054 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1055 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1056 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058
1059 return rval;
1060}
1061
1062/*
1063 * qla2x00_get_retry_cnt
1064 * Get current firmware login retry count and delay.
1065 *
1066 * Input:
1067 * ha = adapter block pointer.
1068 * retry_cnt = pointer to login retry count.
1069 * tov = pointer to login timeout value.
1070 *
1071 * Returns:
1072 * qla2x00 local function return status code.
1073 *
1074 * Context:
1075 * Kernel context.
1076 */
1077int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001078qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 uint16_t *r_a_tov)
1080{
1081 int rval;
1082 uint16_t ratov;
1083 mbx_cmd_t mc;
1084 mbx_cmd_t *mcp = &mc;
1085
1086 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001087 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1090 mcp->out_mb = MBX_0;
1091 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001092 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001094 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 if (rval != QLA_SUCCESS) {
1097 /*EMPTY*/
1098 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001099 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 } else {
1101 /* Convert returned data and check our values. */
1102 *r_a_tov = mcp->mb[3] / 2;
1103 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1104 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1105 /* Update to the larger values */
1106 *retry_cnt = (uint8_t)mcp->mb[1];
1107 *tov = ratov;
1108 }
1109
1110 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001111 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113
1114 return rval;
1115}
1116
1117/*
1118 * qla2x00_init_firmware
1119 * Initialize adapter firmware.
1120 *
1121 * Input:
1122 * ha = adapter block pointer.
1123 * dptr = Initialization control block pointer.
1124 * size = size of initialization control block.
1125 * TARGET_QUEUE_LOCK must be released.
1126 * ADAPTER_STATE_LOCK must be released.
1127 *
1128 * Returns:
1129 * qla2x00 local function return status code.
1130 *
1131 * Context:
1132 * Kernel context.
1133 */
1134int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001135qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136{
1137 int rval;
1138 mbx_cmd_t mc;
1139 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001140 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001143 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Giridhar Malavalia9083012010-04-12 17:59:55 -07001145 if (IS_QLA82XX(ha) && ql2xdbwr)
1146 qla82xx_wr_32(ha, ha->nxdb_wr_ptr,
1147 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1148
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001149 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001150 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1151 else
1152 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1153
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001154 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 mcp->mb[2] = MSW(ha->init_cb_dma);
1156 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1158 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001159 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1160 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1161 mcp->mb[1] = BIT_0;
1162 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1163 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1164 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1165 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1166 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1167 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1168 }
1169 mcp->in_mb = MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 mcp->buf_size = size;
1171 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001172 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001173 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
1175 if (rval != QLA_SUCCESS) {
1176 /*EMPTY*/
1177 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1178 "mb0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001179 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 } else {
1181 /*EMPTY*/
1182 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001183 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 }
1185
1186 return rval;
1187}
1188
1189/*
1190 * qla2x00_get_port_database
1191 * Issue normal/enhanced get port database mailbox command
1192 * and copy device name as necessary.
1193 *
1194 * Input:
1195 * ha = adapter state pointer.
1196 * dev = structure pointer.
1197 * opt = enhanced cmd option byte.
1198 *
1199 * Returns:
1200 * qla2x00 local function return status code.
1201 *
1202 * Context:
1203 * Kernel context.
1204 */
1205int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001206qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
1208 int rval;
1209 mbx_cmd_t mc;
1210 mbx_cmd_t *mcp = &mc;
1211 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001212 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001214 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001216 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001218 pd24 = NULL;
1219 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001221 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001222 "structure.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 return QLA_MEMORY_ALLOC_FAILED;
1224 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001225 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001227 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001228 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 mcp->mb[2] = MSW(pd_dma);
1231 mcp->mb[3] = LSW(pd_dma);
1232 mcp->mb[6] = MSW(MSD(pd_dma));
1233 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001234 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001235 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001237 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001238 mcp->mb[1] = fcport->loop_id;
1239 mcp->mb[10] = opt;
1240 mcp->out_mb |= MBX_10|MBX_1;
1241 mcp->in_mb |= MBX_1;
1242 } else if (HAS_EXTENDED_IDS(ha)) {
1243 mcp->mb[1] = fcport->loop_id;
1244 mcp->mb[10] = opt;
1245 mcp->out_mb |= MBX_10|MBX_1;
1246 } else {
1247 mcp->mb[1] = fcport->loop_id << 8 | opt;
1248 mcp->out_mb |= MBX_1;
1249 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001250 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1251 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 mcp->flags = MBX_DMA_IN;
1253 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001254 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 if (rval != QLA_SUCCESS)
1256 goto gpd_error_out;
1257
Andrew Vasqueze4289242007-07-19 15:05:56 -07001258 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001259 pd24 = (struct port_database_24xx *) pd;
1260
1261 /* Check for logged in state. */
1262 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1263 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1264 DEBUG2(printk("%s(%ld): Unable to verify "
1265 "login-state (%x/%x) for loop_id %x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001266 __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001267 pd24->current_login_state,
1268 pd24->last_login_state, fcport->loop_id));
1269 rval = QLA_FUNCTION_FAILED;
1270 goto gpd_error_out;
1271 }
1272
1273 /* Names are little-endian. */
1274 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1275 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1276
1277 /* Get port_id of device. */
1278 fcport->d_id.b.domain = pd24->port_id[0];
1279 fcport->d_id.b.area = pd24->port_id[1];
1280 fcport->d_id.b.al_pa = pd24->port_id[2];
1281 fcport->d_id.b.rsvd_1 = 0;
1282
1283 /* If not target must be initiator or unknown type. */
1284 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1285 fcport->port_type = FCT_INITIATOR;
1286 else
1287 fcport->port_type = FCT_TARGET;
1288 } else {
1289 /* Check for logged in state. */
1290 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1291 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1292 rval = QLA_FUNCTION_FAILED;
1293 goto gpd_error_out;
1294 }
1295
1296 /* Names are little-endian. */
1297 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1298 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1299
1300 /* Get port_id of device. */
1301 fcport->d_id.b.domain = pd->port_id[0];
1302 fcport->d_id.b.area = pd->port_id[3];
1303 fcport->d_id.b.al_pa = pd->port_id[2];
1304 fcport->d_id.b.rsvd_1 = 0;
1305
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001306 /* If not target must be initiator or unknown type. */
1307 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1308 fcport->port_type = FCT_INITIATOR;
1309 else
1310 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001311
1312 /* Passback COS information. */
1313 fcport->supported_classes = (pd->options & BIT_4) ?
1314 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 }
1316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317gpd_error_out:
1318 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1319
1320 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001321 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001322 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001324 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 }
1326
1327 return rval;
1328}
1329
1330/*
1331 * qla2x00_get_firmware_state
1332 * Get adapter firmware state.
1333 *
1334 * Input:
1335 * ha = adapter block pointer.
1336 * dptr = pointer for firmware state.
1337 * TARGET_QUEUE_LOCK must be released.
1338 * ADAPTER_STATE_LOCK must be released.
1339 *
1340 * Returns:
1341 * qla2x00 local function return status code.
1342 *
1343 * Context:
1344 * Kernel context.
1345 */
1346int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001347qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348{
1349 int rval;
1350 mbx_cmd_t mc;
1351 mbx_cmd_t *mcp = &mc;
1352
1353 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001354 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
1356 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1357 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001358 if (IS_FWI2_CAPABLE(vha->hw))
1359 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1360 else
1361 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001362 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001364 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001366 /* Return firmware states. */
1367 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001368 if (IS_FWI2_CAPABLE(vha->hw)) {
1369 states[1] = mcp->mb[2];
1370 states[2] = mcp->mb[3];
1371 states[3] = mcp->mb[4];
1372 states[4] = mcp->mb[5];
1373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 if (rval != QLA_SUCCESS) {
1376 /*EMPTY*/
1377 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001378 "failed=%x.\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 } else {
1380 /*EMPTY*/
1381 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001382 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
1384
1385 return rval;
1386}
1387
1388/*
1389 * qla2x00_get_port_name
1390 * Issue get port name mailbox command.
1391 * Returned name is in big endian format.
1392 *
1393 * Input:
1394 * ha = adapter block pointer.
1395 * loop_id = loop ID of device.
1396 * name = pointer for name.
1397 * TARGET_QUEUE_LOCK must be released.
1398 * ADAPTER_STATE_LOCK must be released.
1399 *
1400 * Returns:
1401 * qla2x00 local function return status code.
1402 *
1403 * Context:
1404 * Kernel context.
1405 */
1406int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001407qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 uint8_t opt)
1409{
1410 int rval;
1411 mbx_cmd_t mc;
1412 mbx_cmd_t *mcp = &mc;
1413
1414 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001415 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
1417 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001418 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001419 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001420 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 mcp->mb[1] = loop_id;
1422 mcp->mb[10] = opt;
1423 mcp->out_mb |= MBX_10;
1424 } else {
1425 mcp->mb[1] = loop_id << 8 | opt;
1426 }
1427
1428 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001429 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001431 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
1433 if (rval != QLA_SUCCESS) {
1434 /*EMPTY*/
1435 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001436 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 } else {
1438 if (name != NULL) {
1439 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001440 name[0] = MSB(mcp->mb[2]);
1441 name[1] = LSB(mcp->mb[2]);
1442 name[2] = MSB(mcp->mb[3]);
1443 name[3] = LSB(mcp->mb[3]);
1444 name[4] = MSB(mcp->mb[6]);
1445 name[5] = LSB(mcp->mb[6]);
1446 name[6] = MSB(mcp->mb[7]);
1447 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 }
1449
1450 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001451 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 }
1453
1454 return rval;
1455}
1456
1457/*
1458 * qla2x00_lip_reset
1459 * Issue LIP reset mailbox command.
1460 *
1461 * Input:
1462 * ha = adapter block pointer.
1463 * TARGET_QUEUE_LOCK must be released.
1464 * ADAPTER_STATE_LOCK must be released.
1465 *
1466 * Returns:
1467 * qla2x00 local function return status code.
1468 *
1469 * Context:
1470 * Kernel context.
1471 */
1472int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001473qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 int rval;
1476 mbx_cmd_t mc;
1477 mbx_cmd_t *mcp = &mc;
1478
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001479 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Giridhar Malavalia9083012010-04-12 17:59:55 -07001481 if (IS_QLA8XXX_TYPE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001482 /* Logout across all FCFs. */
1483 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1484 mcp->mb[1] = BIT_1;
1485 mcp->mb[2] = 0;
1486 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1487 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001488 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001489 mcp->mb[1] = BIT_6;
1490 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001491 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001492 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001494 mcp->mb[0] = MBC_LIP_RESET;
1495 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001496 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001497 mcp->mb[1] = 0x00ff;
1498 mcp->mb[10] = 0;
1499 mcp->out_mb |= MBX_10;
1500 } else {
1501 mcp->mb[1] = 0xff00;
1502 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001503 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001504 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001507 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001509 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511 if (rval != QLA_SUCCESS) {
1512 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001513 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001514 __func__, vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 } else {
1516 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001517 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
1519
1520 return rval;
1521}
1522
1523/*
1524 * qla2x00_send_sns
1525 * Send SNS command.
1526 *
1527 * Input:
1528 * ha = adapter block pointer.
1529 * sns = pointer for command.
1530 * cmd_size = command size.
1531 * buf_size = response/command size.
1532 * TARGET_QUEUE_LOCK must be released.
1533 * ADAPTER_STATE_LOCK must be released.
1534 *
1535 * Returns:
1536 * qla2x00 local function return status code.
1537 *
1538 * Context:
1539 * Kernel context.
1540 */
1541int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001542qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 uint16_t cmd_size, size_t buf_size)
1544{
1545 int rval;
1546 mbx_cmd_t mc;
1547 mbx_cmd_t *mcp = &mc;
1548
1549 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001550 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001553 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1554 mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1557 mcp->mb[1] = cmd_size;
1558 mcp->mb[2] = MSW(sns_phys_address);
1559 mcp->mb[3] = LSW(sns_phys_address);
1560 mcp->mb[6] = MSW(MSD(sns_phys_address));
1561 mcp->mb[7] = LSW(MSD(sns_phys_address));
1562 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1563 mcp->in_mb = MBX_0|MBX_1;
1564 mcp->buf_size = buf_size;
1565 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001566 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1567 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 if (rval != QLA_SUCCESS) {
1570 /*EMPTY*/
1571 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001572 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001574 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 } else {
1576 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001577 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 }
1579
1580 return rval;
1581}
1582
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001583int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001584qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001585 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1586{
1587 int rval;
1588
1589 struct logio_entry_24xx *lg;
1590 dma_addr_t lg_dma;
1591 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001592 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001593 struct req_que *req;
1594 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001595
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001596 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001597
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001598 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001599 req = ha->req_q_map[0];
1600 else
1601 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001602 rsp = req->rsp;
1603
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001604 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1605 if (lg == NULL) {
1606 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001607 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001608 return QLA_MEMORY_ALLOC_FAILED;
1609 }
1610 memset(lg, 0, sizeof(struct logio_entry_24xx));
1611
1612 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1613 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001614 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001615 lg->nport_handle = cpu_to_le16(loop_id);
1616 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1617 if (opt & BIT_0)
1618 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001619 if (opt & BIT_1)
1620 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001621 lg->port_id[0] = al_pa;
1622 lg->port_id[1] = area;
1623 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001624 lg->vp_index = vha->vp_idx;
1625 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001626 if (rval != QLA_SUCCESS) {
1627 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001628 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001629 } else if (lg->entry_status != 0) {
1630 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001631 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001632 lg->entry_status));
1633 rval = QLA_FUNCTION_FAILED;
1634 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1635 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1636 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1637
1638 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1639 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001640 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001641 iop[1]));
1642
1643 switch (iop[0]) {
1644 case LSC_SCODE_PORTID_USED:
1645 mb[0] = MBS_PORT_ID_USED;
1646 mb[1] = LSW(iop[1]);
1647 break;
1648 case LSC_SCODE_NPORT_USED:
1649 mb[0] = MBS_LOOP_ID_USED;
1650 break;
1651 case LSC_SCODE_NOLINK:
1652 case LSC_SCODE_NOIOCB:
1653 case LSC_SCODE_NOXCB:
1654 case LSC_SCODE_CMD_FAILED:
1655 case LSC_SCODE_NOFABRIC:
1656 case LSC_SCODE_FW_NOT_READY:
1657 case LSC_SCODE_NOT_LOGGED_IN:
1658 case LSC_SCODE_NOPCB:
1659 case LSC_SCODE_ELS_REJECT:
1660 case LSC_SCODE_CMD_PARAM_ERR:
1661 case LSC_SCODE_NONPORT:
1662 case LSC_SCODE_LOGGED_IN:
1663 case LSC_SCODE_NOFLOGI_ACC:
1664 default:
1665 mb[0] = MBS_COMMAND_ERROR;
1666 break;
1667 }
1668 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001669 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001670
1671 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1672
1673 mb[0] = MBS_COMMAND_COMPLETE;
1674 mb[1] = 0;
1675 if (iop[0] & BIT_4) {
1676 if (iop[0] & BIT_8)
1677 mb[1] |= BIT_1;
1678 } else
1679 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001680
1681 /* Passback COS information. */
1682 mb[10] = 0;
1683 if (lg->io_parameter[7] || lg->io_parameter[8])
1684 mb[10] |= BIT_0; /* Class 2. */
1685 if (lg->io_parameter[9] || lg->io_parameter[10])
1686 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001687 }
1688
1689 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1690
1691 return rval;
1692}
1693
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694/*
1695 * qla2x00_login_fabric
1696 * Issue login fabric port mailbox command.
1697 *
1698 * Input:
1699 * ha = adapter block pointer.
1700 * loop_id = device loop ID.
1701 * domain = device domain.
1702 * area = device area.
1703 * al_pa = device AL_PA.
1704 * status = pointer for return status.
1705 * opt = command options.
1706 * TARGET_QUEUE_LOCK must be released.
1707 * ADAPTER_STATE_LOCK must be released.
1708 *
1709 * Returns:
1710 * qla2x00 local function return status code.
1711 *
1712 * Context:
1713 * Kernel context.
1714 */
1715int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001716qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1718{
1719 int rval;
1720 mbx_cmd_t mc;
1721 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001722 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001724 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725
1726 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1727 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1728 if (HAS_EXTENDED_IDS(ha)) {
1729 mcp->mb[1] = loop_id;
1730 mcp->mb[10] = opt;
1731 mcp->out_mb |= MBX_10;
1732 } else {
1733 mcp->mb[1] = (loop_id << 8) | opt;
1734 }
1735 mcp->mb[2] = domain;
1736 mcp->mb[3] = area << 8 | al_pa;
1737
1738 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1739 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1740 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001741 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742
1743 /* Return mailbox statuses. */
1744 if (mb != NULL) {
1745 mb[0] = mcp->mb[0];
1746 mb[1] = mcp->mb[1];
1747 mb[2] = mcp->mb[2];
1748 mb[6] = mcp->mb[6];
1749 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001750 /* COS retrieved from Get-Port-Database mailbox command. */
1751 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 }
1753
1754 if (rval != QLA_SUCCESS) {
1755 /* RLU tmp code: need to change main mailbox_command function to
1756 * return ok even when the mailbox completion value is not
1757 * SUCCESS. The caller needs to be responsible to interpret
1758 * the return values of this mailbox command if we're not
1759 * to change too much of the existing code.
1760 */
1761 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1762 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1763 mcp->mb[0] == 0x4006)
1764 rval = QLA_SUCCESS;
1765
1766 /*EMPTY*/
1767 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001768 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001769 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 } else {
1771 /*EMPTY*/
1772 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001773 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 }
1775
1776 return rval;
1777}
1778
1779/*
1780 * qla2x00_login_local_device
1781 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001782 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * Input:
1784 * ha = adapter block pointer.
1785 * loop_id = device loop ID.
1786 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001787 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 * Returns:
1789 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001790 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 * Context:
1792 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001793 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 */
1795int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001796qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 uint16_t *mb_ret, uint8_t opt)
1798{
1799 int rval;
1800 mbx_cmd_t mc;
1801 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001802 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Andrew Vasqueze4289242007-07-19 15:05:56 -07001804 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001805 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001806 fcport->d_id.b.domain, fcport->d_id.b.area,
1807 fcport->d_id.b.al_pa, mb_ret, opt);
1808
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001809 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1812 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001813 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001815 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 mcp->mb[2] = opt;
1817 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1818 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1819 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1820 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001821 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 /* Return mailbox statuses. */
1824 if (mb_ret != NULL) {
1825 mb_ret[0] = mcp->mb[0];
1826 mb_ret[1] = mcp->mb[1];
1827 mb_ret[6] = mcp->mb[6];
1828 mb_ret[7] = mcp->mb[7];
1829 }
1830
1831 if (rval != QLA_SUCCESS) {
1832 /* AV tmp code: need to change main mailbox_command function to
1833 * return ok even when the mailbox completion value is not
1834 * SUCCESS. The caller needs to be responsible to interpret
1835 * the return values of this mailbox command if we're not
1836 * to change too much of the existing code.
1837 */
1838 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1839 rval = QLA_SUCCESS;
1840
1841 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001842 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001843 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001845 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001846 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 } else {
1848 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001849 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 }
1851
1852 return (rval);
1853}
1854
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001855int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001856qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001857 uint8_t area, uint8_t al_pa)
1858{
1859 int rval;
1860 struct logio_entry_24xx *lg;
1861 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001862 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001863 struct req_que *req;
1864 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001865
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001866 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001867
1868 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1869 if (lg == NULL) {
1870 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001871 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001872 return QLA_MEMORY_ALLOC_FAILED;
1873 }
1874 memset(lg, 0, sizeof(struct logio_entry_24xx));
1875
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001876 if (ql2xmaxqueues > 1)
1877 req = ha->req_q_map[0];
1878 else
1879 req = vha->req;
1880 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001881 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1882 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001883 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001884 lg->nport_handle = cpu_to_le16(loop_id);
1885 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001886 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001887 lg->port_id[0] = al_pa;
1888 lg->port_id[1] = area;
1889 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001890 lg->vp_index = vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001891
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001892 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001893 if (rval != QLA_SUCCESS) {
1894 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001895 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001896 } else if (lg->entry_status != 0) {
1897 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001898 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001899 lg->entry_status));
1900 rval = QLA_FUNCTION_FAILED;
1901 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001902 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001903 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001904 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001905 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001906 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001907 } else {
1908 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001909 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001910 }
1911
1912 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1913
1914 return rval;
1915}
1916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917/*
1918 * qla2x00_fabric_logout
1919 * Issue logout fabric port mailbox command.
1920 *
1921 * Input:
1922 * ha = adapter block pointer.
1923 * loop_id = device loop ID.
1924 * TARGET_QUEUE_LOCK must be released.
1925 * ADAPTER_STATE_LOCK must be released.
1926 *
1927 * Returns:
1928 * qla2x00 local function return status code.
1929 *
1930 * Context:
1931 * Kernel context.
1932 */
1933int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001934qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001935 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936{
1937 int rval;
1938 mbx_cmd_t mc;
1939 mbx_cmd_t *mcp = &mc;
1940
1941 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001942 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
1944 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1945 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001946 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 mcp->mb[1] = loop_id;
1948 mcp->mb[10] = 0;
1949 mcp->out_mb |= MBX_10;
1950 } else {
1951 mcp->mb[1] = loop_id << 8;
1952 }
1953
1954 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001955 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001957 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958
1959 if (rval != QLA_SUCCESS) {
1960 /*EMPTY*/
1961 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001962 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 } else {
1964 /*EMPTY*/
1965 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001966 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 }
1968
1969 return rval;
1970}
1971
1972/*
1973 * qla2x00_full_login_lip
1974 * Issue full login LIP mailbox command.
1975 *
1976 * Input:
1977 * ha = adapter block pointer.
1978 * TARGET_QUEUE_LOCK must be released.
1979 * ADAPTER_STATE_LOCK must be released.
1980 *
1981 * Returns:
1982 * qla2x00 local function return status code.
1983 *
1984 * Context:
1985 * Kernel context.
1986 */
1987int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001988qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989{
1990 int rval;
1991 mbx_cmd_t mc;
1992 mbx_cmd_t *mcp = &mc;
1993
1994 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001995 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001998 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001999 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 mcp->mb[3] = 0;
2001 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2002 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002003 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002005 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 if (rval != QLA_SUCCESS) {
2008 /*EMPTY*/
2009 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002010 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 } else {
2012 /*EMPTY*/
2013 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002014 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 }
2016
2017 return rval;
2018}
2019
2020/*
2021 * qla2x00_get_id_list
2022 *
2023 * Input:
2024 * ha = adapter block pointer.
2025 *
2026 * Returns:
2027 * qla2x00 local function return status code.
2028 *
2029 * Context:
2030 * Kernel context.
2031 */
2032int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002033qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 uint16_t *entries)
2035{
2036 int rval;
2037 mbx_cmd_t mc;
2038 mbx_cmd_t *mcp = &mc;
2039
2040 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002041 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
2043 if (id_list == NULL)
2044 return QLA_FUNCTION_FAILED;
2045
2046 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002047 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002048 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002049 mcp->mb[2] = MSW(id_list_dma);
2050 mcp->mb[3] = LSW(id_list_dma);
2051 mcp->mb[6] = MSW(MSD(id_list_dma));
2052 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002053 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002054 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002055 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002056 } else {
2057 mcp->mb[1] = MSW(id_list_dma);
2058 mcp->mb[2] = LSW(id_list_dma);
2059 mcp->mb[3] = MSW(MSD(id_list_dma));
2060 mcp->mb[6] = LSW(MSD(id_list_dma));
2061 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002064 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002066 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
2068 if (rval != QLA_SUCCESS) {
2069 /*EMPTY*/
2070 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002071 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 } else {
2073 *entries = mcp->mb[1];
2074 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002075 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 }
2077
2078 return rval;
2079}
2080
2081/*
2082 * qla2x00_get_resource_cnts
2083 * Get current firmware resource counts.
2084 *
2085 * Input:
2086 * ha = adapter block pointer.
2087 *
2088 * Returns:
2089 * qla2x00 local function return status code.
2090 *
2091 * Context:
2092 * Kernel context.
2093 */
2094int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002095qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002096 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002097 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
2099 int rval;
2100 mbx_cmd_t mc;
2101 mbx_cmd_t *mcp = &mc;
2102
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002103 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104
2105 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2106 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002107 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 -07002108 if (IS_QLA81XX(vha->hw))
2109 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002110 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002112 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
2114 if (rval != QLA_SUCCESS) {
2115 /*EMPTY*/
2116 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002117 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 } else {
2119 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002120 "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__,
2121 vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3],
2122 mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11],
2123 mcp->mb[12]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 if (cur_xchg_cnt)
2126 *cur_xchg_cnt = mcp->mb[3];
2127 if (orig_xchg_cnt)
2128 *orig_xchg_cnt = mcp->mb[6];
2129 if (cur_iocb_cnt)
2130 *cur_iocb_cnt = mcp->mb[7];
2131 if (orig_iocb_cnt)
2132 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002133 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002134 *max_npiv_vports = mcp->mb[11];
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002135 if (IS_QLA81XX(vha->hw) && max_fcfs)
2136 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 }
2138
2139 return (rval);
2140}
2141
2142#if defined(QL_DEBUG_LEVEL_3)
2143/*
2144 * qla2x00_get_fcal_position_map
2145 * Get FCAL (LILP) position map using mailbox command
2146 *
2147 * Input:
2148 * ha = adapter state pointer.
2149 * pos_map = buffer pointer (can be NULL).
2150 *
2151 * Returns:
2152 * qla2x00 local function return status code.
2153 *
2154 * Context:
2155 * Kernel context.
2156 */
2157int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002158qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159{
2160 int rval;
2161 mbx_cmd_t mc;
2162 mbx_cmd_t *mcp = &mc;
2163 char *pmap;
2164 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002165 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
Andrew Vasquez4b892582008-09-11 21:22:48 -07002167 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 if (pmap == NULL) {
2169 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002170 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 return QLA_MEMORY_ALLOC_FAILED;
2172 }
2173 memset(pmap, 0, FCAL_MAP_SIZE);
2174
2175 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2176 mcp->mb[2] = MSW(pmap_dma);
2177 mcp->mb[3] = LSW(pmap_dma);
2178 mcp->mb[6] = MSW(MSD(pmap_dma));
2179 mcp->mb[7] = LSW(MSD(pmap_dma));
2180 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2181 mcp->in_mb = MBX_1|MBX_0;
2182 mcp->buf_size = FCAL_MAP_SIZE;
2183 mcp->flags = MBX_DMA_IN;
2184 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002185 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
2187 if (rval == QLA_SUCCESS) {
2188 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002189 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 mcp->mb[1], (unsigned)pmap[0]));
2191 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2192
2193 if (pos_map)
2194 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2195 }
2196 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2197
2198 if (rval != QLA_SUCCESS) {
2199 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002200 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002202 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 }
2204
2205 return rval;
2206}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002207#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002208
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002209/*
2210 * qla2x00_get_link_status
2211 *
2212 * Input:
2213 * ha = adapter block pointer.
2214 * loop_id = device loop ID.
2215 * ret_buf = pointer to link status return buffer.
2216 *
2217 * Returns:
2218 * 0 = success.
2219 * BIT_0 = mem alloc error.
2220 * BIT_1 = mailbox error.
2221 */
2222int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002223qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002224 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002225{
2226 int rval;
2227 mbx_cmd_t mc;
2228 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002229 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002230 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002231
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002232 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002233
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002234 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002235 mcp->mb[2] = MSW(stats_dma);
2236 mcp->mb[3] = LSW(stats_dma);
2237 mcp->mb[6] = MSW(MSD(stats_dma));
2238 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002239 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2240 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002241 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002242 mcp->mb[1] = loop_id;
2243 mcp->mb[4] = 0;
2244 mcp->mb[10] = 0;
2245 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2246 mcp->in_mb |= MBX_1;
2247 } else if (HAS_EXTENDED_IDS(ha)) {
2248 mcp->mb[1] = loop_id;
2249 mcp->mb[10] = 0;
2250 mcp->out_mb |= MBX_10|MBX_1;
2251 } else {
2252 mcp->mb[1] = loop_id << 8;
2253 mcp->out_mb |= MBX_1;
2254 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002255 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002256 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002257 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002258
2259 if (rval == QLA_SUCCESS) {
2260 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2261 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002262 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002263 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002264 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002265 /* Copy over data -- firmware data is LE. */
2266 dwords = offsetof(struct link_statistics, unused1) / 4;
2267 siter = diter = &stats->link_fail_cnt;
2268 while (dwords--)
2269 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002270 }
2271 } else {
2272 /* Failed. */
2273 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002274 vha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002275 }
2276
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002277 return rval;
2278}
2279
2280int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002281qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002282 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283{
2284 int rval;
2285 mbx_cmd_t mc;
2286 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002287 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002288
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002289 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002290
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002291 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002292 mcp->mb[2] = MSW(stats_dma);
2293 mcp->mb[3] = LSW(stats_dma);
2294 mcp->mb[6] = MSW(MSD(stats_dma));
2295 mcp->mb[7] = LSW(MSD(stats_dma));
2296 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002297 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002298 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002299 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 -07002300 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002301 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002302 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002303 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002304
2305 if (rval == QLA_SUCCESS) {
2306 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2307 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002308 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002309 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002310 } else {
2311 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002312 dwords = sizeof(struct link_statistics) / 4;
2313 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002314 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002315 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002316 }
2317 } else {
2318 /* Failed. */
2319 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002320 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002321 }
2322
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002323 return rval;
2324}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002325
2326int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002327qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002328{
2329 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002330 unsigned long flags = 0;
2331
2332 struct abort_entry_24xx *abt;
2333 dma_addr_t abt_dma;
2334 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002335 fc_port_t *fcport = sp->fcport;
2336 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002337 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002338 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002339
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002340 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002341
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002342 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002343 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002344 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002345 break;
2346 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002347 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002348 if (handle == MAX_OUTSTANDING_COMMANDS) {
2349 /* Command not found. */
2350 return QLA_FUNCTION_FAILED;
2351 }
2352
2353 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2354 if (abt == NULL) {
2355 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002356 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002357 return QLA_MEMORY_ALLOC_FAILED;
2358 }
2359 memset(abt, 0, sizeof(struct abort_entry_24xx));
2360
2361 abt->entry_type = ABORT_IOCB_TYPE;
2362 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002363 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002364 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2365 abt->handle_to_abort = handle;
2366 abt->port_id[0] = fcport->d_id.b.al_pa;
2367 abt->port_id[1] = fcport->d_id.b.area;
2368 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002369 abt->vp_index = fcport->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002370
2371 abt->req_que_no = cpu_to_le16(req->id);
2372
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002373 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002374 if (rval != QLA_SUCCESS) {
2375 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002376 __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002377 } else if (abt->entry_status != 0) {
2378 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002379 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002380 abt->entry_status));
2381 rval = QLA_FUNCTION_FAILED;
2382 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2383 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002384 "-- completion status (%x).\n", __func__, vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002385 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002386 rval = QLA_FUNCTION_FAILED;
2387 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002388 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002389 }
2390
2391 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2392
2393 return rval;
2394}
2395
2396struct tsk_mgmt_cmd {
2397 union {
2398 struct tsk_mgmt_entry tsk;
2399 struct sts_entry_24xx sts;
2400 } p;
2401};
2402
Andrew Vasquez523ec772008-04-03 13:13:24 -07002403static int
2404__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002405 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002406{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002407 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002408 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002409 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002410 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002411 scsi_qla_host_t *vha;
2412 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002413 struct req_que *req;
2414 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002415
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08002416 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002417
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002418 vha = fcport->vha;
2419 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002420 req = vha->req;
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002421 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002422 rsp = ha->rsp_q_map[tag + 1];
2423 else
2424 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002425 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002426 if (tsk == NULL) {
2427 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002428 "IOCB.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002429 return QLA_MEMORY_ALLOC_FAILED;
2430 }
2431 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2432
2433 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2434 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002435 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002436 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002437 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002438 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002439 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2440 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2441 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002442 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002443 if (type == TCF_LUN_RESET) {
2444 int_to_scsilun(l, &tsk->p.tsk.lun);
2445 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2446 sizeof(tsk->p.tsk.lun));
2447 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002448
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002449 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002450 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002451 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002452 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002453 "(%x).\n", __func__, vha->host_no, name, rval));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002454 } else if (sts->entry_status != 0) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002455 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002456 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002457 sts->entry_status));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002458 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002459 } else if (sts->comp_status !=
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002460 __constant_cpu_to_le16(CS_COMPLETE)) {
2461 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2462 "-- completion status (%x).\n", __func__,
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002463 vha->host_no, le16_to_cpu(sts->comp_status)));
2464 rval = QLA_FUNCTION_FAILED;
2465 } else if (!(le16_to_cpu(sts->scsi_status) &
2466 SS_RESPONSE_INFO_LEN_VALID)) {
2467 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2468 "-- no response info (%x).\n", __func__, vha->host_no,
2469 le16_to_cpu(sts->scsi_status)));
2470 rval = QLA_FUNCTION_FAILED;
2471 } else if (le32_to_cpu(sts->rsp_data_len) < 4) {
2472 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2473 "-- not enough response info (%d).\n", __func__,
2474 vha->host_no, le32_to_cpu(sts->rsp_data_len)));
2475 rval = QLA_FUNCTION_FAILED;
2476 } else if (sts->data[3]) {
2477 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2478 "-- response (%x).\n", __func__,
2479 vha->host_no, sts->data[3]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002480 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002481 }
2482
2483 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002484 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002485 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2486 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002487 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002488 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002489 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002490 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002491 }
2492
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002493 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002494
2495 return rval;
2496}
2497
Andrew Vasquez523ec772008-04-03 13:13:24 -07002498int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002499qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002500{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002501 struct qla_hw_data *ha = fcport->vha->hw;
2502
2503 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2504 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
2505
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002506 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002507}
2508
2509int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002510qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002511{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002512 struct qla_hw_data *ha = fcport->vha->hw;
2513
2514 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2515 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
2516
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002517 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002518}
2519
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002520int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002521qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002522{
2523 int rval;
2524 mbx_cmd_t mc;
2525 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002526 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002527
Andrew Vasquez68af0812008-05-12 22:21:13 -07002528 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002529 return QLA_FUNCTION_FAILED;
2530
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002531 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002532
2533 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2534 mcp->out_mb = MBX_0;
2535 mcp->in_mb = MBX_0;
2536 mcp->tov = 5;
2537 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002538 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002539
2540 if (rval != QLA_SUCCESS) {
2541 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002542 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002543 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002544 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002545 }
2546
2547 return rval;
2548}
2549
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002550/**
2551 * qla2x00_set_serdes_params() -
2552 * @ha: HA context
2553 *
2554 * Returns
2555 */
2556int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002557qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002558 uint16_t sw_em_2g, uint16_t sw_em_4g)
2559{
2560 int rval;
2561 mbx_cmd_t mc;
2562 mbx_cmd_t *mcp = &mc;
2563
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002564 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002565
2566 mcp->mb[0] = MBC_SERDES_PARAMS;
2567 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002568 mcp->mb[2] = sw_em_1g | BIT_15;
2569 mcp->mb[3] = sw_em_2g | BIT_15;
2570 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002571 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2572 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002573 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002574 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002575 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002576
2577 if (rval != QLA_SUCCESS) {
2578 /*EMPTY*/
2579 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002580 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002581 } else {
2582 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002583 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002584 }
2585
2586 return rval;
2587}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002588
2589int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002590qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002591{
2592 int rval;
2593 mbx_cmd_t mc;
2594 mbx_cmd_t *mcp = &mc;
2595
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002596 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002597 return QLA_FUNCTION_FAILED;
2598
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002599 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002600
2601 mcp->mb[0] = MBC_STOP_FIRMWARE;
2602 mcp->out_mb = MBX_0;
2603 mcp->in_mb = MBX_0;
2604 mcp->tov = 5;
2605 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002606 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002607
2608 if (rval != QLA_SUCCESS) {
2609 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002610 vha->host_no, rval));
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07002611 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2612 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002613 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002614 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002615 }
2616
2617 return rval;
2618}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002619
2620int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002621qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002622 uint16_t buffers)
2623{
2624 int rval;
2625 mbx_cmd_t mc;
2626 mbx_cmd_t *mcp = &mc;
2627
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002628 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002629 return QLA_FUNCTION_FAILED;
2630
Andrew Vasquez85880802009-12-15 21:29:46 -08002631 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2632 return QLA_FUNCTION_FAILED;
2633
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002634 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002635
2636 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002637 mcp->mb[1] = TC_EFT_ENABLE;
2638 mcp->mb[2] = LSW(eft_dma);
2639 mcp->mb[3] = MSW(eft_dma);
2640 mcp->mb[4] = LSW(MSD(eft_dma));
2641 mcp->mb[5] = MSW(MSD(eft_dma));
2642 mcp->mb[6] = buffers;
2643 mcp->mb[7] = TC_AEN_DISABLE;
2644 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 -07002645 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002646 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002647 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002648 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002649 if (rval != QLA_SUCCESS) {
2650 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002651 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002652 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002653 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002654 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002655
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002656 return rval;
2657}
2658
2659int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002660qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002661{
2662 int rval;
2663 mbx_cmd_t mc;
2664 mbx_cmd_t *mcp = &mc;
2665
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002666 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002667 return QLA_FUNCTION_FAILED;
2668
Andrew Vasquez85880802009-12-15 21:29:46 -08002669 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2670 return QLA_FUNCTION_FAILED;
2671
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002672 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002673
2674 mcp->mb[0] = MBC_TRACE_CONTROL;
2675 mcp->mb[1] = TC_EFT_DISABLE;
2676 mcp->out_mb = MBX_1|MBX_0;
2677 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002678 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002679 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002680 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002681 if (rval != QLA_SUCCESS) {
2682 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002683 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002684 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002685 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002686 }
2687
2688 return rval;
2689}
2690
Andrew Vasquez88729e52006-06-23 16:10:50 -07002691int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002692qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002693 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2694{
2695 int rval;
2696 mbx_cmd_t mc;
2697 mbx_cmd_t *mcp = &mc;
2698
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002699 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002700 return QLA_FUNCTION_FAILED;
2701
Andrew Vasquez85880802009-12-15 21:29:46 -08002702 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2703 return QLA_FUNCTION_FAILED;
2704
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002705 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002706
2707 mcp->mb[0] = MBC_TRACE_CONTROL;
2708 mcp->mb[1] = TC_FCE_ENABLE;
2709 mcp->mb[2] = LSW(fce_dma);
2710 mcp->mb[3] = MSW(fce_dma);
2711 mcp->mb[4] = LSW(MSD(fce_dma));
2712 mcp->mb[5] = MSW(MSD(fce_dma));
2713 mcp->mb[6] = buffers;
2714 mcp->mb[7] = TC_AEN_DISABLE;
2715 mcp->mb[8] = 0;
2716 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2717 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2718 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2719 MBX_1|MBX_0;
2720 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002721 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002722 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002723 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002724 if (rval != QLA_SUCCESS) {
2725 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002726 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002727 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002728 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002729
2730 if (mb)
2731 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2732 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002733 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002734 }
2735
2736 return rval;
2737}
2738
2739int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002740qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002741{
2742 int rval;
2743 mbx_cmd_t mc;
2744 mbx_cmd_t *mcp = &mc;
2745
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002746 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002747 return QLA_FUNCTION_FAILED;
2748
Andrew Vasquez85880802009-12-15 21:29:46 -08002749 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2750 return QLA_FUNCTION_FAILED;
2751
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002752 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002753
2754 mcp->mb[0] = MBC_TRACE_CONTROL;
2755 mcp->mb[1] = TC_FCE_DISABLE;
2756 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2757 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2758 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2759 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002760 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002761 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002762 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002763 if (rval != QLA_SUCCESS) {
2764 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002765 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002766 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002767 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002768
2769 if (wr)
2770 *wr = (uint64_t) mcp->mb[5] << 48 |
2771 (uint64_t) mcp->mb[4] << 32 |
2772 (uint64_t) mcp->mb[3] << 16 |
2773 (uint64_t) mcp->mb[2];
2774 if (rd)
2775 *rd = (uint64_t) mcp->mb[9] << 48 |
2776 (uint64_t) mcp->mb[8] << 32 |
2777 (uint64_t) mcp->mb[7] << 16 |
2778 (uint64_t) mcp->mb[6];
2779 }
2780
2781 return rval;
2782}
2783
2784int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002785qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
Andrew Vasquez88729e52006-06-23 16:10:50 -07002786 uint16_t off, uint16_t count)
2787{
2788 int rval;
2789 mbx_cmd_t mc;
2790 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002791
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002792 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002793 return QLA_FUNCTION_FAILED;
2794
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002795 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002796
2797 mcp->mb[0] = MBC_READ_SFP;
2798 mcp->mb[1] = addr;
2799 mcp->mb[2] = MSW(sfp_dma);
2800 mcp->mb[3] = LSW(sfp_dma);
2801 mcp->mb[6] = MSW(MSD(sfp_dma));
2802 mcp->mb[7] = LSW(MSD(sfp_dma));
2803 mcp->mb[8] = count;
2804 mcp->mb[9] = off;
2805 mcp->mb[10] = 0;
2806 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2807 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002808 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002809 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002810 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez88729e52006-06-23 16:10:50 -07002811
2812 if (rval != QLA_SUCCESS) {
2813 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002814 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002815 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002816 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002817 }
2818
2819 return rval;
2820}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002821
2822int
Giridhar Malavali6e980162010-03-19 17:03:58 -07002823qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2824 uint16_t *port_speed, uint16_t *mb)
2825{
2826 int rval;
2827 mbx_cmd_t mc;
2828 mbx_cmd_t *mcp = &mc;
2829
2830 if (!IS_IIDMA_CAPABLE(vha->hw))
2831 return QLA_FUNCTION_FAILED;
2832
2833 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
2834
2835 mcp->mb[0] = MBC_PORT_PARAMS;
2836 mcp->mb[1] = loop_id;
2837 mcp->mb[2] = mcp->mb[3] = 0;
2838 mcp->mb[9] = vha->vp_idx;
2839 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2840 mcp->in_mb = MBX_3|MBX_1|MBX_0;
2841 mcp->tov = MBX_TOV_SECONDS;
2842 mcp->flags = 0;
2843 rval = qla2x00_mailbox_command(vha, mcp);
2844
2845 /* Return mailbox statuses. */
2846 if (mb != NULL) {
2847 mb[0] = mcp->mb[0];
2848 mb[1] = mcp->mb[1];
2849 mb[3] = mcp->mb[3];
2850 }
2851
2852 if (rval != QLA_SUCCESS) {
2853 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2854 vha->host_no, rval));
2855 } else {
2856 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
2857 if (port_speed)
2858 *port_speed = mcp->mb[3];
2859 }
2860
2861 return rval;
2862}
2863
2864int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002865qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002866 uint16_t port_speed, uint16_t *mb)
2867{
2868 int rval;
2869 mbx_cmd_t mc;
2870 mbx_cmd_t *mcp = &mc;
2871
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002872 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002873 return QLA_FUNCTION_FAILED;
2874
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002875 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002876
2877 mcp->mb[0] = MBC_PORT_PARAMS;
2878 mcp->mb[1] = loop_id;
2879 mcp->mb[2] = BIT_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002880 if (IS_QLA8XXX_TYPE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002881 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2882 else
2883 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2884 mcp->mb[9] = vha->vp_idx;
2885 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2886 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002887 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002888 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002889 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002890
2891 /* Return mailbox statuses. */
2892 if (mb != NULL) {
2893 mb[0] = mcp->mb[0];
2894 mb[1] = mcp->mb[1];
2895 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002896 }
2897
2898 if (rval != QLA_SUCCESS) {
2899 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002900 vha->host_no, rval));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002901 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002902 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002903 }
2904
2905 return rval;
2906}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002907
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002908void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002909qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002910 struct vp_rpt_id_entry_24xx *rptid_entry)
2911{
2912 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07002913 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002914 struct qla_hw_data *ha = vha->hw;
2915 scsi_qla_host_t *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002916 scsi_qla_host_t *tvp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002917
2918 if (rptid_entry->entry_status != 0)
2919 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002920
2921 if (rptid_entry->format == 0) {
2922 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002923 " number of VPs acquired %d\n", __func__, vha->host_no,
Andrew Vasquez09ccbcc2009-08-04 23:38:21 -07002924 MSB(le16_to_cpu(rptid_entry->vp_count)),
2925 LSB(le16_to_cpu(rptid_entry->vp_count))));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002926 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2927 rptid_entry->port_id[2], rptid_entry->port_id[1],
2928 rptid_entry->port_id[0]));
2929 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07002930 vp_idx = LSB(stat);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002931 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2932 "- status %d - "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002933 "with port id %02x%02x%02x\n", __func__, vha->host_no,
Seokmann Juc6852c42008-04-24 15:21:29 -07002934 vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002935 rptid_entry->port_id[2], rptid_entry->port_id[1],
2936 rptid_entry->port_id[0]));
Andrew Vasquez531a82d2009-10-13 15:16:51 -07002937
2938 vp = vha;
2939 if (vp_idx == 0 && (MSB(stat) != 1))
2940 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002941
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002942 if (MSB(stat) == 1) {
2943 DEBUG2(printk("scsi(%ld): Could not acquire ID for "
2944 "VP[%d].\n", vha->host_no, vp_idx));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002945 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002946 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002947
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002948 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002949 if (vp_idx == vp->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002950 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002951 if (!vp)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002952 return;
2953
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002954 vp->d_id.b.domain = rptid_entry->port_id[2];
2955 vp->d_id.b.area = rptid_entry->port_id[1];
2956 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002957
2958 /*
2959 * Cannot configure here as we are still sitting on the
2960 * response queue. Handle it in dpc context.
2961 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002962 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002963
Andrew Vasquez531a82d2009-10-13 15:16:51 -07002964reg_needed:
2965 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
2966 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
2967 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002968 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002969 }
2970}
2971
2972/*
2973 * qla24xx_modify_vp_config
2974 * Change VP configuration for vha
2975 *
2976 * Input:
2977 * vha = adapter block pointer.
2978 *
2979 * Returns:
2980 * qla2xxx local function return status code.
2981 *
2982 * Context:
2983 * Kernel context.
2984 */
2985int
2986qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2987{
2988 int rval;
2989 struct vp_config_entry_24xx *vpmod;
2990 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002991 struct qla_hw_data *ha = vha->hw;
2992 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002993
2994 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002995
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002996 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002997 if (!vpmod) {
2998 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002999 "IOCB.\n", __func__, vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003000 return QLA_MEMORY_ALLOC_FAILED;
3001 }
3002
3003 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3004 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3005 vpmod->entry_count = 1;
3006 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3007 vpmod->vp_count = 1;
3008 vpmod->vp_index1 = vha->vp_idx;
3009 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
3010 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3011 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3012 vpmod->entry_count = 1;
3013
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003014 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003015 if (rval != QLA_SUCCESS) {
3016 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003017 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003018 } else if (vpmod->comp_status != 0) {
3019 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003020 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003021 vpmod->comp_status));
3022 rval = QLA_FUNCTION_FAILED;
3023 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
3024 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003025 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003026 le16_to_cpu(vpmod->comp_status)));
3027 rval = QLA_FUNCTION_FAILED;
3028 } else {
3029 /* EMPTY */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003030 DEBUG11(printk("%s(%ld): done.\n", __func__,
3031 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003032 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3033 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003034 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003035
3036 return rval;
3037}
3038
3039/*
3040 * qla24xx_control_vp
3041 * Enable a virtual port for given host
3042 *
3043 * Input:
3044 * ha = adapter block pointer.
3045 * vhba = virtual adapter (unused)
3046 * index = index number for enabled VP
3047 *
3048 * Returns:
3049 * qla2xxx local function return status code.
3050 *
3051 * Context:
3052 * Kernel context.
3053 */
3054int
3055qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3056{
3057 int rval;
3058 int map, pos;
3059 struct vp_ctrl_entry_24xx *vce;
3060 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003061 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003062 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003063 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003064
3065 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003066 vha->host_no, vp_index));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003067
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003068 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003069 return QLA_PARAMETER_ERROR;
3070
3071 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3072 if (!vce) {
3073 DEBUG2_3(printk("%s(%ld): "
3074 "failed to allocate VP Control IOCB.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003075 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003076 return QLA_MEMORY_ALLOC_FAILED;
3077 }
3078 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3079
3080 vce->entry_type = VP_CTRL_IOCB_TYPE;
3081 vce->entry_count = 1;
3082 vce->command = cpu_to_le16(cmd);
3083 vce->vp_count = __constant_cpu_to_le16(1);
3084
3085 /* index map in firmware starts with 1; decrement index
3086 * this is ok as we never use index 0
3087 */
3088 map = (vp_index - 1) / 8;
3089 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003090 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003091 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003092 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003093
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003094 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003095 if (rval != QLA_SUCCESS) {
3096 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003097 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003098 printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003099 "(%x).\n", __func__, base_vha->host_no, rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003100 } else if (vce->entry_status != 0) {
3101 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003102 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003103 vce->entry_status));
3104 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003105 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003106 vce->entry_status);
3107 rval = QLA_FUNCTION_FAILED;
3108 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
3109 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003110 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003111 le16_to_cpu(vce->comp_status)));
3112 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003113 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003114 le16_to_cpu(vce->comp_status));
3115 rval = QLA_FUNCTION_FAILED;
3116 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003117 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003118 }
3119
3120 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3121
3122 return rval;
3123}
3124
3125/*
3126 * qla2x00_send_change_request
3127 * Receive or disable RSCN request from fabric controller
3128 *
3129 * Input:
3130 * ha = adapter block pointer
3131 * format = registration format:
3132 * 0 - Reserved
3133 * 1 - Fabric detected registration
3134 * 2 - N_port detected registration
3135 * 3 - Full registration
3136 * FF - clear registration
3137 * vp_idx = Virtual port index
3138 *
3139 * Returns:
3140 * qla2x00 local function return status code.
3141 *
3142 * Context:
3143 * Kernel Context
3144 */
3145
3146int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003147qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003148 uint16_t vp_idx)
3149{
3150 int rval;
3151 mbx_cmd_t mc;
3152 mbx_cmd_t *mcp = &mc;
3153
3154 /*
3155 * This command is implicitly executed by firmware during login for the
3156 * physical hosts
3157 */
3158 if (vp_idx == 0)
3159 return QLA_FUNCTION_FAILED;
3160
3161 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3162 mcp->mb[1] = format;
3163 mcp->mb[9] = vp_idx;
3164 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3165 mcp->in_mb = MBX_0|MBX_1;
3166 mcp->tov = MBX_TOV_SECONDS;
3167 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003168 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003169
3170 if (rval == QLA_SUCCESS) {
3171 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3172 rval = BIT_1;
3173 }
3174 } else
3175 rval = BIT_1;
3176
3177 return rval;
3178}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003179
3180int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003181qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003182 uint32_t size)
3183{
3184 int rval;
3185 mbx_cmd_t mc;
3186 mbx_cmd_t *mcp = &mc;
3187
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003188 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003189
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003190 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003191 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3192 mcp->mb[8] = MSW(addr);
3193 mcp->out_mb = MBX_8|MBX_0;
3194 } else {
3195 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3196 mcp->out_mb = MBX_0;
3197 }
3198 mcp->mb[1] = LSW(addr);
3199 mcp->mb[2] = MSW(req_dma);
3200 mcp->mb[3] = LSW(req_dma);
3201 mcp->mb[6] = MSW(MSD(req_dma));
3202 mcp->mb[7] = LSW(MSD(req_dma));
3203 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003204 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003205 mcp->mb[4] = MSW(size);
3206 mcp->mb[5] = LSW(size);
3207 mcp->out_mb |= MBX_5|MBX_4;
3208 } else {
3209 mcp->mb[4] = LSW(size);
3210 mcp->out_mb |= MBX_4;
3211 }
3212
3213 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003214 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003215 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003216 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003217
3218 if (rval != QLA_SUCCESS) {
3219 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003220 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003221 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003222 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003223 }
3224
3225 return rval;
3226}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003227
3228/* 84XX Support **************************************************************/
3229
3230struct cs84xx_mgmt_cmd {
3231 union {
3232 struct verify_chip_entry_84xx req;
3233 struct verify_chip_rsp_84xx rsp;
3234 } p;
3235};
3236
3237int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003238qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003239{
3240 int rval, retry;
3241 struct cs84xx_mgmt_cmd *mn;
3242 dma_addr_t mn_dma;
3243 uint16_t options;
3244 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003245 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003246
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003247 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003248
3249 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3250 if (mn == NULL) {
3251 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003252 "IOCB.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003253 return QLA_MEMORY_ALLOC_FAILED;
3254 }
3255
3256 /* Force Update? */
3257 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3258 /* Diagnostic firmware? */
3259 /* options |= MENLO_DIAG_FW; */
3260 /* We update the firmware with only one data sequence. */
3261 options |= VCO_END_OF_DATA;
3262
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003263 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003264 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003265 memset(mn, 0, sizeof(*mn));
3266 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3267 mn->p.req.entry_count = 1;
3268 mn->p.req.options = cpu_to_le16(options);
3269
3270 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003271 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003272 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3273 sizeof(*mn)));
3274
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003275 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003276 if (rval != QLA_SUCCESS) {
3277 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003278 "IOCB (%x).\n", __func__, vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003279 goto verify_done;
3280 }
3281
3282 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003283 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003284 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3285 sizeof(*mn)));
3286
3287 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3288 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3289 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3290 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003291 vha->host_no, status[0], status[1]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003292
3293 if (status[0] != CS_COMPLETE) {
3294 rval = QLA_FUNCTION_FAILED;
3295 if (!(options & VCO_DONT_UPDATE_FW)) {
3296 DEBUG2_16(printk("%s(%ld): Firmware update "
3297 "failed. Retrying without update "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003298 "firmware.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003299 options |= VCO_DONT_UPDATE_FW;
3300 options &= ~VCO_FORCE_UPDATE;
3301 retry = 1;
3302 }
3303 } else {
3304 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003305 __func__, vha->host_no,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003306 le32_to_cpu(mn->p.rsp.fw_ver)));
3307
3308 /* NOTE: we only update OP firmware. */
3309 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3310 ha->cs84xx->op_fw_version =
3311 le32_to_cpu(mn->p.rsp.fw_ver);
3312 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3313 flags);
3314 }
3315 } while (retry);
3316
3317verify_done:
3318 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3319
3320 if (rval != QLA_SUCCESS) {
3321 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003322 vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003323 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003324 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003325 }
3326
3327 return rval;
3328}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003329
3330int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003331qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003332{
3333 int rval;
3334 unsigned long flags;
3335 mbx_cmd_t mc;
3336 mbx_cmd_t *mcp = &mc;
3337 struct device_reg_25xxmq __iomem *reg;
3338 struct qla_hw_data *ha = vha->hw;
3339
3340 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003341 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003342 mcp->mb[2] = MSW(LSD(req->dma));
3343 mcp->mb[3] = LSW(LSD(req->dma));
3344 mcp->mb[6] = MSW(MSD(req->dma));
3345 mcp->mb[7] = LSW(MSD(req->dma));
3346 mcp->mb[5] = req->length;
3347 if (req->rsp)
3348 mcp->mb[10] = req->rsp->id;
3349 mcp->mb[12] = req->qos;
3350 mcp->mb[11] = req->vp_idx;
3351 mcp->mb[13] = req->rid;
3352
3353 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3354 QLA_QUE_PAGE * req->id);
3355
3356 mcp->mb[4] = req->id;
3357 /* que in ptr index */
3358 mcp->mb[8] = 0;
3359 /* que out ptr index */
3360 mcp->mb[9] = 0;
3361 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3362 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3363 mcp->in_mb = MBX_0;
3364 mcp->flags = MBX_DMA_OUT;
3365 mcp->tov = 60;
3366
3367 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003368 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003369 WRT_REG_DWORD(&reg->req_q_in, 0);
3370 WRT_REG_DWORD(&reg->req_q_out, 0);
3371 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003372 req->req_q_in = &reg->req_q_in;
3373 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003374 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3375
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003376 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003377 if (rval != QLA_SUCCESS)
3378 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3379 __func__, vha->host_no, rval, mcp->mb[0]));
3380 return rval;
3381}
3382
3383int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003384qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003385{
3386 int rval;
3387 unsigned long flags;
3388 mbx_cmd_t mc;
3389 mbx_cmd_t *mcp = &mc;
3390 struct device_reg_25xxmq __iomem *reg;
3391 struct qla_hw_data *ha = vha->hw;
3392
3393 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003394 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003395 mcp->mb[2] = MSW(LSD(rsp->dma));
3396 mcp->mb[3] = LSW(LSD(rsp->dma));
3397 mcp->mb[6] = MSW(MSD(rsp->dma));
3398 mcp->mb[7] = LSW(MSD(rsp->dma));
3399 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003400 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003401 mcp->mb[13] = rsp->rid;
3402
3403 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3404 QLA_QUE_PAGE * rsp->id);
3405
3406 mcp->mb[4] = rsp->id;
3407 /* que in ptr index */
3408 mcp->mb[8] = 0;
3409 /* que out ptr index */
3410 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003411 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003412 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3413 mcp->in_mb = MBX_0;
3414 mcp->flags = MBX_DMA_OUT;
3415 mcp->tov = 60;
3416
3417 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003418 if (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003419 WRT_REG_DWORD(&reg->rsp_q_out, 0);
3420 WRT_REG_DWORD(&reg->rsp_q_in, 0);
3421 }
3422
3423 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3424
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003425 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003426 if (rval != QLA_SUCCESS)
3427 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3428 "mb0=%x.\n", __func__,
3429 vha->host_no, rval, mcp->mb[0]));
3430 return rval;
3431}
3432
Andrew Vasquez8a659572009-02-08 20:50:12 -08003433int
3434qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3435{
3436 int rval;
3437 mbx_cmd_t mc;
3438 mbx_cmd_t *mcp = &mc;
3439
3440 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3441
3442 mcp->mb[0] = MBC_IDC_ACK;
3443 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3444 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3445 mcp->in_mb = MBX_0;
3446 mcp->tov = MBX_TOV_SECONDS;
3447 mcp->flags = 0;
3448 rval = qla2x00_mailbox_command(vha, mcp);
3449
3450 if (rval != QLA_SUCCESS) {
3451 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3452 vha->host_no, rval, mcp->mb[0]));
3453 } else {
3454 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3455 }
3456
3457 return rval;
3458}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003459
3460int
3461qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3462{
3463 int rval;
3464 mbx_cmd_t mc;
3465 mbx_cmd_t *mcp = &mc;
3466
3467 if (!IS_QLA81XX(vha->hw))
3468 return QLA_FUNCTION_FAILED;
3469
3470 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3471
3472 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3473 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3474 mcp->out_mb = MBX_1|MBX_0;
3475 mcp->in_mb = MBX_1|MBX_0;
3476 mcp->tov = MBX_TOV_SECONDS;
3477 mcp->flags = 0;
3478 rval = qla2x00_mailbox_command(vha, mcp);
3479
3480 if (rval != QLA_SUCCESS) {
3481 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3482 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3483 } else {
3484 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3485 *sector_size = mcp->mb[1];
3486 }
3487
3488 return rval;
3489}
3490
3491int
3492qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3493{
3494 int rval;
3495 mbx_cmd_t mc;
3496 mbx_cmd_t *mcp = &mc;
3497
3498 if (!IS_QLA81XX(vha->hw))
3499 return QLA_FUNCTION_FAILED;
3500
3501 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3502
3503 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3504 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3505 FAC_OPT_CMD_WRITE_PROTECT;
3506 mcp->out_mb = MBX_1|MBX_0;
3507 mcp->in_mb = MBX_1|MBX_0;
3508 mcp->tov = MBX_TOV_SECONDS;
3509 mcp->flags = 0;
3510 rval = qla2x00_mailbox_command(vha, mcp);
3511
3512 if (rval != QLA_SUCCESS) {
3513 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3514 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3515 } else {
3516 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3517 }
3518
3519 return rval;
3520}
3521
3522int
3523qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3524{
3525 int rval;
3526 mbx_cmd_t mc;
3527 mbx_cmd_t *mcp = &mc;
3528
3529 if (!IS_QLA81XX(vha->hw))
3530 return QLA_FUNCTION_FAILED;
3531
3532 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3533
3534 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3535 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3536 mcp->mb[2] = LSW(start);
3537 mcp->mb[3] = MSW(start);
3538 mcp->mb[4] = LSW(finish);
3539 mcp->mb[5] = MSW(finish);
3540 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3541 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3542 mcp->tov = MBX_TOV_SECONDS;
3543 mcp->flags = 0;
3544 rval = qla2x00_mailbox_command(vha, mcp);
3545
3546 if (rval != QLA_SUCCESS) {
3547 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3548 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3549 mcp->mb[1], mcp->mb[2]));
3550 } else {
3551 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3552 }
3553
3554 return rval;
3555}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003556
3557int
3558qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3559{
3560 int rval = 0;
3561 mbx_cmd_t mc;
3562 mbx_cmd_t *mcp = &mc;
3563
3564 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3565
3566 mcp->mb[0] = MBC_RESTART_MPI_FW;
3567 mcp->out_mb = MBX_0;
3568 mcp->in_mb = MBX_0|MBX_1;
3569 mcp->tov = MBX_TOV_SECONDS;
3570 mcp->flags = 0;
3571 rval = qla2x00_mailbox_command(vha, mcp);
3572
3573 if (rval != QLA_SUCCESS) {
3574 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3575 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3576 } else {
3577 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3578 }
3579
3580 return rval;
3581}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003582
3583int
3584qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3585 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3586{
3587 int rval;
3588 mbx_cmd_t mc;
3589 mbx_cmd_t *mcp = &mc;
3590
3591 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3592
3593 mcp->mb[0] = MBC_READ_SFP;
3594 mcp->mb[1] = dev;
3595 mcp->mb[2] = MSW(sfp_dma);
3596 mcp->mb[3] = LSW(sfp_dma);
3597 mcp->mb[6] = MSW(MSD(sfp_dma));
3598 mcp->mb[7] = LSW(MSD(sfp_dma));
3599 mcp->mb[8] = len;
3600 mcp->mb[9] = adr;
3601 mcp->mb[10] = opt;
3602 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3603 mcp->in_mb = MBX_0;
3604 mcp->tov = MBX_TOV_SECONDS;
3605 mcp->flags = 0;
3606 rval = qla2x00_mailbox_command(vha, mcp);
3607
3608 if (opt & BIT_0)
3609 if (sfp)
3610 *sfp = mcp->mb[8];
3611
3612 if (rval != QLA_SUCCESS) {
3613 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3614 vha->host_no, rval, mcp->mb[0]));
3615 } else {
Andrew Vasquez76403352009-04-06 22:33:39 -07003616 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003617 }
3618
3619 return rval;
3620}
3621
3622int
3623qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3624 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3625{
3626 int rval;
3627 mbx_cmd_t mc;
3628 mbx_cmd_t *mcp = &mc;
3629
3630 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3631
3632 if (opt & BIT_0)
3633 if (sfp)
3634 len = *sfp;
3635
3636 mcp->mb[0] = MBC_WRITE_SFP;
3637 mcp->mb[1] = dev;
3638 mcp->mb[2] = MSW(sfp_dma);
3639 mcp->mb[3] = LSW(sfp_dma);
3640 mcp->mb[6] = MSW(MSD(sfp_dma));
3641 mcp->mb[7] = LSW(MSD(sfp_dma));
3642 mcp->mb[8] = len;
3643 mcp->mb[9] = adr;
3644 mcp->mb[10] = opt;
3645 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3646 mcp->in_mb = MBX_0;
3647 mcp->tov = MBX_TOV_SECONDS;
3648 mcp->flags = 0;
3649 rval = qla2x00_mailbox_command(vha, mcp);
3650
3651 if (rval != QLA_SUCCESS) {
3652 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3653 vha->host_no, rval, mcp->mb[0]));
3654 } else {
3655 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3656 }
3657
3658 return rval;
3659}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003660
3661int
3662qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3663 uint16_t size_in_bytes, uint16_t *actual_size)
3664{
3665 int rval;
3666 mbx_cmd_t mc;
3667 mbx_cmd_t *mcp = &mc;
3668
Giridhar Malavalia9083012010-04-12 17:59:55 -07003669 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003670 return QLA_FUNCTION_FAILED;
3671
3672 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3673
3674 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3675 mcp->mb[2] = MSW(stats_dma);
3676 mcp->mb[3] = LSW(stats_dma);
3677 mcp->mb[6] = MSW(MSD(stats_dma));
3678 mcp->mb[7] = LSW(MSD(stats_dma));
3679 mcp->mb[8] = size_in_bytes >> 2;
3680 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3681 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3682 mcp->tov = MBX_TOV_SECONDS;
3683 mcp->flags = 0;
3684 rval = qla2x00_mailbox_command(vha, mcp);
3685
3686 if (rval != QLA_SUCCESS) {
3687 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3688 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3689 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3690 } else {
3691 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3692
3693 *actual_size = mcp->mb[2] << 2;
3694 }
3695
3696 return rval;
3697}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003698
3699int
3700qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3701 uint16_t size)
3702{
3703 int rval;
3704 mbx_cmd_t mc;
3705 mbx_cmd_t *mcp = &mc;
3706
Giridhar Malavalia9083012010-04-12 17:59:55 -07003707 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003708 return QLA_FUNCTION_FAILED;
3709
3710 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3711
3712 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3713 mcp->mb[1] = 0;
3714 mcp->mb[2] = MSW(tlv_dma);
3715 mcp->mb[3] = LSW(tlv_dma);
3716 mcp->mb[6] = MSW(MSD(tlv_dma));
3717 mcp->mb[7] = LSW(MSD(tlv_dma));
3718 mcp->mb[8] = size;
3719 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3720 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3721 mcp->tov = MBX_TOV_SECONDS;
3722 mcp->flags = 0;
3723 rval = qla2x00_mailbox_command(vha, mcp);
3724
3725 if (rval != QLA_SUCCESS) {
3726 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x "
3727 "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval,
3728 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
3729 } else {
3730 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3731 }
3732
3733 return rval;
3734}
Andrew Vasquez18e75552009-06-03 09:55:30 -07003735
3736int
3737qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3738{
3739 int rval;
3740 mbx_cmd_t mc;
3741 mbx_cmd_t *mcp = &mc;
3742
3743 if (!IS_FWI2_CAPABLE(vha->hw))
3744 return QLA_FUNCTION_FAILED;
3745
3746 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3747
3748 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3749 mcp->mb[1] = LSW(risc_addr);
3750 mcp->mb[8] = MSW(risc_addr);
3751 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3752 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3753 mcp->tov = 30;
3754 mcp->flags = 0;
3755 rval = qla2x00_mailbox_command(vha, mcp);
3756 if (rval != QLA_SUCCESS) {
3757 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3758 vha->host_no, rval, mcp->mb[0]));
3759 } else {
3760 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3761 *data = mcp->mb[3] << 16 | mcp->mb[2];
3762 }
3763
3764 return rval;
3765}
3766
3767int
Giridhar Malavalia9083012010-04-12 17:59:55 -07003768qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
3769 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003770{
3771 int rval;
3772 mbx_cmd_t mc;
3773 mbx_cmd_t *mcp = &mc;
3774 uint32_t iter_cnt = 0x1;
3775
3776 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3777
3778 memset(mcp->mb, 0 , sizeof(mcp->mb));
3779 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3780 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3781
3782 /* transfer count */
3783 mcp->mb[10] = LSW(mreq->transfer_size);
3784 mcp->mb[11] = MSW(mreq->transfer_size);
3785
3786 /* send data address */
3787 mcp->mb[14] = LSW(mreq->send_dma);
3788 mcp->mb[15] = MSW(mreq->send_dma);
3789 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3790 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3791
3792 /* recieve data address */
3793 mcp->mb[16] = LSW(mreq->rcv_dma);
3794 mcp->mb[17] = MSW(mreq->rcv_dma);
3795 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3796 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3797
3798 /* Iteration count */
3799 mcp->mb[18] = LSW(iter_cnt);
3800 mcp->mb[19] = MSW(iter_cnt);
3801
3802 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3803 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003804 if (IS_QLA8XXX_TYPE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003805 mcp->out_mb |= MBX_2;
3806 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3807
3808 mcp->buf_size = mreq->transfer_size;
3809 mcp->tov = MBX_TOV_SECONDS;
3810 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3811
3812 rval = qla2x00_mailbox_command(vha, mcp);
3813
3814 if (rval != QLA_SUCCESS) {
3815 DEBUG2(printk(KERN_WARNING
Giridhar Malavalia9083012010-04-12 17:59:55 -07003816 "(%ld): failed=%x mb[0]=0x%x "
3817 "mb[1]=0x%x mb[2]=0x%x mb[3]=0x%x mb[18]=0x%x "
3818 "mb[19]=0x%x.\n",
3819 vha->host_no, rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
3820 mcp->mb[3], mcp->mb[18], mcp->mb[19]));
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003821 } else {
3822 DEBUG2(printk(KERN_WARNING
3823 "scsi(%ld): done.\n", vha->host_no));
3824 }
3825
3826 /* Copy mailbox information */
3827 memcpy( mresp, mcp->mb, 64);
3828 mresp[3] = mcp->mb[18];
3829 mresp[4] = mcp->mb[19];
3830 return rval;
3831}
3832
3833int
Giridhar Malavalia9083012010-04-12 17:59:55 -07003834qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
3835 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003836{
3837 int rval;
3838 mbx_cmd_t mc;
3839 mbx_cmd_t *mcp = &mc;
3840 struct qla_hw_data *ha = vha->hw;
3841
3842 DEBUG11(printk("scsi(%ld): entered.\n", vha->host_no));
3843
3844 memset(mcp->mb, 0 , sizeof(mcp->mb));
3845 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3846 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003847 if (IS_QLA8XXX_TYPE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003848 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003849 mcp->mb[2] = vha->fcoe_fcf_idx;
3850 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003851 mcp->mb[16] = LSW(mreq->rcv_dma);
3852 mcp->mb[17] = MSW(mreq->rcv_dma);
3853 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3854 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3855
3856 mcp->mb[10] = LSW(mreq->transfer_size);
3857
3858 mcp->mb[14] = LSW(mreq->send_dma);
3859 mcp->mb[15] = MSW(mreq->send_dma);
3860 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3861 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3862
3863 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3864 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003865 if (IS_QLA8XXX_TYPE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003866 mcp->out_mb |= MBX_2;
3867
3868 mcp->in_mb = MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003869 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003870 mcp->in_mb |= MBX_1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003871 if (IS_QLA8XXX_TYPE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003872 mcp->in_mb |= MBX_3;
3873
3874 mcp->tov = MBX_TOV_SECONDS;
3875 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3876 mcp->buf_size = mreq->transfer_size;
3877
3878 rval = qla2x00_mailbox_command(vha, mcp);
3879
3880 if (rval != QLA_SUCCESS) {
3881 DEBUG2(printk(KERN_WARNING
3882 "(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3883 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3884 } else {
3885 DEBUG2(printk(KERN_WARNING
3886 "scsi(%ld): done.\n", vha->host_no));
3887 }
3888
3889 /* Copy mailbox information */
3890 memcpy( mresp, mcp->mb, 32);
3891 return rval;
3892}
3893int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003894qla84xx_reset_chip(scsi_qla_host_t *ha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003895{
3896 int rval;
3897 mbx_cmd_t mc;
3898 mbx_cmd_t *mcp = &mc;
3899
3900 DEBUG16(printk("%s(%ld): enable_diag=%d entered.\n", __func__,
3901 ha->host_no, enable_diagnostic));
3902
3903 mcp->mb[0] = MBC_ISP84XX_RESET;
3904 mcp->mb[1] = enable_diagnostic;
3905 mcp->out_mb = MBX_1|MBX_0;
3906 mcp->in_mb = MBX_1|MBX_0;
3907 mcp->tov = MBX_TOV_SECONDS;
3908 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3909 rval = qla2x00_mailbox_command(ha, mcp);
3910
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003911 if (rval != QLA_SUCCESS)
3912 DEBUG16(printk("%s(%ld): failed=%x.\n", __func__, ha->host_no,
3913 rval));
3914 else
3915 DEBUG16(printk("%s(%ld): done.\n", __func__, ha->host_no));
3916
3917 return rval;
3918}
3919
3920int
Andrew Vasquez18e75552009-06-03 09:55:30 -07003921qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3922{
3923 int rval;
3924 mbx_cmd_t mc;
3925 mbx_cmd_t *mcp = &mc;
3926
3927 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07003928 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07003929
3930 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3931
3932 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3933 mcp->mb[1] = LSW(risc_addr);
3934 mcp->mb[2] = LSW(data);
3935 mcp->mb[3] = MSW(data);
3936 mcp->mb[8] = MSW(risc_addr);
3937 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3938 mcp->in_mb = MBX_0;
3939 mcp->tov = 30;
3940 mcp->flags = 0;
3941 rval = qla2x00_mailbox_command(vha, mcp);
3942 if (rval != QLA_SUCCESS) {
3943 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
3944 vha->host_no, rval, mcp->mb[0]));
3945 } else {
3946 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3947 }
3948
3949 return rval;
3950}
Michael Hernandez3064ff32009-12-15 21:29:44 -08003951
3952int
3953qla2x00_get_data_rate(scsi_qla_host_t *vha)
3954{
3955 int rval;
3956 mbx_cmd_t mc;
3957 mbx_cmd_t *mcp = &mc;
3958 struct qla_hw_data *ha = vha->hw;
3959
3960 if (!IS_FWI2_CAPABLE(ha))
3961 return QLA_FUNCTION_FAILED;
3962
Giridhar Malavalia9083012010-04-12 17:59:55 -07003963 DEBUG11(qla_printk(KERN_INFO, ha,
3964 "%s(%ld): entered.\n", __func__, vha->host_no));
Michael Hernandez3064ff32009-12-15 21:29:44 -08003965
3966 mcp->mb[0] = MBC_DATA_RATE;
3967 mcp->mb[1] = 0;
3968 mcp->out_mb = MBX_1|MBX_0;
3969 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3970 mcp->tov = MBX_TOV_SECONDS;
3971 mcp->flags = 0;
3972 rval = qla2x00_mailbox_command(vha, mcp);
3973 if (rval != QLA_SUCCESS) {
3974 DEBUG2_3_11(printk(KERN_INFO "%s(%ld): failed=%x mb[0]=%x.\n",
3975 __func__, vha->host_no, rval, mcp->mb[0]));
3976 } else {
3977 DEBUG11(printk(KERN_INFO
3978 "%s(%ld): done.\n", __func__, vha->host_no));
3979 if (mcp->mb[1] != 0x7)
3980 ha->link_data_rate = mcp->mb[1];
3981 }
3982
3983 return rval;
3984}
Sarang Radke09ff7012010-03-19 17:03:59 -07003985
3986int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07003987qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
3988{
3989 int rval;
3990 mbx_cmd_t mc;
3991 mbx_cmd_t *mcp = &mc;
3992 struct qla_hw_data *ha = vha->hw;
3993
3994 DEBUG11(printk(KERN_INFO
3995 "%s(%ld): entered.\n", __func__, vha->host_no));
3996
3997 if (!IS_QLA81XX(ha))
3998 return QLA_FUNCTION_FAILED;
3999 mcp->mb[0] = MBC_GET_PORT_CONFIG;
4000 mcp->out_mb = MBX_0;
4001 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4002 mcp->tov = MBX_TOV_SECONDS;
4003 mcp->flags = 0;
4004
4005 rval = qla2x00_mailbox_command(vha, mcp);
4006
4007 if (rval != QLA_SUCCESS) {
4008 DEBUG2_3_11(printk(KERN_WARNING
4009 "%s(%ld): failed=%x (%x).\n", __func__,
4010 vha->host_no, rval, mcp->mb[0]));
4011 } else {
4012 /* Copy all bits to preserve original value */
4013 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
4014
4015 DEBUG11(printk(KERN_INFO
4016 "%s(%ld): done.\n", __func__, vha->host_no));
4017 }
4018 return rval;
4019}
4020
4021int
4022qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4023{
4024 int rval;
4025 mbx_cmd_t mc;
4026 mbx_cmd_t *mcp = &mc;
4027
4028 DEBUG11(printk(KERN_INFO
4029 "%s(%ld): entered.\n", __func__, vha->host_no));
4030
4031 mcp->mb[0] = MBC_SET_PORT_CONFIG;
4032 /* Copy all bits to preserve original setting */
4033 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
4034 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4035 mcp->in_mb = MBX_0;
4036 mcp->tov = MBX_TOV_SECONDS;
4037 mcp->flags = 0;
4038 rval = qla2x00_mailbox_command(vha, mcp);
4039
4040 if (rval != QLA_SUCCESS) {
4041 DEBUG2_3_11(printk(KERN_WARNING
4042 "%s(%ld): failed=%x (%x).\n", __func__,
4043 vha->host_no, rval, mcp->mb[0]));
4044 } else
4045 DEBUG11(printk(KERN_INFO
4046 "%s(%ld): done.\n", __func__, vha->host_no));
4047
4048 return rval;
4049}
4050
4051
4052int
Sarang Radke09ff7012010-03-19 17:03:59 -07004053qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
4054 uint16_t *mb)
4055{
4056 int rval;
4057 mbx_cmd_t mc;
4058 mbx_cmd_t *mcp = &mc;
4059 struct qla_hw_data *ha = vha->hw;
4060
4061 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
4062 return QLA_FUNCTION_FAILED;
4063
4064 DEBUG11(printk(KERN_INFO
4065 "%s(%ld): entered.\n", __func__, ha->host_no));
4066
4067 mcp->mb[0] = MBC_PORT_PARAMS;
4068 mcp->mb[1] = loop_id;
4069 if (ha->flags.fcp_prio_enabled)
4070 mcp->mb[2] = BIT_1;
4071 else
4072 mcp->mb[2] = BIT_2;
4073 mcp->mb[4] = priority & 0xf;
4074 mcp->mb[9] = vha->vp_idx;
4075 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4076 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4077 mcp->tov = 30;
4078 mcp->flags = 0;
4079 rval = qla2x00_mailbox_command(vha, mcp);
4080 if (mb != NULL) {
4081 mb[0] = mcp->mb[0];
4082 mb[1] = mcp->mb[1];
4083 mb[3] = mcp->mb[3];
4084 mb[4] = mcp->mb[4];
4085 }
4086
4087 if (rval != QLA_SUCCESS) {
4088 DEBUG2_3_11(printk(KERN_WARNING
4089 "%s(%ld): failed=%x.\n", __func__,
4090 vha->host_no, rval));
4091 } else {
4092 DEBUG11(printk(KERN_INFO
4093 "%s(%ld): done.\n", __func__, vha->host_no));
4094 }
4095
4096 return rval;
4097}
Giridhar Malavalia9083012010-04-12 17:59:55 -07004098
4099int
4100qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
4101{
4102 int rval;
4103 struct qla_hw_data *ha = vha->hw;
4104 mbx_cmd_t mc;
4105 mbx_cmd_t *mcp = &mc;
4106
4107 if (!IS_FWI2_CAPABLE(ha))
4108 return QLA_FUNCTION_FAILED;
4109
4110 DEBUG11(qla_printk(KERN_INFO, ha,
4111 "%s(%ld): entered.\n", __func__, vha->host_no));
4112
4113 memset(mcp, 0, sizeof(mbx_cmd_t));
4114 mcp->mb[0] = MBC_TOGGLE_INTR;
4115 mcp->mb[1] = 1;
4116
4117 mcp->out_mb = MBX_1|MBX_0;
4118 mcp->in_mb = MBX_0;
4119 mcp->tov = 30;
4120 mcp->flags = 0;
4121
4122 rval = qla2x00_mailbox_command(vha, mcp);
4123 if (rval != QLA_SUCCESS) {
4124 DEBUG2_3_11(qla_printk(KERN_WARNING, ha,
4125 "%s(%ld): failed=%x mb[0]=%x.\n", __func__,
4126 vha->host_no, rval, mcp->mb[0]));
4127 } else {
4128 DEBUG11(qla_printk(KERN_INFO, ha,
4129 "%s(%ld): done.\n", __func__, vha->host_no));
4130 }
4131
4132 return rval;
4133}
4134
4135int
4136qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
4137{
4138 int rval;
4139 struct qla_hw_data *ha = vha->hw;
4140 mbx_cmd_t mc;
4141 mbx_cmd_t *mcp = &mc;
4142
4143 if (!IS_QLA82XX(ha))
4144 return QLA_FUNCTION_FAILED;
4145
4146 DEBUG11(qla_printk(KERN_INFO, ha,
4147 "%s(%ld): entered.\n", __func__, vha->host_no));
4148
4149 memset(mcp, 0, sizeof(mbx_cmd_t));
4150 mcp->mb[0] = MBC_TOGGLE_INTR;
4151 mcp->mb[1] = 0;
4152
4153 mcp->out_mb = MBX_1|MBX_0;
4154 mcp->in_mb = MBX_0;
4155 mcp->tov = 30;
4156 mcp->flags = 0;
4157
4158 rval = qla2x00_mailbox_command(vha, mcp);
4159 if (rval != QLA_SUCCESS) {
4160 DEBUG2_3_11(qla_printk(KERN_WARNING, ha,
4161 "%s(%ld): failed=%x mb[0]=%x.\n", __func__,
4162 vha->host_no, rval, mcp->mb[0]));
4163 } else {
4164 DEBUG11(qla_printk(KERN_INFO, ha,
4165 "%s(%ld): done.\n", __func__, vha->host_no));
4166 }
4167
4168 return rval;
4169}