blob: fe7b87d4ed86cc706d4492290b27ee23e9e0abda [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 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;
Chad Dupuisf73cb692014-02-26 04:15:06 -050038 device_reg_t *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
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -040078 if (IS_P3P_TYPE(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. */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400109 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700110 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400111 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(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
Joe Carnuccio7b711622014-09-25 05:16:43 -0400120 ql_dbg(ql_dbg_mbx, vha, 0x1111,
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700121 "Mailbox registers (OUT):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
123 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700124 optr =
125 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700126 if (mboxes & BIT_0) {
127 ql_dbg(ql_dbg_mbx, vha, 0x1112,
128 "mbox[%d]<-0x%04x\n", cnt, *iptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 WRT_REG_WORD(optr, *iptr);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700130 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 mboxes >>= 1;
133 optr++;
134 iptr++;
135 }
136
Arun Easi5e19ed92012-02-09 11:15:51 -0800137 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700138 "I/O Address = %p.\n", optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* Issue set host interrupt command to send cmd out. */
141 ha->flags.mbox_int = 0;
142 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
143
144 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800145 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700146 "Going to unlock irq & waiting for interrupts. "
147 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* Wait for mbx cmd completion until timeout */
150
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800151 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
153
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400154 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700155 if (RD_REG_DWORD(&reg->isp82.hint) &
156 HINT_MBX_INT_PENDING) {
157 spin_unlock_irqrestore(&ha->hardware_lock,
158 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800159 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800160 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700162 rval = QLA_FUNCTION_TIMEOUT;
163 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700164 }
165 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
166 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700167 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
168 else
169 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 spin_unlock_irqrestore(&ha->hardware_lock, flags);
171
Giridhar Malavali754d1242013-06-25 11:27:16 -0400172 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
173 mcp->tov * HZ)) {
174 ql_dbg(ql_dbg_mbx, vha, 0x117a,
175 "cmd=%x Timeout.\n", command);
176 spin_lock_irqsave(&ha->hardware_lock, flags);
177 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
179 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800181 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700182 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400184 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700185 if (RD_REG_DWORD(&reg->isp82.hint) &
186 HINT_MBX_INT_PENDING) {
187 spin_unlock_irqrestore(&ha->hardware_lock,
188 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800189 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800190 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700191 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700192 rval = QLA_FUNCTION_TIMEOUT;
193 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700194 }
195 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
196 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700197 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
198 else
199 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
203 while (!ha->flags.mbox_int) {
204 if (time_after(jiffies, wait_time))
205 break;
206
207 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800208 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Andrew Vasquez85880802009-12-15 21:29:46 -0800210 if (!ha->flags.mbox_int &&
211 !(IS_QLA2200(ha) &&
212 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800213 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800215 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700216 "Waited %d sec.\n",
217 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 }
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 /* Check whether we timed out */
221 if (ha->flags.mbox_int) {
222 uint16_t *iptr2;
223
Arun Easi5e19ed92012-02-09 11:15:51 -0800224 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700225 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227 /* Got interrupt. Clear the flag. */
228 ha->flags.mbox_int = 0;
229 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
230
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400231 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700232 ha->flags.mbox_busy = 0;
233 /* Setting Link-Down error */
234 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
235 ha->mcp = NULL;
236 rval = QLA_FUNCTION_FAILED;
Arun Easi5e19ed92012-02-09 11:15:51 -0800237 ql_log(ql_log_warn, vha, 0x1015,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700238 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700239 goto premature_exit;
240 }
241
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400242 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245 /* Load return mailbox registers. */
246 iptr2 = mcp->mb;
247 iptr = (uint16_t *)&ha->mailbox_out[0];
248 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700249
250 ql_dbg(ql_dbg_mbx, vha, 0x1113,
251 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700253 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700255 ql_dbg(ql_dbg_mbx, vha, 0x1114,
256 "mbox[%d]->0x%04x\n", cnt, *iptr2);
257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
259 mboxes >>= 1;
260 iptr2++;
261 iptr++;
262 }
263 } else {
264
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700265 uint16_t mb0;
266 uint32_t ictrl;
267
Andrew Vasqueze4289242007-07-19 15:05:56 -0700268 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700269 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
270 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
271 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700272 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700273 ictrl = RD_REG_WORD(&reg->isp.ictrl);
274 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800275 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400276 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
277 "mb[0]=0x%x\n", command, ictrl, jiffies, mb0);
Arun Easi5e19ed92012-02-09 11:15:51 -0800278 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800280 /*
281 * Attempt to capture a firmware dump for further analysis
Chad Dupuisb8eb4132013-06-25 11:27:20 -0400282 * of the current firmware state. We do not need to do this
283 * if we are intentionally generating a dump.
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800284 */
Chad Dupuisb8eb4132013-06-25 11:27:20 -0400285 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
286 ha->isp_ops->fw_dump(vha, 0);
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 rval = QLA_FUNCTION_TIMEOUT;
289 }
290
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 ha->flags.mbox_busy = 0;
292
293 /* Clean up */
294 ha->mcp = NULL;
295
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800296 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800297 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700298 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800301 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700304 if (rval == QLA_FUNCTION_TIMEOUT &&
305 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800306 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
307 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800309 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700310 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700311
312 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
313 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
314 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800315 if (IS_QLA82XX(ha)) {
316 ql_dbg(ql_dbg_mbx, vha, 0x112a,
317 "disabling pause transmit on port "
318 "0 & 1.\n");
319 qla82xx_wr_32(ha,
320 QLA82XX_CRB_NIU + 0x98,
321 CRB_NIU_XG_PAUSE_CTL_P0|
322 CRB_NIU_XG_PAUSE_CTL_P1);
323 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700324 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400325 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800326 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
327 "abort.\n", command, mcp->mb[0],
328 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700329 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
330 qla2xxx_wake_dpc(vha);
331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800334 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700335 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700337 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
338 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
339 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800340 if (IS_QLA82XX(ha)) {
341 ql_dbg(ql_dbg_mbx, vha, 0x112b,
342 "disabling pause transmit on port "
343 "0 & 1.\n");
344 qla82xx_wr_32(ha,
345 QLA82XX_CRB_NIU + 0x98,
346 CRB_NIU_XG_PAUSE_CTL_P0|
347 CRB_NIU_XG_PAUSE_CTL_P1);
348 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700349 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400350 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800351 "mb[0]=0x%x. Scheduling ISP abort ",
352 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700353 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
354 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800355 /* Allow next mbx cmd to come in. */
356 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700357 if (ha->isp_ops->abort_isp(vha)) {
358 /* Failed. retry later. */
359 set_bit(ISP_ABORT_NEEDED,
360 &vha->dpc_flags);
361 }
362 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800363 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700364 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800365 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 }
368 }
369
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700370premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800372 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Giridhar Malavalid3360962012-02-09 11:14:10 -0800374mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 if (rval) {
Chad Dupuis34c58012014-08-08 07:38:08 -0400376 ql_dbg(ql_dbg_disc, base_vha, 0x1020,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800377 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
378 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700380 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 return rval;
384}
385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800387qla2x00_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 -0800388 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389{
390 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800391 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 mbx_cmd_t mc;
393 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400395 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
396 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Andrew Vasqueze4289242007-07-19 15:05:56 -0700398 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800399 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
400 mcp->mb[8] = MSW(risc_addr);
401 mcp->out_mb = MBX_8|MBX_0;
402 } else {
403 mcp->mb[0] = MBC_LOAD_RISC_RAM;
404 mcp->out_mb = MBX_0;
405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 mcp->mb[1] = LSW(risc_addr);
407 mcp->mb[2] = MSW(req_dma);
408 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 mcp->mb[6] = MSW(MSD(req_dma));
410 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800411 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700412 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700413 mcp->mb[4] = MSW(risc_code_size);
414 mcp->mb[5] = LSW(risc_code_size);
415 mcp->out_mb |= MBX_5|MBX_4;
416 } else {
417 mcp->mb[4] = LSW(risc_code_size);
418 mcp->out_mb |= MBX_4;
419 }
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700422 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800424 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700427 ql_dbg(ql_dbg_mbx, vha, 0x1023,
428 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400430 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
431 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
434 return rval;
435}
436
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700437#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438/*
439 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700440 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 *
442 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700443 * ha = adapter block pointer.
444 * TARGET_QUEUE_LOCK must be released.
445 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *
447 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700448 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 *
450 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700451 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 */
453int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800454qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
456 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800457 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 mbx_cmd_t mc;
459 mbx_cmd_t *mcp = &mc;
460
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400461 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
462 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700465 mcp->out_mb = MBX_0;
466 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700467 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700468 mcp->mb[1] = MSW(risc_addr);
469 mcp->mb[2] = LSW(risc_addr);
470 mcp->mb[3] = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500471 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
472 IS_QLA27XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700473 struct nvram_81xx *nv = ha->nvram;
474 mcp->mb[4] = (nv->enhanced_features &
475 EXTENDED_BB_CREDITS);
476 } else
477 mcp->mb[4] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700478 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700479 mcp->in_mb |= MBX_1;
480 } else {
481 mcp->mb[1] = LSW(risc_addr);
482 mcp->out_mb |= MBX_1;
483 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
484 mcp->mb[2] = 0;
485 mcp->out_mb |= MBX_2;
486 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488
Ravi Anandb93480e2008-04-03 13:13:25 -0700489 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800491 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700493 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700494 ql_dbg(ql_dbg_mbx, vha, 0x1026,
495 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700496 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700497 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400498 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700499 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700500 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400501 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
502 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700503 }
504 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506 return rval;
507}
508
509/*
510 * qla2x00_get_fw_version
511 * Get firmware version.
512 *
513 * Input:
514 * ha: adapter state pointer.
515 * major: pointer for major number.
516 * minor: pointer for minor number.
517 * subminor: pointer for subminor number.
518 *
519 * Returns:
520 * qla2x00 local function return status code.
521 *
522 * Context:
523 * Kernel context.
524 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700525int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800526qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 int rval;
529 mbx_cmd_t mc;
530 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800531 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
534 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
537 mcp->out_mb = MBX_0;
538 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400539 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700540 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400541 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800542 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500543 if (IS_QLA27XX(ha))
544 mcp->in_mb |= MBX_21|MBX_20|MBX_19|MBX_18;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700546 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800547 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700548 if (rval != QLA_SUCCESS)
549 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800552 ha->fw_major_version = mcp->mb[1];
553 ha->fw_minor_version = mcp->mb[2];
554 ha->fw_subminor_version = mcp->mb[3];
555 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800556 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800557 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800559 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400560 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800561 ha->mpi_version[0] = mcp->mb[10] & 0xff;
562 ha->mpi_version[1] = mcp->mb[11] >> 8;
563 ha->mpi_version[2] = mcp->mb[11] & 0xff;
564 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
565 ha->phy_version[0] = mcp->mb[8] & 0xff;
566 ha->phy_version[1] = mcp->mb[9] >> 8;
567 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800568 }
Saurav Kashyap81178772012-08-22 14:21:04 -0400569 if (IS_FWI2_CAPABLE(ha)) {
570 ha->fw_attributes_h = mcp->mb[15];
571 ha->fw_attributes_ext[0] = mcp->mb[16];
572 ha->fw_attributes_ext[1] = mcp->mb[17];
573 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
574 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
575 __func__, mcp->mb[15], mcp->mb[6]);
576 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
577 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
578 __func__, mcp->mb[17], mcp->mb[16]);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800579 }
Chad Dupuisf73cb692014-02-26 04:15:06 -0500580 if (IS_QLA27XX(ha)) {
581 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
582 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
583 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800584
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700585failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 if (rval != QLA_SUCCESS) {
587 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700588 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 } else {
590 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400591 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
592 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700594 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595}
596
597/*
598 * qla2x00_get_fw_options
599 * Set firmware options.
600 *
601 * Input:
602 * ha = adapter block pointer.
603 * fwopt = pointer for firmware options.
604 *
605 * Returns:
606 * qla2x00 local function return status code.
607 *
608 * Context:
609 * Kernel context.
610 */
611int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800612qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613{
614 int rval;
615 mbx_cmd_t mc;
616 mbx_cmd_t *mcp = &mc;
617
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400618 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
619 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
621 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
622 mcp->out_mb = MBX_0;
623 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700624 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800626 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 if (rval != QLA_SUCCESS) {
629 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700630 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700632 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 fwopts[1] = mcp->mb[1];
634 fwopts[2] = mcp->mb[2];
635 fwopts[3] = mcp->mb[3];
636
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400637 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
638 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640
641 return rval;
642}
643
644
645/*
646 * qla2x00_set_fw_options
647 * Set firmware options.
648 *
649 * Input:
650 * ha = adapter block pointer.
651 * fwopt = pointer for firmware options.
652 *
653 * Returns:
654 * qla2x00 local function return status code.
655 *
656 * Context:
657 * Kernel context.
658 */
659int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800660qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661{
662 int rval;
663 mbx_cmd_t mc;
664 mbx_cmd_t *mcp = &mc;
665
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400666 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
667 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
670 mcp->mb[1] = fwopts[1];
671 mcp->mb[2] = fwopts[2];
672 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700673 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800675 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700676 mcp->in_mb |= MBX_1;
677 } else {
678 mcp->mb[10] = fwopts[10];
679 mcp->mb[11] = fwopts[11];
680 mcp->mb[12] = 0; /* Undocumented, but used */
681 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
682 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700683 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800685 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700687 fwopts[0] = mcp->mb[0];
688
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 if (rval != QLA_SUCCESS) {
690 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700691 ql_dbg(ql_dbg_mbx, vha, 0x1030,
692 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 } else {
694 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400695 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
696 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 }
698
699 return rval;
700}
701
702/*
703 * qla2x00_mbx_reg_test
704 * Mailbox register wrap test.
705 *
706 * Input:
707 * ha = adapter block pointer.
708 * TARGET_QUEUE_LOCK must be released.
709 * ADAPTER_STATE_LOCK must be released.
710 *
711 * Returns:
712 * qla2x00 local function return status code.
713 *
714 * Context:
715 * Kernel context.
716 */
717int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800718qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719{
720 int rval;
721 mbx_cmd_t mc;
722 mbx_cmd_t *mcp = &mc;
723
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400724 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
725 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
727 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
728 mcp->mb[1] = 0xAAAA;
729 mcp->mb[2] = 0x5555;
730 mcp->mb[3] = 0xAA55;
731 mcp->mb[4] = 0x55AA;
732 mcp->mb[5] = 0xA5A5;
733 mcp->mb[6] = 0x5A5A;
734 mcp->mb[7] = 0x2525;
735 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
736 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 -0700737 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800739 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740
741 if (rval == QLA_SUCCESS) {
742 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
743 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
744 rval = QLA_FUNCTION_FAILED;
745 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
746 mcp->mb[7] != 0x2525)
747 rval = QLA_FUNCTION_FAILED;
748 }
749
750 if (rval != QLA_SUCCESS) {
751 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700752 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 } else {
754 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400755 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
756 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 }
758
759 return rval;
760}
761
762/*
763 * qla2x00_verify_checksum
764 * Verify firmware checksum.
765 *
766 * Input:
767 * ha = adapter block pointer.
768 * TARGET_QUEUE_LOCK must be released.
769 * ADAPTER_STATE_LOCK must be released.
770 *
771 * Returns:
772 * qla2x00 local function return status code.
773 *
774 * Context:
775 * Kernel context.
776 */
777int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800778qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 int rval;
781 mbx_cmd_t mc;
782 mbx_cmd_t *mcp = &mc;
783
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400784 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
785 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700788 mcp->out_mb = MBX_0;
789 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800790 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700791 mcp->mb[1] = MSW(risc_addr);
792 mcp->mb[2] = LSW(risc_addr);
793 mcp->out_mb |= MBX_2|MBX_1;
794 mcp->in_mb |= MBX_2|MBX_1;
795 } else {
796 mcp->mb[1] = LSW(risc_addr);
797 mcp->out_mb |= MBX_1;
798 mcp->in_mb |= MBX_1;
799 }
800
Ravi Anandb93480e2008-04-03 13:13:25 -0700801 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800803 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700806 ql_dbg(ql_dbg_mbx, vha, 0x1036,
807 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
808 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400810 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
811 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813
814 return rval;
815}
816
817/*
818 * qla2x00_issue_iocb
819 * Issue IOCB using mailbox command
820 *
821 * Input:
822 * ha = adapter state pointer.
823 * buffer = buffer pointer.
824 * phys_addr = physical address of buffer.
825 * size = size of buffer.
826 * TARGET_QUEUE_LOCK must be released.
827 * ADAPTER_STATE_LOCK must be released.
828 *
829 * Returns:
830 * qla2x00 local function return status code.
831 *
832 * Context:
833 * Kernel context.
834 */
Giridhar Malavali6e980162010-03-19 17:03:58 -0700835int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800836qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700837 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838{
839 int rval;
840 mbx_cmd_t mc;
841 mbx_cmd_t *mcp = &mc;
842
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400843 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
844 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700845
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
847 mcp->mb[1] = 0;
848 mcp->mb[2] = MSW(phys_addr);
849 mcp->mb[3] = LSW(phys_addr);
850 mcp->mb[6] = MSW(MSD(phys_addr));
851 mcp->mb[7] = LSW(MSD(phys_addr));
852 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
853 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700854 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800856 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
858 if (rval != QLA_SUCCESS) {
859 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700860 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700862 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
863
864 /* Mask reserved bits. */
865 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800866 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400867 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
868 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 }
870
871 return rval;
872}
873
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700874int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800875qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700876 size_t size)
877{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800878 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700879 MBX_TOV_SECONDS);
880}
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882/*
883 * qla2x00_abort_command
884 * Abort command aborts a specified IOCB.
885 *
886 * Input:
887 * ha = adapter block pointer.
888 * sp = SB structure pointer.
889 *
890 * Returns:
891 * qla2x00 local function return status code.
892 *
893 * Context:
894 * Kernel context.
895 */
896int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700897qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898{
899 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800901 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 mbx_cmd_t mc;
903 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700904 fc_port_t *fcport = sp->fcport;
905 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800906 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700907 struct req_que *req = vha->req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800908 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400910 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
911 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700913 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -0500914 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800915 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 break;
917 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700918 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Chad Dupuis8d93f552013-01-30 03:34:37 -0500920 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 /* command not found */
922 return QLA_FUNCTION_FAILED;
923 }
924
925 mcp->mb[0] = MBC_ABORT_COMMAND;
926 if (HAS_EXTENDED_IDS(ha))
927 mcp->mb[1] = fcport->loop_id;
928 else
929 mcp->mb[1] = fcport->loop_id << 8;
930 mcp->mb[2] = (uint16_t)handle;
931 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800932 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
934 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700935 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800937 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700940 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400942 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
943 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
945
946 return rval;
947}
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +0200950qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700952 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 mbx_cmd_t mc;
954 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800955 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800956 struct req_que *req;
957 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Andrew Vasquez523ec772008-04-03 13:13:24 -0700959 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800960 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700961
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400962 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
963 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700964
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700965 req = vha->hw->req_q_map[0];
966 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700968 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800969 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 mcp->mb[1] = fcport->loop_id;
971 mcp->mb[10] = 0;
972 mcp->out_mb |= MBX_10;
973 } else {
974 mcp->mb[1] = fcport->loop_id << 8;
975 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800976 mcp->mb[2] = vha->hw->loop_reset_delay;
977 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
979 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700980 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800982 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400984 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
985 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986 }
987
988 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800989 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
990 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700991 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700992 ql_dbg(ql_dbg_mbx, vha, 0x1040,
993 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400995 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
996 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700997 }
998
999 return rval;
1000}
1001
1002int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001003qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001004{
1005 int rval, rval2;
1006 mbx_cmd_t mc;
1007 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001008 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001009 struct req_que *req;
1010 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001011
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001012 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001013
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001014 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1015 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001016
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001017 req = vha->hw->req_q_map[0];
1018 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001019 mcp->mb[0] = MBC_LUN_RESET;
1020 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001021 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001022 mcp->mb[1] = fcport->loop_id;
1023 else
1024 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001025 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001026 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001027 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001028
1029 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001030 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001031 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001032 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001033 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001034 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001035 }
1036
1037 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001038 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1039 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001040 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001041 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1042 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001043 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001044 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1045 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047
1048 return rval;
1049}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
1051/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 * qla2x00_get_adapter_id
1053 * Get adapter ID and topology.
1054 *
1055 * Input:
1056 * ha = adapter block pointer.
1057 * id = pointer for loop ID.
1058 * al_pa = pointer for AL_PA.
1059 * area = pointer for area.
1060 * domain = pointer for domain.
1061 * top = pointer for topology.
1062 * TARGET_QUEUE_LOCK must be released.
1063 * ADAPTER_STATE_LOCK must be released.
1064 *
1065 * Returns:
1066 * qla2x00 local function return status code.
1067 *
1068 * Context:
1069 * Kernel context.
1070 */
1071int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001073 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 int rval;
1076 mbx_cmd_t mc;
1077 mbx_cmd_t *mcp = &mc;
1078
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001079 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1080 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001083 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001084 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001085 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001086 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001087 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001088 if (IS_FWI2_CAPABLE(vha->hw))
1089 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Ravi Anandb93480e2008-04-03 13:13:25 -07001090 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001092 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001093 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1094 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001095 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1096 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098 /* Return data. */
1099 *id = mcp->mb[1];
1100 *al_pa = LSB(mcp->mb[2]);
1101 *area = MSB(mcp->mb[2]);
1102 *domain = LSB(mcp->mb[3]);
1103 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001104 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 if (rval != QLA_SUCCESS) {
1107 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001108 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001110 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1111 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001112
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001113 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001114 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1115 vha->fcoe_fcf_idx = mcp->mb[10];
1116 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1117 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1118 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1119 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1120 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1121 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1122 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001123 /* If FA-WWN supported */
1124 if (mcp->mb[7] & BIT_14) {
1125 vha->port_name[0] = MSB(mcp->mb[16]);
1126 vha->port_name[1] = LSB(mcp->mb[16]);
1127 vha->port_name[2] = MSB(mcp->mb[17]);
1128 vha->port_name[3] = LSB(mcp->mb[17]);
1129 vha->port_name[4] = MSB(mcp->mb[18]);
1130 vha->port_name[5] = LSB(mcp->mb[18]);
1131 vha->port_name[6] = MSB(mcp->mb[19]);
1132 vha->port_name[7] = LSB(mcp->mb[19]);
1133 fc_host_port_name(vha->host) =
1134 wwn_to_u64(vha->port_name);
1135 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1136 "FA-WWN acquired %016llx\n",
1137 wwn_to_u64(vha->port_name));
1138 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
1140
1141 return rval;
1142}
1143
1144/*
1145 * qla2x00_get_retry_cnt
1146 * Get current firmware login retry count and delay.
1147 *
1148 * Input:
1149 * ha = adapter block pointer.
1150 * retry_cnt = pointer to login retry count.
1151 * tov = pointer to login timeout value.
1152 *
1153 * Returns:
1154 * qla2x00 local function return status code.
1155 *
1156 * Context:
1157 * Kernel context.
1158 */
1159int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001160qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 uint16_t *r_a_tov)
1162{
1163 int rval;
1164 uint16_t ratov;
1165 mbx_cmd_t mc;
1166 mbx_cmd_t *mcp = &mc;
1167
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1169 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1172 mcp->out_mb = MBX_0;
1173 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001174 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001176 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 if (rval != QLA_SUCCESS) {
1179 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001180 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1181 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 } else {
1183 /* Convert returned data and check our values. */
1184 *r_a_tov = mcp->mb[3] / 2;
1185 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1186 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1187 /* Update to the larger values */
1188 *retry_cnt = (uint8_t)mcp->mb[1];
1189 *tov = ratov;
1190 }
1191
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001192 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001193 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 }
1195
1196 return rval;
1197}
1198
1199/*
1200 * qla2x00_init_firmware
1201 * Initialize adapter firmware.
1202 *
1203 * Input:
1204 * ha = adapter block pointer.
1205 * dptr = Initialization control block pointer.
1206 * size = size of initialization control block.
1207 * TARGET_QUEUE_LOCK must be released.
1208 * ADAPTER_STATE_LOCK must be released.
1209 *
1210 * Returns:
1211 * qla2x00 local function return status code.
1212 *
1213 * Context:
1214 * Kernel context.
1215 */
1216int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001217qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
1219 int rval;
1220 mbx_cmd_t mc;
1221 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001222 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001224 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1225 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001227 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Giridhar Malavalia9083012010-04-12 17:59:55 -07001228 qla82xx_wr_32(ha, ha->nxdb_wr_ptr,
1229 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1230
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001231 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001232 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1233 else
1234 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1235
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001236 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 mcp->mb[2] = MSW(ha->init_cb_dma);
1238 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1240 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001241 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001242 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001243 mcp->mb[1] = BIT_0;
1244 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1245 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1246 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1247 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1248 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1249 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1250 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001251 /* 1 and 2 should normally be captured. */
1252 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001253 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001254 /* mb3 is additional info about the installed SFP. */
1255 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 mcp->buf_size = size;
1257 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001258 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001259 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 if (rval != QLA_SUCCESS) {
1262 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001263 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001264 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1265 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 } else {
1267 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001268 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1269 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 }
1271
1272 return rval;
1273}
1274
1275/*
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001276 * qla2x00_get_node_name_list
1277 * Issue get node name list mailbox command, kmalloc()
1278 * and return the resulting list. Caller must kfree() it!
1279 *
1280 * Input:
1281 * ha = adapter state pointer.
1282 * out_data = resulting list
1283 * out_len = length of the resulting list
1284 *
1285 * Returns:
1286 * qla2x00 local function return status code.
1287 *
1288 * Context:
1289 * Kernel context.
1290 */
1291int
1292qla2x00_get_node_name_list(scsi_qla_host_t *vha, void **out_data, int *out_len)
1293{
1294 struct qla_hw_data *ha = vha->hw;
1295 struct qla_port_24xx_data *list = NULL;
1296 void *pmap;
1297 mbx_cmd_t mc;
1298 dma_addr_t pmap_dma;
1299 ulong dma_size;
1300 int rval, left;
1301
1302 left = 1;
1303 while (left > 0) {
1304 dma_size = left * sizeof(*list);
1305 pmap = dma_alloc_coherent(&ha->pdev->dev, dma_size,
1306 &pmap_dma, GFP_KERNEL);
1307 if (!pmap) {
1308 ql_log(ql_log_warn, vha, 0x113f,
1309 "%s(%ld): DMA Alloc failed of %ld\n",
1310 __func__, vha->host_no, dma_size);
1311 rval = QLA_MEMORY_ALLOC_FAILED;
1312 goto out;
1313 }
1314
1315 mc.mb[0] = MBC_PORT_NODE_NAME_LIST;
1316 mc.mb[1] = BIT_1 | BIT_3;
1317 mc.mb[2] = MSW(pmap_dma);
1318 mc.mb[3] = LSW(pmap_dma);
1319 mc.mb[6] = MSW(MSD(pmap_dma));
1320 mc.mb[7] = LSW(MSD(pmap_dma));
1321 mc.mb[8] = dma_size;
1322 mc.out_mb = MBX_0|MBX_1|MBX_2|MBX_3|MBX_6|MBX_7|MBX_8;
1323 mc.in_mb = MBX_0|MBX_1;
1324 mc.tov = 30;
1325 mc.flags = MBX_DMA_IN;
1326
1327 rval = qla2x00_mailbox_command(vha, &mc);
1328 if (rval != QLA_SUCCESS) {
1329 if ((mc.mb[0] == MBS_COMMAND_ERROR) &&
1330 (mc.mb[1] == 0xA)) {
1331 left += le16_to_cpu(mc.mb[2]) /
1332 sizeof(struct qla_port_24xx_data);
1333 goto restart;
1334 }
1335 goto out_free;
1336 }
1337
1338 left = 0;
1339
Benoit Tainec1818f12014-05-26 17:21:16 +02001340 list = kmemdup(pmap, dma_size, GFP_KERNEL);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001341 if (!list) {
1342 ql_log(ql_log_warn, vha, 0x1140,
1343 "%s(%ld): failed to allocate node names list "
1344 "structure.\n", __func__, vha->host_no);
1345 rval = QLA_MEMORY_ALLOC_FAILED;
1346 goto out_free;
1347 }
1348
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001349restart:
1350 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1351 }
1352
1353 *out_data = list;
1354 *out_len = dma_size;
1355
1356out:
1357 return rval;
1358
1359out_free:
1360 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1361 return rval;
1362}
1363
1364/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 * qla2x00_get_port_database
1366 * Issue normal/enhanced get port database mailbox command
1367 * and copy device name as necessary.
1368 *
1369 * Input:
1370 * ha = adapter state pointer.
1371 * dev = structure pointer.
1372 * opt = enhanced cmd option byte.
1373 *
1374 * Returns:
1375 * qla2x00 local function return status code.
1376 *
1377 * Context:
1378 * Kernel context.
1379 */
1380int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001381qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382{
1383 int rval;
1384 mbx_cmd_t mc;
1385 mbx_cmd_t *mcp = &mc;
1386 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001387 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001389 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1392 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001394 pd24 = NULL;
1395 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001397 ql_log(ql_log_warn, vha, 0x1050,
1398 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 return QLA_MEMORY_ALLOC_FAILED;
1400 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001401 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001403 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001404 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 mcp->mb[2] = MSW(pd_dma);
1407 mcp->mb[3] = LSW(pd_dma);
1408 mcp->mb[6] = MSW(MSD(pd_dma));
1409 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001410 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001411 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001413 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001414 mcp->mb[1] = fcport->loop_id;
1415 mcp->mb[10] = opt;
1416 mcp->out_mb |= MBX_10|MBX_1;
1417 mcp->in_mb |= MBX_1;
1418 } else if (HAS_EXTENDED_IDS(ha)) {
1419 mcp->mb[1] = fcport->loop_id;
1420 mcp->mb[10] = opt;
1421 mcp->out_mb |= MBX_10|MBX_1;
1422 } else {
1423 mcp->mb[1] = fcport->loop_id << 8 | opt;
1424 mcp->out_mb |= MBX_1;
1425 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001426 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1427 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 mcp->flags = MBX_DMA_IN;
1429 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001430 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 if (rval != QLA_SUCCESS)
1432 goto gpd_error_out;
1433
Andrew Vasqueze4289242007-07-19 15:05:56 -07001434 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001435 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001436 pd24 = (struct port_database_24xx *) pd;
1437
1438 /* Check for logged in state. */
1439 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1440 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001441 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1442 "Unable to verify login-state (%x/%x) for "
1443 "loop_id %x.\n", pd24->current_login_state,
1444 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001445 rval = QLA_FUNCTION_FAILED;
1446 goto gpd_error_out;
1447 }
1448
Arun Easi0eba25d2012-02-09 11:15:58 -08001449 if (fcport->loop_id == FC_NO_LOOP_ID ||
1450 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1451 memcmp(fcport->port_name, pd24->port_name, 8))) {
1452 /* We lost the device mid way. */
1453 rval = QLA_NOT_LOGGED_IN;
1454 goto gpd_error_out;
1455 }
1456
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001457 /* Names are little-endian. */
1458 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1459 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1460
1461 /* Get port_id of device. */
1462 fcport->d_id.b.domain = pd24->port_id[0];
1463 fcport->d_id.b.area = pd24->port_id[1];
1464 fcport->d_id.b.al_pa = pd24->port_id[2];
1465 fcport->d_id.b.rsvd_1 = 0;
1466
1467 /* If not target must be initiator or unknown type. */
1468 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1469 fcport->port_type = FCT_INITIATOR;
1470 else
1471 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001472
1473 /* Passback COS information. */
1474 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1475 FC_COS_CLASS2 : FC_COS_CLASS3;
1476
1477 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1478 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001479 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001480 uint64_t zero = 0;
1481
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001482 /* Check for logged in state. */
1483 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1484 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001485 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1486 "Unable to verify login-state (%x/%x) - "
1487 "portid=%02x%02x%02x.\n", pd->master_state,
1488 pd->slave_state, fcport->d_id.b.domain,
1489 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001490 rval = QLA_FUNCTION_FAILED;
1491 goto gpd_error_out;
1492 }
1493
Arun Easi0eba25d2012-02-09 11:15:58 -08001494 if (fcport->loop_id == FC_NO_LOOP_ID ||
1495 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1496 memcmp(fcport->port_name, pd->port_name, 8))) {
1497 /* We lost the device mid way. */
1498 rval = QLA_NOT_LOGGED_IN;
1499 goto gpd_error_out;
1500 }
1501
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001502 /* Names are little-endian. */
1503 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1504 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1505
1506 /* Get port_id of device. */
1507 fcport->d_id.b.domain = pd->port_id[0];
1508 fcport->d_id.b.area = pd->port_id[3];
1509 fcport->d_id.b.al_pa = pd->port_id[2];
1510 fcport->d_id.b.rsvd_1 = 0;
1511
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001512 /* If not target must be initiator or unknown type. */
1513 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1514 fcport->port_type = FCT_INITIATOR;
1515 else
1516 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001517
1518 /* Passback COS information. */
1519 fcport->supported_classes = (pd->options & BIT_4) ?
1520 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 }
1522
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523gpd_error_out:
1524 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1525
1526 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001527 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1528 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1529 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001531 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1532 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 }
1534
1535 return rval;
1536}
1537
1538/*
1539 * qla2x00_get_firmware_state
1540 * Get adapter firmware state.
1541 *
1542 * Input:
1543 * ha = adapter block pointer.
1544 * dptr = pointer for firmware state.
1545 * TARGET_QUEUE_LOCK must be released.
1546 * ADAPTER_STATE_LOCK must be released.
1547 *
1548 * Returns:
1549 * qla2x00 local function return status code.
1550 *
1551 * Context:
1552 * Kernel context.
1553 */
1554int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001555qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556{
1557 int rval;
1558 mbx_cmd_t mc;
1559 mbx_cmd_t *mcp = &mc;
1560
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001561 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1562 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1565 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001566 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001567 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001568 else
1569 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001570 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001572 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001574 /* Return firmware states. */
1575 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001576 if (IS_FWI2_CAPABLE(vha->hw)) {
1577 states[1] = mcp->mb[2];
1578 states[2] = mcp->mb[3];
1579 states[3] = mcp->mb[4];
1580 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001581 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001582 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 if (rval != QLA_SUCCESS) {
1585 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001586 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 } else {
1588 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001589 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1590 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 }
1592
1593 return rval;
1594}
1595
1596/*
1597 * qla2x00_get_port_name
1598 * Issue get port name mailbox command.
1599 * Returned name is in big endian format.
1600 *
1601 * Input:
1602 * ha = adapter block pointer.
1603 * loop_id = loop ID of device.
1604 * name = pointer for name.
1605 * TARGET_QUEUE_LOCK must be released.
1606 * ADAPTER_STATE_LOCK must be released.
1607 *
1608 * Returns:
1609 * qla2x00 local function return status code.
1610 *
1611 * Context:
1612 * Kernel context.
1613 */
1614int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001615qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 uint8_t opt)
1617{
1618 int rval;
1619 mbx_cmd_t mc;
1620 mbx_cmd_t *mcp = &mc;
1621
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001622 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1623 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
1625 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001626 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001627 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001628 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 mcp->mb[1] = loop_id;
1630 mcp->mb[10] = opt;
1631 mcp->out_mb |= MBX_10;
1632 } else {
1633 mcp->mb[1] = loop_id << 8 | opt;
1634 }
1635
1636 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001637 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001639 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 if (rval != QLA_SUCCESS) {
1642 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001643 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 } else {
1645 if (name != NULL) {
1646 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001647 name[0] = MSB(mcp->mb[2]);
1648 name[1] = LSB(mcp->mb[2]);
1649 name[2] = MSB(mcp->mb[3]);
1650 name[3] = LSB(mcp->mb[3]);
1651 name[4] = MSB(mcp->mb[6]);
1652 name[5] = LSB(mcp->mb[6]);
1653 name[6] = MSB(mcp->mb[7]);
1654 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
1656
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1658 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 }
1660
1661 return rval;
1662}
1663
1664/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001665 * qla24xx_link_initialization
1666 * Issue link initialization mailbox command.
1667 *
1668 * Input:
1669 * ha = adapter block pointer.
1670 * TARGET_QUEUE_LOCK must be released.
1671 * ADAPTER_STATE_LOCK must be released.
1672 *
1673 * Returns:
1674 * qla2x00 local function return status code.
1675 *
1676 * Context:
1677 * Kernel context.
1678 */
1679int
1680qla24xx_link_initialize(scsi_qla_host_t *vha)
1681{
1682 int rval;
1683 mbx_cmd_t mc;
1684 mbx_cmd_t *mcp = &mc;
1685
1686 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
1687 "Entered %s.\n", __func__);
1688
1689 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
1690 return QLA_FUNCTION_FAILED;
1691
1692 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04001693 mcp->mb[1] = BIT_4;
1694 if (vha->hw->operating_mode == LOOP)
1695 mcp->mb[1] |= BIT_6;
1696 else
1697 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001698 mcp->mb[2] = 0;
1699 mcp->mb[3] = 0;
1700 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1701 mcp->in_mb = MBX_0;
1702 mcp->tov = MBX_TOV_SECONDS;
1703 mcp->flags = 0;
1704 rval = qla2x00_mailbox_command(vha, mcp);
1705
1706 if (rval != QLA_SUCCESS) {
1707 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
1708 } else {
1709 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
1710 "Done %s.\n", __func__);
1711 }
1712
1713 return rval;
1714}
1715
1716/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 * qla2x00_lip_reset
1718 * Issue LIP reset mailbox command.
1719 *
1720 * Input:
1721 * ha = adapter block pointer.
1722 * TARGET_QUEUE_LOCK must be released.
1723 * ADAPTER_STATE_LOCK must be released.
1724 *
1725 * Returns:
1726 * qla2x00 local function return status code.
1727 *
1728 * Context:
1729 * Kernel context.
1730 */
1731int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001732qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733{
1734 int rval;
1735 mbx_cmd_t mc;
1736 mbx_cmd_t *mcp = &mc;
1737
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001738 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
1739 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001741 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001742 /* Logout across all FCFs. */
1743 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1744 mcp->mb[1] = BIT_1;
1745 mcp->mb[2] = 0;
1746 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1747 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001748 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001749 mcp->mb[1] = BIT_6;
1750 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001751 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001752 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001754 mcp->mb[0] = MBC_LIP_RESET;
1755 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001756 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001757 mcp->mb[1] = 0x00ff;
1758 mcp->mb[10] = 0;
1759 mcp->out_mb |= MBX_10;
1760 } else {
1761 mcp->mb[1] = 0xff00;
1762 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001763 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001764 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001767 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001769 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
1771 if (rval != QLA_SUCCESS) {
1772 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001773 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 } else {
1775 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
1777 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 }
1779
1780 return rval;
1781}
1782
1783/*
1784 * qla2x00_send_sns
1785 * Send SNS command.
1786 *
1787 * Input:
1788 * ha = adapter block pointer.
1789 * sns = pointer for command.
1790 * cmd_size = command size.
1791 * buf_size = response/command size.
1792 * TARGET_QUEUE_LOCK must be released.
1793 * ADAPTER_STATE_LOCK must be released.
1794 *
1795 * Returns:
1796 * qla2x00 local function return status code.
1797 *
1798 * Context:
1799 * Kernel context.
1800 */
1801int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001802qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 uint16_t cmd_size, size_t buf_size)
1804{
1805 int rval;
1806 mbx_cmd_t mc;
1807 mbx_cmd_t *mcp = &mc;
1808
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
1810 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001812 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001813 "Retry cnt=%d ratov=%d total tov=%d.\n",
1814 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
1816 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1817 mcp->mb[1] = cmd_size;
1818 mcp->mb[2] = MSW(sns_phys_address);
1819 mcp->mb[3] = LSW(sns_phys_address);
1820 mcp->mb[6] = MSW(MSD(sns_phys_address));
1821 mcp->mb[7] = LSW(MSD(sns_phys_address));
1822 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1823 mcp->in_mb = MBX_0|MBX_1;
1824 mcp->buf_size = buf_size;
1825 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001826 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1827 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 if (rval != QLA_SUCCESS) {
1830 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001831 ql_dbg(ql_dbg_mbx, vha, 0x105f,
1832 "Failed=%x mb[0]=%x mb[1]=%x.\n",
1833 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 } else {
1835 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001836 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
1837 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 }
1839
1840 return rval;
1841}
1842
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001843int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001844qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001845 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1846{
1847 int rval;
1848
1849 struct logio_entry_24xx *lg;
1850 dma_addr_t lg_dma;
1851 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001852 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001853 struct req_que *req;
1854 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001855
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001856 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
1857 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001858
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001859 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001860 req = ha->req_q_map[0];
1861 else
1862 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001863 rsp = req->rsp;
1864
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001865 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1866 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001867 ql_log(ql_log_warn, vha, 0x1062,
1868 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001869 return QLA_MEMORY_ALLOC_FAILED;
1870 }
1871 memset(lg, 0, sizeof(struct logio_entry_24xx));
1872
1873 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1874 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001875 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001876 lg->nport_handle = cpu_to_le16(loop_id);
1877 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1878 if (opt & BIT_0)
1879 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001880 if (opt & BIT_1)
1881 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001882 lg->port_id[0] = al_pa;
1883 lg->port_id[1] = area;
1884 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001885 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08001886 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
1887 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001888 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001889 ql_dbg(ql_dbg_mbx, vha, 0x1063,
1890 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001891 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001892 ql_dbg(ql_dbg_mbx, vha, 0x1064,
1893 "Failed to complete IOCB -- error status (%x).\n",
1894 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001895 rval = QLA_FUNCTION_FAILED;
1896 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1897 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1898 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1899
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001900 ql_dbg(ql_dbg_mbx, vha, 0x1065,
1901 "Failed to complete IOCB -- completion status (%x) "
1902 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
1903 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001904
1905 switch (iop[0]) {
1906 case LSC_SCODE_PORTID_USED:
1907 mb[0] = MBS_PORT_ID_USED;
1908 mb[1] = LSW(iop[1]);
1909 break;
1910 case LSC_SCODE_NPORT_USED:
1911 mb[0] = MBS_LOOP_ID_USED;
1912 break;
1913 case LSC_SCODE_NOLINK:
1914 case LSC_SCODE_NOIOCB:
1915 case LSC_SCODE_NOXCB:
1916 case LSC_SCODE_CMD_FAILED:
1917 case LSC_SCODE_NOFABRIC:
1918 case LSC_SCODE_FW_NOT_READY:
1919 case LSC_SCODE_NOT_LOGGED_IN:
1920 case LSC_SCODE_NOPCB:
1921 case LSC_SCODE_ELS_REJECT:
1922 case LSC_SCODE_CMD_PARAM_ERR:
1923 case LSC_SCODE_NONPORT:
1924 case LSC_SCODE_LOGGED_IN:
1925 case LSC_SCODE_NOFLOGI_ACC:
1926 default:
1927 mb[0] = MBS_COMMAND_ERROR;
1928 break;
1929 }
1930 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001931 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
1932 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001933
1934 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1935
1936 mb[0] = MBS_COMMAND_COMPLETE;
1937 mb[1] = 0;
1938 if (iop[0] & BIT_4) {
1939 if (iop[0] & BIT_8)
1940 mb[1] |= BIT_1;
1941 } else
1942 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001943
1944 /* Passback COS information. */
1945 mb[10] = 0;
1946 if (lg->io_parameter[7] || lg->io_parameter[8])
1947 mb[10] |= BIT_0; /* Class 2. */
1948 if (lg->io_parameter[9] || lg->io_parameter[10])
1949 mb[10] |= BIT_1; /* Class 3. */
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001950 if (lg->io_parameter[0] & __constant_cpu_to_le32(BIT_7))
1951 mb[10] |= BIT_7; /* Confirmed Completion
1952 * Allowed
1953 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001954 }
1955
1956 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1957
1958 return rval;
1959}
1960
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961/*
1962 * qla2x00_login_fabric
1963 * Issue login fabric port mailbox command.
1964 *
1965 * Input:
1966 * ha = adapter block pointer.
1967 * loop_id = device loop ID.
1968 * domain = device domain.
1969 * area = device area.
1970 * al_pa = device AL_PA.
1971 * status = pointer for return status.
1972 * opt = command options.
1973 * TARGET_QUEUE_LOCK must be released.
1974 * ADAPTER_STATE_LOCK must be released.
1975 *
1976 * Returns:
1977 * qla2x00 local function return status code.
1978 *
1979 * Context:
1980 * Kernel context.
1981 */
1982int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001983qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1985{
1986 int rval;
1987 mbx_cmd_t mc;
1988 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001989 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001991 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
1992 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
1994 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1995 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1996 if (HAS_EXTENDED_IDS(ha)) {
1997 mcp->mb[1] = loop_id;
1998 mcp->mb[10] = opt;
1999 mcp->out_mb |= MBX_10;
2000 } else {
2001 mcp->mb[1] = (loop_id << 8) | opt;
2002 }
2003 mcp->mb[2] = domain;
2004 mcp->mb[3] = area << 8 | al_pa;
2005
2006 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2007 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2008 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002009 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
2011 /* Return mailbox statuses. */
2012 if (mb != NULL) {
2013 mb[0] = mcp->mb[0];
2014 mb[1] = mcp->mb[1];
2015 mb[2] = mcp->mb[2];
2016 mb[6] = mcp->mb[6];
2017 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002018 /* COS retrieved from Get-Port-Database mailbox command. */
2019 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 }
2021
2022 if (rval != QLA_SUCCESS) {
2023 /* RLU tmp code: need to change main mailbox_command function to
2024 * return ok even when the mailbox completion value is not
2025 * SUCCESS. The caller needs to be responsible to interpret
2026 * the return values of this mailbox command if we're not
2027 * to change too much of the existing code.
2028 */
2029 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2030 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2031 mcp->mb[0] == 0x4006)
2032 rval = QLA_SUCCESS;
2033
2034 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002035 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2036 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2037 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 } else {
2039 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002040 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2041 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 }
2043
2044 return rval;
2045}
2046
2047/*
2048 * qla2x00_login_local_device
2049 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002050 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 * Input:
2052 * ha = adapter block pointer.
2053 * loop_id = device loop ID.
2054 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002055 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 * Returns:
2057 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002058 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 * Context:
2060 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002061 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 */
2063int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002064qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 uint16_t *mb_ret, uint8_t opt)
2066{
2067 int rval;
2068 mbx_cmd_t mc;
2069 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002070 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002072 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2073 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002074
Andrew Vasqueze4289242007-07-19 15:05:56 -07002075 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002076 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002077 fcport->d_id.b.domain, fcport->d_id.b.area,
2078 fcport->d_id.b.al_pa, mb_ret, opt);
2079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2081 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002082 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002084 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 mcp->mb[2] = opt;
2086 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2087 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2088 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2089 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002090 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
2092 /* Return mailbox statuses. */
2093 if (mb_ret != NULL) {
2094 mb_ret[0] = mcp->mb[0];
2095 mb_ret[1] = mcp->mb[1];
2096 mb_ret[6] = mcp->mb[6];
2097 mb_ret[7] = mcp->mb[7];
2098 }
2099
2100 if (rval != QLA_SUCCESS) {
2101 /* AV tmp code: need to change main mailbox_command function to
2102 * return ok even when the mailbox completion value is not
2103 * SUCCESS. The caller needs to be responsible to interpret
2104 * the return values of this mailbox command if we're not
2105 * to change too much of the existing code.
2106 */
2107 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2108 rval = QLA_SUCCESS;
2109
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002110 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2111 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2112 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 } else {
2114 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002115 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2116 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
2118
2119 return (rval);
2120}
2121
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002122int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002123qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002124 uint8_t area, uint8_t al_pa)
2125{
2126 int rval;
2127 struct logio_entry_24xx *lg;
2128 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002129 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002130 struct req_que *req;
2131 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002132
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002133 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2134 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002135
2136 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2137 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002138 ql_log(ql_log_warn, vha, 0x106e,
2139 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002140 return QLA_MEMORY_ALLOC_FAILED;
2141 }
2142 memset(lg, 0, sizeof(struct logio_entry_24xx));
2143
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002144 if (ql2xmaxqueues > 1)
2145 req = ha->req_q_map[0];
2146 else
2147 req = vha->req;
2148 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002149 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2150 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002151 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002152 lg->nport_handle = cpu_to_le16(loop_id);
2153 lg->control_flags =
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002154 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
2155 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002156 lg->port_id[0] = al_pa;
2157 lg->port_id[1] = area;
2158 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002159 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002160 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2161 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002162 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002163 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2164 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002165 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002166 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2167 "Failed to complete IOCB -- error status (%x).\n",
2168 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002169 rval = QLA_FUNCTION_FAILED;
2170 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002171 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2172 "Failed to complete IOCB -- completion status (%x) "
2173 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002174 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002175 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002176 } else {
2177 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002178 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2179 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002180 }
2181
2182 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2183
2184 return rval;
2185}
2186
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187/*
2188 * qla2x00_fabric_logout
2189 * Issue logout fabric port mailbox command.
2190 *
2191 * Input:
2192 * ha = adapter block pointer.
2193 * loop_id = device loop ID.
2194 * TARGET_QUEUE_LOCK must be released.
2195 * ADAPTER_STATE_LOCK must be released.
2196 *
2197 * Returns:
2198 * qla2x00 local function return status code.
2199 *
2200 * Context:
2201 * Kernel context.
2202 */
2203int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002204qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002205 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206{
2207 int rval;
2208 mbx_cmd_t mc;
2209 mbx_cmd_t *mcp = &mc;
2210
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002211 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2212 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
2214 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2215 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002216 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 mcp->mb[1] = loop_id;
2218 mcp->mb[10] = 0;
2219 mcp->out_mb |= MBX_10;
2220 } else {
2221 mcp->mb[1] = loop_id << 8;
2222 }
2223
2224 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002225 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002227 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 if (rval != QLA_SUCCESS) {
2230 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002231 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2232 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 } else {
2234 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2236 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 }
2238
2239 return rval;
2240}
2241
2242/*
2243 * qla2x00_full_login_lip
2244 * Issue full login LIP mailbox command.
2245 *
2246 * Input:
2247 * ha = adapter block pointer.
2248 * TARGET_QUEUE_LOCK must be released.
2249 * ADAPTER_STATE_LOCK must be released.
2250 *
2251 * Returns:
2252 * qla2x00 local function return status code.
2253 *
2254 * Context:
2255 * Kernel context.
2256 */
2257int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002258qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
2260 int rval;
2261 mbx_cmd_t mc;
2262 mbx_cmd_t *mcp = &mc;
2263
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002264 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2265 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002268 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002269 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 mcp->mb[3] = 0;
2271 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2272 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002273 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002275 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
2277 if (rval != QLA_SUCCESS) {
2278 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002279 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 } else {
2281 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002282 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2283 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 }
2285
2286 return rval;
2287}
2288
2289/*
2290 * qla2x00_get_id_list
2291 *
2292 * Input:
2293 * ha = adapter block pointer.
2294 *
2295 * Returns:
2296 * qla2x00 local function return status code.
2297 *
2298 * Context:
2299 * Kernel context.
2300 */
2301int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002302qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 uint16_t *entries)
2304{
2305 int rval;
2306 mbx_cmd_t mc;
2307 mbx_cmd_t *mcp = &mc;
2308
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002309 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2310 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 if (id_list == NULL)
2313 return QLA_FUNCTION_FAILED;
2314
2315 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002316 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002317 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002318 mcp->mb[2] = MSW(id_list_dma);
2319 mcp->mb[3] = LSW(id_list_dma);
2320 mcp->mb[6] = MSW(MSD(id_list_dma));
2321 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002322 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002323 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002324 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002325 } else {
2326 mcp->mb[1] = MSW(id_list_dma);
2327 mcp->mb[2] = LSW(id_list_dma);
2328 mcp->mb[3] = MSW(MSD(id_list_dma));
2329 mcp->mb[6] = LSW(MSD(id_list_dma));
2330 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002333 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002335 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
2337 if (rval != QLA_SUCCESS) {
2338 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002339 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 } else {
2341 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002342 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2343 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 }
2345
2346 return rval;
2347}
2348
2349/*
2350 * qla2x00_get_resource_cnts
2351 * Get current firmware resource counts.
2352 *
2353 * Input:
2354 * ha = adapter block pointer.
2355 *
2356 * Returns:
2357 * qla2x00 local function return status code.
2358 *
2359 * Context:
2360 * Kernel context.
2361 */
2362int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002363qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002364 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002365 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366{
2367 int rval;
2368 mbx_cmd_t mc;
2369 mbx_cmd_t *mcp = &mc;
2370
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2372 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373
2374 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2375 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002376 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002377 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002378 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002379 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002381 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
2383 if (rval != QLA_SUCCESS) {
2384 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002385 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2386 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002388 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002389 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2390 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2391 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2392 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
2394 if (cur_xchg_cnt)
2395 *cur_xchg_cnt = mcp->mb[3];
2396 if (orig_xchg_cnt)
2397 *orig_xchg_cnt = mcp->mb[6];
2398 if (cur_iocb_cnt)
2399 *cur_iocb_cnt = mcp->mb[7];
2400 if (orig_iocb_cnt)
2401 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002402 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002403 *max_npiv_vports = mcp->mb[11];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002404 if ((IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw)) && max_fcfs)
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002405 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 }
2407
2408 return (rval);
2409}
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411/*
2412 * qla2x00_get_fcal_position_map
2413 * Get FCAL (LILP) position map using mailbox command
2414 *
2415 * Input:
2416 * ha = adapter state pointer.
2417 * pos_map = buffer pointer (can be NULL).
2418 *
2419 * Returns:
2420 * qla2x00 local function return status code.
2421 *
2422 * Context:
2423 * Kernel context.
2424 */
2425int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002426qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427{
2428 int rval;
2429 mbx_cmd_t mc;
2430 mbx_cmd_t *mcp = &mc;
2431 char *pmap;
2432 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002433 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002435 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2436 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002437
Andrew Vasquez4b892582008-09-11 21:22:48 -07002438 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002440 ql_log(ql_log_warn, vha, 0x1080,
2441 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 return QLA_MEMORY_ALLOC_FAILED;
2443 }
2444 memset(pmap, 0, FCAL_MAP_SIZE);
2445
2446 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2447 mcp->mb[2] = MSW(pmap_dma);
2448 mcp->mb[3] = LSW(pmap_dma);
2449 mcp->mb[6] = MSW(MSD(pmap_dma));
2450 mcp->mb[7] = LSW(MSD(pmap_dma));
2451 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2452 mcp->in_mb = MBX_1|MBX_0;
2453 mcp->buf_size = FCAL_MAP_SIZE;
2454 mcp->flags = MBX_DMA_IN;
2455 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002456 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
2458 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002459 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002460 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2461 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2462 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2463 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464
2465 if (pos_map)
2466 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2467 }
2468 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2469
2470 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002471 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002473 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2474 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 }
2476
2477 return rval;
2478}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002479
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002480/*
2481 * qla2x00_get_link_status
2482 *
2483 * Input:
2484 * ha = adapter block pointer.
2485 * loop_id = device loop ID.
2486 * ret_buf = pointer to link status return buffer.
2487 *
2488 * Returns:
2489 * 0 = success.
2490 * BIT_0 = mem alloc error.
2491 * BIT_1 = mailbox error.
2492 */
2493int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002494qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002495 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002496{
2497 int rval;
2498 mbx_cmd_t mc;
2499 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002500 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002501 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002502
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2504 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002505
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002506 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002507 mcp->mb[2] = MSW(stats_dma);
2508 mcp->mb[3] = LSW(stats_dma);
2509 mcp->mb[6] = MSW(MSD(stats_dma));
2510 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002511 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2512 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002513 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002514 mcp->mb[1] = loop_id;
2515 mcp->mb[4] = 0;
2516 mcp->mb[10] = 0;
2517 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2518 mcp->in_mb |= MBX_1;
2519 } else if (HAS_EXTENDED_IDS(ha)) {
2520 mcp->mb[1] = loop_id;
2521 mcp->mb[10] = 0;
2522 mcp->out_mb |= MBX_10|MBX_1;
2523 } else {
2524 mcp->mb[1] = loop_id << 8;
2525 mcp->out_mb |= MBX_1;
2526 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002527 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002528 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002529 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002530
2531 if (rval == QLA_SUCCESS) {
2532 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002533 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2534 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002535 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002536 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002537 /* Copy over data -- firmware data is LE. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002538 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2539 "Done %s.\n", __func__);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002540 dwords = offsetof(struct link_statistics, unused1) / 4;
2541 siter = diter = &stats->link_fail_cnt;
2542 while (dwords--)
2543 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002544 }
2545 } else {
2546 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002547 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002548 }
2549
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002550 return rval;
2551}
2552
2553int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002554qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002555 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002556{
2557 int rval;
2558 mbx_cmd_t mc;
2559 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002560 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002561
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002562 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2563 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002564
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002565 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002566 mcp->mb[2] = MSW(stats_dma);
2567 mcp->mb[3] = LSW(stats_dma);
2568 mcp->mb[6] = MSW(MSD(stats_dma));
2569 mcp->mb[7] = LSW(MSD(stats_dma));
2570 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002571 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002572 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002573 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 -07002574 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002575 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002576 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002577 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002578
2579 if (rval == QLA_SUCCESS) {
2580 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002581 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2582 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002583 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002584 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002585 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2586 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002587 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002588 dwords = sizeof(struct link_statistics) / 4;
2589 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002590 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002591 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002592 }
2593 } else {
2594 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002595 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002596 }
2597
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002598 return rval;
2599}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002600
2601int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002602qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002603{
2604 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002605 unsigned long flags = 0;
2606
2607 struct abort_entry_24xx *abt;
2608 dma_addr_t abt_dma;
2609 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002610 fc_port_t *fcport = sp->fcport;
2611 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002612 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002613 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002614
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002615 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2616 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002617
Armen Baloyan4440e462014-02-26 04:15:18 -05002618 if (ql2xasynctmfenable)
2619 return qla24xx_async_abort_command(sp);
2620
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002621 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002622 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002623 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002624 break;
2625 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002626 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002627 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002628 /* Command not found. */
2629 return QLA_FUNCTION_FAILED;
2630 }
2631
2632 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2633 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002634 ql_log(ql_log_warn, vha, 0x108d,
2635 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002636 return QLA_MEMORY_ALLOC_FAILED;
2637 }
2638 memset(abt, 0, sizeof(struct abort_entry_24xx));
2639
2640 abt->entry_type = ABORT_IOCB_TYPE;
2641 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002642 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002643 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002644 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002645 abt->port_id[0] = fcport->d_id.b.al_pa;
2646 abt->port_id[1] = fcport->d_id.b.area;
2647 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002648 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002649
2650 abt->req_que_no = cpu_to_le16(req->id);
2651
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002652 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002653 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002654 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2655 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002656 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002657 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2658 "Failed to complete IOCB -- error status (%x).\n",
2659 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002660 rval = QLA_FUNCTION_FAILED;
2661 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002662 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2663 "Failed to complete IOCB -- completion status (%x).\n",
2664 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04002665 if (abt->nport_handle == CS_IOCB_ERROR)
2666 rval = QLA_FUNCTION_PARAMETER_ERROR;
2667 else
2668 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002669 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002670 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2671 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002672 }
2673
2674 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2675
2676 return rval;
2677}
2678
2679struct tsk_mgmt_cmd {
2680 union {
2681 struct tsk_mgmt_entry tsk;
2682 struct sts_entry_24xx sts;
2683 } p;
2684};
2685
Andrew Vasquez523ec772008-04-03 13:13:24 -07002686static int
2687__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002688 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002689{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002690 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002691 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002692 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002693 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002694 scsi_qla_host_t *vha;
2695 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002696 struct req_que *req;
2697 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002698
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002699 vha = fcport->vha;
2700 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002701 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002702
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002703 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
2704 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002705
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002706 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002707 rsp = ha->rsp_q_map[tag + 1];
2708 else
2709 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002710 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002711 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002712 ql_log(ql_log_warn, vha, 0x1093,
2713 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002714 return QLA_MEMORY_ALLOC_FAILED;
2715 }
2716 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2717
2718 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2719 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002720 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002721 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002722 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002723 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002724 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2725 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2726 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002727 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002728 if (type == TCF_LUN_RESET) {
2729 int_to_scsilun(l, &tsk->p.tsk.lun);
2730 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2731 sizeof(tsk->p.tsk.lun));
2732 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002733
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002734 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002735 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002736 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002737 ql_dbg(ql_dbg_mbx, vha, 0x1094,
2738 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002739 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002740 ql_dbg(ql_dbg_mbx, vha, 0x1095,
2741 "Failed to complete IOCB -- error status (%x).\n",
2742 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002743 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002744 } else if (sts->comp_status !=
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002745 __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002746 ql_dbg(ql_dbg_mbx, vha, 0x1096,
2747 "Failed to complete IOCB -- completion status (%x).\n",
2748 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002749 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08002750 } else if (le16_to_cpu(sts->scsi_status) &
2751 SS_RESPONSE_INFO_LEN_VALID) {
2752 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002753 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002754 "Ignoring inconsistent data length -- not enough "
2755 "response info (%d).\n",
2756 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08002757 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002758 ql_dbg(ql_dbg_mbx, vha, 0x1098,
2759 "Failed to complete IOCB -- response (%x).\n",
2760 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08002761 rval = QLA_FUNCTION_FAILED;
2762 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002763 }
2764
2765 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002766 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002767 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2768 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002769 ql_dbg(ql_dbg_mbx, vha, 0x1099,
2770 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002771 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002772 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
2773 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002774 }
2775
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002776 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002777
2778 return rval;
2779}
2780
Andrew Vasquez523ec772008-04-03 13:13:24 -07002781int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002782qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002783{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002784 struct qla_hw_data *ha = fcport->vha->hw;
2785
2786 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2787 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
2788
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002789 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002790}
2791
2792int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002793qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002794{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002795 struct qla_hw_data *ha = fcport->vha->hw;
2796
2797 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2798 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
2799
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002800 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002801}
2802
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002803int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002804qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002805{
2806 int rval;
2807 mbx_cmd_t mc;
2808 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002809 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002810
Andrew Vasquez68af0812008-05-12 22:21:13 -07002811 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002812 return QLA_FUNCTION_FAILED;
2813
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002814 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
2815 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002816
2817 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2818 mcp->out_mb = MBX_0;
2819 mcp->in_mb = MBX_0;
2820 mcp->tov = 5;
2821 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002822 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002823
2824 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002826 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002827 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
2828 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002829 }
2830
2831 return rval;
2832}
2833
Joe Carnucciodb64e932013-10-30 03:38:18 -04002834int
2835qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
2836{
2837 int rval;
2838 mbx_cmd_t mc;
2839 mbx_cmd_t *mcp = &mc;
2840
Andrew Vasquez064135e2015-04-09 15:00:02 -04002841 if (!IS_QLA2031(vha->hw) && !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04002842 return QLA_FUNCTION_FAILED;
2843
2844 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
2845 "Entered %s.\n", __func__);
2846
2847 mcp->mb[0] = MBC_WRITE_SERDES;
2848 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04002849 if (IS_QLA2031(vha->hw))
2850 mcp->mb[2] = data & 0xff;
2851 else
2852 mcp->mb[2] = data;
2853
Joe Carnucciodb64e932013-10-30 03:38:18 -04002854 mcp->mb[3] = 0;
2855 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2856 mcp->in_mb = MBX_0;
2857 mcp->tov = MBX_TOV_SECONDS;
2858 mcp->flags = 0;
2859 rval = qla2x00_mailbox_command(vha, mcp);
2860
2861 if (rval != QLA_SUCCESS) {
2862 ql_dbg(ql_dbg_mbx, vha, 0x1183,
2863 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
2864 } else {
2865 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
2866 "Done %s.\n", __func__);
2867 }
2868
2869 return rval;
2870}
2871
2872int
2873qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
2874{
2875 int rval;
2876 mbx_cmd_t mc;
2877 mbx_cmd_t *mcp = &mc;
2878
Andrew Vasquez064135e2015-04-09 15:00:02 -04002879 if (!IS_QLA2031(vha->hw) && !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04002880 return QLA_FUNCTION_FAILED;
2881
2882 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
2883 "Entered %s.\n", __func__);
2884
2885 mcp->mb[0] = MBC_READ_SERDES;
2886 mcp->mb[1] = addr;
2887 mcp->mb[3] = 0;
2888 mcp->out_mb = MBX_3|MBX_1|MBX_0;
2889 mcp->in_mb = MBX_1|MBX_0;
2890 mcp->tov = MBX_TOV_SECONDS;
2891 mcp->flags = 0;
2892 rval = qla2x00_mailbox_command(vha, mcp);
2893
Andrew Vasquez064135e2015-04-09 15:00:02 -04002894 if (IS_QLA2031(vha->hw))
2895 *data = mcp->mb[1] & 0xff;
2896 else
2897 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04002898
2899 if (rval != QLA_SUCCESS) {
2900 ql_dbg(ql_dbg_mbx, vha, 0x1186,
2901 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
2902 } else {
2903 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
2904 "Done %s.\n", __func__);
2905 }
2906
2907 return rval;
2908}
2909
Joe Carnuccioe8887c52014-04-11 16:54:17 -04002910int
2911qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
2912{
2913 int rval;
2914 mbx_cmd_t mc;
2915 mbx_cmd_t *mcp = &mc;
2916
2917 if (!IS_QLA8044(vha->hw))
2918 return QLA_FUNCTION_FAILED;
2919
2920 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1186,
2921 "Entered %s.\n", __func__);
2922
2923 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
2924 mcp->mb[1] = HCS_WRITE_SERDES;
2925 mcp->mb[3] = LSW(addr);
2926 mcp->mb[4] = MSW(addr);
2927 mcp->mb[5] = LSW(data);
2928 mcp->mb[6] = MSW(data);
2929 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
2930 mcp->in_mb = MBX_0;
2931 mcp->tov = MBX_TOV_SECONDS;
2932 mcp->flags = 0;
2933 rval = qla2x00_mailbox_command(vha, mcp);
2934
2935 if (rval != QLA_SUCCESS) {
2936 ql_dbg(ql_dbg_mbx, vha, 0x1187,
2937 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
2938 } else {
2939 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
2940 "Done %s.\n", __func__);
2941 }
2942
2943 return rval;
2944}
2945
2946int
2947qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
2948{
2949 int rval;
2950 mbx_cmd_t mc;
2951 mbx_cmd_t *mcp = &mc;
2952
2953 if (!IS_QLA8044(vha->hw))
2954 return QLA_FUNCTION_FAILED;
2955
2956 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
2957 "Entered %s.\n", __func__);
2958
2959 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
2960 mcp->mb[1] = HCS_READ_SERDES;
2961 mcp->mb[3] = LSW(addr);
2962 mcp->mb[4] = MSW(addr);
2963 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
2964 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2965 mcp->tov = MBX_TOV_SECONDS;
2966 mcp->flags = 0;
2967 rval = qla2x00_mailbox_command(vha, mcp);
2968
2969 *data = mcp->mb[2] << 16 | mcp->mb[1];
2970
2971 if (rval != QLA_SUCCESS) {
2972 ql_dbg(ql_dbg_mbx, vha, 0x118a,
2973 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
2974 } else {
2975 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
2976 "Done %s.\n", __func__);
2977 }
2978
2979 return rval;
2980}
2981
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002982/**
2983 * qla2x00_set_serdes_params() -
2984 * @ha: HA context
2985 *
2986 * Returns
2987 */
2988int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002989qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002990 uint16_t sw_em_2g, uint16_t sw_em_4g)
2991{
2992 int rval;
2993 mbx_cmd_t mc;
2994 mbx_cmd_t *mcp = &mc;
2995
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002996 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
2997 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002998
2999 mcp->mb[0] = MBC_SERDES_PARAMS;
3000 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003001 mcp->mb[2] = sw_em_1g | BIT_15;
3002 mcp->mb[3] = sw_em_2g | BIT_15;
3003 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003004 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3005 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003006 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003007 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003008 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003009
3010 if (rval != QLA_SUCCESS) {
3011 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003012 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3013 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003014 } else {
3015 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003016 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3017 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003018 }
3019
3020 return rval;
3021}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003022
3023int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003024qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003025{
3026 int rval;
3027 mbx_cmd_t mc;
3028 mbx_cmd_t *mcp = &mc;
3029
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003030 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003031 return QLA_FUNCTION_FAILED;
3032
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003033 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3034 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003035
3036 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003037 mcp->mb[1] = 0;
3038 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003039 mcp->in_mb = MBX_0;
3040 mcp->tov = 5;
3041 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003042 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003043
3044 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003045 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003046 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3047 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003048 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003049 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3050 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003051 }
3052
3053 return rval;
3054}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003055
3056int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003057qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003058 uint16_t buffers)
3059{
3060 int rval;
3061 mbx_cmd_t mc;
3062 mbx_cmd_t *mcp = &mc;
3063
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003064 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3065 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003066
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003067 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003068 return QLA_FUNCTION_FAILED;
3069
Andrew Vasquez85880802009-12-15 21:29:46 -08003070 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3071 return QLA_FUNCTION_FAILED;
3072
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003073 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003074 mcp->mb[1] = TC_EFT_ENABLE;
3075 mcp->mb[2] = LSW(eft_dma);
3076 mcp->mb[3] = MSW(eft_dma);
3077 mcp->mb[4] = LSW(MSD(eft_dma));
3078 mcp->mb[5] = MSW(MSD(eft_dma));
3079 mcp->mb[6] = buffers;
3080 mcp->mb[7] = TC_AEN_DISABLE;
3081 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 -07003082 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003083 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003084 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003085 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003086 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003087 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3088 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3089 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003090 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003091 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3092 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003093 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003094
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003095 return rval;
3096}
3097
3098int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003099qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003100{
3101 int rval;
3102 mbx_cmd_t mc;
3103 mbx_cmd_t *mcp = &mc;
3104
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003105 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3106 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003107
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003108 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003109 return QLA_FUNCTION_FAILED;
3110
Andrew Vasquez85880802009-12-15 21:29:46 -08003111 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3112 return QLA_FUNCTION_FAILED;
3113
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003114 mcp->mb[0] = MBC_TRACE_CONTROL;
3115 mcp->mb[1] = TC_EFT_DISABLE;
3116 mcp->out_mb = MBX_1|MBX_0;
3117 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003118 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003119 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003120 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003121 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003122 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3123 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3124 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003125 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003126 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3127 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003128 }
3129
3130 return rval;
3131}
3132
Andrew Vasquez88729e52006-06-23 16:10:50 -07003133int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003134qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003135 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3136{
3137 int rval;
3138 mbx_cmd_t mc;
3139 mbx_cmd_t *mcp = &mc;
3140
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003141 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3142 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003143
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003144 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003145 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003146 return QLA_FUNCTION_FAILED;
3147
Andrew Vasquez85880802009-12-15 21:29:46 -08003148 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3149 return QLA_FUNCTION_FAILED;
3150
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003151 mcp->mb[0] = MBC_TRACE_CONTROL;
3152 mcp->mb[1] = TC_FCE_ENABLE;
3153 mcp->mb[2] = LSW(fce_dma);
3154 mcp->mb[3] = MSW(fce_dma);
3155 mcp->mb[4] = LSW(MSD(fce_dma));
3156 mcp->mb[5] = MSW(MSD(fce_dma));
3157 mcp->mb[6] = buffers;
3158 mcp->mb[7] = TC_AEN_DISABLE;
3159 mcp->mb[8] = 0;
3160 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3161 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3162 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3163 MBX_1|MBX_0;
3164 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003165 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003166 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003167 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003168 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003169 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3170 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3171 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003172 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003173 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3174 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003175
3176 if (mb)
3177 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3178 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003179 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003180 }
3181
3182 return rval;
3183}
3184
3185int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003186qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003187{
3188 int rval;
3189 mbx_cmd_t mc;
3190 mbx_cmd_t *mcp = &mc;
3191
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003192 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3193 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003194
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003195 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003196 return QLA_FUNCTION_FAILED;
3197
Andrew Vasquez85880802009-12-15 21:29:46 -08003198 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3199 return QLA_FUNCTION_FAILED;
3200
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003201 mcp->mb[0] = MBC_TRACE_CONTROL;
3202 mcp->mb[1] = TC_FCE_DISABLE;
3203 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3204 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3205 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3206 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003207 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003208 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003209 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003210 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003211 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3212 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3213 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003214 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003215 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3216 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003217
3218 if (wr)
3219 *wr = (uint64_t) mcp->mb[5] << 48 |
3220 (uint64_t) mcp->mb[4] << 32 |
3221 (uint64_t) mcp->mb[3] << 16 |
3222 (uint64_t) mcp->mb[2];
3223 if (rd)
3224 *rd = (uint64_t) mcp->mb[9] << 48 |
3225 (uint64_t) mcp->mb[8] << 32 |
3226 (uint64_t) mcp->mb[7] << 16 |
3227 (uint64_t) mcp->mb[6];
3228 }
3229
3230 return rval;
3231}
3232
3233int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003234qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3235 uint16_t *port_speed, uint16_t *mb)
3236{
3237 int rval;
3238 mbx_cmd_t mc;
3239 mbx_cmd_t *mcp = &mc;
3240
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003241 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3242 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003243
Giridhar Malavali6e980162010-03-19 17:03:58 -07003244 if (!IS_IIDMA_CAPABLE(vha->hw))
3245 return QLA_FUNCTION_FAILED;
3246
Giridhar Malavali6e980162010-03-19 17:03:58 -07003247 mcp->mb[0] = MBC_PORT_PARAMS;
3248 mcp->mb[1] = loop_id;
3249 mcp->mb[2] = mcp->mb[3] = 0;
3250 mcp->mb[9] = vha->vp_idx;
3251 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3252 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3253 mcp->tov = MBX_TOV_SECONDS;
3254 mcp->flags = 0;
3255 rval = qla2x00_mailbox_command(vha, mcp);
3256
3257 /* Return mailbox statuses. */
3258 if (mb != NULL) {
3259 mb[0] = mcp->mb[0];
3260 mb[1] = mcp->mb[1];
3261 mb[3] = mcp->mb[3];
3262 }
3263
3264 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003265 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003266 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003267 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3268 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003269 if (port_speed)
3270 *port_speed = mcp->mb[3];
3271 }
3272
3273 return rval;
3274}
3275
3276int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003277qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003278 uint16_t port_speed, uint16_t *mb)
3279{
3280 int rval;
3281 mbx_cmd_t mc;
3282 mbx_cmd_t *mcp = &mc;
3283
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003284 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3285 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003286
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003287 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003288 return QLA_FUNCTION_FAILED;
3289
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003290 mcp->mb[0] = MBC_PORT_PARAMS;
3291 mcp->mb[1] = loop_id;
3292 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003293 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003294 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3295 else
3296 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3297 mcp->mb[9] = vha->vp_idx;
3298 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3299 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003300 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003301 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003302 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003303
3304 /* Return mailbox statuses. */
3305 if (mb != NULL) {
3306 mb[0] = mcp->mb[0];
3307 mb[1] = mcp->mb[1];
3308 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003309 }
3310
3311 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003312 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3313 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003314 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003315 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3316 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003317 }
3318
3319 return rval;
3320}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003321
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003322void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003323qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003324 struct vp_rpt_id_entry_24xx *rptid_entry)
3325{
3326 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07003327 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003328 struct qla_hw_data *ha = vha->hw;
3329 scsi_qla_host_t *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003330 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003331 int found;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003332
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003333 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3334 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003335
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003336 if (rptid_entry->entry_status != 0)
3337 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003338
3339 if (rptid_entry->format == 0) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003340 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003341 "Format 0 : Number of VPs setup %d, number of "
3342 "VPs acquired %d.\n",
3343 MSB(le16_to_cpu(rptid_entry->vp_count)),
3344 LSB(le16_to_cpu(rptid_entry->vp_count)));
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003345 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003346 "Primary port id %02x%02x%02x.\n",
3347 rptid_entry->port_id[2], rptid_entry->port_id[1],
3348 rptid_entry->port_id[0]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003349 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07003350 vp_idx = LSB(stat);
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003352 "Format 1: VP[%d] enabled - status %d - with "
3353 "port id %02x%02x%02x.\n", vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003354 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003355 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003356
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003357 /* FA-WWN is only for physical port */
3358 if (!vp_idx) {
3359 void *wwpn = ha->init_cb->port_name;
3360
3361 if (!MSB(stat)) {
3362 if (rptid_entry->vp_idx_map[1] & BIT_6)
3363 wwpn = rptid_entry->reserved_4 + 8;
3364 }
3365 memcpy(vha->port_name, wwpn, WWN_SIZE);
3366 fc_host_port_name(vha->host) =
3367 wwn_to_u64(vha->port_name);
3368 ql_dbg(ql_dbg_mbx, vha, 0x1018,
3369 "FA-WWN portname %016llx (%x)\n",
3370 fc_host_port_name(vha->host), MSB(stat));
3371 }
3372
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003373 vp = vha;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003374 if (vp_idx == 0)
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003375 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003376
Saurav Kashyap681e0142012-11-21 02:40:28 -05003377 if (MSB(stat) != 0 && MSB(stat) != 2) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003378 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3379 "Could not acquire ID for VP[%d].\n", vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003380 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07003381 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003382
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003383 found = 0;
Arun Easifeafb7b2010-09-03 14:57:00 -07003384 spin_lock_irqsave(&ha->vport_slock, flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003385 list_for_each_entry(vp, &ha->vp_list, list) {
3386 if (vp_idx == vp->vp_idx) {
3387 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003388 break;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003389 }
3390 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003391 spin_unlock_irqrestore(&ha->vport_slock, flags);
3392
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003393 if (!found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003394 return;
3395
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003396 vp->d_id.b.domain = rptid_entry->port_id[2];
3397 vp->d_id.b.area = rptid_entry->port_id[1];
3398 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003399
3400 /*
3401 * Cannot configure here as we are still sitting on the
3402 * response queue. Handle it in dpc context.
3403 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003404 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003405
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003406reg_needed:
3407 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3408 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
3409 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003410 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003411 }
3412}
3413
3414/*
3415 * qla24xx_modify_vp_config
3416 * Change VP configuration for vha
3417 *
3418 * Input:
3419 * vha = adapter block pointer.
3420 *
3421 * Returns:
3422 * qla2xxx local function return status code.
3423 *
3424 * Context:
3425 * Kernel context.
3426 */
3427int
3428qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3429{
3430 int rval;
3431 struct vp_config_entry_24xx *vpmod;
3432 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003433 struct qla_hw_data *ha = vha->hw;
3434 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003435
3436 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003437
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003438 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3439 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003441 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003442 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003443 ql_log(ql_log_warn, vha, 0x10bc,
3444 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003445 return QLA_MEMORY_ALLOC_FAILED;
3446 }
3447
3448 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3449 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3450 vpmod->entry_count = 1;
3451 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3452 vpmod->vp_count = 1;
3453 vpmod->vp_index1 = vha->vp_idx;
3454 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003455
3456 qlt_modify_vp_config(vha, vpmod);
3457
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003458 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3459 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3460 vpmod->entry_count = 1;
3461
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003462 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003463 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003464 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3465 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003466 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003467 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3468 "Failed to complete IOCB -- error status (%x).\n",
3469 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003470 rval = QLA_FUNCTION_FAILED;
3471 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003472 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3473 "Failed to complete IOCB -- completion status (%x).\n",
3474 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003475 rval = QLA_FUNCTION_FAILED;
3476 } else {
3477 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003478 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3479 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003480 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3481 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003482 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003483
3484 return rval;
3485}
3486
3487/*
3488 * qla24xx_control_vp
3489 * Enable a virtual port for given host
3490 *
3491 * Input:
3492 * ha = adapter block pointer.
3493 * vhba = virtual adapter (unused)
3494 * index = index number for enabled VP
3495 *
3496 * Returns:
3497 * qla2xxx local function return status code.
3498 *
3499 * Context:
3500 * Kernel context.
3501 */
3502int
3503qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3504{
3505 int rval;
3506 int map, pos;
3507 struct vp_ctrl_entry_24xx *vce;
3508 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003509 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003510 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003511 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003512
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003513 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003514 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003515
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003516 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003517 return QLA_PARAMETER_ERROR;
3518
3519 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3520 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003521 ql_log(ql_log_warn, vha, 0x10c2,
3522 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003523 return QLA_MEMORY_ALLOC_FAILED;
3524 }
3525 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3526
3527 vce->entry_type = VP_CTRL_IOCB_TYPE;
3528 vce->entry_count = 1;
3529 vce->command = cpu_to_le16(cmd);
3530 vce->vp_count = __constant_cpu_to_le16(1);
3531
3532 /* index map in firmware starts with 1; decrement index
3533 * this is ok as we never use index 0
3534 */
3535 map = (vp_index - 1) / 8;
3536 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003537 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003538 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003539 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003540
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003541 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003542 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003543 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3544 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003545 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003546 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3547 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003548 vce->entry_status);
3549 rval = QLA_FUNCTION_FAILED;
3550 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003551 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3552 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003553 le16_to_cpu(vce->comp_status));
3554 rval = QLA_FUNCTION_FAILED;
3555 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003556 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3557 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003558 }
3559
3560 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3561
3562 return rval;
3563}
3564
3565/*
3566 * qla2x00_send_change_request
3567 * Receive or disable RSCN request from fabric controller
3568 *
3569 * Input:
3570 * ha = adapter block pointer
3571 * format = registration format:
3572 * 0 - Reserved
3573 * 1 - Fabric detected registration
3574 * 2 - N_port detected registration
3575 * 3 - Full registration
3576 * FF - clear registration
3577 * vp_idx = Virtual port index
3578 *
3579 * Returns:
3580 * qla2x00 local function return status code.
3581 *
3582 * Context:
3583 * Kernel Context
3584 */
3585
3586int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003587qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003588 uint16_t vp_idx)
3589{
3590 int rval;
3591 mbx_cmd_t mc;
3592 mbx_cmd_t *mcp = &mc;
3593
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003594 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3595 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003596
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003597 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3598 mcp->mb[1] = format;
3599 mcp->mb[9] = vp_idx;
3600 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3601 mcp->in_mb = MBX_0|MBX_1;
3602 mcp->tov = MBX_TOV_SECONDS;
3603 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003604 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003605
3606 if (rval == QLA_SUCCESS) {
3607 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3608 rval = BIT_1;
3609 }
3610 } else
3611 rval = BIT_1;
3612
3613 return rval;
3614}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003615
3616int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003617qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003618 uint32_t size)
3619{
3620 int rval;
3621 mbx_cmd_t mc;
3622 mbx_cmd_t *mcp = &mc;
3623
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003624 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3625 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003626
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003627 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003628 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3629 mcp->mb[8] = MSW(addr);
3630 mcp->out_mb = MBX_8|MBX_0;
3631 } else {
3632 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3633 mcp->out_mb = MBX_0;
3634 }
3635 mcp->mb[1] = LSW(addr);
3636 mcp->mb[2] = MSW(req_dma);
3637 mcp->mb[3] = LSW(req_dma);
3638 mcp->mb[6] = MSW(MSD(req_dma));
3639 mcp->mb[7] = LSW(MSD(req_dma));
3640 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003641 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003642 mcp->mb[4] = MSW(size);
3643 mcp->mb[5] = LSW(size);
3644 mcp->out_mb |= MBX_5|MBX_4;
3645 } else {
3646 mcp->mb[4] = LSW(size);
3647 mcp->out_mb |= MBX_4;
3648 }
3649
3650 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003651 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003652 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003653 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003654
3655 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003656 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3657 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003658 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003659 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3660 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003661 }
3662
3663 return rval;
3664}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003665/* 84XX Support **************************************************************/
3666
3667struct cs84xx_mgmt_cmd {
3668 union {
3669 struct verify_chip_entry_84xx req;
3670 struct verify_chip_rsp_84xx rsp;
3671 } p;
3672};
3673
3674int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003675qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003676{
3677 int rval, retry;
3678 struct cs84xx_mgmt_cmd *mn;
3679 dma_addr_t mn_dma;
3680 uint16_t options;
3681 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003682 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003683
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003684 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
3685 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003686
3687 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3688 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003689 return QLA_MEMORY_ALLOC_FAILED;
3690 }
3691
3692 /* Force Update? */
3693 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3694 /* Diagnostic firmware? */
3695 /* options |= MENLO_DIAG_FW; */
3696 /* We update the firmware with only one data sequence. */
3697 options |= VCO_END_OF_DATA;
3698
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003699 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003700 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003701 memset(mn, 0, sizeof(*mn));
3702 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3703 mn->p.req.entry_count = 1;
3704 mn->p.req.options = cpu_to_le16(options);
3705
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003706 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
3707 "Dump of Verify Request.\n");
3708 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
3709 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003710
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003711 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003712 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003713 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
3714 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003715 goto verify_done;
3716 }
3717
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003718 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
3719 "Dump of Verify Response.\n");
3720 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
3721 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003722
3723 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3724 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3725 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003726 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003727 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003728
3729 if (status[0] != CS_COMPLETE) {
3730 rval = QLA_FUNCTION_FAILED;
3731 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003732 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
3733 "Firmware update failed. Retrying "
3734 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003735 options |= VCO_DONT_UPDATE_FW;
3736 options &= ~VCO_FORCE_UPDATE;
3737 retry = 1;
3738 }
3739 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003740 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003741 "Firmware updated to %x.\n",
3742 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003743
3744 /* NOTE: we only update OP firmware. */
3745 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3746 ha->cs84xx->op_fw_version =
3747 le32_to_cpu(mn->p.rsp.fw_ver);
3748 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3749 flags);
3750 }
3751 } while (retry);
3752
3753verify_done:
3754 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3755
3756 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003757 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
3758 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003759 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003760 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
3761 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003762 }
3763
3764 return rval;
3765}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003766
3767int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003768qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003769{
3770 int rval;
3771 unsigned long flags;
3772 mbx_cmd_t mc;
3773 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003774 struct qla_hw_data *ha = vha->hw;
3775
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
3777 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003778
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003779 if (IS_SHADOW_REG_CAPABLE(ha))
3780 req->options |= BIT_13;
3781
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003782 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003783 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003784 mcp->mb[2] = MSW(LSD(req->dma));
3785 mcp->mb[3] = LSW(LSD(req->dma));
3786 mcp->mb[6] = MSW(MSD(req->dma));
3787 mcp->mb[7] = LSW(MSD(req->dma));
3788 mcp->mb[5] = req->length;
3789 if (req->rsp)
3790 mcp->mb[10] = req->rsp->id;
3791 mcp->mb[12] = req->qos;
3792 mcp->mb[11] = req->vp_idx;
3793 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003794 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003795 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003796
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003797 mcp->mb[4] = req->id;
3798 /* que in ptr index */
3799 mcp->mb[8] = 0;
3800 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003801 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003802 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3803 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3804 mcp->in_mb = MBX_0;
3805 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003806 mcp->tov = MBX_TOV_SECONDS * 2;
3807
Chad Dupuisf73cb692014-02-26 04:15:06 -05003808 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003809 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04003810 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003811 mcp->out_mb |= MBX_15;
3812 /* debug q create issue in SR-IOV */
3813 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
3814 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003815
3816 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003817 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04003818 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04003819 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04003820 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003821 }
3822 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3823
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003824 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003825 if (rval != QLA_SUCCESS) {
3826 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
3827 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3828 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
3830 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003831 }
3832
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003833 return rval;
3834}
3835
3836int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003837qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003838{
3839 int rval;
3840 unsigned long flags;
3841 mbx_cmd_t mc;
3842 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003843 struct qla_hw_data *ha = vha->hw;
3844
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003845 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
3846 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003847
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003848 if (IS_SHADOW_REG_CAPABLE(ha))
3849 rsp->options |= BIT_13;
3850
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003851 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003852 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003853 mcp->mb[2] = MSW(LSD(rsp->dma));
3854 mcp->mb[3] = LSW(LSD(rsp->dma));
3855 mcp->mb[6] = MSW(MSD(rsp->dma));
3856 mcp->mb[7] = LSW(MSD(rsp->dma));
3857 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003858 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003859 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003860 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003861 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003862
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003863 mcp->mb[4] = rsp->id;
3864 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04003865 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003866 /* que out ptr index */
3867 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003868 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003869 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3870 mcp->in_mb = MBX_0;
3871 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003872 mcp->tov = MBX_TOV_SECONDS * 2;
3873
3874 if (IS_QLA81XX(ha)) {
3875 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
3876 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05003877 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003878 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
3879 mcp->in_mb |= MBX_1;
3880 /* debug q create issue in SR-IOV */
3881 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
3882 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003883
3884 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003885 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04003886 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003887 if (!IS_QLA83XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04003888 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003889 }
3890
3891 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3892
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003893 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003894 if (rval != QLA_SUCCESS) {
3895 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
3896 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3897 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003898 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
3899 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003900 }
3901
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003902 return rval;
3903}
3904
Andrew Vasquez8a659572009-02-08 20:50:12 -08003905int
3906qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3907{
3908 int rval;
3909 mbx_cmd_t mc;
3910 mbx_cmd_t *mcp = &mc;
3911
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003912 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
3913 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003914
3915 mcp->mb[0] = MBC_IDC_ACK;
3916 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3917 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3918 mcp->in_mb = MBX_0;
3919 mcp->tov = MBX_TOV_SECONDS;
3920 mcp->flags = 0;
3921 rval = qla2x00_mailbox_command(vha, mcp);
3922
3923 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003924 ql_dbg(ql_dbg_mbx, vha, 0x10da,
3925 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003926 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003927 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
3928 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003929 }
3930
3931 return rval;
3932}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003933
3934int
3935qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3936{
3937 int rval;
3938 mbx_cmd_t mc;
3939 mbx_cmd_t *mcp = &mc;
3940
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003941 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
3942 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003943
Chad Dupuisf73cb692014-02-26 04:15:06 -05003944 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
3945 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003946 return QLA_FUNCTION_FAILED;
3947
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003948 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3949 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3950 mcp->out_mb = MBX_1|MBX_0;
3951 mcp->in_mb = MBX_1|MBX_0;
3952 mcp->tov = MBX_TOV_SECONDS;
3953 mcp->flags = 0;
3954 rval = qla2x00_mailbox_command(vha, mcp);
3955
3956 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003957 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
3958 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3959 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003960 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003961 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
3962 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003963 *sector_size = mcp->mb[1];
3964 }
3965
3966 return rval;
3967}
3968
3969int
3970qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3971{
3972 int rval;
3973 mbx_cmd_t mc;
3974 mbx_cmd_t *mcp = &mc;
3975
Chad Dupuisf73cb692014-02-26 04:15:06 -05003976 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
3977 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003978 return QLA_FUNCTION_FAILED;
3979
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003980 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
3981 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003982
3983 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3984 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3985 FAC_OPT_CMD_WRITE_PROTECT;
3986 mcp->out_mb = MBX_1|MBX_0;
3987 mcp->in_mb = MBX_1|MBX_0;
3988 mcp->tov = MBX_TOV_SECONDS;
3989 mcp->flags = 0;
3990 rval = qla2x00_mailbox_command(vha, mcp);
3991
3992 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003993 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
3994 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3995 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003996 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003997 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
3998 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003999 }
4000
4001 return rval;
4002}
4003
4004int
4005qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4006{
4007 int rval;
4008 mbx_cmd_t mc;
4009 mbx_cmd_t *mcp = &mc;
4010
Chad Dupuisf73cb692014-02-26 04:15:06 -05004011 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4012 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004013 return QLA_FUNCTION_FAILED;
4014
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4016 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004017
4018 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4019 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4020 mcp->mb[2] = LSW(start);
4021 mcp->mb[3] = MSW(start);
4022 mcp->mb[4] = LSW(finish);
4023 mcp->mb[5] = MSW(finish);
4024 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4025 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4026 mcp->tov = MBX_TOV_SECONDS;
4027 mcp->flags = 0;
4028 rval = qla2x00_mailbox_command(vha, mcp);
4029
4030 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004031 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4032 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4033 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004034 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004035 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4036 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004037 }
4038
4039 return rval;
4040}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004041
4042int
4043qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4044{
4045 int rval = 0;
4046 mbx_cmd_t mc;
4047 mbx_cmd_t *mcp = &mc;
4048
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004049 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4050 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004051
4052 mcp->mb[0] = MBC_RESTART_MPI_FW;
4053 mcp->out_mb = MBX_0;
4054 mcp->in_mb = MBX_0|MBX_1;
4055 mcp->tov = MBX_TOV_SECONDS;
4056 mcp->flags = 0;
4057 rval = qla2x00_mailbox_command(vha, mcp);
4058
4059 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004060 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4061 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4062 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004063 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004064 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4065 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004066 }
4067
4068 return rval;
4069}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004070
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004071int
4072qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4073{
4074 int rval;
4075 mbx_cmd_t mc;
4076 mbx_cmd_t *mcp = &mc;
4077 int i;
4078 int len;
4079 uint16_t *str;
4080 struct qla_hw_data *ha = vha->hw;
4081
4082 if (!IS_P3P_TYPE(ha))
4083 return QLA_FUNCTION_FAILED;
4084
4085 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4086 "Entered %s.\n", __func__);
4087
4088 str = (void *)version;
4089 len = strlen(version);
4090
4091 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4092 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4093 mcp->out_mb = MBX_1|MBX_0;
4094 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4095 mcp->mb[i] = cpu_to_le16p(str);
4096 mcp->out_mb |= 1<<i;
4097 }
4098 for (; i < 16; i++) {
4099 mcp->mb[i] = 0;
4100 mcp->out_mb |= 1<<i;
4101 }
4102 mcp->in_mb = MBX_1|MBX_0;
4103 mcp->tov = MBX_TOV_SECONDS;
4104 mcp->flags = 0;
4105 rval = qla2x00_mailbox_command(vha, mcp);
4106
4107 if (rval != QLA_SUCCESS) {
4108 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4109 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4110 } else {
4111 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4112 "Done %s.\n", __func__);
4113 }
4114
4115 return rval;
4116}
4117
4118int
4119qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4120{
4121 int rval;
4122 mbx_cmd_t mc;
4123 mbx_cmd_t *mcp = &mc;
4124 int len;
4125 uint16_t dwlen;
4126 uint8_t *str;
4127 dma_addr_t str_dma;
4128 struct qla_hw_data *ha = vha->hw;
4129
4130 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4131 IS_P3P_TYPE(ha))
4132 return QLA_FUNCTION_FAILED;
4133
4134 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4135 "Entered %s.\n", __func__);
4136
4137 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4138 if (!str) {
4139 ql_log(ql_log_warn, vha, 0x117f,
4140 "Failed to allocate driver version param.\n");
4141 return QLA_MEMORY_ALLOC_FAILED;
4142 }
4143
4144 memcpy(str, "\x7\x3\x11\x0", 4);
4145 dwlen = str[0];
4146 len = dwlen * 4 - 4;
4147 memset(str + 4, 0, len);
4148 if (len > strlen(version))
4149 len = strlen(version);
4150 memcpy(str + 4, version, len);
4151
4152 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4153 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4154 mcp->mb[2] = MSW(LSD(str_dma));
4155 mcp->mb[3] = LSW(LSD(str_dma));
4156 mcp->mb[6] = MSW(MSD(str_dma));
4157 mcp->mb[7] = LSW(MSD(str_dma));
4158 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4159 mcp->in_mb = MBX_1|MBX_0;
4160 mcp->tov = MBX_TOV_SECONDS;
4161 mcp->flags = 0;
4162 rval = qla2x00_mailbox_command(vha, mcp);
4163
4164 if (rval != QLA_SUCCESS) {
4165 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4166 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4167 } else {
4168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4169 "Done %s.\n", __func__);
4170 }
4171
4172 dma_pool_free(ha->s_dma_pool, str, str_dma);
4173
4174 return rval;
4175}
4176
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004177static int
4178qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4179{
4180 int rval;
4181 mbx_cmd_t mc;
4182 mbx_cmd_t *mcp = &mc;
4183
4184 if (!IS_FWI2_CAPABLE(vha->hw))
4185 return QLA_FUNCTION_FAILED;
4186
4187 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4188 "Entered %s.\n", __func__);
4189
4190 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4191 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4192 mcp->out_mb = MBX_1|MBX_0;
4193 mcp->in_mb = MBX_1|MBX_0;
4194 mcp->tov = MBX_TOV_SECONDS;
4195 mcp->flags = 0;
4196 rval = qla2x00_mailbox_command(vha, mcp);
4197 *temp = mcp->mb[1];
4198
4199 if (rval != QLA_SUCCESS) {
4200 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4201 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4202 } else {
4203 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4204 "Done %s.\n", __func__);
4205 }
4206
4207 return rval;
4208}
4209
Joe Carnuccio3a117112013-02-08 01:58:00 -05004210int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004211qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4212 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004213{
4214 int rval;
4215 mbx_cmd_t mc;
4216 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004217 struct qla_hw_data *ha = vha->hw;
4218
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004219 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4220 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004221
Joe Carnuccio6766df92011-05-10 11:30:15 -07004222 if (!IS_FWI2_CAPABLE(ha))
4223 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004224
Joe Carnuccio6766df92011-05-10 11:30:15 -07004225 if (len == 1)
4226 opt |= BIT_0;
4227
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004228 mcp->mb[0] = MBC_READ_SFP;
4229 mcp->mb[1] = dev;
4230 mcp->mb[2] = MSW(sfp_dma);
4231 mcp->mb[3] = LSW(sfp_dma);
4232 mcp->mb[6] = MSW(MSD(sfp_dma));
4233 mcp->mb[7] = LSW(MSD(sfp_dma));
4234 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004235 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004236 mcp->mb[10] = opt;
4237 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 -07004238 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004239 mcp->tov = MBX_TOV_SECONDS;
4240 mcp->flags = 0;
4241 rval = qla2x00_mailbox_command(vha, mcp);
4242
4243 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004244 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004245
4246 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004247 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4248 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004249 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004250 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4251 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004252 }
4253
4254 return rval;
4255}
4256
4257int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004258qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4259 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004260{
4261 int rval;
4262 mbx_cmd_t mc;
4263 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004264 struct qla_hw_data *ha = vha->hw;
4265
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004266 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4267 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004268
Joe Carnuccio6766df92011-05-10 11:30:15 -07004269 if (!IS_FWI2_CAPABLE(ha))
4270 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004271
Joe Carnuccio6766df92011-05-10 11:30:15 -07004272 if (len == 1)
4273 opt |= BIT_0;
4274
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004275 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004276 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004277
4278 mcp->mb[0] = MBC_WRITE_SFP;
4279 mcp->mb[1] = dev;
4280 mcp->mb[2] = MSW(sfp_dma);
4281 mcp->mb[3] = LSW(sfp_dma);
4282 mcp->mb[6] = MSW(MSD(sfp_dma));
4283 mcp->mb[7] = LSW(MSD(sfp_dma));
4284 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004285 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004286 mcp->mb[10] = opt;
4287 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 -07004288 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004289 mcp->tov = MBX_TOV_SECONDS;
4290 mcp->flags = 0;
4291 rval = qla2x00_mailbox_command(vha, mcp);
4292
4293 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004294 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4295 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004296 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004297 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4298 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004299 }
4300
4301 return rval;
4302}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004303
4304int
4305qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4306 uint16_t size_in_bytes, uint16_t *actual_size)
4307{
4308 int rval;
4309 mbx_cmd_t mc;
4310 mbx_cmd_t *mcp = &mc;
4311
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004312 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4313 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004314
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004315 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004316 return QLA_FUNCTION_FAILED;
4317
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004318 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4319 mcp->mb[2] = MSW(stats_dma);
4320 mcp->mb[3] = LSW(stats_dma);
4321 mcp->mb[6] = MSW(MSD(stats_dma));
4322 mcp->mb[7] = LSW(MSD(stats_dma));
4323 mcp->mb[8] = size_in_bytes >> 2;
4324 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4325 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4326 mcp->tov = MBX_TOV_SECONDS;
4327 mcp->flags = 0;
4328 rval = qla2x00_mailbox_command(vha, mcp);
4329
4330 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004331 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4332 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4333 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004334 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004335 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4336 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004337
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004338
4339 *actual_size = mcp->mb[2] << 2;
4340 }
4341
4342 return rval;
4343}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004344
4345int
4346qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4347 uint16_t size)
4348{
4349 int rval;
4350 mbx_cmd_t mc;
4351 mbx_cmd_t *mcp = &mc;
4352
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004353 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4354 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004355
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004356 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004357 return QLA_FUNCTION_FAILED;
4358
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004359 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4360 mcp->mb[1] = 0;
4361 mcp->mb[2] = MSW(tlv_dma);
4362 mcp->mb[3] = LSW(tlv_dma);
4363 mcp->mb[6] = MSW(MSD(tlv_dma));
4364 mcp->mb[7] = LSW(MSD(tlv_dma));
4365 mcp->mb[8] = size;
4366 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4367 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4368 mcp->tov = MBX_TOV_SECONDS;
4369 mcp->flags = 0;
4370 rval = qla2x00_mailbox_command(vha, mcp);
4371
4372 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004373 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4374 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4375 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004376 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004377 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4378 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004379 }
4380
4381 return rval;
4382}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004383
4384int
4385qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4386{
4387 int rval;
4388 mbx_cmd_t mc;
4389 mbx_cmd_t *mcp = &mc;
4390
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4392 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004393
Andrew Vasquez18e75552009-06-03 09:55:30 -07004394 if (!IS_FWI2_CAPABLE(vha->hw))
4395 return QLA_FUNCTION_FAILED;
4396
Andrew Vasquez18e75552009-06-03 09:55:30 -07004397 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4398 mcp->mb[1] = LSW(risc_addr);
4399 mcp->mb[8] = MSW(risc_addr);
4400 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4401 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4402 mcp->tov = 30;
4403 mcp->flags = 0;
4404 rval = qla2x00_mailbox_command(vha, mcp);
4405 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004406 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4407 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004408 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004409 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4410 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004411 *data = mcp->mb[3] << 16 | mcp->mb[2];
4412 }
4413
4414 return rval;
4415}
4416
4417int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004418qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4419 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004420{
4421 int rval;
4422 mbx_cmd_t mc;
4423 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004424
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004425 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4426 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004427
4428 memset(mcp->mb, 0 , sizeof(mcp->mb));
4429 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4430 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4431
4432 /* transfer count */
4433 mcp->mb[10] = LSW(mreq->transfer_size);
4434 mcp->mb[11] = MSW(mreq->transfer_size);
4435
4436 /* send data address */
4437 mcp->mb[14] = LSW(mreq->send_dma);
4438 mcp->mb[15] = MSW(mreq->send_dma);
4439 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4440 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4441
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004442 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004443 mcp->mb[16] = LSW(mreq->rcv_dma);
4444 mcp->mb[17] = MSW(mreq->rcv_dma);
4445 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4446 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4447
4448 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004449 mcp->mb[18] = LSW(mreq->iteration_count);
4450 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004451
4452 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4453 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 -08004454 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004455 mcp->out_mb |= MBX_2;
4456 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4457
4458 mcp->buf_size = mreq->transfer_size;
4459 mcp->tov = MBX_TOV_SECONDS;
4460 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4461
4462 rval = qla2x00_mailbox_command(vha, mcp);
4463
4464 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004465 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4466 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4467 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4468 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004469 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4471 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004472 }
4473
4474 /* Copy mailbox information */
4475 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004476 return rval;
4477}
4478
4479int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004480qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4481 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004482{
4483 int rval;
4484 mbx_cmd_t mc;
4485 mbx_cmd_t *mcp = &mc;
4486 struct qla_hw_data *ha = vha->hw;
4487
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004488 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4489 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004490
4491 memset(mcp->mb, 0 , sizeof(mcp->mb));
4492 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
4493 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004494 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004495 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004496 mcp->mb[2] = vha->fcoe_fcf_idx;
4497 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004498 mcp->mb[16] = LSW(mreq->rcv_dma);
4499 mcp->mb[17] = MSW(mreq->rcv_dma);
4500 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4501 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4502
4503 mcp->mb[10] = LSW(mreq->transfer_size);
4504
4505 mcp->mb[14] = LSW(mreq->send_dma);
4506 mcp->mb[15] = MSW(mreq->send_dma);
4507 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4508 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4509
4510 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4511 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004512 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004513 mcp->out_mb |= MBX_2;
4514
4515 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004516 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4517 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004518 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004519 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004520 mcp->in_mb |= MBX_3;
4521
4522 mcp->tov = MBX_TOV_SECONDS;
4523 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4524 mcp->buf_size = mreq->transfer_size;
4525
4526 rval = qla2x00_mailbox_command(vha, mcp);
4527
4528 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004529 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4530 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4531 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004532 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4534 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004535 }
4536
4537 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004538 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004539 return rval;
4540}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004541
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004542int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004543qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004544{
4545 int rval;
4546 mbx_cmd_t mc;
4547 mbx_cmd_t *mcp = &mc;
4548
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004549 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004550 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004551
4552 mcp->mb[0] = MBC_ISP84XX_RESET;
4553 mcp->mb[1] = enable_diagnostic;
4554 mcp->out_mb = MBX_1|MBX_0;
4555 mcp->in_mb = MBX_1|MBX_0;
4556 mcp->tov = MBX_TOV_SECONDS;
4557 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004558 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004559
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004560 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004561 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004562 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004563 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4564 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004565
4566 return rval;
4567}
4568
4569int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004570qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4571{
4572 int rval;
4573 mbx_cmd_t mc;
4574 mbx_cmd_t *mcp = &mc;
4575
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004576 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4577 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004578
Andrew Vasquez18e75552009-06-03 09:55:30 -07004579 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004580 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004581
Andrew Vasquez18e75552009-06-03 09:55:30 -07004582 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4583 mcp->mb[1] = LSW(risc_addr);
4584 mcp->mb[2] = LSW(data);
4585 mcp->mb[3] = MSW(data);
4586 mcp->mb[8] = MSW(risc_addr);
4587 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4588 mcp->in_mb = MBX_0;
4589 mcp->tov = 30;
4590 mcp->flags = 0;
4591 rval = qla2x00_mailbox_command(vha, mcp);
4592 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004593 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4594 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004595 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004596 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4597 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004598 }
4599
4600 return rval;
4601}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004602
4603int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004604qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4605{
4606 int rval;
4607 uint32_t stat, timer;
4608 uint16_t mb0 = 0;
4609 struct qla_hw_data *ha = vha->hw;
4610 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4611
4612 rval = QLA_SUCCESS;
4613
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004614 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4615 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004616
4617 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4618
4619 /* Write the MBC data to the registers */
4620 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4621 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4622 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4623 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4624 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4625
4626 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4627
4628 /* Poll for MBC interrupt */
4629 for (timer = 6000000; timer; timer--) {
4630 /* Check for pending interrupts. */
4631 stat = RD_REG_DWORD(&reg->host_status);
4632 if (stat & HSRX_RISC_INT) {
4633 stat &= 0xff;
4634
4635 if (stat == 0x1 || stat == 0x2 ||
4636 stat == 0x10 || stat == 0x11) {
4637 set_bit(MBX_INTERRUPT,
4638 &ha->mbx_cmd_flags);
4639 mb0 = RD_REG_WORD(&reg->mailbox0);
4640 WRT_REG_DWORD(&reg->hccr,
4641 HCCRX_CLR_RISC_INT);
4642 RD_REG_DWORD(&reg->hccr);
4643 break;
4644 }
4645 }
4646 udelay(5);
4647 }
4648
4649 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4650 rval = mb0 & MBS_MASK;
4651 else
4652 rval = QLA_FUNCTION_FAILED;
4653
4654 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004655 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4656 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004657 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004658 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4659 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004660 }
4661
4662 return rval;
4663}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004664
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004665int
Michael Hernandez3064ff32009-12-15 21:29:44 -08004666qla2x00_get_data_rate(scsi_qla_host_t *vha)
4667{
4668 int rval;
4669 mbx_cmd_t mc;
4670 mbx_cmd_t *mcp = &mc;
4671 struct qla_hw_data *ha = vha->hw;
4672
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004673 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
4674 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004675
Michael Hernandez3064ff32009-12-15 21:29:44 -08004676 if (!IS_FWI2_CAPABLE(ha))
4677 return QLA_FUNCTION_FAILED;
4678
Michael Hernandez3064ff32009-12-15 21:29:44 -08004679 mcp->mb[0] = MBC_DATA_RATE;
4680 mcp->mb[1] = 0;
4681 mcp->out_mb = MBX_1|MBX_0;
4682 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004683 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004684 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08004685 mcp->tov = MBX_TOV_SECONDS;
4686 mcp->flags = 0;
4687 rval = qla2x00_mailbox_command(vha, mcp);
4688 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004689 ql_dbg(ql_dbg_mbx, vha, 0x1107,
4690 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08004691 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004692 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
4693 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08004694 if (mcp->mb[1] != 0x7)
4695 ha->link_data_rate = mcp->mb[1];
4696 }
4697
4698 return rval;
4699}
Sarang Radke09ff7012010-03-19 17:03:59 -07004700
4701int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004702qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4703{
4704 int rval;
4705 mbx_cmd_t mc;
4706 mbx_cmd_t *mcp = &mc;
4707 struct qla_hw_data *ha = vha->hw;
4708
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004709 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
4710 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004711
Chad Dupuisf73cb692014-02-26 04:15:06 -05004712 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
4713 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004714 return QLA_FUNCTION_FAILED;
4715 mcp->mb[0] = MBC_GET_PORT_CONFIG;
4716 mcp->out_mb = MBX_0;
4717 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4718 mcp->tov = MBX_TOV_SECONDS;
4719 mcp->flags = 0;
4720
4721 rval = qla2x00_mailbox_command(vha, mcp);
4722
4723 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004724 ql_dbg(ql_dbg_mbx, vha, 0x110a,
4725 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004726 } else {
4727 /* Copy all bits to preserve original value */
4728 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
4729
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004730 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
4731 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004732 }
4733 return rval;
4734}
4735
4736int
4737qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4738{
4739 int rval;
4740 mbx_cmd_t mc;
4741 mbx_cmd_t *mcp = &mc;
4742
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004743 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
4744 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004745
4746 mcp->mb[0] = MBC_SET_PORT_CONFIG;
4747 /* Copy all bits to preserve original setting */
4748 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
4749 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4750 mcp->in_mb = MBX_0;
4751 mcp->tov = MBX_TOV_SECONDS;
4752 mcp->flags = 0;
4753 rval = qla2x00_mailbox_command(vha, mcp);
4754
4755 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004756 ql_dbg(ql_dbg_mbx, vha, 0x110d,
4757 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004758 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004759 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
4760 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004761
4762 return rval;
4763}
4764
4765
4766int
Sarang Radke09ff7012010-03-19 17:03:59 -07004767qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
4768 uint16_t *mb)
4769{
4770 int rval;
4771 mbx_cmd_t mc;
4772 mbx_cmd_t *mcp = &mc;
4773 struct qla_hw_data *ha = vha->hw;
4774
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004775 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
4776 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004777
Sarang Radke09ff7012010-03-19 17:03:59 -07004778 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
4779 return QLA_FUNCTION_FAILED;
4780
Sarang Radke09ff7012010-03-19 17:03:59 -07004781 mcp->mb[0] = MBC_PORT_PARAMS;
4782 mcp->mb[1] = loop_id;
4783 if (ha->flags.fcp_prio_enabled)
4784 mcp->mb[2] = BIT_1;
4785 else
4786 mcp->mb[2] = BIT_2;
4787 mcp->mb[4] = priority & 0xf;
4788 mcp->mb[9] = vha->vp_idx;
4789 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4790 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4791 mcp->tov = 30;
4792 mcp->flags = 0;
4793 rval = qla2x00_mailbox_command(vha, mcp);
4794 if (mb != NULL) {
4795 mb[0] = mcp->mb[0];
4796 mb[1] = mcp->mb[1];
4797 mb[3] = mcp->mb[3];
4798 mb[4] = mcp->mb[4];
4799 }
4800
4801 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004802 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07004803 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004804 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
4805 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07004806 }
4807
4808 return rval;
4809}
Giridhar Malavalia9083012010-04-12 17:59:55 -07004810
4811int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004812qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08004813{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004814 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004815 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004816 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004817
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04004818 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
4819 ql_dbg(ql_dbg_mbx, vha, 0x1150,
4820 "Thermal not supported by this card.\n");
4821 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004822 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08004823
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04004824 if (IS_QLA25XX(ha)) {
4825 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4826 ha->pdev->subsystem_device == 0x0175) {
4827 rval = qla2x00_read_sfp(vha, 0, &byte,
4828 0x98, 0x1, 1, BIT_13|BIT_0);
4829 *temp = byte;
4830 return rval;
4831 }
4832 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
4833 ha->pdev->subsystem_device == 0x338e) {
4834 rval = qla2x00_read_sfp(vha, 0, &byte,
4835 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
4836 *temp = byte;
4837 return rval;
4838 }
4839 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
4840 "Thermal not supported by this card.\n");
4841 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004842 }
4843
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04004844 if (IS_QLA82XX(ha)) {
4845 *temp = qla82xx_read_temperature(vha);
4846 rval = QLA_SUCCESS;
4847 return rval;
4848 } else if (IS_QLA8044(ha)) {
4849 *temp = qla8044_read_temperature(vha);
4850 rval = QLA_SUCCESS;
4851 return rval;
4852 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004853
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04004854 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004855 return rval;
4856}
4857
4858int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004859qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
4860{
4861 int rval;
4862 struct qla_hw_data *ha = vha->hw;
4863 mbx_cmd_t mc;
4864 mbx_cmd_t *mcp = &mc;
4865
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004866 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
4867 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004868
Giridhar Malavalia9083012010-04-12 17:59:55 -07004869 if (!IS_FWI2_CAPABLE(ha))
4870 return QLA_FUNCTION_FAILED;
4871
Giridhar Malavalia9083012010-04-12 17:59:55 -07004872 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004873 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004874 mcp->mb[1] = 1;
4875
4876 mcp->out_mb = MBX_1|MBX_0;
4877 mcp->in_mb = MBX_0;
4878 mcp->tov = 30;
4879 mcp->flags = 0;
4880
4881 rval = qla2x00_mailbox_command(vha, mcp);
4882 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004883 ql_dbg(ql_dbg_mbx, vha, 0x1016,
4884 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004885 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004886 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
4887 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004888 }
4889
4890 return rval;
4891}
4892
4893int
4894qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
4895{
4896 int rval;
4897 struct qla_hw_data *ha = vha->hw;
4898 mbx_cmd_t mc;
4899 mbx_cmd_t *mcp = &mc;
4900
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004901 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
4902 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004903
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04004904 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07004905 return QLA_FUNCTION_FAILED;
4906
Giridhar Malavalia9083012010-04-12 17:59:55 -07004907 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004908 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004909 mcp->mb[1] = 0;
4910
4911 mcp->out_mb = MBX_1|MBX_0;
4912 mcp->in_mb = MBX_0;
4913 mcp->tov = 30;
4914 mcp->flags = 0;
4915
4916 rval = qla2x00_mailbox_command(vha, mcp);
4917 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004918 ql_dbg(ql_dbg_mbx, vha, 0x100c,
4919 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004920 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004921 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
4922 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004923 }
4924
4925 return rval;
4926}
Giridhar Malavali08de2842011-08-16 11:31:44 -07004927
4928int
4929qla82xx_md_get_template_size(scsi_qla_host_t *vha)
4930{
4931 struct qla_hw_data *ha = vha->hw;
4932 mbx_cmd_t mc;
4933 mbx_cmd_t *mcp = &mc;
4934 int rval = QLA_FUNCTION_FAILED;
4935
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004936 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
4937 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004938
4939 memset(mcp->mb, 0 , sizeof(mcp->mb));
4940 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4941 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4942 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
4943 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
4944
4945 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4946 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
4947 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4948
4949 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4950 mcp->tov = MBX_TOV_SECONDS;
4951 rval = qla2x00_mailbox_command(vha, mcp);
4952
4953 /* Always copy back return mailbox values. */
4954 if (rval != QLA_SUCCESS) {
4955 ql_dbg(ql_dbg_mbx, vha, 0x1120,
4956 "mailbox command FAILED=0x%x, subcode=%x.\n",
4957 (mcp->mb[1] << 16) | mcp->mb[0],
4958 (mcp->mb[3] << 16) | mcp->mb[2]);
4959 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004960 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
4961 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004962 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
4963 if (!ha->md_template_size) {
4964 ql_dbg(ql_dbg_mbx, vha, 0x1122,
4965 "Null template size obtained.\n");
4966 rval = QLA_FUNCTION_FAILED;
4967 }
4968 }
4969 return rval;
4970}
4971
4972int
4973qla82xx_md_get_template(scsi_qla_host_t *vha)
4974{
4975 struct qla_hw_data *ha = vha->hw;
4976 mbx_cmd_t mc;
4977 mbx_cmd_t *mcp = &mc;
4978 int rval = QLA_FUNCTION_FAILED;
4979
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004980 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
4981 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004982
4983 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
4984 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
4985 if (!ha->md_tmplt_hdr) {
4986 ql_log(ql_log_warn, vha, 0x1124,
4987 "Unable to allocate memory for Minidump template.\n");
4988 return rval;
4989 }
4990
4991 memset(mcp->mb, 0 , sizeof(mcp->mb));
4992 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4993 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4994 mcp->mb[2] = LSW(RQST_TMPLT);
4995 mcp->mb[3] = MSW(RQST_TMPLT);
4996 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
4997 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
4998 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
4999 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5000 mcp->mb[8] = LSW(ha->md_template_size);
5001 mcp->mb[9] = MSW(ha->md_template_size);
5002
5003 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5004 mcp->tov = MBX_TOV_SECONDS;
5005 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5006 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5007 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5008 rval = qla2x00_mailbox_command(vha, mcp);
5009
5010 if (rval != QLA_SUCCESS) {
5011 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5012 "mailbox command FAILED=0x%x, subcode=%x.\n",
5013 ((mcp->mb[1] << 16) | mcp->mb[0]),
5014 ((mcp->mb[3] << 16) | mcp->mb[2]));
5015 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005016 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5017 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005018 return rval;
5019}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005020
5021int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005022qla8044_md_get_template(scsi_qla_host_t *vha)
5023{
5024 struct qla_hw_data *ha = vha->hw;
5025 mbx_cmd_t mc;
5026 mbx_cmd_t *mcp = &mc;
5027 int rval = QLA_FUNCTION_FAILED;
5028 int offset = 0, size = MINIDUMP_SIZE_36K;
5029 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5030 "Entered %s.\n", __func__);
5031
5032 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5033 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5034 if (!ha->md_tmplt_hdr) {
5035 ql_log(ql_log_warn, vha, 0xb11b,
5036 "Unable to allocate memory for Minidump template.\n");
5037 return rval;
5038 }
5039
5040 memset(mcp->mb, 0 , sizeof(mcp->mb));
5041 while (offset < ha->md_template_size) {
5042 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5043 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5044 mcp->mb[2] = LSW(RQST_TMPLT);
5045 mcp->mb[3] = MSW(RQST_TMPLT);
5046 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5047 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5048 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5049 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5050 mcp->mb[8] = LSW(size);
5051 mcp->mb[9] = MSW(size);
5052 mcp->mb[10] = offset & 0x0000FFFF;
5053 mcp->mb[11] = offset & 0xFFFF0000;
5054 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5055 mcp->tov = MBX_TOV_SECONDS;
5056 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5057 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5058 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5059 rval = qla2x00_mailbox_command(vha, mcp);
5060
5061 if (rval != QLA_SUCCESS) {
5062 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5063 "mailbox command FAILED=0x%x, subcode=%x.\n",
5064 ((mcp->mb[1] << 16) | mcp->mb[0]),
5065 ((mcp->mb[3] << 16) | mcp->mb[2]));
5066 return rval;
5067 } else
5068 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5069 "Done %s.\n", __func__);
5070 offset = offset + size;
5071 }
5072 return rval;
5073}
5074
5075int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005076qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5077{
5078 int rval;
5079 struct qla_hw_data *ha = vha->hw;
5080 mbx_cmd_t mc;
5081 mbx_cmd_t *mcp = &mc;
5082
5083 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5084 return QLA_FUNCTION_FAILED;
5085
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005086 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5087 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005088
5089 memset(mcp, 0, sizeof(mbx_cmd_t));
5090 mcp->mb[0] = MBC_SET_LED_CONFIG;
5091 mcp->mb[1] = led_cfg[0];
5092 mcp->mb[2] = led_cfg[1];
5093 if (IS_QLA8031(ha)) {
5094 mcp->mb[3] = led_cfg[2];
5095 mcp->mb[4] = led_cfg[3];
5096 mcp->mb[5] = led_cfg[4];
5097 mcp->mb[6] = led_cfg[5];
5098 }
5099
5100 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5101 if (IS_QLA8031(ha))
5102 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5103 mcp->in_mb = MBX_0;
5104 mcp->tov = 30;
5105 mcp->flags = 0;
5106
5107 rval = qla2x00_mailbox_command(vha, mcp);
5108 if (rval != QLA_SUCCESS) {
5109 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5110 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5111 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005112 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5113 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005114 }
5115
5116 return rval;
5117}
5118
5119int
5120qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5121{
5122 int rval;
5123 struct qla_hw_data *ha = vha->hw;
5124 mbx_cmd_t mc;
5125 mbx_cmd_t *mcp = &mc;
5126
5127 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5128 return QLA_FUNCTION_FAILED;
5129
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005130 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5131 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005132
5133 memset(mcp, 0, sizeof(mbx_cmd_t));
5134 mcp->mb[0] = MBC_GET_LED_CONFIG;
5135
5136 mcp->out_mb = MBX_0;
5137 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5138 if (IS_QLA8031(ha))
5139 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5140 mcp->tov = 30;
5141 mcp->flags = 0;
5142
5143 rval = qla2x00_mailbox_command(vha, mcp);
5144 if (rval != QLA_SUCCESS) {
5145 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5146 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5147 } else {
5148 led_cfg[0] = mcp->mb[1];
5149 led_cfg[1] = mcp->mb[2];
5150 if (IS_QLA8031(ha)) {
5151 led_cfg[2] = mcp->mb[3];
5152 led_cfg[3] = mcp->mb[4];
5153 led_cfg[4] = mcp->mb[5];
5154 led_cfg[5] = mcp->mb[6];
5155 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005156 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5157 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005158 }
5159
5160 return rval;
5161}
5162
5163int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005164qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5165{
5166 int rval;
5167 struct qla_hw_data *ha = vha->hw;
5168 mbx_cmd_t mc;
5169 mbx_cmd_t *mcp = &mc;
5170
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005171 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005172 return QLA_FUNCTION_FAILED;
5173
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005174 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005175 "Entered %s.\n", __func__);
5176
5177 memset(mcp, 0, sizeof(mbx_cmd_t));
5178 mcp->mb[0] = MBC_SET_LED_CONFIG;
5179 if (enable)
5180 mcp->mb[7] = 0xE;
5181 else
5182 mcp->mb[7] = 0xD;
5183
5184 mcp->out_mb = MBX_7|MBX_0;
5185 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005186 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005187 mcp->flags = 0;
5188
5189 rval = qla2x00_mailbox_command(vha, mcp);
5190 if (rval != QLA_SUCCESS) {
5191 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5192 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5193 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005194 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005195 "Done %s.\n", __func__);
5196 }
5197
5198 return rval;
5199}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005200
5201int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005202qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005203{
5204 int rval;
5205 struct qla_hw_data *ha = vha->hw;
5206 mbx_cmd_t mc;
5207 mbx_cmd_t *mcp = &mc;
5208
Chad Dupuisf73cb692014-02-26 04:15:06 -05005209 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005210 return QLA_FUNCTION_FAILED;
5211
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005212 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5213 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005214
5215 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5216 mcp->mb[1] = LSW(reg);
5217 mcp->mb[2] = MSW(reg);
5218 mcp->mb[3] = LSW(data);
5219 mcp->mb[4] = MSW(data);
5220 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5221
5222 mcp->in_mb = MBX_1|MBX_0;
5223 mcp->tov = MBX_TOV_SECONDS;
5224 mcp->flags = 0;
5225 rval = qla2x00_mailbox_command(vha, mcp);
5226
5227 if (rval != QLA_SUCCESS) {
5228 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5229 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5230 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005231 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005232 "Done %s.\n", __func__);
5233 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005234
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005235 return rval;
5236}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005237
5238int
5239qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5240{
5241 int rval;
5242 struct qla_hw_data *ha = vha->hw;
5243 mbx_cmd_t mc;
5244 mbx_cmd_t *mcp = &mc;
5245
5246 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005247 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005248 "Implicit LOGO Unsupported.\n");
5249 return QLA_FUNCTION_FAILED;
5250 }
5251
5252
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005253 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5254 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005255
5256 /* Perform Implicit LOGO. */
5257 mcp->mb[0] = MBC_PORT_LOGOUT;
5258 mcp->mb[1] = fcport->loop_id;
5259 mcp->mb[10] = BIT_15;
5260 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5261 mcp->in_mb = MBX_0;
5262 mcp->tov = MBX_TOV_SECONDS;
5263 mcp->flags = 0;
5264 rval = qla2x00_mailbox_command(vha, mcp);
5265 if (rval != QLA_SUCCESS)
5266 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5267 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5268 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005269 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5270 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005271
5272 return rval;
5273}
5274
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005275int
5276qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5277{
5278 int rval;
5279 mbx_cmd_t mc;
5280 mbx_cmd_t *mcp = &mc;
5281 struct qla_hw_data *ha = vha->hw;
5282 unsigned long retry_max_time = jiffies + (2 * HZ);
5283
Chad Dupuisf73cb692014-02-26 04:15:06 -05005284 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005285 return QLA_FUNCTION_FAILED;
5286
5287 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5288
5289retry_rd_reg:
5290 mcp->mb[0] = MBC_READ_REMOTE_REG;
5291 mcp->mb[1] = LSW(reg);
5292 mcp->mb[2] = MSW(reg);
5293 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5294 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5295 mcp->tov = MBX_TOV_SECONDS;
5296 mcp->flags = 0;
5297 rval = qla2x00_mailbox_command(vha, mcp);
5298
5299 if (rval != QLA_SUCCESS) {
5300 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5301 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5302 rval, mcp->mb[0], mcp->mb[1]);
5303 } else {
5304 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5305 if (*data == QLA8XXX_BAD_VALUE) {
5306 /*
5307 * During soft-reset CAMRAM register reads might
5308 * return 0xbad0bad0. So retry for MAX of 2 sec
5309 * while reading camram registers.
5310 */
5311 if (time_after(jiffies, retry_max_time)) {
5312 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5313 "Failure to read CAMRAM register. "
5314 "data=0x%x.\n", *data);
5315 return QLA_FUNCTION_FAILED;
5316 }
5317 msleep(100);
5318 goto retry_rd_reg;
5319 }
5320 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5321 }
5322
5323 return rval;
5324}
5325
5326int
5327qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5328{
5329 int rval;
5330 mbx_cmd_t mc;
5331 mbx_cmd_t *mcp = &mc;
5332 struct qla_hw_data *ha = vha->hw;
5333
5334 if (!IS_QLA83XX(ha))
5335 return QLA_FUNCTION_FAILED;
5336
5337 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5338
5339 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5340 mcp->out_mb = MBX_0;
5341 mcp->in_mb = MBX_1|MBX_0;
5342 mcp->tov = MBX_TOV_SECONDS;
5343 mcp->flags = 0;
5344 rval = qla2x00_mailbox_command(vha, mcp);
5345
5346 if (rval != QLA_SUCCESS) {
5347 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5348 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5349 rval, mcp->mb[0], mcp->mb[1]);
5350 ha->isp_ops->fw_dump(vha, 0);
5351 } else {
5352 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5353 }
5354
5355 return rval;
5356}
5357
5358int
5359qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5360 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5361{
5362 int rval;
5363 mbx_cmd_t mc;
5364 mbx_cmd_t *mcp = &mc;
5365 uint8_t subcode = (uint8_t)options;
5366 struct qla_hw_data *ha = vha->hw;
5367
5368 if (!IS_QLA8031(ha))
5369 return QLA_FUNCTION_FAILED;
5370
5371 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5372
5373 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5374 mcp->mb[1] = options;
5375 mcp->out_mb = MBX_1|MBX_0;
5376 if (subcode & BIT_2) {
5377 mcp->mb[2] = LSW(start_addr);
5378 mcp->mb[3] = MSW(start_addr);
5379 mcp->mb[4] = LSW(end_addr);
5380 mcp->mb[5] = MSW(end_addr);
5381 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5382 }
5383 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5384 if (!(subcode & (BIT_2 | BIT_5)))
5385 mcp->in_mb |= MBX_4|MBX_3;
5386 mcp->tov = MBX_TOV_SECONDS;
5387 mcp->flags = 0;
5388 rval = qla2x00_mailbox_command(vha, mcp);
5389
5390 if (rval != QLA_SUCCESS) {
5391 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5392 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5393 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5394 mcp->mb[4]);
5395 ha->isp_ops->fw_dump(vha, 0);
5396 } else {
5397 if (subcode & BIT_5)
5398 *sector_size = mcp->mb[1];
5399 else if (subcode & (BIT_6 | BIT_7)) {
5400 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5401 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5402 } else if (subcode & (BIT_3 | BIT_4)) {
5403 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5404 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5405 }
5406 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5407 }
5408
5409 return rval;
5410}
Saurav Kashyap81178772012-08-22 14:21:04 -04005411
5412int
5413qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5414 uint32_t size)
5415{
5416 int rval;
5417 mbx_cmd_t mc;
5418 mbx_cmd_t *mcp = &mc;
5419
5420 if (!IS_MCTP_CAPABLE(vha->hw))
5421 return QLA_FUNCTION_FAILED;
5422
5423 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5424 "Entered %s.\n", __func__);
5425
5426 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5427 mcp->mb[1] = LSW(addr);
5428 mcp->mb[2] = MSW(req_dma);
5429 mcp->mb[3] = LSW(req_dma);
5430 mcp->mb[4] = MSW(size);
5431 mcp->mb[5] = LSW(size);
5432 mcp->mb[6] = MSW(MSD(req_dma));
5433 mcp->mb[7] = LSW(MSD(req_dma));
5434 mcp->mb[8] = MSW(addr);
5435 /* Setting RAM ID to valid */
5436 mcp->mb[10] |= BIT_7;
5437 /* For MCTP RAM ID is 0x40 */
5438 mcp->mb[10] |= 0x40;
5439
5440 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5441 MBX_0;
5442
5443 mcp->in_mb = MBX_0;
5444 mcp->tov = MBX_TOV_SECONDS;
5445 mcp->flags = 0;
5446 rval = qla2x00_mailbox_command(vha, mcp);
5447
5448 if (rval != QLA_SUCCESS) {
5449 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5450 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5451 } else {
5452 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5453 "Done %s.\n", __func__);
5454 }
5455
5456 return rval;
5457}