blob: e40ed570d3c1206a87a8347e93c140e86d8a3849 [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;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003626
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3628 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003629
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003630 if (rptid_entry->entry_status != 0)
3631 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003632
3633 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003634 /* loop */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003635 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003636 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003637 "VPs acquired %d.\n", rptid_entry->vp_setup,
3638 rptid_entry->vp_acquired);
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003639 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003640 "Primary port id %02x%02x%02x.\n",
3641 rptid_entry->port_id[2], rptid_entry->port_id[1],
3642 rptid_entry->port_id[0]);
Quinn Tran41dc5292017-01-19 22:28:03 -08003643
3644 vha->d_id.b.domain = rptid_entry->port_id[2];
3645 vha->d_id.b.area = rptid_entry->port_id[1];
3646 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3647
3648 spin_lock_irqsave(&ha->vport_slock, flags);
3649 qlt_update_vp_map(vha, SET_AL_PA);
3650 spin_unlock_irqrestore(&ha->vport_slock, flags);
3651
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003652 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003653 /* fabric */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003654 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, 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 Tran41dc5292017-01-19 22:28:03 -08003676 vha->d_id.b.domain = rptid_entry->port_id[2];
3677 vha->d_id.b.area = rptid_entry->port_id[1];
3678 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3679 spin_lock_irqsave(&ha->vport_slock, flags);
3680 qlt_update_vp_map(vha, SET_AL_PA);
3681 spin_unlock_irqrestore(&ha->vport_slock, flags);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003682 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003683
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003684 fc_host_port_name(vha->host) =
3685 wwn_to_u64(vha->port_name);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003686
Quinn Tran41dc5292017-01-19 22:28:03 -08003687 if (qla_ini_mode_enabled(vha))
3688 ql_dbg(ql_dbg_mbx, vha, 0x1018,
3689 "FA-WWN portname %016llx (%x)\n",
3690 fc_host_port_name(vha->host),
3691 rptid_entry->vp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003692
Quinn Tran41dc5292017-01-19 22:28:03 -08003693 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3694 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3695 } else {
3696 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3697 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3698 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3699 "Could not acquire ID for VP[%d].\n",
3700 rptid_entry->vp_idx);
3701 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003702 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003703
3704 found = 0;
3705 spin_lock_irqsave(&ha->vport_slock, flags);
3706 list_for_each_entry(vp, &ha->vp_list, list) {
3707 if (rptid_entry->vp_idx == vp->vp_idx) {
3708 found = 1;
3709 break;
3710 }
3711 }
3712 spin_unlock_irqrestore(&ha->vport_slock, flags);
3713
3714 if (!found)
3715 return;
3716
3717 vp->d_id.b.domain = rptid_entry->port_id[2];
3718 vp->d_id.b.area = rptid_entry->port_id[1];
3719 vp->d_id.b.al_pa = rptid_entry->port_id[0];
3720 spin_lock_irqsave(&ha->vport_slock, flags);
3721 qlt_update_vp_map(vp, SET_AL_PA);
3722 spin_unlock_irqrestore(&ha->vport_slock, flags);
3723
3724 /*
3725 * Cannot configure here as we are still sitting on the
3726 * response queue. Handle it in dpc context.
3727 */
3728 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3729 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3730 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003731 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003732 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003733 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003734 } else if (rptid_entry->format == 2) {
3735 ql_dbg(ql_dbg_async, vha, 0xffff,
3736 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3737 rptid_entry->port_id[2], rptid_entry->port_id[1],
3738 rptid_entry->port_id[0]);
3739
3740 ql_dbg(ql_dbg_async, vha, 0xffff,
3741 "N2N: Remote WWPN %8phC.\n",
3742 rptid_entry->u.f2.port_name);
3743
3744 /* N2N. direct connect */
3745 vha->d_id.b.domain = rptid_entry->port_id[2];
3746 vha->d_id.b.area = rptid_entry->port_id[1];
3747 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3748
3749 spin_lock_irqsave(&ha->vport_slock, flags);
3750 qlt_update_vp_map(vha, SET_AL_PA);
3751 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003752 }
3753}
3754
3755/*
3756 * qla24xx_modify_vp_config
3757 * Change VP configuration for vha
3758 *
3759 * Input:
3760 * vha = adapter block pointer.
3761 *
3762 * Returns:
3763 * qla2xxx local function return status code.
3764 *
3765 * Context:
3766 * Kernel context.
3767 */
3768int
3769qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3770{
3771 int rval;
3772 struct vp_config_entry_24xx *vpmod;
3773 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003774 struct qla_hw_data *ha = vha->hw;
3775 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003776
3777 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003778
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3780 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003781
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003782 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003783 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003784 ql_log(ql_log_warn, vha, 0x10bc,
3785 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003786 return QLA_MEMORY_ALLOC_FAILED;
3787 }
3788
3789 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3790 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3791 vpmod->entry_count = 1;
3792 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3793 vpmod->vp_count = 1;
3794 vpmod->vp_index1 = vha->vp_idx;
3795 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003796
3797 qlt_modify_vp_config(vha, vpmod);
3798
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003799 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3800 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3801 vpmod->entry_count = 1;
3802
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003803 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003804 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003805 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3806 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003807 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003808 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3809 "Failed to complete IOCB -- error status (%x).\n",
3810 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003811 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003812 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003813 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3814 "Failed to complete IOCB -- completion status (%x).\n",
3815 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003816 rval = QLA_FUNCTION_FAILED;
3817 } else {
3818 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003819 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3820 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003821 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3822 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003823 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003824
3825 return rval;
3826}
3827
3828/*
3829 * qla24xx_control_vp
3830 * Enable a virtual port for given host
3831 *
3832 * Input:
3833 * ha = adapter block pointer.
3834 * vhba = virtual adapter (unused)
3835 * index = index number for enabled VP
3836 *
3837 * Returns:
3838 * qla2xxx local function return status code.
3839 *
3840 * Context:
3841 * Kernel context.
3842 */
3843int
3844qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3845{
3846 int rval;
3847 int map, pos;
3848 struct vp_ctrl_entry_24xx *vce;
3849 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003850 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003851 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003852 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003853
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003854 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003855 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003856
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003857 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003858 return QLA_PARAMETER_ERROR;
3859
3860 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3861 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003862 ql_log(ql_log_warn, vha, 0x10c2,
3863 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003864 return QLA_MEMORY_ALLOC_FAILED;
3865 }
3866 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3867
3868 vce->entry_type = VP_CTRL_IOCB_TYPE;
3869 vce->entry_count = 1;
3870 vce->command = cpu_to_le16(cmd);
Bart Van Asschead950362015-07-09 07:24:08 -07003871 vce->vp_count = cpu_to_le16(1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003872
3873 /* index map in firmware starts with 1; decrement index
3874 * this is ok as we never use index 0
3875 */
3876 map = (vp_index - 1) / 8;
3877 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003878 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003879 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003880 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003881
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003882 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003883 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003884 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3885 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003886 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003887 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3888 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003889 vce->entry_status);
3890 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003891 } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003892 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3893 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003894 le16_to_cpu(vce->comp_status));
3895 rval = QLA_FUNCTION_FAILED;
3896 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003897 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3898 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003899 }
3900
3901 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3902
3903 return rval;
3904}
3905
3906/*
3907 * qla2x00_send_change_request
3908 * Receive or disable RSCN request from fabric controller
3909 *
3910 * Input:
3911 * ha = adapter block pointer
3912 * format = registration format:
3913 * 0 - Reserved
3914 * 1 - Fabric detected registration
3915 * 2 - N_port detected registration
3916 * 3 - Full registration
3917 * FF - clear registration
3918 * vp_idx = Virtual port index
3919 *
3920 * Returns:
3921 * qla2x00 local function return status code.
3922 *
3923 * Context:
3924 * Kernel Context
3925 */
3926
3927int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003928qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003929 uint16_t vp_idx)
3930{
3931 int rval;
3932 mbx_cmd_t mc;
3933 mbx_cmd_t *mcp = &mc;
3934
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003935 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3936 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003937
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003938 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3939 mcp->mb[1] = format;
3940 mcp->mb[9] = vp_idx;
3941 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3942 mcp->in_mb = MBX_0|MBX_1;
3943 mcp->tov = MBX_TOV_SECONDS;
3944 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003945 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003946
3947 if (rval == QLA_SUCCESS) {
3948 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3949 rval = BIT_1;
3950 }
3951 } else
3952 rval = BIT_1;
3953
3954 return rval;
3955}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003956
3957int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003958qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003959 uint32_t size)
3960{
3961 int rval;
3962 mbx_cmd_t mc;
3963 mbx_cmd_t *mcp = &mc;
3964
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003965 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3966 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003967
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003968 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003969 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3970 mcp->mb[8] = MSW(addr);
3971 mcp->out_mb = MBX_8|MBX_0;
3972 } else {
3973 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3974 mcp->out_mb = MBX_0;
3975 }
3976 mcp->mb[1] = LSW(addr);
3977 mcp->mb[2] = MSW(req_dma);
3978 mcp->mb[3] = LSW(req_dma);
3979 mcp->mb[6] = MSW(MSD(req_dma));
3980 mcp->mb[7] = LSW(MSD(req_dma));
3981 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003982 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003983 mcp->mb[4] = MSW(size);
3984 mcp->mb[5] = LSW(size);
3985 mcp->out_mb |= MBX_5|MBX_4;
3986 } else {
3987 mcp->mb[4] = LSW(size);
3988 mcp->out_mb |= MBX_4;
3989 }
3990
3991 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003992 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003993 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003994 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003995
3996 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003997 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3998 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003999 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004000 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4001 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004002 }
4003
4004 return rval;
4005}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004006/* 84XX Support **************************************************************/
4007
4008struct cs84xx_mgmt_cmd {
4009 union {
4010 struct verify_chip_entry_84xx req;
4011 struct verify_chip_rsp_84xx rsp;
4012 } p;
4013};
4014
4015int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004016qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004017{
4018 int rval, retry;
4019 struct cs84xx_mgmt_cmd *mn;
4020 dma_addr_t mn_dma;
4021 uint16_t options;
4022 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004023 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004024
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004025 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4026 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004027
4028 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4029 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004030 return QLA_MEMORY_ALLOC_FAILED;
4031 }
4032
4033 /* Force Update? */
4034 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4035 /* Diagnostic firmware? */
4036 /* options |= MENLO_DIAG_FW; */
4037 /* We update the firmware with only one data sequence. */
4038 options |= VCO_END_OF_DATA;
4039
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004040 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004041 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004042 memset(mn, 0, sizeof(*mn));
4043 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4044 mn->p.req.entry_count = 1;
4045 mn->p.req.options = cpu_to_le16(options);
4046
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004047 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4048 "Dump of Verify Request.\n");
4049 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4050 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004051
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004052 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004053 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004054 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4055 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004056 goto verify_done;
4057 }
4058
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004059 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4060 "Dump of Verify Response.\n");
4061 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4062 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004063
4064 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4065 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4066 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004067 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004068 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004069
4070 if (status[0] != CS_COMPLETE) {
4071 rval = QLA_FUNCTION_FAILED;
4072 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004073 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4074 "Firmware update failed. Retrying "
4075 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004076 options |= VCO_DONT_UPDATE_FW;
4077 options &= ~VCO_FORCE_UPDATE;
4078 retry = 1;
4079 }
4080 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004081 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004082 "Firmware updated to %x.\n",
4083 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004084
4085 /* NOTE: we only update OP firmware. */
4086 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4087 ha->cs84xx->op_fw_version =
4088 le32_to_cpu(mn->p.rsp.fw_ver);
4089 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4090 flags);
4091 }
4092 } while (retry);
4093
4094verify_done:
4095 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4096
4097 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004098 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4099 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004100 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004101 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4102 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004103 }
4104
4105 return rval;
4106}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004107
4108int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004109qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004110{
4111 int rval;
4112 unsigned long flags;
4113 mbx_cmd_t mc;
4114 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004115 struct qla_hw_data *ha = vha->hw;
4116
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004117 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4118 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004119
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004120 if (IS_SHADOW_REG_CAPABLE(ha))
4121 req->options |= BIT_13;
4122
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004123 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004124 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004125 mcp->mb[2] = MSW(LSD(req->dma));
4126 mcp->mb[3] = LSW(LSD(req->dma));
4127 mcp->mb[6] = MSW(MSD(req->dma));
4128 mcp->mb[7] = LSW(MSD(req->dma));
4129 mcp->mb[5] = req->length;
4130 if (req->rsp)
4131 mcp->mb[10] = req->rsp->id;
4132 mcp->mb[12] = req->qos;
4133 mcp->mb[11] = req->vp_idx;
4134 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004135 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004136 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004137
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004138 mcp->mb[4] = req->id;
4139 /* que in ptr index */
4140 mcp->mb[8] = 0;
4141 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004142 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004143 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4144 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4145 mcp->in_mb = MBX_0;
4146 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004147 mcp->tov = MBX_TOV_SECONDS * 2;
4148
Chad Dupuisf73cb692014-02-26 04:15:06 -05004149 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004150 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004151 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004152 mcp->out_mb |= MBX_15;
4153 /* debug q create issue in SR-IOV */
4154 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4155 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004156
4157 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004158 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004159 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004160 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004161 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004162 }
4163 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4164
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004165 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004166 if (rval != QLA_SUCCESS) {
4167 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4168 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4169 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004170 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4171 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004172 }
4173
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004174 return rval;
4175}
4176
4177int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004178qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004179{
4180 int rval;
4181 unsigned long flags;
4182 mbx_cmd_t mc;
4183 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004184 struct qla_hw_data *ha = vha->hw;
4185
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004186 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4187 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004188
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004189 if (IS_SHADOW_REG_CAPABLE(ha))
4190 rsp->options |= BIT_13;
4191
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004192 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004193 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004194 mcp->mb[2] = MSW(LSD(rsp->dma));
4195 mcp->mb[3] = LSW(LSD(rsp->dma));
4196 mcp->mb[6] = MSW(MSD(rsp->dma));
4197 mcp->mb[7] = LSW(MSD(rsp->dma));
4198 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004199 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004200 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004201 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004202 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004203
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004204 mcp->mb[4] = rsp->id;
4205 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004206 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004207 /* que out ptr index */
4208 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004209 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004210 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4211 mcp->in_mb = MBX_0;
4212 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004213 mcp->tov = MBX_TOV_SECONDS * 2;
4214
4215 if (IS_QLA81XX(ha)) {
4216 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4217 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004218 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004219 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4220 mcp->in_mb |= MBX_1;
4221 /* debug q create issue in SR-IOV */
4222 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4223 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004224
4225 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004226 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004227 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004228 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004229 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004230 }
4231
4232 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4233
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004234 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004235 if (rval != QLA_SUCCESS) {
4236 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4237 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4238 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004239 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4240 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004241 }
4242
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004243 return rval;
4244}
4245
Andrew Vasquez8a659572009-02-08 20:50:12 -08004246int
4247qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4248{
4249 int rval;
4250 mbx_cmd_t mc;
4251 mbx_cmd_t *mcp = &mc;
4252
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004253 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4254 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004255
4256 mcp->mb[0] = MBC_IDC_ACK;
4257 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4258 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4259 mcp->in_mb = MBX_0;
4260 mcp->tov = MBX_TOV_SECONDS;
4261 mcp->flags = 0;
4262 rval = qla2x00_mailbox_command(vha, mcp);
4263
4264 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004265 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4266 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004267 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004268 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4269 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004270 }
4271
4272 return rval;
4273}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004274
4275int
4276qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4277{
4278 int rval;
4279 mbx_cmd_t mc;
4280 mbx_cmd_t *mcp = &mc;
4281
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004282 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4283 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004284
Chad Dupuisf73cb692014-02-26 04:15:06 -05004285 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4286 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004287 return QLA_FUNCTION_FAILED;
4288
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004289 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4290 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4291 mcp->out_mb = MBX_1|MBX_0;
4292 mcp->in_mb = MBX_1|MBX_0;
4293 mcp->tov = MBX_TOV_SECONDS;
4294 mcp->flags = 0;
4295 rval = qla2x00_mailbox_command(vha, mcp);
4296
4297 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004298 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4299 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4300 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004301 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4303 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004304 *sector_size = mcp->mb[1];
4305 }
4306
4307 return rval;
4308}
4309
4310int
4311qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4312{
4313 int rval;
4314 mbx_cmd_t mc;
4315 mbx_cmd_t *mcp = &mc;
4316
Chad Dupuisf73cb692014-02-26 04:15:06 -05004317 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4318 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004319 return QLA_FUNCTION_FAILED;
4320
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004321 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4322 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004323
4324 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4325 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4326 FAC_OPT_CMD_WRITE_PROTECT;
4327 mcp->out_mb = MBX_1|MBX_0;
4328 mcp->in_mb = MBX_1|MBX_0;
4329 mcp->tov = MBX_TOV_SECONDS;
4330 mcp->flags = 0;
4331 rval = qla2x00_mailbox_command(vha, mcp);
4332
4333 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004334 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4335 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4336 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004337 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4339 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004340 }
4341
4342 return rval;
4343}
4344
4345int
4346qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4347{
4348 int rval;
4349 mbx_cmd_t mc;
4350 mbx_cmd_t *mcp = &mc;
4351
Chad Dupuisf73cb692014-02-26 04:15:06 -05004352 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4353 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004354 return QLA_FUNCTION_FAILED;
4355
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004356 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4357 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004358
4359 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4360 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4361 mcp->mb[2] = LSW(start);
4362 mcp->mb[3] = MSW(start);
4363 mcp->mb[4] = LSW(finish);
4364 mcp->mb[5] = MSW(finish);
4365 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4366 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4367 mcp->tov = MBX_TOV_SECONDS;
4368 mcp->flags = 0;
4369 rval = qla2x00_mailbox_command(vha, mcp);
4370
4371 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004372 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4373 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4374 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004375 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004376 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4377 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004378 }
4379
4380 return rval;
4381}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004382
4383int
4384qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4385{
4386 int rval = 0;
4387 mbx_cmd_t mc;
4388 mbx_cmd_t *mcp = &mc;
4389
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004390 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4391 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004392
4393 mcp->mb[0] = MBC_RESTART_MPI_FW;
4394 mcp->out_mb = MBX_0;
4395 mcp->in_mb = MBX_0|MBX_1;
4396 mcp->tov = MBX_TOV_SECONDS;
4397 mcp->flags = 0;
4398 rval = qla2x00_mailbox_command(vha, mcp);
4399
4400 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004401 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4402 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4403 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004404 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004405 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4406 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004407 }
4408
4409 return rval;
4410}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004411
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004412int
4413qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4414{
4415 int rval;
4416 mbx_cmd_t mc;
4417 mbx_cmd_t *mcp = &mc;
4418 int i;
4419 int len;
4420 uint16_t *str;
4421 struct qla_hw_data *ha = vha->hw;
4422
4423 if (!IS_P3P_TYPE(ha))
4424 return QLA_FUNCTION_FAILED;
4425
4426 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4427 "Entered %s.\n", __func__);
4428
4429 str = (void *)version;
4430 len = strlen(version);
4431
4432 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4433 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4434 mcp->out_mb = MBX_1|MBX_0;
4435 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4436 mcp->mb[i] = cpu_to_le16p(str);
4437 mcp->out_mb |= 1<<i;
4438 }
4439 for (; i < 16; i++) {
4440 mcp->mb[i] = 0;
4441 mcp->out_mb |= 1<<i;
4442 }
4443 mcp->in_mb = MBX_1|MBX_0;
4444 mcp->tov = MBX_TOV_SECONDS;
4445 mcp->flags = 0;
4446 rval = qla2x00_mailbox_command(vha, mcp);
4447
4448 if (rval != QLA_SUCCESS) {
4449 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4450 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4451 } else {
4452 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4453 "Done %s.\n", __func__);
4454 }
4455
4456 return rval;
4457}
4458
4459int
4460qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4461{
4462 int rval;
4463 mbx_cmd_t mc;
4464 mbx_cmd_t *mcp = &mc;
4465 int len;
4466 uint16_t dwlen;
4467 uint8_t *str;
4468 dma_addr_t str_dma;
4469 struct qla_hw_data *ha = vha->hw;
4470
4471 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4472 IS_P3P_TYPE(ha))
4473 return QLA_FUNCTION_FAILED;
4474
4475 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4476 "Entered %s.\n", __func__);
4477
4478 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4479 if (!str) {
4480 ql_log(ql_log_warn, vha, 0x117f,
4481 "Failed to allocate driver version param.\n");
4482 return QLA_MEMORY_ALLOC_FAILED;
4483 }
4484
4485 memcpy(str, "\x7\x3\x11\x0", 4);
4486 dwlen = str[0];
4487 len = dwlen * 4 - 4;
4488 memset(str + 4, 0, len);
4489 if (len > strlen(version))
4490 len = strlen(version);
4491 memcpy(str + 4, version, len);
4492
4493 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4494 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4495 mcp->mb[2] = MSW(LSD(str_dma));
4496 mcp->mb[3] = LSW(LSD(str_dma));
4497 mcp->mb[6] = MSW(MSD(str_dma));
4498 mcp->mb[7] = LSW(MSD(str_dma));
4499 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4500 mcp->in_mb = MBX_1|MBX_0;
4501 mcp->tov = MBX_TOV_SECONDS;
4502 mcp->flags = 0;
4503 rval = qla2x00_mailbox_command(vha, mcp);
4504
4505 if (rval != QLA_SUCCESS) {
4506 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4507 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4508 } else {
4509 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4510 "Done %s.\n", __func__);
4511 }
4512
4513 dma_pool_free(ha->s_dma_pool, str, str_dma);
4514
4515 return rval;
4516}
4517
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004518static int
4519qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4520{
4521 int rval;
4522 mbx_cmd_t mc;
4523 mbx_cmd_t *mcp = &mc;
4524
4525 if (!IS_FWI2_CAPABLE(vha->hw))
4526 return QLA_FUNCTION_FAILED;
4527
4528 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4529 "Entered %s.\n", __func__);
4530
4531 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4532 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4533 mcp->out_mb = MBX_1|MBX_0;
4534 mcp->in_mb = MBX_1|MBX_0;
4535 mcp->tov = MBX_TOV_SECONDS;
4536 mcp->flags = 0;
4537 rval = qla2x00_mailbox_command(vha, mcp);
4538 *temp = mcp->mb[1];
4539
4540 if (rval != QLA_SUCCESS) {
4541 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4542 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4543 } else {
4544 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4545 "Done %s.\n", __func__);
4546 }
4547
4548 return rval;
4549}
4550
Joe Carnuccio3a117112013-02-08 01:58:00 -05004551int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004552qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4553 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004554{
4555 int rval;
4556 mbx_cmd_t mc;
4557 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004558 struct qla_hw_data *ha = vha->hw;
4559
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4561 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004562
Joe Carnuccio6766df92011-05-10 11:30:15 -07004563 if (!IS_FWI2_CAPABLE(ha))
4564 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004565
Joe Carnuccio6766df92011-05-10 11:30:15 -07004566 if (len == 1)
4567 opt |= BIT_0;
4568
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004569 mcp->mb[0] = MBC_READ_SFP;
4570 mcp->mb[1] = dev;
4571 mcp->mb[2] = MSW(sfp_dma);
4572 mcp->mb[3] = LSW(sfp_dma);
4573 mcp->mb[6] = MSW(MSD(sfp_dma));
4574 mcp->mb[7] = LSW(MSD(sfp_dma));
4575 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004576 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004577 mcp->mb[10] = opt;
4578 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 -07004579 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004580 mcp->tov = MBX_TOV_SECONDS;
4581 mcp->flags = 0;
4582 rval = qla2x00_mailbox_command(vha, mcp);
4583
4584 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004585 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004586
4587 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004588 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4589 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004590 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004591 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4592 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004593 }
4594
4595 return rval;
4596}
4597
4598int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004599qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4600 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004601{
4602 int rval;
4603 mbx_cmd_t mc;
4604 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004605 struct qla_hw_data *ha = vha->hw;
4606
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004607 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4608 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004609
Joe Carnuccio6766df92011-05-10 11:30:15 -07004610 if (!IS_FWI2_CAPABLE(ha))
4611 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004612
Joe Carnuccio6766df92011-05-10 11:30:15 -07004613 if (len == 1)
4614 opt |= BIT_0;
4615
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004616 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004617 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004618
4619 mcp->mb[0] = MBC_WRITE_SFP;
4620 mcp->mb[1] = dev;
4621 mcp->mb[2] = MSW(sfp_dma);
4622 mcp->mb[3] = LSW(sfp_dma);
4623 mcp->mb[6] = MSW(MSD(sfp_dma));
4624 mcp->mb[7] = LSW(MSD(sfp_dma));
4625 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004626 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004627 mcp->mb[10] = opt;
4628 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 -07004629 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004630 mcp->tov = MBX_TOV_SECONDS;
4631 mcp->flags = 0;
4632 rval = qla2x00_mailbox_command(vha, mcp);
4633
4634 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004635 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4636 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004637 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004638 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4639 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004640 }
4641
4642 return rval;
4643}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004644
4645int
4646qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4647 uint16_t size_in_bytes, uint16_t *actual_size)
4648{
4649 int rval;
4650 mbx_cmd_t mc;
4651 mbx_cmd_t *mcp = &mc;
4652
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004653 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4654 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004655
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004656 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004657 return QLA_FUNCTION_FAILED;
4658
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004659 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4660 mcp->mb[2] = MSW(stats_dma);
4661 mcp->mb[3] = LSW(stats_dma);
4662 mcp->mb[6] = MSW(MSD(stats_dma));
4663 mcp->mb[7] = LSW(MSD(stats_dma));
4664 mcp->mb[8] = size_in_bytes >> 2;
4665 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4666 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4667 mcp->tov = MBX_TOV_SECONDS;
4668 mcp->flags = 0;
4669 rval = qla2x00_mailbox_command(vha, mcp);
4670
4671 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004672 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4673 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4674 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004675 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4677 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004678
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004679
4680 *actual_size = mcp->mb[2] << 2;
4681 }
4682
4683 return rval;
4684}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004685
4686int
4687qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4688 uint16_t size)
4689{
4690 int rval;
4691 mbx_cmd_t mc;
4692 mbx_cmd_t *mcp = &mc;
4693
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004694 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4695 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004696
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004697 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004698 return QLA_FUNCTION_FAILED;
4699
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004700 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4701 mcp->mb[1] = 0;
4702 mcp->mb[2] = MSW(tlv_dma);
4703 mcp->mb[3] = LSW(tlv_dma);
4704 mcp->mb[6] = MSW(MSD(tlv_dma));
4705 mcp->mb[7] = LSW(MSD(tlv_dma));
4706 mcp->mb[8] = size;
4707 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4708 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4709 mcp->tov = MBX_TOV_SECONDS;
4710 mcp->flags = 0;
4711 rval = qla2x00_mailbox_command(vha, mcp);
4712
4713 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004714 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4715 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4716 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004717 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004718 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4719 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004720 }
4721
4722 return rval;
4723}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004724
4725int
4726qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4727{
4728 int rval;
4729 mbx_cmd_t mc;
4730 mbx_cmd_t *mcp = &mc;
4731
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004732 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4733 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004734
Andrew Vasquez18e75552009-06-03 09:55:30 -07004735 if (!IS_FWI2_CAPABLE(vha->hw))
4736 return QLA_FUNCTION_FAILED;
4737
Andrew Vasquez18e75552009-06-03 09:55:30 -07004738 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4739 mcp->mb[1] = LSW(risc_addr);
4740 mcp->mb[8] = MSW(risc_addr);
4741 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4742 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4743 mcp->tov = 30;
4744 mcp->flags = 0;
4745 rval = qla2x00_mailbox_command(vha, mcp);
4746 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004747 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4748 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004749 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004750 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4751 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004752 *data = mcp->mb[3] << 16 | mcp->mb[2];
4753 }
4754
4755 return rval;
4756}
4757
4758int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004759qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4760 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004761{
4762 int rval;
4763 mbx_cmd_t mc;
4764 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004765
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004766 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4767 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004768
4769 memset(mcp->mb, 0 , sizeof(mcp->mb));
4770 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4771 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4772
4773 /* transfer count */
4774 mcp->mb[10] = LSW(mreq->transfer_size);
4775 mcp->mb[11] = MSW(mreq->transfer_size);
4776
4777 /* send data address */
4778 mcp->mb[14] = LSW(mreq->send_dma);
4779 mcp->mb[15] = MSW(mreq->send_dma);
4780 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4781 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4782
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004783 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004784 mcp->mb[16] = LSW(mreq->rcv_dma);
4785 mcp->mb[17] = MSW(mreq->rcv_dma);
4786 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4787 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4788
4789 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004790 mcp->mb[18] = LSW(mreq->iteration_count);
4791 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004792
4793 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4794 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 -08004795 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004796 mcp->out_mb |= MBX_2;
4797 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4798
4799 mcp->buf_size = mreq->transfer_size;
4800 mcp->tov = MBX_TOV_SECONDS;
4801 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4802
4803 rval = qla2x00_mailbox_command(vha, mcp);
4804
4805 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004806 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4807 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4808 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4809 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004810 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004811 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4812 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004813 }
4814
4815 /* Copy mailbox information */
4816 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004817 return rval;
4818}
4819
4820int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004821qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4822 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004823{
4824 int rval;
4825 mbx_cmd_t mc;
4826 mbx_cmd_t *mcp = &mc;
4827 struct qla_hw_data *ha = vha->hw;
4828
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4830 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004831
4832 memset(mcp->mb, 0 , sizeof(mcp->mb));
4833 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
4834 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004835 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004836 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004837 mcp->mb[2] = vha->fcoe_fcf_idx;
4838 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004839 mcp->mb[16] = LSW(mreq->rcv_dma);
4840 mcp->mb[17] = MSW(mreq->rcv_dma);
4841 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4842 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4843
4844 mcp->mb[10] = LSW(mreq->transfer_size);
4845
4846 mcp->mb[14] = LSW(mreq->send_dma);
4847 mcp->mb[15] = MSW(mreq->send_dma);
4848 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4849 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4850
4851 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4852 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004853 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004854 mcp->out_mb |= MBX_2;
4855
4856 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004857 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4858 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004859 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004860 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004861 mcp->in_mb |= MBX_3;
4862
4863 mcp->tov = MBX_TOV_SECONDS;
4864 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4865 mcp->buf_size = mreq->transfer_size;
4866
4867 rval = qla2x00_mailbox_command(vha, mcp);
4868
4869 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004870 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4871 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4872 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004873 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004874 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4875 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004876 }
4877
4878 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004879 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004880 return rval;
4881}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004882
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004883int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004884qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004885{
4886 int rval;
4887 mbx_cmd_t mc;
4888 mbx_cmd_t *mcp = &mc;
4889
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004890 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004891 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004892
4893 mcp->mb[0] = MBC_ISP84XX_RESET;
4894 mcp->mb[1] = enable_diagnostic;
4895 mcp->out_mb = MBX_1|MBX_0;
4896 mcp->in_mb = MBX_1|MBX_0;
4897 mcp->tov = MBX_TOV_SECONDS;
4898 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004899 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004900
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004901 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004902 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004903 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4905 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004906
4907 return rval;
4908}
4909
4910int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004911qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4912{
4913 int rval;
4914 mbx_cmd_t mc;
4915 mbx_cmd_t *mcp = &mc;
4916
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004917 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4918 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004919
Andrew Vasquez18e75552009-06-03 09:55:30 -07004920 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004921 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004922
Andrew Vasquez18e75552009-06-03 09:55:30 -07004923 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4924 mcp->mb[1] = LSW(risc_addr);
4925 mcp->mb[2] = LSW(data);
4926 mcp->mb[3] = MSW(data);
4927 mcp->mb[8] = MSW(risc_addr);
4928 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4929 mcp->in_mb = MBX_0;
4930 mcp->tov = 30;
4931 mcp->flags = 0;
4932 rval = qla2x00_mailbox_command(vha, mcp);
4933 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004934 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4935 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004936 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004937 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4938 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004939 }
4940
4941 return rval;
4942}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004943
4944int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004945qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4946{
4947 int rval;
4948 uint32_t stat, timer;
4949 uint16_t mb0 = 0;
4950 struct qla_hw_data *ha = vha->hw;
4951 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4952
4953 rval = QLA_SUCCESS;
4954
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004955 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4956 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004957
4958 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4959
4960 /* Write the MBC data to the registers */
4961 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4962 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4963 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4964 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4965 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4966
4967 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4968
4969 /* Poll for MBC interrupt */
4970 for (timer = 6000000; timer; timer--) {
4971 /* Check for pending interrupts. */
4972 stat = RD_REG_DWORD(&reg->host_status);
4973 if (stat & HSRX_RISC_INT) {
4974 stat &= 0xff;
4975
4976 if (stat == 0x1 || stat == 0x2 ||
4977 stat == 0x10 || stat == 0x11) {
4978 set_bit(MBX_INTERRUPT,
4979 &ha->mbx_cmd_flags);
4980 mb0 = RD_REG_WORD(&reg->mailbox0);
4981 WRT_REG_DWORD(&reg->hccr,
4982 HCCRX_CLR_RISC_INT);
4983 RD_REG_DWORD(&reg->hccr);
4984 break;
4985 }
4986 }
4987 udelay(5);
4988 }
4989
4990 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4991 rval = mb0 & MBS_MASK;
4992 else
4993 rval = QLA_FUNCTION_FAILED;
4994
4995 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004996 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4997 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004998 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004999 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5000 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005001 }
5002
5003 return rval;
5004}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005005
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005006int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005007qla2x00_get_data_rate(scsi_qla_host_t *vha)
5008{
5009 int rval;
5010 mbx_cmd_t mc;
5011 mbx_cmd_t *mcp = &mc;
5012 struct qla_hw_data *ha = vha->hw;
5013
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005014 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5015 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005016
Michael Hernandez3064ff32009-12-15 21:29:44 -08005017 if (!IS_FWI2_CAPABLE(ha))
5018 return QLA_FUNCTION_FAILED;
5019
Michael Hernandez3064ff32009-12-15 21:29:44 -08005020 mcp->mb[0] = MBC_DATA_RATE;
5021 mcp->mb[1] = 0;
5022 mcp->out_mb = MBX_1|MBX_0;
5023 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005024 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005025 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005026 mcp->tov = MBX_TOV_SECONDS;
5027 mcp->flags = 0;
5028 rval = qla2x00_mailbox_command(vha, mcp);
5029 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005030 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5031 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005032 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005033 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5034 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005035 if (mcp->mb[1] != 0x7)
5036 ha->link_data_rate = mcp->mb[1];
5037 }
5038
5039 return rval;
5040}
Sarang Radke09ff7012010-03-19 17:03:59 -07005041
5042int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005043qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5044{
5045 int rval;
5046 mbx_cmd_t mc;
5047 mbx_cmd_t *mcp = &mc;
5048 struct qla_hw_data *ha = vha->hw;
5049
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005050 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5051 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005052
Chad Dupuisf73cb692014-02-26 04:15:06 -05005053 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5054 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005055 return QLA_FUNCTION_FAILED;
5056 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5057 mcp->out_mb = MBX_0;
5058 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5059 mcp->tov = MBX_TOV_SECONDS;
5060 mcp->flags = 0;
5061
5062 rval = qla2x00_mailbox_command(vha, mcp);
5063
5064 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005065 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5066 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005067 } else {
5068 /* Copy all bits to preserve original value */
5069 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5070
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005071 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5072 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005073 }
5074 return rval;
5075}
5076
5077int
5078qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5079{
5080 int rval;
5081 mbx_cmd_t mc;
5082 mbx_cmd_t *mcp = &mc;
5083
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005084 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5085 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005086
5087 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5088 /* Copy all bits to preserve original setting */
5089 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5090 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5091 mcp->in_mb = MBX_0;
5092 mcp->tov = MBX_TOV_SECONDS;
5093 mcp->flags = 0;
5094 rval = qla2x00_mailbox_command(vha, mcp);
5095
5096 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005097 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5098 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005099 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005100 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5101 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005102
5103 return rval;
5104}
5105
5106
5107int
Sarang Radke09ff7012010-03-19 17:03:59 -07005108qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5109 uint16_t *mb)
5110{
5111 int rval;
5112 mbx_cmd_t mc;
5113 mbx_cmd_t *mcp = &mc;
5114 struct qla_hw_data *ha = vha->hw;
5115
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005116 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5117 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005118
Sarang Radke09ff7012010-03-19 17:03:59 -07005119 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5120 return QLA_FUNCTION_FAILED;
5121
Sarang Radke09ff7012010-03-19 17:03:59 -07005122 mcp->mb[0] = MBC_PORT_PARAMS;
5123 mcp->mb[1] = loop_id;
5124 if (ha->flags.fcp_prio_enabled)
5125 mcp->mb[2] = BIT_1;
5126 else
5127 mcp->mb[2] = BIT_2;
5128 mcp->mb[4] = priority & 0xf;
5129 mcp->mb[9] = vha->vp_idx;
5130 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5131 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5132 mcp->tov = 30;
5133 mcp->flags = 0;
5134 rval = qla2x00_mailbox_command(vha, mcp);
5135 if (mb != NULL) {
5136 mb[0] = mcp->mb[0];
5137 mb[1] = mcp->mb[1];
5138 mb[3] = mcp->mb[3];
5139 mb[4] = mcp->mb[4];
5140 }
5141
5142 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005143 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005144 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005145 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5146 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005147 }
5148
5149 return rval;
5150}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005151
5152int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005153qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005154{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005155 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005156 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005157 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005158
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005159 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5160 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5161 "Thermal not supported by this card.\n");
5162 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005163 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005164
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005165 if (IS_QLA25XX(ha)) {
5166 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5167 ha->pdev->subsystem_device == 0x0175) {
5168 rval = qla2x00_read_sfp(vha, 0, &byte,
5169 0x98, 0x1, 1, BIT_13|BIT_0);
5170 *temp = byte;
5171 return rval;
5172 }
5173 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5174 ha->pdev->subsystem_device == 0x338e) {
5175 rval = qla2x00_read_sfp(vha, 0, &byte,
5176 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5177 *temp = byte;
5178 return rval;
5179 }
5180 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5181 "Thermal not supported by this card.\n");
5182 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005183 }
5184
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005185 if (IS_QLA82XX(ha)) {
5186 *temp = qla82xx_read_temperature(vha);
5187 rval = QLA_SUCCESS;
5188 return rval;
5189 } else if (IS_QLA8044(ha)) {
5190 *temp = qla8044_read_temperature(vha);
5191 rval = QLA_SUCCESS;
5192 return rval;
5193 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005194
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005195 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005196 return rval;
5197}
5198
5199int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005200qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5201{
5202 int rval;
5203 struct qla_hw_data *ha = vha->hw;
5204 mbx_cmd_t mc;
5205 mbx_cmd_t *mcp = &mc;
5206
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005207 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5208 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005209
Giridhar Malavalia9083012010-04-12 17:59:55 -07005210 if (!IS_FWI2_CAPABLE(ha))
5211 return QLA_FUNCTION_FAILED;
5212
Giridhar Malavalia9083012010-04-12 17:59:55 -07005213 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005214 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005215 mcp->mb[1] = 1;
5216
5217 mcp->out_mb = MBX_1|MBX_0;
5218 mcp->in_mb = MBX_0;
5219 mcp->tov = 30;
5220 mcp->flags = 0;
5221
5222 rval = qla2x00_mailbox_command(vha, mcp);
5223 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005224 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5225 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005226 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005227 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5228 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005229 }
5230
5231 return rval;
5232}
5233
5234int
5235qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5236{
5237 int rval;
5238 struct qla_hw_data *ha = vha->hw;
5239 mbx_cmd_t mc;
5240 mbx_cmd_t *mcp = &mc;
5241
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5243 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005244
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005245 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005246 return QLA_FUNCTION_FAILED;
5247
Giridhar Malavalia9083012010-04-12 17:59:55 -07005248 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005249 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005250 mcp->mb[1] = 0;
5251
5252 mcp->out_mb = MBX_1|MBX_0;
5253 mcp->in_mb = MBX_0;
5254 mcp->tov = 30;
5255 mcp->flags = 0;
5256
5257 rval = qla2x00_mailbox_command(vha, mcp);
5258 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005259 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5260 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005261 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005262 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5263 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005264 }
5265
5266 return rval;
5267}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005268
5269int
5270qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5271{
5272 struct qla_hw_data *ha = vha->hw;
5273 mbx_cmd_t mc;
5274 mbx_cmd_t *mcp = &mc;
5275 int rval = QLA_FUNCTION_FAILED;
5276
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005277 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5278 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005279
5280 memset(mcp->mb, 0 , sizeof(mcp->mb));
5281 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5282 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5283 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5284 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5285
5286 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5287 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5288 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5289
5290 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5291 mcp->tov = MBX_TOV_SECONDS;
5292 rval = qla2x00_mailbox_command(vha, mcp);
5293
5294 /* Always copy back return mailbox values. */
5295 if (rval != QLA_SUCCESS) {
5296 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5297 "mailbox command FAILED=0x%x, subcode=%x.\n",
5298 (mcp->mb[1] << 16) | mcp->mb[0],
5299 (mcp->mb[3] << 16) | mcp->mb[2]);
5300 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005301 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5302 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005303 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5304 if (!ha->md_template_size) {
5305 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5306 "Null template size obtained.\n");
5307 rval = QLA_FUNCTION_FAILED;
5308 }
5309 }
5310 return rval;
5311}
5312
5313int
5314qla82xx_md_get_template(scsi_qla_host_t *vha)
5315{
5316 struct qla_hw_data *ha = vha->hw;
5317 mbx_cmd_t mc;
5318 mbx_cmd_t *mcp = &mc;
5319 int rval = QLA_FUNCTION_FAILED;
5320
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005321 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5322 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005323
5324 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5325 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5326 if (!ha->md_tmplt_hdr) {
5327 ql_log(ql_log_warn, vha, 0x1124,
5328 "Unable to allocate memory for Minidump template.\n");
5329 return rval;
5330 }
5331
5332 memset(mcp->mb, 0 , sizeof(mcp->mb));
5333 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5334 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5335 mcp->mb[2] = LSW(RQST_TMPLT);
5336 mcp->mb[3] = MSW(RQST_TMPLT);
5337 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5338 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5339 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5340 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5341 mcp->mb[8] = LSW(ha->md_template_size);
5342 mcp->mb[9] = MSW(ha->md_template_size);
5343
5344 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5345 mcp->tov = MBX_TOV_SECONDS;
5346 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5347 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5348 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5349 rval = qla2x00_mailbox_command(vha, mcp);
5350
5351 if (rval != QLA_SUCCESS) {
5352 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5353 "mailbox command FAILED=0x%x, subcode=%x.\n",
5354 ((mcp->mb[1] << 16) | mcp->mb[0]),
5355 ((mcp->mb[3] << 16) | mcp->mb[2]));
5356 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005357 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5358 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005359 return rval;
5360}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005361
5362int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005363qla8044_md_get_template(scsi_qla_host_t *vha)
5364{
5365 struct qla_hw_data *ha = vha->hw;
5366 mbx_cmd_t mc;
5367 mbx_cmd_t *mcp = &mc;
5368 int rval = QLA_FUNCTION_FAILED;
5369 int offset = 0, size = MINIDUMP_SIZE_36K;
5370 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5371 "Entered %s.\n", __func__);
5372
5373 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5374 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5375 if (!ha->md_tmplt_hdr) {
5376 ql_log(ql_log_warn, vha, 0xb11b,
5377 "Unable to allocate memory for Minidump template.\n");
5378 return rval;
5379 }
5380
5381 memset(mcp->mb, 0 , sizeof(mcp->mb));
5382 while (offset < ha->md_template_size) {
5383 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5384 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5385 mcp->mb[2] = LSW(RQST_TMPLT);
5386 mcp->mb[3] = MSW(RQST_TMPLT);
5387 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5388 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5389 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5390 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5391 mcp->mb[8] = LSW(size);
5392 mcp->mb[9] = MSW(size);
5393 mcp->mb[10] = offset & 0x0000FFFF;
5394 mcp->mb[11] = offset & 0xFFFF0000;
5395 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5396 mcp->tov = MBX_TOV_SECONDS;
5397 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5398 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5399 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5400 rval = qla2x00_mailbox_command(vha, mcp);
5401
5402 if (rval != QLA_SUCCESS) {
5403 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5404 "mailbox command FAILED=0x%x, subcode=%x.\n",
5405 ((mcp->mb[1] << 16) | mcp->mb[0]),
5406 ((mcp->mb[3] << 16) | mcp->mb[2]));
5407 return rval;
5408 } else
5409 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5410 "Done %s.\n", __func__);
5411 offset = offset + size;
5412 }
5413 return rval;
5414}
5415
5416int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005417qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5418{
5419 int rval;
5420 struct qla_hw_data *ha = vha->hw;
5421 mbx_cmd_t mc;
5422 mbx_cmd_t *mcp = &mc;
5423
5424 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5425 return QLA_FUNCTION_FAILED;
5426
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005427 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5428 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005429
5430 memset(mcp, 0, sizeof(mbx_cmd_t));
5431 mcp->mb[0] = MBC_SET_LED_CONFIG;
5432 mcp->mb[1] = led_cfg[0];
5433 mcp->mb[2] = led_cfg[1];
5434 if (IS_QLA8031(ha)) {
5435 mcp->mb[3] = led_cfg[2];
5436 mcp->mb[4] = led_cfg[3];
5437 mcp->mb[5] = led_cfg[4];
5438 mcp->mb[6] = led_cfg[5];
5439 }
5440
5441 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5442 if (IS_QLA8031(ha))
5443 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5444 mcp->in_mb = MBX_0;
5445 mcp->tov = 30;
5446 mcp->flags = 0;
5447
5448 rval = qla2x00_mailbox_command(vha, mcp);
5449 if (rval != QLA_SUCCESS) {
5450 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5451 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5452 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005453 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5454 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005455 }
5456
5457 return rval;
5458}
5459
5460int
5461qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5462{
5463 int rval;
5464 struct qla_hw_data *ha = vha->hw;
5465 mbx_cmd_t mc;
5466 mbx_cmd_t *mcp = &mc;
5467
5468 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5469 return QLA_FUNCTION_FAILED;
5470
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005471 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5472 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005473
5474 memset(mcp, 0, sizeof(mbx_cmd_t));
5475 mcp->mb[0] = MBC_GET_LED_CONFIG;
5476
5477 mcp->out_mb = MBX_0;
5478 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5479 if (IS_QLA8031(ha))
5480 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5481 mcp->tov = 30;
5482 mcp->flags = 0;
5483
5484 rval = qla2x00_mailbox_command(vha, mcp);
5485 if (rval != QLA_SUCCESS) {
5486 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5487 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5488 } else {
5489 led_cfg[0] = mcp->mb[1];
5490 led_cfg[1] = mcp->mb[2];
5491 if (IS_QLA8031(ha)) {
5492 led_cfg[2] = mcp->mb[3];
5493 led_cfg[3] = mcp->mb[4];
5494 led_cfg[4] = mcp->mb[5];
5495 led_cfg[5] = mcp->mb[6];
5496 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005497 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5498 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005499 }
5500
5501 return rval;
5502}
5503
5504int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005505qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5506{
5507 int rval;
5508 struct qla_hw_data *ha = vha->hw;
5509 mbx_cmd_t mc;
5510 mbx_cmd_t *mcp = &mc;
5511
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005512 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005513 return QLA_FUNCTION_FAILED;
5514
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005515 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005516 "Entered %s.\n", __func__);
5517
5518 memset(mcp, 0, sizeof(mbx_cmd_t));
5519 mcp->mb[0] = MBC_SET_LED_CONFIG;
5520 if (enable)
5521 mcp->mb[7] = 0xE;
5522 else
5523 mcp->mb[7] = 0xD;
5524
5525 mcp->out_mb = MBX_7|MBX_0;
5526 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005527 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005528 mcp->flags = 0;
5529
5530 rval = qla2x00_mailbox_command(vha, mcp);
5531 if (rval != QLA_SUCCESS) {
5532 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5533 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5534 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005535 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005536 "Done %s.\n", __func__);
5537 }
5538
5539 return rval;
5540}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005541
5542int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005543qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005544{
5545 int rval;
5546 struct qla_hw_data *ha = vha->hw;
5547 mbx_cmd_t mc;
5548 mbx_cmd_t *mcp = &mc;
5549
Chad Dupuisf73cb692014-02-26 04:15:06 -05005550 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005551 return QLA_FUNCTION_FAILED;
5552
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005553 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5554 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005555
5556 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5557 mcp->mb[1] = LSW(reg);
5558 mcp->mb[2] = MSW(reg);
5559 mcp->mb[3] = LSW(data);
5560 mcp->mb[4] = MSW(data);
5561 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5562
5563 mcp->in_mb = MBX_1|MBX_0;
5564 mcp->tov = MBX_TOV_SECONDS;
5565 mcp->flags = 0;
5566 rval = qla2x00_mailbox_command(vha, mcp);
5567
5568 if (rval != QLA_SUCCESS) {
5569 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5570 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5571 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005572 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005573 "Done %s.\n", __func__);
5574 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005575
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005576 return rval;
5577}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005578
5579int
5580qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5581{
5582 int rval;
5583 struct qla_hw_data *ha = vha->hw;
5584 mbx_cmd_t mc;
5585 mbx_cmd_t *mcp = &mc;
5586
5587 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005589 "Implicit LOGO Unsupported.\n");
5590 return QLA_FUNCTION_FAILED;
5591 }
5592
5593
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005594 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5595 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005596
5597 /* Perform Implicit LOGO. */
5598 mcp->mb[0] = MBC_PORT_LOGOUT;
5599 mcp->mb[1] = fcport->loop_id;
5600 mcp->mb[10] = BIT_15;
5601 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5602 mcp->in_mb = MBX_0;
5603 mcp->tov = MBX_TOV_SECONDS;
5604 mcp->flags = 0;
5605 rval = qla2x00_mailbox_command(vha, mcp);
5606 if (rval != QLA_SUCCESS)
5607 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5608 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5609 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005610 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5611 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005612
5613 return rval;
5614}
5615
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005616int
5617qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5618{
5619 int rval;
5620 mbx_cmd_t mc;
5621 mbx_cmd_t *mcp = &mc;
5622 struct qla_hw_data *ha = vha->hw;
5623 unsigned long retry_max_time = jiffies + (2 * HZ);
5624
Chad Dupuisf73cb692014-02-26 04:15:06 -05005625 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005626 return QLA_FUNCTION_FAILED;
5627
5628 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5629
5630retry_rd_reg:
5631 mcp->mb[0] = MBC_READ_REMOTE_REG;
5632 mcp->mb[1] = LSW(reg);
5633 mcp->mb[2] = MSW(reg);
5634 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5635 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5636 mcp->tov = MBX_TOV_SECONDS;
5637 mcp->flags = 0;
5638 rval = qla2x00_mailbox_command(vha, mcp);
5639
5640 if (rval != QLA_SUCCESS) {
5641 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5642 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5643 rval, mcp->mb[0], mcp->mb[1]);
5644 } else {
5645 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5646 if (*data == QLA8XXX_BAD_VALUE) {
5647 /*
5648 * During soft-reset CAMRAM register reads might
5649 * return 0xbad0bad0. So retry for MAX of 2 sec
5650 * while reading camram registers.
5651 */
5652 if (time_after(jiffies, retry_max_time)) {
5653 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5654 "Failure to read CAMRAM register. "
5655 "data=0x%x.\n", *data);
5656 return QLA_FUNCTION_FAILED;
5657 }
5658 msleep(100);
5659 goto retry_rd_reg;
5660 }
5661 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5662 }
5663
5664 return rval;
5665}
5666
5667int
5668qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5669{
5670 int rval;
5671 mbx_cmd_t mc;
5672 mbx_cmd_t *mcp = &mc;
5673 struct qla_hw_data *ha = vha->hw;
5674
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005675 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005676 return QLA_FUNCTION_FAILED;
5677
5678 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5679
5680 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5681 mcp->out_mb = MBX_0;
5682 mcp->in_mb = MBX_1|MBX_0;
5683 mcp->tov = MBX_TOV_SECONDS;
5684 mcp->flags = 0;
5685 rval = qla2x00_mailbox_command(vha, mcp);
5686
5687 if (rval != QLA_SUCCESS) {
5688 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5689 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5690 rval, mcp->mb[0], mcp->mb[1]);
5691 ha->isp_ops->fw_dump(vha, 0);
5692 } else {
5693 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5694 }
5695
5696 return rval;
5697}
5698
5699int
5700qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5701 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5702{
5703 int rval;
5704 mbx_cmd_t mc;
5705 mbx_cmd_t *mcp = &mc;
5706 uint8_t subcode = (uint8_t)options;
5707 struct qla_hw_data *ha = vha->hw;
5708
5709 if (!IS_QLA8031(ha))
5710 return QLA_FUNCTION_FAILED;
5711
5712 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5713
5714 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5715 mcp->mb[1] = options;
5716 mcp->out_mb = MBX_1|MBX_0;
5717 if (subcode & BIT_2) {
5718 mcp->mb[2] = LSW(start_addr);
5719 mcp->mb[3] = MSW(start_addr);
5720 mcp->mb[4] = LSW(end_addr);
5721 mcp->mb[5] = MSW(end_addr);
5722 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5723 }
5724 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5725 if (!(subcode & (BIT_2 | BIT_5)))
5726 mcp->in_mb |= MBX_4|MBX_3;
5727 mcp->tov = MBX_TOV_SECONDS;
5728 mcp->flags = 0;
5729 rval = qla2x00_mailbox_command(vha, mcp);
5730
5731 if (rval != QLA_SUCCESS) {
5732 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5733 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5734 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5735 mcp->mb[4]);
5736 ha->isp_ops->fw_dump(vha, 0);
5737 } else {
5738 if (subcode & BIT_5)
5739 *sector_size = mcp->mb[1];
5740 else if (subcode & (BIT_6 | BIT_7)) {
5741 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5742 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5743 } else if (subcode & (BIT_3 | BIT_4)) {
5744 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5745 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5746 }
5747 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5748 }
5749
5750 return rval;
5751}
Saurav Kashyap81178772012-08-22 14:21:04 -04005752
5753int
5754qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5755 uint32_t size)
5756{
5757 int rval;
5758 mbx_cmd_t mc;
5759 mbx_cmd_t *mcp = &mc;
5760
5761 if (!IS_MCTP_CAPABLE(vha->hw))
5762 return QLA_FUNCTION_FAILED;
5763
5764 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5765 "Entered %s.\n", __func__);
5766
5767 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5768 mcp->mb[1] = LSW(addr);
5769 mcp->mb[2] = MSW(req_dma);
5770 mcp->mb[3] = LSW(req_dma);
5771 mcp->mb[4] = MSW(size);
5772 mcp->mb[5] = LSW(size);
5773 mcp->mb[6] = MSW(MSD(req_dma));
5774 mcp->mb[7] = LSW(MSD(req_dma));
5775 mcp->mb[8] = MSW(addr);
5776 /* Setting RAM ID to valid */
5777 mcp->mb[10] |= BIT_7;
5778 /* For MCTP RAM ID is 0x40 */
5779 mcp->mb[10] |= 0x40;
5780
5781 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5782 MBX_0;
5783
5784 mcp->in_mb = MBX_0;
5785 mcp->tov = MBX_TOV_SECONDS;
5786 mcp->flags = 0;
5787 rval = qla2x00_mailbox_command(vha, mcp);
5788
5789 if (rval != QLA_SUCCESS) {
5790 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5791 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5792 } else {
5793 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5794 "Done %s.\n", __func__);
5795 }
5796
5797 return rval;
5798}
Joe Carnuccioec891462016-07-06 11:14:26 -04005799
5800int
5801qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5802 void *dd_buf, uint size, uint options)
5803{
5804 int rval;
5805 mbx_cmd_t mc;
5806 mbx_cmd_t *mcp = &mc;
5807 dma_addr_t dd_dma;
5808
5809 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5810 return QLA_FUNCTION_FAILED;
5811
5812 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
5813 "Entered %s.\n", __func__);
5814
Joe Carnuccioec891462016-07-06 11:14:26 -04005815 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5816 dd_buf, size, DMA_FROM_DEVICE);
5817 if (!dd_dma) {
5818 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5819 return QLA_MEMORY_ALLOC_FAILED;
5820 }
5821
5822 memset(dd_buf, 0, size);
5823
5824 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5825 mcp->mb[1] = options;
5826 mcp->mb[2] = MSW(LSD(dd_dma));
5827 mcp->mb[3] = LSW(LSD(dd_dma));
5828 mcp->mb[6] = MSW(MSD(dd_dma));
5829 mcp->mb[7] = LSW(MSD(dd_dma));
5830 mcp->mb[8] = size;
5831 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5832 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5833 mcp->buf_size = size;
5834 mcp->flags = MBX_DMA_IN;
5835 mcp->tov = MBX_TOV_SECONDS * 4;
5836 rval = qla2x00_mailbox_command(vha, mcp);
5837
5838 if (rval != QLA_SUCCESS) {
5839 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5840 } else {
5841 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5842 "Done %s.\n", __func__);
5843 }
5844
5845 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5846 size, DMA_FROM_DEVICE);
5847
5848 return rval;
5849}
Quinn Tran15f30a52017-03-15 09:48:52 -07005850
5851static void qla2x00_async_mb_sp_done(void *s, int res)
5852{
5853 struct srb *sp = s;
5854
5855 sp->u.iocb_cmd.u.mbx.rc = res;
5856
5857 complete(&sp->u.iocb_cmd.u.mbx.comp);
5858 /* don't free sp here. Let the caller do the free */
5859}
5860
5861/*
5862 * This mailbox uses the iocb interface to send MB command.
5863 * This allows non-critial (non chip setup) command to go
5864 * out in parrallel.
5865 */
5866int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
5867{
5868 int rval = QLA_FUNCTION_FAILED;
5869 srb_t *sp;
5870 struct srb_iocb *c;
5871
5872 if (!vha->hw->flags.fw_started)
5873 goto done;
5874
5875 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
5876 if (!sp)
5877 goto done;
5878
5879 sp->type = SRB_MB_IOCB;
5880 sp->name = mb_to_str(mcp->mb[0]);
5881
5882 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
5883
5884 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
5885
5886 c = &sp->u.iocb_cmd;
5887 c->timeout = qla2x00_async_iocb_timeout;
5888 init_completion(&c->u.mbx.comp);
5889
5890 sp->done = qla2x00_async_mb_sp_done;
5891
5892 rval = qla2x00_start_sp(sp);
5893 if (rval != QLA_SUCCESS) {
5894 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5895 "%s: %s Failed submission. %x.\n",
5896 __func__, sp->name, rval);
5897 goto done_free_sp;
5898 }
5899
5900 ql_dbg(ql_dbg_mbx, vha, 0xffff, "MB:%s hndl %x submitted\n",
5901 sp->name, sp->handle);
5902
5903 wait_for_completion(&c->u.mbx.comp);
5904 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
5905
5906 rval = c->u.mbx.rc;
5907 switch (rval) {
5908 case QLA_FUNCTION_TIMEOUT:
5909 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s Timeout. %x.\n",
5910 __func__, sp->name, rval);
5911 break;
5912 case QLA_SUCCESS:
5913 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s done.\n",
5914 __func__, sp->name);
5915 sp->free(sp);
5916 break;
5917 default:
5918 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s Failed. %x.\n",
5919 __func__, sp->name, rval);
5920 sp->free(sp);
5921 break;
5922 }
5923
5924 return rval;
5925
5926done_free_sp:
5927 sp->free(sp);
5928done:
5929 return rval;
5930}
5931
5932/*
5933 * qla24xx_gpdb_wait
5934 * NOTE: Do not call this routine from DPC thread
5935 */
5936int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
5937{
5938 int rval = QLA_FUNCTION_FAILED;
5939 dma_addr_t pd_dma;
5940 struct port_database_24xx *pd;
5941 struct qla_hw_data *ha = vha->hw;
5942 mbx_cmd_t mc;
5943
5944 if (!vha->hw->flags.fw_started)
5945 goto done;
5946
5947 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
5948 if (pd == NULL) {
5949 ql_log(ql_log_warn, vha, 0xffff,
5950 "Failed to allocate port database structure.\n");
5951 goto done_free_sp;
5952 }
5953 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
5954
5955 memset(&mc, 0, sizeof(mc));
5956 mc.mb[0] = MBC_GET_PORT_DATABASE;
5957 mc.mb[1] = cpu_to_le16(fcport->loop_id);
5958 mc.mb[2] = MSW(pd_dma);
5959 mc.mb[3] = LSW(pd_dma);
5960 mc.mb[6] = MSW(MSD(pd_dma));
5961 mc.mb[7] = LSW(MSD(pd_dma));
5962 mc.mb[9] = cpu_to_le16(vha->vp_idx);
5963 mc.mb[10] = cpu_to_le16((uint16_t)opt);
5964
5965 rval = qla24xx_send_mb_cmd(vha, &mc);
5966 if (rval != QLA_SUCCESS) {
5967 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5968 "%s: %8phC fail\n", __func__, fcport->port_name);
5969 goto done_free_sp;
5970 }
5971
5972 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
5973
5974 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %8phC done\n",
5975 __func__, fcport->port_name);
5976
5977done_free_sp:
5978 if (pd)
5979 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
5980done:
5981 return rval;
5982}
5983
5984int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
5985 struct port_database_24xx *pd)
5986{
5987 int rval = QLA_SUCCESS;
5988 uint64_t zero = 0;
5989
5990 /* Check for logged in state. */
5991 if (pd->current_login_state != PDS_PRLI_COMPLETE &&
5992 pd->last_login_state != PDS_PRLI_COMPLETE) {
5993 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5994 "Unable to verify login-state (%x/%x) for "
5995 "loop_id %x.\n", pd->current_login_state,
5996 pd->last_login_state, fcport->loop_id);
5997 rval = QLA_FUNCTION_FAILED;
5998 goto gpd_error_out;
5999 }
6000
6001 if (fcport->loop_id == FC_NO_LOOP_ID ||
6002 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6003 memcmp(fcport->port_name, pd->port_name, 8))) {
6004 /* We lost the device mid way. */
6005 rval = QLA_NOT_LOGGED_IN;
6006 goto gpd_error_out;
6007 }
6008
6009 /* Names are little-endian. */
6010 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6011 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6012
6013 /* Get port_id of device. */
6014 fcport->d_id.b.domain = pd->port_id[0];
6015 fcport->d_id.b.area = pd->port_id[1];
6016 fcport->d_id.b.al_pa = pd->port_id[2];
6017 fcport->d_id.b.rsvd_1 = 0;
6018
6019 /* If not target must be initiator or unknown type. */
6020 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6021 fcport->port_type = FCT_INITIATOR;
6022 else
6023 fcport->port_type = FCT_TARGET;
6024
6025 /* Passback COS information. */
6026 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6027 FC_COS_CLASS2 : FC_COS_CLASS3;
6028
6029 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6030 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6031 fcport->conf_compl_supported = 1;
6032 }
6033
6034gpd_error_out:
6035 return rval;
6036}
6037
6038/*
6039 * qla24xx_gidlist__wait
6040 * NOTE: don't call this routine from DPC thread.
6041 */
6042int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6043 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6044{
6045 int rval = QLA_FUNCTION_FAILED;
6046 mbx_cmd_t mc;
6047
6048 if (!vha->hw->flags.fw_started)
6049 goto done;
6050
6051 memset(&mc, 0, sizeof(mc));
6052 mc.mb[0] = MBC_GET_ID_LIST;
6053 mc.mb[2] = MSW(id_list_dma);
6054 mc.mb[3] = LSW(id_list_dma);
6055 mc.mb[6] = MSW(MSD(id_list_dma));
6056 mc.mb[7] = LSW(MSD(id_list_dma));
6057 mc.mb[8] = 0;
6058 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6059
6060 rval = qla24xx_send_mb_cmd(vha, &mc);
6061 if (rval != QLA_SUCCESS) {
6062 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6063 "%s: fail\n", __func__);
6064 } else {
6065 *entries = mc.mb[1];
6066 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6067 "%s: done\n", __func__);
6068 }
6069done:
6070 return rval;
6071}