blob: 3b6a41c7fecf0cf9298f9330f18346929e172ae9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Saurav Kashyap1e633952013-02-08 01:57:54 -05003 * Copyright (c) 2003-2013 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"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/*
15 * qla2x00_mailbox_command
16 * Issue mailbox command and waits for completion.
17 *
18 * Input:
19 * ha = adapter block pointer.
20 * mcp = driver internal mbx struct pointer.
21 *
22 * Output:
23 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
24 *
25 * Returns:
26 * 0 : QLA_SUCCESS = cmd performed success
27 * 1 : QLA_FUNCTION_FAILED (error encountered)
28 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
29 *
30 * Context:
31 * Kernel context.
32 */
33static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080034qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
36 int rval;
37 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070038 device_reg_t __iomem *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070039 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070040 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -070041 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 uint16_t *iptr;
43 uint16_t __iomem *optr;
44 uint32_t cnt;
45 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080047 struct qla_hw_data *ha = vha->hw;
48 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070049
Arun Easi5e19ed92012-02-09 11:15:51 -080050 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -070051
52 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -080053 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070054 "error_state is greater than pci_channel_io_frozen, "
55 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -070056 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -070057 }
Seokmann Jub9b12f72009-03-24 09:08:18 -070058
Giridhar Malavalia9083012010-04-12 17:59:55 -070059 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -080060 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070061 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -070062 return QLA_FUNCTION_TIMEOUT;
63 }
64
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070065 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080069 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070071
Andrew Vasquez85880802009-12-15 21:29:46 -080072 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -080073 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070074 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -080075 return QLA_FUNCTION_TIMEOUT;
76 }
77
Santosh Vernekar7d613ac2012-08-22 14:21:03 -040078 if (IS_QLA82XX(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -080079 /* Setting Link-Down error */
80 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -080081 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070082 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -080083 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -080084 }
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070087 * Wait for active mailbox commands to finish by waiting at most tov
88 * seconds. This is to serialize actual issuing of mailbox cmds during
89 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080091 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
92 /* Timeout occurred. Return error. */
Arun Easi5e19ed92012-02-09 11:15:51 -080093 ql_log(ql_log_warn, vha, 0x1005,
Chad Dupuisd8c0d542012-02-09 11:15:46 -080094 "Cmd access timeout, cmd=0x%x, Exiting.\n",
95 mcp->mb[0]);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080096 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
98
99 ha->flags.mbox_busy = 1;
100 /* Save mailbox command for debug */
101 ha->mcp = mcp;
102
Arun Easi5e19ed92012-02-09 11:15:51 -0800103 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700104 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 spin_lock_irqsave(&ha->hardware_lock, flags);
107
108 /* Load mailbox registers. */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700109 if (IS_QLA82XX(ha))
110 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
111 else if (IS_FWI2_CAPABLE(ha) && !IS_QLA82XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700112 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
113 else
114 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 iptr = mcp->mb;
117 command = mcp->mb[0];
118 mboxes = mcp->out_mb;
119
120 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
121 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700122 optr =
123 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (mboxes & BIT_0)
125 WRT_REG_WORD(optr, *iptr);
126
127 mboxes >>= 1;
128 optr++;
129 iptr++;
130 }
131
Arun Easi5e19ed92012-02-09 11:15:51 -0800132 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1111,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700133 "Loaded MBX registers (displayed in bytes) =.\n");
Arun Easi5e19ed92012-02-09 11:15:51 -0800134 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1112,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700135 (uint8_t *)mcp->mb, 16);
Arun Easi5e19ed92012-02-09 11:15:51 -0800136 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1113,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700137 ".\n");
Arun Easi5e19ed92012-02-09 11:15:51 -0800138 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1114,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700139 ((uint8_t *)mcp->mb + 0x10), 16);
Arun Easi5e19ed92012-02-09 11:15:51 -0800140 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1115,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700141 ".\n");
Arun Easi5e19ed92012-02-09 11:15:51 -0800142 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1116,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700143 ((uint8_t *)mcp->mb + 0x20), 8);
Arun Easi5e19ed92012-02-09 11:15:51 -0800144 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700145 "I/O Address = %p.\n", optr);
Arun Easi5e19ed92012-02-09 11:15:51 -0800146 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x100e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* Issue set host interrupt command to send cmd out. */
149 ha->flags.mbox_int = 0;
150 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
151
152 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800153 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700154 "Going to unlock irq & waiting for interrupts. "
155 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* Wait for mbx cmd completion until timeout */
158
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800159 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
161
Giridhar Malavalia9083012010-04-12 17:59:55 -0700162 if (IS_QLA82XX(ha)) {
163 if (RD_REG_DWORD(&reg->isp82.hint) &
164 HINT_MBX_INT_PENDING) {
165 spin_unlock_irqrestore(&ha->hardware_lock,
166 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800167 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800168 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700169 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700170 rval = QLA_FUNCTION_TIMEOUT;
171 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700172 }
173 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
174 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700175 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
176 else
177 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
179
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800180 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800185 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700186 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188 if (IS_QLA82XX(ha)) {
189 if (RD_REG_DWORD(&reg->isp82.hint) &
190 HINT_MBX_INT_PENDING) {
191 spin_unlock_irqrestore(&ha->hardware_lock,
192 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800193 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800194 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700195 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700196 rval = QLA_FUNCTION_TIMEOUT;
197 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700198 }
199 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
200 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700201 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
202 else
203 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
207 while (!ha->flags.mbox_int) {
208 if (time_after(jiffies, wait_time))
209 break;
210
211 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800212 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Andrew Vasquez85880802009-12-15 21:29:46 -0800214 if (!ha->flags.mbox_int &&
215 !(IS_QLA2200(ha) &&
216 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800217 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800219 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700220 "Waited %d sec.\n",
221 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 /* Check whether we timed out */
225 if (ha->flags.mbox_int) {
226 uint16_t *iptr2;
227
Arun Easi5e19ed92012-02-09 11:15:51 -0800228 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700229 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 /* Got interrupt. Clear the flag. */
232 ha->flags.mbox_int = 0;
233 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
234
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400235 if ((IS_QLA82XX(ha) && ha->flags.isp82xx_fw_hung)) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700236 ha->flags.mbox_busy = 0;
237 /* Setting Link-Down error */
238 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
239 ha->mcp = NULL;
240 rval = QLA_FUNCTION_FAILED;
Arun Easi5e19ed92012-02-09 11:15:51 -0800241 ql_log(ql_log_warn, vha, 0x1015,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700242 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700243 goto premature_exit;
244 }
245
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400246 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* Load return mailbox registers. */
250 iptr2 = mcp->mb;
251 iptr = (uint16_t *)&ha->mailbox_out[0];
252 mboxes = mcp->in_mb;
253 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
254 if (mboxes & BIT_0)
255 *iptr2 = *iptr;
256
257 mboxes >>= 1;
258 iptr2++;
259 iptr++;
260 }
261 } else {
262
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700263 uint16_t mb0;
264 uint32_t ictrl;
265
Andrew Vasqueze4289242007-07-19 15:05:56 -0700266 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700267 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
268 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
269 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700270 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700271 ictrl = RD_REG_WORD(&reg->isp.ictrl);
272 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800273 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400274 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
275 "mb[0]=0x%x\n", command, ictrl, jiffies, mb0);
Arun Easi5e19ed92012-02-09 11:15:51 -0800276 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800278 /*
279 * Attempt to capture a firmware dump for further analysis
280 * of the current firmware state
281 */
282 ha->isp_ops->fw_dump(vha, 0);
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 rval = QLA_FUNCTION_TIMEOUT;
285 }
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ha->flags.mbox_busy = 0;
288
289 /* Clean up */
290 ha->mcp = NULL;
291
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800292 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800293 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800297 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700300 if (rval == QLA_FUNCTION_TIMEOUT &&
301 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800302 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
303 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800305 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700306 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700307
308 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
309 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
310 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800311 if (IS_QLA82XX(ha)) {
312 ql_dbg(ql_dbg_mbx, vha, 0x112a,
313 "disabling pause transmit on port "
314 "0 & 1.\n");
315 qla82xx_wr_32(ha,
316 QLA82XX_CRB_NIU + 0x98,
317 CRB_NIU_XG_PAUSE_CTL_P0|
318 CRB_NIU_XG_PAUSE_CTL_P1);
319 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700320 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400321 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800322 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
323 "abort.\n", command, mcp->mb[0],
324 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700325 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
326 qla2xxx_wake_dpc(vha);
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800330 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700331 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700333 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
334 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
335 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800336 if (IS_QLA82XX(ha)) {
337 ql_dbg(ql_dbg_mbx, vha, 0x112b,
338 "disabling pause transmit on port "
339 "0 & 1.\n");
340 qla82xx_wr_32(ha,
341 QLA82XX_CRB_NIU + 0x98,
342 CRB_NIU_XG_PAUSE_CTL_P0|
343 CRB_NIU_XG_PAUSE_CTL_P1);
344 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700345 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400346 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800347 "mb[0]=0x%x. Scheduling ISP abort ",
348 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700349 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
350 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800351 /* Allow next mbx cmd to come in. */
352 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700353 if (ha->isp_ops->abort_isp(vha)) {
354 /* Failed. retry later. */
355 set_bit(ISP_ABORT_NEEDED,
356 &vha->dpc_flags);
357 }
358 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800359 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700360 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800361 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364 }
365
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700366premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800368 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Giridhar Malavalid3360962012-02-09 11:14:10 -0800370mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (rval) {
Saurav Kashyap09543c092012-08-22 14:20:59 -0400372 ql_log(ql_log_warn, base_vha, 0x1020,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800373 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
374 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700376 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return rval;
380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800383qla2x00_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 -0800384 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800387 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 mbx_cmd_t mc;
389 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
392 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andrew Vasqueze4289242007-07-19 15:05:56 -0700394 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800395 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
396 mcp->mb[8] = MSW(risc_addr);
397 mcp->out_mb = MBX_8|MBX_0;
398 } else {
399 mcp->mb[0] = MBC_LOAD_RISC_RAM;
400 mcp->out_mb = MBX_0;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 mcp->mb[1] = LSW(risc_addr);
403 mcp->mb[2] = MSW(req_dma);
404 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 mcp->mb[6] = MSW(MSD(req_dma));
406 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800407 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700408 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700409 mcp->mb[4] = MSW(risc_code_size);
410 mcp->mb[5] = LSW(risc_code_size);
411 mcp->out_mb |= MBX_5|MBX_4;
412 } else {
413 mcp->mb[4] = LSW(risc_code_size);
414 mcp->out_mb |= MBX_4;
415 }
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700418 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800420 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700423 ql_dbg(ql_dbg_mbx, vha, 0x1023,
424 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400426 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
427 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 return rval;
431}
432
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700433#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434/*
435 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700436 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 *
438 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700439 * ha = adapter block pointer.
440 * TARGET_QUEUE_LOCK must be released.
441 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700444 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 *
446 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700447 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 */
449int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800450qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800453 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 mbx_cmd_t mc;
455 mbx_cmd_t *mcp = &mc;
456
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400457 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
458 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700461 mcp->out_mb = MBX_0;
462 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700463 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700464 mcp->mb[1] = MSW(risc_addr);
465 mcp->mb[2] = LSW(risc_addr);
466 mcp->mb[3] = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800467 if (IS_QLA81XX(ha) || IS_QLA83XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700468 struct nvram_81xx *nv = ha->nvram;
469 mcp->mb[4] = (nv->enhanced_features &
470 EXTENDED_BB_CREDITS);
471 } else
472 mcp->mb[4] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700473 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700474 mcp->in_mb |= MBX_1;
475 } else {
476 mcp->mb[1] = LSW(risc_addr);
477 mcp->out_mb |= MBX_1;
478 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
479 mcp->mb[2] = 0;
480 mcp->out_mb |= MBX_2;
481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 }
483
Ravi Anandb93480e2008-04-03 13:13:25 -0700484 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800486 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700488 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700489 ql_dbg(ql_dbg_mbx, vha, 0x1026,
490 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700491 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700492 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400493 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700494 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700495 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400496 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
497 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700498 }
499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 return rval;
502}
503
504/*
505 * qla2x00_get_fw_version
506 * Get firmware version.
507 *
508 * Input:
509 * ha: adapter state pointer.
510 * major: pointer for major number.
511 * minor: pointer for minor number.
512 * subminor: pointer for subminor number.
513 *
514 * Returns:
515 * qla2x00 local function return status code.
516 *
517 * Context:
518 * Kernel context.
519 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700520int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800521qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 int rval;
524 mbx_cmd_t mc;
525 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800526 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400528 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
529 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
532 mcp->out_mb = MBX_0;
533 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800534 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700535 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400536 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800537 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700539 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800540 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700541 if (rval != QLA_SUCCESS)
542 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800545 ha->fw_major_version = mcp->mb[1];
546 ha->fw_minor_version = mcp->mb[2];
547 ha->fw_subminor_version = mcp->mb[3];
548 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800549 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800550 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800552 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
553 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw)) {
554 ha->mpi_version[0] = mcp->mb[10] & 0xff;
555 ha->mpi_version[1] = mcp->mb[11] >> 8;
556 ha->mpi_version[2] = mcp->mb[11] & 0xff;
557 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
558 ha->phy_version[0] = mcp->mb[8] & 0xff;
559 ha->phy_version[1] = mcp->mb[9] >> 8;
560 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800561 }
Saurav Kashyap81178772012-08-22 14:21:04 -0400562 if (IS_FWI2_CAPABLE(ha)) {
563 ha->fw_attributes_h = mcp->mb[15];
564 ha->fw_attributes_ext[0] = mcp->mb[16];
565 ha->fw_attributes_ext[1] = mcp->mb[17];
566 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
567 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
568 __func__, mcp->mb[15], mcp->mb[6]);
569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
570 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
571 __func__, mcp->mb[17], mcp->mb[16]);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800572 }
573
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700574failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (rval != QLA_SUCCESS) {
576 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700577 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 } else {
579 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
581 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700583 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
586/*
587 * qla2x00_get_fw_options
588 * Set firmware options.
589 *
590 * Input:
591 * ha = adapter block pointer.
592 * fwopt = pointer for firmware options.
593 *
594 * Returns:
595 * qla2x00 local function return status code.
596 *
597 * Context:
598 * Kernel context.
599 */
600int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800601qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int rval;
604 mbx_cmd_t mc;
605 mbx_cmd_t *mcp = &mc;
606
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400607 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
608 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
611 mcp->out_mb = MBX_0;
612 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700613 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800615 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 if (rval != QLA_SUCCESS) {
618 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700619 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700621 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 fwopts[1] = mcp->mb[1];
623 fwopts[2] = mcp->mb[2];
624 fwopts[3] = mcp->mb[3];
625
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400626 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
627 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
630 return rval;
631}
632
633
634/*
635 * qla2x00_set_fw_options
636 * Set firmware options.
637 *
638 * Input:
639 * ha = adapter block pointer.
640 * fwopt = pointer for firmware options.
641 *
642 * Returns:
643 * qla2x00 local function return status code.
644 *
645 * Context:
646 * Kernel context.
647 */
648int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800649qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 int rval;
652 mbx_cmd_t mc;
653 mbx_cmd_t *mcp = &mc;
654
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400655 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
656 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
659 mcp->mb[1] = fwopts[1];
660 mcp->mb[2] = fwopts[2];
661 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700662 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800664 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700665 mcp->in_mb |= MBX_1;
666 } else {
667 mcp->mb[10] = fwopts[10];
668 mcp->mb[11] = fwopts[11];
669 mcp->mb[12] = 0; /* Undocumented, but used */
670 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
671 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700672 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800674 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700676 fwopts[0] = mcp->mb[0];
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (rval != QLA_SUCCESS) {
679 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700680 ql_dbg(ql_dbg_mbx, vha, 0x1030,
681 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 } else {
683 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400684 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
685 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687
688 return rval;
689}
690
691/*
692 * qla2x00_mbx_reg_test
693 * Mailbox register wrap test.
694 *
695 * Input:
696 * ha = adapter block pointer.
697 * TARGET_QUEUE_LOCK must be released.
698 * ADAPTER_STATE_LOCK must be released.
699 *
700 * Returns:
701 * qla2x00 local function return status code.
702 *
703 * Context:
704 * Kernel context.
705 */
706int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800707qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
709 int rval;
710 mbx_cmd_t mc;
711 mbx_cmd_t *mcp = &mc;
712
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
714 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
717 mcp->mb[1] = 0xAAAA;
718 mcp->mb[2] = 0x5555;
719 mcp->mb[3] = 0xAA55;
720 mcp->mb[4] = 0x55AA;
721 mcp->mb[5] = 0xA5A5;
722 mcp->mb[6] = 0x5A5A;
723 mcp->mb[7] = 0x2525;
724 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
725 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 -0700726 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800728 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 if (rval == QLA_SUCCESS) {
731 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
732 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
733 rval = QLA_FUNCTION_FAILED;
734 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
735 mcp->mb[7] != 0x2525)
736 rval = QLA_FUNCTION_FAILED;
737 }
738
739 if (rval != QLA_SUCCESS) {
740 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700741 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 } else {
743 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400744 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
745 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747
748 return rval;
749}
750
751/*
752 * qla2x00_verify_checksum
753 * Verify firmware checksum.
754 *
755 * Input:
756 * ha = adapter block pointer.
757 * TARGET_QUEUE_LOCK must be released.
758 * ADAPTER_STATE_LOCK must be released.
759 *
760 * Returns:
761 * qla2x00 local function return status code.
762 *
763 * Context:
764 * Kernel context.
765 */
766int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800767qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 int rval;
770 mbx_cmd_t mc;
771 mbx_cmd_t *mcp = &mc;
772
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400773 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
774 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700777 mcp->out_mb = MBX_0;
778 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800779 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700780 mcp->mb[1] = MSW(risc_addr);
781 mcp->mb[2] = LSW(risc_addr);
782 mcp->out_mb |= MBX_2|MBX_1;
783 mcp->in_mb |= MBX_2|MBX_1;
784 } else {
785 mcp->mb[1] = LSW(risc_addr);
786 mcp->out_mb |= MBX_1;
787 mcp->in_mb |= MBX_1;
788 }
789
Ravi Anandb93480e2008-04-03 13:13:25 -0700790 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800792 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700795 ql_dbg(ql_dbg_mbx, vha, 0x1036,
796 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
797 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400799 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
800 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802
803 return rval;
804}
805
806/*
807 * qla2x00_issue_iocb
808 * Issue IOCB using mailbox command
809 *
810 * Input:
811 * ha = adapter state pointer.
812 * buffer = buffer pointer.
813 * phys_addr = physical address of buffer.
814 * size = size of buffer.
815 * TARGET_QUEUE_LOCK must be released.
816 * ADAPTER_STATE_LOCK must be released.
817 *
818 * Returns:
819 * qla2x00 local function return status code.
820 *
821 * Context:
822 * Kernel context.
823 */
Giridhar Malavali6e980162010-03-19 17:03:58 -0700824int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800825qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700826 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
828 int rval;
829 mbx_cmd_t mc;
830 mbx_cmd_t *mcp = &mc;
831
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400832 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
833 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
836 mcp->mb[1] = 0;
837 mcp->mb[2] = MSW(phys_addr);
838 mcp->mb[3] = LSW(phys_addr);
839 mcp->mb[6] = MSW(MSD(phys_addr));
840 mcp->mb[7] = LSW(MSD(phys_addr));
841 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
842 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700843 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800845 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 if (rval != QLA_SUCCESS) {
848 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700849 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700851 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
852
853 /* Mask reserved bits. */
854 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800855 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400856 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
857 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 }
859
860 return rval;
861}
862
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700863int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800864qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700865 size_t size)
866{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800867 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700868 MBX_TOV_SECONDS);
869}
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*
872 * qla2x00_abort_command
873 * Abort command aborts a specified IOCB.
874 *
875 * Input:
876 * ha = adapter block pointer.
877 * sp = SB structure pointer.
878 *
879 * Returns:
880 * qla2x00 local function return status code.
881 *
882 * Context:
883 * Kernel context.
884 */
885int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700886qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
888 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800890 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 mbx_cmd_t mc;
892 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700893 fc_port_t *fcport = sp->fcport;
894 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700896 struct req_que *req = vha->req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800897 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
900 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700902 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -0500903 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800904 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 break;
906 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700907 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Chad Dupuis8d93f552013-01-30 03:34:37 -0500909 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 /* command not found */
911 return QLA_FUNCTION_FAILED;
912 }
913
914 mcp->mb[0] = MBC_ABORT_COMMAND;
915 if (HAS_EXTENDED_IDS(ha))
916 mcp->mb[1] = fcport->loop_id;
917 else
918 mcp->mb[1] = fcport->loop_id << 8;
919 mcp->mb[2] = (uint16_t)handle;
920 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800921 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
923 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700924 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800926 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700929 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400931 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
932 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934
935 return rval;
936}
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700939qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700941 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 mbx_cmd_t mc;
943 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800944 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800945 struct req_que *req;
946 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Andrew Vasquez523ec772008-04-03 13:13:24 -0700948 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800949 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700950
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400951 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
952 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700953
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700954 req = vha->hw->req_q_map[0];
955 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700957 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 mcp->mb[1] = fcport->loop_id;
960 mcp->mb[10] = 0;
961 mcp->out_mb |= MBX_10;
962 } else {
963 mcp->mb[1] = fcport->loop_id << 8;
964 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800965 mcp->mb[2] = vha->hw->loop_reset_delay;
966 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700969 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800971 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400973 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
974 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700975 }
976
977 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800978 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
979 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700980 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700981 ql_dbg(ql_dbg_mbx, vha, 0x1040,
982 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400984 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
985 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986 }
987
988 return rval;
989}
990
991int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700992qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700993{
994 int rval, rval2;
995 mbx_cmd_t mc;
996 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800998 struct req_que *req;
999 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001000
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001001 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001003 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1004 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001005
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001006 req = vha->hw->req_q_map[0];
1007 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001008 mcp->mb[0] = MBC_LUN_RESET;
1009 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001010 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001011 mcp->mb[1] = fcport->loop_id;
1012 else
1013 mcp->mb[1] = fcport->loop_id << 8;
1014 mcp->mb[2] = l;
1015 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001016 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001017
1018 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001019 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001020 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001021 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001022 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001023 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001024 }
1025
1026 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001027 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1028 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001029 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001030 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1031 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001032 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001033 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1034 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036
1037 return rval;
1038}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 * qla2x00_get_adapter_id
1042 * Get adapter ID and topology.
1043 *
1044 * Input:
1045 * ha = adapter block pointer.
1046 * id = pointer for loop ID.
1047 * al_pa = pointer for AL_PA.
1048 * area = pointer for area.
1049 * domain = pointer for domain.
1050 * top = pointer for topology.
1051 * TARGET_QUEUE_LOCK must be released.
1052 * ADAPTER_STATE_LOCK must be released.
1053 *
1054 * Returns:
1055 * qla2x00 local function return status code.
1056 *
1057 * Context:
1058 * Kernel context.
1059 */
1060int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001061qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001062 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
1064 int rval;
1065 mbx_cmd_t mc;
1066 mbx_cmd_t *mcp = &mc;
1067
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001068 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1069 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001073 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001074 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001075 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001076 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -07001077 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001079 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001080 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1081 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001082 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1083 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 /* Return data. */
1086 *id = mcp->mb[1];
1087 *al_pa = LSB(mcp->mb[2]);
1088 *area = MSB(mcp->mb[2]);
1089 *domain = LSB(mcp->mb[3]);
1090 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001091 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 if (rval != QLA_SUCCESS) {
1094 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001095 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1098 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001099
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001100 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001101 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1102 vha->fcoe_fcf_idx = mcp->mb[10];
1103 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1104 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1105 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1106 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1107 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1108 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111
1112 return rval;
1113}
1114
1115/*
1116 * qla2x00_get_retry_cnt
1117 * Get current firmware login retry count and delay.
1118 *
1119 * Input:
1120 * ha = adapter block pointer.
1121 * retry_cnt = pointer to login retry count.
1122 * tov = pointer to login timeout value.
1123 *
1124 * Returns:
1125 * qla2x00 local function return status code.
1126 *
1127 * Context:
1128 * Kernel context.
1129 */
1130int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001131qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 uint16_t *r_a_tov)
1133{
1134 int rval;
1135 uint16_t ratov;
1136 mbx_cmd_t mc;
1137 mbx_cmd_t *mcp = &mc;
1138
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001139 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1140 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1143 mcp->out_mb = MBX_0;
1144 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001145 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001147 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 if (rval != QLA_SUCCESS) {
1150 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001151 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1152 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 } else {
1154 /* Convert returned data and check our values. */
1155 *r_a_tov = mcp->mb[3] / 2;
1156 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1157 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1158 /* Update to the larger values */
1159 *retry_cnt = (uint8_t)mcp->mb[1];
1160 *tov = ratov;
1161 }
1162
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001163 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001164 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166
1167 return rval;
1168}
1169
1170/*
1171 * qla2x00_init_firmware
1172 * Initialize adapter firmware.
1173 *
1174 * Input:
1175 * ha = adapter block pointer.
1176 * dptr = Initialization control block pointer.
1177 * size = size of initialization control block.
1178 * TARGET_QUEUE_LOCK must be released.
1179 * ADAPTER_STATE_LOCK must be released.
1180 *
1181 * Returns:
1182 * qla2x00 local function return status code.
1183 *
1184 * Context:
1185 * Kernel context.
1186 */
1187int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001188qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
1190 int rval;
1191 mbx_cmd_t mc;
1192 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001193 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001195 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1196 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Giridhar Malavalia9083012010-04-12 17:59:55 -07001198 if (IS_QLA82XX(ha) && ql2xdbwr)
1199 qla82xx_wr_32(ha, ha->nxdb_wr_ptr,
1200 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1201
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001202 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001203 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1204 else
1205 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1206
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001207 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 mcp->mb[2] = MSW(ha->init_cb_dma);
1209 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1211 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001212 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001213 if ((IS_QLA81XX(ha) || IS_QLA83XX(ha)) && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001214 mcp->mb[1] = BIT_0;
1215 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1216 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1217 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1218 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1219 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1220 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1221 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001222 /* 1 and 2 should normally be captured. */
1223 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1224 if (IS_QLA83XX(ha))
1225 /* mb3 is additional info about the installed SFP. */
1226 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 mcp->buf_size = size;
1228 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001229 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001230 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (rval != QLA_SUCCESS) {
1233 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001234 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001235 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1236 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 } else {
1238 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001239 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1240 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 }
1242
1243 return rval;
1244}
1245
1246/*
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001247 * qla2x00_get_node_name_list
1248 * Issue get node name list mailbox command, kmalloc()
1249 * and return the resulting list. Caller must kfree() it!
1250 *
1251 * Input:
1252 * ha = adapter state pointer.
1253 * out_data = resulting list
1254 * out_len = length of the resulting list
1255 *
1256 * Returns:
1257 * qla2x00 local function return status code.
1258 *
1259 * Context:
1260 * Kernel context.
1261 */
1262int
1263qla2x00_get_node_name_list(scsi_qla_host_t *vha, void **out_data, int *out_len)
1264{
1265 struct qla_hw_data *ha = vha->hw;
1266 struct qla_port_24xx_data *list = NULL;
1267 void *pmap;
1268 mbx_cmd_t mc;
1269 dma_addr_t pmap_dma;
1270 ulong dma_size;
1271 int rval, left;
1272
1273 left = 1;
1274 while (left > 0) {
1275 dma_size = left * sizeof(*list);
1276 pmap = dma_alloc_coherent(&ha->pdev->dev, dma_size,
1277 &pmap_dma, GFP_KERNEL);
1278 if (!pmap) {
1279 ql_log(ql_log_warn, vha, 0x113f,
1280 "%s(%ld): DMA Alloc failed of %ld\n",
1281 __func__, vha->host_no, dma_size);
1282 rval = QLA_MEMORY_ALLOC_FAILED;
1283 goto out;
1284 }
1285
1286 mc.mb[0] = MBC_PORT_NODE_NAME_LIST;
1287 mc.mb[1] = BIT_1 | BIT_3;
1288 mc.mb[2] = MSW(pmap_dma);
1289 mc.mb[3] = LSW(pmap_dma);
1290 mc.mb[6] = MSW(MSD(pmap_dma));
1291 mc.mb[7] = LSW(MSD(pmap_dma));
1292 mc.mb[8] = dma_size;
1293 mc.out_mb = MBX_0|MBX_1|MBX_2|MBX_3|MBX_6|MBX_7|MBX_8;
1294 mc.in_mb = MBX_0|MBX_1;
1295 mc.tov = 30;
1296 mc.flags = MBX_DMA_IN;
1297
1298 rval = qla2x00_mailbox_command(vha, &mc);
1299 if (rval != QLA_SUCCESS) {
1300 if ((mc.mb[0] == MBS_COMMAND_ERROR) &&
1301 (mc.mb[1] == 0xA)) {
1302 left += le16_to_cpu(mc.mb[2]) /
1303 sizeof(struct qla_port_24xx_data);
1304 goto restart;
1305 }
1306 goto out_free;
1307 }
1308
1309 left = 0;
1310
1311 list = kzalloc(dma_size, GFP_KERNEL);
1312 if (!list) {
1313 ql_log(ql_log_warn, vha, 0x1140,
1314 "%s(%ld): failed to allocate node names list "
1315 "structure.\n", __func__, vha->host_no);
1316 rval = QLA_MEMORY_ALLOC_FAILED;
1317 goto out_free;
1318 }
1319
1320 memcpy(list, pmap, dma_size);
1321restart:
1322 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1323 }
1324
1325 *out_data = list;
1326 *out_len = dma_size;
1327
1328out:
1329 return rval;
1330
1331out_free:
1332 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1333 return rval;
1334}
1335
1336/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 * qla2x00_get_port_database
1338 * Issue normal/enhanced get port database mailbox command
1339 * and copy device name as necessary.
1340 *
1341 * Input:
1342 * ha = adapter state pointer.
1343 * dev = structure pointer.
1344 * opt = enhanced cmd option byte.
1345 *
1346 * Returns:
1347 * qla2x00 local function return status code.
1348 *
1349 * Context:
1350 * Kernel context.
1351 */
1352int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001353qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
1355 int rval;
1356 mbx_cmd_t mc;
1357 mbx_cmd_t *mcp = &mc;
1358 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001359 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001361 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001363 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1364 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001366 pd24 = NULL;
1367 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001369 ql_log(ql_log_warn, vha, 0x1050,
1370 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 return QLA_MEMORY_ALLOC_FAILED;
1372 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001373 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001375 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001376 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 mcp->mb[2] = MSW(pd_dma);
1379 mcp->mb[3] = LSW(pd_dma);
1380 mcp->mb[6] = MSW(MSD(pd_dma));
1381 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001382 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001383 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001385 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001386 mcp->mb[1] = fcport->loop_id;
1387 mcp->mb[10] = opt;
1388 mcp->out_mb |= MBX_10|MBX_1;
1389 mcp->in_mb |= MBX_1;
1390 } else if (HAS_EXTENDED_IDS(ha)) {
1391 mcp->mb[1] = fcport->loop_id;
1392 mcp->mb[10] = opt;
1393 mcp->out_mb |= MBX_10|MBX_1;
1394 } else {
1395 mcp->mb[1] = fcport->loop_id << 8 | opt;
1396 mcp->out_mb |= MBX_1;
1397 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001398 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1399 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 mcp->flags = MBX_DMA_IN;
1401 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001402 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 if (rval != QLA_SUCCESS)
1404 goto gpd_error_out;
1405
Andrew Vasqueze4289242007-07-19 15:05:56 -07001406 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001407 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001408 pd24 = (struct port_database_24xx *) pd;
1409
1410 /* Check for logged in state. */
1411 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1412 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001413 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1414 "Unable to verify login-state (%x/%x) for "
1415 "loop_id %x.\n", pd24->current_login_state,
1416 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001417 rval = QLA_FUNCTION_FAILED;
1418 goto gpd_error_out;
1419 }
1420
Arun Easi0eba25d2012-02-09 11:15:58 -08001421 if (fcport->loop_id == FC_NO_LOOP_ID ||
1422 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1423 memcmp(fcport->port_name, pd24->port_name, 8))) {
1424 /* We lost the device mid way. */
1425 rval = QLA_NOT_LOGGED_IN;
1426 goto gpd_error_out;
1427 }
1428
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001429 /* Names are little-endian. */
1430 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1431 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1432
1433 /* Get port_id of device. */
1434 fcport->d_id.b.domain = pd24->port_id[0];
1435 fcport->d_id.b.area = pd24->port_id[1];
1436 fcport->d_id.b.al_pa = pd24->port_id[2];
1437 fcport->d_id.b.rsvd_1 = 0;
1438
1439 /* If not target must be initiator or unknown type. */
1440 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1441 fcport->port_type = FCT_INITIATOR;
1442 else
1443 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001444
1445 /* Passback COS information. */
1446 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1447 FC_COS_CLASS2 : FC_COS_CLASS3;
1448
1449 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1450 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001451 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001452 uint64_t zero = 0;
1453
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001454 /* Check for logged in state. */
1455 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1456 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1458 "Unable to verify login-state (%x/%x) - "
1459 "portid=%02x%02x%02x.\n", pd->master_state,
1460 pd->slave_state, fcport->d_id.b.domain,
1461 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001462 rval = QLA_FUNCTION_FAILED;
1463 goto gpd_error_out;
1464 }
1465
Arun Easi0eba25d2012-02-09 11:15:58 -08001466 if (fcport->loop_id == FC_NO_LOOP_ID ||
1467 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1468 memcmp(fcport->port_name, pd->port_name, 8))) {
1469 /* We lost the device mid way. */
1470 rval = QLA_NOT_LOGGED_IN;
1471 goto gpd_error_out;
1472 }
1473
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001474 /* Names are little-endian. */
1475 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1476 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1477
1478 /* Get port_id of device. */
1479 fcport->d_id.b.domain = pd->port_id[0];
1480 fcport->d_id.b.area = pd->port_id[3];
1481 fcport->d_id.b.al_pa = pd->port_id[2];
1482 fcport->d_id.b.rsvd_1 = 0;
1483
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001484 /* If not target must be initiator or unknown type. */
1485 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1486 fcport->port_type = FCT_INITIATOR;
1487 else
1488 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001489
1490 /* Passback COS information. */
1491 fcport->supported_classes = (pd->options & BIT_4) ?
1492 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 }
1494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495gpd_error_out:
1496 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1497
1498 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001499 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1500 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1501 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1504 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
1506
1507 return rval;
1508}
1509
1510/*
1511 * qla2x00_get_firmware_state
1512 * Get adapter firmware state.
1513 *
1514 * Input:
1515 * ha = adapter block pointer.
1516 * dptr = pointer for firmware state.
1517 * TARGET_QUEUE_LOCK must be released.
1518 * ADAPTER_STATE_LOCK must be released.
1519 *
1520 * Returns:
1521 * qla2x00 local function return status code.
1522 *
1523 * Context:
1524 * Kernel context.
1525 */
1526int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001527qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
1529 int rval;
1530 mbx_cmd_t mc;
1531 mbx_cmd_t *mcp = &mc;
1532
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1534 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1537 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001538 if (IS_FWI2_CAPABLE(vha->hw))
1539 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1540 else
1541 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001542 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001544 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001546 /* Return firmware states. */
1547 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001548 if (IS_FWI2_CAPABLE(vha->hw)) {
1549 states[1] = mcp->mb[2];
1550 states[2] = mcp->mb[3];
1551 states[3] = mcp->mb[4];
1552 states[4] = mcp->mb[5];
1553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 if (rval != QLA_SUCCESS) {
1556 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 } else {
1559 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1561 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 }
1563
1564 return rval;
1565}
1566
1567/*
1568 * qla2x00_get_port_name
1569 * Issue get port name mailbox command.
1570 * Returned name is in big endian format.
1571 *
1572 * Input:
1573 * ha = adapter block pointer.
1574 * loop_id = loop ID of device.
1575 * name = pointer for name.
1576 * TARGET_QUEUE_LOCK must be released.
1577 * ADAPTER_STATE_LOCK must be released.
1578 *
1579 * Returns:
1580 * qla2x00 local function return status code.
1581 *
1582 * Context:
1583 * Kernel context.
1584 */
1585int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001586qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 uint8_t opt)
1588{
1589 int rval;
1590 mbx_cmd_t mc;
1591 mbx_cmd_t *mcp = &mc;
1592
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001593 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1594 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001597 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001598 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001599 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 mcp->mb[1] = loop_id;
1601 mcp->mb[10] = opt;
1602 mcp->out_mb |= MBX_10;
1603 } else {
1604 mcp->mb[1] = loop_id << 8 | opt;
1605 }
1606
1607 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001608 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001610 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 if (rval != QLA_SUCCESS) {
1613 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001614 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 } else {
1616 if (name != NULL) {
1617 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001618 name[0] = MSB(mcp->mb[2]);
1619 name[1] = LSB(mcp->mb[2]);
1620 name[2] = MSB(mcp->mb[3]);
1621 name[3] = LSB(mcp->mb[3]);
1622 name[4] = MSB(mcp->mb[6]);
1623 name[5] = LSB(mcp->mb[6]);
1624 name[6] = MSB(mcp->mb[7]);
1625 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 }
1627
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001628 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1629 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
1631
1632 return rval;
1633}
1634
1635/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001636 * qla24xx_link_initialization
1637 * Issue link initialization mailbox command.
1638 *
1639 * Input:
1640 * ha = adapter block pointer.
1641 * TARGET_QUEUE_LOCK must be released.
1642 * ADAPTER_STATE_LOCK must be released.
1643 *
1644 * Returns:
1645 * qla2x00 local function return status code.
1646 *
1647 * Context:
1648 * Kernel context.
1649 */
1650int
1651qla24xx_link_initialize(scsi_qla_host_t *vha)
1652{
1653 int rval;
1654 mbx_cmd_t mc;
1655 mbx_cmd_t *mcp = &mc;
1656
1657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
1658 "Entered %s.\n", __func__);
1659
1660 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
1661 return QLA_FUNCTION_FAILED;
1662
1663 mcp->mb[0] = MBC_LINK_INITIALIZATION;
1664 mcp->mb[1] = BIT_6|BIT_4;
1665 mcp->mb[2] = 0;
1666 mcp->mb[3] = 0;
1667 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1668 mcp->in_mb = MBX_0;
1669 mcp->tov = MBX_TOV_SECONDS;
1670 mcp->flags = 0;
1671 rval = qla2x00_mailbox_command(vha, mcp);
1672
1673 if (rval != QLA_SUCCESS) {
1674 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
1675 } else {
1676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
1677 "Done %s.\n", __func__);
1678 }
1679
1680 return rval;
1681}
1682
1683/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 * qla2x00_lip_reset
1685 * Issue LIP reset mailbox command.
1686 *
1687 * Input:
1688 * ha = adapter block pointer.
1689 * TARGET_QUEUE_LOCK must be released.
1690 * ADAPTER_STATE_LOCK must be released.
1691 *
1692 * Returns:
1693 * qla2x00 local function return status code.
1694 *
1695 * Context:
1696 * Kernel context.
1697 */
1698int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001699qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
1701 int rval;
1702 mbx_cmd_t mc;
1703 mbx_cmd_t *mcp = &mc;
1704
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001705 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
1706 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001708 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001709 /* Logout across all FCFs. */
1710 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1711 mcp->mb[1] = BIT_1;
1712 mcp->mb[2] = 0;
1713 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1714 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001715 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001716 mcp->mb[1] = BIT_6;
1717 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001718 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001719 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001721 mcp->mb[0] = MBC_LIP_RESET;
1722 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001723 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001724 mcp->mb[1] = 0x00ff;
1725 mcp->mb[10] = 0;
1726 mcp->out_mb |= MBX_10;
1727 } else {
1728 mcp->mb[1] = 0xff00;
1729 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001730 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001731 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001734 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001736 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 if (rval != QLA_SUCCESS) {
1739 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001740 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 } else {
1742 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001743 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
1744 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
1746
1747 return rval;
1748}
1749
1750/*
1751 * qla2x00_send_sns
1752 * Send SNS command.
1753 *
1754 * Input:
1755 * ha = adapter block pointer.
1756 * sns = pointer for command.
1757 * cmd_size = command size.
1758 * buf_size = response/command size.
1759 * TARGET_QUEUE_LOCK must be released.
1760 * ADAPTER_STATE_LOCK must be released.
1761 *
1762 * Returns:
1763 * qla2x00 local function return status code.
1764 *
1765 * Context:
1766 * Kernel context.
1767 */
1768int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001769qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 uint16_t cmd_size, size_t buf_size)
1771{
1772 int rval;
1773 mbx_cmd_t mc;
1774 mbx_cmd_t *mcp = &mc;
1775
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
1777 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001780 "Retry cnt=%d ratov=%d total tov=%d.\n",
1781 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1784 mcp->mb[1] = cmd_size;
1785 mcp->mb[2] = MSW(sns_phys_address);
1786 mcp->mb[3] = LSW(sns_phys_address);
1787 mcp->mb[6] = MSW(MSD(sns_phys_address));
1788 mcp->mb[7] = LSW(MSD(sns_phys_address));
1789 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1790 mcp->in_mb = MBX_0|MBX_1;
1791 mcp->buf_size = buf_size;
1792 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001793 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1794 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 if (rval != QLA_SUCCESS) {
1797 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001798 ql_dbg(ql_dbg_mbx, vha, 0x105f,
1799 "Failed=%x mb[0]=%x mb[1]=%x.\n",
1800 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 } else {
1802 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001803 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
1804 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 }
1806
1807 return rval;
1808}
1809
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001810int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001811qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001812 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1813{
1814 int rval;
1815
1816 struct logio_entry_24xx *lg;
1817 dma_addr_t lg_dma;
1818 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001819 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001820 struct req_que *req;
1821 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001822
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001823 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
1824 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001825
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001826 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001827 req = ha->req_q_map[0];
1828 else
1829 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001830 rsp = req->rsp;
1831
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001832 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1833 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001834 ql_log(ql_log_warn, vha, 0x1062,
1835 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001836 return QLA_MEMORY_ALLOC_FAILED;
1837 }
1838 memset(lg, 0, sizeof(struct logio_entry_24xx));
1839
1840 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1841 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001842 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001843 lg->nport_handle = cpu_to_le16(loop_id);
1844 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1845 if (opt & BIT_0)
1846 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001847 if (opt & BIT_1)
1848 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001849 lg->port_id[0] = al_pa;
1850 lg->port_id[1] = area;
1851 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001852 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08001853 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
1854 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001855 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001856 ql_dbg(ql_dbg_mbx, vha, 0x1063,
1857 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001858 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001859 ql_dbg(ql_dbg_mbx, vha, 0x1064,
1860 "Failed to complete IOCB -- error status (%x).\n",
1861 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001862 rval = QLA_FUNCTION_FAILED;
1863 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1864 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1865 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1866
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001867 ql_dbg(ql_dbg_mbx, vha, 0x1065,
1868 "Failed to complete IOCB -- completion status (%x) "
1869 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
1870 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001871
1872 switch (iop[0]) {
1873 case LSC_SCODE_PORTID_USED:
1874 mb[0] = MBS_PORT_ID_USED;
1875 mb[1] = LSW(iop[1]);
1876 break;
1877 case LSC_SCODE_NPORT_USED:
1878 mb[0] = MBS_LOOP_ID_USED;
1879 break;
1880 case LSC_SCODE_NOLINK:
1881 case LSC_SCODE_NOIOCB:
1882 case LSC_SCODE_NOXCB:
1883 case LSC_SCODE_CMD_FAILED:
1884 case LSC_SCODE_NOFABRIC:
1885 case LSC_SCODE_FW_NOT_READY:
1886 case LSC_SCODE_NOT_LOGGED_IN:
1887 case LSC_SCODE_NOPCB:
1888 case LSC_SCODE_ELS_REJECT:
1889 case LSC_SCODE_CMD_PARAM_ERR:
1890 case LSC_SCODE_NONPORT:
1891 case LSC_SCODE_LOGGED_IN:
1892 case LSC_SCODE_NOFLOGI_ACC:
1893 default:
1894 mb[0] = MBS_COMMAND_ERROR;
1895 break;
1896 }
1897 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001898 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
1899 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001900
1901 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1902
1903 mb[0] = MBS_COMMAND_COMPLETE;
1904 mb[1] = 0;
1905 if (iop[0] & BIT_4) {
1906 if (iop[0] & BIT_8)
1907 mb[1] |= BIT_1;
1908 } else
1909 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001910
1911 /* Passback COS information. */
1912 mb[10] = 0;
1913 if (lg->io_parameter[7] || lg->io_parameter[8])
1914 mb[10] |= BIT_0; /* Class 2. */
1915 if (lg->io_parameter[9] || lg->io_parameter[10])
1916 mb[10] |= BIT_1; /* Class 3. */
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001917 if (lg->io_parameter[0] & __constant_cpu_to_le32(BIT_7))
1918 mb[10] |= BIT_7; /* Confirmed Completion
1919 * Allowed
1920 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001921 }
1922
1923 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1924
1925 return rval;
1926}
1927
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928/*
1929 * qla2x00_login_fabric
1930 * Issue login fabric port mailbox command.
1931 *
1932 * Input:
1933 * ha = adapter block pointer.
1934 * loop_id = device loop ID.
1935 * domain = device domain.
1936 * area = device area.
1937 * al_pa = device AL_PA.
1938 * status = pointer for return status.
1939 * opt = command options.
1940 * TARGET_QUEUE_LOCK must be released.
1941 * ADAPTER_STATE_LOCK must be released.
1942 *
1943 * Returns:
1944 * qla2x00 local function return status code.
1945 *
1946 * Context:
1947 * Kernel context.
1948 */
1949int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001950qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1952{
1953 int rval;
1954 mbx_cmd_t mc;
1955 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001956 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001958 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
1959 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1962 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1963 if (HAS_EXTENDED_IDS(ha)) {
1964 mcp->mb[1] = loop_id;
1965 mcp->mb[10] = opt;
1966 mcp->out_mb |= MBX_10;
1967 } else {
1968 mcp->mb[1] = (loop_id << 8) | opt;
1969 }
1970 mcp->mb[2] = domain;
1971 mcp->mb[3] = area << 8 | al_pa;
1972
1973 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1974 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1975 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001976 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
1978 /* Return mailbox statuses. */
1979 if (mb != NULL) {
1980 mb[0] = mcp->mb[0];
1981 mb[1] = mcp->mb[1];
1982 mb[2] = mcp->mb[2];
1983 mb[6] = mcp->mb[6];
1984 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001985 /* COS retrieved from Get-Port-Database mailbox command. */
1986 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 }
1988
1989 if (rval != QLA_SUCCESS) {
1990 /* RLU tmp code: need to change main mailbox_command function to
1991 * return ok even when the mailbox completion value is not
1992 * SUCCESS. The caller needs to be responsible to interpret
1993 * the return values of this mailbox command if we're not
1994 * to change too much of the existing code.
1995 */
1996 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1997 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1998 mcp->mb[0] == 0x4006)
1999 rval = QLA_SUCCESS;
2000
2001 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002002 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2003 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2004 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 } else {
2006 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2008 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010
2011 return rval;
2012}
2013
2014/*
2015 * qla2x00_login_local_device
2016 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002017 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 * Input:
2019 * ha = adapter block pointer.
2020 * loop_id = device loop ID.
2021 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002022 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 * Returns:
2024 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002025 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 * Context:
2027 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002028 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 */
2030int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002031qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 uint16_t *mb_ret, uint8_t opt)
2033{
2034 int rval;
2035 mbx_cmd_t mc;
2036 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002037 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002039 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2040 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002041
Andrew Vasqueze4289242007-07-19 15:05:56 -07002042 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002043 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002044 fcport->d_id.b.domain, fcport->d_id.b.area,
2045 fcport->d_id.b.al_pa, mb_ret, opt);
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2048 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002049 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002051 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 mcp->mb[2] = opt;
2053 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2054 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2055 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2056 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002057 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
2059 /* Return mailbox statuses. */
2060 if (mb_ret != NULL) {
2061 mb_ret[0] = mcp->mb[0];
2062 mb_ret[1] = mcp->mb[1];
2063 mb_ret[6] = mcp->mb[6];
2064 mb_ret[7] = mcp->mb[7];
2065 }
2066
2067 if (rval != QLA_SUCCESS) {
2068 /* AV tmp code: need to change main mailbox_command function to
2069 * return ok even when the mailbox completion value is not
2070 * SUCCESS. The caller needs to be responsible to interpret
2071 * the return values of this mailbox command if we're not
2072 * to change too much of the existing code.
2073 */
2074 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2075 rval = QLA_SUCCESS;
2076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002077 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2078 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2079 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 } else {
2081 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2083 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 }
2085
2086 return (rval);
2087}
2088
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002089int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002090qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002091 uint8_t area, uint8_t al_pa)
2092{
2093 int rval;
2094 struct logio_entry_24xx *lg;
2095 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002096 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002097 struct req_que *req;
2098 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002099
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002100 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2101 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002102
2103 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2104 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002105 ql_log(ql_log_warn, vha, 0x106e,
2106 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002107 return QLA_MEMORY_ALLOC_FAILED;
2108 }
2109 memset(lg, 0, sizeof(struct logio_entry_24xx));
2110
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002111 if (ql2xmaxqueues > 1)
2112 req = ha->req_q_map[0];
2113 else
2114 req = vha->req;
2115 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002116 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2117 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002118 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002119 lg->nport_handle = cpu_to_le16(loop_id);
2120 lg->control_flags =
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002121 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
2122 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002123 lg->port_id[0] = al_pa;
2124 lg->port_id[1] = area;
2125 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002126 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002127 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2128 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002129 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002130 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2131 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002132 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002133 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2134 "Failed to complete IOCB -- error status (%x).\n",
2135 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002136 rval = QLA_FUNCTION_FAILED;
2137 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002138 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2139 "Failed to complete IOCB -- completion status (%x) "
2140 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002141 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002142 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002143 } else {
2144 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002145 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2146 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002147 }
2148
2149 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2150
2151 return rval;
2152}
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154/*
2155 * qla2x00_fabric_logout
2156 * Issue logout fabric port mailbox command.
2157 *
2158 * Input:
2159 * ha = adapter block pointer.
2160 * loop_id = device loop ID.
2161 * TARGET_QUEUE_LOCK must be released.
2162 * ADAPTER_STATE_LOCK must be released.
2163 *
2164 * Returns:
2165 * qla2x00 local function return status code.
2166 *
2167 * Context:
2168 * Kernel context.
2169 */
2170int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002171qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002172 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
2174 int rval;
2175 mbx_cmd_t mc;
2176 mbx_cmd_t *mcp = &mc;
2177
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002178 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2179 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
2181 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2182 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002183 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 mcp->mb[1] = loop_id;
2185 mcp->mb[10] = 0;
2186 mcp->out_mb |= MBX_10;
2187 } else {
2188 mcp->mb[1] = loop_id << 8;
2189 }
2190
2191 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002192 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002194 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 if (rval != QLA_SUCCESS) {
2197 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002198 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2199 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 } else {
2201 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002202 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2203 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 }
2205
2206 return rval;
2207}
2208
2209/*
2210 * qla2x00_full_login_lip
2211 * Issue full login LIP mailbox command.
2212 *
2213 * Input:
2214 * ha = adapter block pointer.
2215 * TARGET_QUEUE_LOCK must be released.
2216 * ADAPTER_STATE_LOCK must be released.
2217 *
2218 * Returns:
2219 * qla2x00 local function return status code.
2220 *
2221 * Context:
2222 * Kernel context.
2223 */
2224int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002225qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
2227 int rval;
2228 mbx_cmd_t mc;
2229 mbx_cmd_t *mcp = &mc;
2230
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002231 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2232 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002235 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002236 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 mcp->mb[3] = 0;
2238 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2239 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002240 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002242 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244 if (rval != QLA_SUCCESS) {
2245 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002246 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 } else {
2248 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2250 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 }
2252
2253 return rval;
2254}
2255
2256/*
2257 * qla2x00_get_id_list
2258 *
2259 * Input:
2260 * ha = adapter block pointer.
2261 *
2262 * Returns:
2263 * qla2x00 local function return status code.
2264 *
2265 * Context:
2266 * Kernel context.
2267 */
2268int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002269qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 uint16_t *entries)
2271{
2272 int rval;
2273 mbx_cmd_t mc;
2274 mbx_cmd_t *mcp = &mc;
2275
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002276 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2277 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
2279 if (id_list == NULL)
2280 return QLA_FUNCTION_FAILED;
2281
2282 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002284 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002285 mcp->mb[2] = MSW(id_list_dma);
2286 mcp->mb[3] = LSW(id_list_dma);
2287 mcp->mb[6] = MSW(MSD(id_list_dma));
2288 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002289 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002290 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002291 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002292 } else {
2293 mcp->mb[1] = MSW(id_list_dma);
2294 mcp->mb[2] = LSW(id_list_dma);
2295 mcp->mb[3] = MSW(MSD(id_list_dma));
2296 mcp->mb[6] = LSW(MSD(id_list_dma));
2297 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002300 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002302 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
2304 if (rval != QLA_SUCCESS) {
2305 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002306 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 } else {
2308 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002309 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2310 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312
2313 return rval;
2314}
2315
2316/*
2317 * qla2x00_get_resource_cnts
2318 * Get current firmware resource counts.
2319 *
2320 * Input:
2321 * ha = adapter block pointer.
2322 *
2323 * Returns:
2324 * qla2x00 local function return status code.
2325 *
2326 * Context:
2327 * Kernel context.
2328 */
2329int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002330qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002331 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002332 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
2334 int rval;
2335 mbx_cmd_t mc;
2336 mbx_cmd_t *mcp = &mc;
2337
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2339 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
2341 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2342 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002343 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002344 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002345 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002346 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002348 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
2350 if (rval != QLA_SUCCESS) {
2351 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002352 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2353 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002355 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002356 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2357 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2358 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2359 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
2361 if (cur_xchg_cnt)
2362 *cur_xchg_cnt = mcp->mb[3];
2363 if (orig_xchg_cnt)
2364 *orig_xchg_cnt = mcp->mb[6];
2365 if (cur_iocb_cnt)
2366 *cur_iocb_cnt = mcp->mb[7];
2367 if (orig_iocb_cnt)
2368 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002369 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002370 *max_npiv_vports = mcp->mb[11];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002371 if ((IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw)) && max_fcfs)
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002372 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 }
2374
2375 return (rval);
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378/*
2379 * qla2x00_get_fcal_position_map
2380 * Get FCAL (LILP) position map using mailbox command
2381 *
2382 * Input:
2383 * ha = adapter state pointer.
2384 * pos_map = buffer pointer (can be NULL).
2385 *
2386 * Returns:
2387 * qla2x00 local function return status code.
2388 *
2389 * Context:
2390 * Kernel context.
2391 */
2392int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002393qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
2395 int rval;
2396 mbx_cmd_t mc;
2397 mbx_cmd_t *mcp = &mc;
2398 char *pmap;
2399 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002400 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002402 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2403 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002404
Andrew Vasquez4b892582008-09-11 21:22:48 -07002405 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002407 ql_log(ql_log_warn, vha, 0x1080,
2408 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 return QLA_MEMORY_ALLOC_FAILED;
2410 }
2411 memset(pmap, 0, FCAL_MAP_SIZE);
2412
2413 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2414 mcp->mb[2] = MSW(pmap_dma);
2415 mcp->mb[3] = LSW(pmap_dma);
2416 mcp->mb[6] = MSW(MSD(pmap_dma));
2417 mcp->mb[7] = LSW(MSD(pmap_dma));
2418 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2419 mcp->in_mb = MBX_1|MBX_0;
2420 mcp->buf_size = FCAL_MAP_SIZE;
2421 mcp->flags = MBX_DMA_IN;
2422 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002423 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002426 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002427 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2428 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2429 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2430 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
2432 if (pos_map)
2433 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2434 }
2435 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2436
2437 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002438 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002440 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2441 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 }
2443
2444 return rval;
2445}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002446
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002447/*
2448 * qla2x00_get_link_status
2449 *
2450 * Input:
2451 * ha = adapter block pointer.
2452 * loop_id = device loop ID.
2453 * ret_buf = pointer to link status return buffer.
2454 *
2455 * Returns:
2456 * 0 = success.
2457 * BIT_0 = mem alloc error.
2458 * BIT_1 = mailbox error.
2459 */
2460int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002461qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002462 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002463{
2464 int rval;
2465 mbx_cmd_t mc;
2466 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002467 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002468 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002469
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2471 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002472
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002473 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002474 mcp->mb[2] = MSW(stats_dma);
2475 mcp->mb[3] = LSW(stats_dma);
2476 mcp->mb[6] = MSW(MSD(stats_dma));
2477 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002478 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2479 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002480 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002481 mcp->mb[1] = loop_id;
2482 mcp->mb[4] = 0;
2483 mcp->mb[10] = 0;
2484 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2485 mcp->in_mb |= MBX_1;
2486 } else if (HAS_EXTENDED_IDS(ha)) {
2487 mcp->mb[1] = loop_id;
2488 mcp->mb[10] = 0;
2489 mcp->out_mb |= MBX_10|MBX_1;
2490 } else {
2491 mcp->mb[1] = loop_id << 8;
2492 mcp->out_mb |= MBX_1;
2493 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002494 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002495 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002496 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002497
2498 if (rval == QLA_SUCCESS) {
2499 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002500 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2501 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002502 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002503 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002504 /* Copy over data -- firmware data is LE. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002505 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2506 "Done %s.\n", __func__);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002507 dwords = offsetof(struct link_statistics, unused1) / 4;
2508 siter = diter = &stats->link_fail_cnt;
2509 while (dwords--)
2510 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002511 }
2512 } else {
2513 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002514 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002515 }
2516
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002517 return rval;
2518}
2519
2520int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002521qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002522 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002523{
2524 int rval;
2525 mbx_cmd_t mc;
2526 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002527 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002528
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002529 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2530 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002531
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002532 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002533 mcp->mb[2] = MSW(stats_dma);
2534 mcp->mb[3] = LSW(stats_dma);
2535 mcp->mb[6] = MSW(MSD(stats_dma));
2536 mcp->mb[7] = LSW(MSD(stats_dma));
2537 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002538 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002539 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002540 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 -07002541 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002542 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002543 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002544 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002545
2546 if (rval == QLA_SUCCESS) {
2547 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002548 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2549 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002550 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002551 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002552 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2553 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002554 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002555 dwords = sizeof(struct link_statistics) / 4;
2556 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002557 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002558 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002559 }
2560 } else {
2561 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002562 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002563 }
2564
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002565 return rval;
2566}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002567
2568int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002569qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002570{
2571 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002572 unsigned long flags = 0;
2573
2574 struct abort_entry_24xx *abt;
2575 dma_addr_t abt_dma;
2576 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002577 fc_port_t *fcport = sp->fcport;
2578 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002579 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002580 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002581
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002582 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2583 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002584
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002585 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002586 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002587 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002588 break;
2589 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002590 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002591 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002592 /* Command not found. */
2593 return QLA_FUNCTION_FAILED;
2594 }
2595
2596 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2597 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002598 ql_log(ql_log_warn, vha, 0x108d,
2599 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002600 return QLA_MEMORY_ALLOC_FAILED;
2601 }
2602 memset(abt, 0, sizeof(struct abort_entry_24xx));
2603
2604 abt->entry_type = ABORT_IOCB_TYPE;
2605 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002606 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002607 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002608 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002609 abt->port_id[0] = fcport->d_id.b.al_pa;
2610 abt->port_id[1] = fcport->d_id.b.area;
2611 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002612 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002613
2614 abt->req_que_no = cpu_to_le16(req->id);
2615
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002616 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002617 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002618 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2619 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002620 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002621 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2622 "Failed to complete IOCB -- error status (%x).\n",
2623 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002624 rval = QLA_FUNCTION_FAILED;
2625 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002626 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2627 "Failed to complete IOCB -- completion status (%x).\n",
2628 le16_to_cpu(abt->nport_handle));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002629 rval = QLA_FUNCTION_FAILED;
2630 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002631 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2632 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002633 }
2634
2635 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2636
2637 return rval;
2638}
2639
2640struct tsk_mgmt_cmd {
2641 union {
2642 struct tsk_mgmt_entry tsk;
2643 struct sts_entry_24xx sts;
2644 } p;
2645};
2646
Andrew Vasquez523ec772008-04-03 13:13:24 -07002647static int
2648__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002649 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002650{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002651 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002652 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002653 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002654 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002655 scsi_qla_host_t *vha;
2656 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002657 struct req_que *req;
2658 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002659
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002660 vha = fcport->vha;
2661 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002662 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002663
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002664 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
2665 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002666
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002667 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002668 rsp = ha->rsp_q_map[tag + 1];
2669 else
2670 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002671 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002672 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002673 ql_log(ql_log_warn, vha, 0x1093,
2674 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002675 return QLA_MEMORY_ALLOC_FAILED;
2676 }
2677 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2678
2679 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2680 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002681 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002682 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002683 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002684 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002685 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2686 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2687 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002688 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002689 if (type == TCF_LUN_RESET) {
2690 int_to_scsilun(l, &tsk->p.tsk.lun);
2691 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2692 sizeof(tsk->p.tsk.lun));
2693 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002694
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002695 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002696 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002697 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002698 ql_dbg(ql_dbg_mbx, vha, 0x1094,
2699 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002700 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002701 ql_dbg(ql_dbg_mbx, vha, 0x1095,
2702 "Failed to complete IOCB -- error status (%x).\n",
2703 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002704 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002705 } else if (sts->comp_status !=
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002706 __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002707 ql_dbg(ql_dbg_mbx, vha, 0x1096,
2708 "Failed to complete IOCB -- completion status (%x).\n",
2709 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002710 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08002711 } else if (le16_to_cpu(sts->scsi_status) &
2712 SS_RESPONSE_INFO_LEN_VALID) {
2713 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002714 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002715 "Ignoring inconsistent data length -- not enough "
2716 "response info (%d).\n",
2717 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08002718 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002719 ql_dbg(ql_dbg_mbx, vha, 0x1098,
2720 "Failed to complete IOCB -- response (%x).\n",
2721 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08002722 rval = QLA_FUNCTION_FAILED;
2723 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002724 }
2725
2726 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002727 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002728 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2729 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002730 ql_dbg(ql_dbg_mbx, vha, 0x1099,
2731 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002732 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002733 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
2734 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002735 }
2736
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002737 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002738
2739 return rval;
2740}
2741
Andrew Vasquez523ec772008-04-03 13:13:24 -07002742int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002743qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002744{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002745 struct qla_hw_data *ha = fcport->vha->hw;
2746
2747 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2748 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
2749
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002750 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002751}
2752
2753int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002754qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002755{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002756 struct qla_hw_data *ha = fcport->vha->hw;
2757
2758 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2759 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
2760
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002761 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002762}
2763
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002764int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002765qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002766{
2767 int rval;
2768 mbx_cmd_t mc;
2769 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002770 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002771
Andrew Vasquez68af0812008-05-12 22:21:13 -07002772 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002773 return QLA_FUNCTION_FAILED;
2774
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002775 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
2776 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002777
2778 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2779 mcp->out_mb = MBX_0;
2780 mcp->in_mb = MBX_0;
2781 mcp->tov = 5;
2782 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002783 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002784
2785 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002786 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002787 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002788 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
2789 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002790 }
2791
2792 return rval;
2793}
2794
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002795/**
2796 * qla2x00_set_serdes_params() -
2797 * @ha: HA context
2798 *
2799 * Returns
2800 */
2801int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002802qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002803 uint16_t sw_em_2g, uint16_t sw_em_4g)
2804{
2805 int rval;
2806 mbx_cmd_t mc;
2807 mbx_cmd_t *mcp = &mc;
2808
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
2810 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002811
2812 mcp->mb[0] = MBC_SERDES_PARAMS;
2813 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002814 mcp->mb[2] = sw_em_1g | BIT_15;
2815 mcp->mb[3] = sw_em_2g | BIT_15;
2816 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002817 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2818 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002819 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002820 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002821 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002822
2823 if (rval != QLA_SUCCESS) {
2824 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 ql_dbg(ql_dbg_mbx, vha, 0x109f,
2826 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002827 } else {
2828 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
2830 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002831 }
2832
2833 return rval;
2834}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002835
2836int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002837qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002838{
2839 int rval;
2840 mbx_cmd_t mc;
2841 mbx_cmd_t *mcp = &mc;
2842
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002843 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002844 return QLA_FUNCTION_FAILED;
2845
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002846 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
2847 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002848
2849 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08002850 mcp->mb[1] = 0;
2851 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002852 mcp->in_mb = MBX_0;
2853 mcp->tov = 5;
2854 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002855 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002856
2857 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002858 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07002859 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2860 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002861 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002862 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
2863 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002864 }
2865
2866 return rval;
2867}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002868
2869int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002870qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002871 uint16_t buffers)
2872{
2873 int rval;
2874 mbx_cmd_t mc;
2875 mbx_cmd_t *mcp = &mc;
2876
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002877 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
2878 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002879
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002880 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002881 return QLA_FUNCTION_FAILED;
2882
Andrew Vasquez85880802009-12-15 21:29:46 -08002883 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2884 return QLA_FUNCTION_FAILED;
2885
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002886 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002887 mcp->mb[1] = TC_EFT_ENABLE;
2888 mcp->mb[2] = LSW(eft_dma);
2889 mcp->mb[3] = MSW(eft_dma);
2890 mcp->mb[4] = LSW(MSD(eft_dma));
2891 mcp->mb[5] = MSW(MSD(eft_dma));
2892 mcp->mb[6] = buffers;
2893 mcp->mb[7] = TC_AEN_DISABLE;
2894 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 -07002895 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002896 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002897 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002898 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002899 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002900 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
2901 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2902 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002903 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
2905 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002906 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002907
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002908 return rval;
2909}
2910
2911int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002912qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002913{
2914 int rval;
2915 mbx_cmd_t mc;
2916 mbx_cmd_t *mcp = &mc;
2917
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002918 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
2919 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002920
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002921 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002922 return QLA_FUNCTION_FAILED;
2923
Andrew Vasquez85880802009-12-15 21:29:46 -08002924 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2925 return QLA_FUNCTION_FAILED;
2926
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002927 mcp->mb[0] = MBC_TRACE_CONTROL;
2928 mcp->mb[1] = TC_EFT_DISABLE;
2929 mcp->out_mb = MBX_1|MBX_0;
2930 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002931 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002932 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002933 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002934 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002935 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
2936 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2937 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002938 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002939 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
2940 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002941 }
2942
2943 return rval;
2944}
2945
Andrew Vasquez88729e52006-06-23 16:10:50 -07002946int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002947qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002948 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2949{
2950 int rval;
2951 mbx_cmd_t mc;
2952 mbx_cmd_t *mcp = &mc;
2953
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002954 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
2955 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002956
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002957 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
2958 !IS_QLA83XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002959 return QLA_FUNCTION_FAILED;
2960
Andrew Vasquez85880802009-12-15 21:29:46 -08002961 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2962 return QLA_FUNCTION_FAILED;
2963
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002964 mcp->mb[0] = MBC_TRACE_CONTROL;
2965 mcp->mb[1] = TC_FCE_ENABLE;
2966 mcp->mb[2] = LSW(fce_dma);
2967 mcp->mb[3] = MSW(fce_dma);
2968 mcp->mb[4] = LSW(MSD(fce_dma));
2969 mcp->mb[5] = MSW(MSD(fce_dma));
2970 mcp->mb[6] = buffers;
2971 mcp->mb[7] = TC_AEN_DISABLE;
2972 mcp->mb[8] = 0;
2973 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2974 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2975 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2976 MBX_1|MBX_0;
2977 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002978 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002979 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002980 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002981 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002982 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
2983 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2984 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002985 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002986 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
2987 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002988
2989 if (mb)
2990 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2991 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002992 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002993 }
2994
2995 return rval;
2996}
2997
2998int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002999qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003000{
3001 int rval;
3002 mbx_cmd_t mc;
3003 mbx_cmd_t *mcp = &mc;
3004
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003005 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3006 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003007
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003008 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003009 return QLA_FUNCTION_FAILED;
3010
Andrew Vasquez85880802009-12-15 21:29:46 -08003011 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3012 return QLA_FUNCTION_FAILED;
3013
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003014 mcp->mb[0] = MBC_TRACE_CONTROL;
3015 mcp->mb[1] = TC_FCE_DISABLE;
3016 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3017 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3018 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3019 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003020 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003021 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003022 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003023 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003024 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3025 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3026 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003027 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003028 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3029 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003030
3031 if (wr)
3032 *wr = (uint64_t) mcp->mb[5] << 48 |
3033 (uint64_t) mcp->mb[4] << 32 |
3034 (uint64_t) mcp->mb[3] << 16 |
3035 (uint64_t) mcp->mb[2];
3036 if (rd)
3037 *rd = (uint64_t) mcp->mb[9] << 48 |
3038 (uint64_t) mcp->mb[8] << 32 |
3039 (uint64_t) mcp->mb[7] << 16 |
3040 (uint64_t) mcp->mb[6];
3041 }
3042
3043 return rval;
3044}
3045
3046int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003047qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3048 uint16_t *port_speed, uint16_t *mb)
3049{
3050 int rval;
3051 mbx_cmd_t mc;
3052 mbx_cmd_t *mcp = &mc;
3053
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003054 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3055 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003056
Giridhar Malavali6e980162010-03-19 17:03:58 -07003057 if (!IS_IIDMA_CAPABLE(vha->hw))
3058 return QLA_FUNCTION_FAILED;
3059
Giridhar Malavali6e980162010-03-19 17:03:58 -07003060 mcp->mb[0] = MBC_PORT_PARAMS;
3061 mcp->mb[1] = loop_id;
3062 mcp->mb[2] = mcp->mb[3] = 0;
3063 mcp->mb[9] = vha->vp_idx;
3064 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3065 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3066 mcp->tov = MBX_TOV_SECONDS;
3067 mcp->flags = 0;
3068 rval = qla2x00_mailbox_command(vha, mcp);
3069
3070 /* Return mailbox statuses. */
3071 if (mb != NULL) {
3072 mb[0] = mcp->mb[0];
3073 mb[1] = mcp->mb[1];
3074 mb[3] = mcp->mb[3];
3075 }
3076
3077 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003078 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003079 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003080 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3081 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003082 if (port_speed)
3083 *port_speed = mcp->mb[3];
3084 }
3085
3086 return rval;
3087}
3088
3089int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003090qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003091 uint16_t port_speed, uint16_t *mb)
3092{
3093 int rval;
3094 mbx_cmd_t mc;
3095 mbx_cmd_t *mcp = &mc;
3096
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3098 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003099
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003100 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003101 return QLA_FUNCTION_FAILED;
3102
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003103 mcp->mb[0] = MBC_PORT_PARAMS;
3104 mcp->mb[1] = loop_id;
3105 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003106 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003107 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3108 else
3109 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3110 mcp->mb[9] = vha->vp_idx;
3111 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3112 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003113 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003114 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003115 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003116
3117 /* Return mailbox statuses. */
3118 if (mb != NULL) {
3119 mb[0] = mcp->mb[0];
3120 mb[1] = mcp->mb[1];
3121 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003122 }
3123
3124 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003125 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3126 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003127 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003128 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3129 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003130 }
3131
3132 return rval;
3133}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003134
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003135void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003136qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003137 struct vp_rpt_id_entry_24xx *rptid_entry)
3138{
3139 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07003140 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003141 struct qla_hw_data *ha = vha->hw;
3142 scsi_qla_host_t *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003143 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003144 int found;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003145
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003146 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3147 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003148
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003149 if (rptid_entry->entry_status != 0)
3150 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003151
3152 if (rptid_entry->format == 0) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003153 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003154 "Format 0 : Number of VPs setup %d, number of "
3155 "VPs acquired %d.\n",
3156 MSB(le16_to_cpu(rptid_entry->vp_count)),
3157 LSB(le16_to_cpu(rptid_entry->vp_count)));
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003158 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003159 "Primary port id %02x%02x%02x.\n",
3160 rptid_entry->port_id[2], rptid_entry->port_id[1],
3161 rptid_entry->port_id[0]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003162 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07003163 vp_idx = LSB(stat);
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003164 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003165 "Format 1: VP[%d] enabled - status %d - with "
3166 "port id %02x%02x%02x.\n", vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003167 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003168 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003169
3170 vp = vha;
3171 if (vp_idx == 0 && (MSB(stat) != 1))
3172 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003173
Saurav Kashyap681e0142012-11-21 02:40:28 -05003174 if (MSB(stat) != 0 && MSB(stat) != 2) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003175 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3176 "Could not acquire ID for VP[%d].\n", vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003177 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07003178 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003179
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003180 found = 0;
Arun Easifeafb7b2010-09-03 14:57:00 -07003181 spin_lock_irqsave(&ha->vport_slock, flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003182 list_for_each_entry(vp, &ha->vp_list, list) {
3183 if (vp_idx == vp->vp_idx) {
3184 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003185 break;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003186 }
3187 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003188 spin_unlock_irqrestore(&ha->vport_slock, flags);
3189
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003190 if (!found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003191 return;
3192
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003193 vp->d_id.b.domain = rptid_entry->port_id[2];
3194 vp->d_id.b.area = rptid_entry->port_id[1];
3195 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003196
3197 /*
3198 * Cannot configure here as we are still sitting on the
3199 * response queue. Handle it in dpc context.
3200 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003201 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003202
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003203reg_needed:
3204 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3205 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
3206 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003207 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003208 }
3209}
3210
3211/*
3212 * qla24xx_modify_vp_config
3213 * Change VP configuration for vha
3214 *
3215 * Input:
3216 * vha = adapter block pointer.
3217 *
3218 * Returns:
3219 * qla2xxx local function return status code.
3220 *
3221 * Context:
3222 * Kernel context.
3223 */
3224int
3225qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3226{
3227 int rval;
3228 struct vp_config_entry_24xx *vpmod;
3229 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003230 struct qla_hw_data *ha = vha->hw;
3231 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003232
3233 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003234
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3236 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003237
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003238 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003239 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003240 ql_log(ql_log_warn, vha, 0x10bc,
3241 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003242 return QLA_MEMORY_ALLOC_FAILED;
3243 }
3244
3245 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3246 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3247 vpmod->entry_count = 1;
3248 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3249 vpmod->vp_count = 1;
3250 vpmod->vp_index1 = vha->vp_idx;
3251 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003252
3253 qlt_modify_vp_config(vha, vpmod);
3254
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003255 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3256 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3257 vpmod->entry_count = 1;
3258
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003259 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003260 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003261 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3262 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003263 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003264 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3265 "Failed to complete IOCB -- error status (%x).\n",
3266 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003267 rval = QLA_FUNCTION_FAILED;
3268 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003269 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3270 "Failed to complete IOCB -- completion status (%x).\n",
3271 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003272 rval = QLA_FUNCTION_FAILED;
3273 } else {
3274 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003275 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3276 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003277 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3278 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003279 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003280
3281 return rval;
3282}
3283
3284/*
3285 * qla24xx_control_vp
3286 * Enable a virtual port for given host
3287 *
3288 * Input:
3289 * ha = adapter block pointer.
3290 * vhba = virtual adapter (unused)
3291 * index = index number for enabled VP
3292 *
3293 * Returns:
3294 * qla2xxx local function return status code.
3295 *
3296 * Context:
3297 * Kernel context.
3298 */
3299int
3300qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3301{
3302 int rval;
3303 int map, pos;
3304 struct vp_ctrl_entry_24xx *vce;
3305 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003306 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003307 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003308 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003309
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003310 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003311 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003312
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003313 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003314 return QLA_PARAMETER_ERROR;
3315
3316 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3317 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003318 ql_log(ql_log_warn, vha, 0x10c2,
3319 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003320 return QLA_MEMORY_ALLOC_FAILED;
3321 }
3322 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3323
3324 vce->entry_type = VP_CTRL_IOCB_TYPE;
3325 vce->entry_count = 1;
3326 vce->command = cpu_to_le16(cmd);
3327 vce->vp_count = __constant_cpu_to_le16(1);
3328
3329 /* index map in firmware starts with 1; decrement index
3330 * this is ok as we never use index 0
3331 */
3332 map = (vp_index - 1) / 8;
3333 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003334 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003335 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003336 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003337
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003338 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003339 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003340 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3341 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003342 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003343 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3344 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003345 vce->entry_status);
3346 rval = QLA_FUNCTION_FAILED;
3347 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003348 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3349 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003350 le16_to_cpu(vce->comp_status));
3351 rval = QLA_FUNCTION_FAILED;
3352 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003353 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3354 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003355 }
3356
3357 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3358
3359 return rval;
3360}
3361
3362/*
3363 * qla2x00_send_change_request
3364 * Receive or disable RSCN request from fabric controller
3365 *
3366 * Input:
3367 * ha = adapter block pointer
3368 * format = registration format:
3369 * 0 - Reserved
3370 * 1 - Fabric detected registration
3371 * 2 - N_port detected registration
3372 * 3 - Full registration
3373 * FF - clear registration
3374 * vp_idx = Virtual port index
3375 *
3376 * Returns:
3377 * qla2x00 local function return status code.
3378 *
3379 * Context:
3380 * Kernel Context
3381 */
3382
3383int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003384qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003385 uint16_t vp_idx)
3386{
3387 int rval;
3388 mbx_cmd_t mc;
3389 mbx_cmd_t *mcp = &mc;
3390
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3392 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003393
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003394 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3395 mcp->mb[1] = format;
3396 mcp->mb[9] = vp_idx;
3397 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3398 mcp->in_mb = MBX_0|MBX_1;
3399 mcp->tov = MBX_TOV_SECONDS;
3400 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003401 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003402
3403 if (rval == QLA_SUCCESS) {
3404 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3405 rval = BIT_1;
3406 }
3407 } else
3408 rval = BIT_1;
3409
3410 return rval;
3411}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003412
3413int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003414qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003415 uint32_t size)
3416{
3417 int rval;
3418 mbx_cmd_t mc;
3419 mbx_cmd_t *mcp = &mc;
3420
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003421 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3422 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003423
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003424 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003425 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3426 mcp->mb[8] = MSW(addr);
3427 mcp->out_mb = MBX_8|MBX_0;
3428 } else {
3429 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3430 mcp->out_mb = MBX_0;
3431 }
3432 mcp->mb[1] = LSW(addr);
3433 mcp->mb[2] = MSW(req_dma);
3434 mcp->mb[3] = LSW(req_dma);
3435 mcp->mb[6] = MSW(MSD(req_dma));
3436 mcp->mb[7] = LSW(MSD(req_dma));
3437 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003438 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003439 mcp->mb[4] = MSW(size);
3440 mcp->mb[5] = LSW(size);
3441 mcp->out_mb |= MBX_5|MBX_4;
3442 } else {
3443 mcp->mb[4] = LSW(size);
3444 mcp->out_mb |= MBX_4;
3445 }
3446
3447 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003448 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003449 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003450 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003451
3452 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003453 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3454 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003455 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003456 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3457 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003458 }
3459
3460 return rval;
3461}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003462/* 84XX Support **************************************************************/
3463
3464struct cs84xx_mgmt_cmd {
3465 union {
3466 struct verify_chip_entry_84xx req;
3467 struct verify_chip_rsp_84xx rsp;
3468 } p;
3469};
3470
3471int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003472qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003473{
3474 int rval, retry;
3475 struct cs84xx_mgmt_cmd *mn;
3476 dma_addr_t mn_dma;
3477 uint16_t options;
3478 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003479 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003480
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003481 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
3482 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003483
3484 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3485 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003486 return QLA_MEMORY_ALLOC_FAILED;
3487 }
3488
3489 /* Force Update? */
3490 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3491 /* Diagnostic firmware? */
3492 /* options |= MENLO_DIAG_FW; */
3493 /* We update the firmware with only one data sequence. */
3494 options |= VCO_END_OF_DATA;
3495
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003496 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003497 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003498 memset(mn, 0, sizeof(*mn));
3499 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3500 mn->p.req.entry_count = 1;
3501 mn->p.req.options = cpu_to_le16(options);
3502
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003503 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
3504 "Dump of Verify Request.\n");
3505 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
3506 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003507
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003508 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003509 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003510 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
3511 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003512 goto verify_done;
3513 }
3514
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003515 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
3516 "Dump of Verify Response.\n");
3517 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
3518 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003519
3520 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3521 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3522 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003523 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003524 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003525
3526 if (status[0] != CS_COMPLETE) {
3527 rval = QLA_FUNCTION_FAILED;
3528 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003529 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
3530 "Firmware update failed. Retrying "
3531 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003532 options |= VCO_DONT_UPDATE_FW;
3533 options &= ~VCO_FORCE_UPDATE;
3534 retry = 1;
3535 }
3536 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003537 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003538 "Firmware updated to %x.\n",
3539 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003540
3541 /* NOTE: we only update OP firmware. */
3542 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3543 ha->cs84xx->op_fw_version =
3544 le32_to_cpu(mn->p.rsp.fw_ver);
3545 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3546 flags);
3547 }
3548 } while (retry);
3549
3550verify_done:
3551 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3552
3553 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003554 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
3555 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003556 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003557 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
3558 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003559 }
3560
3561 return rval;
3562}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003563
3564int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003565qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003566{
3567 int rval;
3568 unsigned long flags;
3569 mbx_cmd_t mc;
3570 mbx_cmd_t *mcp = &mc;
3571 struct device_reg_25xxmq __iomem *reg;
3572 struct qla_hw_data *ha = vha->hw;
3573
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003574 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
3575 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003576
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003577 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003578 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003579 mcp->mb[2] = MSW(LSD(req->dma));
3580 mcp->mb[3] = LSW(LSD(req->dma));
3581 mcp->mb[6] = MSW(MSD(req->dma));
3582 mcp->mb[7] = LSW(MSD(req->dma));
3583 mcp->mb[5] = req->length;
3584 if (req->rsp)
3585 mcp->mb[10] = req->rsp->id;
3586 mcp->mb[12] = req->qos;
3587 mcp->mb[11] = req->vp_idx;
3588 mcp->mb[13] = req->rid;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003589 if (IS_QLA83XX(ha))
3590 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003591
Saurav Kashyapfa492632012-11-21 02:40:29 -05003592 reg = (struct device_reg_25xxmq __iomem *)((ha->mqiobase) +
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003593 QLA_QUE_PAGE * req->id);
3594
3595 mcp->mb[4] = req->id;
3596 /* que in ptr index */
3597 mcp->mb[8] = 0;
3598 /* que out ptr index */
3599 mcp->mb[9] = 0;
3600 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3601 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3602 mcp->in_mb = MBX_0;
3603 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003604 mcp->tov = MBX_TOV_SECONDS * 2;
3605
3606 if (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3607 mcp->in_mb |= MBX_1;
3608 if (IS_QLA83XX(ha)) {
3609 mcp->out_mb |= MBX_15;
3610 /* debug q create issue in SR-IOV */
3611 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
3612 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003613
3614 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003615 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003616 WRT_REG_DWORD(&reg->req_q_in, 0);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003617 if (!IS_QLA83XX(ha))
3618 WRT_REG_DWORD(&reg->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003619 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003620 req->req_q_in = &reg->req_q_in;
3621 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003622 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3623
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003624 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003625 if (rval != QLA_SUCCESS) {
3626 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
3627 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3628 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003629 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
3630 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003631 }
3632
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003633 return rval;
3634}
3635
3636int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003637qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003638{
3639 int rval;
3640 unsigned long flags;
3641 mbx_cmd_t mc;
3642 mbx_cmd_t *mcp = &mc;
3643 struct device_reg_25xxmq __iomem *reg;
3644 struct qla_hw_data *ha = vha->hw;
3645
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003646 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
3647 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003648
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003649 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003650 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003651 mcp->mb[2] = MSW(LSD(rsp->dma));
3652 mcp->mb[3] = LSW(LSD(rsp->dma));
3653 mcp->mb[6] = MSW(MSD(rsp->dma));
3654 mcp->mb[7] = LSW(MSD(rsp->dma));
3655 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003656 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003657 mcp->mb[13] = rsp->rid;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003658 if (IS_QLA83XX(ha))
3659 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003660
Saurav Kashyapfa492632012-11-21 02:40:29 -05003661 reg = (struct device_reg_25xxmq __iomem *)((ha->mqiobase) +
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003662 QLA_QUE_PAGE * rsp->id);
3663
3664 mcp->mb[4] = rsp->id;
3665 /* que in ptr index */
3666 mcp->mb[8] = 0;
3667 /* que out ptr index */
3668 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003669 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003670 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3671 mcp->in_mb = MBX_0;
3672 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003673 mcp->tov = MBX_TOV_SECONDS * 2;
3674
3675 if (IS_QLA81XX(ha)) {
3676 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
3677 mcp->in_mb |= MBX_1;
3678 } else if (IS_QLA83XX(ha)) {
3679 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
3680 mcp->in_mb |= MBX_1;
3681 /* debug q create issue in SR-IOV */
3682 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
3683 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003684
3685 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003686 if (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003687 WRT_REG_DWORD(&reg->rsp_q_out, 0);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003688 if (!IS_QLA83XX(ha))
3689 WRT_REG_DWORD(&reg->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003690 }
3691
3692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3693
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003694 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003695 if (rval != QLA_SUCCESS) {
3696 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
3697 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3698 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003699 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
3700 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003701 }
3702
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003703 return rval;
3704}
3705
Andrew Vasquez8a659572009-02-08 20:50:12 -08003706int
3707qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3708{
3709 int rval;
3710 mbx_cmd_t mc;
3711 mbx_cmd_t *mcp = &mc;
3712
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
3714 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003715
3716 mcp->mb[0] = MBC_IDC_ACK;
3717 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3718 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3719 mcp->in_mb = MBX_0;
3720 mcp->tov = MBX_TOV_SECONDS;
3721 mcp->flags = 0;
3722 rval = qla2x00_mailbox_command(vha, mcp);
3723
3724 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003725 ql_dbg(ql_dbg_mbx, vha, 0x10da,
3726 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003727 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003728 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
3729 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003730 }
3731
3732 return rval;
3733}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003734
3735int
3736qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3737{
3738 int rval;
3739 mbx_cmd_t mc;
3740 mbx_cmd_t *mcp = &mc;
3741
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003742 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
3743 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003744
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003745 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003746 return QLA_FUNCTION_FAILED;
3747
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003748 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3749 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3750 mcp->out_mb = MBX_1|MBX_0;
3751 mcp->in_mb = MBX_1|MBX_0;
3752 mcp->tov = MBX_TOV_SECONDS;
3753 mcp->flags = 0;
3754 rval = qla2x00_mailbox_command(vha, mcp);
3755
3756 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003757 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
3758 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3759 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003760 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003761 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
3762 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003763 *sector_size = mcp->mb[1];
3764 }
3765
3766 return rval;
3767}
3768
3769int
3770qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3771{
3772 int rval;
3773 mbx_cmd_t mc;
3774 mbx_cmd_t *mcp = &mc;
3775
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003776 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003777 return QLA_FUNCTION_FAILED;
3778
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
3780 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003781
3782 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3783 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3784 FAC_OPT_CMD_WRITE_PROTECT;
3785 mcp->out_mb = MBX_1|MBX_0;
3786 mcp->in_mb = MBX_1|MBX_0;
3787 mcp->tov = MBX_TOV_SECONDS;
3788 mcp->flags = 0;
3789 rval = qla2x00_mailbox_command(vha, mcp);
3790
3791 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003792 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
3793 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3794 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003795 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003796 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
3797 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003798 }
3799
3800 return rval;
3801}
3802
3803int
3804qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3805{
3806 int rval;
3807 mbx_cmd_t mc;
3808 mbx_cmd_t *mcp = &mc;
3809
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003810 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003811 return QLA_FUNCTION_FAILED;
3812
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003813 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
3814 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003815
3816 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3817 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3818 mcp->mb[2] = LSW(start);
3819 mcp->mb[3] = MSW(start);
3820 mcp->mb[4] = LSW(finish);
3821 mcp->mb[5] = MSW(finish);
3822 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3823 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3824 mcp->tov = MBX_TOV_SECONDS;
3825 mcp->flags = 0;
3826 rval = qla2x00_mailbox_command(vha, mcp);
3827
3828 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003829 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
3830 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
3831 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003832 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003833 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
3834 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003835 }
3836
3837 return rval;
3838}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003839
3840int
3841qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3842{
3843 int rval = 0;
3844 mbx_cmd_t mc;
3845 mbx_cmd_t *mcp = &mc;
3846
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003847 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
3848 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003849
3850 mcp->mb[0] = MBC_RESTART_MPI_FW;
3851 mcp->out_mb = MBX_0;
3852 mcp->in_mb = MBX_0|MBX_1;
3853 mcp->tov = MBX_TOV_SECONDS;
3854 mcp->flags = 0;
3855 rval = qla2x00_mailbox_command(vha, mcp);
3856
3857 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003858 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
3859 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3860 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003861 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003862 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
3863 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003864 }
3865
3866 return rval;
3867}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003868
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05003869static int
3870qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
3871{
3872 int rval;
3873 mbx_cmd_t mc;
3874 mbx_cmd_t *mcp = &mc;
3875
3876 if (!IS_FWI2_CAPABLE(vha->hw))
3877 return QLA_FUNCTION_FAILED;
3878
3879 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
3880 "Entered %s.\n", __func__);
3881
3882 mcp->mb[0] = MBC_GET_RNID_PARAMS;
3883 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
3884 mcp->out_mb = MBX_1|MBX_0;
3885 mcp->in_mb = MBX_1|MBX_0;
3886 mcp->tov = MBX_TOV_SECONDS;
3887 mcp->flags = 0;
3888 rval = qla2x00_mailbox_command(vha, mcp);
3889 *temp = mcp->mb[1];
3890
3891 if (rval != QLA_SUCCESS) {
3892 ql_dbg(ql_dbg_mbx, vha, 0x115a,
3893 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
3894 } else {
3895 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
3896 "Done %s.\n", __func__);
3897 }
3898
3899 return rval;
3900}
3901
Joe Carnuccio3a117112013-02-08 01:58:00 -05003902int
Joe Carnuccio6766df92011-05-10 11:30:15 -07003903qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
3904 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003905{
3906 int rval;
3907 mbx_cmd_t mc;
3908 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003909 struct qla_hw_data *ha = vha->hw;
3910
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003911 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
3912 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003913
Joe Carnuccio6766df92011-05-10 11:30:15 -07003914 if (!IS_FWI2_CAPABLE(ha))
3915 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003916
Joe Carnuccio6766df92011-05-10 11:30:15 -07003917 if (len == 1)
3918 opt |= BIT_0;
3919
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003920 mcp->mb[0] = MBC_READ_SFP;
3921 mcp->mb[1] = dev;
3922 mcp->mb[2] = MSW(sfp_dma);
3923 mcp->mb[3] = LSW(sfp_dma);
3924 mcp->mb[6] = MSW(MSD(sfp_dma));
3925 mcp->mb[7] = LSW(MSD(sfp_dma));
3926 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003927 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003928 mcp->mb[10] = opt;
3929 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 -07003930 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003931 mcp->tov = MBX_TOV_SECONDS;
3932 mcp->flags = 0;
3933 rval = qla2x00_mailbox_command(vha, mcp);
3934
3935 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07003936 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003937
3938 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003939 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
3940 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003941 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003942 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
3943 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003944 }
3945
3946 return rval;
3947}
3948
3949int
Joe Carnuccio6766df92011-05-10 11:30:15 -07003950qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
3951 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003952{
3953 int rval;
3954 mbx_cmd_t mc;
3955 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003956 struct qla_hw_data *ha = vha->hw;
3957
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003958 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
3959 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003960
Joe Carnuccio6766df92011-05-10 11:30:15 -07003961 if (!IS_FWI2_CAPABLE(ha))
3962 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003963
Joe Carnuccio6766df92011-05-10 11:30:15 -07003964 if (len == 1)
3965 opt |= BIT_0;
3966
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003967 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07003968 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003969
3970 mcp->mb[0] = MBC_WRITE_SFP;
3971 mcp->mb[1] = dev;
3972 mcp->mb[2] = MSW(sfp_dma);
3973 mcp->mb[3] = LSW(sfp_dma);
3974 mcp->mb[6] = MSW(MSD(sfp_dma));
3975 mcp->mb[7] = LSW(MSD(sfp_dma));
3976 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003977 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003978 mcp->mb[10] = opt;
3979 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 -07003980 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003981 mcp->tov = MBX_TOV_SECONDS;
3982 mcp->flags = 0;
3983 rval = qla2x00_mailbox_command(vha, mcp);
3984
3985 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003986 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
3987 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003988 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003989 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
3990 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003991 }
3992
3993 return rval;
3994}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003995
3996int
3997qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3998 uint16_t size_in_bytes, uint16_t *actual_size)
3999{
4000 int rval;
4001 mbx_cmd_t mc;
4002 mbx_cmd_t *mcp = &mc;
4003
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004004 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4005 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004006
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004007 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004008 return QLA_FUNCTION_FAILED;
4009
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004010 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4011 mcp->mb[2] = MSW(stats_dma);
4012 mcp->mb[3] = LSW(stats_dma);
4013 mcp->mb[6] = MSW(MSD(stats_dma));
4014 mcp->mb[7] = LSW(MSD(stats_dma));
4015 mcp->mb[8] = size_in_bytes >> 2;
4016 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4017 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4018 mcp->tov = MBX_TOV_SECONDS;
4019 mcp->flags = 0;
4020 rval = qla2x00_mailbox_command(vha, mcp);
4021
4022 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004023 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4024 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4025 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004026 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004027 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4028 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004029
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004030
4031 *actual_size = mcp->mb[2] << 2;
4032 }
4033
4034 return rval;
4035}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004036
4037int
4038qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4039 uint16_t size)
4040{
4041 int rval;
4042 mbx_cmd_t mc;
4043 mbx_cmd_t *mcp = &mc;
4044
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004045 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4046 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004047
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004048 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004049 return QLA_FUNCTION_FAILED;
4050
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004051 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4052 mcp->mb[1] = 0;
4053 mcp->mb[2] = MSW(tlv_dma);
4054 mcp->mb[3] = LSW(tlv_dma);
4055 mcp->mb[6] = MSW(MSD(tlv_dma));
4056 mcp->mb[7] = LSW(MSD(tlv_dma));
4057 mcp->mb[8] = size;
4058 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4059 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4060 mcp->tov = MBX_TOV_SECONDS;
4061 mcp->flags = 0;
4062 rval = qla2x00_mailbox_command(vha, mcp);
4063
4064 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004065 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4066 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4067 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004068 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004069 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4070 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004071 }
4072
4073 return rval;
4074}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004075
4076int
4077qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4078{
4079 int rval;
4080 mbx_cmd_t mc;
4081 mbx_cmd_t *mcp = &mc;
4082
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004083 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4084 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004085
Andrew Vasquez18e75552009-06-03 09:55:30 -07004086 if (!IS_FWI2_CAPABLE(vha->hw))
4087 return QLA_FUNCTION_FAILED;
4088
Andrew Vasquez18e75552009-06-03 09:55:30 -07004089 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4090 mcp->mb[1] = LSW(risc_addr);
4091 mcp->mb[8] = MSW(risc_addr);
4092 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4093 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4094 mcp->tov = 30;
4095 mcp->flags = 0;
4096 rval = qla2x00_mailbox_command(vha, mcp);
4097 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004098 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4099 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004100 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004101 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4102 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004103 *data = mcp->mb[3] << 16 | mcp->mb[2];
4104 }
4105
4106 return rval;
4107}
4108
4109int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004110qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4111 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004112{
4113 int rval;
4114 mbx_cmd_t mc;
4115 mbx_cmd_t *mcp = &mc;
4116 uint32_t iter_cnt = 0x1;
4117
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004118 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4119 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004120
4121 memset(mcp->mb, 0 , sizeof(mcp->mb));
4122 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4123 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4124
4125 /* transfer count */
4126 mcp->mb[10] = LSW(mreq->transfer_size);
4127 mcp->mb[11] = MSW(mreq->transfer_size);
4128
4129 /* send data address */
4130 mcp->mb[14] = LSW(mreq->send_dma);
4131 mcp->mb[15] = MSW(mreq->send_dma);
4132 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4133 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4134
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004135 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004136 mcp->mb[16] = LSW(mreq->rcv_dma);
4137 mcp->mb[17] = MSW(mreq->rcv_dma);
4138 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4139 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4140
4141 /* Iteration count */
4142 mcp->mb[18] = LSW(iter_cnt);
4143 mcp->mb[19] = MSW(iter_cnt);
4144
4145 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4146 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004147 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004148 mcp->out_mb |= MBX_2;
4149 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4150
4151 mcp->buf_size = mreq->transfer_size;
4152 mcp->tov = MBX_TOV_SECONDS;
4153 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4154
4155 rval = qla2x00_mailbox_command(vha, mcp);
4156
4157 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004158 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4159 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4160 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4161 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004162 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004163 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4164 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004165 }
4166
4167 /* Copy mailbox information */
4168 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004169 return rval;
4170}
4171
4172int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004173qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4174 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004175{
4176 int rval;
4177 mbx_cmd_t mc;
4178 mbx_cmd_t *mcp = &mc;
4179 struct qla_hw_data *ha = vha->hw;
4180
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004181 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4182 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004183
4184 memset(mcp->mb, 0 , sizeof(mcp->mb));
4185 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
4186 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004187 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004188 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004189 mcp->mb[2] = vha->fcoe_fcf_idx;
4190 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004191 mcp->mb[16] = LSW(mreq->rcv_dma);
4192 mcp->mb[17] = MSW(mreq->rcv_dma);
4193 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4194 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4195
4196 mcp->mb[10] = LSW(mreq->transfer_size);
4197
4198 mcp->mb[14] = LSW(mreq->send_dma);
4199 mcp->mb[15] = MSW(mreq->send_dma);
4200 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4201 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4202
4203 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4204 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004205 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004206 mcp->out_mb |= MBX_2;
4207
4208 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004209 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4210 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004211 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004212 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004213 mcp->in_mb |= MBX_3;
4214
4215 mcp->tov = MBX_TOV_SECONDS;
4216 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4217 mcp->buf_size = mreq->transfer_size;
4218
4219 rval = qla2x00_mailbox_command(vha, mcp);
4220
4221 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004222 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4223 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4224 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004225 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004226 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4227 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004228 }
4229
4230 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004231 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004232 return rval;
4233}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004234
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004235int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004236qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004237{
4238 int rval;
4239 mbx_cmd_t mc;
4240 mbx_cmd_t *mcp = &mc;
4241
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004243 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004244
4245 mcp->mb[0] = MBC_ISP84XX_RESET;
4246 mcp->mb[1] = enable_diagnostic;
4247 mcp->out_mb = MBX_1|MBX_0;
4248 mcp->in_mb = MBX_1|MBX_0;
4249 mcp->tov = MBX_TOV_SECONDS;
4250 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004251 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004252
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004253 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004254 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004255 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004256 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4257 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004258
4259 return rval;
4260}
4261
4262int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004263qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4264{
4265 int rval;
4266 mbx_cmd_t mc;
4267 mbx_cmd_t *mcp = &mc;
4268
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004269 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4270 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004271
Andrew Vasquez18e75552009-06-03 09:55:30 -07004272 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004273 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004274
Andrew Vasquez18e75552009-06-03 09:55:30 -07004275 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4276 mcp->mb[1] = LSW(risc_addr);
4277 mcp->mb[2] = LSW(data);
4278 mcp->mb[3] = MSW(data);
4279 mcp->mb[8] = MSW(risc_addr);
4280 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4281 mcp->in_mb = MBX_0;
4282 mcp->tov = 30;
4283 mcp->flags = 0;
4284 rval = qla2x00_mailbox_command(vha, mcp);
4285 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004286 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4287 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004288 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004289 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4290 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004291 }
4292
4293 return rval;
4294}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004295
4296int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004297qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4298{
4299 int rval;
4300 uint32_t stat, timer;
4301 uint16_t mb0 = 0;
4302 struct qla_hw_data *ha = vha->hw;
4303 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4304
4305 rval = QLA_SUCCESS;
4306
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004307 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4308 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004309
4310 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4311
4312 /* Write the MBC data to the registers */
4313 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4314 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4315 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4316 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4317 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4318
4319 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4320
4321 /* Poll for MBC interrupt */
4322 for (timer = 6000000; timer; timer--) {
4323 /* Check for pending interrupts. */
4324 stat = RD_REG_DWORD(&reg->host_status);
4325 if (stat & HSRX_RISC_INT) {
4326 stat &= 0xff;
4327
4328 if (stat == 0x1 || stat == 0x2 ||
4329 stat == 0x10 || stat == 0x11) {
4330 set_bit(MBX_INTERRUPT,
4331 &ha->mbx_cmd_flags);
4332 mb0 = RD_REG_WORD(&reg->mailbox0);
4333 WRT_REG_DWORD(&reg->hccr,
4334 HCCRX_CLR_RISC_INT);
4335 RD_REG_DWORD(&reg->hccr);
4336 break;
4337 }
4338 }
4339 udelay(5);
4340 }
4341
4342 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4343 rval = mb0 & MBS_MASK;
4344 else
4345 rval = QLA_FUNCTION_FAILED;
4346
4347 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004348 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4349 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004350 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4352 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004353 }
4354
4355 return rval;
4356}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004357
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004358int
Michael Hernandez3064ff32009-12-15 21:29:44 -08004359qla2x00_get_data_rate(scsi_qla_host_t *vha)
4360{
4361 int rval;
4362 mbx_cmd_t mc;
4363 mbx_cmd_t *mcp = &mc;
4364 struct qla_hw_data *ha = vha->hw;
4365
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004366 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
4367 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004368
Michael Hernandez3064ff32009-12-15 21:29:44 -08004369 if (!IS_FWI2_CAPABLE(ha))
4370 return QLA_FUNCTION_FAILED;
4371
Michael Hernandez3064ff32009-12-15 21:29:44 -08004372 mcp->mb[0] = MBC_DATA_RATE;
4373 mcp->mb[1] = 0;
4374 mcp->out_mb = MBX_1|MBX_0;
4375 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004376 if (IS_QLA83XX(ha))
4377 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08004378 mcp->tov = MBX_TOV_SECONDS;
4379 mcp->flags = 0;
4380 rval = qla2x00_mailbox_command(vha, mcp);
4381 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004382 ql_dbg(ql_dbg_mbx, vha, 0x1107,
4383 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08004384 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004385 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
4386 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08004387 if (mcp->mb[1] != 0x7)
4388 ha->link_data_rate = mcp->mb[1];
4389 }
4390
4391 return rval;
4392}
Sarang Radke09ff7012010-03-19 17:03:59 -07004393
4394int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004395qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4396{
4397 int rval;
4398 mbx_cmd_t mc;
4399 mbx_cmd_t *mcp = &mc;
4400 struct qla_hw_data *ha = vha->hw;
4401
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004402 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
4403 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004404
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004405 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004406 return QLA_FUNCTION_FAILED;
4407 mcp->mb[0] = MBC_GET_PORT_CONFIG;
4408 mcp->out_mb = MBX_0;
4409 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4410 mcp->tov = MBX_TOV_SECONDS;
4411 mcp->flags = 0;
4412
4413 rval = qla2x00_mailbox_command(vha, mcp);
4414
4415 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004416 ql_dbg(ql_dbg_mbx, vha, 0x110a,
4417 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004418 } else {
4419 /* Copy all bits to preserve original value */
4420 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
4421
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004422 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
4423 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004424 }
4425 return rval;
4426}
4427
4428int
4429qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4430{
4431 int rval;
4432 mbx_cmd_t mc;
4433 mbx_cmd_t *mcp = &mc;
4434
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004435 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
4436 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004437
4438 mcp->mb[0] = MBC_SET_PORT_CONFIG;
4439 /* Copy all bits to preserve original setting */
4440 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
4441 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4442 mcp->in_mb = MBX_0;
4443 mcp->tov = MBX_TOV_SECONDS;
4444 mcp->flags = 0;
4445 rval = qla2x00_mailbox_command(vha, mcp);
4446
4447 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004448 ql_dbg(ql_dbg_mbx, vha, 0x110d,
4449 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004450 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004451 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
4452 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004453
4454 return rval;
4455}
4456
4457
4458int
Sarang Radke09ff7012010-03-19 17:03:59 -07004459qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
4460 uint16_t *mb)
4461{
4462 int rval;
4463 mbx_cmd_t mc;
4464 mbx_cmd_t *mcp = &mc;
4465 struct qla_hw_data *ha = vha->hw;
4466
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004467 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
4468 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004469
Sarang Radke09ff7012010-03-19 17:03:59 -07004470 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
4471 return QLA_FUNCTION_FAILED;
4472
Sarang Radke09ff7012010-03-19 17:03:59 -07004473 mcp->mb[0] = MBC_PORT_PARAMS;
4474 mcp->mb[1] = loop_id;
4475 if (ha->flags.fcp_prio_enabled)
4476 mcp->mb[2] = BIT_1;
4477 else
4478 mcp->mb[2] = BIT_2;
4479 mcp->mb[4] = priority & 0xf;
4480 mcp->mb[9] = vha->vp_idx;
4481 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4482 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4483 mcp->tov = 30;
4484 mcp->flags = 0;
4485 rval = qla2x00_mailbox_command(vha, mcp);
4486 if (mb != NULL) {
4487 mb[0] = mcp->mb[0];
4488 mb[1] = mcp->mb[1];
4489 mb[3] = mcp->mb[3];
4490 mb[4] = mcp->mb[4];
4491 }
4492
4493 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004494 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07004495 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004496 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
4497 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07004498 }
4499
4500 return rval;
4501}
Giridhar Malavalia9083012010-04-12 17:59:55 -07004502
4503int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004504qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08004505{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004506 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004507 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004508 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004509
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004510 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ca,
4511 "Entered %s.\n", __func__);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004512
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004513 if (ha->thermal_support & THERMAL_SUPPORT_I2C) {
4514 rval = qla2x00_read_sfp(vha, 0, &byte,
4515 0x98, 0x1, 1, BIT_13|BIT_12|BIT_0);
4516 *temp = byte;
4517 if (rval == QLA_SUCCESS)
4518 goto done;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004519
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004520 ql_log(ql_log_warn, vha, 0x10c9,
Joe Carnuccio490b7732013-03-28 08:21:25 -04004521 "Thermal not supported through I2C bus, trying alternate "
4522 "method (ISP access).\n");
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004523 ha->thermal_support &= ~THERMAL_SUPPORT_I2C;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004524 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08004525
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004526 if (ha->thermal_support & THERMAL_SUPPORT_ISP) {
4527 rval = qla2x00_read_asic_temperature(vha, temp);
4528 if (rval == QLA_SUCCESS)
4529 goto done;
4530
4531 ql_log(ql_log_warn, vha, 0x1019,
Joe Carnuccio490b7732013-03-28 08:21:25 -04004532 "Thermal not supported through ISP.\n");
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004533 ha->thermal_support &= ~THERMAL_SUPPORT_ISP;
4534 }
4535
Joe Carnuccio37f489b2013-02-08 01:57:45 -05004536 ql_log(ql_log_warn, vha, 0x1150,
4537 "Thermal not supported by this card "
4538 "(ignoring further requests).\n");
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004539 return rval;
4540
4541done:
4542 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1018,
4543 "Done %s.\n", __func__);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004544 return rval;
4545}
4546
4547int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004548qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
4549{
4550 int rval;
4551 struct qla_hw_data *ha = vha->hw;
4552 mbx_cmd_t mc;
4553 mbx_cmd_t *mcp = &mc;
4554
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004555 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
4556 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004557
Giridhar Malavalia9083012010-04-12 17:59:55 -07004558 if (!IS_FWI2_CAPABLE(ha))
4559 return QLA_FUNCTION_FAILED;
4560
Giridhar Malavalia9083012010-04-12 17:59:55 -07004561 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004562 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004563 mcp->mb[1] = 1;
4564
4565 mcp->out_mb = MBX_1|MBX_0;
4566 mcp->in_mb = MBX_0;
4567 mcp->tov = 30;
4568 mcp->flags = 0;
4569
4570 rval = qla2x00_mailbox_command(vha, mcp);
4571 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004572 ql_dbg(ql_dbg_mbx, vha, 0x1016,
4573 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004574 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004575 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
4576 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004577 }
4578
4579 return rval;
4580}
4581
4582int
4583qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
4584{
4585 int rval;
4586 struct qla_hw_data *ha = vha->hw;
4587 mbx_cmd_t mc;
4588 mbx_cmd_t *mcp = &mc;
4589
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004590 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
4591 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004592
Giridhar Malavalia9083012010-04-12 17:59:55 -07004593 if (!IS_QLA82XX(ha))
4594 return QLA_FUNCTION_FAILED;
4595
Giridhar Malavalia9083012010-04-12 17:59:55 -07004596 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004597 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004598 mcp->mb[1] = 0;
4599
4600 mcp->out_mb = MBX_1|MBX_0;
4601 mcp->in_mb = MBX_0;
4602 mcp->tov = 30;
4603 mcp->flags = 0;
4604
4605 rval = qla2x00_mailbox_command(vha, mcp);
4606 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004607 ql_dbg(ql_dbg_mbx, vha, 0x100c,
4608 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004609 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004610 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
4611 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004612 }
4613
4614 return rval;
4615}
Giridhar Malavali08de2842011-08-16 11:31:44 -07004616
4617int
4618qla82xx_md_get_template_size(scsi_qla_host_t *vha)
4619{
4620 struct qla_hw_data *ha = vha->hw;
4621 mbx_cmd_t mc;
4622 mbx_cmd_t *mcp = &mc;
4623 int rval = QLA_FUNCTION_FAILED;
4624
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004625 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
4626 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004627
4628 memset(mcp->mb, 0 , sizeof(mcp->mb));
4629 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4630 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4631 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
4632 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
4633
4634 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4635 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
4636 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4637
4638 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4639 mcp->tov = MBX_TOV_SECONDS;
4640 rval = qla2x00_mailbox_command(vha, mcp);
4641
4642 /* Always copy back return mailbox values. */
4643 if (rval != QLA_SUCCESS) {
4644 ql_dbg(ql_dbg_mbx, vha, 0x1120,
4645 "mailbox command FAILED=0x%x, subcode=%x.\n",
4646 (mcp->mb[1] << 16) | mcp->mb[0],
4647 (mcp->mb[3] << 16) | mcp->mb[2]);
4648 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004649 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
4650 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004651 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
4652 if (!ha->md_template_size) {
4653 ql_dbg(ql_dbg_mbx, vha, 0x1122,
4654 "Null template size obtained.\n");
4655 rval = QLA_FUNCTION_FAILED;
4656 }
4657 }
4658 return rval;
4659}
4660
4661int
4662qla82xx_md_get_template(scsi_qla_host_t *vha)
4663{
4664 struct qla_hw_data *ha = vha->hw;
4665 mbx_cmd_t mc;
4666 mbx_cmd_t *mcp = &mc;
4667 int rval = QLA_FUNCTION_FAILED;
4668
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004669 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
4670 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004671
4672 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
4673 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
4674 if (!ha->md_tmplt_hdr) {
4675 ql_log(ql_log_warn, vha, 0x1124,
4676 "Unable to allocate memory for Minidump template.\n");
4677 return rval;
4678 }
4679
4680 memset(mcp->mb, 0 , sizeof(mcp->mb));
4681 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4682 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4683 mcp->mb[2] = LSW(RQST_TMPLT);
4684 mcp->mb[3] = MSW(RQST_TMPLT);
4685 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
4686 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
4687 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
4688 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
4689 mcp->mb[8] = LSW(ha->md_template_size);
4690 mcp->mb[9] = MSW(ha->md_template_size);
4691
4692 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4693 mcp->tov = MBX_TOV_SECONDS;
4694 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
4695 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4696 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4697 rval = qla2x00_mailbox_command(vha, mcp);
4698
4699 if (rval != QLA_SUCCESS) {
4700 ql_dbg(ql_dbg_mbx, vha, 0x1125,
4701 "mailbox command FAILED=0x%x, subcode=%x.\n",
4702 ((mcp->mb[1] << 16) | mcp->mb[0]),
4703 ((mcp->mb[3] << 16) | mcp->mb[2]));
4704 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004705 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
4706 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004707 return rval;
4708}
Saurav Kashyap999916d2011-08-16 11:31:45 -07004709
4710int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004711qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
4712{
4713 int rval;
4714 struct qla_hw_data *ha = vha->hw;
4715 mbx_cmd_t mc;
4716 mbx_cmd_t *mcp = &mc;
4717
4718 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
4719 return QLA_FUNCTION_FAILED;
4720
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004721 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
4722 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004723
4724 memset(mcp, 0, sizeof(mbx_cmd_t));
4725 mcp->mb[0] = MBC_SET_LED_CONFIG;
4726 mcp->mb[1] = led_cfg[0];
4727 mcp->mb[2] = led_cfg[1];
4728 if (IS_QLA8031(ha)) {
4729 mcp->mb[3] = led_cfg[2];
4730 mcp->mb[4] = led_cfg[3];
4731 mcp->mb[5] = led_cfg[4];
4732 mcp->mb[6] = led_cfg[5];
4733 }
4734
4735 mcp->out_mb = MBX_2|MBX_1|MBX_0;
4736 if (IS_QLA8031(ha))
4737 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
4738 mcp->in_mb = MBX_0;
4739 mcp->tov = 30;
4740 mcp->flags = 0;
4741
4742 rval = qla2x00_mailbox_command(vha, mcp);
4743 if (rval != QLA_SUCCESS) {
4744 ql_dbg(ql_dbg_mbx, vha, 0x1134,
4745 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4746 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004747 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
4748 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004749 }
4750
4751 return rval;
4752}
4753
4754int
4755qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
4756{
4757 int rval;
4758 struct qla_hw_data *ha = vha->hw;
4759 mbx_cmd_t mc;
4760 mbx_cmd_t *mcp = &mc;
4761
4762 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
4763 return QLA_FUNCTION_FAILED;
4764
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004765 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
4766 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004767
4768 memset(mcp, 0, sizeof(mbx_cmd_t));
4769 mcp->mb[0] = MBC_GET_LED_CONFIG;
4770
4771 mcp->out_mb = MBX_0;
4772 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4773 if (IS_QLA8031(ha))
4774 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
4775 mcp->tov = 30;
4776 mcp->flags = 0;
4777
4778 rval = qla2x00_mailbox_command(vha, mcp);
4779 if (rval != QLA_SUCCESS) {
4780 ql_dbg(ql_dbg_mbx, vha, 0x1137,
4781 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4782 } else {
4783 led_cfg[0] = mcp->mb[1];
4784 led_cfg[1] = mcp->mb[2];
4785 if (IS_QLA8031(ha)) {
4786 led_cfg[2] = mcp->mb[3];
4787 led_cfg[3] = mcp->mb[4];
4788 led_cfg[4] = mcp->mb[5];
4789 led_cfg[5] = mcp->mb[6];
4790 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004791 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
4792 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004793 }
4794
4795 return rval;
4796}
4797
4798int
Saurav Kashyap999916d2011-08-16 11:31:45 -07004799qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
4800{
4801 int rval;
4802 struct qla_hw_data *ha = vha->hw;
4803 mbx_cmd_t mc;
4804 mbx_cmd_t *mcp = &mc;
4805
4806 if (!IS_QLA82XX(ha))
4807 return QLA_FUNCTION_FAILED;
4808
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07004810 "Entered %s.\n", __func__);
4811
4812 memset(mcp, 0, sizeof(mbx_cmd_t));
4813 mcp->mb[0] = MBC_SET_LED_CONFIG;
4814 if (enable)
4815 mcp->mb[7] = 0xE;
4816 else
4817 mcp->mb[7] = 0xD;
4818
4819 mcp->out_mb = MBX_7|MBX_0;
4820 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004821 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07004822 mcp->flags = 0;
4823
4824 rval = qla2x00_mailbox_command(vha, mcp);
4825 if (rval != QLA_SUCCESS) {
4826 ql_dbg(ql_dbg_mbx, vha, 0x1128,
4827 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4828 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07004830 "Done %s.\n", __func__);
4831 }
4832
4833 return rval;
4834}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004835
4836int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004837qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004838{
4839 int rval;
4840 struct qla_hw_data *ha = vha->hw;
4841 mbx_cmd_t mc;
4842 mbx_cmd_t *mcp = &mc;
4843
4844 if (!IS_QLA83XX(ha))
4845 return QLA_FUNCTION_FAILED;
4846
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004847 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
4848 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004849
4850 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
4851 mcp->mb[1] = LSW(reg);
4852 mcp->mb[2] = MSW(reg);
4853 mcp->mb[3] = LSW(data);
4854 mcp->mb[4] = MSW(data);
4855 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4856
4857 mcp->in_mb = MBX_1|MBX_0;
4858 mcp->tov = MBX_TOV_SECONDS;
4859 mcp->flags = 0;
4860 rval = qla2x00_mailbox_command(vha, mcp);
4861
4862 if (rval != QLA_SUCCESS) {
4863 ql_dbg(ql_dbg_mbx, vha, 0x1131,
4864 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4865 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004866 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004867 "Done %s.\n", __func__);
4868 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004869
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004870 return rval;
4871}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004872
4873int
4874qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
4875{
4876 int rval;
4877 struct qla_hw_data *ha = vha->hw;
4878 mbx_cmd_t mc;
4879 mbx_cmd_t *mcp = &mc;
4880
4881 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004882 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004883 "Implicit LOGO Unsupported.\n");
4884 return QLA_FUNCTION_FAILED;
4885 }
4886
4887
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004888 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
4889 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004890
4891 /* Perform Implicit LOGO. */
4892 mcp->mb[0] = MBC_PORT_LOGOUT;
4893 mcp->mb[1] = fcport->loop_id;
4894 mcp->mb[10] = BIT_15;
4895 mcp->out_mb = MBX_10|MBX_1|MBX_0;
4896 mcp->in_mb = MBX_0;
4897 mcp->tov = MBX_TOV_SECONDS;
4898 mcp->flags = 0;
4899 rval = qla2x00_mailbox_command(vha, mcp);
4900 if (rval != QLA_SUCCESS)
4901 ql_dbg(ql_dbg_mbx, vha, 0x113d,
4902 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4903 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
4905 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004906
4907 return rval;
4908}
4909
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004910int
4911qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
4912{
4913 int rval;
4914 mbx_cmd_t mc;
4915 mbx_cmd_t *mcp = &mc;
4916 struct qla_hw_data *ha = vha->hw;
4917 unsigned long retry_max_time = jiffies + (2 * HZ);
4918
4919 if (!IS_QLA83XX(ha))
4920 return QLA_FUNCTION_FAILED;
4921
4922 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
4923
4924retry_rd_reg:
4925 mcp->mb[0] = MBC_READ_REMOTE_REG;
4926 mcp->mb[1] = LSW(reg);
4927 mcp->mb[2] = MSW(reg);
4928 mcp->out_mb = MBX_2|MBX_1|MBX_0;
4929 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4930 mcp->tov = MBX_TOV_SECONDS;
4931 mcp->flags = 0;
4932 rval = qla2x00_mailbox_command(vha, mcp);
4933
4934 if (rval != QLA_SUCCESS) {
4935 ql_dbg(ql_dbg_mbx, vha, 0x114c,
4936 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4937 rval, mcp->mb[0], mcp->mb[1]);
4938 } else {
4939 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
4940 if (*data == QLA8XXX_BAD_VALUE) {
4941 /*
4942 * During soft-reset CAMRAM register reads might
4943 * return 0xbad0bad0. So retry for MAX of 2 sec
4944 * while reading camram registers.
4945 */
4946 if (time_after(jiffies, retry_max_time)) {
4947 ql_dbg(ql_dbg_mbx, vha, 0x1141,
4948 "Failure to read CAMRAM register. "
4949 "data=0x%x.\n", *data);
4950 return QLA_FUNCTION_FAILED;
4951 }
4952 msleep(100);
4953 goto retry_rd_reg;
4954 }
4955 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
4956 }
4957
4958 return rval;
4959}
4960
4961int
4962qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
4963{
4964 int rval;
4965 mbx_cmd_t mc;
4966 mbx_cmd_t *mcp = &mc;
4967 struct qla_hw_data *ha = vha->hw;
4968
4969 if (!IS_QLA83XX(ha))
4970 return QLA_FUNCTION_FAILED;
4971
4972 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
4973
4974 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
4975 mcp->out_mb = MBX_0;
4976 mcp->in_mb = MBX_1|MBX_0;
4977 mcp->tov = MBX_TOV_SECONDS;
4978 mcp->flags = 0;
4979 rval = qla2x00_mailbox_command(vha, mcp);
4980
4981 if (rval != QLA_SUCCESS) {
4982 ql_dbg(ql_dbg_mbx, vha, 0x1144,
4983 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4984 rval, mcp->mb[0], mcp->mb[1]);
4985 ha->isp_ops->fw_dump(vha, 0);
4986 } else {
4987 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
4988 }
4989
4990 return rval;
4991}
4992
4993int
4994qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
4995 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
4996{
4997 int rval;
4998 mbx_cmd_t mc;
4999 mbx_cmd_t *mcp = &mc;
5000 uint8_t subcode = (uint8_t)options;
5001 struct qla_hw_data *ha = vha->hw;
5002
5003 if (!IS_QLA8031(ha))
5004 return QLA_FUNCTION_FAILED;
5005
5006 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5007
5008 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5009 mcp->mb[1] = options;
5010 mcp->out_mb = MBX_1|MBX_0;
5011 if (subcode & BIT_2) {
5012 mcp->mb[2] = LSW(start_addr);
5013 mcp->mb[3] = MSW(start_addr);
5014 mcp->mb[4] = LSW(end_addr);
5015 mcp->mb[5] = MSW(end_addr);
5016 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5017 }
5018 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5019 if (!(subcode & (BIT_2 | BIT_5)))
5020 mcp->in_mb |= MBX_4|MBX_3;
5021 mcp->tov = MBX_TOV_SECONDS;
5022 mcp->flags = 0;
5023 rval = qla2x00_mailbox_command(vha, mcp);
5024
5025 if (rval != QLA_SUCCESS) {
5026 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5027 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5028 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5029 mcp->mb[4]);
5030 ha->isp_ops->fw_dump(vha, 0);
5031 } else {
5032 if (subcode & BIT_5)
5033 *sector_size = mcp->mb[1];
5034 else if (subcode & (BIT_6 | BIT_7)) {
5035 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5036 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5037 } else if (subcode & (BIT_3 | BIT_4)) {
5038 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5039 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5040 }
5041 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5042 }
5043
5044 return rval;
5045}
Saurav Kashyap81178772012-08-22 14:21:04 -04005046
5047int
5048qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5049 uint32_t size)
5050{
5051 int rval;
5052 mbx_cmd_t mc;
5053 mbx_cmd_t *mcp = &mc;
5054
5055 if (!IS_MCTP_CAPABLE(vha->hw))
5056 return QLA_FUNCTION_FAILED;
5057
5058 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5059 "Entered %s.\n", __func__);
5060
5061 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5062 mcp->mb[1] = LSW(addr);
5063 mcp->mb[2] = MSW(req_dma);
5064 mcp->mb[3] = LSW(req_dma);
5065 mcp->mb[4] = MSW(size);
5066 mcp->mb[5] = LSW(size);
5067 mcp->mb[6] = MSW(MSD(req_dma));
5068 mcp->mb[7] = LSW(MSD(req_dma));
5069 mcp->mb[8] = MSW(addr);
5070 /* Setting RAM ID to valid */
5071 mcp->mb[10] |= BIT_7;
5072 /* For MCTP RAM ID is 0x40 */
5073 mcp->mb[10] |= 0x40;
5074
5075 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5076 MBX_0;
5077
5078 mcp->in_mb = MBX_0;
5079 mcp->tov = MBX_TOV_SECONDS;
5080 mcp->flags = 0;
5081 rval = qla2x00_mailbox_command(vha, mcp);
5082
5083 if (rval != QLA_SUCCESS) {
5084 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5085 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5086 } else {
5087 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5088 "Done %s.\n", __func__);
5089 }
5090
5091 return rval;
5092}