blob: 82a33533ed26c25dc87e90cfe1a35f95c33ccb44 [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 Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 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
Saurav Kashyap7c3df132011-07-14 12:00:13 -070049 ql_dbg(ql_dbg_mbx, base_vha, 0x1000, "Entered %s.\n", __func__);
50
51 if (ha->pdev->error_state > pci_channel_io_frozen) {
52 ql_log(ql_log_warn, base_vha, 0x1001,
53 "error_state is greater than pci_channel_io_frozen, "
54 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -070055 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -070056 }
Seokmann Jub9b12f72009-03-24 09:08:18 -070057
Giridhar Malavalia9083012010-04-12 17:59:55 -070058 if (vha->device_flags & DFLG_DEV_FAILED) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -070059 ql_log(ql_log_warn, base_vha, 0x1002,
60 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -070061 return QLA_FUNCTION_TIMEOUT;
62 }
63
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070064 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080065 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080068 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070070
Andrew Vasquez85880802009-12-15 21:29:46 -080071 if (ha->flags.pci_channel_io_perm_failure) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -070072 ql_log(ql_log_warn, base_vha, 0x1003,
73 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -080074 return QLA_FUNCTION_TIMEOUT;
75 }
76
Giridhar Malavali862cd012011-02-23 15:27:11 -080077 if (ha->flags.isp82xx_fw_hung) {
78 /* Setting Link-Down error */
79 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Saurav Kashyap7c3df132011-07-14 12:00:13 -070080 ql_log(ql_log_warn, base_vha, 0x1004,
81 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -080082 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -080083 }
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070086 * Wait for active mailbox commands to finish by waiting at most tov
87 * seconds. This is to serialize actual issuing of mailbox cmds during
88 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080090 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
91 /* Timeout occurred. Return error. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -070092 ql_log(ql_log_warn, base_vha, 0x1005,
93 "Cmd access timeout, Exiting.\n");
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080094 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
96
97 ha->flags.mbox_busy = 1;
98 /* Save mailbox command for debug */
99 ha->mcp = mcp;
100
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700101 ql_dbg(ql_dbg_mbx, base_vha, 0x1006,
102 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 spin_lock_irqsave(&ha->hardware_lock, flags);
105
106 /* Load mailbox registers. */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700107 if (IS_QLA82XX(ha))
108 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
109 else if (IS_FWI2_CAPABLE(ha) && !IS_QLA82XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700110 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
111 else
112 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 iptr = mcp->mb;
115 command = mcp->mb[0];
116 mboxes = mcp->out_mb;
117
118 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
119 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700120 optr =
121 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 if (mboxes & BIT_0)
123 WRT_REG_WORD(optr, *iptr);
124
125 mboxes >>= 1;
126 optr++;
127 iptr++;
128 }
129
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700130 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1111,
131 "Loaded MBX registers (displayed in bytes) =.\n");
132 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1112,
133 (uint8_t *)mcp->mb, 16);
134 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1113,
135 ".\n");
136 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1114,
137 ((uint8_t *)mcp->mb + 0x10), 16);
138 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1115,
139 ".\n");
140 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1116,
141 ((uint8_t *)mcp->mb + 0x20), 8);
142 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1117,
143 "I/O Address = %p.\n", optr);
144 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x100e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* Issue set host interrupt command to send cmd out. */
147 ha->flags.mbox_int = 0;
148 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
149
150 /* Unlock mbx registers and wait for interrupt */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700151 ql_dbg(ql_dbg_mbx, base_vha, 0x100f,
152 "Going to unlock irq & waiting for interrupts. "
153 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
155 /* Wait for mbx cmd completion until timeout */
156
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800157 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
159
Giridhar Malavalia9083012010-04-12 17:59:55 -0700160 if (IS_QLA82XX(ha)) {
161 if (RD_REG_DWORD(&reg->isp82.hint) &
162 HINT_MBX_INT_PENDING) {
163 spin_unlock_irqrestore(&ha->hardware_lock,
164 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800165 ha->flags.mbox_busy = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700166 ql_dbg(ql_dbg_mbx, base_vha, 0x1010,
167 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700168 rval = QLA_FUNCTION_TIMEOUT;
169 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700170 }
171 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
172 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700173 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
174 else
175 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 spin_unlock_irqrestore(&ha->hardware_lock, flags);
177
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800178 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700183 ql_dbg(ql_dbg_mbx, base_vha, 0x1011,
184 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
Giridhar Malavalia9083012010-04-12 17:59:55 -0700186 if (IS_QLA82XX(ha)) {
187 if (RD_REG_DWORD(&reg->isp82.hint) &
188 HINT_MBX_INT_PENDING) {
189 spin_unlock_irqrestore(&ha->hardware_lock,
190 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800191 ha->flags.mbox_busy = 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700192 ql_dbg(ql_dbg_mbx, base_vha, 0x1012,
193 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700194 rval = QLA_FUNCTION_TIMEOUT;
195 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700196 }
197 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
198 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700199 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
200 else
201 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
205 while (!ha->flags.mbox_int) {
206 if (time_after(jiffies, wait_time))
207 break;
208
209 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800210 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Andrew Vasquez85880802009-12-15 21:29:46 -0800212 if (!ha->flags.mbox_int &&
213 !(IS_QLA2200(ha) &&
214 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800215 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 } /* while */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700217 ql_dbg(ql_dbg_mbx, base_vha, 0x1013,
218 "Waited %d sec.\n",
219 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 /* Check whether we timed out */
223 if (ha->flags.mbox_int) {
224 uint16_t *iptr2;
225
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700226 ql_dbg(ql_dbg_mbx, base_vha, 0x1014,
227 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* Got interrupt. Clear the flag. */
230 ha->flags.mbox_int = 0;
231 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
232
Giridhar Malavali71905752011-02-23 15:27:10 -0800233 if (ha->flags.isp82xx_fw_hung) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700234 ha->flags.mbox_busy = 0;
235 /* Setting Link-Down error */
236 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
237 ha->mcp = NULL;
238 rval = QLA_FUNCTION_FAILED;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700239 ql_log(ql_log_warn, base_vha, 0x1015,
240 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700241 goto premature_exit;
242 }
243
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400244 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246
247 /* Load return mailbox registers. */
248 iptr2 = mcp->mb;
249 iptr = (uint16_t *)&ha->mailbox_out[0];
250 mboxes = mcp->in_mb;
251 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
252 if (mboxes & BIT_0)
253 *iptr2 = *iptr;
254
255 mboxes >>= 1;
256 iptr2++;
257 iptr++;
258 }
259 } else {
260
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700261 uint16_t mb0;
262 uint32_t ictrl;
263
Andrew Vasqueze4289242007-07-19 15:05:56 -0700264 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700265 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
266 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
267 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700268 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700269 ictrl = RD_REG_WORD(&reg->isp.ictrl);
270 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700271 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1119,
272 "MBX Command timeout for cmd %x.\n", command);
273 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x111a,
274 "iocontrol=%x jiffies=%lx.\n", ictrl, jiffies);
275 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x111b,
276 "mb[0] = 0x%x.\n", mb0);
277 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, base_vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 rval = QLA_FUNCTION_TIMEOUT;
280 }
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 ha->flags.mbox_busy = 0;
283
284 /* Clean up */
285 ha->mcp = NULL;
286
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800287 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700288 ql_dbg(ql_dbg_mbx, base_vha, 0x101a,
289 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
291 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800292 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
294
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700295 if (rval == QLA_FUNCTION_TIMEOUT &&
296 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800297 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
298 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 /* not in dpc. schedule it for dpc to take over. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700300 ql_dbg(ql_dbg_mbx, base_vha, 0x101b,
301 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700302
303 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
304 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
305 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800306 if (IS_QLA82XX(ha)) {
307 ql_dbg(ql_dbg_mbx, vha, 0x112a,
308 "disabling pause transmit on port "
309 "0 & 1.\n");
310 qla82xx_wr_32(ha,
311 QLA82XX_CRB_NIU + 0x98,
312 CRB_NIU_XG_PAUSE_CTL_P0|
313 CRB_NIU_XG_PAUSE_CTL_P1);
314 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700315 ql_log(ql_log_info, base_vha, 0x101c,
316 "Mailbox cmd timeout occured. "
317 "Scheduling ISP abort eeh_busy=0x%x.\n",
318 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700319 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
320 qla2xxx_wake_dpc(vha);
321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 /* call abort directly since we are in the DPC thread */
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700324 ql_dbg(ql_dbg_mbx, base_vha, 0x101d,
325 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700327 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
328 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
329 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800330 if (IS_QLA82XX(ha)) {
331 ql_dbg(ql_dbg_mbx, vha, 0x112b,
332 "disabling pause transmit on port "
333 "0 & 1.\n");
334 qla82xx_wr_32(ha,
335 QLA82XX_CRB_NIU + 0x98,
336 CRB_NIU_XG_PAUSE_CTL_P0|
337 CRB_NIU_XG_PAUSE_CTL_P1);
338 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700339 ql_log(ql_log_info, base_vha, 0x101e,
340 "Mailbox cmd timeout occured. "
341 "Scheduling ISP abort.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700342
343 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
344 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
345 if (ha->isp_ops->abort_isp(vha)) {
346 /* Failed. retry later. */
347 set_bit(ISP_ABORT_NEEDED,
348 &vha->dpc_flags);
349 }
350 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700351 ql_dbg(ql_dbg_mbx, base_vha, 0x101f,
352 "Finished abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355 }
356
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700357premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800359 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 if (rval) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700362 ql_dbg(ql_dbg_mbx, base_vha, 0x1020,
363 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, cmd=%x ****.\n",
364 mcp->mb[0], mcp->mb[1], mcp->mb[2], command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700366 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 return rval;
370}
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800373qla2x00_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 -0800374 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
376 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800377 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 mbx_cmd_t mc;
379 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700381 ql_dbg(ql_dbg_mbx, vha, 0x1022, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Andrew Vasqueze4289242007-07-19 15:05:56 -0700383 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800384 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
385 mcp->mb[8] = MSW(risc_addr);
386 mcp->out_mb = MBX_8|MBX_0;
387 } else {
388 mcp->mb[0] = MBC_LOAD_RISC_RAM;
389 mcp->out_mb = MBX_0;
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 mcp->mb[1] = LSW(risc_addr);
392 mcp->mb[2] = MSW(req_dma);
393 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 mcp->mb[6] = MSW(MSD(req_dma));
395 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800396 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700397 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700398 mcp->mb[4] = MSW(risc_code_size);
399 mcp->mb[5] = LSW(risc_code_size);
400 mcp->out_mb |= MBX_5|MBX_4;
401 } else {
402 mcp->mb[4] = LSW(risc_code_size);
403 mcp->out_mb |= MBX_4;
404 }
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700407 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800409 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700412 ql_dbg(ql_dbg_mbx, vha, 0x1023,
413 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700415 ql_dbg(ql_dbg_mbx, vha, 0x1024, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
418 return rval;
419}
420
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700421#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422/*
423 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700424 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 *
426 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700427 * ha = adapter block pointer.
428 * TARGET_QUEUE_LOCK must be released.
429 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 *
431 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700432 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 *
434 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700435 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 */
437int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800438qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
440 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800441 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 mbx_cmd_t mc;
443 mbx_cmd_t *mcp = &mc;
444
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700445 ql_dbg(ql_dbg_mbx, vha, 0x1025, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700448 mcp->out_mb = MBX_0;
449 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700450 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700451 mcp->mb[1] = MSW(risc_addr);
452 mcp->mb[2] = LSW(risc_addr);
453 mcp->mb[3] = 0;
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700454 if (IS_QLA81XX(ha)) {
455 struct nvram_81xx *nv = ha->nvram;
456 mcp->mb[4] = (nv->enhanced_features &
457 EXTENDED_BB_CREDITS);
458 } else
459 mcp->mb[4] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700460 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700461 mcp->in_mb |= MBX_1;
462 } else {
463 mcp->mb[1] = LSW(risc_addr);
464 mcp->out_mb |= MBX_1;
465 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
466 mcp->mb[2] = 0;
467 mcp->out_mb |= MBX_2;
468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470
Ravi Anandb93480e2008-04-03 13:13:25 -0700471 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800473 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700475 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700476 ql_dbg(ql_dbg_mbx, vha, 0x1026,
477 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700478 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700479 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700480 ql_dbg(ql_dbg_mbx, vha, 0x1027,
481 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700482 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700483 ql_dbg(ql_dbg_mbx, vha, 0x1028, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700484 }
485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 return rval;
488}
489
490/*
491 * qla2x00_get_fw_version
492 * Get firmware version.
493 *
494 * Input:
495 * ha: adapter state pointer.
496 * major: pointer for major number.
497 * minor: pointer for minor number.
498 * subminor: pointer for subminor number.
499 *
500 * Returns:
501 * qla2x00 local function return status code.
502 *
503 * Context:
504 * Kernel context.
505 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700506int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800507qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800508 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700509 uint32_t *mpi_caps, uint8_t *phy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
511 int rval;
512 mbx_cmd_t mc;
513 mbx_cmd_t *mcp = &mc;
514
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700515 ql_dbg(ql_dbg_mbx, vha, 0x1029, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
517 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
518 mcp->out_mb = MBX_0;
519 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800520 if (IS_QLA81XX(vha->hw))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700521 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700523 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800524 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700525 if (rval != QLA_SUCCESS)
526 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 /* Return mailbox data. */
529 *major = mcp->mb[1];
530 *minor = mcp->mb[2];
531 *subminor = mcp->mb[3];
532 *attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800533 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 *memory = 0x1FFFF; /* Defaults to 128KB. */
535 else
536 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800537 if (IS_QLA81XX(vha->hw)) {
Andrew Vasquez55a96152009-03-24 09:08:03 -0700538 mpi[0] = mcp->mb[10] & 0xff;
539 mpi[1] = mcp->mb[11] >> 8;
540 mpi[2] = mcp->mb[11] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800541 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
Andrew Vasquez55a96152009-03-24 09:08:03 -0700542 phy[0] = mcp->mb[8] & 0xff;
543 phy[1] = mcp->mb[9] >> 8;
544 phy[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800545 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700546failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 if (rval != QLA_SUCCESS) {
548 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700549 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 } else {
551 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700552 ql_dbg(ql_dbg_mbx, vha, 0x102b, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700554 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
557/*
558 * qla2x00_get_fw_options
559 * Set firmware options.
560 *
561 * Input:
562 * ha = adapter block pointer.
563 * fwopt = pointer for firmware options.
564 *
565 * Returns:
566 * qla2x00 local function return status code.
567 *
568 * Context:
569 * Kernel context.
570 */
571int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800572qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
574 int rval;
575 mbx_cmd_t mc;
576 mbx_cmd_t *mcp = &mc;
577
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700578 ql_dbg(ql_dbg_mbx, vha, 0x102c, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
581 mcp->out_mb = MBX_0;
582 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700583 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800585 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 if (rval != QLA_SUCCESS) {
588 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700589 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700591 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 fwopts[1] = mcp->mb[1];
593 fwopts[2] = mcp->mb[2];
594 fwopts[3] = mcp->mb[3];
595
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700596 ql_dbg(ql_dbg_mbx, vha, 0x102e, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
599 return rval;
600}
601
602
603/*
604 * qla2x00_set_fw_options
605 * Set firmware options.
606 *
607 * Input:
608 * ha = adapter block pointer.
609 * fwopt = pointer for firmware options.
610 *
611 * Returns:
612 * qla2x00 local function return status code.
613 *
614 * Context:
615 * Kernel context.
616 */
617int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800618qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
620 int rval;
621 mbx_cmd_t mc;
622 mbx_cmd_t *mcp = &mc;
623
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700624 ql_dbg(ql_dbg_mbx, vha, 0x102f, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
627 mcp->mb[1] = fwopts[1];
628 mcp->mb[2] = fwopts[2];
629 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700630 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800632 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700633 mcp->in_mb |= MBX_1;
634 } else {
635 mcp->mb[10] = fwopts[10];
636 mcp->mb[11] = fwopts[11];
637 mcp->mb[12] = 0; /* Undocumented, but used */
638 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
639 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700640 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800642 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700644 fwopts[0] = mcp->mb[0];
645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (rval != QLA_SUCCESS) {
647 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700648 ql_dbg(ql_dbg_mbx, vha, 0x1030,
649 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 } else {
651 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700652 ql_dbg(ql_dbg_mbx, vha, 0x1031, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654
655 return rval;
656}
657
658/*
659 * qla2x00_mbx_reg_test
660 * Mailbox register wrap test.
661 *
662 * Input:
663 * ha = adapter block pointer.
664 * TARGET_QUEUE_LOCK must be released.
665 * ADAPTER_STATE_LOCK must be released.
666 *
667 * Returns:
668 * qla2x00 local function return status code.
669 *
670 * Context:
671 * Kernel context.
672 */
673int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800674qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675{
676 int rval;
677 mbx_cmd_t mc;
678 mbx_cmd_t *mcp = &mc;
679
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700680 ql_dbg(ql_dbg_mbx, vha, 0x1032, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
683 mcp->mb[1] = 0xAAAA;
684 mcp->mb[2] = 0x5555;
685 mcp->mb[3] = 0xAA55;
686 mcp->mb[4] = 0x55AA;
687 mcp->mb[5] = 0xA5A5;
688 mcp->mb[6] = 0x5A5A;
689 mcp->mb[7] = 0x2525;
690 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
691 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 -0700692 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800694 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 if (rval == QLA_SUCCESS) {
697 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
698 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
699 rval = QLA_FUNCTION_FAILED;
700 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
701 mcp->mb[7] != 0x2525)
702 rval = QLA_FUNCTION_FAILED;
703 }
704
705 if (rval != QLA_SUCCESS) {
706 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700707 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 } else {
709 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700710 ql_dbg(ql_dbg_mbx, vha, 0x1034, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
712
713 return rval;
714}
715
716/*
717 * qla2x00_verify_checksum
718 * Verify firmware checksum.
719 *
720 * Input:
721 * ha = adapter block pointer.
722 * TARGET_QUEUE_LOCK must be released.
723 * ADAPTER_STATE_LOCK must be released.
724 *
725 * Returns:
726 * qla2x00 local function return status code.
727 *
728 * Context:
729 * Kernel context.
730 */
731int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800732qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 int rval;
735 mbx_cmd_t mc;
736 mbx_cmd_t *mcp = &mc;
737
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700738 ql_dbg(ql_dbg_mbx, vha, 0x1035, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
740 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700741 mcp->out_mb = MBX_0;
742 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800743 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700744 mcp->mb[1] = MSW(risc_addr);
745 mcp->mb[2] = LSW(risc_addr);
746 mcp->out_mb |= MBX_2|MBX_1;
747 mcp->in_mb |= MBX_2|MBX_1;
748 } else {
749 mcp->mb[1] = LSW(risc_addr);
750 mcp->out_mb |= MBX_1;
751 mcp->in_mb |= MBX_1;
752 }
753
Ravi Anandb93480e2008-04-03 13:13:25 -0700754 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800756 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700759 ql_dbg(ql_dbg_mbx, vha, 0x1036,
760 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
761 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700763 ql_dbg(ql_dbg_mbx, vha, 0x1037, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765
766 return rval;
767}
768
769/*
770 * qla2x00_issue_iocb
771 * Issue IOCB using mailbox command
772 *
773 * Input:
774 * ha = adapter state pointer.
775 * buffer = buffer pointer.
776 * phys_addr = physical address of buffer.
777 * size = size of buffer.
778 * TARGET_QUEUE_LOCK must be released.
779 * ADAPTER_STATE_LOCK must be released.
780 *
781 * Returns:
782 * qla2x00 local function return status code.
783 *
784 * Context:
785 * Kernel context.
786 */
Giridhar Malavali6e980162010-03-19 17:03:58 -0700787int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800788qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700789 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 int rval;
792 mbx_cmd_t mc;
793 mbx_cmd_t *mcp = &mc;
794
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700795 ql_dbg(ql_dbg_mbx, vha, 0x1038, "Entered %s.\n", __func__);
796
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
798 mcp->mb[1] = 0;
799 mcp->mb[2] = MSW(phys_addr);
800 mcp->mb[3] = LSW(phys_addr);
801 mcp->mb[6] = MSW(MSD(phys_addr));
802 mcp->mb[7] = LSW(MSD(phys_addr));
803 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
804 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700805 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800807 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 if (rval != QLA_SUCCESS) {
810 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700811 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700813 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
814
815 /* Mask reserved bits. */
816 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800817 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700818 ql_dbg(ql_dbg_mbx, vha, 0x103a, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 }
820
821 return rval;
822}
823
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700824int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800825qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700826 size_t size)
827{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800828 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700829 MBX_TOV_SECONDS);
830}
831
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832/*
833 * qla2x00_abort_command
834 * Abort command aborts a specified IOCB.
835 *
836 * Input:
837 * ha = adapter block pointer.
838 * sp = SB structure pointer.
839 *
840 * Returns:
841 * qla2x00 local function return status code.
842 *
843 * Context:
844 * Kernel context.
845 */
846int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700847qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848{
849 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800851 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 mbx_cmd_t mc;
853 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700854 fc_port_t *fcport = sp->fcport;
855 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800856 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700857 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700859 ql_dbg(ql_dbg_mbx, vha, 0x103b, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700861 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800863 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 break;
865 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700866 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (handle == MAX_OUTSTANDING_COMMANDS) {
869 /* command not found */
870 return QLA_FUNCTION_FAILED;
871 }
872
873 mcp->mb[0] = MBC_ABORT_COMMAND;
874 if (HAS_EXTENDED_IDS(ha))
875 mcp->mb[1] = fcport->loop_id;
876 else
877 mcp->mb[1] = fcport->loop_id << 8;
878 mcp->mb[2] = (uint16_t)handle;
879 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500880 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
882 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700883 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800885 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700888 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700890 ql_dbg(ql_dbg_mbx, vha, 0x103d, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 }
892
893 return rval;
894}
895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700897qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700899 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 mbx_cmd_t mc;
901 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800902 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800903 struct req_que *req;
904 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905
Andrew Vasquez523ec772008-04-03 13:13:24 -0700906 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800907 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700908
909 ql_dbg(ql_dbg_mbx, vha, 0x103e, "Entered %s.\n", __func__);
910
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700911 req = vha->hw->req_q_map[0];
912 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700914 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800915 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 mcp->mb[1] = fcport->loop_id;
917 mcp->mb[10] = 0;
918 mcp->out_mb |= MBX_10;
919 } else {
920 mcp->mb[1] = fcport->loop_id << 8;
921 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800922 mcp->mb[2] = vha->hw->loop_reset_delay;
923 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
925 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700926 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800928 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700930 ql_dbg(ql_dbg_mbx, vha, 0x103f, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700931 }
932
933 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800934 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
935 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700936 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700937 ql_dbg(ql_dbg_mbx, vha, 0x1040,
938 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 ql_dbg(ql_dbg_mbx, vha, 0x1041, "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700941 }
942
943 return rval;
944}
945
946int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700947qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700948{
949 int rval, rval2;
950 mbx_cmd_t mc;
951 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800952 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800953 struct req_que *req;
954 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700955
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800956 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700957
958 ql_dbg(ql_dbg_mbx, vha, 0x1042, "Entered %s.\n", __func__);
959
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700960 req = vha->hw->req_q_map[0];
961 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700962 mcp->mb[0] = MBC_LUN_RESET;
963 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800964 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700965 mcp->mb[1] = fcport->loop_id;
966 else
967 mcp->mb[1] = fcport->loop_id << 8;
968 mcp->mb[2] = l;
969 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800970 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700971
972 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700973 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700974 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800975 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700976 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700977 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700978 }
979
980 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800981 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
982 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700983 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700984 ql_dbg(ql_dbg_mbx, vha, 0x1044,
985 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700987 ql_dbg(ql_dbg_mbx, vha, 0x1045, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 }
989
990 return rval;
991}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 * qla2x00_get_adapter_id
995 * Get adapter ID and topology.
996 *
997 * Input:
998 * ha = adapter block pointer.
999 * id = pointer for loop ID.
1000 * al_pa = pointer for AL_PA.
1001 * area = pointer for area.
1002 * domain = pointer for domain.
1003 * top = pointer for topology.
1004 * TARGET_QUEUE_LOCK must be released.
1005 * ADAPTER_STATE_LOCK must be released.
1006 *
1007 * Returns:
1008 * qla2x00 local function return status code.
1009 *
1010 * Context:
1011 * Kernel context.
1012 */
1013int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001014qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001015 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
1017 int rval;
1018 mbx_cmd_t mc;
1019 mbx_cmd_t *mcp = &mc;
1020
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001021 ql_dbg(ql_dbg_mbx, vha, 0x1046, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
1023 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001024 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001025 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001026 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001027 if (IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001028 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -07001029 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001031 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001032 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1033 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001034 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1035 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
1037 /* Return data. */
1038 *id = mcp->mb[1];
1039 *al_pa = LSB(mcp->mb[2]);
1040 *area = MSB(mcp->mb[2]);
1041 *domain = LSB(mcp->mb[3]);
1042 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001043 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 if (rval != QLA_SUCCESS) {
1046 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001047 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001049 ql_dbg(ql_dbg_mbx, vha, 0x1048, "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001050
Giridhar Malavalia9083012010-04-12 17:59:55 -07001051 if (IS_QLA8XXX_TYPE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001052 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1053 vha->fcoe_fcf_idx = mcp->mb[10];
1054 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1055 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1056 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1057 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1058 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1059 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062
1063 return rval;
1064}
1065
1066/*
1067 * qla2x00_get_retry_cnt
1068 * Get current firmware login retry count and delay.
1069 *
1070 * Input:
1071 * ha = adapter block pointer.
1072 * retry_cnt = pointer to login retry count.
1073 * tov = pointer to login timeout value.
1074 *
1075 * Returns:
1076 * qla2x00 local function return status code.
1077 *
1078 * Context:
1079 * Kernel context.
1080 */
1081int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001082qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 uint16_t *r_a_tov)
1084{
1085 int rval;
1086 uint16_t ratov;
1087 mbx_cmd_t mc;
1088 mbx_cmd_t *mcp = &mc;
1089
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001090 ql_dbg(ql_dbg_mbx, vha, 0x1049, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1093 mcp->out_mb = MBX_0;
1094 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001095 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001097 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
1099 if (rval != QLA_SUCCESS) {
1100 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001101 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1102 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 } else {
1104 /* Convert returned data and check our values. */
1105 *r_a_tov = mcp->mb[3] / 2;
1106 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1107 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1108 /* Update to the larger values */
1109 *retry_cnt = (uint8_t)mcp->mb[1];
1110 *tov = ratov;
1111 }
1112
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001113 ql_dbg(ql_dbg_mbx, vha, 0x104b,
1114 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 }
1116
1117 return rval;
1118}
1119
1120/*
1121 * qla2x00_init_firmware
1122 * Initialize adapter firmware.
1123 *
1124 * Input:
1125 * ha = adapter block pointer.
1126 * dptr = Initialization control block pointer.
1127 * size = size of initialization control block.
1128 * TARGET_QUEUE_LOCK must be released.
1129 * ADAPTER_STATE_LOCK must be released.
1130 *
1131 * Returns:
1132 * qla2x00 local function return status code.
1133 *
1134 * Context:
1135 * Kernel context.
1136 */
1137int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001138qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139{
1140 int rval;
1141 mbx_cmd_t mc;
1142 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001143 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001145 ql_dbg(ql_dbg_mbx, vha, 0x104c, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Giridhar Malavalia9083012010-04-12 17:59:55 -07001147 if (IS_QLA82XX(ha) && ql2xdbwr)
1148 qla82xx_wr_32(ha, ha->nxdb_wr_ptr,
1149 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1150
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001151 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001152 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1153 else
1154 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1155
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001156 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 mcp->mb[2] = MSW(ha->init_cb_dma);
1158 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1160 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001161 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1162 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1163 mcp->mb[1] = BIT_0;
1164 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1165 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1166 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1167 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1168 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1169 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1170 }
1171 mcp->in_mb = MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 mcp->buf_size = size;
1173 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001174 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001175 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
1177 if (rval != QLA_SUCCESS) {
1178 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001179 ql_dbg(ql_dbg_mbx, vha, 0x104d,
1180 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 } else {
1182 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001183 ql_dbg(ql_dbg_mbx, vha, 0x104e, "Done %s.\n", __func__);
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
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001216 ql_dbg(ql_dbg_mbx, vha, 0x104f, "Entered %s.\n", __func__);
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) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001221 ql_log(ql_log_warn, vha, 0x1050,
1222 "Failed to allocate port database structure.\n");
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) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001264 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1265 "Unable to verify login-state (%x/%x) for "
1266 "loop_id %x.\n", pd24->current_login_state,
1267 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001268 rval = QLA_FUNCTION_FAILED;
1269 goto gpd_error_out;
1270 }
1271
1272 /* Names are little-endian. */
1273 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1274 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1275
1276 /* Get port_id of device. */
1277 fcport->d_id.b.domain = pd24->port_id[0];
1278 fcport->d_id.b.area = pd24->port_id[1];
1279 fcport->d_id.b.al_pa = pd24->port_id[2];
1280 fcport->d_id.b.rsvd_1 = 0;
1281
1282 /* If not target must be initiator or unknown type. */
1283 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1284 fcport->port_type = FCT_INITIATOR;
1285 else
1286 fcport->port_type = FCT_TARGET;
1287 } else {
1288 /* Check for logged in state. */
1289 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1290 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001291 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1292 "Unable to verify login-state (%x/%x) - "
1293 "portid=%02x%02x%02x.\n", pd->master_state,
1294 pd->slave_state, fcport->d_id.b.domain,
1295 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001296 rval = QLA_FUNCTION_FAILED;
1297 goto gpd_error_out;
1298 }
1299
1300 /* Names are little-endian. */
1301 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1302 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1303
1304 /* Get port_id of device. */
1305 fcport->d_id.b.domain = pd->port_id[0];
1306 fcport->d_id.b.area = pd->port_id[3];
1307 fcport->d_id.b.al_pa = pd->port_id[2];
1308 fcport->d_id.b.rsvd_1 = 0;
1309
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001310 /* If not target must be initiator or unknown type. */
1311 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1312 fcport->port_type = FCT_INITIATOR;
1313 else
1314 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001315
1316 /* Passback COS information. */
1317 fcport->supported_classes = (pd->options & BIT_4) ?
1318 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 }
1320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321gpd_error_out:
1322 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1323
1324 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001325 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1326 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1327 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001329 ql_dbg(ql_dbg_mbx, vha, 0x1053, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331
1332 return rval;
1333}
1334
1335/*
1336 * qla2x00_get_firmware_state
1337 * Get adapter firmware state.
1338 *
1339 * Input:
1340 * ha = adapter block pointer.
1341 * dptr = pointer for firmware state.
1342 * TARGET_QUEUE_LOCK must be released.
1343 * ADAPTER_STATE_LOCK must be released.
1344 *
1345 * Returns:
1346 * qla2x00 local function return status code.
1347 *
1348 * Context:
1349 * Kernel context.
1350 */
1351int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001352qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353{
1354 int rval;
1355 mbx_cmd_t mc;
1356 mbx_cmd_t *mcp = &mc;
1357
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001358 ql_dbg(ql_dbg_mbx, vha, 0x1054, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1361 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001362 if (IS_FWI2_CAPABLE(vha->hw))
1363 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1364 else
1365 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001366 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001368 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001370 /* Return firmware states. */
1371 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001372 if (IS_FWI2_CAPABLE(vha->hw)) {
1373 states[1] = mcp->mb[2];
1374 states[2] = mcp->mb[3];
1375 states[3] = mcp->mb[4];
1376 states[4] = mcp->mb[5];
1377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
1379 if (rval != QLA_SUCCESS) {
1380 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001381 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 } else {
1383 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001384 ql_dbg(ql_dbg_mbx, vha, 0x1056, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 }
1386
1387 return rval;
1388}
1389
1390/*
1391 * qla2x00_get_port_name
1392 * Issue get port name mailbox command.
1393 * Returned name is in big endian format.
1394 *
1395 * Input:
1396 * ha = adapter block pointer.
1397 * loop_id = loop ID of device.
1398 * name = pointer for name.
1399 * TARGET_QUEUE_LOCK must be released.
1400 * ADAPTER_STATE_LOCK must be released.
1401 *
1402 * Returns:
1403 * qla2x00 local function return status code.
1404 *
1405 * Context:
1406 * Kernel context.
1407 */
1408int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001409qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 uint8_t opt)
1411{
1412 int rval;
1413 mbx_cmd_t mc;
1414 mbx_cmd_t *mcp = &mc;
1415
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001416 ql_dbg(ql_dbg_mbx, vha, 0x1057, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001419 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001420 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001421 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 mcp->mb[1] = loop_id;
1423 mcp->mb[10] = opt;
1424 mcp->out_mb |= MBX_10;
1425 } else {
1426 mcp->mb[1] = loop_id << 8 | opt;
1427 }
1428
1429 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001430 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001432 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 if (rval != QLA_SUCCESS) {
1435 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001436 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", 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
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001450 ql_dbg(ql_dbg_mbx, vha, 0x1059, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 }
1452
1453 return rval;
1454}
1455
1456/*
1457 * qla2x00_lip_reset
1458 * Issue LIP reset mailbox command.
1459 *
1460 * Input:
1461 * ha = adapter block pointer.
1462 * TARGET_QUEUE_LOCK must be released.
1463 * ADAPTER_STATE_LOCK must be released.
1464 *
1465 * Returns:
1466 * qla2x00 local function return status code.
1467 *
1468 * Context:
1469 * Kernel context.
1470 */
1471int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001472qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
1474 int rval;
1475 mbx_cmd_t mc;
1476 mbx_cmd_t *mcp = &mc;
1477
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001478 ql_dbg(ql_dbg_mbx, vha, 0x105a, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Giridhar Malavalia9083012010-04-12 17:59:55 -07001480 if (IS_QLA8XXX_TYPE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001481 /* Logout across all FCFs. */
1482 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1483 mcp->mb[1] = BIT_1;
1484 mcp->mb[2] = 0;
1485 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1486 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001487 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001488 mcp->mb[1] = BIT_6;
1489 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001490 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001491 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001493 mcp->mb[0] = MBC_LIP_RESET;
1494 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001495 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001496 mcp->mb[1] = 0x00ff;
1497 mcp->mb[10] = 0;
1498 mcp->out_mb |= MBX_10;
1499 } else {
1500 mcp->mb[1] = 0xff00;
1501 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001502 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001503 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001506 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001508 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 if (rval != QLA_SUCCESS) {
1511 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001512 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 } else {
1514 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001515 ql_dbg(ql_dbg_mbx, vha, 0x105c, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 }
1517
1518 return rval;
1519}
1520
1521/*
1522 * qla2x00_send_sns
1523 * Send SNS command.
1524 *
1525 * Input:
1526 * ha = adapter block pointer.
1527 * sns = pointer for command.
1528 * cmd_size = command size.
1529 * buf_size = response/command size.
1530 * TARGET_QUEUE_LOCK must be released.
1531 * ADAPTER_STATE_LOCK must be released.
1532 *
1533 * Returns:
1534 * qla2x00 local function return status code.
1535 *
1536 * Context:
1537 * Kernel context.
1538 */
1539int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001540qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 uint16_t cmd_size, size_t buf_size)
1542{
1543 int rval;
1544 mbx_cmd_t mc;
1545 mbx_cmd_t *mcp = &mc;
1546
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001547 ql_dbg(ql_dbg_mbx, vha, 0x105d, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001549 ql_dbg(ql_dbg_mbx, vha, 0x105e,
1550 "Retry cnt=%d ratov=%d total tov=%d.\n",
1551 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
1553 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1554 mcp->mb[1] = cmd_size;
1555 mcp->mb[2] = MSW(sns_phys_address);
1556 mcp->mb[3] = LSW(sns_phys_address);
1557 mcp->mb[6] = MSW(MSD(sns_phys_address));
1558 mcp->mb[7] = LSW(MSD(sns_phys_address));
1559 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1560 mcp->in_mb = MBX_0|MBX_1;
1561 mcp->buf_size = buf_size;
1562 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001563 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1564 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 if (rval != QLA_SUCCESS) {
1567 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001568 ql_dbg(ql_dbg_mbx, vha, 0x105f,
1569 "Failed=%x mb[0]=%x mb[1]=%x.\n",
1570 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 } else {
1572 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001573 ql_dbg(ql_dbg_mbx, vha, 0x1060, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 }
1575
1576 return rval;
1577}
1578
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001579int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001580qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001581 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1582{
1583 int rval;
1584
1585 struct logio_entry_24xx *lg;
1586 dma_addr_t lg_dma;
1587 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001588 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001589 struct req_que *req;
1590 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001591
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001592 ql_dbg(ql_dbg_mbx, vha, 0x1061, "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001593
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001594 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001595 req = ha->req_q_map[0];
1596 else
1597 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001598 rsp = req->rsp;
1599
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001600 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1601 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001602 ql_log(ql_log_warn, vha, 0x1062,
1603 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001604 return QLA_MEMORY_ALLOC_FAILED;
1605 }
1606 memset(lg, 0, sizeof(struct logio_entry_24xx));
1607
1608 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1609 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001610 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001611 lg->nport_handle = cpu_to_le16(loop_id);
1612 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1613 if (opt & BIT_0)
1614 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001615 if (opt & BIT_1)
1616 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001617 lg->port_id[0] = al_pa;
1618 lg->port_id[1] = area;
1619 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001620 lg->vp_index = vha->vp_idx;
1621 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001622 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001623 ql_dbg(ql_dbg_mbx, vha, 0x1063,
1624 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001625 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001626 ql_dbg(ql_dbg_mbx, vha, 0x1064,
1627 "Failed to complete IOCB -- error status (%x).\n",
1628 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001629 rval = QLA_FUNCTION_FAILED;
1630 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1631 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1632 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1633
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001634 ql_dbg(ql_dbg_mbx, vha, 0x1065,
1635 "Failed to complete IOCB -- completion status (%x) "
1636 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
1637 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001638
1639 switch (iop[0]) {
1640 case LSC_SCODE_PORTID_USED:
1641 mb[0] = MBS_PORT_ID_USED;
1642 mb[1] = LSW(iop[1]);
1643 break;
1644 case LSC_SCODE_NPORT_USED:
1645 mb[0] = MBS_LOOP_ID_USED;
1646 break;
1647 case LSC_SCODE_NOLINK:
1648 case LSC_SCODE_NOIOCB:
1649 case LSC_SCODE_NOXCB:
1650 case LSC_SCODE_CMD_FAILED:
1651 case LSC_SCODE_NOFABRIC:
1652 case LSC_SCODE_FW_NOT_READY:
1653 case LSC_SCODE_NOT_LOGGED_IN:
1654 case LSC_SCODE_NOPCB:
1655 case LSC_SCODE_ELS_REJECT:
1656 case LSC_SCODE_CMD_PARAM_ERR:
1657 case LSC_SCODE_NONPORT:
1658 case LSC_SCODE_LOGGED_IN:
1659 case LSC_SCODE_NOFLOGI_ACC:
1660 default:
1661 mb[0] = MBS_COMMAND_ERROR;
1662 break;
1663 }
1664 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001665 ql_dbg(ql_dbg_mbx, vha, 0x1066, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001666
1667 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1668
1669 mb[0] = MBS_COMMAND_COMPLETE;
1670 mb[1] = 0;
1671 if (iop[0] & BIT_4) {
1672 if (iop[0] & BIT_8)
1673 mb[1] |= BIT_1;
1674 } else
1675 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001676
1677 /* Passback COS information. */
1678 mb[10] = 0;
1679 if (lg->io_parameter[7] || lg->io_parameter[8])
1680 mb[10] |= BIT_0; /* Class 2. */
1681 if (lg->io_parameter[9] || lg->io_parameter[10])
1682 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001683 }
1684
1685 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1686
1687 return rval;
1688}
1689
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690/*
1691 * qla2x00_login_fabric
1692 * Issue login fabric port mailbox command.
1693 *
1694 * Input:
1695 * ha = adapter block pointer.
1696 * loop_id = device loop ID.
1697 * domain = device domain.
1698 * area = device area.
1699 * al_pa = device AL_PA.
1700 * status = pointer for return status.
1701 * opt = command options.
1702 * TARGET_QUEUE_LOCK must be released.
1703 * ADAPTER_STATE_LOCK must be released.
1704 *
1705 * Returns:
1706 * qla2x00 local function return status code.
1707 *
1708 * Context:
1709 * Kernel context.
1710 */
1711int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001712qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1714{
1715 int rval;
1716 mbx_cmd_t mc;
1717 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001718 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001720 ql_dbg(ql_dbg_mbx, vha, 0x1067, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1723 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1724 if (HAS_EXTENDED_IDS(ha)) {
1725 mcp->mb[1] = loop_id;
1726 mcp->mb[10] = opt;
1727 mcp->out_mb |= MBX_10;
1728 } else {
1729 mcp->mb[1] = (loop_id << 8) | opt;
1730 }
1731 mcp->mb[2] = domain;
1732 mcp->mb[3] = area << 8 | al_pa;
1733
1734 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1735 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1736 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001737 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
1739 /* Return mailbox statuses. */
1740 if (mb != NULL) {
1741 mb[0] = mcp->mb[0];
1742 mb[1] = mcp->mb[1];
1743 mb[2] = mcp->mb[2];
1744 mb[6] = mcp->mb[6];
1745 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001746 /* COS retrieved from Get-Port-Database mailbox command. */
1747 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 }
1749
1750 if (rval != QLA_SUCCESS) {
1751 /* RLU tmp code: need to change main mailbox_command function to
1752 * return ok even when the mailbox completion value is not
1753 * SUCCESS. The caller needs to be responsible to interpret
1754 * the return values of this mailbox command if we're not
1755 * to change too much of the existing code.
1756 */
1757 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1758 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1759 mcp->mb[0] == 0x4006)
1760 rval = QLA_SUCCESS;
1761
1762 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001763 ql_dbg(ql_dbg_mbx, vha, 0x1068,
1764 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
1765 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 } else {
1767 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001768 ql_dbg(ql_dbg_mbx, vha, 0x1069, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 }
1770
1771 return rval;
1772}
1773
1774/*
1775 * qla2x00_login_local_device
1776 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001777 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 * Input:
1779 * ha = adapter block pointer.
1780 * loop_id = device loop ID.
1781 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001782 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 * Returns:
1784 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001785 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 * Context:
1787 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001788 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 */
1790int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001791qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 uint16_t *mb_ret, uint8_t opt)
1793{
1794 int rval;
1795 mbx_cmd_t mc;
1796 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001797 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001799 ql_dbg(ql_dbg_mbx, vha, 0x106a, "Entered %s.\n", __func__);
1800
Andrew Vasqueze4289242007-07-19 15:05:56 -07001801 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001802 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001803 fcport->d_id.b.domain, fcport->d_id.b.area,
1804 fcport->d_id.b.al_pa, mb_ret, opt);
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1807 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001808 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001810 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 mcp->mb[2] = opt;
1812 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1813 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1814 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1815 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001816 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817
1818 /* Return mailbox statuses. */
1819 if (mb_ret != NULL) {
1820 mb_ret[0] = mcp->mb[0];
1821 mb_ret[1] = mcp->mb[1];
1822 mb_ret[6] = mcp->mb[6];
1823 mb_ret[7] = mcp->mb[7];
1824 }
1825
1826 if (rval != QLA_SUCCESS) {
1827 /* AV tmp code: need to change main mailbox_command function to
1828 * return ok even when the mailbox completion value is not
1829 * SUCCESS. The caller needs to be responsible to interpret
1830 * the return values of this mailbox command if we're not
1831 * to change too much of the existing code.
1832 */
1833 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1834 rval = QLA_SUCCESS;
1835
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001836 ql_dbg(ql_dbg_mbx, vha, 0x106b,
1837 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
1838 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 } else {
1840 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001841 ql_dbg(ql_dbg_mbx, vha, 0x106c, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 }
1843
1844 return (rval);
1845}
1846
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001847int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001848qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001849 uint8_t area, uint8_t al_pa)
1850{
1851 int rval;
1852 struct logio_entry_24xx *lg;
1853 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001854 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001855 struct req_que *req;
1856 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001857
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001858 ql_dbg(ql_dbg_mbx, vha, 0x106d, "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001859
1860 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1861 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001862 ql_log(ql_log_warn, vha, 0x106e,
1863 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001864 return QLA_MEMORY_ALLOC_FAILED;
1865 }
1866 memset(lg, 0, sizeof(struct logio_entry_24xx));
1867
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001868 if (ql2xmaxqueues > 1)
1869 req = ha->req_q_map[0];
1870 else
1871 req = vha->req;
1872 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001873 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1874 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001875 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001876 lg->nport_handle = cpu_to_le16(loop_id);
1877 lg->control_flags =
Andrew Vasquezc8d66912011-03-30 11:46:21 -07001878 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
1879 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001880 lg->port_id[0] = al_pa;
1881 lg->port_id[1] = area;
1882 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001883 lg->vp_index = vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001884
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001885 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001886 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001887 ql_dbg(ql_dbg_mbx, vha, 0x106f,
1888 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001889 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001890 ql_dbg(ql_dbg_mbx, vha, 0x1070,
1891 "Failed to complete IOCB -- error status (%x).\n",
1892 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001893 rval = QLA_FUNCTION_FAILED;
1894 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001895 ql_dbg(ql_dbg_mbx, vha, 0x1071,
1896 "Failed to complete IOCB -- completion status (%x) "
1897 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001898 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001899 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001900 } else {
1901 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001902 ql_dbg(ql_dbg_mbx, vha, 0x1072, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001903 }
1904
1905 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1906
1907 return rval;
1908}
1909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910/*
1911 * qla2x00_fabric_logout
1912 * Issue logout fabric port mailbox command.
1913 *
1914 * Input:
1915 * ha = adapter block pointer.
1916 * loop_id = device loop ID.
1917 * TARGET_QUEUE_LOCK must be released.
1918 * ADAPTER_STATE_LOCK must be released.
1919 *
1920 * Returns:
1921 * qla2x00 local function return status code.
1922 *
1923 * Context:
1924 * Kernel context.
1925 */
1926int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001927qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001928 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929{
1930 int rval;
1931 mbx_cmd_t mc;
1932 mbx_cmd_t *mcp = &mc;
1933
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001934 ql_dbg(ql_dbg_mbx, vha, 0x1073, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
1936 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1937 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001938 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 mcp->mb[1] = loop_id;
1940 mcp->mb[10] = 0;
1941 mcp->out_mb |= MBX_10;
1942 } else {
1943 mcp->mb[1] = loop_id << 8;
1944 }
1945
1946 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001947 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001949 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
1951 if (rval != QLA_SUCCESS) {
1952 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001953 ql_dbg(ql_dbg_mbx, vha, 0x1074,
1954 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 } else {
1956 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001957 ql_dbg(ql_dbg_mbx, vha, 0x1075, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
1959
1960 return rval;
1961}
1962
1963/*
1964 * qla2x00_full_login_lip
1965 * Issue full login LIP mailbox command.
1966 *
1967 * Input:
1968 * ha = adapter block pointer.
1969 * TARGET_QUEUE_LOCK must be released.
1970 * ADAPTER_STATE_LOCK must be released.
1971 *
1972 * Returns:
1973 * qla2x00 local function return status code.
1974 *
1975 * Context:
1976 * Kernel context.
1977 */
1978int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001979qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
1981 int rval;
1982 mbx_cmd_t mc;
1983 mbx_cmd_t *mcp = &mc;
1984
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001985 ql_dbg(ql_dbg_mbx, vha, 0x1076, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986
1987 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001988 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001989 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 mcp->mb[3] = 0;
1991 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1992 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001993 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001995 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 if (rval != QLA_SUCCESS) {
1998 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001999 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 } else {
2001 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002002 ql_dbg(ql_dbg_mbx, vha, 0x1078, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 }
2004
2005 return rval;
2006}
2007
2008/*
2009 * qla2x00_get_id_list
2010 *
2011 * Input:
2012 * ha = adapter block pointer.
2013 *
2014 * Returns:
2015 * qla2x00 local function return status code.
2016 *
2017 * Context:
2018 * Kernel context.
2019 */
2020int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002021qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 uint16_t *entries)
2023{
2024 int rval;
2025 mbx_cmd_t mc;
2026 mbx_cmd_t *mcp = &mc;
2027
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002028 ql_dbg(ql_dbg_mbx, vha, 0x1079, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 if (id_list == NULL)
2031 return QLA_FUNCTION_FAILED;
2032
2033 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002034 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002035 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002036 mcp->mb[2] = MSW(id_list_dma);
2037 mcp->mb[3] = LSW(id_list_dma);
2038 mcp->mb[6] = MSW(MSD(id_list_dma));
2039 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002040 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002041 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002042 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002043 } else {
2044 mcp->mb[1] = MSW(id_list_dma);
2045 mcp->mb[2] = LSW(id_list_dma);
2046 mcp->mb[3] = MSW(MSD(id_list_dma));
2047 mcp->mb[6] = LSW(MSD(id_list_dma));
2048 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2049 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002051 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002053 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 if (rval != QLA_SUCCESS) {
2056 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002057 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 } else {
2059 *entries = mcp->mb[1];
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002060 ql_dbg(ql_dbg_mbx, vha, 0x107b, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 }
2062
2063 return rval;
2064}
2065
2066/*
2067 * qla2x00_get_resource_cnts
2068 * Get current firmware resource counts.
2069 *
2070 * Input:
2071 * ha = adapter block pointer.
2072 *
2073 * Returns:
2074 * qla2x00 local function return status code.
2075 *
2076 * Context:
2077 * Kernel context.
2078 */
2079int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002080qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002081 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002082 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083{
2084 int rval;
2085 mbx_cmd_t mc;
2086 mbx_cmd_t *mcp = &mc;
2087
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002088 ql_dbg(ql_dbg_mbx, vha, 0x107c, "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2091 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002092 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 -07002093 if (IS_QLA81XX(vha->hw))
2094 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002095 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002097 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 if (rval != QLA_SUCCESS) {
2100 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002101 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2102 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002104 ql_dbg(ql_dbg_mbx, vha, 0x107e,
2105 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2106 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2107 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2108 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
2110 if (cur_xchg_cnt)
2111 *cur_xchg_cnt = mcp->mb[3];
2112 if (orig_xchg_cnt)
2113 *orig_xchg_cnt = mcp->mb[6];
2114 if (cur_iocb_cnt)
2115 *cur_iocb_cnt = mcp->mb[7];
2116 if (orig_iocb_cnt)
2117 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002118 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002119 *max_npiv_vports = mcp->mb[11];
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002120 if (IS_QLA81XX(vha->hw) && max_fcfs)
2121 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 }
2123
2124 return (rval);
2125}
2126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127/*
2128 * qla2x00_get_fcal_position_map
2129 * Get FCAL (LILP) position map using mailbox command
2130 *
2131 * Input:
2132 * ha = adapter state pointer.
2133 * pos_map = buffer pointer (can be NULL).
2134 *
2135 * Returns:
2136 * qla2x00 local function return status code.
2137 *
2138 * Context:
2139 * Kernel context.
2140 */
2141int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002142qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143{
2144 int rval;
2145 mbx_cmd_t mc;
2146 mbx_cmd_t *mcp = &mc;
2147 char *pmap;
2148 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002149 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002151 ql_dbg(ql_dbg_mbx, vha, 0x107f, "Entered %s.\n", __func__);
2152
Andrew Vasquez4b892582008-09-11 21:22:48 -07002153 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002155 ql_log(ql_log_warn, vha, 0x1080,
2156 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 return QLA_MEMORY_ALLOC_FAILED;
2158 }
2159 memset(pmap, 0, FCAL_MAP_SIZE);
2160
2161 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2162 mcp->mb[2] = MSW(pmap_dma);
2163 mcp->mb[3] = LSW(pmap_dma);
2164 mcp->mb[6] = MSW(MSD(pmap_dma));
2165 mcp->mb[7] = LSW(MSD(pmap_dma));
2166 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2167 mcp->in_mb = MBX_1|MBX_0;
2168 mcp->buf_size = FCAL_MAP_SIZE;
2169 mcp->flags = MBX_DMA_IN;
2170 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002171 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173 if (rval == QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002174 ql_dbg(ql_dbg_mbx, vha, 0x1081,
2175 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2176 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2177 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2178 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
2180 if (pos_map)
2181 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2182 }
2183 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2184
2185 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002186 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002188 ql_dbg(ql_dbg_mbx, vha, 0x1083, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 }
2190
2191 return rval;
2192}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002193
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002194/*
2195 * qla2x00_get_link_status
2196 *
2197 * Input:
2198 * ha = adapter block pointer.
2199 * loop_id = device loop ID.
2200 * ret_buf = pointer to link status return buffer.
2201 *
2202 * Returns:
2203 * 0 = success.
2204 * BIT_0 = mem alloc error.
2205 * BIT_1 = mailbox error.
2206 */
2207int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002208qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002209 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002210{
2211 int rval;
2212 mbx_cmd_t mc;
2213 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002214 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002215 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002216
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002217 ql_dbg(ql_dbg_mbx, vha, 0x1084, "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002218
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002219 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002220 mcp->mb[2] = MSW(stats_dma);
2221 mcp->mb[3] = LSW(stats_dma);
2222 mcp->mb[6] = MSW(MSD(stats_dma));
2223 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002224 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2225 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002226 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002227 mcp->mb[1] = loop_id;
2228 mcp->mb[4] = 0;
2229 mcp->mb[10] = 0;
2230 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2231 mcp->in_mb |= MBX_1;
2232 } else if (HAS_EXTENDED_IDS(ha)) {
2233 mcp->mb[1] = loop_id;
2234 mcp->mb[10] = 0;
2235 mcp->out_mb |= MBX_10|MBX_1;
2236 } else {
2237 mcp->mb[1] = loop_id << 8;
2238 mcp->out_mb |= MBX_1;
2239 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002240 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002241 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002242 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002243
2244 if (rval == QLA_SUCCESS) {
2245 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002246 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2247 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002248 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002249 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002250 /* Copy over data -- firmware data is LE. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002251 ql_dbg(ql_dbg_mbx, vha, 0x1086, "Done %s.\n", __func__);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002252 dwords = offsetof(struct link_statistics, unused1) / 4;
2253 siter = diter = &stats->link_fail_cnt;
2254 while (dwords--)
2255 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002256 }
2257 } else {
2258 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002259 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002260 }
2261
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002262 return rval;
2263}
2264
2265int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002266qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002267 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002268{
2269 int rval;
2270 mbx_cmd_t mc;
2271 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002272 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002273
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002274 ql_dbg(ql_dbg_mbx, vha, 0x1088, "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002275
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002276 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002277 mcp->mb[2] = MSW(stats_dma);
2278 mcp->mb[3] = LSW(stats_dma);
2279 mcp->mb[6] = MSW(MSD(stats_dma));
2280 mcp->mb[7] = LSW(MSD(stats_dma));
2281 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002282 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002284 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 -07002285 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002286 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002287 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002288 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002289
2290 if (rval == QLA_SUCCESS) {
2291 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002292 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2293 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002294 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002295 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002296 ql_dbg(ql_dbg_mbx, vha, 0x108a, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002297 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002298 dwords = sizeof(struct link_statistics) / 4;
2299 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002300 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002301 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002302 }
2303 } else {
2304 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002305 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002306 }
2307
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002308 return rval;
2309}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002310
2311int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002312qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002313{
2314 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002315 unsigned long flags = 0;
2316
2317 struct abort_entry_24xx *abt;
2318 dma_addr_t abt_dma;
2319 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002320 fc_port_t *fcport = sp->fcport;
2321 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002322 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002323 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002324
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002325 ql_dbg(ql_dbg_mbx, vha, 0x108c, "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002326
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002327 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002328 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002329 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002330 break;
2331 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002332 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002333 if (handle == MAX_OUTSTANDING_COMMANDS) {
2334 /* Command not found. */
2335 return QLA_FUNCTION_FAILED;
2336 }
2337
2338 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2339 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002340 ql_log(ql_log_warn, vha, 0x108d,
2341 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002342 return QLA_MEMORY_ALLOC_FAILED;
2343 }
2344 memset(abt, 0, sizeof(struct abort_entry_24xx));
2345
2346 abt->entry_type = ABORT_IOCB_TYPE;
2347 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002348 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002349 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002350 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002351 abt->port_id[0] = fcport->d_id.b.al_pa;
2352 abt->port_id[1] = fcport->d_id.b.area;
2353 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002354 abt->vp_index = fcport->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002355
2356 abt->req_que_no = cpu_to_le16(req->id);
2357
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002358 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002359 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002360 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2361 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002362 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002363 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2364 "Failed to complete IOCB -- error status (%x).\n",
2365 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002366 rval = QLA_FUNCTION_FAILED;
2367 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002368 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2369 "Failed to complete IOCB -- completion status (%x).\n",
2370 le16_to_cpu(abt->nport_handle));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002371 rval = QLA_FUNCTION_FAILED;
2372 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002373 ql_dbg(ql_dbg_mbx, vha, 0x1091, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002374 }
2375
2376 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2377
2378 return rval;
2379}
2380
2381struct tsk_mgmt_cmd {
2382 union {
2383 struct tsk_mgmt_entry tsk;
2384 struct sts_entry_24xx sts;
2385 } p;
2386};
2387
Andrew Vasquez523ec772008-04-03 13:13:24 -07002388static int
2389__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002390 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002391{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002392 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002393 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002394 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002395 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002396 scsi_qla_host_t *vha;
2397 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002398 struct req_que *req;
2399 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002400
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002401 vha = fcport->vha;
2402 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002403 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002404
2405 ql_dbg(ql_dbg_mbx, vha, 0x1092, "Entered %s.\n", __func__);
2406
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002407 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002408 rsp = ha->rsp_q_map[tag + 1];
2409 else
2410 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002411 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002412 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002413 ql_log(ql_log_warn, vha, 0x1093,
2414 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002415 return QLA_MEMORY_ALLOC_FAILED;
2416 }
2417 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2418
2419 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2420 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002421 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002422 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002423 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002424 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002425 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2426 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2427 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002428 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002429 if (type == TCF_LUN_RESET) {
2430 int_to_scsilun(l, &tsk->p.tsk.lun);
2431 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2432 sizeof(tsk->p.tsk.lun));
2433 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002434
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002435 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002436 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002437 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002438 ql_dbg(ql_dbg_mbx, vha, 0x1094,
2439 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002440 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002441 ql_dbg(ql_dbg_mbx, vha, 0x1095,
2442 "Failed to complete IOCB -- error status (%x).\n",
2443 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002444 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002445 } else if (sts->comp_status !=
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002446 __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002447 ql_dbg(ql_dbg_mbx, vha, 0x1096,
2448 "Failed to complete IOCB -- completion status (%x).\n",
2449 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002450 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08002451 } else if (le16_to_cpu(sts->scsi_status) &
2452 SS_RESPONSE_INFO_LEN_VALID) {
2453 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002454 ql_dbg(ql_dbg_mbx, vha, 0x1097,
2455 "Ignoring inconsistent data length -- not enough "
2456 "response info (%d).\n",
2457 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08002458 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002459 ql_dbg(ql_dbg_mbx, vha, 0x1098,
2460 "Failed to complete IOCB -- response (%x).\n",
2461 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08002462 rval = QLA_FUNCTION_FAILED;
2463 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002464 }
2465
2466 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002467 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002468 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2469 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002470 ql_dbg(ql_dbg_mbx, vha, 0x1099,
2471 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002472 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002473 ql_dbg(ql_dbg_mbx, vha, 0x109a, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002474 }
2475
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002476 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002477
2478 return rval;
2479}
2480
Andrew Vasquez523ec772008-04-03 13:13:24 -07002481int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002482qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002483{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002484 struct qla_hw_data *ha = fcport->vha->hw;
2485
2486 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2487 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
2488
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002489 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002490}
2491
2492int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002493qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002494{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002495 struct qla_hw_data *ha = fcport->vha->hw;
2496
2497 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2498 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
2499
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002500 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002501}
2502
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002503int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002504qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002505{
2506 int rval;
2507 mbx_cmd_t mc;
2508 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002509 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002510
Andrew Vasquez68af0812008-05-12 22:21:13 -07002511 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002512 return QLA_FUNCTION_FAILED;
2513
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002514 ql_dbg(ql_dbg_mbx, vha, 0x109b, "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002515
2516 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2517 mcp->out_mb = MBX_0;
2518 mcp->in_mb = MBX_0;
2519 mcp->tov = 5;
2520 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002521 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002522
2523 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002524 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002525 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002526 ql_dbg(ql_dbg_mbx, vha, 0x109d, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002527 }
2528
2529 return rval;
2530}
2531
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002532/**
2533 * qla2x00_set_serdes_params() -
2534 * @ha: HA context
2535 *
2536 * Returns
2537 */
2538int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002539qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002540 uint16_t sw_em_2g, uint16_t sw_em_4g)
2541{
2542 int rval;
2543 mbx_cmd_t mc;
2544 mbx_cmd_t *mcp = &mc;
2545
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002546 ql_dbg(ql_dbg_mbx, vha, 0x109e, "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002547
2548 mcp->mb[0] = MBC_SERDES_PARAMS;
2549 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002550 mcp->mb[2] = sw_em_1g | BIT_15;
2551 mcp->mb[3] = sw_em_2g | BIT_15;
2552 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002553 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2554 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002555 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002556 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002557 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002558
2559 if (rval != QLA_SUCCESS) {
2560 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002561 ql_dbg(ql_dbg_mbx, vha, 0x109f,
2562 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002563 } else {
2564 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002565 ql_dbg(ql_dbg_mbx, vha, 0x10a0, "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002566 }
2567
2568 return rval;
2569}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002570
2571int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002572qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002573{
2574 int rval;
2575 mbx_cmd_t mc;
2576 mbx_cmd_t *mcp = &mc;
2577
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002578 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002579 return QLA_FUNCTION_FAILED;
2580
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002581 ql_dbg(ql_dbg_mbx, vha, 0x10a1, "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002582
2583 mcp->mb[0] = MBC_STOP_FIRMWARE;
2584 mcp->out_mb = MBX_0;
2585 mcp->in_mb = MBX_0;
2586 mcp->tov = 5;
2587 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002588 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002589
2590 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002591 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07002592 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2593 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002594 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002595 ql_dbg(ql_dbg_mbx, vha, 0x10a3, "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002596 }
2597
2598 return rval;
2599}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002600
2601int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002602qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002603 uint16_t buffers)
2604{
2605 int rval;
2606 mbx_cmd_t mc;
2607 mbx_cmd_t *mcp = &mc;
2608
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002609 ql_dbg(ql_dbg_mbx, vha, 0x10a4, "Entered %s.\n", __func__);
2610
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002611 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002612 return QLA_FUNCTION_FAILED;
2613
Andrew Vasquez85880802009-12-15 21:29:46 -08002614 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2615 return QLA_FUNCTION_FAILED;
2616
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002617 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002618 mcp->mb[1] = TC_EFT_ENABLE;
2619 mcp->mb[2] = LSW(eft_dma);
2620 mcp->mb[3] = MSW(eft_dma);
2621 mcp->mb[4] = LSW(MSD(eft_dma));
2622 mcp->mb[5] = MSW(MSD(eft_dma));
2623 mcp->mb[6] = buffers;
2624 mcp->mb[7] = TC_AEN_DISABLE;
2625 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 -07002626 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002627 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002628 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002629 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002630 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002631 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
2632 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2633 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002634 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002635 ql_dbg(ql_dbg_mbx, vha, 0x10a6, "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002636 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002637
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002638 return rval;
2639}
2640
2641int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002642qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002643{
2644 int rval;
2645 mbx_cmd_t mc;
2646 mbx_cmd_t *mcp = &mc;
2647
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002648 ql_dbg(ql_dbg_mbx, vha, 0x10a7, "Entered %s.\n", __func__);
2649
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002650 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002651 return QLA_FUNCTION_FAILED;
2652
Andrew Vasquez85880802009-12-15 21:29:46 -08002653 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2654 return QLA_FUNCTION_FAILED;
2655
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002656 mcp->mb[0] = MBC_TRACE_CONTROL;
2657 mcp->mb[1] = TC_EFT_DISABLE;
2658 mcp->out_mb = MBX_1|MBX_0;
2659 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002660 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002661 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002662 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002663 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002664 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
2665 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2666 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002667 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002668 ql_dbg(ql_dbg_mbx, vha, 0x10a9, "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002669 }
2670
2671 return rval;
2672}
2673
Andrew Vasquez88729e52006-06-23 16:10:50 -07002674int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002675qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002676 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2677{
2678 int rval;
2679 mbx_cmd_t mc;
2680 mbx_cmd_t *mcp = &mc;
2681
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002682 ql_dbg(ql_dbg_mbx, vha, 0x10aa, "Entered %s.\n", __func__);
2683
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002684 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002685 return QLA_FUNCTION_FAILED;
2686
Andrew Vasquez85880802009-12-15 21:29:46 -08002687 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2688 return QLA_FUNCTION_FAILED;
2689
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002690 mcp->mb[0] = MBC_TRACE_CONTROL;
2691 mcp->mb[1] = TC_FCE_ENABLE;
2692 mcp->mb[2] = LSW(fce_dma);
2693 mcp->mb[3] = MSW(fce_dma);
2694 mcp->mb[4] = LSW(MSD(fce_dma));
2695 mcp->mb[5] = MSW(MSD(fce_dma));
2696 mcp->mb[6] = buffers;
2697 mcp->mb[7] = TC_AEN_DISABLE;
2698 mcp->mb[8] = 0;
2699 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2700 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2701 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2702 MBX_1|MBX_0;
2703 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002704 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002705 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002706 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002707 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002708 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
2709 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2710 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002711 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002712 ql_dbg(ql_dbg_mbx, vha, 0x10ac, "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002713
2714 if (mb)
2715 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2716 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002717 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002718 }
2719
2720 return rval;
2721}
2722
2723int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002724qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002725{
2726 int rval;
2727 mbx_cmd_t mc;
2728 mbx_cmd_t *mcp = &mc;
2729
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002730 ql_dbg(ql_dbg_mbx, vha, 0x10ad, "Entered %s.\n", __func__);
2731
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002732 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002733 return QLA_FUNCTION_FAILED;
2734
Andrew Vasquez85880802009-12-15 21:29:46 -08002735 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2736 return QLA_FUNCTION_FAILED;
2737
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002738 mcp->mb[0] = MBC_TRACE_CONTROL;
2739 mcp->mb[1] = TC_FCE_DISABLE;
2740 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2741 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2742 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2743 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002744 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002745 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002746 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002747 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002748 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
2749 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2750 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002751 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002752 ql_dbg(ql_dbg_mbx, vha, 0x10af, "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002753
2754 if (wr)
2755 *wr = (uint64_t) mcp->mb[5] << 48 |
2756 (uint64_t) mcp->mb[4] << 32 |
2757 (uint64_t) mcp->mb[3] << 16 |
2758 (uint64_t) mcp->mb[2];
2759 if (rd)
2760 *rd = (uint64_t) mcp->mb[9] << 48 |
2761 (uint64_t) mcp->mb[8] << 32 |
2762 (uint64_t) mcp->mb[7] << 16 |
2763 (uint64_t) mcp->mb[6];
2764 }
2765
2766 return rval;
2767}
2768
2769int
Giridhar Malavali6e980162010-03-19 17:03:58 -07002770qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
2771 uint16_t *port_speed, uint16_t *mb)
2772{
2773 int rval;
2774 mbx_cmd_t mc;
2775 mbx_cmd_t *mcp = &mc;
2776
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002777 ql_dbg(ql_dbg_mbx, vha, 0x10b0, "Entered %s.\n", __func__);
2778
Giridhar Malavali6e980162010-03-19 17:03:58 -07002779 if (!IS_IIDMA_CAPABLE(vha->hw))
2780 return QLA_FUNCTION_FAILED;
2781
Giridhar Malavali6e980162010-03-19 17:03:58 -07002782 mcp->mb[0] = MBC_PORT_PARAMS;
2783 mcp->mb[1] = loop_id;
2784 mcp->mb[2] = mcp->mb[3] = 0;
2785 mcp->mb[9] = vha->vp_idx;
2786 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2787 mcp->in_mb = MBX_3|MBX_1|MBX_0;
2788 mcp->tov = MBX_TOV_SECONDS;
2789 mcp->flags = 0;
2790 rval = qla2x00_mailbox_command(vha, mcp);
2791
2792 /* Return mailbox statuses. */
2793 if (mb != NULL) {
2794 mb[0] = mcp->mb[0];
2795 mb[1] = mcp->mb[1];
2796 mb[3] = mcp->mb[3];
2797 }
2798
2799 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002800 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002801 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002802 ql_dbg(ql_dbg_mbx, vha, 0x10b2, "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07002803 if (port_speed)
2804 *port_speed = mcp->mb[3];
2805 }
2806
2807 return rval;
2808}
2809
2810int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002811qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002812 uint16_t port_speed, uint16_t *mb)
2813{
2814 int rval;
2815 mbx_cmd_t mc;
2816 mbx_cmd_t *mcp = &mc;
2817
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002818 ql_dbg(ql_dbg_mbx, vha, 0x10b3, "Entered %s.\n", __func__);
2819
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002820 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002821 return QLA_FUNCTION_FAILED;
2822
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002823 mcp->mb[0] = MBC_PORT_PARAMS;
2824 mcp->mb[1] = loop_id;
2825 mcp->mb[2] = BIT_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07002826 if (IS_QLA8XXX_TYPE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002827 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
2828 else
2829 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2830 mcp->mb[9] = vha->vp_idx;
2831 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
2832 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002833 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002834 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002835 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002836
2837 /* Return mailbox statuses. */
2838 if (mb != NULL) {
2839 mb[0] = mcp->mb[0];
2840 mb[1] = mcp->mb[1];
2841 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002842 }
2843
2844 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845 ql_dbg(ql_dbg_mbx, vha, 0x10b4, "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002846 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002847 ql_dbg(ql_dbg_mbx, vha, 0x10b5, "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002848 }
2849
2850 return rval;
2851}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002852
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002853void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002854qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002855 struct vp_rpt_id_entry_24xx *rptid_entry)
2856{
2857 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07002858 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002859 struct qla_hw_data *ha = vha->hw;
2860 scsi_qla_host_t *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07002861 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002862
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002863 ql_dbg(ql_dbg_mbx, vha, 0x10b6, "Entered %s.\n", __func__);
2864
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002865 if (rptid_entry->entry_status != 0)
2866 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002867
2868 if (rptid_entry->format == 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002869 ql_dbg(ql_dbg_mbx, vha, 0x10b7,
2870 "Format 0 : Number of VPs setup %d, number of "
2871 "VPs acquired %d.\n",
2872 MSB(le16_to_cpu(rptid_entry->vp_count)),
2873 LSB(le16_to_cpu(rptid_entry->vp_count)));
2874 ql_dbg(ql_dbg_mbx, vha, 0x10b8,
2875 "Primary port id %02x%02x%02x.\n",
2876 rptid_entry->port_id[2], rptid_entry->port_id[1],
2877 rptid_entry->port_id[0]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002878 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07002879 vp_idx = LSB(stat);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002880 ql_dbg(ql_dbg_mbx, vha, 0x10b9,
2881 "Format 1: VP[%d] enabled - status %d - with "
2882 "port id %02x%02x%02x.\n", vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002883 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002884 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07002885
2886 vp = vha;
2887 if (vp_idx == 0 && (MSB(stat) != 1))
2888 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002889
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002890 if (MSB(stat) == 1) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002891 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
2892 "Could not acquire ID for VP[%d].\n", vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002893 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07002894 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002895
Arun Easifeafb7b2010-09-03 14:57:00 -07002896 spin_lock_irqsave(&ha->vport_slock, flags);
2897 list_for_each_entry(vp, &ha->vp_list, list)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002898 if (vp_idx == vp->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002899 break;
Arun Easifeafb7b2010-09-03 14:57:00 -07002900 spin_unlock_irqrestore(&ha->vport_slock, flags);
2901
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002902 if (!vp)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002903 return;
2904
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002905 vp->d_id.b.domain = rptid_entry->port_id[2];
2906 vp->d_id.b.area = rptid_entry->port_id[1];
2907 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002908
2909 /*
2910 * Cannot configure here as we are still sitting on the
2911 * response queue. Handle it in dpc context.
2912 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002913 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002914
Andrew Vasquez531a82d2009-10-13 15:16:51 -07002915reg_needed:
2916 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
2917 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
2918 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002919 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002920 }
2921}
2922
2923/*
2924 * qla24xx_modify_vp_config
2925 * Change VP configuration for vha
2926 *
2927 * Input:
2928 * vha = adapter block pointer.
2929 *
2930 * Returns:
2931 * qla2xxx local function return status code.
2932 *
2933 * Context:
2934 * Kernel context.
2935 */
2936int
2937qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2938{
2939 int rval;
2940 struct vp_config_entry_24xx *vpmod;
2941 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002942 struct qla_hw_data *ha = vha->hw;
2943 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002944
2945 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002946
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002947 ql_dbg(ql_dbg_mbx, vha, 0x10bb, "Entered %s.\n", __func__);
2948
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002949 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002950 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002951 ql_log(ql_log_warn, vha, 0x10bc,
2952 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002953 return QLA_MEMORY_ALLOC_FAILED;
2954 }
2955
2956 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2957 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2958 vpmod->entry_count = 1;
2959 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2960 vpmod->vp_count = 1;
2961 vpmod->vp_index1 = vha->vp_idx;
2962 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2963 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2964 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2965 vpmod->entry_count = 1;
2966
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002967 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002968 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002969 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
2970 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002971 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002972 ql_dbg(ql_dbg_mbx, vha, 0x10be,
2973 "Failed to complete IOCB -- error status (%x).\n",
2974 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002975 rval = QLA_FUNCTION_FAILED;
2976 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002977 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
2978 "Failed to complete IOCB -- completion status (%x).\n",
2979 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002980 rval = QLA_FUNCTION_FAILED;
2981 } else {
2982 /* EMPTY */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002983 ql_dbg(ql_dbg_mbx, vha, 0x10c0, "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002984 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2985 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002986 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002987
2988 return rval;
2989}
2990
2991/*
2992 * qla24xx_control_vp
2993 * Enable a virtual port for given host
2994 *
2995 * Input:
2996 * ha = adapter block pointer.
2997 * vhba = virtual adapter (unused)
2998 * index = index number for enabled VP
2999 *
3000 * Returns:
3001 * qla2xxx local function return status code.
3002 *
3003 * Context:
3004 * Kernel context.
3005 */
3006int
3007qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3008{
3009 int rval;
3010 int map, pos;
3011 struct vp_ctrl_entry_24xx *vce;
3012 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003013 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003014 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003015 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003016
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003017 ql_dbg(ql_dbg_mbx, vha, 0x10c1,
3018 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003019
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003020 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003021 return QLA_PARAMETER_ERROR;
3022
3023 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3024 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003025 ql_log(ql_log_warn, vha, 0x10c2,
3026 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003027 return QLA_MEMORY_ALLOC_FAILED;
3028 }
3029 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3030
3031 vce->entry_type = VP_CTRL_IOCB_TYPE;
3032 vce->entry_count = 1;
3033 vce->command = cpu_to_le16(cmd);
3034 vce->vp_count = __constant_cpu_to_le16(1);
3035
3036 /* index map in firmware starts with 1; decrement index
3037 * this is ok as we never use index 0
3038 */
3039 map = (vp_index - 1) / 8;
3040 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003041 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003042 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003043 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003044
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003045 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003046 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003047 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3048 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003049 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003050 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3051 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003052 vce->entry_status);
3053 rval = QLA_FUNCTION_FAILED;
3054 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003055 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3056 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003057 le16_to_cpu(vce->comp_status));
3058 rval = QLA_FUNCTION_FAILED;
3059 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003060 ql_dbg(ql_dbg_mbx, vha, 0x10c6, "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003061 }
3062
3063 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3064
3065 return rval;
3066}
3067
3068/*
3069 * qla2x00_send_change_request
3070 * Receive or disable RSCN request from fabric controller
3071 *
3072 * Input:
3073 * ha = adapter block pointer
3074 * format = registration format:
3075 * 0 - Reserved
3076 * 1 - Fabric detected registration
3077 * 2 - N_port detected registration
3078 * 3 - Full registration
3079 * FF - clear registration
3080 * vp_idx = Virtual port index
3081 *
3082 * Returns:
3083 * qla2x00 local function return status code.
3084 *
3085 * Context:
3086 * Kernel Context
3087 */
3088
3089int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003090qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003091 uint16_t vp_idx)
3092{
3093 int rval;
3094 mbx_cmd_t mc;
3095 mbx_cmd_t *mcp = &mc;
3096
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003097 ql_dbg(ql_dbg_mbx, vha, 0x10c7, "Entered %s.\n", __func__);
3098
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003099 /*
3100 * This command is implicitly executed by firmware during login for the
3101 * physical hosts
3102 */
3103 if (vp_idx == 0)
3104 return QLA_FUNCTION_FAILED;
3105
3106 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3107 mcp->mb[1] = format;
3108 mcp->mb[9] = vp_idx;
3109 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3110 mcp->in_mb = MBX_0|MBX_1;
3111 mcp->tov = MBX_TOV_SECONDS;
3112 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003113 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003114
3115 if (rval == QLA_SUCCESS) {
3116 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3117 rval = BIT_1;
3118 }
3119 } else
3120 rval = BIT_1;
3121
3122 return rval;
3123}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003124
3125int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003126qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003127 uint32_t size)
3128{
3129 int rval;
3130 mbx_cmd_t mc;
3131 mbx_cmd_t *mcp = &mc;
3132
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003133 ql_dbg(ql_dbg_mbx, vha, 0x1009, "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003134
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003135 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003136 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3137 mcp->mb[8] = MSW(addr);
3138 mcp->out_mb = MBX_8|MBX_0;
3139 } else {
3140 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3141 mcp->out_mb = MBX_0;
3142 }
3143 mcp->mb[1] = LSW(addr);
3144 mcp->mb[2] = MSW(req_dma);
3145 mcp->mb[3] = LSW(req_dma);
3146 mcp->mb[6] = MSW(MSD(req_dma));
3147 mcp->mb[7] = LSW(MSD(req_dma));
3148 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003149 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003150 mcp->mb[4] = MSW(size);
3151 mcp->mb[5] = LSW(size);
3152 mcp->out_mb |= MBX_5|MBX_4;
3153 } else {
3154 mcp->mb[4] = LSW(size);
3155 mcp->out_mb |= MBX_4;
3156 }
3157
3158 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003159 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003160 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003161 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003162
3163 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003164 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3165 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003166 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003167 ql_dbg(ql_dbg_mbx, vha, 0x1007, "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003168 }
3169
3170 return rval;
3171}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003172
3173/* 84XX Support **************************************************************/
3174
3175struct cs84xx_mgmt_cmd {
3176 union {
3177 struct verify_chip_entry_84xx req;
3178 struct verify_chip_rsp_84xx rsp;
3179 } p;
3180};
3181
3182int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003183qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003184{
3185 int rval, retry;
3186 struct cs84xx_mgmt_cmd *mn;
3187 dma_addr_t mn_dma;
3188 uint16_t options;
3189 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003190 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003191
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003192 ql_dbg(ql_dbg_mbx, vha, 0x10c8, "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003193
3194 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3195 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003196 return QLA_MEMORY_ALLOC_FAILED;
3197 }
3198
3199 /* Force Update? */
3200 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3201 /* Diagnostic firmware? */
3202 /* options |= MENLO_DIAG_FW; */
3203 /* We update the firmware with only one data sequence. */
3204 options |= VCO_END_OF_DATA;
3205
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003206 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003207 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003208 memset(mn, 0, sizeof(*mn));
3209 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3210 mn->p.req.entry_count = 1;
3211 mn->p.req.options = cpu_to_le16(options);
3212
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003213 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
3214 "Dump of Verify Request.\n");
3215 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
3216 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003217
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003218 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003219 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003220 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
3221 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003222 goto verify_done;
3223 }
3224
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003225 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
3226 "Dump of Verify Response.\n");
3227 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
3228 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003229
3230 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3231 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3232 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003233 ql_dbg(ql_dbg_mbx, vha, 0x10ce,
3234 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003235
3236 if (status[0] != CS_COMPLETE) {
3237 rval = QLA_FUNCTION_FAILED;
3238 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003239 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
3240 "Firmware update failed. Retrying "
3241 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003242 options |= VCO_DONT_UPDATE_FW;
3243 options &= ~VCO_FORCE_UPDATE;
3244 retry = 1;
3245 }
3246 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003247 ql_dbg(ql_dbg_mbx, vha, 0x10d0,
3248 "Firmware updated to %x.\n",
3249 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003250
3251 /* NOTE: we only update OP firmware. */
3252 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3253 ha->cs84xx->op_fw_version =
3254 le32_to_cpu(mn->p.rsp.fw_ver);
3255 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3256 flags);
3257 }
3258 } while (retry);
3259
3260verify_done:
3261 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3262
3263 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003264 ql_dbg(ql_dbg_mbx, vha, 0x10d1, "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003265 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003266 ql_dbg(ql_dbg_mbx, vha, 0x10d2, "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003267 }
3268
3269 return rval;
3270}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003271
3272int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003273qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003274{
3275 int rval;
3276 unsigned long flags;
3277 mbx_cmd_t mc;
3278 mbx_cmd_t *mcp = &mc;
3279 struct device_reg_25xxmq __iomem *reg;
3280 struct qla_hw_data *ha = vha->hw;
3281
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003282 ql_dbg(ql_dbg_mbx, vha, 0x10d3, "Entered %s.\n", __func__);
3283
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003284 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003285 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003286 mcp->mb[2] = MSW(LSD(req->dma));
3287 mcp->mb[3] = LSW(LSD(req->dma));
3288 mcp->mb[6] = MSW(MSD(req->dma));
3289 mcp->mb[7] = LSW(MSD(req->dma));
3290 mcp->mb[5] = req->length;
3291 if (req->rsp)
3292 mcp->mb[10] = req->rsp->id;
3293 mcp->mb[12] = req->qos;
3294 mcp->mb[11] = req->vp_idx;
3295 mcp->mb[13] = req->rid;
3296
3297 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3298 QLA_QUE_PAGE * req->id);
3299
3300 mcp->mb[4] = req->id;
3301 /* que in ptr index */
3302 mcp->mb[8] = 0;
3303 /* que out ptr index */
3304 mcp->mb[9] = 0;
3305 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3306 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3307 mcp->in_mb = MBX_0;
3308 mcp->flags = MBX_DMA_OUT;
3309 mcp->tov = 60;
3310
3311 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003312 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003313 WRT_REG_DWORD(&reg->req_q_in, 0);
3314 WRT_REG_DWORD(&reg->req_q_out, 0);
3315 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003316 req->req_q_in = &reg->req_q_in;
3317 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003318 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3319
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003320 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003321 if (rval != QLA_SUCCESS) {
3322 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
3323 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3324 } else {
3325 ql_dbg(ql_dbg_mbx, vha, 0x10d5, "Done %s.\n", __func__);
3326 }
3327
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003328 return rval;
3329}
3330
3331int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003332qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003333{
3334 int rval;
3335 unsigned long flags;
3336 mbx_cmd_t mc;
3337 mbx_cmd_t *mcp = &mc;
3338 struct device_reg_25xxmq __iomem *reg;
3339 struct qla_hw_data *ha = vha->hw;
3340
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003341 ql_dbg(ql_dbg_mbx, vha, 0x10d6, "Entered %s.\n", __func__);
3342
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003343 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003344 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003345 mcp->mb[2] = MSW(LSD(rsp->dma));
3346 mcp->mb[3] = LSW(LSD(rsp->dma));
3347 mcp->mb[6] = MSW(MSD(rsp->dma));
3348 mcp->mb[7] = LSW(MSD(rsp->dma));
3349 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003350 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003351 mcp->mb[13] = rsp->rid;
3352
3353 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3354 QLA_QUE_PAGE * rsp->id);
3355
3356 mcp->mb[4] = rsp->id;
3357 /* que in ptr index */
3358 mcp->mb[8] = 0;
3359 /* que out ptr index */
3360 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003361 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003362 |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 (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003369 WRT_REG_DWORD(&reg->rsp_q_out, 0);
3370 WRT_REG_DWORD(&reg->rsp_q_in, 0);
3371 }
3372
3373 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3374
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003375 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003376 if (rval != QLA_SUCCESS) {
3377 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
3378 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3379 } else {
3380 ql_dbg(ql_dbg_mbx, vha, 0x10d8, "Done %s.\n", __func__);
3381 }
3382
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003383 return rval;
3384}
3385
Andrew Vasquez8a659572009-02-08 20:50:12 -08003386int
3387qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3388{
3389 int rval;
3390 mbx_cmd_t mc;
3391 mbx_cmd_t *mcp = &mc;
3392
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003393 ql_dbg(ql_dbg_mbx, vha, 0x10d9, "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003394
3395 mcp->mb[0] = MBC_IDC_ACK;
3396 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3397 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3398 mcp->in_mb = MBX_0;
3399 mcp->tov = MBX_TOV_SECONDS;
3400 mcp->flags = 0;
3401 rval = qla2x00_mailbox_command(vha, mcp);
3402
3403 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003404 ql_dbg(ql_dbg_mbx, vha, 0x10da,
3405 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003406 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003407 ql_dbg(ql_dbg_mbx, vha, 0x10db, "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003408 }
3409
3410 return rval;
3411}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003412
3413int
3414qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3415{
3416 int rval;
3417 mbx_cmd_t mc;
3418 mbx_cmd_t *mcp = &mc;
3419
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003420 ql_dbg(ql_dbg_mbx, vha, 0x10dc, "Entered %s.\n", __func__);
3421
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003422 if (!IS_QLA81XX(vha->hw))
3423 return QLA_FUNCTION_FAILED;
3424
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003425 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3426 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3427 mcp->out_mb = MBX_1|MBX_0;
3428 mcp->in_mb = MBX_1|MBX_0;
3429 mcp->tov = MBX_TOV_SECONDS;
3430 mcp->flags = 0;
3431 rval = qla2x00_mailbox_command(vha, mcp);
3432
3433 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003434 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
3435 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3436 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003437 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003438 ql_dbg(ql_dbg_mbx, vha, 0x10de, "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003439 *sector_size = mcp->mb[1];
3440 }
3441
3442 return rval;
3443}
3444
3445int
3446qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3447{
3448 int rval;
3449 mbx_cmd_t mc;
3450 mbx_cmd_t *mcp = &mc;
3451
3452 if (!IS_QLA81XX(vha->hw))
3453 return QLA_FUNCTION_FAILED;
3454
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003455 ql_dbg(ql_dbg_mbx, vha, 0x10df, "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003456
3457 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3458 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3459 FAC_OPT_CMD_WRITE_PROTECT;
3460 mcp->out_mb = MBX_1|MBX_0;
3461 mcp->in_mb = MBX_1|MBX_0;
3462 mcp->tov = MBX_TOV_SECONDS;
3463 mcp->flags = 0;
3464 rval = qla2x00_mailbox_command(vha, mcp);
3465
3466 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003467 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
3468 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3469 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003470 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003471 ql_dbg(ql_dbg_mbx, vha, 0x10e1, "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003472 }
3473
3474 return rval;
3475}
3476
3477int
3478qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3479{
3480 int rval;
3481 mbx_cmd_t mc;
3482 mbx_cmd_t *mcp = &mc;
3483
3484 if (!IS_QLA81XX(vha->hw))
3485 return QLA_FUNCTION_FAILED;
3486
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003487 ql_dbg(ql_dbg_mbx, vha, 0x10e2, "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003488
3489 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3490 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3491 mcp->mb[2] = LSW(start);
3492 mcp->mb[3] = MSW(start);
3493 mcp->mb[4] = LSW(finish);
3494 mcp->mb[5] = MSW(finish);
3495 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3496 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3497 mcp->tov = MBX_TOV_SECONDS;
3498 mcp->flags = 0;
3499 rval = qla2x00_mailbox_command(vha, mcp);
3500
3501 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003502 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
3503 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
3504 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003505 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003506 ql_dbg(ql_dbg_mbx, vha, 0x10e4, "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003507 }
3508
3509 return rval;
3510}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003511
3512int
3513qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3514{
3515 int rval = 0;
3516 mbx_cmd_t mc;
3517 mbx_cmd_t *mcp = &mc;
3518
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003519 ql_dbg(ql_dbg_mbx, vha, 0x10e5, "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003520
3521 mcp->mb[0] = MBC_RESTART_MPI_FW;
3522 mcp->out_mb = MBX_0;
3523 mcp->in_mb = MBX_0|MBX_1;
3524 mcp->tov = MBX_TOV_SECONDS;
3525 mcp->flags = 0;
3526 rval = qla2x00_mailbox_command(vha, mcp);
3527
3528 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003529 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
3530 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3531 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003532 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003533 ql_dbg(ql_dbg_mbx, vha, 0x10e7, "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003534 }
3535
3536 return rval;
3537}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003538
3539int
Joe Carnuccio6766df92011-05-10 11:30:15 -07003540qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
3541 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003542{
3543 int rval;
3544 mbx_cmd_t mc;
3545 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003546 struct qla_hw_data *ha = vha->hw;
3547
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003548 ql_dbg(ql_dbg_mbx, vha, 0x10e8, "Entered %s.\n", __func__);
3549
Joe Carnuccio6766df92011-05-10 11:30:15 -07003550 if (!IS_FWI2_CAPABLE(ha))
3551 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003552
Joe Carnuccio6766df92011-05-10 11:30:15 -07003553 if (len == 1)
3554 opt |= BIT_0;
3555
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003556 mcp->mb[0] = MBC_READ_SFP;
3557 mcp->mb[1] = dev;
3558 mcp->mb[2] = MSW(sfp_dma);
3559 mcp->mb[3] = LSW(sfp_dma);
3560 mcp->mb[6] = MSW(MSD(sfp_dma));
3561 mcp->mb[7] = LSW(MSD(sfp_dma));
3562 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003563 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003564 mcp->mb[10] = opt;
3565 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio1bff6cc2011-05-10 11:30:11 -07003566 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003567 mcp->tov = MBX_TOV_SECONDS;
3568 mcp->flags = 0;
3569 rval = qla2x00_mailbox_command(vha, mcp);
3570
3571 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07003572 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003573
3574 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003575 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
3576 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003577 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003578 ql_dbg(ql_dbg_mbx, vha, 0x10ea, "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003579 }
3580
3581 return rval;
3582}
3583
3584int
Joe Carnuccio6766df92011-05-10 11:30:15 -07003585qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
3586 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003587{
3588 int rval;
3589 mbx_cmd_t mc;
3590 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003591 struct qla_hw_data *ha = vha->hw;
3592
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003593 ql_dbg(ql_dbg_mbx, vha, 0x10eb, "Entered %s.\n", __func__);
3594
Joe Carnuccio6766df92011-05-10 11:30:15 -07003595 if (!IS_FWI2_CAPABLE(ha))
3596 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003597
Joe Carnuccio6766df92011-05-10 11:30:15 -07003598 if (len == 1)
3599 opt |= BIT_0;
3600
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003601 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07003602 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003603
3604 mcp->mb[0] = MBC_WRITE_SFP;
3605 mcp->mb[1] = dev;
3606 mcp->mb[2] = MSW(sfp_dma);
3607 mcp->mb[3] = LSW(sfp_dma);
3608 mcp->mb[6] = MSW(MSD(sfp_dma));
3609 mcp->mb[7] = LSW(MSD(sfp_dma));
3610 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003611 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003612 mcp->mb[10] = opt;
3613 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003614 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003615 mcp->tov = MBX_TOV_SECONDS;
3616 mcp->flags = 0;
3617 rval = qla2x00_mailbox_command(vha, mcp);
3618
3619 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003620 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
3621 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003622 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003623 ql_dbg(ql_dbg_mbx, vha, 0x10ed, "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003624 }
3625
3626 return rval;
3627}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003628
3629int
3630qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3631 uint16_t size_in_bytes, uint16_t *actual_size)
3632{
3633 int rval;
3634 mbx_cmd_t mc;
3635 mbx_cmd_t *mcp = &mc;
3636
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003637 ql_dbg(ql_dbg_mbx, vha, 0x10ee, "Entered %s.\n", __func__);
3638
Giridhar Malavalia9083012010-04-12 17:59:55 -07003639 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003640 return QLA_FUNCTION_FAILED;
3641
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003642 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3643 mcp->mb[2] = MSW(stats_dma);
3644 mcp->mb[3] = LSW(stats_dma);
3645 mcp->mb[6] = MSW(MSD(stats_dma));
3646 mcp->mb[7] = LSW(MSD(stats_dma));
3647 mcp->mb[8] = size_in_bytes >> 2;
3648 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3649 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3650 mcp->tov = MBX_TOV_SECONDS;
3651 mcp->flags = 0;
3652 rval = qla2x00_mailbox_command(vha, mcp);
3653
3654 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003655 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
3656 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
3657 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003658 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003659 ql_dbg(ql_dbg_mbx, vha, 0x10f0, "Done %s.\n", __func__);
3660
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003661
3662 *actual_size = mcp->mb[2] << 2;
3663 }
3664
3665 return rval;
3666}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003667
3668int
3669qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
3670 uint16_t size)
3671{
3672 int rval;
3673 mbx_cmd_t mc;
3674 mbx_cmd_t *mcp = &mc;
3675
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003676 ql_dbg(ql_dbg_mbx, vha, 0x10f1, "Entered %s.\n", __func__);
3677
Giridhar Malavalia9083012010-04-12 17:59:55 -07003678 if (!IS_QLA8XXX_TYPE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003679 return QLA_FUNCTION_FAILED;
3680
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003681 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
3682 mcp->mb[1] = 0;
3683 mcp->mb[2] = MSW(tlv_dma);
3684 mcp->mb[3] = LSW(tlv_dma);
3685 mcp->mb[6] = MSW(MSD(tlv_dma));
3686 mcp->mb[7] = LSW(MSD(tlv_dma));
3687 mcp->mb[8] = size;
3688 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3689 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3690 mcp->tov = MBX_TOV_SECONDS;
3691 mcp->flags = 0;
3692 rval = qla2x00_mailbox_command(vha, mcp);
3693
3694 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003695 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
3696 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
3697 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003698 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003699 ql_dbg(ql_dbg_mbx, vha, 0x10f3, "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003700 }
3701
3702 return rval;
3703}
Andrew Vasquez18e75552009-06-03 09:55:30 -07003704
3705int
3706qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
3707{
3708 int rval;
3709 mbx_cmd_t mc;
3710 mbx_cmd_t *mcp = &mc;
3711
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003712 ql_dbg(ql_dbg_mbx, vha, 0x10f4, "Entered %s.\n", __func__);
3713
Andrew Vasquez18e75552009-06-03 09:55:30 -07003714 if (!IS_FWI2_CAPABLE(vha->hw))
3715 return QLA_FUNCTION_FAILED;
3716
Andrew Vasquez18e75552009-06-03 09:55:30 -07003717 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
3718 mcp->mb[1] = LSW(risc_addr);
3719 mcp->mb[8] = MSW(risc_addr);
3720 mcp->out_mb = MBX_8|MBX_1|MBX_0;
3721 mcp->in_mb = MBX_3|MBX_2|MBX_0;
3722 mcp->tov = 30;
3723 mcp->flags = 0;
3724 rval = qla2x00_mailbox_command(vha, mcp);
3725 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003726 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
3727 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07003728 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003729 ql_dbg(ql_dbg_mbx, vha, 0x10f6, "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07003730 *data = mcp->mb[3] << 16 | mcp->mb[2];
3731 }
3732
3733 return rval;
3734}
3735
3736int
Giridhar Malavalia9083012010-04-12 17:59:55 -07003737qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
3738 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003739{
3740 int rval;
3741 mbx_cmd_t mc;
3742 mbx_cmd_t *mcp = &mc;
3743 uint32_t iter_cnt = 0x1;
3744
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003745 ql_dbg(ql_dbg_mbx, vha, 0x10f7, "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003746
3747 memset(mcp->mb, 0 , sizeof(mcp->mb));
3748 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
3749 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
3750
3751 /* transfer count */
3752 mcp->mb[10] = LSW(mreq->transfer_size);
3753 mcp->mb[11] = MSW(mreq->transfer_size);
3754
3755 /* send data address */
3756 mcp->mb[14] = LSW(mreq->send_dma);
3757 mcp->mb[15] = MSW(mreq->send_dma);
3758 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3759 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3760
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003761 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003762 mcp->mb[16] = LSW(mreq->rcv_dma);
3763 mcp->mb[17] = MSW(mreq->rcv_dma);
3764 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3765 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3766
3767 /* Iteration count */
3768 mcp->mb[18] = LSW(iter_cnt);
3769 mcp->mb[19] = MSW(iter_cnt);
3770
3771 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
3772 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 -07003773 if (IS_QLA8XXX_TYPE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003774 mcp->out_mb |= MBX_2;
3775 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
3776
3777 mcp->buf_size = mreq->transfer_size;
3778 mcp->tov = MBX_TOV_SECONDS;
3779 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3780
3781 rval = qla2x00_mailbox_command(vha, mcp);
3782
3783 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003784 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
3785 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
3786 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
3787 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003788 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003789 ql_dbg(ql_dbg_mbx, vha, 0x10f9, "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003790 }
3791
3792 /* Copy mailbox information */
3793 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003794 return rval;
3795}
3796
3797int
Giridhar Malavalia9083012010-04-12 17:59:55 -07003798qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
3799 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003800{
3801 int rval;
3802 mbx_cmd_t mc;
3803 mbx_cmd_t *mcp = &mc;
3804 struct qla_hw_data *ha = vha->hw;
3805
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003806 ql_dbg(ql_dbg_mbx, vha, 0x10fa, "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003807
3808 memset(mcp->mb, 0 , sizeof(mcp->mb));
3809 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
3810 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003811 if (IS_QLA8XXX_TYPE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003812 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003813 mcp->mb[2] = vha->fcoe_fcf_idx;
3814 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003815 mcp->mb[16] = LSW(mreq->rcv_dma);
3816 mcp->mb[17] = MSW(mreq->rcv_dma);
3817 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
3818 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
3819
3820 mcp->mb[10] = LSW(mreq->transfer_size);
3821
3822 mcp->mb[14] = LSW(mreq->send_dma);
3823 mcp->mb[15] = MSW(mreq->send_dma);
3824 mcp->mb[20] = LSW(MSD(mreq->send_dma));
3825 mcp->mb[21] = MSW(MSD(mreq->send_dma));
3826
3827 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
3828 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003829 if (IS_QLA8XXX_TYPE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003830 mcp->out_mb |= MBX_2;
3831
3832 mcp->in_mb = MBX_0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003833 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003834 mcp->in_mb |= MBX_1;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003835 if (IS_QLA8XXX_TYPE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003836 mcp->in_mb |= MBX_3;
3837
3838 mcp->tov = MBX_TOV_SECONDS;
3839 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
3840 mcp->buf_size = mreq->transfer_size;
3841
3842 rval = qla2x00_mailbox_command(vha, mcp);
3843
3844 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003845 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
3846 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3847 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003848 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003849 ql_dbg(ql_dbg_mbx, vha, 0x10fc, "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003850 }
3851
3852 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07003853 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003854 return rval;
3855}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07003856
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003857int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003858qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003859{
3860 int rval;
3861 mbx_cmd_t mc;
3862 mbx_cmd_t *mcp = &mc;
3863
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003864 ql_dbg(ql_dbg_mbx, vha, 0x10fd,
3865 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003866
3867 mcp->mb[0] = MBC_ISP84XX_RESET;
3868 mcp->mb[1] = enable_diagnostic;
3869 mcp->out_mb = MBX_1|MBX_0;
3870 mcp->in_mb = MBX_1|MBX_0;
3871 mcp->tov = MBX_TOV_SECONDS;
3872 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003873 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003874
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003875 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003876 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003877 else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003878 ql_dbg(ql_dbg_mbx, vha, 0x10ff, "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08003879
3880 return rval;
3881}
3882
3883int
Andrew Vasquez18e75552009-06-03 09:55:30 -07003884qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
3885{
3886 int rval;
3887 mbx_cmd_t mc;
3888 mbx_cmd_t *mcp = &mc;
3889
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003890 ql_dbg(ql_dbg_mbx, vha, 0x1100, "Entered %s.\n", __func__);
3891
Andrew Vasquez18e75552009-06-03 09:55:30 -07003892 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07003893 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07003894
Andrew Vasquez18e75552009-06-03 09:55:30 -07003895 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
3896 mcp->mb[1] = LSW(risc_addr);
3897 mcp->mb[2] = LSW(data);
3898 mcp->mb[3] = MSW(data);
3899 mcp->mb[8] = MSW(risc_addr);
3900 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
3901 mcp->in_mb = MBX_0;
3902 mcp->tov = 30;
3903 mcp->flags = 0;
3904 rval = qla2x00_mailbox_command(vha, mcp);
3905 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003906 ql_dbg(ql_dbg_mbx, vha, 0x1101,
3907 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07003908 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003909 ql_dbg(ql_dbg_mbx, vha, 0x1102, "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07003910 }
3911
3912 return rval;
3913}
Michael Hernandez3064ff32009-12-15 21:29:44 -08003914
3915int
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07003916qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
3917{
3918 int rval;
3919 uint32_t stat, timer;
3920 uint16_t mb0 = 0;
3921 struct qla_hw_data *ha = vha->hw;
3922 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3923
3924 rval = QLA_SUCCESS;
3925
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003926 ql_dbg(ql_dbg_mbx, vha, 0x1103, "Entered %s.\n", __func__);
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07003927
3928 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
3929
3930 /* Write the MBC data to the registers */
3931 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
3932 WRT_REG_WORD(&reg->mailbox1, mb[0]);
3933 WRT_REG_WORD(&reg->mailbox2, mb[1]);
3934 WRT_REG_WORD(&reg->mailbox3, mb[2]);
3935 WRT_REG_WORD(&reg->mailbox4, mb[3]);
3936
3937 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
3938
3939 /* Poll for MBC interrupt */
3940 for (timer = 6000000; timer; timer--) {
3941 /* Check for pending interrupts. */
3942 stat = RD_REG_DWORD(&reg->host_status);
3943 if (stat & HSRX_RISC_INT) {
3944 stat &= 0xff;
3945
3946 if (stat == 0x1 || stat == 0x2 ||
3947 stat == 0x10 || stat == 0x11) {
3948 set_bit(MBX_INTERRUPT,
3949 &ha->mbx_cmd_flags);
3950 mb0 = RD_REG_WORD(&reg->mailbox0);
3951 WRT_REG_DWORD(&reg->hccr,
3952 HCCRX_CLR_RISC_INT);
3953 RD_REG_DWORD(&reg->hccr);
3954 break;
3955 }
3956 }
3957 udelay(5);
3958 }
3959
3960 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
3961 rval = mb0 & MBS_MASK;
3962 else
3963 rval = QLA_FUNCTION_FAILED;
3964
3965 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003966 ql_dbg(ql_dbg_mbx, vha, 0x1104,
3967 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07003968 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003969 ql_dbg(ql_dbg_mbx, vha, 0x1105, "Done %s.\n", __func__);
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07003970 }
3971
3972 return rval;
3973}
3974int
Michael Hernandez3064ff32009-12-15 21:29:44 -08003975qla2x00_get_data_rate(scsi_qla_host_t *vha)
3976{
3977 int rval;
3978 mbx_cmd_t mc;
3979 mbx_cmd_t *mcp = &mc;
3980 struct qla_hw_data *ha = vha->hw;
3981
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003982 ql_dbg(ql_dbg_mbx, vha, 0x1106, "Entered %s.\n", __func__);
3983
Michael Hernandez3064ff32009-12-15 21:29:44 -08003984 if (!IS_FWI2_CAPABLE(ha))
3985 return QLA_FUNCTION_FAILED;
3986
Michael Hernandez3064ff32009-12-15 21:29:44 -08003987 mcp->mb[0] = MBC_DATA_RATE;
3988 mcp->mb[1] = 0;
3989 mcp->out_mb = MBX_1|MBX_0;
3990 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3991 mcp->tov = MBX_TOV_SECONDS;
3992 mcp->flags = 0;
3993 rval = qla2x00_mailbox_command(vha, mcp);
3994 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003995 ql_dbg(ql_dbg_mbx, vha, 0x1107,
3996 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08003997 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003998 ql_dbg(ql_dbg_mbx, vha, 0x1108, "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08003999 if (mcp->mb[1] != 0x7)
4000 ha->link_data_rate = mcp->mb[1];
4001 }
4002
4003 return rval;
4004}
Sarang Radke09ff7012010-03-19 17:03:59 -07004005
4006int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004007qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4008{
4009 int rval;
4010 mbx_cmd_t mc;
4011 mbx_cmd_t *mcp = &mc;
4012 struct qla_hw_data *ha = vha->hw;
4013
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004014 ql_dbg(ql_dbg_mbx, vha, 0x1109, "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004015
4016 if (!IS_QLA81XX(ha))
4017 return QLA_FUNCTION_FAILED;
4018 mcp->mb[0] = MBC_GET_PORT_CONFIG;
4019 mcp->out_mb = MBX_0;
4020 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4021 mcp->tov = MBX_TOV_SECONDS;
4022 mcp->flags = 0;
4023
4024 rval = qla2x00_mailbox_command(vha, mcp);
4025
4026 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004027 ql_dbg(ql_dbg_mbx, vha, 0x110a,
4028 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004029 } else {
4030 /* Copy all bits to preserve original value */
4031 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
4032
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004033 ql_dbg(ql_dbg_mbx, vha, 0x110b, "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004034 }
4035 return rval;
4036}
4037
4038int
4039qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4040{
4041 int rval;
4042 mbx_cmd_t mc;
4043 mbx_cmd_t *mcp = &mc;
4044
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004045 ql_dbg(ql_dbg_mbx, vha, 0x110c, "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004046
4047 mcp->mb[0] = MBC_SET_PORT_CONFIG;
4048 /* Copy all bits to preserve original setting */
4049 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
4050 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4051 mcp->in_mb = MBX_0;
4052 mcp->tov = MBX_TOV_SECONDS;
4053 mcp->flags = 0;
4054 rval = qla2x00_mailbox_command(vha, mcp);
4055
4056 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004057 ql_dbg(ql_dbg_mbx, vha, 0x110d,
4058 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004059 } else
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004060 ql_dbg(ql_dbg_mbx, vha, 0x110e, "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004061
4062 return rval;
4063}
4064
4065
4066int
Sarang Radke09ff7012010-03-19 17:03:59 -07004067qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
4068 uint16_t *mb)
4069{
4070 int rval;
4071 mbx_cmd_t mc;
4072 mbx_cmd_t *mcp = &mc;
4073 struct qla_hw_data *ha = vha->hw;
4074
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004075 ql_dbg(ql_dbg_mbx, vha, 0x110f, "Entered %s.\n", __func__);
4076
Sarang Radke09ff7012010-03-19 17:03:59 -07004077 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
4078 return QLA_FUNCTION_FAILED;
4079
Sarang Radke09ff7012010-03-19 17:03:59 -07004080 mcp->mb[0] = MBC_PORT_PARAMS;
4081 mcp->mb[1] = loop_id;
4082 if (ha->flags.fcp_prio_enabled)
4083 mcp->mb[2] = BIT_1;
4084 else
4085 mcp->mb[2] = BIT_2;
4086 mcp->mb[4] = priority & 0xf;
4087 mcp->mb[9] = vha->vp_idx;
4088 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4089 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4090 mcp->tov = 30;
4091 mcp->flags = 0;
4092 rval = qla2x00_mailbox_command(vha, mcp);
4093 if (mb != NULL) {
4094 mb[0] = mcp->mb[0];
4095 mb[1] = mcp->mb[1];
4096 mb[3] = mcp->mb[3];
4097 mb[4] = mcp->mb[4];
4098 }
4099
4100 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004101 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07004102 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004103 ql_dbg(ql_dbg_mbx, vha, 0x10cc, "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07004104 }
4105
4106 return rval;
4107}
Giridhar Malavalia9083012010-04-12 17:59:55 -07004108
4109int
Andrew Vasquez794a5692010-12-21 16:00:21 -08004110qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp, uint16_t *frac)
4111{
4112 int rval;
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004113 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004114 struct qla_hw_data *ha = vha->hw;
4115
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004116 ql_dbg(ql_dbg_mbx, vha, 0x10ca, "Entered %s.\n", __func__);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004117
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004118 /* Integer part */
4119 rval = qla2x00_read_sfp(vha, 0, &byte, 0x98, 0x01, 1, BIT_13|BIT_0);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004120 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004121 ql_dbg(ql_dbg_mbx, vha, 0x10c9, "Failed=%x.\n", rval);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004122 ha->flags.thermal_supported = 0;
4123 goto fail;
4124 }
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004125 *temp = byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004126
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004127 /* Fraction part */
4128 rval = qla2x00_read_sfp(vha, 0, &byte, 0x98, 0x10, 1, BIT_13|BIT_0);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004129 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004130 ql_dbg(ql_dbg_mbx, vha, 0x1019, "Failed=%x.\n", rval);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004131 ha->flags.thermal_supported = 0;
4132 goto fail;
4133 }
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004134 *frac = (byte >> 6) * 25;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004135
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004136 ql_dbg(ql_dbg_mbx, vha, 0x1018, "Done %s.\n", __func__);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004137fail:
4138 return rval;
4139}
4140
4141int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004142qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
4143{
4144 int rval;
4145 struct qla_hw_data *ha = vha->hw;
4146 mbx_cmd_t mc;
4147 mbx_cmd_t *mcp = &mc;
4148
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004149 ql_dbg(ql_dbg_mbx, vha, 0x1017, "Entered %s.\n", __func__);
4150
Giridhar Malavalia9083012010-04-12 17:59:55 -07004151 if (!IS_FWI2_CAPABLE(ha))
4152 return QLA_FUNCTION_FAILED;
4153
Giridhar Malavalia9083012010-04-12 17:59:55 -07004154 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004155 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004156 mcp->mb[1] = 1;
4157
4158 mcp->out_mb = MBX_1|MBX_0;
4159 mcp->in_mb = MBX_0;
4160 mcp->tov = 30;
4161 mcp->flags = 0;
4162
4163 rval = qla2x00_mailbox_command(vha, mcp);
4164 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004165 ql_dbg(ql_dbg_mbx, vha, 0x1016,
4166 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004167 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004168 ql_dbg(ql_dbg_mbx, vha, 0x100e, "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004169 }
4170
4171 return rval;
4172}
4173
4174int
4175qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
4176{
4177 int rval;
4178 struct qla_hw_data *ha = vha->hw;
4179 mbx_cmd_t mc;
4180 mbx_cmd_t *mcp = &mc;
4181
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004182 ql_dbg(ql_dbg_mbx, vha, 0x100d, "Entered %s.\n", __func__);
4183
Giridhar Malavalia9083012010-04-12 17:59:55 -07004184 if (!IS_QLA82XX(ha))
4185 return QLA_FUNCTION_FAILED;
4186
Giridhar Malavalia9083012010-04-12 17:59:55 -07004187 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004188 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004189 mcp->mb[1] = 0;
4190
4191 mcp->out_mb = MBX_1|MBX_0;
4192 mcp->in_mb = MBX_0;
4193 mcp->tov = 30;
4194 mcp->flags = 0;
4195
4196 rval = qla2x00_mailbox_command(vha, mcp);
4197 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004198 ql_dbg(ql_dbg_mbx, vha, 0x100c,
4199 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004200 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004201 ql_dbg(ql_dbg_mbx, vha, 0x100b, "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004202 }
4203
4204 return rval;
4205}
Giridhar Malavali08de2842011-08-16 11:31:44 -07004206
4207int
4208qla82xx_md_get_template_size(scsi_qla_host_t *vha)
4209{
4210 struct qla_hw_data *ha = vha->hw;
4211 mbx_cmd_t mc;
4212 mbx_cmd_t *mcp = &mc;
4213 int rval = QLA_FUNCTION_FAILED;
4214
4215 ql_dbg(ql_dbg_mbx, vha, 0x111f, "Entered %s.\n", __func__);
4216
4217 memset(mcp->mb, 0 , sizeof(mcp->mb));
4218 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4219 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4220 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
4221 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
4222
4223 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4224 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
4225 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4226
4227 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4228 mcp->tov = MBX_TOV_SECONDS;
4229 rval = qla2x00_mailbox_command(vha, mcp);
4230
4231 /* Always copy back return mailbox values. */
4232 if (rval != QLA_SUCCESS) {
4233 ql_dbg(ql_dbg_mbx, vha, 0x1120,
4234 "mailbox command FAILED=0x%x, subcode=%x.\n",
4235 (mcp->mb[1] << 16) | mcp->mb[0],
4236 (mcp->mb[3] << 16) | mcp->mb[2]);
4237 } else {
4238 ql_dbg(ql_dbg_mbx, vha, 0x1121, "Done %s.\n", __func__);
4239 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
4240 if (!ha->md_template_size) {
4241 ql_dbg(ql_dbg_mbx, vha, 0x1122,
4242 "Null template size obtained.\n");
4243 rval = QLA_FUNCTION_FAILED;
4244 }
4245 }
4246 return rval;
4247}
4248
4249int
4250qla82xx_md_get_template(scsi_qla_host_t *vha)
4251{
4252 struct qla_hw_data *ha = vha->hw;
4253 mbx_cmd_t mc;
4254 mbx_cmd_t *mcp = &mc;
4255 int rval = QLA_FUNCTION_FAILED;
4256
4257 ql_dbg(ql_dbg_mbx, vha, 0x1123, "Entered %s.\n", __func__);
4258
4259 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
4260 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
4261 if (!ha->md_tmplt_hdr) {
4262 ql_log(ql_log_warn, vha, 0x1124,
4263 "Unable to allocate memory for Minidump template.\n");
4264 return rval;
4265 }
4266
4267 memset(mcp->mb, 0 , sizeof(mcp->mb));
4268 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4269 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4270 mcp->mb[2] = LSW(RQST_TMPLT);
4271 mcp->mb[3] = MSW(RQST_TMPLT);
4272 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
4273 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
4274 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
4275 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
4276 mcp->mb[8] = LSW(ha->md_template_size);
4277 mcp->mb[9] = MSW(ha->md_template_size);
4278
4279 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4280 mcp->tov = MBX_TOV_SECONDS;
4281 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
4282 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4283 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4284 rval = qla2x00_mailbox_command(vha, mcp);
4285
4286 if (rval != QLA_SUCCESS) {
4287 ql_dbg(ql_dbg_mbx, vha, 0x1125,
4288 "mailbox command FAILED=0x%x, subcode=%x.\n",
4289 ((mcp->mb[1] << 16) | mcp->mb[0]),
4290 ((mcp->mb[3] << 16) | mcp->mb[2]));
4291 } else
4292 ql_dbg(ql_dbg_mbx, vha, 0x1126, "Done %s.\n", __func__);
4293 return rval;
4294}
Saurav Kashyap999916d2011-08-16 11:31:45 -07004295
4296int
4297qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
4298{
4299 int rval;
4300 struct qla_hw_data *ha = vha->hw;
4301 mbx_cmd_t mc;
4302 mbx_cmd_t *mcp = &mc;
4303
4304 if (!IS_QLA82XX(ha))
4305 return QLA_FUNCTION_FAILED;
4306
4307 ql_dbg(ql_dbg_mbx, vha, 0x1127,
4308 "Entered %s.\n", __func__);
4309
4310 memset(mcp, 0, sizeof(mbx_cmd_t));
4311 mcp->mb[0] = MBC_SET_LED_CONFIG;
4312 if (enable)
4313 mcp->mb[7] = 0xE;
4314 else
4315 mcp->mb[7] = 0xD;
4316
4317 mcp->out_mb = MBX_7|MBX_0;
4318 mcp->in_mb = MBX_0;
4319 mcp->tov = 30;
4320 mcp->flags = 0;
4321
4322 rval = qla2x00_mailbox_command(vha, mcp);
4323 if (rval != QLA_SUCCESS) {
4324 ql_dbg(ql_dbg_mbx, vha, 0x1128,
4325 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4326 } else {
4327 ql_dbg(ql_dbg_mbx, vha, 0x1129,
4328 "Done %s.\n", __func__);
4329 }
4330
4331 return rval;
4332}