blob: 9a97f2ceffbab1e7a55402719efda19be7b264c7 [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"},
Quinn Tran94d83e32017-12-28 12:33:23 -080020 {MBC_GET_RESOURCE_COUNTS, "ResCnt"},
Quinn Tran15f30a52017-03-15 09:48:52 -070021};
22
23static const char *mb_to_str(uint16_t cmd)
24{
25 int i;
26 struct mb_cmd_name *e;
27
28 for (i = 0; i < ARRAY_SIZE(mb_str); i++) {
29 e = mb_str + i;
30 if (cmd == e->cmd)
31 return e->str;
32 }
33 return "unknown";
34}
35
Bart Van Asscheca825822017-01-17 09:34:14 -080036static struct rom_cmd {
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080037 uint16_t cmd;
38} rom_cmds[] = {
39 { MBC_LOAD_RAM },
40 { MBC_EXECUTE_FIRMWARE },
41 { MBC_READ_RAM_WORD },
42 { MBC_MAILBOX_REGISTER_TEST },
43 { MBC_VERIFY_CHECKSUM },
44 { MBC_GET_FIRMWARE_VERSION },
45 { MBC_LOAD_RISC_RAM },
46 { MBC_DUMP_RISC_RAM },
47 { MBC_LOAD_RISC_RAM_EXTENDED },
48 { MBC_DUMP_RISC_RAM_EXTENDED },
49 { MBC_WRITE_RAM_WORD_EXTENDED },
50 { MBC_READ_RAM_EXTENDED },
51 { MBC_GET_RESOURCE_COUNTS },
52 { MBC_SET_FIRMWARE_OPTION },
53 { MBC_MID_INITIALIZE_FIRMWARE },
54 { MBC_GET_FIRMWARE_STATE },
55 { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
56 { MBC_GET_RETRY_COUNT },
57 { MBC_TRACE_CONTROL },
Michael Hernandezb7edfa22017-08-23 15:04:56 -070058 { MBC_INITIALIZE_MULTIQ },
Quinn Tran1608cc42017-08-23 15:05:03 -070059 { MBC_IOCB_COMMAND_A64 },
60 { MBC_GET_ADAPTER_LOOP_ID },
Quinn Trane4e3a2c2017-08-23 15:05:07 -070061 { MBC_READ_SFP },
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080062};
63
64static int is_rom_cmd(uint16_t cmd)
65{
66 int i;
67 struct rom_cmd *wc;
68
69 for (i = 0; i < ARRAY_SIZE(rom_cmds); i++) {
70 wc = rom_cmds + i;
71 if (wc->cmd == cmd)
72 return 1;
73 }
74
75 return 0;
76}
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/*
79 * qla2x00_mailbox_command
80 * Issue mailbox command and waits for completion.
81 *
82 * Input:
83 * ha = adapter block pointer.
84 * mcp = driver internal mbx struct pointer.
85 *
86 * Output:
87 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
88 *
89 * Returns:
90 * 0 : QLA_SUCCESS = cmd performed success
91 * 1 : QLA_FUNCTION_FAILED (error encountered)
92 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
93 *
94 * Context:
95 * Kernel context.
96 */
97static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080098qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400100 int rval, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 unsigned long flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500102 device_reg_t *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700103 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700104 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700105 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 uint16_t *iptr;
107 uint16_t __iomem *optr;
108 uint32_t cnt;
109 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800111 struct qla_hw_data *ha = vha->hw;
112 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700113
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400114
Arun Easi5e19ed92012-02-09 11:15:51 -0800115 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700116
117 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800118 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700119 "error_state is greater than pci_channel_io_frozen, "
120 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -0700121 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700122 }
Seokmann Jub9b12f72009-03-24 09:08:18 -0700123
Giridhar Malavalia9083012010-04-12 17:59:55 -0700124 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800125 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700126 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700127 return QLA_FUNCTION_TIMEOUT;
128 }
129
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800130 /* if PCI error, then avoid mbx processing.*/
Sawan Chandakba175892017-06-02 09:11:58 -0700131 if (test_bit(PFLG_DISCONNECTED, &base_vha->dpc_flags) &&
132 test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700133 ql_log(ql_log_warn, vha, 0xd04e,
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400134 "PCI error, exiting.\n");
135 return QLA_FUNCTION_TIMEOUT;
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800136 }
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400137
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700138 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800139 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
141 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800142 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700144
Andrew Vasquez85880802009-12-15 21:29:46 -0800145 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800146 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700147 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800148 return QLA_FUNCTION_TIMEOUT;
149 }
150
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400151 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -0800152 /* Setting Link-Down error */
153 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -0800154 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700155 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -0800156 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -0800157 }
158
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800159 /* check if ISP abort is active and return cmd with timeout */
160 if ((test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
161 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
162 test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) &&
163 !is_rom_cmd(mcp->mb[0])) {
164 ql_log(ql_log_info, vha, 0x1005,
165 "Cmd 0x%x aborted with timeout since ISP Abort is pending\n",
166 mcp->mb[0]);
167 return QLA_FUNCTION_TIMEOUT;
168 }
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700171 * Wait for active mailbox commands to finish by waiting at most tov
172 * seconds. This is to serialize actual issuing of mailbox cmds during
173 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800175 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
176 /* Timeout occurred. Return error. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700177 ql_log(ql_log_warn, vha, 0xd035,
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800178 "Cmd access timeout, cmd=0x%x, Exiting.\n",
179 mcp->mb[0]);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800180 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 }
182
183 ha->flags.mbox_busy = 1;
184 /* Save mailbox command for debug */
185 ha->mcp = mcp;
186
Arun Easi5e19ed92012-02-09 11:15:51 -0800187 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700188 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189
190 spin_lock_irqsave(&ha->hardware_lock, flags);
191
192 /* Load mailbox registers. */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400193 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700194 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400195 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha)))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700196 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
197 else
198 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 iptr = mcp->mb;
201 command = mcp->mb[0];
202 mboxes = mcp->out_mb;
203
Joe Carnuccio7b711622014-09-25 05:16:43 -0400204 ql_dbg(ql_dbg_mbx, vha, 0x1111,
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700205 "Mailbox registers (OUT):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
207 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700208 optr =
209 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700210 if (mboxes & BIT_0) {
211 ql_dbg(ql_dbg_mbx, vha, 0x1112,
212 "mbox[%d]<-0x%04x\n", cnt, *iptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 WRT_REG_WORD(optr, *iptr);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216 mboxes >>= 1;
217 optr++;
218 iptr++;
219 }
220
Arun Easi5e19ed92012-02-09 11:15:51 -0800221 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700222 "I/O Address = %p.\n", optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 /* Issue set host interrupt command to send cmd out. */
225 ha->flags.mbox_int = 0;
226 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
227
228 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800229 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700230 "Going to unlock irq & waiting for interrupts. "
231 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 /* Wait for mbx cmd completion until timeout */
234
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800235 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
237
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400238 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700239 if (RD_REG_DWORD(&reg->isp82.hint) &
240 HINT_MBX_INT_PENDING) {
241 spin_unlock_irqrestore(&ha->hardware_lock,
242 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800243 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800244 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700245 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700246 rval = QLA_FUNCTION_TIMEOUT;
247 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700248 }
249 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
250 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700251 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
252 else
253 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 spin_unlock_irqrestore(&ha->hardware_lock, flags);
255
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800256 wait_time = jiffies;
Giridhar Malavali754d1242013-06-25 11:27:16 -0400257 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
258 mcp->tov * HZ)) {
259 ql_dbg(ql_dbg_mbx, vha, 0x117a,
260 "cmd=%x Timeout.\n", command);
261 spin_lock_irqsave(&ha->hardware_lock, flags);
262 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
264 }
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800265 if (time_after(jiffies, wait_time + 5 * HZ))
266 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
267 command, jiffies_to_msecs(jiffies - wait_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800269 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700270 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400272 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700273 if (RD_REG_DWORD(&reg->isp82.hint) &
274 HINT_MBX_INT_PENDING) {
275 spin_unlock_irqrestore(&ha->hardware_lock,
276 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800277 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800278 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700279 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700280 rval = QLA_FUNCTION_TIMEOUT;
281 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700282 }
283 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
284 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700285 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
286 else
287 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
291 while (!ha->flags.mbox_int) {
292 if (time_after(jiffies, wait_time))
293 break;
294
295 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800296 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
Andrew Vasquez85880802009-12-15 21:29:46 -0800298 if (!ha->flags.mbox_int &&
299 !(IS_QLA2200(ha) &&
300 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800301 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800303 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700304 "Waited %d sec.\n",
305 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 }
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 /* Check whether we timed out */
309 if (ha->flags.mbox_int) {
310 uint16_t *iptr2;
311
Arun Easi5e19ed92012-02-09 11:15:51 -0800312 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700313 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 /* Got interrupt. Clear the flag. */
316 ha->flags.mbox_int = 0;
317 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
318
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400319 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700320 ha->flags.mbox_busy = 0;
321 /* Setting Link-Down error */
322 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
323 ha->mcp = NULL;
324 rval = QLA_FUNCTION_FAILED;
Quinn Tran83548fe2017-06-02 09:12:01 -0700325 ql_log(ql_log_warn, vha, 0xd048,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700326 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700327 goto premature_exit;
328 }
329
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400330 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
333 /* Load return mailbox registers. */
334 iptr2 = mcp->mb;
335 iptr = (uint16_t *)&ha->mailbox_out[0];
336 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700337
338 ql_dbg(ql_dbg_mbx, vha, 0x1113,
339 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700341 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700343 ql_dbg(ql_dbg_mbx, vha, 0x1114,
344 "mbox[%d]->0x%04x\n", cnt, *iptr2);
345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 mboxes >>= 1;
348 iptr2++;
349 iptr++;
350 }
351 } else {
352
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800353 uint16_t mb[8];
354 uint32_t ictrl, host_status, hccr;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400355 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700356
Andrew Vasqueze4289242007-07-19 15:05:56 -0700357 if (IS_FWI2_CAPABLE(ha)) {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800358 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
359 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
360 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
361 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
362 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700363 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800364 host_status = RD_REG_DWORD(&reg->isp24.host_status);
365 hccr = RD_REG_DWORD(&reg->isp24.hccr);
366
Quinn Tran83548fe2017-06-02 09:12:01 -0700367 ql_log(ql_log_warn, vha, 0xd04c,
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800368 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
369 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
370 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
371 mb[7], host_status, hccr);
372
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700373 } else {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800374 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700375 ictrl = RD_REG_WORD(&reg->isp.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800376 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
377 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
378 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700379 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800380 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400382 /* Capture FW dump only, if PCI device active */
383 if (!pci_channel_offline(vha->hw->pdev)) {
384 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
385 if (w == 0xffff || ictrl == 0xffffffff) {
386 /* This is special case if there is unload
387 * of driver happening and if PCI device go
388 * into bad state due to PCI error condition
389 * then only PCI ERR flag would be set.
390 * we will do premature exit for above case.
391 */
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400392 ha->flags.mbox_busy = 0;
393 rval = QLA_FUNCTION_TIMEOUT;
394 goto premature_exit;
395 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800396
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400397 /* Attempt to capture firmware dump for further
398 * anallysis of the current formware state. we do not
399 * need to do this if we are intentionally generating
400 * a dump
401 */
402 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
403 ha->isp_ops->fw_dump(vha, 0);
404 rval = QLA_FUNCTION_TIMEOUT;
405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 }
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 ha->flags.mbox_busy = 0;
409
410 /* Clean up */
411 ha->mcp = NULL;
412
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800413 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800414 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700415 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800418 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 }
420
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700421 if (rval == QLA_FUNCTION_TIMEOUT &&
422 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800423 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
424 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800426 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700427 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700428
429 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
430 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
431 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800432 if (IS_QLA82XX(ha)) {
433 ql_dbg(ql_dbg_mbx, vha, 0x112a,
434 "disabling pause transmit on port "
435 "0 & 1.\n");
436 qla82xx_wr_32(ha,
437 QLA82XX_CRB_NIU + 0x98,
438 CRB_NIU_XG_PAUSE_CTL_P0|
439 CRB_NIU_XG_PAUSE_CTL_P1);
440 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700441 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400442 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800443 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
444 "abort.\n", command, mcp->mb[0],
445 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700446 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
447 qla2xxx_wake_dpc(vha);
448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800451 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700452 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700454 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
455 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
456 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800457 if (IS_QLA82XX(ha)) {
458 ql_dbg(ql_dbg_mbx, vha, 0x112b,
459 "disabling pause transmit on port "
460 "0 & 1.\n");
461 qla82xx_wr_32(ha,
462 QLA82XX_CRB_NIU + 0x98,
463 CRB_NIU_XG_PAUSE_CTL_P0|
464 CRB_NIU_XG_PAUSE_CTL_P1);
465 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700466 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400467 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800468 "mb[0]=0x%x. Scheduling ISP abort ",
469 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700470 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
471 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800472 /* Allow next mbx cmd to come in. */
473 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700474 if (ha->isp_ops->abort_isp(vha)) {
475 /* Failed. retry later. */
476 set_bit(ISP_ABORT_NEEDED,
477 &vha->dpc_flags);
478 }
479 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800480 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700481 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800482 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 }
485 }
486
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700487premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800489 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Giridhar Malavalid3360962012-02-09 11:14:10 -0800491mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (rval) {
Joe Carnuccio050dc762017-08-23 15:05:14 -0700493 if (ql2xextended_error_logging & (ql_dbg_disc|ql_dbg_mbx)) {
494 pr_warn("%s [%s]-%04x:%ld: **** Failed", QL_MSGHDR,
495 dev_name(&ha->pdev->dev), 0x1020+0x800,
496 vha->host_no);
497 mboxes = mcp->in_mb;
498 cnt = 4;
499 for (i = 0; i < ha->mbx_count && cnt; i++, mboxes >>= 1)
500 if (mboxes & BIT_0) {
501 printk(" mb[%u]=%x", i, mcp->mb[i]);
502 cnt--;
503 }
504 pr_warn(" cmd=%x ****\n", command);
505 }
Meelis Roosf7e59e92018-03-08 15:44:07 +0200506 if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha))) {
507 ql_dbg(ql_dbg_mbx, vha, 0x1198,
508 "host_status=%#x intr_ctrl=%#x intr_status=%#x\n",
509 RD_REG_DWORD(&reg->isp24.host_status),
510 RD_REG_DWORD(&reg->isp24.ictrl),
511 RD_REG_DWORD(&reg->isp24.istatus));
512 } else {
513 ql_dbg(ql_dbg_mbx, vha, 0x1206,
514 "ctrl_status=%#x ictrl=%#x istatus=%#x\n",
515 RD_REG_WORD(&reg->isp.ctrl_status),
516 RD_REG_WORD(&reg->isp.ictrl),
517 RD_REG_WORD(&reg->isp.istatus));
518 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700520 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 return rval;
524}
525
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800527qla2x00_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 -0800528 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
530 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800531 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 mbx_cmd_t mc;
533 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400535 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
536 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Andrew Vasqueze4289242007-07-19 15:05:56 -0700538 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800539 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
540 mcp->mb[8] = MSW(risc_addr);
541 mcp->out_mb = MBX_8|MBX_0;
542 } else {
543 mcp->mb[0] = MBC_LOAD_RISC_RAM;
544 mcp->out_mb = MBX_0;
545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 mcp->mb[1] = LSW(risc_addr);
547 mcp->mb[2] = MSW(req_dma);
548 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 mcp->mb[6] = MSW(MSD(req_dma));
550 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800551 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700552 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700553 mcp->mb[4] = MSW(risc_code_size);
554 mcp->mb[5] = LSW(risc_code_size);
555 mcp->out_mb |= MBX_5|MBX_4;
556 } else {
557 mcp->mb[4] = LSW(risc_code_size);
558 mcp->out_mb |= MBX_4;
559 }
560
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700562 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800564 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700567 ql_dbg(ql_dbg_mbx, vha, 0x1023,
568 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400570 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
571 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 }
573
574 return rval;
575}
576
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700577#define EXTENDED_BB_CREDITS BIT_0
Duane Grigsbye84067d2017-06-21 13:48:43 -0700578#define NVME_ENABLE_FLAG BIT_3
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700579static inline uint16_t qla25xx_set_sfp_lr_dist(struct qla_hw_data *ha)
580{
581 uint16_t mb4 = BIT_0;
582
583 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
584 mb4 |= ha->long_range_distance << LR_DIST_FW_POS;
585
586 return mb4;
587}
588
589static inline uint16_t qla25xx_set_nvr_lr_dist(struct qla_hw_data *ha)
590{
591 uint16_t mb4 = BIT_0;
592
593 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
594 struct nvram_81xx *nv = ha->nvram;
595
596 mb4 |= LR_DIST_FW_FIELD(nv->enhanced_features);
597 }
598
599 return mb4;
600}
Duane Grigsbye84067d2017-06-21 13:48:43 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602/*
603 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700604 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 *
606 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700607 * ha = adapter block pointer.
608 * TARGET_QUEUE_LOCK must be released.
609 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 *
611 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700612 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 *
614 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700615 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 */
617int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800618qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619{
620 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800621 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 mbx_cmd_t mc;
623 mbx_cmd_t *mcp = &mc;
624
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400625 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
626 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
628 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700629 mcp->out_mb = MBX_0;
630 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700631 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700632 mcp->mb[1] = MSW(risc_addr);
633 mcp->mb[2] = LSW(risc_addr);
634 mcp->mb[3] = 0;
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700635 mcp->mb[4] = 0;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700636 ha->flags.using_lr_setting = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500637 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
638 IS_QLA27XX(ha)) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700639 if (ql2xautodetectsfp) {
640 if (ha->flags.detected_lr_sfp) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700641 mcp->mb[4] |=
642 qla25xx_set_sfp_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700643 ha->flags.using_lr_setting = 1;
644 }
645 } else {
646 struct nvram_81xx *nv = ha->nvram;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700647 /* set LR distance if specified in nvram */
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700648 if (nv->enhanced_features &
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700649 NEF_LR_DIST_ENABLE) {
650 mcp->mb[4] |=
651 qla25xx_set_nvr_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700652 ha->flags.using_lr_setting = 1;
653 }
654 }
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700655 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500656
Duane Grigsbye84067d2017-06-21 13:48:43 -0700657 if (ql2xnvmeenable && IS_QLA27XX(ha))
658 mcp->mb[4] |= NVME_ENABLE_FLAG;
659
Sawan Chandak92d44082017-08-23 15:05:16 -0700660 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
661 struct nvram_81xx *nv = ha->nvram;
662 /* set minimum speed if specified in nvram */
663 if (nv->min_link_speed >= 2 &&
664 nv->min_link_speed <= 5) {
665 mcp->mb[4] |= BIT_4;
666 mcp->mb[11] = nv->min_link_speed;
667 mcp->out_mb |= MBX_11;
668 mcp->in_mb |= BIT_5;
669 vha->min_link_speed_feat = nv->min_link_speed;
670 }
671 }
672
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500673 if (ha->flags.exlogins_enabled)
674 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
675
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500676 if (ha->flags.exchoffld_enabled)
677 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
678
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700679 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700680 mcp->in_mb |= MBX_3 | MBX_2 | MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700681 } else {
682 mcp->mb[1] = LSW(risc_addr);
683 mcp->out_mb |= MBX_1;
684 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
685 mcp->mb[2] = 0;
686 mcp->out_mb |= MBX_2;
687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 }
689
Ravi Anandb93480e2008-04-03 13:13:25 -0700690 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800692 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700694 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700695 ql_dbg(ql_dbg_mbx, vha, 0x1026,
696 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700697 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700698 if (IS_FWI2_CAPABLE(ha)) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700699 ha->fw_ability_mask = mcp->mb[3] << 16 | mcp->mb[2];
700 ql_dbg(ql_dbg_mbx, vha, 0x119a,
701 "fw_ability_mask=%x.\n", ha->fw_ability_mask);
Sawan Chandak92d44082017-08-23 15:05:16 -0700702 ql_dbg(ql_dbg_mbx, vha, 0x1027,
703 "exchanges=%x.\n", mcp->mb[1]);
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700704 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
705 ha->max_speed_sup = mcp->mb[2] & BIT_0;
Sawan Chandak92d44082017-08-23 15:05:16 -0700706 ql_dbg(ql_dbg_mbx, vha, 0x119b,
707 "Maximum speed supported=%s.\n",
708 ha->max_speed_sup ? "32Gps" : "16Gps");
709 if (vha->min_link_speed_feat) {
710 ha->min_link_speed = mcp->mb[5];
711 ql_dbg(ql_dbg_mbx, vha, 0x119c,
712 "Minimum speed set=%s.\n",
713 mcp->mb[5] == 5 ? "32Gps" :
714 mcp->mb[5] == 4 ? "16Gps" :
715 mcp->mb[5] == 3 ? "8Gps" :
716 mcp->mb[5] == 2 ? "4Gps" :
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700717 "unknown");
Sawan Chandak92d44082017-08-23 15:05:16 -0700718 }
719 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700720 }
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700721 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
722 "Done.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
725 return rval;
726}
727
728/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500729 * qla_get_exlogin_status
730 * Get extended login status
731 * uses the memory offload control/status Mailbox
732 *
733 * Input:
734 * ha: adapter state pointer.
735 * fwopt: firmware options
736 *
737 * Returns:
738 * qla2x00 local function status
739 *
740 * Context:
741 * Kernel context.
742 */
743#define FETCH_XLOGINS_STAT 0x8
744int
745qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
746 uint16_t *ex_logins_cnt)
747{
748 int rval;
749 mbx_cmd_t mc;
750 mbx_cmd_t *mcp = &mc;
751
752 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
753 "Entered %s\n", __func__);
754
755 memset(mcp->mb, 0 , sizeof(mcp->mb));
756 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
757 mcp->mb[1] = FETCH_XLOGINS_STAT;
758 mcp->out_mb = MBX_1|MBX_0;
759 mcp->in_mb = MBX_10|MBX_4|MBX_0;
760 mcp->tov = MBX_TOV_SECONDS;
761 mcp->flags = 0;
762
763 rval = qla2x00_mailbox_command(vha, mcp);
764 if (rval != QLA_SUCCESS) {
765 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
766 } else {
767 *buf_sz = mcp->mb[4];
768 *ex_logins_cnt = mcp->mb[10];
769
770 ql_log(ql_log_info, vha, 0x1190,
771 "buffer size 0x%x, exchange login count=%d\n",
772 mcp->mb[4], mcp->mb[10]);
773
774 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
775 "Done %s.\n", __func__);
776 }
777
778 return rval;
779}
780
781/*
782 * qla_set_exlogin_mem_cfg
783 * set extended login memory configuration
784 * Mbx needs to be issues before init_cb is set
785 *
786 * Input:
787 * ha: adapter state pointer.
788 * buffer: buffer pointer
789 * phys_addr: physical address of buffer
790 * size: size of buffer
791 * TARGET_QUEUE_LOCK must be released
792 * ADAPTER_STATE_LOCK must be release
793 *
794 * Returns:
795 * qla2x00 local funxtion status code.
796 *
797 * Context:
798 * Kernel context.
799 */
800#define CONFIG_XLOGINS_MEM 0x3
801int
802qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
803{
804 int rval;
805 mbx_cmd_t mc;
806 mbx_cmd_t *mcp = &mc;
807 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500808
809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
810 "Entered %s.\n", __func__);
811
812 memset(mcp->mb, 0 , sizeof(mcp->mb));
813 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
814 mcp->mb[1] = CONFIG_XLOGINS_MEM;
815 mcp->mb[2] = MSW(phys_addr);
816 mcp->mb[3] = LSW(phys_addr);
817 mcp->mb[6] = MSW(MSD(phys_addr));
818 mcp->mb[7] = LSW(MSD(phys_addr));
819 mcp->mb[8] = MSW(ha->exlogin_size);
820 mcp->mb[9] = LSW(ha->exlogin_size);
821 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
822 mcp->in_mb = MBX_11|MBX_0;
823 mcp->tov = MBX_TOV_SECONDS;
824 mcp->flags = 0;
825 rval = qla2x00_mailbox_command(vha, mcp);
826 if (rval != QLA_SUCCESS) {
827 /*EMPTY*/
828 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
829 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500830 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
831 "Done %s.\n", __func__);
832 }
833
834 return rval;
835}
836
837/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500838 * qla_get_exchoffld_status
839 * Get exchange offload status
840 * uses the memory offload control/status Mailbox
841 *
842 * Input:
843 * ha: adapter state pointer.
844 * fwopt: firmware options
845 *
846 * Returns:
847 * qla2x00 local function status
848 *
849 * Context:
850 * Kernel context.
851 */
852#define FETCH_XCHOFFLD_STAT 0x2
853int
854qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
855 uint16_t *ex_logins_cnt)
856{
857 int rval;
858 mbx_cmd_t mc;
859 mbx_cmd_t *mcp = &mc;
860
861 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
862 "Entered %s\n", __func__);
863
864 memset(mcp->mb, 0 , sizeof(mcp->mb));
865 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
866 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
867 mcp->out_mb = MBX_1|MBX_0;
868 mcp->in_mb = MBX_10|MBX_4|MBX_0;
869 mcp->tov = MBX_TOV_SECONDS;
870 mcp->flags = 0;
871
872 rval = qla2x00_mailbox_command(vha, mcp);
873 if (rval != QLA_SUCCESS) {
874 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
875 } else {
876 *buf_sz = mcp->mb[4];
877 *ex_logins_cnt = mcp->mb[10];
878
879 ql_log(ql_log_info, vha, 0x118e,
880 "buffer size 0x%x, exchange offload count=%d\n",
881 mcp->mb[4], mcp->mb[10]);
882
883 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
884 "Done %s.\n", __func__);
885 }
886
887 return rval;
888}
889
890/*
891 * qla_set_exchoffld_mem_cfg
892 * Set exchange offload memory configuration
893 * Mbx needs to be issues before init_cb is set
894 *
895 * Input:
896 * ha: adapter state pointer.
897 * buffer: buffer pointer
898 * phys_addr: physical address of buffer
899 * size: size of buffer
900 * TARGET_QUEUE_LOCK must be released
901 * ADAPTER_STATE_LOCK must be release
902 *
903 * Returns:
904 * qla2x00 local funxtion status code.
905 *
906 * Context:
907 * Kernel context.
908 */
909#define CONFIG_XCHOFFLD_MEM 0x3
910int
Quinn Tran99e1b682017-06-02 09:12:03 -0700911qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500912{
913 int rval;
914 mbx_cmd_t mc;
915 mbx_cmd_t *mcp = &mc;
916 struct qla_hw_data *ha = vha->hw;
917
918 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
919 "Entered %s.\n", __func__);
920
921 memset(mcp->mb, 0 , sizeof(mcp->mb));
922 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
923 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -0700924 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
925 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
926 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
927 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
928 mcp->mb[8] = MSW(ha->exchoffld_size);
929 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500930 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
931 mcp->in_mb = MBX_11|MBX_0;
932 mcp->tov = MBX_TOV_SECONDS;
933 mcp->flags = 0;
934 rval = qla2x00_mailbox_command(vha, mcp);
935 if (rval != QLA_SUCCESS) {
936 /*EMPTY*/
937 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
938 } else {
939 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
940 "Done %s.\n", __func__);
941 }
942
943 return rval;
944}
945
946/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 * qla2x00_get_fw_version
948 * Get firmware version.
949 *
950 * Input:
951 * ha: adapter state pointer.
952 * major: pointer for major number.
953 * minor: pointer for minor number.
954 * subminor: pointer for subminor number.
955 *
956 * Returns:
957 * qla2x00 local function return status code.
958 *
959 * Context:
960 * Kernel context.
961 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700962int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800963qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964{
965 int rval;
966 mbx_cmd_t mc;
967 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800968 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400970 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
971 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
973 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
974 mcp->out_mb = MBX_0;
975 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400976 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700977 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400978 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800979 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500980 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400981 mcp->in_mb |=
982 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
983 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -0400984
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700986 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800987 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700988 if (rval != QLA_SUCCESS)
989 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800992 ha->fw_major_version = mcp->mb[1];
993 ha->fw_minor_version = mcp->mb[2];
994 ha->fw_subminor_version = mcp->mb[3];
995 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800996 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800997 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800999 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -04001000
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001001 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001002 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1003 ha->mpi_version[1] = mcp->mb[11] >> 8;
1004 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1005 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
1006 ha->phy_version[0] = mcp->mb[8] & 0xff;
1007 ha->phy_version[1] = mcp->mb[9] >> 8;
1008 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001009 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001010
Saurav Kashyap81178772012-08-22 14:21:04 -04001011 if (IS_FWI2_CAPABLE(ha)) {
1012 ha->fw_attributes_h = mcp->mb[15];
1013 ha->fw_attributes_ext[0] = mcp->mb[16];
1014 ha->fw_attributes_ext[1] = mcp->mb[17];
1015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
1016 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
1017 __func__, mcp->mb[15], mcp->mb[6]);
1018 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
1019 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
1020 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001021
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001022 if (ha->fw_attributes_h & 0x4)
1023 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
1024 "%s: Firmware supports Extended Login 0x%x\n",
1025 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001026
1027 if (ha->fw_attributes_h & 0x8)
1028 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
1029 "%s: Firmware supports Exchange Offload 0x%x\n",
1030 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -07001031
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07001032 /*
1033 * FW supports nvme and driver load parameter requested nvme.
1034 * BIT 26 of fw_attributes indicates NVMe support.
1035 */
1036 if ((ha->fw_attributes_h & 0x400) && ql2xnvmeenable)
Duane Grigsbye84067d2017-06-21 13:48:43 -07001037 vha->flags.nvme_enabled = 1;
Duane Grigsbye84067d2017-06-21 13:48:43 -07001038
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001039 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001040
Chad Dupuisf73cb692014-02-26 04:15:06 -05001041 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -04001042 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1043 ha->mpi_version[1] = mcp->mb[11] >> 8;
1044 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1045 ha->pep_version[0] = mcp->mb[13] & 0xff;
1046 ha->pep_version[1] = mcp->mb[14] >> 8;
1047 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001048 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
1049 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001050 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
1051 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -05001052 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001053
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001054failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if (rval != QLA_SUCCESS) {
1056 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001057 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 } else {
1059 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001060 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
1061 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001063 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064}
1065
1066/*
1067 * qla2x00_get_fw_options
1068 * Set firmware options.
1069 *
1070 * Input:
1071 * ha = adapter block pointer.
1072 * fwopt = pointer for firmware options.
1073 *
1074 * Returns:
1075 * qla2x00 local function return status code.
1076 *
1077 * Context:
1078 * Kernel context.
1079 */
1080int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001081qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082{
1083 int rval;
1084 mbx_cmd_t mc;
1085 mbx_cmd_t *mcp = &mc;
1086
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001087 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1088 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1091 mcp->out_mb = MBX_0;
1092 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001093 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001095 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096
1097 if (rval != QLA_SUCCESS) {
1098 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001099 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001101 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 fwopts[1] = mcp->mb[1];
1103 fwopts[2] = mcp->mb[2];
1104 fwopts[3] = mcp->mb[3];
1105
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001106 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1107 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
1109
1110 return rval;
1111}
1112
1113
1114/*
1115 * qla2x00_set_fw_options
1116 * Set firmware options.
1117 *
1118 * Input:
1119 * ha = adapter block pointer.
1120 * fwopt = pointer for firmware options.
1121 *
1122 * Returns:
1123 * qla2x00 local function return status code.
1124 *
1125 * Context:
1126 * Kernel context.
1127 */
1128int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001129qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
1131 int rval;
1132 mbx_cmd_t mc;
1133 mbx_cmd_t *mcp = &mc;
1134
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001135 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1136 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1139 mcp->mb[1] = fwopts[1];
1140 mcp->mb[2] = fwopts[2];
1141 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001142 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001144 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001145 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001146 mcp->mb[10] = fwopts[10];
1147 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001148 } else {
1149 mcp->mb[10] = fwopts[10];
1150 mcp->mb[11] = fwopts[11];
1151 mcp->mb[12] = 0; /* Undocumented, but used */
1152 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1153 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001154 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001156 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001158 fwopts[0] = mcp->mb[0];
1159
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (rval != QLA_SUCCESS) {
1161 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001162 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1163 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 } else {
1165 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001166 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1167 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 }
1169
1170 return rval;
1171}
1172
1173/*
1174 * qla2x00_mbx_reg_test
1175 * Mailbox register wrap test.
1176 *
1177 * Input:
1178 * ha = adapter block pointer.
1179 * TARGET_QUEUE_LOCK must be released.
1180 * ADAPTER_STATE_LOCK must be released.
1181 *
1182 * Returns:
1183 * qla2x00 local function return status code.
1184 *
1185 * Context:
1186 * Kernel context.
1187 */
1188int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001189qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190{
1191 int rval;
1192 mbx_cmd_t mc;
1193 mbx_cmd_t *mcp = &mc;
1194
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001195 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1196 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
1198 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1199 mcp->mb[1] = 0xAAAA;
1200 mcp->mb[2] = 0x5555;
1201 mcp->mb[3] = 0xAA55;
1202 mcp->mb[4] = 0x55AA;
1203 mcp->mb[5] = 0xA5A5;
1204 mcp->mb[6] = 0x5A5A;
1205 mcp->mb[7] = 0x2525;
1206 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1207 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 -07001208 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001210 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
1212 if (rval == QLA_SUCCESS) {
1213 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1214 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1215 rval = QLA_FUNCTION_FAILED;
1216 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1217 mcp->mb[7] != 0x2525)
1218 rval = QLA_FUNCTION_FAILED;
1219 }
1220
1221 if (rval != QLA_SUCCESS) {
1222 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001223 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 } else {
1225 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001226 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1227 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 }
1229
1230 return rval;
1231}
1232
1233/*
1234 * qla2x00_verify_checksum
1235 * Verify firmware checksum.
1236 *
1237 * Input:
1238 * ha = adapter block pointer.
1239 * TARGET_QUEUE_LOCK must be released.
1240 * ADAPTER_STATE_LOCK must be released.
1241 *
1242 * Returns:
1243 * qla2x00 local function return status code.
1244 *
1245 * Context:
1246 * Kernel context.
1247 */
1248int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001249qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250{
1251 int rval;
1252 mbx_cmd_t mc;
1253 mbx_cmd_t *mcp = &mc;
1254
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001255 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1256 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
1258 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001259 mcp->out_mb = MBX_0;
1260 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001261 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001262 mcp->mb[1] = MSW(risc_addr);
1263 mcp->mb[2] = LSW(risc_addr);
1264 mcp->out_mb |= MBX_2|MBX_1;
1265 mcp->in_mb |= MBX_2|MBX_1;
1266 } else {
1267 mcp->mb[1] = LSW(risc_addr);
1268 mcp->out_mb |= MBX_1;
1269 mcp->in_mb |= MBX_1;
1270 }
1271
Ravi Anandb93480e2008-04-03 13:13:25 -07001272 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001274 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001277 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1278 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1279 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001281 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1282 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 }
1284
1285 return rval;
1286}
1287
1288/*
1289 * qla2x00_issue_iocb
1290 * Issue IOCB using mailbox command
1291 *
1292 * Input:
1293 * ha = adapter state pointer.
1294 * buffer = buffer pointer.
1295 * phys_addr = physical address of buffer.
1296 * size = size of buffer.
1297 * TARGET_QUEUE_LOCK must be released.
1298 * ADAPTER_STATE_LOCK must be released.
1299 *
1300 * Returns:
1301 * qla2x00 local function return status code.
1302 *
1303 * Context:
1304 * Kernel context.
1305 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001306int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001307qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001308 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
1310 int rval;
1311 mbx_cmd_t mc;
1312 mbx_cmd_t *mcp = &mc;
1313
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001314 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1315 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001316
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1318 mcp->mb[1] = 0;
1319 mcp->mb[2] = MSW(phys_addr);
1320 mcp->mb[3] = LSW(phys_addr);
1321 mcp->mb[6] = MSW(MSD(phys_addr));
1322 mcp->mb[7] = LSW(MSD(phys_addr));
1323 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1324 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001325 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001327 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 if (rval != QLA_SUCCESS) {
1330 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001331 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001333 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1334
1335 /* Mask reserved bits. */
1336 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001337 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1339 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341
1342 return rval;
1343}
1344
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001345int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001346qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001347 size_t size)
1348{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001349 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001350 MBX_TOV_SECONDS);
1351}
1352
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353/*
1354 * qla2x00_abort_command
1355 * Abort command aborts a specified IOCB.
1356 *
1357 * Input:
1358 * ha = adapter block pointer.
1359 * sp = SB structure pointer.
1360 *
1361 * Returns:
1362 * qla2x00 local function return status code.
1363 *
1364 * Context:
1365 * Kernel context.
1366 */
1367int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001368qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369{
1370 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001372 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 mbx_cmd_t mc;
1374 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001375 fc_port_t *fcport = sp->fcport;
1376 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001377 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001378 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001379 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001381 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1382 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
Michael Hernandezd7459522016-12-12 14:40:07 -08001384 if (vha->flags.qpairs_available && sp->qpair)
1385 req = sp->qpair->req;
1386 else
1387 req = vha->req;
1388
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001389 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001390 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001391 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 break;
1393 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001394 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Chad Dupuis8d93f552013-01-30 03:34:37 -05001396 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 /* command not found */
1398 return QLA_FUNCTION_FAILED;
1399 }
1400
1401 mcp->mb[0] = MBC_ABORT_COMMAND;
1402 if (HAS_EXTENDED_IDS(ha))
1403 mcp->mb[1] = fcport->loop_id;
1404 else
1405 mcp->mb[1] = fcport->loop_id << 8;
1406 mcp->mb[2] = (uint16_t)handle;
1407 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001408 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1410 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001411 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001413 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001416 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001418 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1419 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421
1422 return rval;
1423}
1424
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001426qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001428 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 mbx_cmd_t mc;
1430 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001431 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001432 struct req_que *req;
1433 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434
Andrew Vasquez523ec772008-04-03 13:13:24 -07001435 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001436 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001437
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001438 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1439 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001440
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001441 req = vha->hw->req_q_map[0];
1442 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001444 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001445 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 mcp->mb[1] = fcport->loop_id;
1447 mcp->mb[10] = 0;
1448 mcp->out_mb |= MBX_10;
1449 } else {
1450 mcp->mb[1] = fcport->loop_id << 8;
1451 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001452 mcp->mb[2] = vha->hw->loop_reset_delay;
1453 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
1455 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001456 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001458 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001460 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1461 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001462 }
1463
1464 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001465 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1466 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001467 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001468 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1469 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001471 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1472 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001473 }
1474
1475 return rval;
1476}
1477
1478int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001479qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001480{
1481 int rval, rval2;
1482 mbx_cmd_t mc;
1483 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001484 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001485 struct req_que *req;
1486 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001487
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001488 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001489
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001490 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1491 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001492
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001493 req = vha->hw->req_q_map[0];
1494 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001495 mcp->mb[0] = MBC_LUN_RESET;
1496 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001497 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001498 mcp->mb[1] = fcport->loop_id;
1499 else
1500 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001501 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001502 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001503 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001504
1505 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001506 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001507 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001508 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001509 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001510 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001511 }
1512
1513 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001514 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1515 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001516 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001517 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1518 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001519 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001520 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1521 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 }
1523
1524 return rval;
1525}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 * qla2x00_get_adapter_id
1529 * Get adapter ID and topology.
1530 *
1531 * Input:
1532 * ha = adapter block pointer.
1533 * id = pointer for loop ID.
1534 * al_pa = pointer for AL_PA.
1535 * area = pointer for area.
1536 * domain = pointer for domain.
1537 * top = pointer for topology.
1538 * TARGET_QUEUE_LOCK must be released.
1539 * ADAPTER_STATE_LOCK must be released.
1540 *
1541 * Returns:
1542 * qla2x00 local function return status code.
1543 *
1544 * Context:
1545 * Kernel context.
1546 */
1547int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001548qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001549 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
1551 int rval;
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, 0x1046,
1556 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001559 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001560 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001561 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001562 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001563 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001564 if (IS_FWI2_CAPABLE(vha->hw))
1565 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001566 if (IS_QLA27XX(vha->hw))
1567 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001568 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001570 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001571 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1572 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001573 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1574 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
1576 /* Return data. */
1577 *id = mcp->mb[1];
1578 *al_pa = LSB(mcp->mb[2]);
1579 *area = MSB(mcp->mb[2]);
1580 *domain = LSB(mcp->mb[3]);
1581 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001582 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 if (rval != QLA_SUCCESS) {
1585 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001586 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1589 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001590
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001591 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001592 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1593 vha->fcoe_fcf_idx = mcp->mb[10];
1594 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1595 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1596 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1597 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1598 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1599 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1600 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001601 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001602 if (IS_FAWWN_CAPABLE(vha->hw)) {
1603 if (mcp->mb[7] & BIT_14) {
1604 vha->port_name[0] = MSB(mcp->mb[16]);
1605 vha->port_name[1] = LSB(mcp->mb[16]);
1606 vha->port_name[2] = MSB(mcp->mb[17]);
1607 vha->port_name[3] = LSB(mcp->mb[17]);
1608 vha->port_name[4] = MSB(mcp->mb[18]);
1609 vha->port_name[5] = LSB(mcp->mb[18]);
1610 vha->port_name[6] = MSB(mcp->mb[19]);
1611 vha->port_name[7] = LSB(mcp->mb[19]);
1612 fc_host_port_name(vha->host) =
1613 wwn_to_u64(vha->port_name);
1614 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1615 "FA-WWN acquired %016llx\n",
1616 wwn_to_u64(vha->port_name));
1617 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001618 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001619
1620 if (IS_QLA27XX(vha->hw))
1621 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 }
1623
1624 return rval;
1625}
1626
1627/*
1628 * qla2x00_get_retry_cnt
1629 * Get current firmware login retry count and delay.
1630 *
1631 * Input:
1632 * ha = adapter block pointer.
1633 * retry_cnt = pointer to login retry count.
1634 * tov = pointer to login timeout value.
1635 *
1636 * Returns:
1637 * qla2x00 local function return status code.
1638 *
1639 * Context:
1640 * Kernel context.
1641 */
1642int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001643qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 uint16_t *r_a_tov)
1645{
1646 int rval;
1647 uint16_t ratov;
1648 mbx_cmd_t mc;
1649 mbx_cmd_t *mcp = &mc;
1650
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001651 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1652 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1655 mcp->out_mb = MBX_0;
1656 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001657 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001659 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 if (rval != QLA_SUCCESS) {
1662 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001663 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1664 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 } else {
1666 /* Convert returned data and check our values. */
1667 *r_a_tov = mcp->mb[3] / 2;
1668 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1669 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1670 /* Update to the larger values */
1671 *retry_cnt = (uint8_t)mcp->mb[1];
1672 *tov = ratov;
1673 }
1674
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001675 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001676 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 }
1678
1679 return rval;
1680}
1681
1682/*
1683 * qla2x00_init_firmware
1684 * Initialize adapter firmware.
1685 *
1686 * Input:
1687 * ha = adapter block pointer.
1688 * dptr = Initialization control block pointer.
1689 * size = size of initialization control block.
1690 * TARGET_QUEUE_LOCK must be released.
1691 * ADAPTER_STATE_LOCK must be released.
1692 *
1693 * Returns:
1694 * qla2x00 local function return status code.
1695 *
1696 * Context:
1697 * Kernel context.
1698 */
1699int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001700qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701{
1702 int rval;
1703 mbx_cmd_t mc;
1704 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001705 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001707 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1708 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001710 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001711 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001712 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1713
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001714 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001715 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1716 else
1717 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1718
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001719 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 mcp->mb[2] = MSW(ha->init_cb_dma);
1721 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1723 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001724 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001725 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001726 mcp->mb[1] = BIT_0;
1727 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1728 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1729 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1730 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1731 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1732 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1733 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001734 /* 1 and 2 should normally be captured. */
1735 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001736 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001737 /* mb3 is additional info about the installed SFP. */
1738 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 mcp->buf_size = size;
1740 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001741 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001742 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 if (rval != QLA_SUCCESS) {
1745 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001746 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001747 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1748 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 } else {
Sawan Chandak92d44082017-08-23 15:05:16 -07001750 if (IS_QLA27XX(ha)) {
1751 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1752 ql_dbg(ql_dbg_mbx, vha, 0x119d,
1753 "Invalid SFP/Validation Failed\n");
1754 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001755 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1756 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 }
1758
1759 return rval;
1760}
1761
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001762
1763/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 * qla2x00_get_port_database
1765 * Issue normal/enhanced get port database mailbox command
1766 * and copy device name as necessary.
1767 *
1768 * Input:
1769 * ha = adapter state pointer.
1770 * dev = structure pointer.
1771 * opt = enhanced cmd option byte.
1772 *
1773 * Returns:
1774 * qla2x00 local function return status code.
1775 *
1776 * Context:
1777 * Kernel context.
1778 */
1779int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001780qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781{
1782 int rval;
1783 mbx_cmd_t mc;
1784 mbx_cmd_t *mcp = &mc;
1785 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001786 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001788 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001790 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1791 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001793 pd24 = NULL;
Thomas Meyer08eb7f42017-09-21 08:15:26 +02001794 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001796 ql_log(ql_log_warn, vha, 0x1050,
1797 "Failed to allocate port database structure.\n");
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001798 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 return QLA_MEMORY_ALLOC_FAILED;
1800 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001802 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001803 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 mcp->mb[2] = MSW(pd_dma);
1806 mcp->mb[3] = LSW(pd_dma);
1807 mcp->mb[6] = MSW(MSD(pd_dma));
1808 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001809 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001810 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001812 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001813 mcp->mb[1] = fcport->loop_id;
1814 mcp->mb[10] = opt;
1815 mcp->out_mb |= MBX_10|MBX_1;
1816 mcp->in_mb |= MBX_1;
1817 } else if (HAS_EXTENDED_IDS(ha)) {
1818 mcp->mb[1] = fcport->loop_id;
1819 mcp->mb[10] = opt;
1820 mcp->out_mb |= MBX_10|MBX_1;
1821 } else {
1822 mcp->mb[1] = fcport->loop_id << 8 | opt;
1823 mcp->out_mb |= MBX_1;
1824 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001825 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1826 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 mcp->flags = MBX_DMA_IN;
1828 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001829 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 if (rval != QLA_SUCCESS)
1831 goto gpd_error_out;
1832
Andrew Vasqueze4289242007-07-19 15:05:56 -07001833 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001834 uint64_t zero = 0;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001835 u8 current_login_state, last_login_state;
1836
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001837 pd24 = (struct port_database_24xx *) pd;
1838
1839 /* Check for logged in state. */
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001840 if (fcport->fc4f_nvme) {
1841 current_login_state = pd24->current_login_state >> 4;
1842 last_login_state = pd24->last_login_state >> 4;
1843 } else {
1844 current_login_state = pd24->current_login_state & 0xf;
1845 last_login_state = pd24->last_login_state & 0xf;
1846 }
1847 fcport->current_login_state = pd24->current_login_state;
1848 fcport->last_login_state = pd24->last_login_state;
1849
1850 /* Check for logged in state. */
1851 if (current_login_state != PDS_PRLI_COMPLETE &&
1852 last_login_state != PDS_PRLI_COMPLETE) {
1853 ql_dbg(ql_dbg_mbx, vha, 0x119a,
1854 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
1855 current_login_state, last_login_state,
1856 fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001857 rval = QLA_FUNCTION_FAILED;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001858
1859 if (!fcport->query)
1860 goto gpd_error_out;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001861 }
1862
Arun Easi0eba25d2012-02-09 11:15:58 -08001863 if (fcport->loop_id == FC_NO_LOOP_ID ||
1864 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1865 memcmp(fcport->port_name, pd24->port_name, 8))) {
1866 /* We lost the device mid way. */
1867 rval = QLA_NOT_LOGGED_IN;
1868 goto gpd_error_out;
1869 }
1870
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001871 /* Names are little-endian. */
1872 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1873 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1874
1875 /* Get port_id of device. */
1876 fcport->d_id.b.domain = pd24->port_id[0];
1877 fcport->d_id.b.area = pd24->port_id[1];
1878 fcport->d_id.b.al_pa = pd24->port_id[2];
1879 fcport->d_id.b.rsvd_1 = 0;
1880
1881 /* If not target must be initiator or unknown type. */
1882 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1883 fcport->port_type = FCT_INITIATOR;
1884 else
1885 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001886
1887 /* Passback COS information. */
1888 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1889 FC_COS_CLASS2 : FC_COS_CLASS3;
1890
1891 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1892 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001893 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001894 uint64_t zero = 0;
1895
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001896 /* Check for logged in state. */
1897 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1898 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001899 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1900 "Unable to verify login-state (%x/%x) - "
1901 "portid=%02x%02x%02x.\n", pd->master_state,
1902 pd->slave_state, fcport->d_id.b.domain,
1903 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001904 rval = QLA_FUNCTION_FAILED;
1905 goto gpd_error_out;
1906 }
1907
Arun Easi0eba25d2012-02-09 11:15:58 -08001908 if (fcport->loop_id == FC_NO_LOOP_ID ||
1909 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1910 memcmp(fcport->port_name, pd->port_name, 8))) {
1911 /* We lost the device mid way. */
1912 rval = QLA_NOT_LOGGED_IN;
1913 goto gpd_error_out;
1914 }
1915
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001916 /* Names are little-endian. */
1917 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1918 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1919
1920 /* Get port_id of device. */
1921 fcport->d_id.b.domain = pd->port_id[0];
1922 fcport->d_id.b.area = pd->port_id[3];
1923 fcport->d_id.b.al_pa = pd->port_id[2];
1924 fcport->d_id.b.rsvd_1 = 0;
1925
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001926 /* If not target must be initiator or unknown type. */
1927 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1928 fcport->port_type = FCT_INITIATOR;
1929 else
1930 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001931
1932 /* Passback COS information. */
1933 fcport->supported_classes = (pd->options & BIT_4) ?
1934 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 }
1936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937gpd_error_out:
1938 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001939 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
1941 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001942 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1943 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1944 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001946 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1947 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 }
1949
1950 return rval;
1951}
1952
1953/*
1954 * qla2x00_get_firmware_state
1955 * Get adapter firmware state.
1956 *
1957 * Input:
1958 * ha = adapter block pointer.
1959 * dptr = pointer for firmware state.
1960 * TARGET_QUEUE_LOCK must be released.
1961 * ADAPTER_STATE_LOCK must be released.
1962 *
1963 * Returns:
1964 * qla2x00 local function return status code.
1965 *
1966 * Context:
1967 * Kernel context.
1968 */
1969int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001970qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971{
1972 int rval;
1973 mbx_cmd_t mc;
1974 mbx_cmd_t *mcp = &mc;
Sawan Chandak92d44082017-08-23 15:05:16 -07001975 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001977 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1978 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
1980 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1981 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001982 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001983 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001984 else
1985 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001986 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001988 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001990 /* Return firmware states. */
1991 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001992 if (IS_FWI2_CAPABLE(vha->hw)) {
1993 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04001994 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001995 states[3] = mcp->mb[4];
1996 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001997 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001998 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 if (rval != QLA_SUCCESS) {
2001 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002002 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 } else {
Sawan Chandak92d44082017-08-23 15:05:16 -07002004 if (IS_QLA27XX(ha)) {
2005 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
2006 ql_dbg(ql_dbg_mbx, vha, 0x119e,
2007 "Invalid SFP/Validation Failed\n");
2008 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002009 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
2010 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 }
2012
2013 return rval;
2014}
2015
2016/*
2017 * qla2x00_get_port_name
2018 * Issue get port name mailbox command.
2019 * Returned name is in big endian format.
2020 *
2021 * Input:
2022 * ha = adapter block pointer.
2023 * loop_id = loop ID of device.
2024 * name = pointer for name.
2025 * TARGET_QUEUE_LOCK must be released.
2026 * ADAPTER_STATE_LOCK must be released.
2027 *
2028 * Returns:
2029 * qla2x00 local function return status code.
2030 *
2031 * Context:
2032 * Kernel context.
2033 */
2034int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002035qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 uint8_t opt)
2037{
2038 int rval;
2039 mbx_cmd_t mc;
2040 mbx_cmd_t *mcp = &mc;
2041
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002042 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
2043 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
2045 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002046 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002047 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002048 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 mcp->mb[1] = loop_id;
2050 mcp->mb[10] = opt;
2051 mcp->out_mb |= MBX_10;
2052 } else {
2053 mcp->mb[1] = loop_id << 8 | opt;
2054 }
2055
2056 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002057 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002059 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 if (rval != QLA_SUCCESS) {
2062 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002063 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 } else {
2065 if (name != NULL) {
2066 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002067 name[0] = MSB(mcp->mb[2]);
2068 name[1] = LSB(mcp->mb[2]);
2069 name[2] = MSB(mcp->mb[3]);
2070 name[3] = LSB(mcp->mb[3]);
2071 name[4] = MSB(mcp->mb[6]);
2072 name[5] = LSB(mcp->mb[6]);
2073 name[6] = MSB(mcp->mb[7]);
2074 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 }
2076
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002077 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2078 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 }
2080
2081 return rval;
2082}
2083
2084/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002085 * qla24xx_link_initialization
2086 * Issue link initialization mailbox command.
2087 *
2088 * Input:
2089 * ha = adapter block pointer.
2090 * TARGET_QUEUE_LOCK must be released.
2091 * ADAPTER_STATE_LOCK must be released.
2092 *
2093 * Returns:
2094 * qla2x00 local function return status code.
2095 *
2096 * Context:
2097 * Kernel context.
2098 */
2099int
2100qla24xx_link_initialize(scsi_qla_host_t *vha)
2101{
2102 int rval;
2103 mbx_cmd_t mc;
2104 mbx_cmd_t *mcp = &mc;
2105
2106 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2107 "Entered %s.\n", __func__);
2108
2109 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2110 return QLA_FUNCTION_FAILED;
2111
2112 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002113 mcp->mb[1] = BIT_4;
2114 if (vha->hw->operating_mode == LOOP)
2115 mcp->mb[1] |= BIT_6;
2116 else
2117 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002118 mcp->mb[2] = 0;
2119 mcp->mb[3] = 0;
2120 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2121 mcp->in_mb = MBX_0;
2122 mcp->tov = MBX_TOV_SECONDS;
2123 mcp->flags = 0;
2124 rval = qla2x00_mailbox_command(vha, mcp);
2125
2126 if (rval != QLA_SUCCESS) {
2127 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2128 } else {
2129 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2130 "Done %s.\n", __func__);
2131 }
2132
2133 return rval;
2134}
2135
2136/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 * qla2x00_lip_reset
2138 * Issue LIP reset mailbox command.
2139 *
2140 * Input:
2141 * ha = adapter block pointer.
2142 * TARGET_QUEUE_LOCK must be released.
2143 * ADAPTER_STATE_LOCK must be released.
2144 *
2145 * Returns:
2146 * qla2x00 local function return status code.
2147 *
2148 * Context:
2149 * Kernel context.
2150 */
2151int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002152qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
2154 int rval;
2155 mbx_cmd_t mc;
2156 mbx_cmd_t *mcp = &mc;
2157
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002158 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2159 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002161 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002162 /* Logout across all FCFs. */
2163 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2164 mcp->mb[1] = BIT_1;
2165 mcp->mb[2] = 0;
2166 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2167 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002168 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002169 mcp->mb[1] = BIT_6;
2170 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002171 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002172 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002174 mcp->mb[0] = MBC_LIP_RESET;
2175 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002176 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002177 mcp->mb[1] = 0x00ff;
2178 mcp->mb[10] = 0;
2179 mcp->out_mb |= MBX_10;
2180 } else {
2181 mcp->mb[1] = 0xff00;
2182 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002183 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002184 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002187 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002189 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
2191 if (rval != QLA_SUCCESS) {
2192 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002193 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 } else {
2195 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002196 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2197 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 }
2199
2200 return rval;
2201}
2202
2203/*
2204 * qla2x00_send_sns
2205 * Send SNS command.
2206 *
2207 * Input:
2208 * ha = adapter block pointer.
2209 * sns = pointer for command.
2210 * cmd_size = command size.
2211 * buf_size = response/command size.
2212 * TARGET_QUEUE_LOCK must be released.
2213 * ADAPTER_STATE_LOCK must be released.
2214 *
2215 * Returns:
2216 * qla2x00 local function return status code.
2217 *
2218 * Context:
2219 * Kernel context.
2220 */
2221int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002222qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 uint16_t cmd_size, size_t buf_size)
2224{
2225 int rval;
2226 mbx_cmd_t mc;
2227 mbx_cmd_t *mcp = &mc;
2228
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002229 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2230 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002232 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002233 "Retry cnt=%d ratov=%d total tov=%d.\n",
2234 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
2236 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2237 mcp->mb[1] = cmd_size;
2238 mcp->mb[2] = MSW(sns_phys_address);
2239 mcp->mb[3] = LSW(sns_phys_address);
2240 mcp->mb[6] = MSW(MSD(sns_phys_address));
2241 mcp->mb[7] = LSW(MSD(sns_phys_address));
2242 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2243 mcp->in_mb = MBX_0|MBX_1;
2244 mcp->buf_size = buf_size;
2245 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002246 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2247 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 if (rval != QLA_SUCCESS) {
2250 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002251 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2252 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2253 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 } else {
2255 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002256 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2257 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 }
2259
2260 return rval;
2261}
2262
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002263int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002264qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002265 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2266{
2267 int rval;
2268
2269 struct logio_entry_24xx *lg;
2270 dma_addr_t lg_dma;
2271 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002272 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002273 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002274
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002275 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2276 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002277
Michael Hernandezd7459522016-12-12 14:40:07 -08002278 if (vha->vp_idx && vha->qpair)
2279 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002280 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002281 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002282
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002283 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002284 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002285 ql_log(ql_log_warn, vha, 0x1062,
2286 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002287 return QLA_MEMORY_ALLOC_FAILED;
2288 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002289
2290 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2291 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002292 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002293 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002294 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002295 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002296 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002297 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002298 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002299 lg->port_id[0] = al_pa;
2300 lg->port_id[1] = area;
2301 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002302 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002303 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2304 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002305 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002306 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2307 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002308 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002309 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2310 "Failed to complete IOCB -- error status (%x).\n",
2311 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002312 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002313 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002314 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2315 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2316
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002317 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2318 "Failed to complete IOCB -- completion status (%x) "
2319 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2320 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002321
2322 switch (iop[0]) {
2323 case LSC_SCODE_PORTID_USED:
2324 mb[0] = MBS_PORT_ID_USED;
2325 mb[1] = LSW(iop[1]);
2326 break;
2327 case LSC_SCODE_NPORT_USED:
2328 mb[0] = MBS_LOOP_ID_USED;
2329 break;
2330 case LSC_SCODE_NOLINK:
2331 case LSC_SCODE_NOIOCB:
2332 case LSC_SCODE_NOXCB:
2333 case LSC_SCODE_CMD_FAILED:
2334 case LSC_SCODE_NOFABRIC:
2335 case LSC_SCODE_FW_NOT_READY:
2336 case LSC_SCODE_NOT_LOGGED_IN:
2337 case LSC_SCODE_NOPCB:
2338 case LSC_SCODE_ELS_REJECT:
2339 case LSC_SCODE_CMD_PARAM_ERR:
2340 case LSC_SCODE_NONPORT:
2341 case LSC_SCODE_LOGGED_IN:
2342 case LSC_SCODE_NOFLOGI_ACC:
2343 default:
2344 mb[0] = MBS_COMMAND_ERROR;
2345 break;
2346 }
2347 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002348 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2349 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002350
2351 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2352
2353 mb[0] = MBS_COMMAND_COMPLETE;
2354 mb[1] = 0;
2355 if (iop[0] & BIT_4) {
2356 if (iop[0] & BIT_8)
2357 mb[1] |= BIT_1;
2358 } else
2359 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002360
2361 /* Passback COS information. */
2362 mb[10] = 0;
2363 if (lg->io_parameter[7] || lg->io_parameter[8])
2364 mb[10] |= BIT_0; /* Class 2. */
2365 if (lg->io_parameter[9] || lg->io_parameter[10])
2366 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002367 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002368 mb[10] |= BIT_7; /* Confirmed Completion
2369 * Allowed
2370 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002371 }
2372
2373 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2374
2375 return rval;
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378/*
2379 * qla2x00_login_fabric
2380 * Issue login fabric port mailbox command.
2381 *
2382 * Input:
2383 * ha = adapter block pointer.
2384 * loop_id = device loop ID.
2385 * domain = device domain.
2386 * area = device area.
2387 * al_pa = device AL_PA.
2388 * status = pointer for return status.
2389 * opt = command options.
2390 * TARGET_QUEUE_LOCK must be released.
2391 * ADAPTER_STATE_LOCK must be released.
2392 *
2393 * Returns:
2394 * qla2x00 local function return status code.
2395 *
2396 * Context:
2397 * Kernel context.
2398 */
2399int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002400qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2402{
2403 int rval;
2404 mbx_cmd_t mc;
2405 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002406 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2409 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
2411 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2412 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2413 if (HAS_EXTENDED_IDS(ha)) {
2414 mcp->mb[1] = loop_id;
2415 mcp->mb[10] = opt;
2416 mcp->out_mb |= MBX_10;
2417 } else {
2418 mcp->mb[1] = (loop_id << 8) | opt;
2419 }
2420 mcp->mb[2] = domain;
2421 mcp->mb[3] = area << 8 | al_pa;
2422
2423 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2424 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2425 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002426 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 /* Return mailbox statuses. */
2429 if (mb != NULL) {
2430 mb[0] = mcp->mb[0];
2431 mb[1] = mcp->mb[1];
2432 mb[2] = mcp->mb[2];
2433 mb[6] = mcp->mb[6];
2434 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002435 /* COS retrieved from Get-Port-Database mailbox command. */
2436 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 }
2438
2439 if (rval != QLA_SUCCESS) {
2440 /* RLU tmp code: need to change main mailbox_command function to
2441 * return ok even when the mailbox completion value is not
2442 * SUCCESS. The caller needs to be responsible to interpret
2443 * the return values of this mailbox command if we're not
2444 * to change too much of the existing code.
2445 */
2446 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2447 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2448 mcp->mb[0] == 0x4006)
2449 rval = QLA_SUCCESS;
2450
2451 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002452 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2453 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2454 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 } else {
2456 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002457 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2458 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 }
2460
2461 return rval;
2462}
2463
2464/*
2465 * qla2x00_login_local_device
2466 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002467 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 * Input:
2469 * ha = adapter block pointer.
2470 * loop_id = device loop ID.
2471 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002472 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 * Returns:
2474 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002475 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 * Context:
2477 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002478 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 */
2480int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002481qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 uint16_t *mb_ret, uint8_t opt)
2483{
2484 int rval;
2485 mbx_cmd_t mc;
2486 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002487 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002489 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2490 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002491
Andrew Vasqueze4289242007-07-19 15:05:56 -07002492 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002493 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002494 fcport->d_id.b.domain, fcport->d_id.b.area,
2495 fcport->d_id.b.al_pa, mb_ret, opt);
2496
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2498 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002499 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002501 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 mcp->mb[2] = opt;
2503 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2504 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2505 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2506 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002507 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509 /* Return mailbox statuses. */
2510 if (mb_ret != NULL) {
2511 mb_ret[0] = mcp->mb[0];
2512 mb_ret[1] = mcp->mb[1];
2513 mb_ret[6] = mcp->mb[6];
2514 mb_ret[7] = mcp->mb[7];
2515 }
2516
2517 if (rval != QLA_SUCCESS) {
2518 /* AV tmp code: need to change main mailbox_command function to
2519 * return ok even when the mailbox completion value is not
2520 * SUCCESS. The caller needs to be responsible to interpret
2521 * the return values of this mailbox command if we're not
2522 * to change too much of the existing code.
2523 */
2524 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2525 rval = QLA_SUCCESS;
2526
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002527 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2528 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2529 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 } else {
2531 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002532 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2533 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 }
2535
2536 return (rval);
2537}
2538
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002539int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002540qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002541 uint8_t area, uint8_t al_pa)
2542{
2543 int rval;
2544 struct logio_entry_24xx *lg;
2545 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002546 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002547 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002548
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002549 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2550 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002551
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002552 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002553 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002554 ql_log(ql_log_warn, vha, 0x106e,
2555 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002556 return QLA_MEMORY_ALLOC_FAILED;
2557 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002558
Michael Hernandezd7459522016-12-12 14:40:07 -08002559 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002560 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2561 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002562 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002563 lg->nport_handle = cpu_to_le16(loop_id);
2564 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002565 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002566 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002567 lg->port_id[0] = al_pa;
2568 lg->port_id[1] = area;
2569 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002570 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002571 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2572 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002573 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002574 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2575 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002576 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002577 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2578 "Failed to complete IOCB -- error status (%x).\n",
2579 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002580 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002581 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002582 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2583 "Failed to complete IOCB -- completion status (%x) "
2584 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002585 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002586 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002587 } else {
2588 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002589 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2590 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002591 }
2592
2593 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2594
2595 return rval;
2596}
2597
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598/*
2599 * qla2x00_fabric_logout
2600 * Issue logout fabric port mailbox command.
2601 *
2602 * Input:
2603 * ha = adapter block pointer.
2604 * loop_id = device loop ID.
2605 * TARGET_QUEUE_LOCK must be released.
2606 * ADAPTER_STATE_LOCK must be released.
2607 *
2608 * Returns:
2609 * qla2x00 local function return status code.
2610 *
2611 * Context:
2612 * Kernel context.
2613 */
2614int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002615qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002616 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617{
2618 int rval;
2619 mbx_cmd_t mc;
2620 mbx_cmd_t *mcp = &mc;
2621
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002622 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2623 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
2625 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2626 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002627 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 mcp->mb[1] = loop_id;
2629 mcp->mb[10] = 0;
2630 mcp->out_mb |= MBX_10;
2631 } else {
2632 mcp->mb[1] = loop_id << 8;
2633 }
2634
2635 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002636 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002638 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
2640 if (rval != QLA_SUCCESS) {
2641 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002642 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2643 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 } else {
2645 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002646 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2647 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 }
2649
2650 return rval;
2651}
2652
2653/*
2654 * qla2x00_full_login_lip
2655 * Issue full login LIP mailbox command.
2656 *
2657 * Input:
2658 * ha = adapter block pointer.
2659 * TARGET_QUEUE_LOCK must be released.
2660 * ADAPTER_STATE_LOCK must be released.
2661 *
2662 * Returns:
2663 * qla2x00 local function return status code.
2664 *
2665 * Context:
2666 * Kernel context.
2667 */
2668int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002669qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
2671 int rval;
2672 mbx_cmd_t mc;
2673 mbx_cmd_t *mcp = &mc;
2674
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002675 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2676 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
2678 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002679 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002680 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 mcp->mb[3] = 0;
2682 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2683 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002684 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002686 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
2688 if (rval != QLA_SUCCESS) {
2689 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002690 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 } else {
2692 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002693 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2694 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 }
2696
2697 return rval;
2698}
2699
2700/*
2701 * qla2x00_get_id_list
2702 *
2703 * Input:
2704 * ha = adapter block pointer.
2705 *
2706 * Returns:
2707 * qla2x00 local function return status code.
2708 *
2709 * Context:
2710 * Kernel context.
2711 */
2712int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002713qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 uint16_t *entries)
2715{
2716 int rval;
2717 mbx_cmd_t mc;
2718 mbx_cmd_t *mcp = &mc;
2719
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002720 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2721 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
2723 if (id_list == NULL)
2724 return QLA_FUNCTION_FAILED;
2725
2726 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002727 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002728 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002729 mcp->mb[2] = MSW(id_list_dma);
2730 mcp->mb[3] = LSW(id_list_dma);
2731 mcp->mb[6] = MSW(MSD(id_list_dma));
2732 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002733 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002734 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002735 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002736 } else {
2737 mcp->mb[1] = MSW(id_list_dma);
2738 mcp->mb[2] = LSW(id_list_dma);
2739 mcp->mb[3] = MSW(MSD(id_list_dma));
2740 mcp->mb[6] = LSW(MSD(id_list_dma));
2741 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002744 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002746 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748 if (rval != QLA_SUCCESS) {
2749 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002750 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 } else {
2752 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002753 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2754 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 }
2756
2757 return rval;
2758}
2759
2760/*
2761 * qla2x00_get_resource_cnts
2762 * Get current firmware resource counts.
2763 *
2764 * Input:
2765 * ha = adapter block pointer.
2766 *
2767 * Returns:
2768 * qla2x00 local function return status code.
2769 *
2770 * Context:
2771 * Kernel context.
2772 */
2773int
Quinn Tran03e8c682015-12-17 14:56:59 -05002774qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775{
Quinn Tran03e8c682015-12-17 14:56:59 -05002776 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 int rval;
2778 mbx_cmd_t mc;
2779 mbx_cmd_t *mcp = &mc;
2780
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002781 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2782 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2785 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002786 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 -05002787 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002788 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002789 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002791 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
2793 if (rval != QLA_SUCCESS) {
2794 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002795 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2796 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002798 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002799 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2800 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2801 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2802 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Quinn Tran03e8c682015-12-17 14:56:59 -05002804 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2805 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2806 ha->cur_fw_xcb_count = mcp->mb[3];
2807 ha->orig_fw_xcb_count = mcp->mb[6];
2808 ha->cur_fw_iocb_count = mcp->mb[7];
2809 ha->orig_fw_iocb_count = mcp->mb[10];
2810 if (ha->flags.npiv_supported)
2811 ha->max_npiv_vports = mcp->mb[11];
2812 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2813 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 }
2815
2816 return (rval);
2817}
2818
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819/*
2820 * qla2x00_get_fcal_position_map
2821 * Get FCAL (LILP) position map using mailbox command
2822 *
2823 * Input:
2824 * ha = adapter state pointer.
2825 * pos_map = buffer pointer (can be NULL).
2826 *
2827 * Returns:
2828 * qla2x00 local function return status code.
2829 *
2830 * Context:
2831 * Kernel context.
2832 */
2833int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002834qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835{
2836 int rval;
2837 mbx_cmd_t mc;
2838 mbx_cmd_t *mcp = &mc;
2839 char *pmap;
2840 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002841 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002843 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2844 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002846 pmap = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002848 ql_log(ql_log_warn, vha, 0x1080,
2849 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 return QLA_MEMORY_ALLOC_FAILED;
2851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
2853 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2854 mcp->mb[2] = MSW(pmap_dma);
2855 mcp->mb[3] = LSW(pmap_dma);
2856 mcp->mb[6] = MSW(MSD(pmap_dma));
2857 mcp->mb[7] = LSW(MSD(pmap_dma));
2858 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2859 mcp->in_mb = MBX_1|MBX_0;
2860 mcp->buf_size = FCAL_MAP_SIZE;
2861 mcp->flags = MBX_DMA_IN;
2862 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002863 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
2865 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002866 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002867 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2868 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2869 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2870 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
2872 if (pos_map)
2873 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2874 }
2875 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2876
2877 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002878 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002880 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2881 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 }
2883
2884 return rval;
2885}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002886
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002887/*
2888 * qla2x00_get_link_status
2889 *
2890 * Input:
2891 * ha = adapter block pointer.
2892 * loop_id = device loop ID.
2893 * ret_buf = pointer to link status return buffer.
2894 *
2895 * Returns:
2896 * 0 = success.
2897 * BIT_0 = mem alloc error.
2898 * BIT_1 = mailbox error.
2899 */
2900int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002901qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002902 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002903{
2904 int rval;
2905 mbx_cmd_t mc;
2906 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002907 uint32_t *iter = (void *)stats;
2908 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002909 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002910
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002911 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2912 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002913
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002914 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002915 mcp->mb[2] = MSW(LSD(stats_dma));
2916 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002917 mcp->mb[6] = MSW(MSD(stats_dma));
2918 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002919 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2920 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002921 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002922 mcp->mb[1] = loop_id;
2923 mcp->mb[4] = 0;
2924 mcp->mb[10] = 0;
2925 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2926 mcp->in_mb |= MBX_1;
2927 } else if (HAS_EXTENDED_IDS(ha)) {
2928 mcp->mb[1] = loop_id;
2929 mcp->mb[10] = 0;
2930 mcp->out_mb |= MBX_10|MBX_1;
2931 } else {
2932 mcp->mb[1] = loop_id << 8;
2933 mcp->out_mb |= MBX_1;
2934 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002935 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002936 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002937 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002938
2939 if (rval == QLA_SUCCESS) {
2940 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002941 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2942 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002943 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002944 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002945 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002946 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2947 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002948 for ( ; dwords--; iter++)
2949 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002950 }
2951 } else {
2952 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002953 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002954 }
2955
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002956 return rval;
2957}
2958
2959int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002960qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07002961 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002962{
2963 int rval;
2964 mbx_cmd_t mc;
2965 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002966 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002967
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002968 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2969 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002970
Quinn Tran15f30a52017-03-15 09:48:52 -07002971 memset(&mc, 0, sizeof(mc));
2972 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
2973 mc.mb[2] = MSW(stats_dma);
2974 mc.mb[3] = LSW(stats_dma);
2975 mc.mb[6] = MSW(MSD(stats_dma));
2976 mc.mb[7] = LSW(MSD(stats_dma));
2977 mc.mb[8] = sizeof(struct link_statistics) / 4;
2978 mc.mb[9] = cpu_to_le16(vha->vp_idx);
2979 mc.mb[10] = cpu_to_le16(options);
2980
2981 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002982
2983 if (rval == QLA_SUCCESS) {
2984 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002985 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2986 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002987 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002988 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002989 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2990 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002991 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002992 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002993 iter = &stats->link_fail_cnt;
2994 for ( ; dwords--; iter++)
2995 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002996 }
2997 } else {
2998 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002999 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003000 }
3001
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003002 return rval;
3003}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003004
3005int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003006qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003007{
3008 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003009 unsigned long flags = 0;
3010
3011 struct abort_entry_24xx *abt;
3012 dma_addr_t abt_dma;
3013 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003014 fc_port_t *fcport = sp->fcport;
3015 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003016 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003017 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003018
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003019 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
3020 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003021
Michael Hernandezd7459522016-12-12 14:40:07 -08003022 if (vha->flags.qpairs_available && sp->qpair)
3023 req = sp->qpair->req;
3024
Armen Baloyan4440e462014-02-26 04:15:18 -05003025 if (ql2xasynctmfenable)
3026 return qla24xx_async_abort_command(sp);
3027
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003028 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003029 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003030 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003031 break;
3032 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003033 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003034 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003035 /* Command not found. */
3036 return QLA_FUNCTION_FAILED;
3037 }
3038
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003039 abt = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003040 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003041 ql_log(ql_log_warn, vha, 0x108d,
3042 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003043 return QLA_MEMORY_ALLOC_FAILED;
3044 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003045
3046 abt->entry_type = ABORT_IOCB_TYPE;
3047 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003048 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003049 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07003050 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003051 abt->port_id[0] = fcport->d_id.b.al_pa;
3052 abt->port_id[1] = fcport->d_id.b.area;
3053 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003054 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003055
3056 abt->req_que_no = cpu_to_le16(req->id);
3057
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003058 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003059 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003060 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3061 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003062 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003063 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3064 "Failed to complete IOCB -- error status (%x).\n",
3065 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003066 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003067 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003068 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3069 "Failed to complete IOCB -- completion status (%x).\n",
3070 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003071 if (abt->nport_handle == CS_IOCB_ERROR)
3072 rval = QLA_FUNCTION_PARAMETER_ERROR;
3073 else
3074 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003075 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003076 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3077 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003078 }
3079
3080 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3081
3082 return rval;
3083}
3084
3085struct tsk_mgmt_cmd {
3086 union {
3087 struct tsk_mgmt_entry tsk;
3088 struct sts_entry_24xx sts;
3089 } p;
3090};
3091
Andrew Vasquez523ec772008-04-03 13:13:24 -07003092static int
3093__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003094 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003095{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003096 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003097 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003098 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003099 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003100 scsi_qla_host_t *vha;
3101 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003102 struct req_que *req;
3103 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003104 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003105
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003106 vha = fcport->vha;
3107 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003108 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003109
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003110 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3111 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003112
Michael Hernandezd7459522016-12-12 14:40:07 -08003113 if (vha->vp_idx && vha->qpair) {
3114 /* NPIV port */
3115 qpair = vha->qpair;
3116 rsp = qpair->rsp;
3117 req = qpair->req;
3118 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003119 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003120 }
3121
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003122 tsk = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003123 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003124 ql_log(ql_log_warn, vha, 0x1093,
3125 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003126 return QLA_MEMORY_ALLOC_FAILED;
3127 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003128
3129 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3130 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003131 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003132 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003133 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003134 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003135 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3136 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3137 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003138 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003139 if (type == TCF_LUN_RESET) {
3140 int_to_scsilun(l, &tsk->p.tsk.lun);
3141 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3142 sizeof(tsk->p.tsk.lun));
3143 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003144
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003145 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003146 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003147 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003148 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3149 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003150 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003151 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3152 "Failed to complete IOCB -- error status (%x).\n",
3153 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003154 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003155 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003156 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3157 "Failed to complete IOCB -- completion status (%x).\n",
3158 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003159 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003160 } else if (le16_to_cpu(sts->scsi_status) &
3161 SS_RESPONSE_INFO_LEN_VALID) {
3162 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003163 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003164 "Ignoring inconsistent data length -- not enough "
3165 "response info (%d).\n",
3166 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003167 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003168 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3169 "Failed to complete IOCB -- response (%x).\n",
3170 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003171 rval = QLA_FUNCTION_FAILED;
3172 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003173 }
3174
3175 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003176 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003177 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3178 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003179 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3180 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003181 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003182 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3183 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003184 }
3185
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003186 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003187
3188 return rval;
3189}
3190
Andrew Vasquez523ec772008-04-03 13:13:24 -07003191int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003192qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003193{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003194 struct qla_hw_data *ha = fcport->vha->hw;
3195
3196 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3197 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3198
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003199 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003200}
3201
3202int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003203qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003204{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003205 struct qla_hw_data *ha = fcport->vha->hw;
3206
3207 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3208 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3209
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003210 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003211}
3212
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003213int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003214qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003215{
3216 int rval;
3217 mbx_cmd_t mc;
3218 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003219 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003220
Andrew Vasquez68af0812008-05-12 22:21:13 -07003221 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003222 return QLA_FUNCTION_FAILED;
3223
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003224 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3225 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003226
3227 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3228 mcp->out_mb = MBX_0;
3229 mcp->in_mb = MBX_0;
3230 mcp->tov = 5;
3231 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003232 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003233
3234 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003235 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003236 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003237 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3238 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003239 }
3240
3241 return rval;
3242}
3243
Joe Carnucciodb64e932013-10-30 03:38:18 -04003244int
3245qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3246{
3247 int rval;
3248 mbx_cmd_t mc;
3249 mbx_cmd_t *mcp = &mc;
3250
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003251 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3252 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003253 return QLA_FUNCTION_FAILED;
3254
3255 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3256 "Entered %s.\n", __func__);
3257
3258 mcp->mb[0] = MBC_WRITE_SERDES;
3259 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003260 if (IS_QLA2031(vha->hw))
3261 mcp->mb[2] = data & 0xff;
3262 else
3263 mcp->mb[2] = data;
3264
Joe Carnucciodb64e932013-10-30 03:38:18 -04003265 mcp->mb[3] = 0;
3266 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3267 mcp->in_mb = MBX_0;
3268 mcp->tov = MBX_TOV_SECONDS;
3269 mcp->flags = 0;
3270 rval = qla2x00_mailbox_command(vha, mcp);
3271
3272 if (rval != QLA_SUCCESS) {
3273 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3274 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3275 } else {
3276 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3277 "Done %s.\n", __func__);
3278 }
3279
3280 return rval;
3281}
3282
3283int
3284qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3285{
3286 int rval;
3287 mbx_cmd_t mc;
3288 mbx_cmd_t *mcp = &mc;
3289
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003290 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3291 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003292 return QLA_FUNCTION_FAILED;
3293
3294 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3295 "Entered %s.\n", __func__);
3296
3297 mcp->mb[0] = MBC_READ_SERDES;
3298 mcp->mb[1] = addr;
3299 mcp->mb[3] = 0;
3300 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3301 mcp->in_mb = MBX_1|MBX_0;
3302 mcp->tov = MBX_TOV_SECONDS;
3303 mcp->flags = 0;
3304 rval = qla2x00_mailbox_command(vha, mcp);
3305
Andrew Vasquez064135e2015-04-09 15:00:02 -04003306 if (IS_QLA2031(vha->hw))
3307 *data = mcp->mb[1] & 0xff;
3308 else
3309 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003310
3311 if (rval != QLA_SUCCESS) {
3312 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3313 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3314 } else {
3315 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3316 "Done %s.\n", __func__);
3317 }
3318
3319 return rval;
3320}
3321
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003322int
3323qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3324{
3325 int rval;
3326 mbx_cmd_t mc;
3327 mbx_cmd_t *mcp = &mc;
3328
3329 if (!IS_QLA8044(vha->hw))
3330 return QLA_FUNCTION_FAILED;
3331
Quinn Tran83548fe2017-06-02 09:12:01 -07003332 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003333 "Entered %s.\n", __func__);
3334
3335 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3336 mcp->mb[1] = HCS_WRITE_SERDES;
3337 mcp->mb[3] = LSW(addr);
3338 mcp->mb[4] = MSW(addr);
3339 mcp->mb[5] = LSW(data);
3340 mcp->mb[6] = MSW(data);
3341 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3342 mcp->in_mb = MBX_0;
3343 mcp->tov = MBX_TOV_SECONDS;
3344 mcp->flags = 0;
3345 rval = qla2x00_mailbox_command(vha, mcp);
3346
3347 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003348 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003349 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3350 } else {
3351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3352 "Done %s.\n", __func__);
3353 }
3354
3355 return rval;
3356}
3357
3358int
3359qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3360{
3361 int rval;
3362 mbx_cmd_t mc;
3363 mbx_cmd_t *mcp = &mc;
3364
3365 if (!IS_QLA8044(vha->hw))
3366 return QLA_FUNCTION_FAILED;
3367
3368 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3369 "Entered %s.\n", __func__);
3370
3371 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3372 mcp->mb[1] = HCS_READ_SERDES;
3373 mcp->mb[3] = LSW(addr);
3374 mcp->mb[4] = MSW(addr);
3375 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3376 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3377 mcp->tov = MBX_TOV_SECONDS;
3378 mcp->flags = 0;
3379 rval = qla2x00_mailbox_command(vha, mcp);
3380
3381 *data = mcp->mb[2] << 16 | mcp->mb[1];
3382
3383 if (rval != QLA_SUCCESS) {
3384 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3385 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3386 } else {
3387 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3388 "Done %s.\n", __func__);
3389 }
3390
3391 return rval;
3392}
3393
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003394/**
3395 * qla2x00_set_serdes_params() -
3396 * @ha: HA context
3397 *
3398 * Returns
3399 */
3400int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003401qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003402 uint16_t sw_em_2g, uint16_t sw_em_4g)
3403{
3404 int rval;
3405 mbx_cmd_t mc;
3406 mbx_cmd_t *mcp = &mc;
3407
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3409 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003410
3411 mcp->mb[0] = MBC_SERDES_PARAMS;
3412 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003413 mcp->mb[2] = sw_em_1g | BIT_15;
3414 mcp->mb[3] = sw_em_2g | BIT_15;
3415 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003416 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3417 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003418 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003419 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003420 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003421
3422 if (rval != QLA_SUCCESS) {
3423 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003424 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3425 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003426 } else {
3427 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003428 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3429 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003430 }
3431
3432 return rval;
3433}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003434
3435int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003436qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003437{
3438 int rval;
3439 mbx_cmd_t mc;
3440 mbx_cmd_t *mcp = &mc;
3441
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003442 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003443 return QLA_FUNCTION_FAILED;
3444
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003445 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3446 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003447
3448 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003449 mcp->mb[1] = 0;
3450 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003451 mcp->in_mb = MBX_0;
3452 mcp->tov = 5;
3453 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003454 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003455
3456 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003457 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003458 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3459 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003460 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003461 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3462 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003463 }
3464
3465 return rval;
3466}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003467
3468int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003469qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003470 uint16_t buffers)
3471{
3472 int rval;
3473 mbx_cmd_t mc;
3474 mbx_cmd_t *mcp = &mc;
3475
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003476 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3477 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003478
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003479 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003480 return QLA_FUNCTION_FAILED;
3481
Andrew Vasquez85880802009-12-15 21:29:46 -08003482 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3483 return QLA_FUNCTION_FAILED;
3484
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003485 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003486 mcp->mb[1] = TC_EFT_ENABLE;
3487 mcp->mb[2] = LSW(eft_dma);
3488 mcp->mb[3] = MSW(eft_dma);
3489 mcp->mb[4] = LSW(MSD(eft_dma));
3490 mcp->mb[5] = MSW(MSD(eft_dma));
3491 mcp->mb[6] = buffers;
3492 mcp->mb[7] = TC_AEN_DISABLE;
3493 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 -07003494 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003495 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003496 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003497 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003498 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003499 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3500 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3501 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003502 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3504 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003505 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003506
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003507 return rval;
3508}
3509
3510int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003511qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003512{
3513 int rval;
3514 mbx_cmd_t mc;
3515 mbx_cmd_t *mcp = &mc;
3516
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003517 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3518 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003519
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003520 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003521 return QLA_FUNCTION_FAILED;
3522
Andrew Vasquez85880802009-12-15 21:29:46 -08003523 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3524 return QLA_FUNCTION_FAILED;
3525
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003526 mcp->mb[0] = MBC_TRACE_CONTROL;
3527 mcp->mb[1] = TC_EFT_DISABLE;
3528 mcp->out_mb = MBX_1|MBX_0;
3529 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003530 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003531 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003532 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003533 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003534 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3535 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3536 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003537 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003538 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3539 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003540 }
3541
3542 return rval;
3543}
3544
Andrew Vasquez88729e52006-06-23 16:10:50 -07003545int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003546qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003547 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3548{
3549 int rval;
3550 mbx_cmd_t mc;
3551 mbx_cmd_t *mcp = &mc;
3552
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003553 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3554 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003555
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003556 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003557 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003558 return QLA_FUNCTION_FAILED;
3559
Andrew Vasquez85880802009-12-15 21:29:46 -08003560 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3561 return QLA_FUNCTION_FAILED;
3562
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003563 mcp->mb[0] = MBC_TRACE_CONTROL;
3564 mcp->mb[1] = TC_FCE_ENABLE;
3565 mcp->mb[2] = LSW(fce_dma);
3566 mcp->mb[3] = MSW(fce_dma);
3567 mcp->mb[4] = LSW(MSD(fce_dma));
3568 mcp->mb[5] = MSW(MSD(fce_dma));
3569 mcp->mb[6] = buffers;
3570 mcp->mb[7] = TC_AEN_DISABLE;
3571 mcp->mb[8] = 0;
3572 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3573 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3574 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3575 MBX_1|MBX_0;
3576 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003577 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003578 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003579 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003580 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003581 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3582 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3583 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003584 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003585 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3586 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003587
3588 if (mb)
3589 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3590 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003591 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003592 }
3593
3594 return rval;
3595}
3596
3597int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003598qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003599{
3600 int rval;
3601 mbx_cmd_t mc;
3602 mbx_cmd_t *mcp = &mc;
3603
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003604 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3605 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003606
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003607 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003608 return QLA_FUNCTION_FAILED;
3609
Andrew Vasquez85880802009-12-15 21:29:46 -08003610 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3611 return QLA_FUNCTION_FAILED;
3612
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003613 mcp->mb[0] = MBC_TRACE_CONTROL;
3614 mcp->mb[1] = TC_FCE_DISABLE;
3615 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3616 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3617 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3618 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003619 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003620 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003621 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003622 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003623 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3624 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3625 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003626 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3628 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003629
3630 if (wr)
3631 *wr = (uint64_t) mcp->mb[5] << 48 |
3632 (uint64_t) mcp->mb[4] << 32 |
3633 (uint64_t) mcp->mb[3] << 16 |
3634 (uint64_t) mcp->mb[2];
3635 if (rd)
3636 *rd = (uint64_t) mcp->mb[9] << 48 |
3637 (uint64_t) mcp->mb[8] << 32 |
3638 (uint64_t) mcp->mb[7] << 16 |
3639 (uint64_t) mcp->mb[6];
3640 }
3641
3642 return rval;
3643}
3644
3645int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003646qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3647 uint16_t *port_speed, uint16_t *mb)
3648{
3649 int rval;
3650 mbx_cmd_t mc;
3651 mbx_cmd_t *mcp = &mc;
3652
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003653 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3654 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003655
Giridhar Malavali6e980162010-03-19 17:03:58 -07003656 if (!IS_IIDMA_CAPABLE(vha->hw))
3657 return QLA_FUNCTION_FAILED;
3658
Giridhar Malavali6e980162010-03-19 17:03:58 -07003659 mcp->mb[0] = MBC_PORT_PARAMS;
3660 mcp->mb[1] = loop_id;
3661 mcp->mb[2] = mcp->mb[3] = 0;
3662 mcp->mb[9] = vha->vp_idx;
3663 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3664 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3665 mcp->tov = MBX_TOV_SECONDS;
3666 mcp->flags = 0;
3667 rval = qla2x00_mailbox_command(vha, mcp);
3668
3669 /* Return mailbox statuses. */
3670 if (mb != NULL) {
3671 mb[0] = mcp->mb[0];
3672 mb[1] = mcp->mb[1];
3673 mb[3] = mcp->mb[3];
3674 }
3675
3676 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003677 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003678 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003679 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3680 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003681 if (port_speed)
3682 *port_speed = mcp->mb[3];
3683 }
3684
3685 return rval;
3686}
3687
3688int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003689qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003690 uint16_t port_speed, uint16_t *mb)
3691{
3692 int rval;
3693 mbx_cmd_t mc;
3694 mbx_cmd_t *mcp = &mc;
3695
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003696 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3697 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003698
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003699 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003700 return QLA_FUNCTION_FAILED;
3701
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003702 mcp->mb[0] = MBC_PORT_PARAMS;
3703 mcp->mb[1] = loop_id;
3704 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003705 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003706 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3707 else
3708 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3709 mcp->mb[9] = vha->vp_idx;
3710 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3711 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003712 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003713 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003714 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003715
3716 /* Return mailbox statuses. */
3717 if (mb != NULL) {
3718 mb[0] = mcp->mb[0];
3719 mb[1] = mcp->mb[1];
3720 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003721 }
3722
3723 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003724 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3725 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003726 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003727 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3728 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003729 }
3730
3731 return rval;
3732}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003733
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003734void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003735qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003736 struct vp_rpt_id_entry_24xx *rptid_entry)
3737{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003738 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003739 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003740 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003741 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003742 port_id_t id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08003743 struct fc_port *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003744
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3746 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003747
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003748 if (rptid_entry->entry_status != 0)
3749 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003750
Quinn Tran482c9dc2017-03-15 09:48:54 -07003751 id.b.domain = rptid_entry->port_id[2];
3752 id.b.area = rptid_entry->port_id[1];
3753 id.b.al_pa = rptid_entry->port_id[0];
3754 id.b.rsvd_1 = 0;
3755
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003756 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003757 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003758 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003759 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003760 "VPs acquired %d.\n", rptid_entry->vp_setup,
3761 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003762 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003763 "Primary port id %02x%02x%02x.\n",
3764 rptid_entry->port_id[2], rptid_entry->port_id[1],
3765 rptid_entry->port_id[0]);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003766 ha->current_topology = ISP_CFG_NL;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003767 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003768
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003769 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003770 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003771 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003772 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003773 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3774 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003775 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003776 rptid_entry->port_id[0]);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003777 ql_dbg(ql_dbg_async, vha, 0x5075,
3778 "Format 1: Remote WWPN %8phC.\n",
3779 rptid_entry->u.f1.port_name);
3780
3781 ql_dbg(ql_dbg_async, vha, 0x5075,
3782 "Format 1: WWPN %8phC.\n",
3783 vha->port_name);
3784
3785 /* N2N. direct connect */
3786 if (IS_QLA27XX(ha) &&
3787 ((rptid_entry->u.f1.flags>>1) & 0x7) == 2) {
3788 /* if our portname is higher then initiate N2N login */
3789 if (wwn_to_u64(vha->port_name) >
3790 wwn_to_u64(rptid_entry->u.f1.port_name)) {
3791 // ??? qlt_update_host_map(vha, id);
3792 vha->n2n_id = 0x1;
3793 ql_dbg(ql_dbg_async, vha, 0x5075,
3794 "Format 1: Setting n2n_update_needed for id %d\n",
3795 vha->n2n_id);
3796 } else {
3797 ql_dbg(ql_dbg_async, vha, 0x5075,
3798 "Format 1: Remote login - Waiting for WWPN %8phC.\n",
3799 rptid_entry->u.f1.port_name);
3800 }
3801
3802 memcpy(vha->n2n_port_name, rptid_entry->u.f1.port_name,
3803 WWN_SIZE);
3804 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
3805 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3806 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3807 return;
3808 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003809
Quinn Tran9cd883f2017-12-28 12:33:24 -08003810 ha->flags.gpsc_supported = 1;
3811 ha->current_topology = ISP_CFG_F;
Sawan Chandak969a6192016-01-27 12:03:32 -05003812 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003813 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003814
Quinn Tran41dc5292017-01-19 22:28:03 -08003815 if (rptid_entry->vp_idx == 0) {
3816 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3817 /* FA-WWN is only for physical port */
3818 if (qla_ini_mode_enabled(vha) &&
3819 ha->flags.fawwpn_enabled &&
3820 (rptid_entry->u.f1.flags &
Sawan Chandakfcc5b5c2017-08-23 15:05:02 -07003821 BIT_6)) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003822 memcpy(vha->port_name,
3823 rptid_entry->u.f1.port_name,
3824 WWN_SIZE);
3825 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003826
Quinn Tran482c9dc2017-03-15 09:48:54 -07003827 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003828 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003829
Quinn Tran41dc5292017-01-19 22:28:03 -08003830 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3831 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3832 } else {
3833 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3834 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3835 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3836 "Could not acquire ID for VP[%d].\n",
3837 rptid_entry->vp_idx);
3838 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003839 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003840
3841 found = 0;
3842 spin_lock_irqsave(&ha->vport_slock, flags);
3843 list_for_each_entry(vp, &ha->vp_list, list) {
3844 if (rptid_entry->vp_idx == vp->vp_idx) {
3845 found = 1;
3846 break;
3847 }
3848 }
3849 spin_unlock_irqrestore(&ha->vport_slock, flags);
3850
3851 if (!found)
3852 return;
3853
Quinn Tran482c9dc2017-03-15 09:48:54 -07003854 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003855
3856 /*
3857 * Cannot configure here as we are still sitting on the
3858 * response queue. Handle it in dpc context.
3859 */
3860 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3861 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3862 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003863 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003864 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003865 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003866 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003867 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08003868 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3869 rptid_entry->port_id[2], rptid_entry->port_id[1],
3870 rptid_entry->port_id[0]);
3871
Quinn Tran83548fe2017-06-02 09:12:01 -07003872 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08003873 "N2N: Remote WWPN %8phC.\n",
3874 rptid_entry->u.f2.port_name);
3875
3876 /* N2N. direct connect */
Quinn Tran9cd883f2017-12-28 12:33:24 -08003877 ha->current_topology = ISP_CFG_N;
3878 ha->flags.rida_fmt2 = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08003879 vha->d_id.b.domain = rptid_entry->port_id[2];
3880 vha->d_id.b.area = rptid_entry->port_id[1];
3881 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3882
3883 spin_lock_irqsave(&ha->vport_slock, flags);
3884 qlt_update_vp_map(vha, SET_AL_PA);
3885 spin_unlock_irqrestore(&ha->vport_slock, flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003886
3887 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3888 fcport->scan_state = QLA_FCPORT_SCAN;
3889 }
3890
3891 fcport = qla2x00_find_fcport_by_wwpn(vha,
3892 rptid_entry->u.f2.port_name, 1);
3893
3894 if (fcport) {
3895 fcport->plogi_nack_done_deadline = jiffies + HZ;
3896 fcport->scan_state = QLA_FCPORT_FOUND;
3897 switch (fcport->disc_state) {
3898 case DSC_DELETED:
3899 ql_dbg(ql_dbg_disc, vha, 0x210d,
3900 "%s %d %8phC login\n",
3901 __func__, __LINE__, fcport->port_name);
3902 qla24xx_fcport_handle_login(vha, fcport);
3903 break;
3904 case DSC_DELETE_PEND:
3905 break;
3906 default:
Quinn Trand8630bb2017-12-28 12:33:43 -08003907 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003908 break;
3909 }
3910 } else {
3911 id.b.al_pa = rptid_entry->u.f2.remote_nport_id[0];
3912 id.b.area = rptid_entry->u.f2.remote_nport_id[1];
3913 id.b.domain = rptid_entry->u.f2.remote_nport_id[2];
3914 qla24xx_post_newsess_work(vha, &id,
Quinn Trana4239942017-12-28 12:33:26 -08003915 rptid_entry->u.f2.port_name,
3916 rptid_entry->u.f2.node_name,
3917 NULL,
3918 FC4_TYPE_UNKNOWN);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003919 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003920 }
3921}
3922
3923/*
3924 * qla24xx_modify_vp_config
3925 * Change VP configuration for vha
3926 *
3927 * Input:
3928 * vha = adapter block pointer.
3929 *
3930 * Returns:
3931 * qla2xxx local function return status code.
3932 *
3933 * Context:
3934 * Kernel context.
3935 */
3936int
3937qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3938{
3939 int rval;
3940 struct vp_config_entry_24xx *vpmod;
3941 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003942 struct qla_hw_data *ha = vha->hw;
3943 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003944
3945 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003946
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003947 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3948 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003949
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003950 vpmod = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003951 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003952 ql_log(ql_log_warn, vha, 0x10bc,
3953 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003954 return QLA_MEMORY_ALLOC_FAILED;
3955 }
3956
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003957 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3958 vpmod->entry_count = 1;
3959 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3960 vpmod->vp_count = 1;
3961 vpmod->vp_index1 = vha->vp_idx;
3962 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003963
3964 qlt_modify_vp_config(vha, vpmod);
3965
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003966 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3967 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3968 vpmod->entry_count = 1;
3969
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003970 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003971 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003972 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3973 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003974 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003975 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3976 "Failed to complete IOCB -- error status (%x).\n",
3977 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003978 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003979 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003980 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3981 "Failed to complete IOCB -- completion status (%x).\n",
3982 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003983 rval = QLA_FUNCTION_FAILED;
3984 } else {
3985 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003986 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3987 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003988 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3989 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003990 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003991
3992 return rval;
3993}
3994
3995/*
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003996 * qla2x00_send_change_request
3997 * Receive or disable RSCN request from fabric controller
3998 *
3999 * Input:
4000 * ha = adapter block pointer
4001 * format = registration format:
4002 * 0 - Reserved
4003 * 1 - Fabric detected registration
4004 * 2 - N_port detected registration
4005 * 3 - Full registration
4006 * FF - clear registration
4007 * vp_idx = Virtual port index
4008 *
4009 * Returns:
4010 * qla2x00 local function return status code.
4011 *
4012 * Context:
4013 * Kernel Context
4014 */
4015
4016int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004017qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004018 uint16_t vp_idx)
4019{
4020 int rval;
4021 mbx_cmd_t mc;
4022 mbx_cmd_t *mcp = &mc;
4023
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004024 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
4025 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004026
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004027 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
4028 mcp->mb[1] = format;
4029 mcp->mb[9] = vp_idx;
4030 mcp->out_mb = MBX_9|MBX_1|MBX_0;
4031 mcp->in_mb = MBX_0|MBX_1;
4032 mcp->tov = MBX_TOV_SECONDS;
4033 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004034 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004035
4036 if (rval == QLA_SUCCESS) {
4037 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
4038 rval = BIT_1;
4039 }
4040 } else
4041 rval = BIT_1;
4042
4043 return rval;
4044}
Andrew Vasquez338c9162007-09-20 14:07:33 -07004045
4046int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004047qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07004048 uint32_t size)
4049{
4050 int rval;
4051 mbx_cmd_t mc;
4052 mbx_cmd_t *mcp = &mc;
4053
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004054 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
4055 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004056
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004057 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004058 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
4059 mcp->mb[8] = MSW(addr);
4060 mcp->out_mb = MBX_8|MBX_0;
4061 } else {
4062 mcp->mb[0] = MBC_DUMP_RISC_RAM;
4063 mcp->out_mb = MBX_0;
4064 }
4065 mcp->mb[1] = LSW(addr);
4066 mcp->mb[2] = MSW(req_dma);
4067 mcp->mb[3] = LSW(req_dma);
4068 mcp->mb[6] = MSW(MSD(req_dma));
4069 mcp->mb[7] = LSW(MSD(req_dma));
4070 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004071 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004072 mcp->mb[4] = MSW(size);
4073 mcp->mb[5] = LSW(size);
4074 mcp->out_mb |= MBX_5|MBX_4;
4075 } else {
4076 mcp->mb[4] = LSW(size);
4077 mcp->out_mb |= MBX_4;
4078 }
4079
4080 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004081 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004082 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004083 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004084
4085 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004086 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4087 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004088 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004089 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4090 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004091 }
4092
4093 return rval;
4094}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004095/* 84XX Support **************************************************************/
4096
4097struct cs84xx_mgmt_cmd {
4098 union {
4099 struct verify_chip_entry_84xx req;
4100 struct verify_chip_rsp_84xx rsp;
4101 } p;
4102};
4103
4104int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004105qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004106{
4107 int rval, retry;
4108 struct cs84xx_mgmt_cmd *mn;
4109 dma_addr_t mn_dma;
4110 uint16_t options;
4111 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004112 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004113
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004114 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4115 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004116
4117 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4118 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004119 return QLA_MEMORY_ALLOC_FAILED;
4120 }
4121
4122 /* Force Update? */
4123 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4124 /* Diagnostic firmware? */
4125 /* options |= MENLO_DIAG_FW; */
4126 /* We update the firmware with only one data sequence. */
4127 options |= VCO_END_OF_DATA;
4128
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004129 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004130 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004131 memset(mn, 0, sizeof(*mn));
4132 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4133 mn->p.req.entry_count = 1;
4134 mn->p.req.options = cpu_to_le16(options);
4135
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004136 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4137 "Dump of Verify Request.\n");
4138 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4139 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004140
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004141 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004142 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004143 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4144 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004145 goto verify_done;
4146 }
4147
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004148 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4149 "Dump of Verify Response.\n");
4150 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4151 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004152
4153 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4154 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4155 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004156 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004157 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004158
4159 if (status[0] != CS_COMPLETE) {
4160 rval = QLA_FUNCTION_FAILED;
4161 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004162 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4163 "Firmware update failed. Retrying "
4164 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004165 options |= VCO_DONT_UPDATE_FW;
4166 options &= ~VCO_FORCE_UPDATE;
4167 retry = 1;
4168 }
4169 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004170 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004171 "Firmware updated to %x.\n",
4172 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004173
4174 /* NOTE: we only update OP firmware. */
4175 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4176 ha->cs84xx->op_fw_version =
4177 le32_to_cpu(mn->p.rsp.fw_ver);
4178 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4179 flags);
4180 }
4181 } while (retry);
4182
4183verify_done:
4184 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4185
4186 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004187 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4188 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004189 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004190 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4191 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004192 }
4193
4194 return rval;
4195}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004196
4197int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004198qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004199{
4200 int rval;
4201 unsigned long flags;
4202 mbx_cmd_t mc;
4203 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004204 struct qla_hw_data *ha = vha->hw;
4205
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004206 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4207 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004208
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004209 if (IS_SHADOW_REG_CAPABLE(ha))
4210 req->options |= BIT_13;
4211
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004212 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004213 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004214 mcp->mb[2] = MSW(LSD(req->dma));
4215 mcp->mb[3] = LSW(LSD(req->dma));
4216 mcp->mb[6] = MSW(MSD(req->dma));
4217 mcp->mb[7] = LSW(MSD(req->dma));
4218 mcp->mb[5] = req->length;
4219 if (req->rsp)
4220 mcp->mb[10] = req->rsp->id;
4221 mcp->mb[12] = req->qos;
4222 mcp->mb[11] = req->vp_idx;
4223 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004224 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004225 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004226
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004227 mcp->mb[4] = req->id;
4228 /* que in ptr index */
4229 mcp->mb[8] = 0;
4230 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004231 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004232 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4233 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4234 mcp->in_mb = MBX_0;
4235 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004236 mcp->tov = MBX_TOV_SECONDS * 2;
4237
Chad Dupuisf73cb692014-02-26 04:15:06 -05004238 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004239 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004240 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004241 mcp->out_mb |= MBX_15;
4242 /* debug q create issue in SR-IOV */
4243 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4244 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004245
4246 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004247 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004248 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004249 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004250 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004251 }
4252 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4253
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004254 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004255 if (rval != QLA_SUCCESS) {
4256 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4257 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4258 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004259 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4260 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004261 }
4262
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004263 return rval;
4264}
4265
4266int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004267qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004268{
4269 int rval;
4270 unsigned long flags;
4271 mbx_cmd_t mc;
4272 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004273 struct qla_hw_data *ha = vha->hw;
4274
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004275 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4276 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004277
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004278 if (IS_SHADOW_REG_CAPABLE(ha))
4279 rsp->options |= BIT_13;
4280
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004281 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004282 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004283 mcp->mb[2] = MSW(LSD(rsp->dma));
4284 mcp->mb[3] = LSW(LSD(rsp->dma));
4285 mcp->mb[6] = MSW(MSD(rsp->dma));
4286 mcp->mb[7] = LSW(MSD(rsp->dma));
4287 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004288 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004289 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004290 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004291 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004292
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004293 mcp->mb[4] = rsp->id;
4294 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004295 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004296 /* que out ptr index */
4297 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004298 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004299 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4300 mcp->in_mb = MBX_0;
4301 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004302 mcp->tov = MBX_TOV_SECONDS * 2;
4303
4304 if (IS_QLA81XX(ha)) {
4305 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4306 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004307 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004308 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4309 mcp->in_mb |= MBX_1;
4310 /* debug q create issue in SR-IOV */
4311 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4312 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004313
4314 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004315 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004316 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004317 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004318 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004319 }
4320
4321 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4322
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004323 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004324 if (rval != QLA_SUCCESS) {
4325 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4326 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4327 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004328 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4329 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004330 }
4331
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004332 return rval;
4333}
4334
Andrew Vasquez8a659572009-02-08 20:50:12 -08004335int
4336qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4337{
4338 int rval;
4339 mbx_cmd_t mc;
4340 mbx_cmd_t *mcp = &mc;
4341
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004342 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4343 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004344
4345 mcp->mb[0] = MBC_IDC_ACK;
4346 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4347 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4348 mcp->in_mb = MBX_0;
4349 mcp->tov = MBX_TOV_SECONDS;
4350 mcp->flags = 0;
4351 rval = qla2x00_mailbox_command(vha, mcp);
4352
4353 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004354 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4355 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004356 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004357 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4358 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004359 }
4360
4361 return rval;
4362}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004363
4364int
4365qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4366{
4367 int rval;
4368 mbx_cmd_t mc;
4369 mbx_cmd_t *mcp = &mc;
4370
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4372 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004373
Chad Dupuisf73cb692014-02-26 04:15:06 -05004374 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4375 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004376 return QLA_FUNCTION_FAILED;
4377
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004378 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4379 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4380 mcp->out_mb = MBX_1|MBX_0;
4381 mcp->in_mb = MBX_1|MBX_0;
4382 mcp->tov = MBX_TOV_SECONDS;
4383 mcp->flags = 0;
4384 rval = qla2x00_mailbox_command(vha, mcp);
4385
4386 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004387 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4388 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4389 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004390 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4392 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004393 *sector_size = mcp->mb[1];
4394 }
4395
4396 return rval;
4397}
4398
4399int
4400qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4401{
4402 int rval;
4403 mbx_cmd_t mc;
4404 mbx_cmd_t *mcp = &mc;
4405
Chad Dupuisf73cb692014-02-26 04:15:06 -05004406 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4407 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004408 return QLA_FUNCTION_FAILED;
4409
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004410 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4411 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004412
4413 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4414 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4415 FAC_OPT_CMD_WRITE_PROTECT;
4416 mcp->out_mb = MBX_1|MBX_0;
4417 mcp->in_mb = MBX_1|MBX_0;
4418 mcp->tov = MBX_TOV_SECONDS;
4419 mcp->flags = 0;
4420 rval = qla2x00_mailbox_command(vha, mcp);
4421
4422 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004423 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4424 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4425 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004426 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004427 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4428 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004429 }
4430
4431 return rval;
4432}
4433
4434int
4435qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4436{
4437 int rval;
4438 mbx_cmd_t mc;
4439 mbx_cmd_t *mcp = &mc;
4440
Chad Dupuisf73cb692014-02-26 04:15:06 -05004441 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4442 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004443 return QLA_FUNCTION_FAILED;
4444
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004445 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4446 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004447
4448 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4449 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4450 mcp->mb[2] = LSW(start);
4451 mcp->mb[3] = MSW(start);
4452 mcp->mb[4] = LSW(finish);
4453 mcp->mb[5] = MSW(finish);
4454 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4455 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4456 mcp->tov = MBX_TOV_SECONDS;
4457 mcp->flags = 0;
4458 rval = qla2x00_mailbox_command(vha, mcp);
4459
4460 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004461 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4462 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4463 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004464 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004465 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4466 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004467 }
4468
4469 return rval;
4470}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004471
4472int
4473qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4474{
4475 int rval = 0;
4476 mbx_cmd_t mc;
4477 mbx_cmd_t *mcp = &mc;
4478
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004479 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4480 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004481
4482 mcp->mb[0] = MBC_RESTART_MPI_FW;
4483 mcp->out_mb = MBX_0;
4484 mcp->in_mb = MBX_0|MBX_1;
4485 mcp->tov = MBX_TOV_SECONDS;
4486 mcp->flags = 0;
4487 rval = qla2x00_mailbox_command(vha, mcp);
4488
4489 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004490 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4491 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4492 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004493 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004494 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4495 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004496 }
4497
4498 return rval;
4499}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004500
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004501int
4502qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4503{
4504 int rval;
4505 mbx_cmd_t mc;
4506 mbx_cmd_t *mcp = &mc;
4507 int i;
4508 int len;
4509 uint16_t *str;
4510 struct qla_hw_data *ha = vha->hw;
4511
4512 if (!IS_P3P_TYPE(ha))
4513 return QLA_FUNCTION_FAILED;
4514
4515 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4516 "Entered %s.\n", __func__);
4517
4518 str = (void *)version;
4519 len = strlen(version);
4520
4521 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4522 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4523 mcp->out_mb = MBX_1|MBX_0;
4524 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4525 mcp->mb[i] = cpu_to_le16p(str);
4526 mcp->out_mb |= 1<<i;
4527 }
4528 for (; i < 16; i++) {
4529 mcp->mb[i] = 0;
4530 mcp->out_mb |= 1<<i;
4531 }
4532 mcp->in_mb = MBX_1|MBX_0;
4533 mcp->tov = MBX_TOV_SECONDS;
4534 mcp->flags = 0;
4535 rval = qla2x00_mailbox_command(vha, mcp);
4536
4537 if (rval != QLA_SUCCESS) {
4538 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4539 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4540 } else {
4541 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4542 "Done %s.\n", __func__);
4543 }
4544
4545 return rval;
4546}
4547
4548int
4549qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4550{
4551 int rval;
4552 mbx_cmd_t mc;
4553 mbx_cmd_t *mcp = &mc;
4554 int len;
4555 uint16_t dwlen;
4556 uint8_t *str;
4557 dma_addr_t str_dma;
4558 struct qla_hw_data *ha = vha->hw;
4559
4560 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4561 IS_P3P_TYPE(ha))
4562 return QLA_FUNCTION_FAILED;
4563
4564 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4565 "Entered %s.\n", __func__);
4566
4567 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4568 if (!str) {
4569 ql_log(ql_log_warn, vha, 0x117f,
4570 "Failed to allocate driver version param.\n");
4571 return QLA_MEMORY_ALLOC_FAILED;
4572 }
4573
4574 memcpy(str, "\x7\x3\x11\x0", 4);
4575 dwlen = str[0];
4576 len = dwlen * 4 - 4;
4577 memset(str + 4, 0, len);
4578 if (len > strlen(version))
4579 len = strlen(version);
4580 memcpy(str + 4, version, len);
4581
4582 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4583 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4584 mcp->mb[2] = MSW(LSD(str_dma));
4585 mcp->mb[3] = LSW(LSD(str_dma));
4586 mcp->mb[6] = MSW(MSD(str_dma));
4587 mcp->mb[7] = LSW(MSD(str_dma));
4588 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4589 mcp->in_mb = MBX_1|MBX_0;
4590 mcp->tov = MBX_TOV_SECONDS;
4591 mcp->flags = 0;
4592 rval = qla2x00_mailbox_command(vha, mcp);
4593
4594 if (rval != QLA_SUCCESS) {
4595 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4596 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4597 } else {
4598 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4599 "Done %s.\n", __func__);
4600 }
4601
4602 dma_pool_free(ha->s_dma_pool, str, str_dma);
4603
4604 return rval;
4605}
4606
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004607int
4608qla24xx_get_port_login_templ(scsi_qla_host_t *vha, dma_addr_t buf_dma,
4609 void *buf, uint16_t bufsiz)
4610{
4611 int rval, i;
4612 mbx_cmd_t mc;
4613 mbx_cmd_t *mcp = &mc;
4614 uint32_t *bp;
4615
4616 if (!IS_FWI2_CAPABLE(vha->hw))
4617 return QLA_FUNCTION_FAILED;
4618
4619 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4620 "Entered %s.\n", __func__);
4621
4622 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4623 mcp->mb[1] = RNID_TYPE_PORT_LOGIN << 8;
4624 mcp->mb[2] = MSW(buf_dma);
4625 mcp->mb[3] = LSW(buf_dma);
4626 mcp->mb[6] = MSW(MSD(buf_dma));
4627 mcp->mb[7] = LSW(MSD(buf_dma));
4628 mcp->mb[8] = bufsiz/4;
4629 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4630 mcp->in_mb = MBX_1|MBX_0;
4631 mcp->tov = MBX_TOV_SECONDS;
4632 mcp->flags = 0;
4633 rval = qla2x00_mailbox_command(vha, mcp);
4634
4635 if (rval != QLA_SUCCESS) {
4636 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4637 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4638 } else {
4639 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4640 "Done %s.\n", __func__);
4641 bp = (uint32_t *) buf;
4642 for (i = 0; i < (bufsiz-4)/4; i++, bp++)
4643 *bp = cpu_to_be32(*bp);
4644 }
4645
4646 return rval;
4647}
4648
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004649static int
4650qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4651{
4652 int rval;
4653 mbx_cmd_t mc;
4654 mbx_cmd_t *mcp = &mc;
4655
4656 if (!IS_FWI2_CAPABLE(vha->hw))
4657 return QLA_FUNCTION_FAILED;
4658
4659 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4660 "Entered %s.\n", __func__);
4661
4662 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4663 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4664 mcp->out_mb = MBX_1|MBX_0;
4665 mcp->in_mb = MBX_1|MBX_0;
4666 mcp->tov = MBX_TOV_SECONDS;
4667 mcp->flags = 0;
4668 rval = qla2x00_mailbox_command(vha, mcp);
4669 *temp = mcp->mb[1];
4670
4671 if (rval != QLA_SUCCESS) {
4672 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4673 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4674 } else {
4675 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4676 "Done %s.\n", __func__);
4677 }
4678
4679 return rval;
4680}
4681
Joe Carnuccio3a117112013-02-08 01:58:00 -05004682int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004683qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4684 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004685{
4686 int rval;
4687 mbx_cmd_t mc;
4688 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004689 struct qla_hw_data *ha = vha->hw;
4690
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004691 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4692 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004693
Joe Carnuccio6766df92011-05-10 11:30:15 -07004694 if (!IS_FWI2_CAPABLE(ha))
4695 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004696
Joe Carnuccio6766df92011-05-10 11:30:15 -07004697 if (len == 1)
4698 opt |= BIT_0;
4699
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004700 mcp->mb[0] = MBC_READ_SFP;
4701 mcp->mb[1] = dev;
4702 mcp->mb[2] = MSW(sfp_dma);
4703 mcp->mb[3] = LSW(sfp_dma);
4704 mcp->mb[6] = MSW(MSD(sfp_dma));
4705 mcp->mb[7] = LSW(MSD(sfp_dma));
4706 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004707 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004708 mcp->mb[10] = opt;
4709 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 -07004710 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004711 mcp->tov = MBX_TOV_SECONDS;
4712 mcp->flags = 0;
4713 rval = qla2x00_mailbox_command(vha, mcp);
4714
4715 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004716 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004717
4718 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004719 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4720 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004721 if (mcp->mb[0] == MBS_COMMAND_ERROR &&
4722 mcp->mb[1] == 0x22)
4723 /* sfp is not there */
4724 rval = QLA_INTERFACE_ERROR;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004725 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004726 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4727 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004728 }
4729
4730 return rval;
4731}
4732
4733int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004734qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4735 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004736{
4737 int rval;
4738 mbx_cmd_t mc;
4739 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004740 struct qla_hw_data *ha = vha->hw;
4741
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004742 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4743 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004744
Joe Carnuccio6766df92011-05-10 11:30:15 -07004745 if (!IS_FWI2_CAPABLE(ha))
4746 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004747
Joe Carnuccio6766df92011-05-10 11:30:15 -07004748 if (len == 1)
4749 opt |= BIT_0;
4750
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004751 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004752 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004753
4754 mcp->mb[0] = MBC_WRITE_SFP;
4755 mcp->mb[1] = dev;
4756 mcp->mb[2] = MSW(sfp_dma);
4757 mcp->mb[3] = LSW(sfp_dma);
4758 mcp->mb[6] = MSW(MSD(sfp_dma));
4759 mcp->mb[7] = LSW(MSD(sfp_dma));
4760 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004761 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004762 mcp->mb[10] = opt;
4763 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 -07004764 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004765 mcp->tov = MBX_TOV_SECONDS;
4766 mcp->flags = 0;
4767 rval = qla2x00_mailbox_command(vha, mcp);
4768
4769 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004770 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4771 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004772 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004773 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4774 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004775 }
4776
4777 return rval;
4778}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004779
4780int
4781qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4782 uint16_t size_in_bytes, uint16_t *actual_size)
4783{
4784 int rval;
4785 mbx_cmd_t mc;
4786 mbx_cmd_t *mcp = &mc;
4787
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004788 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4789 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004790
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004791 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004792 return QLA_FUNCTION_FAILED;
4793
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004794 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4795 mcp->mb[2] = MSW(stats_dma);
4796 mcp->mb[3] = LSW(stats_dma);
4797 mcp->mb[6] = MSW(MSD(stats_dma));
4798 mcp->mb[7] = LSW(MSD(stats_dma));
4799 mcp->mb[8] = size_in_bytes >> 2;
4800 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4801 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4802 mcp->tov = MBX_TOV_SECONDS;
4803 mcp->flags = 0;
4804 rval = qla2x00_mailbox_command(vha, mcp);
4805
4806 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004807 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4808 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4809 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004810 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004811 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4812 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004813
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004814
4815 *actual_size = mcp->mb[2] << 2;
4816 }
4817
4818 return rval;
4819}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004820
4821int
4822qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4823 uint16_t size)
4824{
4825 int rval;
4826 mbx_cmd_t mc;
4827 mbx_cmd_t *mcp = &mc;
4828
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4830 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004831
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004832 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004833 return QLA_FUNCTION_FAILED;
4834
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004835 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4836 mcp->mb[1] = 0;
4837 mcp->mb[2] = MSW(tlv_dma);
4838 mcp->mb[3] = LSW(tlv_dma);
4839 mcp->mb[6] = MSW(MSD(tlv_dma));
4840 mcp->mb[7] = LSW(MSD(tlv_dma));
4841 mcp->mb[8] = size;
4842 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4843 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4844 mcp->tov = MBX_TOV_SECONDS;
4845 mcp->flags = 0;
4846 rval = qla2x00_mailbox_command(vha, mcp);
4847
4848 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004849 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4850 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4851 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004852 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004853 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4854 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004855 }
4856
4857 return rval;
4858}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004859
4860int
4861qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4862{
4863 int rval;
4864 mbx_cmd_t mc;
4865 mbx_cmd_t *mcp = &mc;
4866
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004867 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4868 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004869
Andrew Vasquez18e75552009-06-03 09:55:30 -07004870 if (!IS_FWI2_CAPABLE(vha->hw))
4871 return QLA_FUNCTION_FAILED;
4872
Andrew Vasquez18e75552009-06-03 09:55:30 -07004873 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4874 mcp->mb[1] = LSW(risc_addr);
4875 mcp->mb[8] = MSW(risc_addr);
4876 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4877 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4878 mcp->tov = 30;
4879 mcp->flags = 0;
4880 rval = qla2x00_mailbox_command(vha, mcp);
4881 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004882 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4883 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004884 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4886 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004887 *data = mcp->mb[3] << 16 | mcp->mb[2];
4888 }
4889
4890 return rval;
4891}
4892
4893int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004894qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4895 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004896{
4897 int rval;
4898 mbx_cmd_t mc;
4899 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004900
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004901 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4902 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004903
4904 memset(mcp->mb, 0 , sizeof(mcp->mb));
4905 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4906 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4907
4908 /* transfer count */
4909 mcp->mb[10] = LSW(mreq->transfer_size);
4910 mcp->mb[11] = MSW(mreq->transfer_size);
4911
4912 /* send data address */
4913 mcp->mb[14] = LSW(mreq->send_dma);
4914 mcp->mb[15] = MSW(mreq->send_dma);
4915 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4916 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4917
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004918 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004919 mcp->mb[16] = LSW(mreq->rcv_dma);
4920 mcp->mb[17] = MSW(mreq->rcv_dma);
4921 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4922 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4923
4924 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004925 mcp->mb[18] = LSW(mreq->iteration_count);
4926 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004927
4928 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4929 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 -08004930 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004931 mcp->out_mb |= MBX_2;
4932 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4933
4934 mcp->buf_size = mreq->transfer_size;
4935 mcp->tov = MBX_TOV_SECONDS;
4936 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4937
4938 rval = qla2x00_mailbox_command(vha, mcp);
4939
4940 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004941 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4942 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4943 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4944 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004945 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004946 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4947 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004948 }
4949
4950 /* Copy mailbox information */
4951 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004952 return rval;
4953}
4954
4955int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004956qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4957 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004958{
4959 int rval;
4960 mbx_cmd_t mc;
4961 mbx_cmd_t *mcp = &mc;
4962 struct qla_hw_data *ha = vha->hw;
4963
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004964 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4965 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004966
4967 memset(mcp->mb, 0 , sizeof(mcp->mb));
4968 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07004969 /* BIT_6 specifies 64bit address */
4970 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004971 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004972 mcp->mb[2] = vha->fcoe_fcf_idx;
4973 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004974 mcp->mb[16] = LSW(mreq->rcv_dma);
4975 mcp->mb[17] = MSW(mreq->rcv_dma);
4976 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4977 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4978
4979 mcp->mb[10] = LSW(mreq->transfer_size);
4980
4981 mcp->mb[14] = LSW(mreq->send_dma);
4982 mcp->mb[15] = MSW(mreq->send_dma);
4983 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4984 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4985
4986 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4987 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004988 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004989 mcp->out_mb |= MBX_2;
4990
4991 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004992 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4993 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004994 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004995 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004996 mcp->in_mb |= MBX_3;
4997
4998 mcp->tov = MBX_TOV_SECONDS;
4999 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5000 mcp->buf_size = mreq->transfer_size;
5001
5002 rval = qla2x00_mailbox_command(vha, mcp);
5003
5004 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005005 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
5006 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5007 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005008 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005009 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
5010 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005011 }
5012
5013 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005014 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005015 return rval;
5016}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005017
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005018int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005019qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005020{
5021 int rval;
5022 mbx_cmd_t mc;
5023 mbx_cmd_t *mcp = &mc;
5024
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005025 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005026 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005027
5028 mcp->mb[0] = MBC_ISP84XX_RESET;
5029 mcp->mb[1] = enable_diagnostic;
5030 mcp->out_mb = MBX_1|MBX_0;
5031 mcp->in_mb = MBX_1|MBX_0;
5032 mcp->tov = MBX_TOV_SECONDS;
5033 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005034 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005035
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005036 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005037 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005038 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005039 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
5040 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005041
5042 return rval;
5043}
5044
5045int
Andrew Vasquez18e75552009-06-03 09:55:30 -07005046qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
5047{
5048 int rval;
5049 mbx_cmd_t mc;
5050 mbx_cmd_t *mcp = &mc;
5051
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005052 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
5053 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005054
Andrew Vasquez18e75552009-06-03 09:55:30 -07005055 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005056 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005057
Andrew Vasquez18e75552009-06-03 09:55:30 -07005058 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
5059 mcp->mb[1] = LSW(risc_addr);
5060 mcp->mb[2] = LSW(data);
5061 mcp->mb[3] = MSW(data);
5062 mcp->mb[8] = MSW(risc_addr);
5063 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
5064 mcp->in_mb = MBX_0;
5065 mcp->tov = 30;
5066 mcp->flags = 0;
5067 rval = qla2x00_mailbox_command(vha, mcp);
5068 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005069 ql_dbg(ql_dbg_mbx, vha, 0x1101,
5070 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005071 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005072 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
5073 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005074 }
5075
5076 return rval;
5077}
Michael Hernandez3064ff32009-12-15 21:29:44 -08005078
5079int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005080qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
5081{
5082 int rval;
5083 uint32_t stat, timer;
5084 uint16_t mb0 = 0;
5085 struct qla_hw_data *ha = vha->hw;
5086 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5087
5088 rval = QLA_SUCCESS;
5089
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005090 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
5091 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005092
5093 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
5094
5095 /* Write the MBC data to the registers */
5096 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
5097 WRT_REG_WORD(&reg->mailbox1, mb[0]);
5098 WRT_REG_WORD(&reg->mailbox2, mb[1]);
5099 WRT_REG_WORD(&reg->mailbox3, mb[2]);
5100 WRT_REG_WORD(&reg->mailbox4, mb[3]);
5101
5102 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
5103
5104 /* Poll for MBC interrupt */
5105 for (timer = 6000000; timer; timer--) {
5106 /* Check for pending interrupts. */
5107 stat = RD_REG_DWORD(&reg->host_status);
5108 if (stat & HSRX_RISC_INT) {
5109 stat &= 0xff;
5110
5111 if (stat == 0x1 || stat == 0x2 ||
5112 stat == 0x10 || stat == 0x11) {
5113 set_bit(MBX_INTERRUPT,
5114 &ha->mbx_cmd_flags);
5115 mb0 = RD_REG_WORD(&reg->mailbox0);
5116 WRT_REG_DWORD(&reg->hccr,
5117 HCCRX_CLR_RISC_INT);
5118 RD_REG_DWORD(&reg->hccr);
5119 break;
5120 }
5121 }
5122 udelay(5);
5123 }
5124
5125 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5126 rval = mb0 & MBS_MASK;
5127 else
5128 rval = QLA_FUNCTION_FAILED;
5129
5130 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005131 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5132 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005133 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005134 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5135 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005136 }
5137
5138 return rval;
5139}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005140
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005141int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005142qla2x00_get_data_rate(scsi_qla_host_t *vha)
5143{
5144 int rval;
5145 mbx_cmd_t mc;
5146 mbx_cmd_t *mcp = &mc;
5147 struct qla_hw_data *ha = vha->hw;
5148
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005149 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5150 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005151
Michael Hernandez3064ff32009-12-15 21:29:44 -08005152 if (!IS_FWI2_CAPABLE(ha))
5153 return QLA_FUNCTION_FAILED;
5154
Michael Hernandez3064ff32009-12-15 21:29:44 -08005155 mcp->mb[0] = MBC_DATA_RATE;
5156 mcp->mb[1] = 0;
5157 mcp->out_mb = MBX_1|MBX_0;
5158 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005159 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005160 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005161 mcp->tov = MBX_TOV_SECONDS;
5162 mcp->flags = 0;
5163 rval = qla2x00_mailbox_command(vha, mcp);
5164 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005165 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5166 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005167 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5169 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005170 if (mcp->mb[1] != 0x7)
5171 ha->link_data_rate = mcp->mb[1];
5172 }
5173
5174 return rval;
5175}
Sarang Radke09ff7012010-03-19 17:03:59 -07005176
5177int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005178qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5179{
5180 int rval;
5181 mbx_cmd_t mc;
5182 mbx_cmd_t *mcp = &mc;
5183 struct qla_hw_data *ha = vha->hw;
5184
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005185 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5186 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005187
Chad Dupuisf73cb692014-02-26 04:15:06 -05005188 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5189 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005190 return QLA_FUNCTION_FAILED;
5191 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5192 mcp->out_mb = MBX_0;
5193 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5194 mcp->tov = MBX_TOV_SECONDS;
5195 mcp->flags = 0;
5196
5197 rval = qla2x00_mailbox_command(vha, mcp);
5198
5199 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005200 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5201 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005202 } else {
5203 /* Copy all bits to preserve original value */
5204 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5205
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005206 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5207 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005208 }
5209 return rval;
5210}
5211
5212int
5213qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5214{
5215 int rval;
5216 mbx_cmd_t mc;
5217 mbx_cmd_t *mcp = &mc;
5218
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005219 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5220 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005221
5222 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5223 /* Copy all bits to preserve original setting */
5224 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5225 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5226 mcp->in_mb = MBX_0;
5227 mcp->tov = MBX_TOV_SECONDS;
5228 mcp->flags = 0;
5229 rval = qla2x00_mailbox_command(vha, mcp);
5230
5231 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005232 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5233 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005234 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5236 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005237
5238 return rval;
5239}
5240
5241
5242int
Sarang Radke09ff7012010-03-19 17:03:59 -07005243qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5244 uint16_t *mb)
5245{
5246 int rval;
5247 mbx_cmd_t mc;
5248 mbx_cmd_t *mcp = &mc;
5249 struct qla_hw_data *ha = vha->hw;
5250
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005251 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5252 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005253
Sarang Radke09ff7012010-03-19 17:03:59 -07005254 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5255 return QLA_FUNCTION_FAILED;
5256
Sarang Radke09ff7012010-03-19 17:03:59 -07005257 mcp->mb[0] = MBC_PORT_PARAMS;
5258 mcp->mb[1] = loop_id;
5259 if (ha->flags.fcp_prio_enabled)
5260 mcp->mb[2] = BIT_1;
5261 else
5262 mcp->mb[2] = BIT_2;
5263 mcp->mb[4] = priority & 0xf;
5264 mcp->mb[9] = vha->vp_idx;
5265 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5266 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5267 mcp->tov = 30;
5268 mcp->flags = 0;
5269 rval = qla2x00_mailbox_command(vha, mcp);
5270 if (mb != NULL) {
5271 mb[0] = mcp->mb[0];
5272 mb[1] = mcp->mb[1];
5273 mb[3] = mcp->mb[3];
5274 mb[4] = mcp->mb[4];
5275 }
5276
5277 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005278 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005279 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005280 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5281 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005282 }
5283
5284 return rval;
5285}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005286
5287int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005288qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005289{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005290 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005291 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005292 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005293
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005294 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5295 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5296 "Thermal not supported by this card.\n");
5297 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005298 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005299
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005300 if (IS_QLA25XX(ha)) {
5301 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5302 ha->pdev->subsystem_device == 0x0175) {
5303 rval = qla2x00_read_sfp(vha, 0, &byte,
5304 0x98, 0x1, 1, BIT_13|BIT_0);
5305 *temp = byte;
5306 return rval;
5307 }
5308 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5309 ha->pdev->subsystem_device == 0x338e) {
5310 rval = qla2x00_read_sfp(vha, 0, &byte,
5311 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5312 *temp = byte;
5313 return rval;
5314 }
5315 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5316 "Thermal not supported by this card.\n");
5317 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005318 }
5319
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005320 if (IS_QLA82XX(ha)) {
5321 *temp = qla82xx_read_temperature(vha);
5322 rval = QLA_SUCCESS;
5323 return rval;
5324 } else if (IS_QLA8044(ha)) {
5325 *temp = qla8044_read_temperature(vha);
5326 rval = QLA_SUCCESS;
5327 return rval;
5328 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005329
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005330 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005331 return rval;
5332}
5333
5334int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005335qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5336{
5337 int rval;
5338 struct qla_hw_data *ha = vha->hw;
5339 mbx_cmd_t mc;
5340 mbx_cmd_t *mcp = &mc;
5341
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005342 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5343 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005344
Giridhar Malavalia9083012010-04-12 17:59:55 -07005345 if (!IS_FWI2_CAPABLE(ha))
5346 return QLA_FUNCTION_FAILED;
5347
Giridhar Malavalia9083012010-04-12 17:59:55 -07005348 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005349 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005350 mcp->mb[1] = 1;
5351
5352 mcp->out_mb = MBX_1|MBX_0;
5353 mcp->in_mb = MBX_0;
5354 mcp->tov = 30;
5355 mcp->flags = 0;
5356
5357 rval = qla2x00_mailbox_command(vha, mcp);
5358 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005359 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5360 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005361 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005362 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5363 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005364 }
5365
5366 return rval;
5367}
5368
5369int
5370qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5371{
5372 int rval;
5373 struct qla_hw_data *ha = vha->hw;
5374 mbx_cmd_t mc;
5375 mbx_cmd_t *mcp = &mc;
5376
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005377 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5378 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005379
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005380 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005381 return QLA_FUNCTION_FAILED;
5382
Giridhar Malavalia9083012010-04-12 17:59:55 -07005383 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005384 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005385 mcp->mb[1] = 0;
5386
5387 mcp->out_mb = MBX_1|MBX_0;
5388 mcp->in_mb = MBX_0;
5389 mcp->tov = 30;
5390 mcp->flags = 0;
5391
5392 rval = qla2x00_mailbox_command(vha, mcp);
5393 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005394 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5395 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005396 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005397 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5398 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005399 }
5400
5401 return rval;
5402}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005403
5404int
5405qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5406{
5407 struct qla_hw_data *ha = vha->hw;
5408 mbx_cmd_t mc;
5409 mbx_cmd_t *mcp = &mc;
5410 int rval = QLA_FUNCTION_FAILED;
5411
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005412 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5413 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005414
5415 memset(mcp->mb, 0 , sizeof(mcp->mb));
5416 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5417 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5418 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5419 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5420
5421 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5422 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5423 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5424
5425 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5426 mcp->tov = MBX_TOV_SECONDS;
5427 rval = qla2x00_mailbox_command(vha, mcp);
5428
5429 /* Always copy back return mailbox values. */
5430 if (rval != QLA_SUCCESS) {
5431 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5432 "mailbox command FAILED=0x%x, subcode=%x.\n",
5433 (mcp->mb[1] << 16) | mcp->mb[0],
5434 (mcp->mb[3] << 16) | mcp->mb[2]);
5435 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005436 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5437 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005438 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5439 if (!ha->md_template_size) {
5440 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5441 "Null template size obtained.\n");
5442 rval = QLA_FUNCTION_FAILED;
5443 }
5444 }
5445 return rval;
5446}
5447
5448int
5449qla82xx_md_get_template(scsi_qla_host_t *vha)
5450{
5451 struct qla_hw_data *ha = vha->hw;
5452 mbx_cmd_t mc;
5453 mbx_cmd_t *mcp = &mc;
5454 int rval = QLA_FUNCTION_FAILED;
5455
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005456 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5457 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005458
5459 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5460 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5461 if (!ha->md_tmplt_hdr) {
5462 ql_log(ql_log_warn, vha, 0x1124,
5463 "Unable to allocate memory for Minidump template.\n");
5464 return rval;
5465 }
5466
5467 memset(mcp->mb, 0 , sizeof(mcp->mb));
5468 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5469 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5470 mcp->mb[2] = LSW(RQST_TMPLT);
5471 mcp->mb[3] = MSW(RQST_TMPLT);
5472 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5473 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5474 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5475 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5476 mcp->mb[8] = LSW(ha->md_template_size);
5477 mcp->mb[9] = MSW(ha->md_template_size);
5478
5479 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5480 mcp->tov = MBX_TOV_SECONDS;
5481 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5482 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5483 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5484 rval = qla2x00_mailbox_command(vha, mcp);
5485
5486 if (rval != QLA_SUCCESS) {
5487 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5488 "mailbox command FAILED=0x%x, subcode=%x.\n",
5489 ((mcp->mb[1] << 16) | mcp->mb[0]),
5490 ((mcp->mb[3] << 16) | mcp->mb[2]));
5491 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005492 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5493 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005494 return rval;
5495}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005496
5497int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005498qla8044_md_get_template(scsi_qla_host_t *vha)
5499{
5500 struct qla_hw_data *ha = vha->hw;
5501 mbx_cmd_t mc;
5502 mbx_cmd_t *mcp = &mc;
5503 int rval = QLA_FUNCTION_FAILED;
5504 int offset = 0, size = MINIDUMP_SIZE_36K;
5505 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5506 "Entered %s.\n", __func__);
5507
5508 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5509 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5510 if (!ha->md_tmplt_hdr) {
5511 ql_log(ql_log_warn, vha, 0xb11b,
5512 "Unable to allocate memory for Minidump template.\n");
5513 return rval;
5514 }
5515
5516 memset(mcp->mb, 0 , sizeof(mcp->mb));
5517 while (offset < ha->md_template_size) {
5518 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5519 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5520 mcp->mb[2] = LSW(RQST_TMPLT);
5521 mcp->mb[3] = MSW(RQST_TMPLT);
5522 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5523 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5524 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5525 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5526 mcp->mb[8] = LSW(size);
5527 mcp->mb[9] = MSW(size);
5528 mcp->mb[10] = offset & 0x0000FFFF;
5529 mcp->mb[11] = offset & 0xFFFF0000;
5530 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5531 mcp->tov = MBX_TOV_SECONDS;
5532 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5533 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5534 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5535 rval = qla2x00_mailbox_command(vha, mcp);
5536
5537 if (rval != QLA_SUCCESS) {
5538 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5539 "mailbox command FAILED=0x%x, subcode=%x.\n",
5540 ((mcp->mb[1] << 16) | mcp->mb[0]),
5541 ((mcp->mb[3] << 16) | mcp->mb[2]));
5542 return rval;
5543 } else
5544 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5545 "Done %s.\n", __func__);
5546 offset = offset + size;
5547 }
5548 return rval;
5549}
5550
5551int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005552qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5553{
5554 int rval;
5555 struct qla_hw_data *ha = vha->hw;
5556 mbx_cmd_t mc;
5557 mbx_cmd_t *mcp = &mc;
5558
5559 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5560 return QLA_FUNCTION_FAILED;
5561
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005562 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5563 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005564
5565 memset(mcp, 0, sizeof(mbx_cmd_t));
5566 mcp->mb[0] = MBC_SET_LED_CONFIG;
5567 mcp->mb[1] = led_cfg[0];
5568 mcp->mb[2] = led_cfg[1];
5569 if (IS_QLA8031(ha)) {
5570 mcp->mb[3] = led_cfg[2];
5571 mcp->mb[4] = led_cfg[3];
5572 mcp->mb[5] = led_cfg[4];
5573 mcp->mb[6] = led_cfg[5];
5574 }
5575
5576 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5577 if (IS_QLA8031(ha))
5578 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5579 mcp->in_mb = MBX_0;
5580 mcp->tov = 30;
5581 mcp->flags = 0;
5582
5583 rval = qla2x00_mailbox_command(vha, mcp);
5584 if (rval != QLA_SUCCESS) {
5585 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5586 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5587 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5589 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005590 }
5591
5592 return rval;
5593}
5594
5595int
5596qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5597{
5598 int rval;
5599 struct qla_hw_data *ha = vha->hw;
5600 mbx_cmd_t mc;
5601 mbx_cmd_t *mcp = &mc;
5602
5603 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5604 return QLA_FUNCTION_FAILED;
5605
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005606 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5607 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005608
5609 memset(mcp, 0, sizeof(mbx_cmd_t));
5610 mcp->mb[0] = MBC_GET_LED_CONFIG;
5611
5612 mcp->out_mb = MBX_0;
5613 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5614 if (IS_QLA8031(ha))
5615 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5616 mcp->tov = 30;
5617 mcp->flags = 0;
5618
5619 rval = qla2x00_mailbox_command(vha, mcp);
5620 if (rval != QLA_SUCCESS) {
5621 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5622 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5623 } else {
5624 led_cfg[0] = mcp->mb[1];
5625 led_cfg[1] = mcp->mb[2];
5626 if (IS_QLA8031(ha)) {
5627 led_cfg[2] = mcp->mb[3];
5628 led_cfg[3] = mcp->mb[4];
5629 led_cfg[4] = mcp->mb[5];
5630 led_cfg[5] = mcp->mb[6];
5631 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005632 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5633 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005634 }
5635
5636 return rval;
5637}
5638
5639int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005640qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5641{
5642 int rval;
5643 struct qla_hw_data *ha = vha->hw;
5644 mbx_cmd_t mc;
5645 mbx_cmd_t *mcp = &mc;
5646
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005647 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005648 return QLA_FUNCTION_FAILED;
5649
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005650 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005651 "Entered %s.\n", __func__);
5652
5653 memset(mcp, 0, sizeof(mbx_cmd_t));
5654 mcp->mb[0] = MBC_SET_LED_CONFIG;
5655 if (enable)
5656 mcp->mb[7] = 0xE;
5657 else
5658 mcp->mb[7] = 0xD;
5659
5660 mcp->out_mb = MBX_7|MBX_0;
5661 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005662 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005663 mcp->flags = 0;
5664
5665 rval = qla2x00_mailbox_command(vha, mcp);
5666 if (rval != QLA_SUCCESS) {
5667 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5668 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5669 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005670 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005671 "Done %s.\n", __func__);
5672 }
5673
5674 return rval;
5675}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005676
5677int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005678qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005679{
5680 int rval;
5681 struct qla_hw_data *ha = vha->hw;
5682 mbx_cmd_t mc;
5683 mbx_cmd_t *mcp = &mc;
5684
Chad Dupuisf73cb692014-02-26 04:15:06 -05005685 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005686 return QLA_FUNCTION_FAILED;
5687
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005688 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5689 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005690
5691 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5692 mcp->mb[1] = LSW(reg);
5693 mcp->mb[2] = MSW(reg);
5694 mcp->mb[3] = LSW(data);
5695 mcp->mb[4] = MSW(data);
5696 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5697
5698 mcp->in_mb = MBX_1|MBX_0;
5699 mcp->tov = MBX_TOV_SECONDS;
5700 mcp->flags = 0;
5701 rval = qla2x00_mailbox_command(vha, mcp);
5702
5703 if (rval != QLA_SUCCESS) {
5704 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5705 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5706 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005707 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005708 "Done %s.\n", __func__);
5709 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005710
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005711 return rval;
5712}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005713
5714int
5715qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5716{
5717 int rval;
5718 struct qla_hw_data *ha = vha->hw;
5719 mbx_cmd_t mc;
5720 mbx_cmd_t *mcp = &mc;
5721
5722 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005723 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005724 "Implicit LOGO Unsupported.\n");
5725 return QLA_FUNCTION_FAILED;
5726 }
5727
5728
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005729 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5730 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005731
5732 /* Perform Implicit LOGO. */
5733 mcp->mb[0] = MBC_PORT_LOGOUT;
5734 mcp->mb[1] = fcport->loop_id;
5735 mcp->mb[10] = BIT_15;
5736 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5737 mcp->in_mb = MBX_0;
5738 mcp->tov = MBX_TOV_SECONDS;
5739 mcp->flags = 0;
5740 rval = qla2x00_mailbox_command(vha, mcp);
5741 if (rval != QLA_SUCCESS)
5742 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5743 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5744 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5746 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005747
5748 return rval;
5749}
5750
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005751int
5752qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5753{
5754 int rval;
5755 mbx_cmd_t mc;
5756 mbx_cmd_t *mcp = &mc;
5757 struct qla_hw_data *ha = vha->hw;
5758 unsigned long retry_max_time = jiffies + (2 * HZ);
5759
Chad Dupuisf73cb692014-02-26 04:15:06 -05005760 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005761 return QLA_FUNCTION_FAILED;
5762
5763 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5764
5765retry_rd_reg:
5766 mcp->mb[0] = MBC_READ_REMOTE_REG;
5767 mcp->mb[1] = LSW(reg);
5768 mcp->mb[2] = MSW(reg);
5769 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5770 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5771 mcp->tov = MBX_TOV_SECONDS;
5772 mcp->flags = 0;
5773 rval = qla2x00_mailbox_command(vha, mcp);
5774
5775 if (rval != QLA_SUCCESS) {
5776 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5777 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5778 rval, mcp->mb[0], mcp->mb[1]);
5779 } else {
5780 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5781 if (*data == QLA8XXX_BAD_VALUE) {
5782 /*
5783 * During soft-reset CAMRAM register reads might
5784 * return 0xbad0bad0. So retry for MAX of 2 sec
5785 * while reading camram registers.
5786 */
5787 if (time_after(jiffies, retry_max_time)) {
5788 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5789 "Failure to read CAMRAM register. "
5790 "data=0x%x.\n", *data);
5791 return QLA_FUNCTION_FAILED;
5792 }
5793 msleep(100);
5794 goto retry_rd_reg;
5795 }
5796 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5797 }
5798
5799 return rval;
5800}
5801
5802int
5803qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5804{
5805 int rval;
5806 mbx_cmd_t mc;
5807 mbx_cmd_t *mcp = &mc;
5808 struct qla_hw_data *ha = vha->hw;
5809
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005810 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005811 return QLA_FUNCTION_FAILED;
5812
5813 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5814
5815 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5816 mcp->out_mb = MBX_0;
5817 mcp->in_mb = MBX_1|MBX_0;
5818 mcp->tov = MBX_TOV_SECONDS;
5819 mcp->flags = 0;
5820 rval = qla2x00_mailbox_command(vha, mcp);
5821
5822 if (rval != QLA_SUCCESS) {
5823 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5824 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5825 rval, mcp->mb[0], mcp->mb[1]);
5826 ha->isp_ops->fw_dump(vha, 0);
5827 } else {
5828 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5829 }
5830
5831 return rval;
5832}
5833
5834int
5835qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5836 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5837{
5838 int rval;
5839 mbx_cmd_t mc;
5840 mbx_cmd_t *mcp = &mc;
5841 uint8_t subcode = (uint8_t)options;
5842 struct qla_hw_data *ha = vha->hw;
5843
5844 if (!IS_QLA8031(ha))
5845 return QLA_FUNCTION_FAILED;
5846
5847 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5848
5849 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5850 mcp->mb[1] = options;
5851 mcp->out_mb = MBX_1|MBX_0;
5852 if (subcode & BIT_2) {
5853 mcp->mb[2] = LSW(start_addr);
5854 mcp->mb[3] = MSW(start_addr);
5855 mcp->mb[4] = LSW(end_addr);
5856 mcp->mb[5] = MSW(end_addr);
5857 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5858 }
5859 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5860 if (!(subcode & (BIT_2 | BIT_5)))
5861 mcp->in_mb |= MBX_4|MBX_3;
5862 mcp->tov = MBX_TOV_SECONDS;
5863 mcp->flags = 0;
5864 rval = qla2x00_mailbox_command(vha, mcp);
5865
5866 if (rval != QLA_SUCCESS) {
5867 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5868 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5869 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5870 mcp->mb[4]);
5871 ha->isp_ops->fw_dump(vha, 0);
5872 } else {
5873 if (subcode & BIT_5)
5874 *sector_size = mcp->mb[1];
5875 else if (subcode & (BIT_6 | BIT_7)) {
5876 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5877 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5878 } else if (subcode & (BIT_3 | BIT_4)) {
5879 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5880 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5881 }
5882 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5883 }
5884
5885 return rval;
5886}
Saurav Kashyap81178772012-08-22 14:21:04 -04005887
5888int
5889qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5890 uint32_t size)
5891{
5892 int rval;
5893 mbx_cmd_t mc;
5894 mbx_cmd_t *mcp = &mc;
5895
5896 if (!IS_MCTP_CAPABLE(vha->hw))
5897 return QLA_FUNCTION_FAILED;
5898
5899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5900 "Entered %s.\n", __func__);
5901
5902 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5903 mcp->mb[1] = LSW(addr);
5904 mcp->mb[2] = MSW(req_dma);
5905 mcp->mb[3] = LSW(req_dma);
5906 mcp->mb[4] = MSW(size);
5907 mcp->mb[5] = LSW(size);
5908 mcp->mb[6] = MSW(MSD(req_dma));
5909 mcp->mb[7] = LSW(MSD(req_dma));
5910 mcp->mb[8] = MSW(addr);
5911 /* Setting RAM ID to valid */
5912 mcp->mb[10] |= BIT_7;
5913 /* For MCTP RAM ID is 0x40 */
5914 mcp->mb[10] |= 0x40;
5915
5916 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5917 MBX_0;
5918
5919 mcp->in_mb = MBX_0;
5920 mcp->tov = MBX_TOV_SECONDS;
5921 mcp->flags = 0;
5922 rval = qla2x00_mailbox_command(vha, mcp);
5923
5924 if (rval != QLA_SUCCESS) {
5925 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5926 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5927 } else {
5928 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5929 "Done %s.\n", __func__);
5930 }
5931
5932 return rval;
5933}
Joe Carnuccioec891462016-07-06 11:14:26 -04005934
5935int
5936qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5937 void *dd_buf, uint size, uint options)
5938{
5939 int rval;
5940 mbx_cmd_t mc;
5941 mbx_cmd_t *mcp = &mc;
5942 dma_addr_t dd_dma;
5943
5944 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5945 return QLA_FUNCTION_FAILED;
5946
Quinn Tran83548fe2017-06-02 09:12:01 -07005947 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04005948 "Entered %s.\n", __func__);
5949
Joe Carnuccioec891462016-07-06 11:14:26 -04005950 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5951 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08005952 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04005953 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5954 return QLA_MEMORY_ALLOC_FAILED;
5955 }
5956
5957 memset(dd_buf, 0, size);
5958
5959 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5960 mcp->mb[1] = options;
5961 mcp->mb[2] = MSW(LSD(dd_dma));
5962 mcp->mb[3] = LSW(LSD(dd_dma));
5963 mcp->mb[6] = MSW(MSD(dd_dma));
5964 mcp->mb[7] = LSW(MSD(dd_dma));
5965 mcp->mb[8] = size;
5966 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5967 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5968 mcp->buf_size = size;
5969 mcp->flags = MBX_DMA_IN;
5970 mcp->tov = MBX_TOV_SECONDS * 4;
5971 rval = qla2x00_mailbox_command(vha, mcp);
5972
5973 if (rval != QLA_SUCCESS) {
5974 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5975 } else {
5976 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5977 "Done %s.\n", __func__);
5978 }
5979
5980 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5981 size, DMA_FROM_DEVICE);
5982
5983 return rval;
5984}
Quinn Tran15f30a52017-03-15 09:48:52 -07005985
5986static void qla2x00_async_mb_sp_done(void *s, int res)
5987{
5988 struct srb *sp = s;
5989
5990 sp->u.iocb_cmd.u.mbx.rc = res;
5991
5992 complete(&sp->u.iocb_cmd.u.mbx.comp);
5993 /* don't free sp here. Let the caller do the free */
5994}
5995
5996/*
5997 * This mailbox uses the iocb interface to send MB command.
5998 * This allows non-critial (non chip setup) command to go
5999 * out in parrallel.
6000 */
6001int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
6002{
6003 int rval = QLA_FUNCTION_FAILED;
6004 srb_t *sp;
6005 struct srb_iocb *c;
6006
6007 if (!vha->hw->flags.fw_started)
6008 goto done;
6009
6010 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
6011 if (!sp)
6012 goto done;
6013
6014 sp->type = SRB_MB_IOCB;
6015 sp->name = mb_to_str(mcp->mb[0]);
6016
6017 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
6018
6019 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
6020
6021 c = &sp->u.iocb_cmd;
6022 c->timeout = qla2x00_async_iocb_timeout;
6023 init_completion(&c->u.mbx.comp);
6024
6025 sp->done = qla2x00_async_mb_sp_done;
6026
6027 rval = qla2x00_start_sp(sp);
6028 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006029 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07006030 "%s: %s Failed submission. %x.\n",
6031 __func__, sp->name, rval);
6032 goto done_free_sp;
6033 }
6034
Quinn Tran83548fe2017-06-02 09:12:01 -07006035 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006036 sp->name, sp->handle);
6037
6038 wait_for_completion(&c->u.mbx.comp);
6039 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
6040
6041 rval = c->u.mbx.rc;
6042 switch (rval) {
6043 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07006044 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006045 __func__, sp->name, rval);
6046 break;
6047 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07006048 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006049 __func__, sp->name);
6050 sp->free(sp);
6051 break;
6052 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07006053 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006054 __func__, sp->name, rval);
6055 sp->free(sp);
6056 break;
6057 }
6058
6059 return rval;
6060
6061done_free_sp:
6062 sp->free(sp);
6063done:
6064 return rval;
6065}
6066
6067/*
6068 * qla24xx_gpdb_wait
6069 * NOTE: Do not call this routine from DPC thread
6070 */
6071int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
6072{
6073 int rval = QLA_FUNCTION_FAILED;
6074 dma_addr_t pd_dma;
6075 struct port_database_24xx *pd;
6076 struct qla_hw_data *ha = vha->hw;
6077 mbx_cmd_t mc;
6078
6079 if (!vha->hw->flags.fw_started)
6080 goto done;
6081
Thomas Meyer08eb7f42017-09-21 08:15:26 +02006082 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran15f30a52017-03-15 09:48:52 -07006083 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006084 ql_log(ql_log_warn, vha, 0xd047,
6085 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07006086 goto done_free_sp;
6087 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006088
6089 memset(&mc, 0, sizeof(mc));
6090 mc.mb[0] = MBC_GET_PORT_DATABASE;
6091 mc.mb[1] = cpu_to_le16(fcport->loop_id);
6092 mc.mb[2] = MSW(pd_dma);
6093 mc.mb[3] = LSW(pd_dma);
6094 mc.mb[6] = MSW(MSD(pd_dma));
6095 mc.mb[7] = LSW(MSD(pd_dma));
6096 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6097 mc.mb[10] = cpu_to_le16((uint16_t)opt);
6098
6099 rval = qla24xx_send_mb_cmd(vha, &mc);
6100 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006101 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07006102 "%s: %8phC fail\n", __func__, fcport->port_name);
6103 goto done_free_sp;
6104 }
6105
6106 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
6107
Quinn Tran83548fe2017-06-02 09:12:01 -07006108 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006109 __func__, fcport->port_name);
6110
6111done_free_sp:
6112 if (pd)
6113 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
6114done:
6115 return rval;
6116}
6117
6118int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
6119 struct port_database_24xx *pd)
6120{
6121 int rval = QLA_SUCCESS;
6122 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006123 u8 current_login_state, last_login_state;
6124
6125 if (fcport->fc4f_nvme) {
6126 current_login_state = pd->current_login_state >> 4;
6127 last_login_state = pd->last_login_state >> 4;
6128 } else {
6129 current_login_state = pd->current_login_state & 0xf;
6130 last_login_state = pd->last_login_state & 0xf;
6131 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006132
6133 /* Check for logged in state. */
Quinn Tran23c64552017-12-04 14:45:08 -08006134 if (current_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006135 ql_dbg(ql_dbg_mbx, vha, 0x119a,
6136 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006137 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006138 rval = QLA_FUNCTION_FAILED;
6139 goto gpd_error_out;
6140 }
6141
6142 if (fcport->loop_id == FC_NO_LOOP_ID ||
6143 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6144 memcmp(fcport->port_name, pd->port_name, 8))) {
6145 /* We lost the device mid way. */
6146 rval = QLA_NOT_LOGGED_IN;
6147 goto gpd_error_out;
6148 }
6149
6150 /* Names are little-endian. */
6151 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6152 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6153
6154 /* Get port_id of device. */
6155 fcport->d_id.b.domain = pd->port_id[0];
6156 fcport->d_id.b.area = pd->port_id[1];
6157 fcport->d_id.b.al_pa = pd->port_id[2];
6158 fcport->d_id.b.rsvd_1 = 0;
6159
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006160 if (fcport->fc4f_nvme) {
6161 fcport->nvme_prli_service_param =
6162 pd->prli_nvme_svc_param_word_3;
6163 fcport->port_type = FCT_NVME;
6164 } else {
6165 /* If not target must be initiator or unknown type. */
6166 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6167 fcport->port_type = FCT_INITIATOR;
6168 else
6169 fcport->port_type = FCT_TARGET;
6170 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006171 /* Passback COS information. */
6172 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6173 FC_COS_CLASS2 : FC_COS_CLASS3;
6174
6175 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6176 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6177 fcport->conf_compl_supported = 1;
6178 }
6179
6180gpd_error_out:
6181 return rval;
6182}
6183
6184/*
6185 * qla24xx_gidlist__wait
6186 * NOTE: don't call this routine from DPC thread.
6187 */
6188int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6189 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6190{
6191 int rval = QLA_FUNCTION_FAILED;
6192 mbx_cmd_t mc;
6193
6194 if (!vha->hw->flags.fw_started)
6195 goto done;
6196
6197 memset(&mc, 0, sizeof(mc));
6198 mc.mb[0] = MBC_GET_ID_LIST;
6199 mc.mb[2] = MSW(id_list_dma);
6200 mc.mb[3] = LSW(id_list_dma);
6201 mc.mb[6] = MSW(MSD(id_list_dma));
6202 mc.mb[7] = LSW(MSD(id_list_dma));
6203 mc.mb[8] = 0;
6204 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6205
6206 rval = qla24xx_send_mb_cmd(vha, &mc);
6207 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006208 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6209 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006210 } else {
6211 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006212 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6213 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006214 }
6215done:
6216 return rval;
6217}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006218
6219int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6220{
6221 int rval;
6222 mbx_cmd_t mc;
6223 mbx_cmd_t *mcp = &mc;
6224
6225 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6226 "Entered %s\n", __func__);
6227
6228 memset(mcp->mb, 0 , sizeof(mcp->mb));
6229 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6230 mcp->mb[1] = cpu_to_le16(1);
6231 mcp->mb[2] = cpu_to_le16(value);
6232 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6233 mcp->in_mb = MBX_2 | MBX_0;
6234 mcp->tov = MBX_TOV_SECONDS;
6235 mcp->flags = 0;
6236
6237 rval = qla2x00_mailbox_command(vha, mcp);
6238
6239 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6240 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6241
6242 return rval;
6243}
6244
6245int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6246{
6247 int rval;
6248 mbx_cmd_t mc;
6249 mbx_cmd_t *mcp = &mc;
6250
6251 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6252 "Entered %s\n", __func__);
6253
6254 memset(mcp->mb, 0, sizeof(mcp->mb));
6255 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6256 mcp->mb[1] = cpu_to_le16(0);
6257 mcp->out_mb = MBX_1 | MBX_0;
6258 mcp->in_mb = MBX_2 | MBX_0;
6259 mcp->tov = MBX_TOV_SECONDS;
6260 mcp->flags = 0;
6261
6262 rval = qla2x00_mailbox_command(vha, mcp);
6263 if (rval == QLA_SUCCESS)
6264 *value = mc.mb[2];
6265
6266 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6267 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6268
6269 return rval;
6270}
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006271
6272int
6273qla2x00_read_sfp_dev(struct scsi_qla_host *vha, char *buf, int count)
6274{
6275 struct qla_hw_data *ha = vha->hw;
6276 uint16_t iter, addr, offset;
6277 dma_addr_t phys_addr;
6278 int rval, c;
6279 u8 *sfp_data;
6280
6281 memset(ha->sfp_data, 0, SFP_DEV_SIZE);
6282 addr = 0xa0;
6283 phys_addr = ha->sfp_data_dma;
6284 sfp_data = ha->sfp_data;
6285 offset = c = 0;
6286
6287 for (iter = 0; iter < SFP_DEV_SIZE / SFP_BLOCK_SIZE; iter++) {
6288 if (iter == 4) {
6289 /* Skip to next device address. */
6290 addr = 0xa2;
6291 offset = 0;
6292 }
6293
6294 rval = qla2x00_read_sfp(vha, phys_addr, sfp_data,
6295 addr, offset, SFP_BLOCK_SIZE, BIT_1);
6296 if (rval != QLA_SUCCESS) {
6297 ql_log(ql_log_warn, vha, 0x706d,
6298 "Unable to read SFP data (%x/%x/%x).\n", rval,
6299 addr, offset);
6300
6301 return rval;
6302 }
6303
6304 if (buf && (c < count)) {
6305 u16 sz;
6306
6307 if ((count - c) >= SFP_BLOCK_SIZE)
6308 sz = SFP_BLOCK_SIZE;
6309 else
6310 sz = count - c;
6311
6312 memcpy(buf, sfp_data, sz);
6313 buf += SFP_BLOCK_SIZE;
6314 c += sz;
6315 }
6316 phys_addr += SFP_BLOCK_SIZE;
6317 sfp_data += SFP_BLOCK_SIZE;
6318 offset += SFP_BLOCK_SIZE;
6319 }
6320
6321 return rval;
6322}
Quinn Tran94d83e32017-12-28 12:33:23 -08006323
6324int qla24xx_res_count_wait(struct scsi_qla_host *vha,
6325 uint16_t *out_mb, int out_mb_sz)
6326{
6327 int rval = QLA_FUNCTION_FAILED;
6328 mbx_cmd_t mc;
6329
6330 if (!vha->hw->flags.fw_started)
6331 goto done;
6332
6333 memset(&mc, 0, sizeof(mc));
6334 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
6335
6336 rval = qla24xx_send_mb_cmd(vha, &mc);
6337 if (rval != QLA_SUCCESS) {
6338 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6339 "%s: fail\n", __func__);
6340 } else {
6341 if (out_mb_sz <= SIZEOF_IOCB_MB_REG)
6342 memcpy(out_mb, mc.mb, out_mb_sz);
6343 else
6344 memcpy(out_mb, mc.mb, SIZEOF_IOCB_MB_REG);
6345
6346 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6347 "%s: done\n", __func__);
6348 }
6349done:
6350 return rval;
6351}