blob: cba1fc5e8be9d58fce789694b508734790689a83 [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
Quinn Tran15f30a52017-03-15 09:48:52 -070013static struct mb_cmd_name {
14 uint16_t cmd;
15 const char *str;
16} mb_str[] = {
17 {MBC_GET_PORT_DATABASE, "GPDB"},
18 {MBC_GET_ID_LIST, "GIDList"},
19 {MBC_GET_LINK_PRIV_STATS, "Stats"},
20};
21
22static const char *mb_to_str(uint16_t cmd)
23{
24 int i;
25 struct mb_cmd_name *e;
26
27 for (i = 0; i < ARRAY_SIZE(mb_str); i++) {
28 e = mb_str + i;
29 if (cmd == e->cmd)
30 return e->str;
31 }
32 return "unknown";
33}
34
Bart Van Asscheca825822017-01-17 09:34:14 -080035static struct rom_cmd {
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080036 uint16_t cmd;
37} rom_cmds[] = {
38 { MBC_LOAD_RAM },
39 { MBC_EXECUTE_FIRMWARE },
40 { MBC_READ_RAM_WORD },
41 { MBC_MAILBOX_REGISTER_TEST },
42 { MBC_VERIFY_CHECKSUM },
43 { MBC_GET_FIRMWARE_VERSION },
44 { MBC_LOAD_RISC_RAM },
45 { MBC_DUMP_RISC_RAM },
46 { MBC_LOAD_RISC_RAM_EXTENDED },
47 { MBC_DUMP_RISC_RAM_EXTENDED },
48 { MBC_WRITE_RAM_WORD_EXTENDED },
49 { MBC_READ_RAM_EXTENDED },
50 { MBC_GET_RESOURCE_COUNTS },
51 { MBC_SET_FIRMWARE_OPTION },
52 { MBC_MID_INITIALIZE_FIRMWARE },
53 { MBC_GET_FIRMWARE_STATE },
54 { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
55 { MBC_GET_RETRY_COUNT },
56 { MBC_TRACE_CONTROL },
57};
58
59static int is_rom_cmd(uint16_t cmd)
60{
61 int i;
62 struct rom_cmd *wc;
63
64 for (i = 0; i < ARRAY_SIZE(rom_cmds); i++) {
65 wc = rom_cmds + i;
66 if (wc->cmd == cmd)
67 return 1;
68 }
69
70 return 0;
71}
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/*
74 * qla2x00_mailbox_command
75 * Issue mailbox command and waits for completion.
76 *
77 * Input:
78 * ha = adapter block pointer.
79 * mcp = driver internal mbx struct pointer.
80 *
81 * Output:
82 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
83 *
84 * Returns:
85 * 0 : QLA_SUCCESS = cmd performed success
86 * 1 : QLA_FUNCTION_FAILED (error encountered)
87 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
88 *
89 * Context:
90 * Kernel context.
91 */
92static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080093qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040095 int rval, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned long flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -050097 device_reg_t *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070098 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070099 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700100 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 uint16_t *iptr;
102 uint16_t __iomem *optr;
103 uint32_t cnt;
104 uint32_t mboxes;
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400105 uint16_t __iomem *mbx_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800107 struct qla_hw_data *ha = vha->hw;
108 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700109
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400110
Arun Easi5e19ed92012-02-09 11:15:51 -0800111 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700112
113 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800114 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700115 "error_state is greater than pci_channel_io_frozen, "
116 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -0700117 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700118 }
Seokmann Jub9b12f72009-03-24 09:08:18 -0700119
Giridhar Malavalia9083012010-04-12 17:59:55 -0700120 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800121 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700122 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700123 return QLA_FUNCTION_TIMEOUT;
124 }
125
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800126 /* if PCI error, then avoid mbx processing.*/
127 if (test_bit(PCI_ERR, &base_vha->dpc_flags)) {
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400128 ql_log(ql_log_warn, vha, 0x1191,
129 "PCI error, exiting.\n");
130 return QLA_FUNCTION_TIMEOUT;
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800131 }
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400132
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700133 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800134 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800137 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700139
Andrew Vasquez85880802009-12-15 21:29:46 -0800140 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800141 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700142 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800143 return QLA_FUNCTION_TIMEOUT;
144 }
145
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400146 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -0800147 /* Setting Link-Down error */
148 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -0800149 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700150 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -0800151 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -0800152 }
153
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800154 /* check if ISP abort is active and return cmd with timeout */
155 if ((test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
156 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
157 test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) &&
158 !is_rom_cmd(mcp->mb[0])) {
159 ql_log(ql_log_info, vha, 0x1005,
160 "Cmd 0x%x aborted with timeout since ISP Abort is pending\n",
161 mcp->mb[0]);
162 return QLA_FUNCTION_TIMEOUT;
163 }
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700166 * Wait for active mailbox commands to finish by waiting at most tov
167 * seconds. This is to serialize actual issuing of mailbox cmds during
168 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800170 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
171 /* Timeout occurred. Return error. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800172 ql_log(ql_log_warn, vha, 0x1005,
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800173 "Cmd access timeout, cmd=0x%x, Exiting.\n",
174 mcp->mb[0]);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800175 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 }
177
178 ha->flags.mbox_busy = 1;
179 /* Save mailbox command for debug */
180 ha->mcp = mcp;
181
Arun Easi5e19ed92012-02-09 11:15:51 -0800182 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700183 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 spin_lock_irqsave(&ha->hardware_lock, flags);
186
187 /* Load mailbox registers. */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400188 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700189 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400190 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha)))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700191 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
192 else
193 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 iptr = mcp->mb;
196 command = mcp->mb[0];
197 mboxes = mcp->out_mb;
198
Joe Carnuccio7b711622014-09-25 05:16:43 -0400199 ql_dbg(ql_dbg_mbx, vha, 0x1111,
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700200 "Mailbox registers (OUT):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
202 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700203 optr =
204 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700205 if (mboxes & BIT_0) {
206 ql_dbg(ql_dbg_mbx, vha, 0x1112,
207 "mbox[%d]<-0x%04x\n", cnt, *iptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 WRT_REG_WORD(optr, *iptr);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700209 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 mboxes >>= 1;
212 optr++;
213 iptr++;
214 }
215
Arun Easi5e19ed92012-02-09 11:15:51 -0800216 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700217 "I/O Address = %p.\n", optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 /* Issue set host interrupt command to send cmd out. */
220 ha->flags.mbox_int = 0;
221 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
222
223 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800224 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700225 "Going to unlock irq & waiting for interrupts. "
226 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 /* Wait for mbx cmd completion until timeout */
229
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800230 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
232
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400233 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700234 if (RD_REG_DWORD(&reg->isp82.hint) &
235 HINT_MBX_INT_PENDING) {
236 spin_unlock_irqrestore(&ha->hardware_lock,
237 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800238 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800239 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700240 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700241 rval = QLA_FUNCTION_TIMEOUT;
242 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700243 }
244 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
245 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700246 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
247 else
248 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
250
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800251 wait_time = jiffies;
Giridhar Malavali754d1242013-06-25 11:27:16 -0400252 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
253 mcp->tov * HZ)) {
254 ql_dbg(ql_dbg_mbx, vha, 0x117a,
255 "cmd=%x Timeout.\n", command);
256 spin_lock_irqsave(&ha->hardware_lock, flags);
257 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
258 spin_unlock_irqrestore(&ha->hardware_lock, flags);
259 }
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800260 if (time_after(jiffies, wait_time + 5 * HZ))
261 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
262 command, jiffies_to_msecs(jiffies - wait_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800264 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700265 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400267 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700268 if (RD_REG_DWORD(&reg->isp82.hint) &
269 HINT_MBX_INT_PENDING) {
270 spin_unlock_irqrestore(&ha->hardware_lock,
271 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800272 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800273 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700274 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700275 rval = QLA_FUNCTION_TIMEOUT;
276 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700277 }
278 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
279 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700280 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
281 else
282 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
286 while (!ha->flags.mbox_int) {
287 if (time_after(jiffies, wait_time))
288 break;
289
290 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800291 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Andrew Vasquez85880802009-12-15 21:29:46 -0800293 if (!ha->flags.mbox_int &&
294 !(IS_QLA2200(ha) &&
295 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800296 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800298 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700299 "Waited %d sec.\n",
300 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 }
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 /* Check whether we timed out */
304 if (ha->flags.mbox_int) {
305 uint16_t *iptr2;
306
Arun Easi5e19ed92012-02-09 11:15:51 -0800307 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700308 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 /* Got interrupt. Clear the flag. */
311 ha->flags.mbox_int = 0;
312 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
313
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400314 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700315 ha->flags.mbox_busy = 0;
316 /* Setting Link-Down error */
317 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
318 ha->mcp = NULL;
319 rval = QLA_FUNCTION_FAILED;
Arun Easi5e19ed92012-02-09 11:15:51 -0800320 ql_log(ql_log_warn, vha, 0x1015,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700321 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700322 goto premature_exit;
323 }
324
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400325 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Load return mailbox registers. */
329 iptr2 = mcp->mb;
330 iptr = (uint16_t *)&ha->mailbox_out[0];
331 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700332
333 ql_dbg(ql_dbg_mbx, vha, 0x1113,
334 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700336 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700338 ql_dbg(ql_dbg_mbx, vha, 0x1114,
339 "mbox[%d]->0x%04x\n", cnt, *iptr2);
340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 mboxes >>= 1;
343 iptr2++;
344 iptr++;
345 }
346 } else {
347
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800348 uint16_t mb[8];
349 uint32_t ictrl, host_status, hccr;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400350 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700351
Andrew Vasqueze4289242007-07-19 15:05:56 -0700352 if (IS_FWI2_CAPABLE(ha)) {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800353 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
354 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
355 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
356 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
357 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700358 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800359 host_status = RD_REG_DWORD(&reg->isp24.host_status);
360 hccr = RD_REG_DWORD(&reg->isp24.hccr);
361
362 ql_log(ql_log_warn, vha, 0x1119,
363 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
364 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
365 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
366 mb[7], host_status, hccr);
367
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700368 } else {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800369 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700370 ictrl = RD_REG_WORD(&reg->isp.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800371 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
372 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
373 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700374 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800375 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400377 /* Capture FW dump only, if PCI device active */
378 if (!pci_channel_offline(vha->hw->pdev)) {
379 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
380 if (w == 0xffff || ictrl == 0xffffffff) {
381 /* This is special case if there is unload
382 * of driver happening and if PCI device go
383 * into bad state due to PCI error condition
384 * then only PCI ERR flag would be set.
385 * we will do premature exit for above case.
386 */
387 if (test_bit(UNLOADING, &base_vha->dpc_flags))
388 set_bit(PCI_ERR, &base_vha->dpc_flags);
389 ha->flags.mbox_busy = 0;
390 rval = QLA_FUNCTION_TIMEOUT;
391 goto premature_exit;
392 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800393
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400394 /* Attempt to capture firmware dump for further
395 * anallysis of the current formware state. we do not
396 * need to do this if we are intentionally generating
397 * a dump
398 */
399 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
400 ha->isp_ops->fw_dump(vha, 0);
401 rval = QLA_FUNCTION_TIMEOUT;
402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 }
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 ha->flags.mbox_busy = 0;
406
407 /* Clean up */
408 ha->mcp = NULL;
409
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800410 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800411 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700412 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800415 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700418 if (rval == QLA_FUNCTION_TIMEOUT &&
419 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800420 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
421 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800423 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700424 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700425
426 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
427 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
428 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800429 if (IS_QLA82XX(ha)) {
430 ql_dbg(ql_dbg_mbx, vha, 0x112a,
431 "disabling pause transmit on port "
432 "0 & 1.\n");
433 qla82xx_wr_32(ha,
434 QLA82XX_CRB_NIU + 0x98,
435 CRB_NIU_XG_PAUSE_CTL_P0|
436 CRB_NIU_XG_PAUSE_CTL_P1);
437 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700438 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400439 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800440 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
441 "abort.\n", command, mcp->mb[0],
442 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700443 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
444 qla2xxx_wake_dpc(vha);
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800448 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700449 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700451 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
452 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
453 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800454 if (IS_QLA82XX(ha)) {
455 ql_dbg(ql_dbg_mbx, vha, 0x112b,
456 "disabling pause transmit on port "
457 "0 & 1.\n");
458 qla82xx_wr_32(ha,
459 QLA82XX_CRB_NIU + 0x98,
460 CRB_NIU_XG_PAUSE_CTL_P0|
461 CRB_NIU_XG_PAUSE_CTL_P1);
462 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700463 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400464 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800465 "mb[0]=0x%x. Scheduling ISP abort ",
466 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700467 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
468 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800469 /* Allow next mbx cmd to come in. */
470 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700471 if (ha->isp_ops->abort_isp(vha)) {
472 /* Failed. retry later. */
473 set_bit(ISP_ABORT_NEEDED,
474 &vha->dpc_flags);
475 }
476 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800477 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700478 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800479 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482 }
483
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700484premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800486 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Giridhar Malavalid3360962012-02-09 11:14:10 -0800488mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 if (rval) {
Chad Dupuis34c58012014-08-08 07:38:08 -0400490 ql_dbg(ql_dbg_disc, base_vha, 0x1020,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800491 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
492 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400493
Sawan Chandak75d560e2016-07-06 11:14:33 -0400494 ql_dbg(ql_dbg_mbx, vha, 0x1198,
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400495 "host status: 0x%x, flags:0x%lx, intr ctrl reg:0x%x, intr status:0x%x\n",
496 RD_REG_DWORD(&reg->isp24.host_status),
497 ha->fw_dump_cap_flags,
498 RD_REG_DWORD(&reg->isp24.ictrl),
499 RD_REG_DWORD(&reg->isp24.istatus));
500
501 mbx_reg = &reg->isp24.mailbox0;
502 for (i = 0; i < 6; i++)
Sawan Chandak75d560e2016-07-06 11:14:33 -0400503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1199,
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400504 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700506 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 }
508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 return rval;
510}
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800513qla2x00_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 -0800514 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
516 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800517 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 mbx_cmd_t mc;
519 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400521 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
522 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Andrew Vasqueze4289242007-07-19 15:05:56 -0700524 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800525 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
526 mcp->mb[8] = MSW(risc_addr);
527 mcp->out_mb = MBX_8|MBX_0;
528 } else {
529 mcp->mb[0] = MBC_LOAD_RISC_RAM;
530 mcp->out_mb = MBX_0;
531 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 mcp->mb[1] = LSW(risc_addr);
533 mcp->mb[2] = MSW(req_dma);
534 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 mcp->mb[6] = MSW(MSD(req_dma));
536 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800537 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700538 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700539 mcp->mb[4] = MSW(risc_code_size);
540 mcp->mb[5] = LSW(risc_code_size);
541 mcp->out_mb |= MBX_5|MBX_4;
542 } else {
543 mcp->mb[4] = LSW(risc_code_size);
544 mcp->out_mb |= MBX_4;
545 }
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700548 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800550 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700553 ql_dbg(ql_dbg_mbx, vha, 0x1023,
554 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400556 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
557 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 }
559
560 return rval;
561}
562
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700563#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564/*
565 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700566 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 *
568 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700569 * ha = adapter block pointer.
570 * TARGET_QUEUE_LOCK must be released.
571 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 *
573 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700574 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 *
576 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700577 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 */
579int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800580qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
582 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800583 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 mbx_cmd_t mc;
585 mbx_cmd_t *mcp = &mc;
586
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400587 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
588 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700591 mcp->out_mb = MBX_0;
592 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700593 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700594 mcp->mb[1] = MSW(risc_addr);
595 mcp->mb[2] = LSW(risc_addr);
596 mcp->mb[3] = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500597 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
598 IS_QLA27XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700599 struct nvram_81xx *nv = ha->nvram;
600 mcp->mb[4] = (nv->enhanced_features &
601 EXTENDED_BB_CREDITS);
602 } else
603 mcp->mb[4] = 0;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500604
605 if (ha->flags.exlogins_enabled)
606 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
607
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500608 if (ha->flags.exchoffld_enabled)
609 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
610
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700611 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700612 mcp->in_mb |= MBX_1;
613 } else {
614 mcp->mb[1] = LSW(risc_addr);
615 mcp->out_mb |= MBX_1;
616 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
617 mcp->mb[2] = 0;
618 mcp->out_mb |= MBX_2;
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621
Ravi Anandb93480e2008-04-03 13:13:25 -0700622 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800624 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700626 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700627 ql_dbg(ql_dbg_mbx, vha, 0x1026,
628 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700629 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700630 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400631 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700632 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700633 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400634 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
635 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700636 }
637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 return rval;
640}
641
642/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500643 * qla_get_exlogin_status
644 * Get extended login status
645 * uses the memory offload control/status Mailbox
646 *
647 * Input:
648 * ha: adapter state pointer.
649 * fwopt: firmware options
650 *
651 * Returns:
652 * qla2x00 local function status
653 *
654 * Context:
655 * Kernel context.
656 */
657#define FETCH_XLOGINS_STAT 0x8
658int
659qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
660 uint16_t *ex_logins_cnt)
661{
662 int rval;
663 mbx_cmd_t mc;
664 mbx_cmd_t *mcp = &mc;
665
666 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
667 "Entered %s\n", __func__);
668
669 memset(mcp->mb, 0 , sizeof(mcp->mb));
670 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
671 mcp->mb[1] = FETCH_XLOGINS_STAT;
672 mcp->out_mb = MBX_1|MBX_0;
673 mcp->in_mb = MBX_10|MBX_4|MBX_0;
674 mcp->tov = MBX_TOV_SECONDS;
675 mcp->flags = 0;
676
677 rval = qla2x00_mailbox_command(vha, mcp);
678 if (rval != QLA_SUCCESS) {
679 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
680 } else {
681 *buf_sz = mcp->mb[4];
682 *ex_logins_cnt = mcp->mb[10];
683
684 ql_log(ql_log_info, vha, 0x1190,
685 "buffer size 0x%x, exchange login count=%d\n",
686 mcp->mb[4], mcp->mb[10]);
687
688 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
689 "Done %s.\n", __func__);
690 }
691
692 return rval;
693}
694
695/*
696 * qla_set_exlogin_mem_cfg
697 * set extended login memory configuration
698 * Mbx needs to be issues before init_cb is set
699 *
700 * Input:
701 * ha: adapter state pointer.
702 * buffer: buffer pointer
703 * phys_addr: physical address of buffer
704 * size: size of buffer
705 * TARGET_QUEUE_LOCK must be released
706 * ADAPTER_STATE_LOCK must be release
707 *
708 * Returns:
709 * qla2x00 local funxtion status code.
710 *
711 * Context:
712 * Kernel context.
713 */
714#define CONFIG_XLOGINS_MEM 0x3
715int
716qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
717{
718 int rval;
719 mbx_cmd_t mc;
720 mbx_cmd_t *mcp = &mc;
721 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500722
723 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
724 "Entered %s.\n", __func__);
725
726 memset(mcp->mb, 0 , sizeof(mcp->mb));
727 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
728 mcp->mb[1] = CONFIG_XLOGINS_MEM;
729 mcp->mb[2] = MSW(phys_addr);
730 mcp->mb[3] = LSW(phys_addr);
731 mcp->mb[6] = MSW(MSD(phys_addr));
732 mcp->mb[7] = LSW(MSD(phys_addr));
733 mcp->mb[8] = MSW(ha->exlogin_size);
734 mcp->mb[9] = LSW(ha->exlogin_size);
735 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
736 mcp->in_mb = MBX_11|MBX_0;
737 mcp->tov = MBX_TOV_SECONDS;
738 mcp->flags = 0;
739 rval = qla2x00_mailbox_command(vha, mcp);
740 if (rval != QLA_SUCCESS) {
741 /*EMPTY*/
742 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
743 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500744 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
745 "Done %s.\n", __func__);
746 }
747
748 return rval;
749}
750
751/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500752 * qla_get_exchoffld_status
753 * Get exchange offload status
754 * uses the memory offload control/status Mailbox
755 *
756 * Input:
757 * ha: adapter state pointer.
758 * fwopt: firmware options
759 *
760 * Returns:
761 * qla2x00 local function status
762 *
763 * Context:
764 * Kernel context.
765 */
766#define FETCH_XCHOFFLD_STAT 0x2
767int
768qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
769 uint16_t *ex_logins_cnt)
770{
771 int rval;
772 mbx_cmd_t mc;
773 mbx_cmd_t *mcp = &mc;
774
775 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
776 "Entered %s\n", __func__);
777
778 memset(mcp->mb, 0 , sizeof(mcp->mb));
779 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
780 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
781 mcp->out_mb = MBX_1|MBX_0;
782 mcp->in_mb = MBX_10|MBX_4|MBX_0;
783 mcp->tov = MBX_TOV_SECONDS;
784 mcp->flags = 0;
785
786 rval = qla2x00_mailbox_command(vha, mcp);
787 if (rval != QLA_SUCCESS) {
788 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
789 } else {
790 *buf_sz = mcp->mb[4];
791 *ex_logins_cnt = mcp->mb[10];
792
793 ql_log(ql_log_info, vha, 0x118e,
794 "buffer size 0x%x, exchange offload count=%d\n",
795 mcp->mb[4], mcp->mb[10]);
796
797 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
798 "Done %s.\n", __func__);
799 }
800
801 return rval;
802}
803
804/*
805 * qla_set_exchoffld_mem_cfg
806 * Set exchange offload memory configuration
807 * Mbx needs to be issues before init_cb is set
808 *
809 * Input:
810 * ha: adapter state pointer.
811 * buffer: buffer pointer
812 * phys_addr: physical address of buffer
813 * size: size of buffer
814 * TARGET_QUEUE_LOCK must be released
815 * ADAPTER_STATE_LOCK must be release
816 *
817 * Returns:
818 * qla2x00 local funxtion status code.
819 *
820 * Context:
821 * Kernel context.
822 */
823#define CONFIG_XCHOFFLD_MEM 0x3
824int
825qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
826{
827 int rval;
828 mbx_cmd_t mc;
829 mbx_cmd_t *mcp = &mc;
830 struct qla_hw_data *ha = vha->hw;
831
832 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
833 "Entered %s.\n", __func__);
834
835 memset(mcp->mb, 0 , sizeof(mcp->mb));
836 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
837 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
838 mcp->mb[2] = MSW(phys_addr);
839 mcp->mb[3] = LSW(phys_addr);
840 mcp->mb[6] = MSW(MSD(phys_addr));
841 mcp->mb[7] = LSW(MSD(phys_addr));
842 mcp->mb[8] = MSW(ha->exlogin_size);
843 mcp->mb[9] = LSW(ha->exlogin_size);
844 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
845 mcp->in_mb = MBX_11|MBX_0;
846 mcp->tov = MBX_TOV_SECONDS;
847 mcp->flags = 0;
848 rval = qla2x00_mailbox_command(vha, mcp);
849 if (rval != QLA_SUCCESS) {
850 /*EMPTY*/
851 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
852 } else {
853 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
854 "Done %s.\n", __func__);
855 }
856
857 return rval;
858}
859
860/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 * qla2x00_get_fw_version
862 * Get firmware version.
863 *
864 * Input:
865 * ha: adapter state pointer.
866 * major: pointer for major number.
867 * minor: pointer for minor number.
868 * subminor: pointer for subminor number.
869 *
870 * Returns:
871 * qla2x00 local function return status code.
872 *
873 * Context:
874 * Kernel context.
875 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700876int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800877qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878{
879 int rval;
880 mbx_cmd_t mc;
881 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800882 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400884 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
885 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
888 mcp->out_mb = MBX_0;
889 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400890 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700891 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400892 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800893 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500894 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400895 mcp->in_mb |=
896 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
897 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -0400898
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700900 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800901 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700902 if (rval != QLA_SUCCESS)
903 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800906 ha->fw_major_version = mcp->mb[1];
907 ha->fw_minor_version = mcp->mb[2];
908 ha->fw_subminor_version = mcp->mb[3];
909 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800910 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800911 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800913 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -0400914
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400915 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800916 ha->mpi_version[0] = mcp->mb[10] & 0xff;
917 ha->mpi_version[1] = mcp->mb[11] >> 8;
918 ha->mpi_version[2] = mcp->mb[11] & 0xff;
919 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
920 ha->phy_version[0] = mcp->mb[8] & 0xff;
921 ha->phy_version[1] = mcp->mb[9] >> 8;
922 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800923 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400924
Saurav Kashyap81178772012-08-22 14:21:04 -0400925 if (IS_FWI2_CAPABLE(ha)) {
926 ha->fw_attributes_h = mcp->mb[15];
927 ha->fw_attributes_ext[0] = mcp->mb[16];
928 ha->fw_attributes_ext[1] = mcp->mb[17];
929 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
930 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
931 __func__, mcp->mb[15], mcp->mb[6]);
932 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
933 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
934 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500935
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500936 if (ha->fw_attributes_h & 0x4)
937 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
938 "%s: Firmware supports Extended Login 0x%x\n",
939 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500940
941 if (ha->fw_attributes_h & 0x8)
942 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
943 "%s: Firmware supports Exchange Offload 0x%x\n",
944 __func__, ha->fw_attributes_h);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800945 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400946
Chad Dupuisf73cb692014-02-26 04:15:06 -0500947 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -0400948 ha->mpi_version[0] = mcp->mb[10] & 0xff;
949 ha->mpi_version[1] = mcp->mb[11] >> 8;
950 ha->mpi_version[2] = mcp->mb[11] & 0xff;
951 ha->pep_version[0] = mcp->mb[13] & 0xff;
952 ha->pep_version[1] = mcp->mb[14] >> 8;
953 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500954 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
955 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400956 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
957 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -0500958 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800959
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700960failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 if (rval != QLA_SUCCESS) {
962 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700963 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 } else {
965 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400966 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
967 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700969 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}
971
972/*
973 * qla2x00_get_fw_options
974 * Set firmware options.
975 *
976 * Input:
977 * ha = adapter block pointer.
978 * fwopt = pointer for firmware options.
979 *
980 * Returns:
981 * qla2x00 local function return status code.
982 *
983 * Context:
984 * Kernel context.
985 */
986int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800987qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988{
989 int rval;
990 mbx_cmd_t mc;
991 mbx_cmd_t *mcp = &mc;
992
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400993 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
994 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
997 mcp->out_mb = MBX_0;
998 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700999 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001001 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003 if (rval != QLA_SUCCESS) {
1004 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001005 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001007 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 fwopts[1] = mcp->mb[1];
1009 fwopts[2] = mcp->mb[2];
1010 fwopts[3] = mcp->mb[3];
1011
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001012 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1013 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 }
1015
1016 return rval;
1017}
1018
1019
1020/*
1021 * qla2x00_set_fw_options
1022 * Set firmware options.
1023 *
1024 * Input:
1025 * ha = adapter block pointer.
1026 * fwopt = pointer for firmware options.
1027 *
1028 * Returns:
1029 * qla2x00 local function return status code.
1030 *
1031 * Context:
1032 * Kernel context.
1033 */
1034int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001035qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036{
1037 int rval;
1038 mbx_cmd_t mc;
1039 mbx_cmd_t *mcp = &mc;
1040
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001041 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1042 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043
1044 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1045 mcp->mb[1] = fwopts[1];
1046 mcp->mb[2] = fwopts[2];
1047 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001048 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001050 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001051 mcp->in_mb |= MBX_1;
1052 } else {
1053 mcp->mb[10] = fwopts[10];
1054 mcp->mb[11] = fwopts[11];
1055 mcp->mb[12] = 0; /* Undocumented, but used */
1056 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1057 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001058 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001060 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001062 fwopts[0] = mcp->mb[0];
1063
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 if (rval != QLA_SUCCESS) {
1065 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001066 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1067 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 } else {
1069 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001070 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1071 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 }
1073
1074 return rval;
1075}
1076
1077/*
1078 * qla2x00_mbx_reg_test
1079 * Mailbox register wrap test.
1080 *
1081 * Input:
1082 * ha = adapter block pointer.
1083 * TARGET_QUEUE_LOCK must be released.
1084 * ADAPTER_STATE_LOCK must be released.
1085 *
1086 * Returns:
1087 * qla2x00 local function return status code.
1088 *
1089 * Context:
1090 * Kernel context.
1091 */
1092int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001093qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094{
1095 int rval;
1096 mbx_cmd_t mc;
1097 mbx_cmd_t *mcp = &mc;
1098
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001099 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1100 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
1102 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1103 mcp->mb[1] = 0xAAAA;
1104 mcp->mb[2] = 0x5555;
1105 mcp->mb[3] = 0xAA55;
1106 mcp->mb[4] = 0x55AA;
1107 mcp->mb[5] = 0xA5A5;
1108 mcp->mb[6] = 0x5A5A;
1109 mcp->mb[7] = 0x2525;
1110 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1111 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 -07001112 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001114 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 if (rval == QLA_SUCCESS) {
1117 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1118 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1119 rval = QLA_FUNCTION_FAILED;
1120 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1121 mcp->mb[7] != 0x2525)
1122 rval = QLA_FUNCTION_FAILED;
1123 }
1124
1125 if (rval != QLA_SUCCESS) {
1126 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001127 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 } else {
1129 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001130 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1131 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 }
1133
1134 return rval;
1135}
1136
1137/*
1138 * qla2x00_verify_checksum
1139 * Verify firmware checksum.
1140 *
1141 * Input:
1142 * ha = adapter block pointer.
1143 * TARGET_QUEUE_LOCK must be released.
1144 * ADAPTER_STATE_LOCK must be released.
1145 *
1146 * Returns:
1147 * qla2x00 local function return status code.
1148 *
1149 * Context:
1150 * Kernel context.
1151 */
1152int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001153qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
1155 int rval;
1156 mbx_cmd_t mc;
1157 mbx_cmd_t *mcp = &mc;
1158
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001159 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1160 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
1162 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001163 mcp->out_mb = MBX_0;
1164 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001165 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001166 mcp->mb[1] = MSW(risc_addr);
1167 mcp->mb[2] = LSW(risc_addr);
1168 mcp->out_mb |= MBX_2|MBX_1;
1169 mcp->in_mb |= MBX_2|MBX_1;
1170 } else {
1171 mcp->mb[1] = LSW(risc_addr);
1172 mcp->out_mb |= MBX_1;
1173 mcp->in_mb |= MBX_1;
1174 }
1175
Ravi Anandb93480e2008-04-03 13:13:25 -07001176 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001181 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1182 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1183 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001185 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1186 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 }
1188
1189 return rval;
1190}
1191
1192/*
1193 * qla2x00_issue_iocb
1194 * Issue IOCB using mailbox command
1195 *
1196 * Input:
1197 * ha = adapter state pointer.
1198 * buffer = buffer pointer.
1199 * phys_addr = physical address of buffer.
1200 * size = size of buffer.
1201 * TARGET_QUEUE_LOCK must be released.
1202 * ADAPTER_STATE_LOCK must be released.
1203 *
1204 * Returns:
1205 * qla2x00 local function return status code.
1206 *
1207 * Context:
1208 * Kernel context.
1209 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001210int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001211qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001212 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213{
1214 int rval;
1215 mbx_cmd_t mc;
1216 mbx_cmd_t *mcp = &mc;
1217
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001218 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1219 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001220
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1222 mcp->mb[1] = 0;
1223 mcp->mb[2] = MSW(phys_addr);
1224 mcp->mb[3] = LSW(phys_addr);
1225 mcp->mb[6] = MSW(MSD(phys_addr));
1226 mcp->mb[7] = LSW(MSD(phys_addr));
1227 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1228 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001229 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001231 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (rval != QLA_SUCCESS) {
1234 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001235 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001237 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1238
1239 /* Mask reserved bits. */
1240 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001241 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1243 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 }
1245
1246 return rval;
1247}
1248
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001249int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001250qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001251 size_t size)
1252{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001253 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001254 MBX_TOV_SECONDS);
1255}
1256
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257/*
1258 * qla2x00_abort_command
1259 * Abort command aborts a specified IOCB.
1260 *
1261 * Input:
1262 * ha = adapter block pointer.
1263 * sp = SB structure pointer.
1264 *
1265 * Returns:
1266 * qla2x00 local function return status code.
1267 *
1268 * Context:
1269 * Kernel context.
1270 */
1271int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001272qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273{
1274 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001276 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 mbx_cmd_t mc;
1278 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001279 fc_port_t *fcport = sp->fcport;
1280 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001281 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001282 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001283 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001285 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1286 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Michael Hernandezd7459522016-12-12 14:40:07 -08001288 if (vha->flags.qpairs_available && sp->qpair)
1289 req = sp->qpair->req;
1290 else
1291 req = vha->req;
1292
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001293 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001294 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001295 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 break;
1297 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
Chad Dupuis8d93f552013-01-30 03:34:37 -05001300 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 /* command not found */
1302 return QLA_FUNCTION_FAILED;
1303 }
1304
1305 mcp->mb[0] = MBC_ABORT_COMMAND;
1306 if (HAS_EXTENDED_IDS(ha))
1307 mcp->mb[1] = fcport->loop_id;
1308 else
1309 mcp->mb[1] = fcport->loop_id << 8;
1310 mcp->mb[2] = (uint16_t)handle;
1311 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001312 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1314 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001315 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001317 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001320 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001322 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1323 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
1325
1326 return rval;
1327}
1328
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001330qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001332 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 mbx_cmd_t mc;
1334 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001335 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001336 struct req_que *req;
1337 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338
Andrew Vasquez523ec772008-04-03 13:13:24 -07001339 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001340 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001341
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001342 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1343 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001344
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001345 req = vha->hw->req_q_map[0];
1346 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001348 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001349 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 mcp->mb[1] = fcport->loop_id;
1351 mcp->mb[10] = 0;
1352 mcp->out_mb |= MBX_10;
1353 } else {
1354 mcp->mb[1] = fcport->loop_id << 8;
1355 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001356 mcp->mb[2] = vha->hw->loop_reset_delay;
1357 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358
1359 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001360 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001362 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001364 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1365 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001366 }
1367
1368 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001369 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1370 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001371 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001372 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1373 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001375 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1376 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001377 }
1378
1379 return rval;
1380}
1381
1382int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001383qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001384{
1385 int rval, rval2;
1386 mbx_cmd_t mc;
1387 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001388 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001389 struct req_que *req;
1390 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001391
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001392 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001393
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001394 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1395 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001396
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001397 req = vha->hw->req_q_map[0];
1398 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001399 mcp->mb[0] = MBC_LUN_RESET;
1400 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001401 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001402 mcp->mb[1] = fcport->loop_id;
1403 else
1404 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001405 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001406 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001407 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001408
1409 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001410 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001411 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001412 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001413 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001414 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001415 }
1416
1417 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001418 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1419 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001420 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001421 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1422 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001423 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001424 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1425 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 }
1427
1428 return rval;
1429}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 * qla2x00_get_adapter_id
1433 * Get adapter ID and topology.
1434 *
1435 * Input:
1436 * ha = adapter block pointer.
1437 * id = pointer for loop ID.
1438 * al_pa = pointer for AL_PA.
1439 * area = pointer for area.
1440 * domain = pointer for domain.
1441 * top = pointer for topology.
1442 * TARGET_QUEUE_LOCK must be released.
1443 * ADAPTER_STATE_LOCK must be released.
1444 *
1445 * Returns:
1446 * qla2x00 local function return status code.
1447 *
1448 * Context:
1449 * Kernel context.
1450 */
1451int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001452qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001453 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454{
1455 int rval;
1456 mbx_cmd_t mc;
1457 mbx_cmd_t *mcp = &mc;
1458
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001459 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1460 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
1462 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001463 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001464 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001465 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001466 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001467 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001468 if (IS_FWI2_CAPABLE(vha->hw))
1469 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001470 if (IS_QLA27XX(vha->hw))
1471 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001472 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001474 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001475 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1476 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001477 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1478 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 /* Return data. */
1481 *id = mcp->mb[1];
1482 *al_pa = LSB(mcp->mb[2]);
1483 *area = MSB(mcp->mb[2]);
1484 *domain = LSB(mcp->mb[3]);
1485 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001486 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 if (rval != QLA_SUCCESS) {
1489 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001490 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001492 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1493 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001494
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001495 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001496 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1497 vha->fcoe_fcf_idx = mcp->mb[10];
1498 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1499 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1500 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1501 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1502 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1503 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1504 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001505 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001506 if (IS_FAWWN_CAPABLE(vha->hw)) {
1507 if (mcp->mb[7] & BIT_14) {
1508 vha->port_name[0] = MSB(mcp->mb[16]);
1509 vha->port_name[1] = LSB(mcp->mb[16]);
1510 vha->port_name[2] = MSB(mcp->mb[17]);
1511 vha->port_name[3] = LSB(mcp->mb[17]);
1512 vha->port_name[4] = MSB(mcp->mb[18]);
1513 vha->port_name[5] = LSB(mcp->mb[18]);
1514 vha->port_name[6] = MSB(mcp->mb[19]);
1515 vha->port_name[7] = LSB(mcp->mb[19]);
1516 fc_host_port_name(vha->host) =
1517 wwn_to_u64(vha->port_name);
1518 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1519 "FA-WWN acquired %016llx\n",
1520 wwn_to_u64(vha->port_name));
1521 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001522 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001523
1524 if (IS_QLA27XX(vha->hw))
1525 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 }
1527
1528 return rval;
1529}
1530
1531/*
1532 * qla2x00_get_retry_cnt
1533 * Get current firmware login retry count and delay.
1534 *
1535 * Input:
1536 * ha = adapter block pointer.
1537 * retry_cnt = pointer to login retry count.
1538 * tov = pointer to login timeout value.
1539 *
1540 * Returns:
1541 * qla2x00 local function return status code.
1542 *
1543 * Context:
1544 * Kernel context.
1545 */
1546int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001547qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 uint16_t *r_a_tov)
1549{
1550 int rval;
1551 uint16_t ratov;
1552 mbx_cmd_t mc;
1553 mbx_cmd_t *mcp = &mc;
1554
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001555 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1556 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1559 mcp->out_mb = MBX_0;
1560 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001561 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001563 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 if (rval != QLA_SUCCESS) {
1566 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001567 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1568 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 } else {
1570 /* Convert returned data and check our values. */
1571 *r_a_tov = mcp->mb[3] / 2;
1572 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1573 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1574 /* Update to the larger values */
1575 *retry_cnt = (uint8_t)mcp->mb[1];
1576 *tov = ratov;
1577 }
1578
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001579 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001580 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582
1583 return rval;
1584}
1585
1586/*
1587 * qla2x00_init_firmware
1588 * Initialize adapter firmware.
1589 *
1590 * Input:
1591 * ha = adapter block pointer.
1592 * dptr = Initialization control block pointer.
1593 * size = size of initialization control block.
1594 * TARGET_QUEUE_LOCK must be released.
1595 * ADAPTER_STATE_LOCK must be released.
1596 *
1597 * Returns:
1598 * qla2x00 local function return status code.
1599 *
1600 * Context:
1601 * Kernel context.
1602 */
1603int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001604qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605{
1606 int rval;
1607 mbx_cmd_t mc;
1608 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001609 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001611 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1612 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001614 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001615 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001616 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1617
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001618 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001619 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1620 else
1621 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1622
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001623 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 mcp->mb[2] = MSW(ha->init_cb_dma);
1625 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1627 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001628 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001629 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001630 mcp->mb[1] = BIT_0;
1631 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1632 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1633 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1634 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1635 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1636 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1637 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001638 /* 1 and 2 should normally be captured. */
1639 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001640 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001641 /* mb3 is additional info about the installed SFP. */
1642 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 mcp->buf_size = size;
1644 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001645 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001646 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648 if (rval != QLA_SUCCESS) {
1649 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001650 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001651 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1652 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 } else {
1654 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001655 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1656 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 }
1658
1659 return rval;
1660}
1661
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001662
1663/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 * qla2x00_get_port_database
1665 * Issue normal/enhanced get port database mailbox command
1666 * and copy device name as necessary.
1667 *
1668 * Input:
1669 * ha = adapter state pointer.
1670 * dev = structure pointer.
1671 * opt = enhanced cmd option byte.
1672 *
1673 * Returns:
1674 * qla2x00 local function return status code.
1675 *
1676 * Context:
1677 * Kernel context.
1678 */
1679int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001680qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681{
1682 int rval;
1683 mbx_cmd_t mc;
1684 mbx_cmd_t *mcp = &mc;
1685 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001686 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001688 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001690 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1691 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001693 pd24 = NULL;
1694 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001696 ql_log(ql_log_warn, vha, 0x1050,
1697 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 return QLA_MEMORY_ALLOC_FAILED;
1699 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001700 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001702 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001703 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 mcp->mb[2] = MSW(pd_dma);
1706 mcp->mb[3] = LSW(pd_dma);
1707 mcp->mb[6] = MSW(MSD(pd_dma));
1708 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001709 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001710 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001712 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001713 mcp->mb[1] = fcport->loop_id;
1714 mcp->mb[10] = opt;
1715 mcp->out_mb |= MBX_10|MBX_1;
1716 mcp->in_mb |= MBX_1;
1717 } else if (HAS_EXTENDED_IDS(ha)) {
1718 mcp->mb[1] = fcport->loop_id;
1719 mcp->mb[10] = opt;
1720 mcp->out_mb |= MBX_10|MBX_1;
1721 } else {
1722 mcp->mb[1] = fcport->loop_id << 8 | opt;
1723 mcp->out_mb |= MBX_1;
1724 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001725 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1726 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 mcp->flags = MBX_DMA_IN;
1728 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001729 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 if (rval != QLA_SUCCESS)
1731 goto gpd_error_out;
1732
Andrew Vasqueze4289242007-07-19 15:05:56 -07001733 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001734 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001735 pd24 = (struct port_database_24xx *) pd;
1736
1737 /* Check for logged in state. */
1738 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1739 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001740 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1741 "Unable to verify login-state (%x/%x) for "
1742 "loop_id %x.\n", pd24->current_login_state,
1743 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001744 rval = QLA_FUNCTION_FAILED;
1745 goto gpd_error_out;
1746 }
1747
Arun Easi0eba25d2012-02-09 11:15:58 -08001748 if (fcport->loop_id == FC_NO_LOOP_ID ||
1749 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1750 memcmp(fcport->port_name, pd24->port_name, 8))) {
1751 /* We lost the device mid way. */
1752 rval = QLA_NOT_LOGGED_IN;
1753 goto gpd_error_out;
1754 }
1755
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001756 /* Names are little-endian. */
1757 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1758 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1759
1760 /* Get port_id of device. */
1761 fcport->d_id.b.domain = pd24->port_id[0];
1762 fcport->d_id.b.area = pd24->port_id[1];
1763 fcport->d_id.b.al_pa = pd24->port_id[2];
1764 fcport->d_id.b.rsvd_1 = 0;
1765
1766 /* If not target must be initiator or unknown type. */
1767 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1768 fcport->port_type = FCT_INITIATOR;
1769 else
1770 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001771
1772 /* Passback COS information. */
1773 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1774 FC_COS_CLASS2 : FC_COS_CLASS3;
1775
1776 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1777 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001778 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001779 uint64_t zero = 0;
1780
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001781 /* Check for logged in state. */
1782 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1783 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001784 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1785 "Unable to verify login-state (%x/%x) - "
1786 "portid=%02x%02x%02x.\n", pd->master_state,
1787 pd->slave_state, fcport->d_id.b.domain,
1788 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001789 rval = QLA_FUNCTION_FAILED;
1790 goto gpd_error_out;
1791 }
1792
Arun Easi0eba25d2012-02-09 11:15:58 -08001793 if (fcport->loop_id == FC_NO_LOOP_ID ||
1794 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1795 memcmp(fcport->port_name, pd->port_name, 8))) {
1796 /* We lost the device mid way. */
1797 rval = QLA_NOT_LOGGED_IN;
1798 goto gpd_error_out;
1799 }
1800
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001801 /* Names are little-endian. */
1802 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1803 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1804
1805 /* Get port_id of device. */
1806 fcport->d_id.b.domain = pd->port_id[0];
1807 fcport->d_id.b.area = pd->port_id[3];
1808 fcport->d_id.b.al_pa = pd->port_id[2];
1809 fcport->d_id.b.rsvd_1 = 0;
1810
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001811 /* If not target must be initiator or unknown type. */
1812 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1813 fcport->port_type = FCT_INITIATOR;
1814 else
1815 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001816
1817 /* Passback COS information. */
1818 fcport->supported_classes = (pd->options & BIT_4) ?
1819 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 }
1821
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822gpd_error_out:
1823 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1824
1825 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001826 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1827 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1828 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001830 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1831 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 }
1833
1834 return rval;
1835}
1836
1837/*
1838 * qla2x00_get_firmware_state
1839 * Get adapter firmware state.
1840 *
1841 * Input:
1842 * ha = adapter block pointer.
1843 * dptr = pointer for firmware state.
1844 * TARGET_QUEUE_LOCK must be released.
1845 * ADAPTER_STATE_LOCK must be released.
1846 *
1847 * Returns:
1848 * qla2x00 local function return status code.
1849 *
1850 * Context:
1851 * Kernel context.
1852 */
1853int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001854qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855{
1856 int rval;
1857 mbx_cmd_t mc;
1858 mbx_cmd_t *mcp = &mc;
1859
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001860 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1861 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
1863 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1864 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001865 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001866 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001867 else
1868 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001869 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001871 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001873 /* Return firmware states. */
1874 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001875 if (IS_FWI2_CAPABLE(vha->hw)) {
1876 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04001877 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001878 states[3] = mcp->mb[4];
1879 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001880 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001881 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 if (rval != QLA_SUCCESS) {
1884 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001885 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 } else {
1887 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001888 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1889 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 }
1891
1892 return rval;
1893}
1894
1895/*
1896 * qla2x00_get_port_name
1897 * Issue get port name mailbox command.
1898 * Returned name is in big endian format.
1899 *
1900 * Input:
1901 * ha = adapter block pointer.
1902 * loop_id = loop ID of device.
1903 * name = pointer for name.
1904 * TARGET_QUEUE_LOCK must be released.
1905 * ADAPTER_STATE_LOCK must be released.
1906 *
1907 * Returns:
1908 * qla2x00 local function return status code.
1909 *
1910 * Context:
1911 * Kernel context.
1912 */
1913int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001914qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 uint8_t opt)
1916{
1917 int rval;
1918 mbx_cmd_t mc;
1919 mbx_cmd_t *mcp = &mc;
1920
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001921 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1922 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923
1924 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001925 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001926 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001927 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 mcp->mb[1] = loop_id;
1929 mcp->mb[10] = opt;
1930 mcp->out_mb |= MBX_10;
1931 } else {
1932 mcp->mb[1] = loop_id << 8 | opt;
1933 }
1934
1935 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001936 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001938 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
1940 if (rval != QLA_SUCCESS) {
1941 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001942 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 } else {
1944 if (name != NULL) {
1945 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001946 name[0] = MSB(mcp->mb[2]);
1947 name[1] = LSB(mcp->mb[2]);
1948 name[2] = MSB(mcp->mb[3]);
1949 name[3] = LSB(mcp->mb[3]);
1950 name[4] = MSB(mcp->mb[6]);
1951 name[5] = LSB(mcp->mb[6]);
1952 name[6] = MSB(mcp->mb[7]);
1953 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 }
1955
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001956 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1957 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
1959
1960 return rval;
1961}
1962
1963/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001964 * qla24xx_link_initialization
1965 * Issue link initialization mailbox command.
1966 *
1967 * Input:
1968 * ha = adapter block pointer.
1969 * TARGET_QUEUE_LOCK must be released.
1970 * ADAPTER_STATE_LOCK must be released.
1971 *
1972 * Returns:
1973 * qla2x00 local function return status code.
1974 *
1975 * Context:
1976 * Kernel context.
1977 */
1978int
1979qla24xx_link_initialize(scsi_qla_host_t *vha)
1980{
1981 int rval;
1982 mbx_cmd_t mc;
1983 mbx_cmd_t *mcp = &mc;
1984
1985 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
1986 "Entered %s.\n", __func__);
1987
1988 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
1989 return QLA_FUNCTION_FAILED;
1990
1991 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04001992 mcp->mb[1] = BIT_4;
1993 if (vha->hw->operating_mode == LOOP)
1994 mcp->mb[1] |= BIT_6;
1995 else
1996 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001997 mcp->mb[2] = 0;
1998 mcp->mb[3] = 0;
1999 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2000 mcp->in_mb = MBX_0;
2001 mcp->tov = MBX_TOV_SECONDS;
2002 mcp->flags = 0;
2003 rval = qla2x00_mailbox_command(vha, mcp);
2004
2005 if (rval != QLA_SUCCESS) {
2006 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2007 } else {
2008 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2009 "Done %s.\n", __func__);
2010 }
2011
2012 return rval;
2013}
2014
2015/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 * qla2x00_lip_reset
2017 * Issue LIP reset mailbox command.
2018 *
2019 * Input:
2020 * ha = adapter block pointer.
2021 * TARGET_QUEUE_LOCK must be released.
2022 * ADAPTER_STATE_LOCK must be released.
2023 *
2024 * Returns:
2025 * qla2x00 local function return status code.
2026 *
2027 * Context:
2028 * Kernel context.
2029 */
2030int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002031qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032{
2033 int rval;
2034 mbx_cmd_t mc;
2035 mbx_cmd_t *mcp = &mc;
2036
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002037 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2038 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002040 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002041 /* Logout across all FCFs. */
2042 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2043 mcp->mb[1] = BIT_1;
2044 mcp->mb[2] = 0;
2045 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2046 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002047 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002048 mcp->mb[1] = BIT_6;
2049 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002050 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002051 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002053 mcp->mb[0] = MBC_LIP_RESET;
2054 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002055 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002056 mcp->mb[1] = 0x00ff;
2057 mcp->mb[10] = 0;
2058 mcp->out_mb |= MBX_10;
2059 } else {
2060 mcp->mb[1] = 0xff00;
2061 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002062 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002063 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002066 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002068 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069
2070 if (rval != QLA_SUCCESS) {
2071 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002072 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 } else {
2074 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002075 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2076 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 }
2078
2079 return rval;
2080}
2081
2082/*
2083 * qla2x00_send_sns
2084 * Send SNS command.
2085 *
2086 * Input:
2087 * ha = adapter block pointer.
2088 * sns = pointer for command.
2089 * cmd_size = command size.
2090 * buf_size = response/command size.
2091 * TARGET_QUEUE_LOCK must be released.
2092 * ADAPTER_STATE_LOCK must be released.
2093 *
2094 * Returns:
2095 * qla2x00 local function return status code.
2096 *
2097 * Context:
2098 * Kernel context.
2099 */
2100int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002101qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 uint16_t cmd_size, size_t buf_size)
2103{
2104 int rval;
2105 mbx_cmd_t mc;
2106 mbx_cmd_t *mcp = &mc;
2107
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002108 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2109 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002111 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002112 "Retry cnt=%d ratov=%d total tov=%d.\n",
2113 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
2115 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2116 mcp->mb[1] = cmd_size;
2117 mcp->mb[2] = MSW(sns_phys_address);
2118 mcp->mb[3] = LSW(sns_phys_address);
2119 mcp->mb[6] = MSW(MSD(sns_phys_address));
2120 mcp->mb[7] = LSW(MSD(sns_phys_address));
2121 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2122 mcp->in_mb = MBX_0|MBX_1;
2123 mcp->buf_size = buf_size;
2124 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002125 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2126 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
2128 if (rval != QLA_SUCCESS) {
2129 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002130 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2131 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2132 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 } else {
2134 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002135 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2136 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 }
2138
2139 return rval;
2140}
2141
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002142int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002143qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002144 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2145{
2146 int rval;
2147
2148 struct logio_entry_24xx *lg;
2149 dma_addr_t lg_dma;
2150 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002151 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002152 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002153
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002154 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2155 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002156
Michael Hernandezd7459522016-12-12 14:40:07 -08002157 if (vha->vp_idx && vha->qpair)
2158 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002159 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002160 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002161
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002162 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2163 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002164 ql_log(ql_log_warn, vha, 0x1062,
2165 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002166 return QLA_MEMORY_ALLOC_FAILED;
2167 }
2168 memset(lg, 0, sizeof(struct logio_entry_24xx));
2169
2170 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2171 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002172 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002173 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002174 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002175 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002176 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002177 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002178 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002179 lg->port_id[0] = al_pa;
2180 lg->port_id[1] = area;
2181 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002182 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002183 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2184 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002185 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002186 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2187 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002188 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002189 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2190 "Failed to complete IOCB -- error status (%x).\n",
2191 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002192 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002193 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002194 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2195 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2196
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002197 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2198 "Failed to complete IOCB -- completion status (%x) "
2199 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2200 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002201
2202 switch (iop[0]) {
2203 case LSC_SCODE_PORTID_USED:
2204 mb[0] = MBS_PORT_ID_USED;
2205 mb[1] = LSW(iop[1]);
2206 break;
2207 case LSC_SCODE_NPORT_USED:
2208 mb[0] = MBS_LOOP_ID_USED;
2209 break;
2210 case LSC_SCODE_NOLINK:
2211 case LSC_SCODE_NOIOCB:
2212 case LSC_SCODE_NOXCB:
2213 case LSC_SCODE_CMD_FAILED:
2214 case LSC_SCODE_NOFABRIC:
2215 case LSC_SCODE_FW_NOT_READY:
2216 case LSC_SCODE_NOT_LOGGED_IN:
2217 case LSC_SCODE_NOPCB:
2218 case LSC_SCODE_ELS_REJECT:
2219 case LSC_SCODE_CMD_PARAM_ERR:
2220 case LSC_SCODE_NONPORT:
2221 case LSC_SCODE_LOGGED_IN:
2222 case LSC_SCODE_NOFLOGI_ACC:
2223 default:
2224 mb[0] = MBS_COMMAND_ERROR;
2225 break;
2226 }
2227 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002228 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2229 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002230
2231 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2232
2233 mb[0] = MBS_COMMAND_COMPLETE;
2234 mb[1] = 0;
2235 if (iop[0] & BIT_4) {
2236 if (iop[0] & BIT_8)
2237 mb[1] |= BIT_1;
2238 } else
2239 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002240
2241 /* Passback COS information. */
2242 mb[10] = 0;
2243 if (lg->io_parameter[7] || lg->io_parameter[8])
2244 mb[10] |= BIT_0; /* Class 2. */
2245 if (lg->io_parameter[9] || lg->io_parameter[10])
2246 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002247 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002248 mb[10] |= BIT_7; /* Confirmed Completion
2249 * Allowed
2250 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002251 }
2252
2253 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2254
2255 return rval;
2256}
2257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258/*
2259 * qla2x00_login_fabric
2260 * Issue login fabric port mailbox command.
2261 *
2262 * Input:
2263 * ha = adapter block pointer.
2264 * loop_id = device loop ID.
2265 * domain = device domain.
2266 * area = device area.
2267 * al_pa = device AL_PA.
2268 * status = pointer for return status.
2269 * opt = command options.
2270 * TARGET_QUEUE_LOCK must be released.
2271 * ADAPTER_STATE_LOCK must be released.
2272 *
2273 * Returns:
2274 * qla2x00 local function return status code.
2275 *
2276 * Context:
2277 * Kernel context.
2278 */
2279int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002280qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2282{
2283 int rval;
2284 mbx_cmd_t mc;
2285 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002286 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002288 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2289 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290
2291 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2292 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2293 if (HAS_EXTENDED_IDS(ha)) {
2294 mcp->mb[1] = loop_id;
2295 mcp->mb[10] = opt;
2296 mcp->out_mb |= MBX_10;
2297 } else {
2298 mcp->mb[1] = (loop_id << 8) | opt;
2299 }
2300 mcp->mb[2] = domain;
2301 mcp->mb[3] = area << 8 | al_pa;
2302
2303 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2304 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2305 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002306 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 /* Return mailbox statuses. */
2309 if (mb != NULL) {
2310 mb[0] = mcp->mb[0];
2311 mb[1] = mcp->mb[1];
2312 mb[2] = mcp->mb[2];
2313 mb[6] = mcp->mb[6];
2314 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002315 /* COS retrieved from Get-Port-Database mailbox command. */
2316 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318
2319 if (rval != QLA_SUCCESS) {
2320 /* RLU tmp code: need to change main mailbox_command function to
2321 * return ok even when the mailbox completion value is not
2322 * SUCCESS. The caller needs to be responsible to interpret
2323 * the return values of this mailbox command if we're not
2324 * to change too much of the existing code.
2325 */
2326 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2327 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2328 mcp->mb[0] == 0x4006)
2329 rval = QLA_SUCCESS;
2330
2331 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002332 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2333 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2334 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 } else {
2336 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002337 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2338 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 }
2340
2341 return rval;
2342}
2343
2344/*
2345 * qla2x00_login_local_device
2346 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002347 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 * Input:
2349 * ha = adapter block pointer.
2350 * loop_id = device loop ID.
2351 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002352 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 * Returns:
2354 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002355 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 * Context:
2357 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002358 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 */
2360int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002361qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 uint16_t *mb_ret, uint8_t opt)
2363{
2364 int rval;
2365 mbx_cmd_t mc;
2366 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002367 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002369 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2370 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002371
Andrew Vasqueze4289242007-07-19 15:05:56 -07002372 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002373 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002374 fcport->d_id.b.domain, fcport->d_id.b.area,
2375 fcport->d_id.b.al_pa, mb_ret, opt);
2376
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2378 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002379 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002381 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 mcp->mb[2] = opt;
2383 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2384 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2385 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2386 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002387 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388
2389 /* Return mailbox statuses. */
2390 if (mb_ret != NULL) {
2391 mb_ret[0] = mcp->mb[0];
2392 mb_ret[1] = mcp->mb[1];
2393 mb_ret[6] = mcp->mb[6];
2394 mb_ret[7] = mcp->mb[7];
2395 }
2396
2397 if (rval != QLA_SUCCESS) {
2398 /* AV tmp code: need to change main mailbox_command function to
2399 * return ok even when the mailbox completion value is not
2400 * SUCCESS. The caller needs to be responsible to interpret
2401 * the return values of this mailbox command if we're not
2402 * to change too much of the existing code.
2403 */
2404 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2405 rval = QLA_SUCCESS;
2406
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002407 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2408 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2409 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 } else {
2411 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002412 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2413 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 }
2415
2416 return (rval);
2417}
2418
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002419int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002420qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002421 uint8_t area, uint8_t al_pa)
2422{
2423 int rval;
2424 struct logio_entry_24xx *lg;
2425 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002426 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002427 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002428
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002429 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2430 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002431
2432 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2433 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002434 ql_log(ql_log_warn, vha, 0x106e,
2435 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002436 return QLA_MEMORY_ALLOC_FAILED;
2437 }
2438 memset(lg, 0, sizeof(struct logio_entry_24xx));
2439
Michael Hernandezd7459522016-12-12 14:40:07 -08002440 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002441 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2442 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002443 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002444 lg->nport_handle = cpu_to_le16(loop_id);
2445 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002446 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002447 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002448 lg->port_id[0] = al_pa;
2449 lg->port_id[1] = area;
2450 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002451 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002452 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2453 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002454 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002455 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2456 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002457 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002458 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2459 "Failed to complete IOCB -- error status (%x).\n",
2460 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002461 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002462 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002463 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2464 "Failed to complete IOCB -- completion status (%x) "
2465 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002466 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002467 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002468 } else {
2469 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2471 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002472 }
2473
2474 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2475
2476 return rval;
2477}
2478
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479/*
2480 * qla2x00_fabric_logout
2481 * Issue logout fabric port mailbox command.
2482 *
2483 * Input:
2484 * ha = adapter block pointer.
2485 * loop_id = device loop ID.
2486 * TARGET_QUEUE_LOCK must be released.
2487 * ADAPTER_STATE_LOCK must be released.
2488 *
2489 * Returns:
2490 * qla2x00 local function return status code.
2491 *
2492 * Context:
2493 * Kernel context.
2494 */
2495int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002496qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002497 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498{
2499 int rval;
2500 mbx_cmd_t mc;
2501 mbx_cmd_t *mcp = &mc;
2502
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2504 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
2506 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2507 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002508 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 mcp->mb[1] = loop_id;
2510 mcp->mb[10] = 0;
2511 mcp->out_mb |= MBX_10;
2512 } else {
2513 mcp->mb[1] = loop_id << 8;
2514 }
2515
2516 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002517 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002519 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
2521 if (rval != QLA_SUCCESS) {
2522 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002523 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2524 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 } else {
2526 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002527 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2528 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 }
2530
2531 return rval;
2532}
2533
2534/*
2535 * qla2x00_full_login_lip
2536 * Issue full login LIP mailbox command.
2537 *
2538 * Input:
2539 * ha = adapter block pointer.
2540 * TARGET_QUEUE_LOCK must be released.
2541 * ADAPTER_STATE_LOCK must be released.
2542 *
2543 * Returns:
2544 * qla2x00 local function return status code.
2545 *
2546 * Context:
2547 * Kernel context.
2548 */
2549int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002550qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551{
2552 int rval;
2553 mbx_cmd_t mc;
2554 mbx_cmd_t *mcp = &mc;
2555
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002556 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2557 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
2559 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002560 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002561 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 mcp->mb[3] = 0;
2563 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2564 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002565 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002567 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
2569 if (rval != QLA_SUCCESS) {
2570 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002571 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 } else {
2573 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002574 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2575 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 }
2577
2578 return rval;
2579}
2580
2581/*
2582 * qla2x00_get_id_list
2583 *
2584 * Input:
2585 * ha = adapter block pointer.
2586 *
2587 * Returns:
2588 * qla2x00 local function return status code.
2589 *
2590 * Context:
2591 * Kernel context.
2592 */
2593int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002594qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 uint16_t *entries)
2596{
2597 int rval;
2598 mbx_cmd_t mc;
2599 mbx_cmd_t *mcp = &mc;
2600
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002601 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2602 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
2604 if (id_list == NULL)
2605 return QLA_FUNCTION_FAILED;
2606
2607 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002608 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002609 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002610 mcp->mb[2] = MSW(id_list_dma);
2611 mcp->mb[3] = LSW(id_list_dma);
2612 mcp->mb[6] = MSW(MSD(id_list_dma));
2613 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002614 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002615 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002616 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002617 } else {
2618 mcp->mb[1] = MSW(id_list_dma);
2619 mcp->mb[2] = LSW(id_list_dma);
2620 mcp->mb[3] = MSW(MSD(id_list_dma));
2621 mcp->mb[6] = LSW(MSD(id_list_dma));
2622 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002625 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002627 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628
2629 if (rval != QLA_SUCCESS) {
2630 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002631 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 } else {
2633 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002634 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2635 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 }
2637
2638 return rval;
2639}
2640
2641/*
2642 * qla2x00_get_resource_cnts
2643 * Get current firmware resource counts.
2644 *
2645 * Input:
2646 * ha = adapter block pointer.
2647 *
2648 * Returns:
2649 * qla2x00 local function return status code.
2650 *
2651 * Context:
2652 * Kernel context.
2653 */
2654int
Quinn Tran03e8c682015-12-17 14:56:59 -05002655qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656{
Quinn Tran03e8c682015-12-17 14:56:59 -05002657 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 int rval;
2659 mbx_cmd_t mc;
2660 mbx_cmd_t *mcp = &mc;
2661
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002662 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2663 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664
2665 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2666 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002667 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 -05002668 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002669 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002670 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002672 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
2674 if (rval != QLA_SUCCESS) {
2675 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002676 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2677 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002679 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002680 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2681 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2682 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2683 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
Quinn Tran03e8c682015-12-17 14:56:59 -05002685 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2686 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2687 ha->cur_fw_xcb_count = mcp->mb[3];
2688 ha->orig_fw_xcb_count = mcp->mb[6];
2689 ha->cur_fw_iocb_count = mcp->mb[7];
2690 ha->orig_fw_iocb_count = mcp->mb[10];
2691 if (ha->flags.npiv_supported)
2692 ha->max_npiv_vports = mcp->mb[11];
2693 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2694 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
2696
2697 return (rval);
2698}
2699
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700/*
2701 * qla2x00_get_fcal_position_map
2702 * Get FCAL (LILP) position map using mailbox command
2703 *
2704 * Input:
2705 * ha = adapter state pointer.
2706 * pos_map = buffer pointer (can be NULL).
2707 *
2708 * Returns:
2709 * qla2x00 local function return status code.
2710 *
2711 * Context:
2712 * Kernel context.
2713 */
2714int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002715qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716{
2717 int rval;
2718 mbx_cmd_t mc;
2719 mbx_cmd_t *mcp = &mc;
2720 char *pmap;
2721 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002722 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002724 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2725 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002726
Andrew Vasquez4b892582008-09-11 21:22:48 -07002727 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002729 ql_log(ql_log_warn, vha, 0x1080,
2730 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 return QLA_MEMORY_ALLOC_FAILED;
2732 }
2733 memset(pmap, 0, FCAL_MAP_SIZE);
2734
2735 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2736 mcp->mb[2] = MSW(pmap_dma);
2737 mcp->mb[3] = LSW(pmap_dma);
2738 mcp->mb[6] = MSW(MSD(pmap_dma));
2739 mcp->mb[7] = LSW(MSD(pmap_dma));
2740 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2741 mcp->in_mb = MBX_1|MBX_0;
2742 mcp->buf_size = FCAL_MAP_SIZE;
2743 mcp->flags = MBX_DMA_IN;
2744 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002745 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746
2747 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002748 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002749 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2750 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2751 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2752 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754 if (pos_map)
2755 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2756 }
2757 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2758
2759 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002760 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002762 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2763 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
2765
2766 return rval;
2767}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002768
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002769/*
2770 * qla2x00_get_link_status
2771 *
2772 * Input:
2773 * ha = adapter block pointer.
2774 * loop_id = device loop ID.
2775 * ret_buf = pointer to link status return buffer.
2776 *
2777 * Returns:
2778 * 0 = success.
2779 * BIT_0 = mem alloc error.
2780 * BIT_1 = mailbox error.
2781 */
2782int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002783qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002784 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002785{
2786 int rval;
2787 mbx_cmd_t mc;
2788 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002789 uint32_t *iter = (void *)stats;
2790 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002791 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002792
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002793 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2794 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002795
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002796 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002797 mcp->mb[2] = MSW(LSD(stats_dma));
2798 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002799 mcp->mb[6] = MSW(MSD(stats_dma));
2800 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002801 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2802 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002803 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002804 mcp->mb[1] = loop_id;
2805 mcp->mb[4] = 0;
2806 mcp->mb[10] = 0;
2807 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2808 mcp->in_mb |= MBX_1;
2809 } else if (HAS_EXTENDED_IDS(ha)) {
2810 mcp->mb[1] = loop_id;
2811 mcp->mb[10] = 0;
2812 mcp->out_mb |= MBX_10|MBX_1;
2813 } else {
2814 mcp->mb[1] = loop_id << 8;
2815 mcp->out_mb |= MBX_1;
2816 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002817 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002818 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002819 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002820
2821 if (rval == QLA_SUCCESS) {
2822 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002823 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2824 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002825 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002826 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002827 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002828 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2829 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002830 for ( ; dwords--; iter++)
2831 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002832 }
2833 } else {
2834 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002835 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002836 }
2837
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002838 return rval;
2839}
2840
2841int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002842qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07002843 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002844{
2845 int rval;
2846 mbx_cmd_t mc;
2847 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002848 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002849
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002850 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2851 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002852
Quinn Tran15f30a52017-03-15 09:48:52 -07002853 memset(&mc, 0, sizeof(mc));
2854 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
2855 mc.mb[2] = MSW(stats_dma);
2856 mc.mb[3] = LSW(stats_dma);
2857 mc.mb[6] = MSW(MSD(stats_dma));
2858 mc.mb[7] = LSW(MSD(stats_dma));
2859 mc.mb[8] = sizeof(struct link_statistics) / 4;
2860 mc.mb[9] = cpu_to_le16(vha->vp_idx);
2861 mc.mb[10] = cpu_to_le16(options);
2862
2863 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002864
2865 if (rval == QLA_SUCCESS) {
2866 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002867 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2868 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002869 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002870 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002871 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2872 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002873 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002874 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002875 iter = &stats->link_fail_cnt;
2876 for ( ; dwords--; iter++)
2877 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002878 }
2879 } else {
2880 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002881 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002882 }
2883
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002884 return rval;
2885}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002886
2887int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002888qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002889{
2890 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002891 unsigned long flags = 0;
2892
2893 struct abort_entry_24xx *abt;
2894 dma_addr_t abt_dma;
2895 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002896 fc_port_t *fcport = sp->fcport;
2897 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002898 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002899 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002900
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002901 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2902 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002903
Michael Hernandezd7459522016-12-12 14:40:07 -08002904 if (vha->flags.qpairs_available && sp->qpair)
2905 req = sp->qpair->req;
2906
Armen Baloyan4440e462014-02-26 04:15:18 -05002907 if (ql2xasynctmfenable)
2908 return qla24xx_async_abort_command(sp);
2909
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002910 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002911 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002912 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002913 break;
2914 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002915 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002916 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002917 /* Command not found. */
2918 return QLA_FUNCTION_FAILED;
2919 }
2920
2921 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2922 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002923 ql_log(ql_log_warn, vha, 0x108d,
2924 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002925 return QLA_MEMORY_ALLOC_FAILED;
2926 }
2927 memset(abt, 0, sizeof(struct abort_entry_24xx));
2928
2929 abt->entry_type = ABORT_IOCB_TYPE;
2930 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002931 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002932 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002933 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002934 abt->port_id[0] = fcport->d_id.b.al_pa;
2935 abt->port_id[1] = fcport->d_id.b.area;
2936 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002937 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002938
2939 abt->req_que_no = cpu_to_le16(req->id);
2940
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002941 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002942 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002943 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2944 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002945 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002946 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2947 "Failed to complete IOCB -- error status (%x).\n",
2948 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002949 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002950 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002951 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2952 "Failed to complete IOCB -- completion status (%x).\n",
2953 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04002954 if (abt->nport_handle == CS_IOCB_ERROR)
2955 rval = QLA_FUNCTION_PARAMETER_ERROR;
2956 else
2957 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002958 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002959 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2960 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002961 }
2962
2963 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2964
2965 return rval;
2966}
2967
2968struct tsk_mgmt_cmd {
2969 union {
2970 struct tsk_mgmt_entry tsk;
2971 struct sts_entry_24xx sts;
2972 } p;
2973};
2974
Andrew Vasquez523ec772008-04-03 13:13:24 -07002975static int
2976__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002977 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002978{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002979 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002980 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002981 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002982 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002983 scsi_qla_host_t *vha;
2984 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002985 struct req_que *req;
2986 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08002987 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002988
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002989 vha = fcport->vha;
2990 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002991 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002992
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002993 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
2994 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002995
Michael Hernandezd7459522016-12-12 14:40:07 -08002996 if (vha->vp_idx && vha->qpair) {
2997 /* NPIV port */
2998 qpair = vha->qpair;
2999 rsp = qpair->rsp;
3000 req = qpair->req;
3001 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003002 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003003 }
3004
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003005 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003006 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003007 ql_log(ql_log_warn, vha, 0x1093,
3008 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003009 return QLA_MEMORY_ALLOC_FAILED;
3010 }
3011 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
3012
3013 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3014 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003015 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003016 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003017 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003018 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003019 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3020 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3021 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003022 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003023 if (type == TCF_LUN_RESET) {
3024 int_to_scsilun(l, &tsk->p.tsk.lun);
3025 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3026 sizeof(tsk->p.tsk.lun));
3027 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003028
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003029 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003030 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003031 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003032 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3033 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003034 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003035 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3036 "Failed to complete IOCB -- error status (%x).\n",
3037 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003038 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003039 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003040 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3041 "Failed to complete IOCB -- completion status (%x).\n",
3042 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003043 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003044 } else if (le16_to_cpu(sts->scsi_status) &
3045 SS_RESPONSE_INFO_LEN_VALID) {
3046 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003047 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003048 "Ignoring inconsistent data length -- not enough "
3049 "response info (%d).\n",
3050 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003051 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3053 "Failed to complete IOCB -- response (%x).\n",
3054 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003055 rval = QLA_FUNCTION_FAILED;
3056 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003057 }
3058
3059 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003060 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003061 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3062 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003063 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3064 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003065 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003066 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3067 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003068 }
3069
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003070 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003071
3072 return rval;
3073}
3074
Andrew Vasquez523ec772008-04-03 13:13:24 -07003075int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003076qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003077{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003078 struct qla_hw_data *ha = fcport->vha->hw;
3079
3080 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3081 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3082
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003083 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003084}
3085
3086int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003087qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003088{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003089 struct qla_hw_data *ha = fcport->vha->hw;
3090
3091 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3092 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3093
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003094 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003095}
3096
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003097int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003098qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003099{
3100 int rval;
3101 mbx_cmd_t mc;
3102 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003103 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003104
Andrew Vasquez68af0812008-05-12 22:21:13 -07003105 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003106 return QLA_FUNCTION_FAILED;
3107
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003108 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3109 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003110
3111 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3112 mcp->out_mb = MBX_0;
3113 mcp->in_mb = MBX_0;
3114 mcp->tov = 5;
3115 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003116 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003117
3118 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003119 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003120 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003121 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3122 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003123 }
3124
3125 return rval;
3126}
3127
Joe Carnucciodb64e932013-10-30 03:38:18 -04003128int
3129qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3130{
3131 int rval;
3132 mbx_cmd_t mc;
3133 mbx_cmd_t *mcp = &mc;
3134
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003135 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3136 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003137 return QLA_FUNCTION_FAILED;
3138
3139 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3140 "Entered %s.\n", __func__);
3141
3142 mcp->mb[0] = MBC_WRITE_SERDES;
3143 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003144 if (IS_QLA2031(vha->hw))
3145 mcp->mb[2] = data & 0xff;
3146 else
3147 mcp->mb[2] = data;
3148
Joe Carnucciodb64e932013-10-30 03:38:18 -04003149 mcp->mb[3] = 0;
3150 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3151 mcp->in_mb = MBX_0;
3152 mcp->tov = MBX_TOV_SECONDS;
3153 mcp->flags = 0;
3154 rval = qla2x00_mailbox_command(vha, mcp);
3155
3156 if (rval != QLA_SUCCESS) {
3157 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3158 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3159 } else {
3160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3161 "Done %s.\n", __func__);
3162 }
3163
3164 return rval;
3165}
3166
3167int
3168qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3169{
3170 int rval;
3171 mbx_cmd_t mc;
3172 mbx_cmd_t *mcp = &mc;
3173
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003174 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3175 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003176 return QLA_FUNCTION_FAILED;
3177
3178 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3179 "Entered %s.\n", __func__);
3180
3181 mcp->mb[0] = MBC_READ_SERDES;
3182 mcp->mb[1] = addr;
3183 mcp->mb[3] = 0;
3184 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3185 mcp->in_mb = MBX_1|MBX_0;
3186 mcp->tov = MBX_TOV_SECONDS;
3187 mcp->flags = 0;
3188 rval = qla2x00_mailbox_command(vha, mcp);
3189
Andrew Vasquez064135e2015-04-09 15:00:02 -04003190 if (IS_QLA2031(vha->hw))
3191 *data = mcp->mb[1] & 0xff;
3192 else
3193 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003194
3195 if (rval != QLA_SUCCESS) {
3196 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3197 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3198 } else {
3199 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3200 "Done %s.\n", __func__);
3201 }
3202
3203 return rval;
3204}
3205
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003206int
3207qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3208{
3209 int rval;
3210 mbx_cmd_t mc;
3211 mbx_cmd_t *mcp = &mc;
3212
3213 if (!IS_QLA8044(vha->hw))
3214 return QLA_FUNCTION_FAILED;
3215
3216 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1186,
3217 "Entered %s.\n", __func__);
3218
3219 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3220 mcp->mb[1] = HCS_WRITE_SERDES;
3221 mcp->mb[3] = LSW(addr);
3222 mcp->mb[4] = MSW(addr);
3223 mcp->mb[5] = LSW(data);
3224 mcp->mb[6] = MSW(data);
3225 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3226 mcp->in_mb = MBX_0;
3227 mcp->tov = MBX_TOV_SECONDS;
3228 mcp->flags = 0;
3229 rval = qla2x00_mailbox_command(vha, mcp);
3230
3231 if (rval != QLA_SUCCESS) {
3232 ql_dbg(ql_dbg_mbx, vha, 0x1187,
3233 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3234 } else {
3235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3236 "Done %s.\n", __func__);
3237 }
3238
3239 return rval;
3240}
3241
3242int
3243qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3244{
3245 int rval;
3246 mbx_cmd_t mc;
3247 mbx_cmd_t *mcp = &mc;
3248
3249 if (!IS_QLA8044(vha->hw))
3250 return QLA_FUNCTION_FAILED;
3251
3252 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3253 "Entered %s.\n", __func__);
3254
3255 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3256 mcp->mb[1] = HCS_READ_SERDES;
3257 mcp->mb[3] = LSW(addr);
3258 mcp->mb[4] = MSW(addr);
3259 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3260 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3261 mcp->tov = MBX_TOV_SECONDS;
3262 mcp->flags = 0;
3263 rval = qla2x00_mailbox_command(vha, mcp);
3264
3265 *data = mcp->mb[2] << 16 | mcp->mb[1];
3266
3267 if (rval != QLA_SUCCESS) {
3268 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3269 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3270 } else {
3271 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3272 "Done %s.\n", __func__);
3273 }
3274
3275 return rval;
3276}
3277
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003278/**
3279 * qla2x00_set_serdes_params() -
3280 * @ha: HA context
3281 *
3282 * Returns
3283 */
3284int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003285qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003286 uint16_t sw_em_2g, uint16_t sw_em_4g)
3287{
3288 int rval;
3289 mbx_cmd_t mc;
3290 mbx_cmd_t *mcp = &mc;
3291
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003292 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3293 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003294
3295 mcp->mb[0] = MBC_SERDES_PARAMS;
3296 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003297 mcp->mb[2] = sw_em_1g | BIT_15;
3298 mcp->mb[3] = sw_em_2g | BIT_15;
3299 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003300 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3301 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003302 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003303 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003304 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003305
3306 if (rval != QLA_SUCCESS) {
3307 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003308 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3309 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003310 } else {
3311 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003312 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3313 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003314 }
3315
3316 return rval;
3317}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003318
3319int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003320qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003321{
3322 int rval;
3323 mbx_cmd_t mc;
3324 mbx_cmd_t *mcp = &mc;
3325
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003326 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003327 return QLA_FUNCTION_FAILED;
3328
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003329 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3330 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003331
3332 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003333 mcp->mb[1] = 0;
3334 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003335 mcp->in_mb = MBX_0;
3336 mcp->tov = 5;
3337 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003338 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003339
3340 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003341 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003342 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3343 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003344 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003345 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3346 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003347 }
3348
3349 return rval;
3350}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003351
3352int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003353qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003354 uint16_t buffers)
3355{
3356 int rval;
3357 mbx_cmd_t mc;
3358 mbx_cmd_t *mcp = &mc;
3359
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003360 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3361 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003362
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003363 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003364 return QLA_FUNCTION_FAILED;
3365
Andrew Vasquez85880802009-12-15 21:29:46 -08003366 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3367 return QLA_FUNCTION_FAILED;
3368
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003369 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003370 mcp->mb[1] = TC_EFT_ENABLE;
3371 mcp->mb[2] = LSW(eft_dma);
3372 mcp->mb[3] = MSW(eft_dma);
3373 mcp->mb[4] = LSW(MSD(eft_dma));
3374 mcp->mb[5] = MSW(MSD(eft_dma));
3375 mcp->mb[6] = buffers;
3376 mcp->mb[7] = TC_AEN_DISABLE;
3377 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 -07003378 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003379 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003380 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003381 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003382 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003383 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3384 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3385 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003386 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003387 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3388 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003389 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003390
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003391 return rval;
3392}
3393
3394int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003395qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003396{
3397 int rval;
3398 mbx_cmd_t mc;
3399 mbx_cmd_t *mcp = &mc;
3400
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003401 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3402 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003403
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003404 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003405 return QLA_FUNCTION_FAILED;
3406
Andrew Vasquez85880802009-12-15 21:29:46 -08003407 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3408 return QLA_FUNCTION_FAILED;
3409
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003410 mcp->mb[0] = MBC_TRACE_CONTROL;
3411 mcp->mb[1] = TC_EFT_DISABLE;
3412 mcp->out_mb = MBX_1|MBX_0;
3413 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003414 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003415 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003416 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003417 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003418 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3419 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3420 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003421 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003422 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3423 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003424 }
3425
3426 return rval;
3427}
3428
Andrew Vasquez88729e52006-06-23 16:10:50 -07003429int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003430qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003431 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3432{
3433 int rval;
3434 mbx_cmd_t mc;
3435 mbx_cmd_t *mcp = &mc;
3436
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003437 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3438 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003439
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003440 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003441 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003442 return QLA_FUNCTION_FAILED;
3443
Andrew Vasquez85880802009-12-15 21:29:46 -08003444 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3445 return QLA_FUNCTION_FAILED;
3446
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003447 mcp->mb[0] = MBC_TRACE_CONTROL;
3448 mcp->mb[1] = TC_FCE_ENABLE;
3449 mcp->mb[2] = LSW(fce_dma);
3450 mcp->mb[3] = MSW(fce_dma);
3451 mcp->mb[4] = LSW(MSD(fce_dma));
3452 mcp->mb[5] = MSW(MSD(fce_dma));
3453 mcp->mb[6] = buffers;
3454 mcp->mb[7] = TC_AEN_DISABLE;
3455 mcp->mb[8] = 0;
3456 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3457 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3458 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3459 MBX_1|MBX_0;
3460 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003461 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003462 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003463 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003464 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003465 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3466 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3467 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003468 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003469 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3470 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003471
3472 if (mb)
3473 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3474 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003475 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003476 }
3477
3478 return rval;
3479}
3480
3481int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003482qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003483{
3484 int rval;
3485 mbx_cmd_t mc;
3486 mbx_cmd_t *mcp = &mc;
3487
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003488 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3489 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003490
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003491 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003492 return QLA_FUNCTION_FAILED;
3493
Andrew Vasquez85880802009-12-15 21:29:46 -08003494 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3495 return QLA_FUNCTION_FAILED;
3496
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003497 mcp->mb[0] = MBC_TRACE_CONTROL;
3498 mcp->mb[1] = TC_FCE_DISABLE;
3499 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3500 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3501 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3502 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003503 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003504 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003505 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003506 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003507 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3508 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3509 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003510 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003511 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3512 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003513
3514 if (wr)
3515 *wr = (uint64_t) mcp->mb[5] << 48 |
3516 (uint64_t) mcp->mb[4] << 32 |
3517 (uint64_t) mcp->mb[3] << 16 |
3518 (uint64_t) mcp->mb[2];
3519 if (rd)
3520 *rd = (uint64_t) mcp->mb[9] << 48 |
3521 (uint64_t) mcp->mb[8] << 32 |
3522 (uint64_t) mcp->mb[7] << 16 |
3523 (uint64_t) mcp->mb[6];
3524 }
3525
3526 return rval;
3527}
3528
3529int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003530qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3531 uint16_t *port_speed, uint16_t *mb)
3532{
3533 int rval;
3534 mbx_cmd_t mc;
3535 mbx_cmd_t *mcp = &mc;
3536
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003537 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3538 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003539
Giridhar Malavali6e980162010-03-19 17:03:58 -07003540 if (!IS_IIDMA_CAPABLE(vha->hw))
3541 return QLA_FUNCTION_FAILED;
3542
Giridhar Malavali6e980162010-03-19 17:03:58 -07003543 mcp->mb[0] = MBC_PORT_PARAMS;
3544 mcp->mb[1] = loop_id;
3545 mcp->mb[2] = mcp->mb[3] = 0;
3546 mcp->mb[9] = vha->vp_idx;
3547 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3548 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3549 mcp->tov = MBX_TOV_SECONDS;
3550 mcp->flags = 0;
3551 rval = qla2x00_mailbox_command(vha, mcp);
3552
3553 /* Return mailbox statuses. */
3554 if (mb != NULL) {
3555 mb[0] = mcp->mb[0];
3556 mb[1] = mcp->mb[1];
3557 mb[3] = mcp->mb[3];
3558 }
3559
3560 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003561 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003562 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003563 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3564 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003565 if (port_speed)
3566 *port_speed = mcp->mb[3];
3567 }
3568
3569 return rval;
3570}
3571
3572int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003573qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003574 uint16_t port_speed, uint16_t *mb)
3575{
3576 int rval;
3577 mbx_cmd_t mc;
3578 mbx_cmd_t *mcp = &mc;
3579
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3581 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003582
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003583 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003584 return QLA_FUNCTION_FAILED;
3585
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003586 mcp->mb[0] = MBC_PORT_PARAMS;
3587 mcp->mb[1] = loop_id;
3588 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003589 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003590 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3591 else
3592 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3593 mcp->mb[9] = vha->vp_idx;
3594 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3595 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003596 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003597 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003598 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003599
3600 /* Return mailbox statuses. */
3601 if (mb != NULL) {
3602 mb[0] = mcp->mb[0];
3603 mb[1] = mcp->mb[1];
3604 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003605 }
3606
3607 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003608 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3609 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003610 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003611 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3612 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003613 }
3614
3615 return rval;
3616}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003617
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003618void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003619qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003620 struct vp_rpt_id_entry_24xx *rptid_entry)
3621{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003622 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003623 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003624 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003625 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003626 port_id_t id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003627
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003628 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3629 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003630
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003631 if (rptid_entry->entry_status != 0)
3632 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003633
Quinn Tran482c9dc2017-03-15 09:48:54 -07003634 id.b.domain = rptid_entry->port_id[2];
3635 id.b.area = rptid_entry->port_id[1];
3636 id.b.al_pa = rptid_entry->port_id[0];
3637 id.b.rsvd_1 = 0;
3638
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003639 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003640 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003641 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003642 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003643 "VPs acquired %d.\n", rptid_entry->vp_setup,
3644 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003645 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003646 "Primary port id %02x%02x%02x.\n",
3647 rptid_entry->port_id[2], rptid_entry->port_id[1],
3648 rptid_entry->port_id[0]);
Quinn Tran41dc5292017-01-19 22:28:03 -08003649
Quinn Tran482c9dc2017-03-15 09:48:54 -07003650 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003651
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003652 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003653 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003654 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003655 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003656 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3657 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003658 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003659 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003660
Sawan Chandak969a6192016-01-27 12:03:32 -05003661 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003662 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003663
Quinn Tran41dc5292017-01-19 22:28:03 -08003664 if (rptid_entry->vp_idx == 0) {
3665 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3666 /* FA-WWN is only for physical port */
3667 if (qla_ini_mode_enabled(vha) &&
3668 ha->flags.fawwpn_enabled &&
3669 (rptid_entry->u.f1.flags &
3670 VP_FLAGS_NAME_VALID)) {
3671 memcpy(vha->port_name,
3672 rptid_entry->u.f1.port_name,
3673 WWN_SIZE);
3674 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003675
Quinn Tran482c9dc2017-03-15 09:48:54 -07003676 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003677 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003678
Quinn Tran41dc5292017-01-19 22:28:03 -08003679 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3680 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3681 } else {
3682 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3683 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3684 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3685 "Could not acquire ID for VP[%d].\n",
3686 rptid_entry->vp_idx);
3687 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003688 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003689
3690 found = 0;
3691 spin_lock_irqsave(&ha->vport_slock, flags);
3692 list_for_each_entry(vp, &ha->vp_list, list) {
3693 if (rptid_entry->vp_idx == vp->vp_idx) {
3694 found = 1;
3695 break;
3696 }
3697 }
3698 spin_unlock_irqrestore(&ha->vport_slock, flags);
3699
3700 if (!found)
3701 return;
3702
Quinn Tran482c9dc2017-03-15 09:48:54 -07003703 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003704
3705 /*
3706 * Cannot configure here as we are still sitting on the
3707 * response queue. Handle it in dpc context.
3708 */
3709 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3710 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3711 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003712 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003713 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003714 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003715 } else if (rptid_entry->format == 2) {
3716 ql_dbg(ql_dbg_async, vha, 0xffff,
3717 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3718 rptid_entry->port_id[2], rptid_entry->port_id[1],
3719 rptid_entry->port_id[0]);
3720
3721 ql_dbg(ql_dbg_async, vha, 0xffff,
3722 "N2N: Remote WWPN %8phC.\n",
3723 rptid_entry->u.f2.port_name);
3724
3725 /* N2N. direct connect */
3726 vha->d_id.b.domain = rptid_entry->port_id[2];
3727 vha->d_id.b.area = rptid_entry->port_id[1];
3728 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3729
3730 spin_lock_irqsave(&ha->vport_slock, flags);
3731 qlt_update_vp_map(vha, SET_AL_PA);
3732 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003733 }
3734}
3735
3736/*
3737 * qla24xx_modify_vp_config
3738 * Change VP configuration for vha
3739 *
3740 * Input:
3741 * vha = adapter block pointer.
3742 *
3743 * Returns:
3744 * qla2xxx local function return status code.
3745 *
3746 * Context:
3747 * Kernel context.
3748 */
3749int
3750qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3751{
3752 int rval;
3753 struct vp_config_entry_24xx *vpmod;
3754 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003755 struct qla_hw_data *ha = vha->hw;
3756 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003757
3758 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003759
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003760 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3761 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003762
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003763 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003764 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003765 ql_log(ql_log_warn, vha, 0x10bc,
3766 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003767 return QLA_MEMORY_ALLOC_FAILED;
3768 }
3769
3770 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3771 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3772 vpmod->entry_count = 1;
3773 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3774 vpmod->vp_count = 1;
3775 vpmod->vp_index1 = vha->vp_idx;
3776 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003777
3778 qlt_modify_vp_config(vha, vpmod);
3779
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003780 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3781 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3782 vpmod->entry_count = 1;
3783
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003784 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003785 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003786 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3787 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003788 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003789 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3790 "Failed to complete IOCB -- error status (%x).\n",
3791 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003792 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003793 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003794 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3795 "Failed to complete IOCB -- completion status (%x).\n",
3796 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003797 rval = QLA_FUNCTION_FAILED;
3798 } else {
3799 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003800 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3801 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003802 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3803 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003804 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003805
3806 return rval;
3807}
3808
3809/*
3810 * qla24xx_control_vp
3811 * Enable a virtual port for given host
3812 *
3813 * Input:
3814 * ha = adapter block pointer.
3815 * vhba = virtual adapter (unused)
3816 * index = index number for enabled VP
3817 *
3818 * Returns:
3819 * qla2xxx local function return status code.
3820 *
3821 * Context:
3822 * Kernel context.
3823 */
3824int
3825qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3826{
3827 int rval;
3828 int map, pos;
3829 struct vp_ctrl_entry_24xx *vce;
3830 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003831 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003832 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003833 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003834
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003835 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003836 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003837
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003838 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003839 return QLA_PARAMETER_ERROR;
3840
3841 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3842 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003843 ql_log(ql_log_warn, vha, 0x10c2,
3844 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003845 return QLA_MEMORY_ALLOC_FAILED;
3846 }
3847 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3848
3849 vce->entry_type = VP_CTRL_IOCB_TYPE;
3850 vce->entry_count = 1;
3851 vce->command = cpu_to_le16(cmd);
Bart Van Asschead950362015-07-09 07:24:08 -07003852 vce->vp_count = cpu_to_le16(1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003853
3854 /* index map in firmware starts with 1; decrement index
3855 * this is ok as we never use index 0
3856 */
3857 map = (vp_index - 1) / 8;
3858 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003859 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003860 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003861 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003862
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003863 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003864 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003865 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3866 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003867 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003868 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3869 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003870 vce->entry_status);
3871 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003872 } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003873 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3874 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003875 le16_to_cpu(vce->comp_status));
3876 rval = QLA_FUNCTION_FAILED;
3877 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003878 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3879 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003880 }
3881
3882 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3883
3884 return rval;
3885}
3886
3887/*
3888 * qla2x00_send_change_request
3889 * Receive or disable RSCN request from fabric controller
3890 *
3891 * Input:
3892 * ha = adapter block pointer
3893 * format = registration format:
3894 * 0 - Reserved
3895 * 1 - Fabric detected registration
3896 * 2 - N_port detected registration
3897 * 3 - Full registration
3898 * FF - clear registration
3899 * vp_idx = Virtual port index
3900 *
3901 * Returns:
3902 * qla2x00 local function return status code.
3903 *
3904 * Context:
3905 * Kernel Context
3906 */
3907
3908int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003909qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003910 uint16_t vp_idx)
3911{
3912 int rval;
3913 mbx_cmd_t mc;
3914 mbx_cmd_t *mcp = &mc;
3915
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003916 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3917 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003918
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003919 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3920 mcp->mb[1] = format;
3921 mcp->mb[9] = vp_idx;
3922 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3923 mcp->in_mb = MBX_0|MBX_1;
3924 mcp->tov = MBX_TOV_SECONDS;
3925 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003926 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003927
3928 if (rval == QLA_SUCCESS) {
3929 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3930 rval = BIT_1;
3931 }
3932 } else
3933 rval = BIT_1;
3934
3935 return rval;
3936}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003937
3938int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003939qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003940 uint32_t size)
3941{
3942 int rval;
3943 mbx_cmd_t mc;
3944 mbx_cmd_t *mcp = &mc;
3945
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003946 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3947 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003948
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003949 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003950 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3951 mcp->mb[8] = MSW(addr);
3952 mcp->out_mb = MBX_8|MBX_0;
3953 } else {
3954 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3955 mcp->out_mb = MBX_0;
3956 }
3957 mcp->mb[1] = LSW(addr);
3958 mcp->mb[2] = MSW(req_dma);
3959 mcp->mb[3] = LSW(req_dma);
3960 mcp->mb[6] = MSW(MSD(req_dma));
3961 mcp->mb[7] = LSW(MSD(req_dma));
3962 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003963 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003964 mcp->mb[4] = MSW(size);
3965 mcp->mb[5] = LSW(size);
3966 mcp->out_mb |= MBX_5|MBX_4;
3967 } else {
3968 mcp->mb[4] = LSW(size);
3969 mcp->out_mb |= MBX_4;
3970 }
3971
3972 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003973 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003974 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003975 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003976
3977 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003978 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3979 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003980 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003981 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3982 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003983 }
3984
3985 return rval;
3986}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003987/* 84XX Support **************************************************************/
3988
3989struct cs84xx_mgmt_cmd {
3990 union {
3991 struct verify_chip_entry_84xx req;
3992 struct verify_chip_rsp_84xx rsp;
3993 } p;
3994};
3995
3996int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003997qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003998{
3999 int rval, retry;
4000 struct cs84xx_mgmt_cmd *mn;
4001 dma_addr_t mn_dma;
4002 uint16_t options;
4003 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004004 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004005
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004006 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4007 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004008
4009 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4010 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004011 return QLA_MEMORY_ALLOC_FAILED;
4012 }
4013
4014 /* Force Update? */
4015 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4016 /* Diagnostic firmware? */
4017 /* options |= MENLO_DIAG_FW; */
4018 /* We update the firmware with only one data sequence. */
4019 options |= VCO_END_OF_DATA;
4020
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004021 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004022 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004023 memset(mn, 0, sizeof(*mn));
4024 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4025 mn->p.req.entry_count = 1;
4026 mn->p.req.options = cpu_to_le16(options);
4027
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004028 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4029 "Dump of Verify Request.\n");
4030 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4031 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004032
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004033 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004034 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004035 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4036 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004037 goto verify_done;
4038 }
4039
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004040 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4041 "Dump of Verify Response.\n");
4042 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4043 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004044
4045 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4046 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4047 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004048 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004049 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004050
4051 if (status[0] != CS_COMPLETE) {
4052 rval = QLA_FUNCTION_FAILED;
4053 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004054 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4055 "Firmware update failed. Retrying "
4056 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004057 options |= VCO_DONT_UPDATE_FW;
4058 options &= ~VCO_FORCE_UPDATE;
4059 retry = 1;
4060 }
4061 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004062 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004063 "Firmware updated to %x.\n",
4064 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004065
4066 /* NOTE: we only update OP firmware. */
4067 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4068 ha->cs84xx->op_fw_version =
4069 le32_to_cpu(mn->p.rsp.fw_ver);
4070 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4071 flags);
4072 }
4073 } while (retry);
4074
4075verify_done:
4076 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4077
4078 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004079 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4080 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004081 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4083 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004084 }
4085
4086 return rval;
4087}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004088
4089int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004090qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004091{
4092 int rval;
4093 unsigned long flags;
4094 mbx_cmd_t mc;
4095 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004096 struct qla_hw_data *ha = vha->hw;
4097
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004098 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4099 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004100
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004101 if (IS_SHADOW_REG_CAPABLE(ha))
4102 req->options |= BIT_13;
4103
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004104 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004105 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004106 mcp->mb[2] = MSW(LSD(req->dma));
4107 mcp->mb[3] = LSW(LSD(req->dma));
4108 mcp->mb[6] = MSW(MSD(req->dma));
4109 mcp->mb[7] = LSW(MSD(req->dma));
4110 mcp->mb[5] = req->length;
4111 if (req->rsp)
4112 mcp->mb[10] = req->rsp->id;
4113 mcp->mb[12] = req->qos;
4114 mcp->mb[11] = req->vp_idx;
4115 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004116 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004117 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004118
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004119 mcp->mb[4] = req->id;
4120 /* que in ptr index */
4121 mcp->mb[8] = 0;
4122 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004123 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004124 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4125 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4126 mcp->in_mb = MBX_0;
4127 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004128 mcp->tov = MBX_TOV_SECONDS * 2;
4129
Chad Dupuisf73cb692014-02-26 04:15:06 -05004130 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004131 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004132 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004133 mcp->out_mb |= MBX_15;
4134 /* debug q create issue in SR-IOV */
4135 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4136 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004137
4138 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004139 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004140 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004141 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004142 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004143 }
4144 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4145
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004146 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004147 if (rval != QLA_SUCCESS) {
4148 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4149 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4150 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004151 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4152 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004153 }
4154
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004155 return rval;
4156}
4157
4158int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004159qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004160{
4161 int rval;
4162 unsigned long flags;
4163 mbx_cmd_t mc;
4164 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004165 struct qla_hw_data *ha = vha->hw;
4166
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004167 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4168 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004169
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004170 if (IS_SHADOW_REG_CAPABLE(ha))
4171 rsp->options |= BIT_13;
4172
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004173 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004174 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004175 mcp->mb[2] = MSW(LSD(rsp->dma));
4176 mcp->mb[3] = LSW(LSD(rsp->dma));
4177 mcp->mb[6] = MSW(MSD(rsp->dma));
4178 mcp->mb[7] = LSW(MSD(rsp->dma));
4179 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004180 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004181 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004182 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004183 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004184
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004185 mcp->mb[4] = rsp->id;
4186 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004187 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004188 /* que out ptr index */
4189 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004190 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004191 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4192 mcp->in_mb = MBX_0;
4193 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004194 mcp->tov = MBX_TOV_SECONDS * 2;
4195
4196 if (IS_QLA81XX(ha)) {
4197 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4198 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004199 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004200 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4201 mcp->in_mb |= MBX_1;
4202 /* debug q create issue in SR-IOV */
4203 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4204 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004205
4206 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004207 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004208 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004209 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004210 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004211 }
4212
4213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4214
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004215 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004216 if (rval != QLA_SUCCESS) {
4217 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4218 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4219 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004220 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4221 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004222 }
4223
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004224 return rval;
4225}
4226
Andrew Vasquez8a659572009-02-08 20:50:12 -08004227int
4228qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4229{
4230 int rval;
4231 mbx_cmd_t mc;
4232 mbx_cmd_t *mcp = &mc;
4233
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004234 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4235 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004236
4237 mcp->mb[0] = MBC_IDC_ACK;
4238 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4239 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4240 mcp->in_mb = MBX_0;
4241 mcp->tov = MBX_TOV_SECONDS;
4242 mcp->flags = 0;
4243 rval = qla2x00_mailbox_command(vha, mcp);
4244
4245 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004246 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4247 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004248 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4250 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004251 }
4252
4253 return rval;
4254}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004255
4256int
4257qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4258{
4259 int rval;
4260 mbx_cmd_t mc;
4261 mbx_cmd_t *mcp = &mc;
4262
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004263 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4264 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004265
Chad Dupuisf73cb692014-02-26 04:15:06 -05004266 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4267 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004268 return QLA_FUNCTION_FAILED;
4269
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004270 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4271 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4272 mcp->out_mb = MBX_1|MBX_0;
4273 mcp->in_mb = MBX_1|MBX_0;
4274 mcp->tov = MBX_TOV_SECONDS;
4275 mcp->flags = 0;
4276 rval = qla2x00_mailbox_command(vha, mcp);
4277
4278 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004279 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4280 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4281 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004282 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004283 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4284 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004285 *sector_size = mcp->mb[1];
4286 }
4287
4288 return rval;
4289}
4290
4291int
4292qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4293{
4294 int rval;
4295 mbx_cmd_t mc;
4296 mbx_cmd_t *mcp = &mc;
4297
Chad Dupuisf73cb692014-02-26 04:15:06 -05004298 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4299 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004300 return QLA_FUNCTION_FAILED;
4301
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4303 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004304
4305 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4306 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4307 FAC_OPT_CMD_WRITE_PROTECT;
4308 mcp->out_mb = MBX_1|MBX_0;
4309 mcp->in_mb = MBX_1|MBX_0;
4310 mcp->tov = MBX_TOV_SECONDS;
4311 mcp->flags = 0;
4312 rval = qla2x00_mailbox_command(vha, mcp);
4313
4314 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004315 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4316 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4317 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004318 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004319 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4320 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004321 }
4322
4323 return rval;
4324}
4325
4326int
4327qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4328{
4329 int rval;
4330 mbx_cmd_t mc;
4331 mbx_cmd_t *mcp = &mc;
4332
Chad Dupuisf73cb692014-02-26 04:15:06 -05004333 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4334 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004335 return QLA_FUNCTION_FAILED;
4336
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004337 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4338 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004339
4340 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4341 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4342 mcp->mb[2] = LSW(start);
4343 mcp->mb[3] = MSW(start);
4344 mcp->mb[4] = LSW(finish);
4345 mcp->mb[5] = MSW(finish);
4346 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4347 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4348 mcp->tov = MBX_TOV_SECONDS;
4349 mcp->flags = 0;
4350 rval = qla2x00_mailbox_command(vha, mcp);
4351
4352 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004353 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4354 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4355 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004356 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004357 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4358 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004359 }
4360
4361 return rval;
4362}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004363
4364int
4365qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4366{
4367 int rval = 0;
4368 mbx_cmd_t mc;
4369 mbx_cmd_t *mcp = &mc;
4370
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4372 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004373
4374 mcp->mb[0] = MBC_RESTART_MPI_FW;
4375 mcp->out_mb = MBX_0;
4376 mcp->in_mb = MBX_0|MBX_1;
4377 mcp->tov = MBX_TOV_SECONDS;
4378 mcp->flags = 0;
4379 rval = qla2x00_mailbox_command(vha, mcp);
4380
4381 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004382 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4383 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4384 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004385 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004386 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4387 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004388 }
4389
4390 return rval;
4391}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004392
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004393int
4394qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4395{
4396 int rval;
4397 mbx_cmd_t mc;
4398 mbx_cmd_t *mcp = &mc;
4399 int i;
4400 int len;
4401 uint16_t *str;
4402 struct qla_hw_data *ha = vha->hw;
4403
4404 if (!IS_P3P_TYPE(ha))
4405 return QLA_FUNCTION_FAILED;
4406
4407 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4408 "Entered %s.\n", __func__);
4409
4410 str = (void *)version;
4411 len = strlen(version);
4412
4413 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4414 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4415 mcp->out_mb = MBX_1|MBX_0;
4416 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4417 mcp->mb[i] = cpu_to_le16p(str);
4418 mcp->out_mb |= 1<<i;
4419 }
4420 for (; i < 16; i++) {
4421 mcp->mb[i] = 0;
4422 mcp->out_mb |= 1<<i;
4423 }
4424 mcp->in_mb = MBX_1|MBX_0;
4425 mcp->tov = MBX_TOV_SECONDS;
4426 mcp->flags = 0;
4427 rval = qla2x00_mailbox_command(vha, mcp);
4428
4429 if (rval != QLA_SUCCESS) {
4430 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4431 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4432 } else {
4433 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4434 "Done %s.\n", __func__);
4435 }
4436
4437 return rval;
4438}
4439
4440int
4441qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4442{
4443 int rval;
4444 mbx_cmd_t mc;
4445 mbx_cmd_t *mcp = &mc;
4446 int len;
4447 uint16_t dwlen;
4448 uint8_t *str;
4449 dma_addr_t str_dma;
4450 struct qla_hw_data *ha = vha->hw;
4451
4452 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4453 IS_P3P_TYPE(ha))
4454 return QLA_FUNCTION_FAILED;
4455
4456 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4457 "Entered %s.\n", __func__);
4458
4459 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4460 if (!str) {
4461 ql_log(ql_log_warn, vha, 0x117f,
4462 "Failed to allocate driver version param.\n");
4463 return QLA_MEMORY_ALLOC_FAILED;
4464 }
4465
4466 memcpy(str, "\x7\x3\x11\x0", 4);
4467 dwlen = str[0];
4468 len = dwlen * 4 - 4;
4469 memset(str + 4, 0, len);
4470 if (len > strlen(version))
4471 len = strlen(version);
4472 memcpy(str + 4, version, len);
4473
4474 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4475 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4476 mcp->mb[2] = MSW(LSD(str_dma));
4477 mcp->mb[3] = LSW(LSD(str_dma));
4478 mcp->mb[6] = MSW(MSD(str_dma));
4479 mcp->mb[7] = LSW(MSD(str_dma));
4480 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4481 mcp->in_mb = MBX_1|MBX_0;
4482 mcp->tov = MBX_TOV_SECONDS;
4483 mcp->flags = 0;
4484 rval = qla2x00_mailbox_command(vha, mcp);
4485
4486 if (rval != QLA_SUCCESS) {
4487 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4488 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4489 } else {
4490 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4491 "Done %s.\n", __func__);
4492 }
4493
4494 dma_pool_free(ha->s_dma_pool, str, str_dma);
4495
4496 return rval;
4497}
4498
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004499static int
4500qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4501{
4502 int rval;
4503 mbx_cmd_t mc;
4504 mbx_cmd_t *mcp = &mc;
4505
4506 if (!IS_FWI2_CAPABLE(vha->hw))
4507 return QLA_FUNCTION_FAILED;
4508
4509 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4510 "Entered %s.\n", __func__);
4511
4512 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4513 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4514 mcp->out_mb = MBX_1|MBX_0;
4515 mcp->in_mb = MBX_1|MBX_0;
4516 mcp->tov = MBX_TOV_SECONDS;
4517 mcp->flags = 0;
4518 rval = qla2x00_mailbox_command(vha, mcp);
4519 *temp = mcp->mb[1];
4520
4521 if (rval != QLA_SUCCESS) {
4522 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4523 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4524 } else {
4525 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4526 "Done %s.\n", __func__);
4527 }
4528
4529 return rval;
4530}
4531
Joe Carnuccio3a117112013-02-08 01:58:00 -05004532int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004533qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4534 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004535{
4536 int rval;
4537 mbx_cmd_t mc;
4538 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004539 struct qla_hw_data *ha = vha->hw;
4540
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004541 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4542 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004543
Joe Carnuccio6766df92011-05-10 11:30:15 -07004544 if (!IS_FWI2_CAPABLE(ha))
4545 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004546
Joe Carnuccio6766df92011-05-10 11:30:15 -07004547 if (len == 1)
4548 opt |= BIT_0;
4549
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004550 mcp->mb[0] = MBC_READ_SFP;
4551 mcp->mb[1] = dev;
4552 mcp->mb[2] = MSW(sfp_dma);
4553 mcp->mb[3] = LSW(sfp_dma);
4554 mcp->mb[6] = MSW(MSD(sfp_dma));
4555 mcp->mb[7] = LSW(MSD(sfp_dma));
4556 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004557 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004558 mcp->mb[10] = opt;
4559 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 -07004560 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004561 mcp->tov = MBX_TOV_SECONDS;
4562 mcp->flags = 0;
4563 rval = qla2x00_mailbox_command(vha, mcp);
4564
4565 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004566 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004567
4568 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004569 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4570 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004571 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004572 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4573 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004574 }
4575
4576 return rval;
4577}
4578
4579int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004580qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4581 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004582{
4583 int rval;
4584 mbx_cmd_t mc;
4585 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004586 struct qla_hw_data *ha = vha->hw;
4587
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4589 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004590
Joe Carnuccio6766df92011-05-10 11:30:15 -07004591 if (!IS_FWI2_CAPABLE(ha))
4592 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004593
Joe Carnuccio6766df92011-05-10 11:30:15 -07004594 if (len == 1)
4595 opt |= BIT_0;
4596
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004597 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004598 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004599
4600 mcp->mb[0] = MBC_WRITE_SFP;
4601 mcp->mb[1] = dev;
4602 mcp->mb[2] = MSW(sfp_dma);
4603 mcp->mb[3] = LSW(sfp_dma);
4604 mcp->mb[6] = MSW(MSD(sfp_dma));
4605 mcp->mb[7] = LSW(MSD(sfp_dma));
4606 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004607 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004608 mcp->mb[10] = opt;
4609 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 -07004610 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004611 mcp->tov = MBX_TOV_SECONDS;
4612 mcp->flags = 0;
4613 rval = qla2x00_mailbox_command(vha, mcp);
4614
4615 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004616 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4617 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004618 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004619 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4620 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004621 }
4622
4623 return rval;
4624}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004625
4626int
4627qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4628 uint16_t size_in_bytes, uint16_t *actual_size)
4629{
4630 int rval;
4631 mbx_cmd_t mc;
4632 mbx_cmd_t *mcp = &mc;
4633
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004634 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4635 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004636
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004637 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004638 return QLA_FUNCTION_FAILED;
4639
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004640 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4641 mcp->mb[2] = MSW(stats_dma);
4642 mcp->mb[3] = LSW(stats_dma);
4643 mcp->mb[6] = MSW(MSD(stats_dma));
4644 mcp->mb[7] = LSW(MSD(stats_dma));
4645 mcp->mb[8] = size_in_bytes >> 2;
4646 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4647 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4648 mcp->tov = MBX_TOV_SECONDS;
4649 mcp->flags = 0;
4650 rval = qla2x00_mailbox_command(vha, mcp);
4651
4652 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004653 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4654 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4655 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004656 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4658 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004659
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004660
4661 *actual_size = mcp->mb[2] << 2;
4662 }
4663
4664 return rval;
4665}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004666
4667int
4668qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4669 uint16_t size)
4670{
4671 int rval;
4672 mbx_cmd_t mc;
4673 mbx_cmd_t *mcp = &mc;
4674
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004675 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4676 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004677
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004678 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004679 return QLA_FUNCTION_FAILED;
4680
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004681 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4682 mcp->mb[1] = 0;
4683 mcp->mb[2] = MSW(tlv_dma);
4684 mcp->mb[3] = LSW(tlv_dma);
4685 mcp->mb[6] = MSW(MSD(tlv_dma));
4686 mcp->mb[7] = LSW(MSD(tlv_dma));
4687 mcp->mb[8] = size;
4688 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4689 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4690 mcp->tov = MBX_TOV_SECONDS;
4691 mcp->flags = 0;
4692 rval = qla2x00_mailbox_command(vha, mcp);
4693
4694 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004695 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4696 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4697 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004698 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004699 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4700 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004701 }
4702
4703 return rval;
4704}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004705
4706int
4707qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4708{
4709 int rval;
4710 mbx_cmd_t mc;
4711 mbx_cmd_t *mcp = &mc;
4712
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4714 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004715
Andrew Vasquez18e75552009-06-03 09:55:30 -07004716 if (!IS_FWI2_CAPABLE(vha->hw))
4717 return QLA_FUNCTION_FAILED;
4718
Andrew Vasquez18e75552009-06-03 09:55:30 -07004719 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4720 mcp->mb[1] = LSW(risc_addr);
4721 mcp->mb[8] = MSW(risc_addr);
4722 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4723 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4724 mcp->tov = 30;
4725 mcp->flags = 0;
4726 rval = qla2x00_mailbox_command(vha, mcp);
4727 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004728 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4729 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004730 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004731 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4732 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004733 *data = mcp->mb[3] << 16 | mcp->mb[2];
4734 }
4735
4736 return rval;
4737}
4738
4739int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004740qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4741 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004742{
4743 int rval;
4744 mbx_cmd_t mc;
4745 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004746
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004747 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4748 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004749
4750 memset(mcp->mb, 0 , sizeof(mcp->mb));
4751 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4752 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4753
4754 /* transfer count */
4755 mcp->mb[10] = LSW(mreq->transfer_size);
4756 mcp->mb[11] = MSW(mreq->transfer_size);
4757
4758 /* send data address */
4759 mcp->mb[14] = LSW(mreq->send_dma);
4760 mcp->mb[15] = MSW(mreq->send_dma);
4761 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4762 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4763
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004764 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004765 mcp->mb[16] = LSW(mreq->rcv_dma);
4766 mcp->mb[17] = MSW(mreq->rcv_dma);
4767 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4768 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4769
4770 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004771 mcp->mb[18] = LSW(mreq->iteration_count);
4772 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004773
4774 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4775 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 -08004776 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004777 mcp->out_mb |= MBX_2;
4778 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4779
4780 mcp->buf_size = mreq->transfer_size;
4781 mcp->tov = MBX_TOV_SECONDS;
4782 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4783
4784 rval = qla2x00_mailbox_command(vha, mcp);
4785
4786 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004787 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4788 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4789 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4790 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004791 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004792 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4793 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004794 }
4795
4796 /* Copy mailbox information */
4797 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004798 return rval;
4799}
4800
4801int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004802qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4803 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004804{
4805 int rval;
4806 mbx_cmd_t mc;
4807 mbx_cmd_t *mcp = &mc;
4808 struct qla_hw_data *ha = vha->hw;
4809
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004810 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4811 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004812
4813 memset(mcp->mb, 0 , sizeof(mcp->mb));
4814 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07004815 /* BIT_6 specifies 64bit address */
4816 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004817 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004818 mcp->mb[2] = vha->fcoe_fcf_idx;
4819 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004820 mcp->mb[16] = LSW(mreq->rcv_dma);
4821 mcp->mb[17] = MSW(mreq->rcv_dma);
4822 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4823 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4824
4825 mcp->mb[10] = LSW(mreq->transfer_size);
4826
4827 mcp->mb[14] = LSW(mreq->send_dma);
4828 mcp->mb[15] = MSW(mreq->send_dma);
4829 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4830 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4831
4832 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4833 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004834 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004835 mcp->out_mb |= MBX_2;
4836
4837 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004838 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4839 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004840 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004841 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004842 mcp->in_mb |= MBX_3;
4843
4844 mcp->tov = MBX_TOV_SECONDS;
4845 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4846 mcp->buf_size = mreq->transfer_size;
4847
4848 rval = qla2x00_mailbox_command(vha, mcp);
4849
4850 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004851 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4852 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4853 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004854 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004855 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4856 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004857 }
4858
4859 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004860 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004861 return rval;
4862}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004863
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004864int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004865qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004866{
4867 int rval;
4868 mbx_cmd_t mc;
4869 mbx_cmd_t *mcp = &mc;
4870
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004871 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004872 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004873
4874 mcp->mb[0] = MBC_ISP84XX_RESET;
4875 mcp->mb[1] = enable_diagnostic;
4876 mcp->out_mb = MBX_1|MBX_0;
4877 mcp->in_mb = MBX_1|MBX_0;
4878 mcp->tov = MBX_TOV_SECONDS;
4879 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004880 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004881
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004882 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004883 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004884 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4886 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004887
4888 return rval;
4889}
4890
4891int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004892qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4893{
4894 int rval;
4895 mbx_cmd_t mc;
4896 mbx_cmd_t *mcp = &mc;
4897
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004898 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4899 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004900
Andrew Vasquez18e75552009-06-03 09:55:30 -07004901 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004902 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004903
Andrew Vasquez18e75552009-06-03 09:55:30 -07004904 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4905 mcp->mb[1] = LSW(risc_addr);
4906 mcp->mb[2] = LSW(data);
4907 mcp->mb[3] = MSW(data);
4908 mcp->mb[8] = MSW(risc_addr);
4909 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4910 mcp->in_mb = MBX_0;
4911 mcp->tov = 30;
4912 mcp->flags = 0;
4913 rval = qla2x00_mailbox_command(vha, mcp);
4914 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004915 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4916 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004917 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004918 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4919 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004920 }
4921
4922 return rval;
4923}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004924
4925int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004926qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4927{
4928 int rval;
4929 uint32_t stat, timer;
4930 uint16_t mb0 = 0;
4931 struct qla_hw_data *ha = vha->hw;
4932 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4933
4934 rval = QLA_SUCCESS;
4935
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004936 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4937 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004938
4939 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4940
4941 /* Write the MBC data to the registers */
4942 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4943 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4944 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4945 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4946 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4947
4948 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4949
4950 /* Poll for MBC interrupt */
4951 for (timer = 6000000; timer; timer--) {
4952 /* Check for pending interrupts. */
4953 stat = RD_REG_DWORD(&reg->host_status);
4954 if (stat & HSRX_RISC_INT) {
4955 stat &= 0xff;
4956
4957 if (stat == 0x1 || stat == 0x2 ||
4958 stat == 0x10 || stat == 0x11) {
4959 set_bit(MBX_INTERRUPT,
4960 &ha->mbx_cmd_flags);
4961 mb0 = RD_REG_WORD(&reg->mailbox0);
4962 WRT_REG_DWORD(&reg->hccr,
4963 HCCRX_CLR_RISC_INT);
4964 RD_REG_DWORD(&reg->hccr);
4965 break;
4966 }
4967 }
4968 udelay(5);
4969 }
4970
4971 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4972 rval = mb0 & MBS_MASK;
4973 else
4974 rval = QLA_FUNCTION_FAILED;
4975
4976 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004977 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4978 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004979 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004980 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4981 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004982 }
4983
4984 return rval;
4985}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004986
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004987int
Michael Hernandez3064ff32009-12-15 21:29:44 -08004988qla2x00_get_data_rate(scsi_qla_host_t *vha)
4989{
4990 int rval;
4991 mbx_cmd_t mc;
4992 mbx_cmd_t *mcp = &mc;
4993 struct qla_hw_data *ha = vha->hw;
4994
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004995 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
4996 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004997
Michael Hernandez3064ff32009-12-15 21:29:44 -08004998 if (!IS_FWI2_CAPABLE(ha))
4999 return QLA_FUNCTION_FAILED;
5000
Michael Hernandez3064ff32009-12-15 21:29:44 -08005001 mcp->mb[0] = MBC_DATA_RATE;
5002 mcp->mb[1] = 0;
5003 mcp->out_mb = MBX_1|MBX_0;
5004 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005005 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005006 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005007 mcp->tov = MBX_TOV_SECONDS;
5008 mcp->flags = 0;
5009 rval = qla2x00_mailbox_command(vha, mcp);
5010 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005011 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5012 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005013 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005014 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5015 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005016 if (mcp->mb[1] != 0x7)
5017 ha->link_data_rate = mcp->mb[1];
5018 }
5019
5020 return rval;
5021}
Sarang Radke09ff7012010-03-19 17:03:59 -07005022
5023int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005024qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5025{
5026 int rval;
5027 mbx_cmd_t mc;
5028 mbx_cmd_t *mcp = &mc;
5029 struct qla_hw_data *ha = vha->hw;
5030
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005031 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5032 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005033
Chad Dupuisf73cb692014-02-26 04:15:06 -05005034 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5035 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005036 return QLA_FUNCTION_FAILED;
5037 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5038 mcp->out_mb = MBX_0;
5039 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5040 mcp->tov = MBX_TOV_SECONDS;
5041 mcp->flags = 0;
5042
5043 rval = qla2x00_mailbox_command(vha, mcp);
5044
5045 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005046 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5047 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005048 } else {
5049 /* Copy all bits to preserve original value */
5050 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5051
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005052 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5053 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005054 }
5055 return rval;
5056}
5057
5058int
5059qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5060{
5061 int rval;
5062 mbx_cmd_t mc;
5063 mbx_cmd_t *mcp = &mc;
5064
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005065 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5066 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005067
5068 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5069 /* Copy all bits to preserve original setting */
5070 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5071 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5072 mcp->in_mb = MBX_0;
5073 mcp->tov = MBX_TOV_SECONDS;
5074 mcp->flags = 0;
5075 rval = qla2x00_mailbox_command(vha, mcp);
5076
5077 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005078 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5079 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005080 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005081 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5082 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005083
5084 return rval;
5085}
5086
5087
5088int
Sarang Radke09ff7012010-03-19 17:03:59 -07005089qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5090 uint16_t *mb)
5091{
5092 int rval;
5093 mbx_cmd_t mc;
5094 mbx_cmd_t *mcp = &mc;
5095 struct qla_hw_data *ha = vha->hw;
5096
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5098 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005099
Sarang Radke09ff7012010-03-19 17:03:59 -07005100 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5101 return QLA_FUNCTION_FAILED;
5102
Sarang Radke09ff7012010-03-19 17:03:59 -07005103 mcp->mb[0] = MBC_PORT_PARAMS;
5104 mcp->mb[1] = loop_id;
5105 if (ha->flags.fcp_prio_enabled)
5106 mcp->mb[2] = BIT_1;
5107 else
5108 mcp->mb[2] = BIT_2;
5109 mcp->mb[4] = priority & 0xf;
5110 mcp->mb[9] = vha->vp_idx;
5111 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5112 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5113 mcp->tov = 30;
5114 mcp->flags = 0;
5115 rval = qla2x00_mailbox_command(vha, mcp);
5116 if (mb != NULL) {
5117 mb[0] = mcp->mb[0];
5118 mb[1] = mcp->mb[1];
5119 mb[3] = mcp->mb[3];
5120 mb[4] = mcp->mb[4];
5121 }
5122
5123 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005124 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005125 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005126 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5127 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005128 }
5129
5130 return rval;
5131}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005132
5133int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005134qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005135{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005136 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005137 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005138 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005139
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005140 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5141 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5142 "Thermal not supported by this card.\n");
5143 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005144 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005145
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005146 if (IS_QLA25XX(ha)) {
5147 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5148 ha->pdev->subsystem_device == 0x0175) {
5149 rval = qla2x00_read_sfp(vha, 0, &byte,
5150 0x98, 0x1, 1, BIT_13|BIT_0);
5151 *temp = byte;
5152 return rval;
5153 }
5154 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5155 ha->pdev->subsystem_device == 0x338e) {
5156 rval = qla2x00_read_sfp(vha, 0, &byte,
5157 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5158 *temp = byte;
5159 return rval;
5160 }
5161 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5162 "Thermal not supported by this card.\n");
5163 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005164 }
5165
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005166 if (IS_QLA82XX(ha)) {
5167 *temp = qla82xx_read_temperature(vha);
5168 rval = QLA_SUCCESS;
5169 return rval;
5170 } else if (IS_QLA8044(ha)) {
5171 *temp = qla8044_read_temperature(vha);
5172 rval = QLA_SUCCESS;
5173 return rval;
5174 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005175
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005176 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005177 return rval;
5178}
5179
5180int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005181qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5182{
5183 int rval;
5184 struct qla_hw_data *ha = vha->hw;
5185 mbx_cmd_t mc;
5186 mbx_cmd_t *mcp = &mc;
5187
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5189 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005190
Giridhar Malavalia9083012010-04-12 17:59:55 -07005191 if (!IS_FWI2_CAPABLE(ha))
5192 return QLA_FUNCTION_FAILED;
5193
Giridhar Malavalia9083012010-04-12 17:59:55 -07005194 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005195 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005196 mcp->mb[1] = 1;
5197
5198 mcp->out_mb = MBX_1|MBX_0;
5199 mcp->in_mb = MBX_0;
5200 mcp->tov = 30;
5201 mcp->flags = 0;
5202
5203 rval = qla2x00_mailbox_command(vha, mcp);
5204 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005205 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5206 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005207 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005208 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5209 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005210 }
5211
5212 return rval;
5213}
5214
5215int
5216qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5217{
5218 int rval;
5219 struct qla_hw_data *ha = vha->hw;
5220 mbx_cmd_t mc;
5221 mbx_cmd_t *mcp = &mc;
5222
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005223 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5224 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005225
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005226 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005227 return QLA_FUNCTION_FAILED;
5228
Giridhar Malavalia9083012010-04-12 17:59:55 -07005229 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005230 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005231 mcp->mb[1] = 0;
5232
5233 mcp->out_mb = MBX_1|MBX_0;
5234 mcp->in_mb = MBX_0;
5235 mcp->tov = 30;
5236 mcp->flags = 0;
5237
5238 rval = qla2x00_mailbox_command(vha, mcp);
5239 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005240 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5241 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005242 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005243 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5244 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005245 }
5246
5247 return rval;
5248}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005249
5250int
5251qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5252{
5253 struct qla_hw_data *ha = vha->hw;
5254 mbx_cmd_t mc;
5255 mbx_cmd_t *mcp = &mc;
5256 int rval = QLA_FUNCTION_FAILED;
5257
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005258 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5259 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005260
5261 memset(mcp->mb, 0 , sizeof(mcp->mb));
5262 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5263 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5264 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5265 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5266
5267 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5268 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5269 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5270
5271 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5272 mcp->tov = MBX_TOV_SECONDS;
5273 rval = qla2x00_mailbox_command(vha, mcp);
5274
5275 /* Always copy back return mailbox values. */
5276 if (rval != QLA_SUCCESS) {
5277 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5278 "mailbox command FAILED=0x%x, subcode=%x.\n",
5279 (mcp->mb[1] << 16) | mcp->mb[0],
5280 (mcp->mb[3] << 16) | mcp->mb[2]);
5281 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005282 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5283 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005284 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5285 if (!ha->md_template_size) {
5286 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5287 "Null template size obtained.\n");
5288 rval = QLA_FUNCTION_FAILED;
5289 }
5290 }
5291 return rval;
5292}
5293
5294int
5295qla82xx_md_get_template(scsi_qla_host_t *vha)
5296{
5297 struct qla_hw_data *ha = vha->hw;
5298 mbx_cmd_t mc;
5299 mbx_cmd_t *mcp = &mc;
5300 int rval = QLA_FUNCTION_FAILED;
5301
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5303 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005304
5305 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5306 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5307 if (!ha->md_tmplt_hdr) {
5308 ql_log(ql_log_warn, vha, 0x1124,
5309 "Unable to allocate memory for Minidump template.\n");
5310 return rval;
5311 }
5312
5313 memset(mcp->mb, 0 , sizeof(mcp->mb));
5314 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5315 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5316 mcp->mb[2] = LSW(RQST_TMPLT);
5317 mcp->mb[3] = MSW(RQST_TMPLT);
5318 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5319 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5320 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5321 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5322 mcp->mb[8] = LSW(ha->md_template_size);
5323 mcp->mb[9] = MSW(ha->md_template_size);
5324
5325 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5326 mcp->tov = MBX_TOV_SECONDS;
5327 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5328 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5329 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5330 rval = qla2x00_mailbox_command(vha, mcp);
5331
5332 if (rval != QLA_SUCCESS) {
5333 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5334 "mailbox command FAILED=0x%x, subcode=%x.\n",
5335 ((mcp->mb[1] << 16) | mcp->mb[0]),
5336 ((mcp->mb[3] << 16) | mcp->mb[2]));
5337 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5339 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005340 return rval;
5341}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005342
5343int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005344qla8044_md_get_template(scsi_qla_host_t *vha)
5345{
5346 struct qla_hw_data *ha = vha->hw;
5347 mbx_cmd_t mc;
5348 mbx_cmd_t *mcp = &mc;
5349 int rval = QLA_FUNCTION_FAILED;
5350 int offset = 0, size = MINIDUMP_SIZE_36K;
5351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5352 "Entered %s.\n", __func__);
5353
5354 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5355 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5356 if (!ha->md_tmplt_hdr) {
5357 ql_log(ql_log_warn, vha, 0xb11b,
5358 "Unable to allocate memory for Minidump template.\n");
5359 return rval;
5360 }
5361
5362 memset(mcp->mb, 0 , sizeof(mcp->mb));
5363 while (offset < ha->md_template_size) {
5364 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5365 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5366 mcp->mb[2] = LSW(RQST_TMPLT);
5367 mcp->mb[3] = MSW(RQST_TMPLT);
5368 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5369 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5370 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5371 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5372 mcp->mb[8] = LSW(size);
5373 mcp->mb[9] = MSW(size);
5374 mcp->mb[10] = offset & 0x0000FFFF;
5375 mcp->mb[11] = offset & 0xFFFF0000;
5376 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5377 mcp->tov = MBX_TOV_SECONDS;
5378 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5379 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5380 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5381 rval = qla2x00_mailbox_command(vha, mcp);
5382
5383 if (rval != QLA_SUCCESS) {
5384 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5385 "mailbox command FAILED=0x%x, subcode=%x.\n",
5386 ((mcp->mb[1] << 16) | mcp->mb[0]),
5387 ((mcp->mb[3] << 16) | mcp->mb[2]));
5388 return rval;
5389 } else
5390 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5391 "Done %s.\n", __func__);
5392 offset = offset + size;
5393 }
5394 return rval;
5395}
5396
5397int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005398qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5399{
5400 int rval;
5401 struct qla_hw_data *ha = vha->hw;
5402 mbx_cmd_t mc;
5403 mbx_cmd_t *mcp = &mc;
5404
5405 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5406 return QLA_FUNCTION_FAILED;
5407
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5409 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005410
5411 memset(mcp, 0, sizeof(mbx_cmd_t));
5412 mcp->mb[0] = MBC_SET_LED_CONFIG;
5413 mcp->mb[1] = led_cfg[0];
5414 mcp->mb[2] = led_cfg[1];
5415 if (IS_QLA8031(ha)) {
5416 mcp->mb[3] = led_cfg[2];
5417 mcp->mb[4] = led_cfg[3];
5418 mcp->mb[5] = led_cfg[4];
5419 mcp->mb[6] = led_cfg[5];
5420 }
5421
5422 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5423 if (IS_QLA8031(ha))
5424 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5425 mcp->in_mb = MBX_0;
5426 mcp->tov = 30;
5427 mcp->flags = 0;
5428
5429 rval = qla2x00_mailbox_command(vha, mcp);
5430 if (rval != QLA_SUCCESS) {
5431 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5432 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5433 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005434 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5435 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005436 }
5437
5438 return rval;
5439}
5440
5441int
5442qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5443{
5444 int rval;
5445 struct qla_hw_data *ha = vha->hw;
5446 mbx_cmd_t mc;
5447 mbx_cmd_t *mcp = &mc;
5448
5449 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5450 return QLA_FUNCTION_FAILED;
5451
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005452 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5453 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005454
5455 memset(mcp, 0, sizeof(mbx_cmd_t));
5456 mcp->mb[0] = MBC_GET_LED_CONFIG;
5457
5458 mcp->out_mb = MBX_0;
5459 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5460 if (IS_QLA8031(ha))
5461 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5462 mcp->tov = 30;
5463 mcp->flags = 0;
5464
5465 rval = qla2x00_mailbox_command(vha, mcp);
5466 if (rval != QLA_SUCCESS) {
5467 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5468 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5469 } else {
5470 led_cfg[0] = mcp->mb[1];
5471 led_cfg[1] = mcp->mb[2];
5472 if (IS_QLA8031(ha)) {
5473 led_cfg[2] = mcp->mb[3];
5474 led_cfg[3] = mcp->mb[4];
5475 led_cfg[4] = mcp->mb[5];
5476 led_cfg[5] = mcp->mb[6];
5477 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005478 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5479 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005480 }
5481
5482 return rval;
5483}
5484
5485int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005486qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5487{
5488 int rval;
5489 struct qla_hw_data *ha = vha->hw;
5490 mbx_cmd_t mc;
5491 mbx_cmd_t *mcp = &mc;
5492
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005493 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005494 return QLA_FUNCTION_FAILED;
5495
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005496 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005497 "Entered %s.\n", __func__);
5498
5499 memset(mcp, 0, sizeof(mbx_cmd_t));
5500 mcp->mb[0] = MBC_SET_LED_CONFIG;
5501 if (enable)
5502 mcp->mb[7] = 0xE;
5503 else
5504 mcp->mb[7] = 0xD;
5505
5506 mcp->out_mb = MBX_7|MBX_0;
5507 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005508 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005509 mcp->flags = 0;
5510
5511 rval = qla2x00_mailbox_command(vha, mcp);
5512 if (rval != QLA_SUCCESS) {
5513 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5514 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5515 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005516 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005517 "Done %s.\n", __func__);
5518 }
5519
5520 return rval;
5521}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005522
5523int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005524qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005525{
5526 int rval;
5527 struct qla_hw_data *ha = vha->hw;
5528 mbx_cmd_t mc;
5529 mbx_cmd_t *mcp = &mc;
5530
Chad Dupuisf73cb692014-02-26 04:15:06 -05005531 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005532 return QLA_FUNCTION_FAILED;
5533
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005534 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5535 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005536
5537 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5538 mcp->mb[1] = LSW(reg);
5539 mcp->mb[2] = MSW(reg);
5540 mcp->mb[3] = LSW(data);
5541 mcp->mb[4] = MSW(data);
5542 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5543
5544 mcp->in_mb = MBX_1|MBX_0;
5545 mcp->tov = MBX_TOV_SECONDS;
5546 mcp->flags = 0;
5547 rval = qla2x00_mailbox_command(vha, mcp);
5548
5549 if (rval != QLA_SUCCESS) {
5550 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5551 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5552 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005553 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005554 "Done %s.\n", __func__);
5555 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005556
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005557 return rval;
5558}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005559
5560int
5561qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5562{
5563 int rval;
5564 struct qla_hw_data *ha = vha->hw;
5565 mbx_cmd_t mc;
5566 mbx_cmd_t *mcp = &mc;
5567
5568 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005570 "Implicit LOGO Unsupported.\n");
5571 return QLA_FUNCTION_FAILED;
5572 }
5573
5574
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005575 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5576 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005577
5578 /* Perform Implicit LOGO. */
5579 mcp->mb[0] = MBC_PORT_LOGOUT;
5580 mcp->mb[1] = fcport->loop_id;
5581 mcp->mb[10] = BIT_15;
5582 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5583 mcp->in_mb = MBX_0;
5584 mcp->tov = MBX_TOV_SECONDS;
5585 mcp->flags = 0;
5586 rval = qla2x00_mailbox_command(vha, mcp);
5587 if (rval != QLA_SUCCESS)
5588 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5589 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5590 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005591 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5592 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005593
5594 return rval;
5595}
5596
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005597int
5598qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5599{
5600 int rval;
5601 mbx_cmd_t mc;
5602 mbx_cmd_t *mcp = &mc;
5603 struct qla_hw_data *ha = vha->hw;
5604 unsigned long retry_max_time = jiffies + (2 * HZ);
5605
Chad Dupuisf73cb692014-02-26 04:15:06 -05005606 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005607 return QLA_FUNCTION_FAILED;
5608
5609 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5610
5611retry_rd_reg:
5612 mcp->mb[0] = MBC_READ_REMOTE_REG;
5613 mcp->mb[1] = LSW(reg);
5614 mcp->mb[2] = MSW(reg);
5615 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5616 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5617 mcp->tov = MBX_TOV_SECONDS;
5618 mcp->flags = 0;
5619 rval = qla2x00_mailbox_command(vha, mcp);
5620
5621 if (rval != QLA_SUCCESS) {
5622 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5623 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5624 rval, mcp->mb[0], mcp->mb[1]);
5625 } else {
5626 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5627 if (*data == QLA8XXX_BAD_VALUE) {
5628 /*
5629 * During soft-reset CAMRAM register reads might
5630 * return 0xbad0bad0. So retry for MAX of 2 sec
5631 * while reading camram registers.
5632 */
5633 if (time_after(jiffies, retry_max_time)) {
5634 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5635 "Failure to read CAMRAM register. "
5636 "data=0x%x.\n", *data);
5637 return QLA_FUNCTION_FAILED;
5638 }
5639 msleep(100);
5640 goto retry_rd_reg;
5641 }
5642 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5643 }
5644
5645 return rval;
5646}
5647
5648int
5649qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5650{
5651 int rval;
5652 mbx_cmd_t mc;
5653 mbx_cmd_t *mcp = &mc;
5654 struct qla_hw_data *ha = vha->hw;
5655
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005656 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005657 return QLA_FUNCTION_FAILED;
5658
5659 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5660
5661 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5662 mcp->out_mb = MBX_0;
5663 mcp->in_mb = MBX_1|MBX_0;
5664 mcp->tov = MBX_TOV_SECONDS;
5665 mcp->flags = 0;
5666 rval = qla2x00_mailbox_command(vha, mcp);
5667
5668 if (rval != QLA_SUCCESS) {
5669 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5670 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5671 rval, mcp->mb[0], mcp->mb[1]);
5672 ha->isp_ops->fw_dump(vha, 0);
5673 } else {
5674 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5675 }
5676
5677 return rval;
5678}
5679
5680int
5681qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5682 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5683{
5684 int rval;
5685 mbx_cmd_t mc;
5686 mbx_cmd_t *mcp = &mc;
5687 uint8_t subcode = (uint8_t)options;
5688 struct qla_hw_data *ha = vha->hw;
5689
5690 if (!IS_QLA8031(ha))
5691 return QLA_FUNCTION_FAILED;
5692
5693 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5694
5695 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5696 mcp->mb[1] = options;
5697 mcp->out_mb = MBX_1|MBX_0;
5698 if (subcode & BIT_2) {
5699 mcp->mb[2] = LSW(start_addr);
5700 mcp->mb[3] = MSW(start_addr);
5701 mcp->mb[4] = LSW(end_addr);
5702 mcp->mb[5] = MSW(end_addr);
5703 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5704 }
5705 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5706 if (!(subcode & (BIT_2 | BIT_5)))
5707 mcp->in_mb |= MBX_4|MBX_3;
5708 mcp->tov = MBX_TOV_SECONDS;
5709 mcp->flags = 0;
5710 rval = qla2x00_mailbox_command(vha, mcp);
5711
5712 if (rval != QLA_SUCCESS) {
5713 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5714 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5715 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5716 mcp->mb[4]);
5717 ha->isp_ops->fw_dump(vha, 0);
5718 } else {
5719 if (subcode & BIT_5)
5720 *sector_size = mcp->mb[1];
5721 else if (subcode & (BIT_6 | BIT_7)) {
5722 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5723 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5724 } else if (subcode & (BIT_3 | BIT_4)) {
5725 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5726 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5727 }
5728 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5729 }
5730
5731 return rval;
5732}
Saurav Kashyap81178772012-08-22 14:21:04 -04005733
5734int
5735qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5736 uint32_t size)
5737{
5738 int rval;
5739 mbx_cmd_t mc;
5740 mbx_cmd_t *mcp = &mc;
5741
5742 if (!IS_MCTP_CAPABLE(vha->hw))
5743 return QLA_FUNCTION_FAILED;
5744
5745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5746 "Entered %s.\n", __func__);
5747
5748 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5749 mcp->mb[1] = LSW(addr);
5750 mcp->mb[2] = MSW(req_dma);
5751 mcp->mb[3] = LSW(req_dma);
5752 mcp->mb[4] = MSW(size);
5753 mcp->mb[5] = LSW(size);
5754 mcp->mb[6] = MSW(MSD(req_dma));
5755 mcp->mb[7] = LSW(MSD(req_dma));
5756 mcp->mb[8] = MSW(addr);
5757 /* Setting RAM ID to valid */
5758 mcp->mb[10] |= BIT_7;
5759 /* For MCTP RAM ID is 0x40 */
5760 mcp->mb[10] |= 0x40;
5761
5762 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5763 MBX_0;
5764
5765 mcp->in_mb = MBX_0;
5766 mcp->tov = MBX_TOV_SECONDS;
5767 mcp->flags = 0;
5768 rval = qla2x00_mailbox_command(vha, mcp);
5769
5770 if (rval != QLA_SUCCESS) {
5771 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5772 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5773 } else {
5774 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5775 "Done %s.\n", __func__);
5776 }
5777
5778 return rval;
5779}
Joe Carnuccioec891462016-07-06 11:14:26 -04005780
5781int
5782qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5783 void *dd_buf, uint size, uint options)
5784{
5785 int rval;
5786 mbx_cmd_t mc;
5787 mbx_cmd_t *mcp = &mc;
5788 dma_addr_t dd_dma;
5789
5790 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5791 return QLA_FUNCTION_FAILED;
5792
5793 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
5794 "Entered %s.\n", __func__);
5795
Joe Carnuccioec891462016-07-06 11:14:26 -04005796 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5797 dd_buf, size, DMA_FROM_DEVICE);
5798 if (!dd_dma) {
5799 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5800 return QLA_MEMORY_ALLOC_FAILED;
5801 }
5802
5803 memset(dd_buf, 0, size);
5804
5805 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5806 mcp->mb[1] = options;
5807 mcp->mb[2] = MSW(LSD(dd_dma));
5808 mcp->mb[3] = LSW(LSD(dd_dma));
5809 mcp->mb[6] = MSW(MSD(dd_dma));
5810 mcp->mb[7] = LSW(MSD(dd_dma));
5811 mcp->mb[8] = size;
5812 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5813 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5814 mcp->buf_size = size;
5815 mcp->flags = MBX_DMA_IN;
5816 mcp->tov = MBX_TOV_SECONDS * 4;
5817 rval = qla2x00_mailbox_command(vha, mcp);
5818
5819 if (rval != QLA_SUCCESS) {
5820 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5821 } else {
5822 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5823 "Done %s.\n", __func__);
5824 }
5825
5826 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5827 size, DMA_FROM_DEVICE);
5828
5829 return rval;
5830}
Quinn Tran15f30a52017-03-15 09:48:52 -07005831
5832static void qla2x00_async_mb_sp_done(void *s, int res)
5833{
5834 struct srb *sp = s;
5835
5836 sp->u.iocb_cmd.u.mbx.rc = res;
5837
5838 complete(&sp->u.iocb_cmd.u.mbx.comp);
5839 /* don't free sp here. Let the caller do the free */
5840}
5841
5842/*
5843 * This mailbox uses the iocb interface to send MB command.
5844 * This allows non-critial (non chip setup) command to go
5845 * out in parrallel.
5846 */
5847int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
5848{
5849 int rval = QLA_FUNCTION_FAILED;
5850 srb_t *sp;
5851 struct srb_iocb *c;
5852
5853 if (!vha->hw->flags.fw_started)
5854 goto done;
5855
5856 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
5857 if (!sp)
5858 goto done;
5859
5860 sp->type = SRB_MB_IOCB;
5861 sp->name = mb_to_str(mcp->mb[0]);
5862
5863 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
5864
5865 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
5866
5867 c = &sp->u.iocb_cmd;
5868 c->timeout = qla2x00_async_iocb_timeout;
5869 init_completion(&c->u.mbx.comp);
5870
5871 sp->done = qla2x00_async_mb_sp_done;
5872
5873 rval = qla2x00_start_sp(sp);
5874 if (rval != QLA_SUCCESS) {
5875 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5876 "%s: %s Failed submission. %x.\n",
5877 __func__, sp->name, rval);
5878 goto done_free_sp;
5879 }
5880
5881 ql_dbg(ql_dbg_mbx, vha, 0xffff, "MB:%s hndl %x submitted\n",
5882 sp->name, sp->handle);
5883
5884 wait_for_completion(&c->u.mbx.comp);
5885 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
5886
5887 rval = c->u.mbx.rc;
5888 switch (rval) {
5889 case QLA_FUNCTION_TIMEOUT:
5890 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s Timeout. %x.\n",
5891 __func__, sp->name, rval);
5892 break;
5893 case QLA_SUCCESS:
5894 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s done.\n",
5895 __func__, sp->name);
5896 sp->free(sp);
5897 break;
5898 default:
5899 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s Failed. %x.\n",
5900 __func__, sp->name, rval);
5901 sp->free(sp);
5902 break;
5903 }
5904
5905 return rval;
5906
5907done_free_sp:
5908 sp->free(sp);
5909done:
5910 return rval;
5911}
5912
5913/*
5914 * qla24xx_gpdb_wait
5915 * NOTE: Do not call this routine from DPC thread
5916 */
5917int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
5918{
5919 int rval = QLA_FUNCTION_FAILED;
5920 dma_addr_t pd_dma;
5921 struct port_database_24xx *pd;
5922 struct qla_hw_data *ha = vha->hw;
5923 mbx_cmd_t mc;
5924
5925 if (!vha->hw->flags.fw_started)
5926 goto done;
5927
5928 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
5929 if (pd == NULL) {
5930 ql_log(ql_log_warn, vha, 0xffff,
5931 "Failed to allocate port database structure.\n");
5932 goto done_free_sp;
5933 }
5934 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
5935
5936 memset(&mc, 0, sizeof(mc));
5937 mc.mb[0] = MBC_GET_PORT_DATABASE;
5938 mc.mb[1] = cpu_to_le16(fcport->loop_id);
5939 mc.mb[2] = MSW(pd_dma);
5940 mc.mb[3] = LSW(pd_dma);
5941 mc.mb[6] = MSW(MSD(pd_dma));
5942 mc.mb[7] = LSW(MSD(pd_dma));
5943 mc.mb[9] = cpu_to_le16(vha->vp_idx);
5944 mc.mb[10] = cpu_to_le16((uint16_t)opt);
5945
5946 rval = qla24xx_send_mb_cmd(vha, &mc);
5947 if (rval != QLA_SUCCESS) {
5948 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5949 "%s: %8phC fail\n", __func__, fcport->port_name);
5950 goto done_free_sp;
5951 }
5952
5953 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
5954
5955 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %8phC done\n",
5956 __func__, fcport->port_name);
5957
5958done_free_sp:
5959 if (pd)
5960 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
5961done:
5962 return rval;
5963}
5964
5965int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
5966 struct port_database_24xx *pd)
5967{
5968 int rval = QLA_SUCCESS;
5969 uint64_t zero = 0;
5970
5971 /* Check for logged in state. */
5972 if (pd->current_login_state != PDS_PRLI_COMPLETE &&
5973 pd->last_login_state != PDS_PRLI_COMPLETE) {
5974 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5975 "Unable to verify login-state (%x/%x) for "
5976 "loop_id %x.\n", pd->current_login_state,
5977 pd->last_login_state, fcport->loop_id);
5978 rval = QLA_FUNCTION_FAILED;
5979 goto gpd_error_out;
5980 }
5981
5982 if (fcport->loop_id == FC_NO_LOOP_ID ||
5983 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
5984 memcmp(fcport->port_name, pd->port_name, 8))) {
5985 /* We lost the device mid way. */
5986 rval = QLA_NOT_LOGGED_IN;
5987 goto gpd_error_out;
5988 }
5989
5990 /* Names are little-endian. */
5991 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
5992 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
5993
5994 /* Get port_id of device. */
5995 fcport->d_id.b.domain = pd->port_id[0];
5996 fcport->d_id.b.area = pd->port_id[1];
5997 fcport->d_id.b.al_pa = pd->port_id[2];
5998 fcport->d_id.b.rsvd_1 = 0;
5999
6000 /* If not target must be initiator or unknown type. */
6001 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6002 fcport->port_type = FCT_INITIATOR;
6003 else
6004 fcport->port_type = FCT_TARGET;
6005
6006 /* Passback COS information. */
6007 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6008 FC_COS_CLASS2 : FC_COS_CLASS3;
6009
6010 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6011 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6012 fcport->conf_compl_supported = 1;
6013 }
6014
6015gpd_error_out:
6016 return rval;
6017}
6018
6019/*
6020 * qla24xx_gidlist__wait
6021 * NOTE: don't call this routine from DPC thread.
6022 */
6023int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6024 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6025{
6026 int rval = QLA_FUNCTION_FAILED;
6027 mbx_cmd_t mc;
6028
6029 if (!vha->hw->flags.fw_started)
6030 goto done;
6031
6032 memset(&mc, 0, sizeof(mc));
6033 mc.mb[0] = MBC_GET_ID_LIST;
6034 mc.mb[2] = MSW(id_list_dma);
6035 mc.mb[3] = LSW(id_list_dma);
6036 mc.mb[6] = MSW(MSD(id_list_dma));
6037 mc.mb[7] = LSW(MSD(id_list_dma));
6038 mc.mb[8] = 0;
6039 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6040
6041 rval = qla24xx_send_mb_cmd(vha, &mc);
6042 if (rval != QLA_SUCCESS) {
6043 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6044 "%s: fail\n", __func__);
6045 } else {
6046 *entries = mc.mb[1];
6047 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6048 "%s: done\n", __func__);
6049 }
6050done:
6051 return rval;
6052}