blob: 735079ba691c63ead9837b1259315044a6859e5e [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 }
Sawan Chandak75d560e2016-07-06 11:14:33 -0400506 ql_dbg(ql_dbg_mbx, vha, 0x1198,
Joe Carnuccio050dc762017-08-23 15:05:14 -0700507 "host_status=%#x intr_ctrl=%#x intr_status=%#x\n",
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400508 RD_REG_DWORD(&reg->isp24.host_status),
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400509 RD_REG_DWORD(&reg->isp24.ictrl),
510 RD_REG_DWORD(&reg->isp24.istatus));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700512 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 return rval;
516}
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800519qla2x00_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 -0800520 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
522 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800523 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 mbx_cmd_t mc;
525 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400527 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
528 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Andrew Vasqueze4289242007-07-19 15:05:56 -0700530 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800531 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
532 mcp->mb[8] = MSW(risc_addr);
533 mcp->out_mb = MBX_8|MBX_0;
534 } else {
535 mcp->mb[0] = MBC_LOAD_RISC_RAM;
536 mcp->out_mb = MBX_0;
537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 mcp->mb[1] = LSW(risc_addr);
539 mcp->mb[2] = MSW(req_dma);
540 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 mcp->mb[6] = MSW(MSD(req_dma));
542 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800543 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700544 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700545 mcp->mb[4] = MSW(risc_code_size);
546 mcp->mb[5] = LSW(risc_code_size);
547 mcp->out_mb |= MBX_5|MBX_4;
548 } else {
549 mcp->mb[4] = LSW(risc_code_size);
550 mcp->out_mb |= MBX_4;
551 }
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700554 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800556 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700559 ql_dbg(ql_dbg_mbx, vha, 0x1023,
560 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400562 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
563 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565
566 return rval;
567}
568
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700569#define EXTENDED_BB_CREDITS BIT_0
Duane Grigsbye84067d2017-06-21 13:48:43 -0700570#define NVME_ENABLE_FLAG BIT_3
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700571static inline uint16_t qla25xx_set_sfp_lr_dist(struct qla_hw_data *ha)
572{
573 uint16_t mb4 = BIT_0;
574
575 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
576 mb4 |= ha->long_range_distance << LR_DIST_FW_POS;
577
578 return mb4;
579}
580
581static inline uint16_t qla25xx_set_nvr_lr_dist(struct qla_hw_data *ha)
582{
583 uint16_t mb4 = BIT_0;
584
585 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
586 struct nvram_81xx *nv = ha->nvram;
587
588 mb4 |= LR_DIST_FW_FIELD(nv->enhanced_features);
589 }
590
591 return mb4;
592}
Duane Grigsbye84067d2017-06-21 13:48:43 -0700593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594/*
595 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700596 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 *
598 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700599 * ha = adapter block pointer.
600 * TARGET_QUEUE_LOCK must be released.
601 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 *
603 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700604 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 *
606 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700607 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 */
609int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800610qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611{
612 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800613 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 mbx_cmd_t mc;
615 mbx_cmd_t *mcp = &mc;
616
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400617 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
618 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700621 mcp->out_mb = MBX_0;
622 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700623 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700624 mcp->mb[1] = MSW(risc_addr);
625 mcp->mb[2] = LSW(risc_addr);
626 mcp->mb[3] = 0;
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700627 mcp->mb[4] = 0;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700628 ha->flags.using_lr_setting = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500629 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
630 IS_QLA27XX(ha)) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700631 if (ql2xautodetectsfp) {
632 if (ha->flags.detected_lr_sfp) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700633 mcp->mb[4] |=
634 qla25xx_set_sfp_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700635 ha->flags.using_lr_setting = 1;
636 }
637 } else {
638 struct nvram_81xx *nv = ha->nvram;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700639 /* set LR distance if specified in nvram */
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700640 if (nv->enhanced_features &
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700641 NEF_LR_DIST_ENABLE) {
642 mcp->mb[4] |=
643 qla25xx_set_nvr_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700644 ha->flags.using_lr_setting = 1;
645 }
646 }
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700647 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500648
Duane Grigsbye84067d2017-06-21 13:48:43 -0700649 if (ql2xnvmeenable && IS_QLA27XX(ha))
650 mcp->mb[4] |= NVME_ENABLE_FLAG;
651
Sawan Chandak92d44082017-08-23 15:05:16 -0700652 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
653 struct nvram_81xx *nv = ha->nvram;
654 /* set minimum speed if specified in nvram */
655 if (nv->min_link_speed >= 2 &&
656 nv->min_link_speed <= 5) {
657 mcp->mb[4] |= BIT_4;
658 mcp->mb[11] = nv->min_link_speed;
659 mcp->out_mb |= MBX_11;
660 mcp->in_mb |= BIT_5;
661 vha->min_link_speed_feat = nv->min_link_speed;
662 }
663 }
664
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500665 if (ha->flags.exlogins_enabled)
666 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
667
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500668 if (ha->flags.exchoffld_enabled)
669 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
670
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700671 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700672 mcp->in_mb |= MBX_3 | MBX_2 | MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700673 } else {
674 mcp->mb[1] = LSW(risc_addr);
675 mcp->out_mb |= MBX_1;
676 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
677 mcp->mb[2] = 0;
678 mcp->out_mb |= MBX_2;
679 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 }
681
Ravi Anandb93480e2008-04-03 13:13:25 -0700682 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800684 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700686 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700687 ql_dbg(ql_dbg_mbx, vha, 0x1026,
688 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700689 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700690 if (IS_FWI2_CAPABLE(ha)) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700691 ha->fw_ability_mask = mcp->mb[3] << 16 | mcp->mb[2];
692 ql_dbg(ql_dbg_mbx, vha, 0x119a,
693 "fw_ability_mask=%x.\n", ha->fw_ability_mask);
Sawan Chandak92d44082017-08-23 15:05:16 -0700694 ql_dbg(ql_dbg_mbx, vha, 0x1027,
695 "exchanges=%x.\n", mcp->mb[1]);
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700696 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
697 ha->max_speed_sup = mcp->mb[2] & BIT_0;
Sawan Chandak92d44082017-08-23 15:05:16 -0700698 ql_dbg(ql_dbg_mbx, vha, 0x119b,
699 "Maximum speed supported=%s.\n",
700 ha->max_speed_sup ? "32Gps" : "16Gps");
701 if (vha->min_link_speed_feat) {
702 ha->min_link_speed = mcp->mb[5];
703 ql_dbg(ql_dbg_mbx, vha, 0x119c,
704 "Minimum speed set=%s.\n",
705 mcp->mb[5] == 5 ? "32Gps" :
706 mcp->mb[5] == 4 ? "16Gps" :
707 mcp->mb[5] == 3 ? "8Gps" :
708 mcp->mb[5] == 2 ? "4Gps" :
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700709 "unknown");
Sawan Chandak92d44082017-08-23 15:05:16 -0700710 }
711 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700712 }
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
714 "Done.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 return rval;
718}
719
720/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500721 * qla_get_exlogin_status
722 * Get extended login status
723 * uses the memory offload control/status Mailbox
724 *
725 * Input:
726 * ha: adapter state pointer.
727 * fwopt: firmware options
728 *
729 * Returns:
730 * qla2x00 local function status
731 *
732 * Context:
733 * Kernel context.
734 */
735#define FETCH_XLOGINS_STAT 0x8
736int
737qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
738 uint16_t *ex_logins_cnt)
739{
740 int rval;
741 mbx_cmd_t mc;
742 mbx_cmd_t *mcp = &mc;
743
744 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
745 "Entered %s\n", __func__);
746
747 memset(mcp->mb, 0 , sizeof(mcp->mb));
748 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
749 mcp->mb[1] = FETCH_XLOGINS_STAT;
750 mcp->out_mb = MBX_1|MBX_0;
751 mcp->in_mb = MBX_10|MBX_4|MBX_0;
752 mcp->tov = MBX_TOV_SECONDS;
753 mcp->flags = 0;
754
755 rval = qla2x00_mailbox_command(vha, mcp);
756 if (rval != QLA_SUCCESS) {
757 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
758 } else {
759 *buf_sz = mcp->mb[4];
760 *ex_logins_cnt = mcp->mb[10];
761
762 ql_log(ql_log_info, vha, 0x1190,
763 "buffer size 0x%x, exchange login count=%d\n",
764 mcp->mb[4], mcp->mb[10]);
765
766 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
767 "Done %s.\n", __func__);
768 }
769
770 return rval;
771}
772
773/*
774 * qla_set_exlogin_mem_cfg
775 * set extended login memory configuration
776 * Mbx needs to be issues before init_cb is set
777 *
778 * Input:
779 * ha: adapter state pointer.
780 * buffer: buffer pointer
781 * phys_addr: physical address of buffer
782 * size: size of buffer
783 * TARGET_QUEUE_LOCK must be released
784 * ADAPTER_STATE_LOCK must be release
785 *
786 * Returns:
787 * qla2x00 local funxtion status code.
788 *
789 * Context:
790 * Kernel context.
791 */
792#define CONFIG_XLOGINS_MEM 0x3
793int
794qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
795{
796 int rval;
797 mbx_cmd_t mc;
798 mbx_cmd_t *mcp = &mc;
799 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500800
801 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
802 "Entered %s.\n", __func__);
803
804 memset(mcp->mb, 0 , sizeof(mcp->mb));
805 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
806 mcp->mb[1] = CONFIG_XLOGINS_MEM;
807 mcp->mb[2] = MSW(phys_addr);
808 mcp->mb[3] = LSW(phys_addr);
809 mcp->mb[6] = MSW(MSD(phys_addr));
810 mcp->mb[7] = LSW(MSD(phys_addr));
811 mcp->mb[8] = MSW(ha->exlogin_size);
812 mcp->mb[9] = LSW(ha->exlogin_size);
813 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
814 mcp->in_mb = MBX_11|MBX_0;
815 mcp->tov = MBX_TOV_SECONDS;
816 mcp->flags = 0;
817 rval = qla2x00_mailbox_command(vha, mcp);
818 if (rval != QLA_SUCCESS) {
819 /*EMPTY*/
820 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
821 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500822 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
823 "Done %s.\n", __func__);
824 }
825
826 return rval;
827}
828
829/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500830 * qla_get_exchoffld_status
831 * Get exchange offload status
832 * uses the memory offload control/status Mailbox
833 *
834 * Input:
835 * ha: adapter state pointer.
836 * fwopt: firmware options
837 *
838 * Returns:
839 * qla2x00 local function status
840 *
841 * Context:
842 * Kernel context.
843 */
844#define FETCH_XCHOFFLD_STAT 0x2
845int
846qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
847 uint16_t *ex_logins_cnt)
848{
849 int rval;
850 mbx_cmd_t mc;
851 mbx_cmd_t *mcp = &mc;
852
853 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
854 "Entered %s\n", __func__);
855
856 memset(mcp->mb, 0 , sizeof(mcp->mb));
857 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
858 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
859 mcp->out_mb = MBX_1|MBX_0;
860 mcp->in_mb = MBX_10|MBX_4|MBX_0;
861 mcp->tov = MBX_TOV_SECONDS;
862 mcp->flags = 0;
863
864 rval = qla2x00_mailbox_command(vha, mcp);
865 if (rval != QLA_SUCCESS) {
866 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
867 } else {
868 *buf_sz = mcp->mb[4];
869 *ex_logins_cnt = mcp->mb[10];
870
871 ql_log(ql_log_info, vha, 0x118e,
872 "buffer size 0x%x, exchange offload count=%d\n",
873 mcp->mb[4], mcp->mb[10]);
874
875 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
876 "Done %s.\n", __func__);
877 }
878
879 return rval;
880}
881
882/*
883 * qla_set_exchoffld_mem_cfg
884 * Set exchange offload memory configuration
885 * Mbx needs to be issues before init_cb is set
886 *
887 * Input:
888 * ha: adapter state pointer.
889 * buffer: buffer pointer
890 * phys_addr: physical address of buffer
891 * size: size of buffer
892 * TARGET_QUEUE_LOCK must be released
893 * ADAPTER_STATE_LOCK must be release
894 *
895 * Returns:
896 * qla2x00 local funxtion status code.
897 *
898 * Context:
899 * Kernel context.
900 */
901#define CONFIG_XCHOFFLD_MEM 0x3
902int
Quinn Tran99e1b682017-06-02 09:12:03 -0700903qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500904{
905 int rval;
906 mbx_cmd_t mc;
907 mbx_cmd_t *mcp = &mc;
908 struct qla_hw_data *ha = vha->hw;
909
910 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
911 "Entered %s.\n", __func__);
912
913 memset(mcp->mb, 0 , sizeof(mcp->mb));
914 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
915 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -0700916 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
917 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
918 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
919 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
920 mcp->mb[8] = MSW(ha->exchoffld_size);
921 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500922 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
923 mcp->in_mb = MBX_11|MBX_0;
924 mcp->tov = MBX_TOV_SECONDS;
925 mcp->flags = 0;
926 rval = qla2x00_mailbox_command(vha, mcp);
927 if (rval != QLA_SUCCESS) {
928 /*EMPTY*/
929 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
930 } else {
931 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
932 "Done %s.\n", __func__);
933 }
934
935 return rval;
936}
937
938/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939 * qla2x00_get_fw_version
940 * Get firmware version.
941 *
942 * Input:
943 * ha: adapter state pointer.
944 * major: pointer for major number.
945 * minor: pointer for minor number.
946 * subminor: pointer for subminor number.
947 *
948 * Returns:
949 * qla2x00 local function return status code.
950 *
951 * Context:
952 * Kernel context.
953 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700954int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800955qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
957 int rval;
958 mbx_cmd_t mc;
959 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800960 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400962 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
963 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
966 mcp->out_mb = MBX_0;
967 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400968 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700969 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400970 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800971 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500972 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400973 mcp->in_mb |=
974 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
975 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -0400976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700978 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800979 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700980 if (rval != QLA_SUCCESS)
981 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800984 ha->fw_major_version = mcp->mb[1];
985 ha->fw_minor_version = mcp->mb[2];
986 ha->fw_subminor_version = mcp->mb[3];
987 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800988 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800989 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800991 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -0400992
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400993 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800994 ha->mpi_version[0] = mcp->mb[10] & 0xff;
995 ha->mpi_version[1] = mcp->mb[11] >> 8;
996 ha->mpi_version[2] = mcp->mb[11] & 0xff;
997 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
998 ha->phy_version[0] = mcp->mb[8] & 0xff;
999 ha->phy_version[1] = mcp->mb[9] >> 8;
1000 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001001 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001002
Saurav Kashyap81178772012-08-22 14:21:04 -04001003 if (IS_FWI2_CAPABLE(ha)) {
1004 ha->fw_attributes_h = mcp->mb[15];
1005 ha->fw_attributes_ext[0] = mcp->mb[16];
1006 ha->fw_attributes_ext[1] = mcp->mb[17];
1007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
1008 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
1009 __func__, mcp->mb[15], mcp->mb[6]);
1010 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
1011 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
1012 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001013
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001014 if (ha->fw_attributes_h & 0x4)
1015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
1016 "%s: Firmware supports Extended Login 0x%x\n",
1017 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001018
1019 if (ha->fw_attributes_h & 0x8)
1020 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
1021 "%s: Firmware supports Exchange Offload 0x%x\n",
1022 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -07001023
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07001024 /*
1025 * FW supports nvme and driver load parameter requested nvme.
1026 * BIT 26 of fw_attributes indicates NVMe support.
1027 */
1028 if ((ha->fw_attributes_h & 0x400) && ql2xnvmeenable)
Duane Grigsbye84067d2017-06-21 13:48:43 -07001029 vha->flags.nvme_enabled = 1;
Duane Grigsbye84067d2017-06-21 13:48:43 -07001030
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001031 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001032
Chad Dupuisf73cb692014-02-26 04:15:06 -05001033 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -04001034 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1035 ha->mpi_version[1] = mcp->mb[11] >> 8;
1036 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1037 ha->pep_version[0] = mcp->mb[13] & 0xff;
1038 ha->pep_version[1] = mcp->mb[14] >> 8;
1039 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001040 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
1041 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001042 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
1043 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -05001044 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001045
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001046failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 if (rval != QLA_SUCCESS) {
1048 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001049 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 } else {
1051 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001052 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
1053 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001055 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056}
1057
1058/*
1059 * qla2x00_get_fw_options
1060 * Set firmware options.
1061 *
1062 * Input:
1063 * ha = adapter block pointer.
1064 * fwopt = pointer for firmware options.
1065 *
1066 * Returns:
1067 * qla2x00 local function return status code.
1068 *
1069 * Context:
1070 * Kernel context.
1071 */
1072int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001073qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074{
1075 int rval;
1076 mbx_cmd_t mc;
1077 mbx_cmd_t *mcp = &mc;
1078
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001079 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1080 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081
1082 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1083 mcp->out_mb = MBX_0;
1084 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001085 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001087 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
1089 if (rval != QLA_SUCCESS) {
1090 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001091 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001093 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 fwopts[1] = mcp->mb[1];
1095 fwopts[2] = mcp->mb[2];
1096 fwopts[3] = mcp->mb[3];
1097
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001098 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1099 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 }
1101
1102 return rval;
1103}
1104
1105
1106/*
1107 * qla2x00_set_fw_options
1108 * Set firmware options.
1109 *
1110 * Input:
1111 * ha = adapter block pointer.
1112 * fwopt = pointer for firmware options.
1113 *
1114 * Returns:
1115 * qla2x00 local function return status code.
1116 *
1117 * Context:
1118 * Kernel context.
1119 */
1120int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001121qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122{
1123 int rval;
1124 mbx_cmd_t mc;
1125 mbx_cmd_t *mcp = &mc;
1126
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001127 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1128 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1131 mcp->mb[1] = fwopts[1];
1132 mcp->mb[2] = fwopts[2];
1133 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001134 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001136 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001137 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001138 mcp->mb[10] = fwopts[10];
1139 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001140 } else {
1141 mcp->mb[10] = fwopts[10];
1142 mcp->mb[11] = fwopts[11];
1143 mcp->mb[12] = 0; /* Undocumented, but used */
1144 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1145 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001146 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001148 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001150 fwopts[0] = mcp->mb[0];
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 if (rval != QLA_SUCCESS) {
1153 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001154 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1155 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 } else {
1157 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001158 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1159 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 }
1161
1162 return rval;
1163}
1164
1165/*
1166 * qla2x00_mbx_reg_test
1167 * Mailbox register wrap test.
1168 *
1169 * Input:
1170 * ha = adapter block pointer.
1171 * TARGET_QUEUE_LOCK must be released.
1172 * ADAPTER_STATE_LOCK must be released.
1173 *
1174 * Returns:
1175 * qla2x00 local function return status code.
1176 *
1177 * Context:
1178 * Kernel context.
1179 */
1180int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001181qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182{
1183 int rval;
1184 mbx_cmd_t mc;
1185 mbx_cmd_t *mcp = &mc;
1186
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001187 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1188 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1191 mcp->mb[1] = 0xAAAA;
1192 mcp->mb[2] = 0x5555;
1193 mcp->mb[3] = 0xAA55;
1194 mcp->mb[4] = 0x55AA;
1195 mcp->mb[5] = 0xA5A5;
1196 mcp->mb[6] = 0x5A5A;
1197 mcp->mb[7] = 0x2525;
1198 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1199 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 -07001200 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001202 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203
1204 if (rval == QLA_SUCCESS) {
1205 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1206 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1207 rval = QLA_FUNCTION_FAILED;
1208 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1209 mcp->mb[7] != 0x2525)
1210 rval = QLA_FUNCTION_FAILED;
1211 }
1212
1213 if (rval != QLA_SUCCESS) {
1214 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001215 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 } else {
1217 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001218 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1219 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 }
1221
1222 return rval;
1223}
1224
1225/*
1226 * qla2x00_verify_checksum
1227 * Verify firmware checksum.
1228 *
1229 * Input:
1230 * ha = adapter block pointer.
1231 * TARGET_QUEUE_LOCK must be released.
1232 * ADAPTER_STATE_LOCK must be released.
1233 *
1234 * Returns:
1235 * qla2x00 local function return status code.
1236 *
1237 * Context:
1238 * Kernel context.
1239 */
1240int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001241qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242{
1243 int rval;
1244 mbx_cmd_t mc;
1245 mbx_cmd_t *mcp = &mc;
1246
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001247 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1248 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249
1250 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001251 mcp->out_mb = MBX_0;
1252 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001253 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001254 mcp->mb[1] = MSW(risc_addr);
1255 mcp->mb[2] = LSW(risc_addr);
1256 mcp->out_mb |= MBX_2|MBX_1;
1257 mcp->in_mb |= MBX_2|MBX_1;
1258 } else {
1259 mcp->mb[1] = LSW(risc_addr);
1260 mcp->out_mb |= MBX_1;
1261 mcp->in_mb |= MBX_1;
1262 }
1263
Ravi Anandb93480e2008-04-03 13:13:25 -07001264 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001266 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001269 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1270 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1271 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001273 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1274 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 }
1276
1277 return rval;
1278}
1279
1280/*
1281 * qla2x00_issue_iocb
1282 * Issue IOCB using mailbox command
1283 *
1284 * Input:
1285 * ha = adapter state pointer.
1286 * buffer = buffer pointer.
1287 * phys_addr = physical address of buffer.
1288 * size = size of buffer.
1289 * TARGET_QUEUE_LOCK must be released.
1290 * ADAPTER_STATE_LOCK must be released.
1291 *
1292 * Returns:
1293 * qla2x00 local function return status code.
1294 *
1295 * Context:
1296 * Kernel context.
1297 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001298int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001299qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001300 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301{
1302 int rval;
1303 mbx_cmd_t mc;
1304 mbx_cmd_t *mcp = &mc;
1305
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001306 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1307 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001308
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1310 mcp->mb[1] = 0;
1311 mcp->mb[2] = MSW(phys_addr);
1312 mcp->mb[3] = LSW(phys_addr);
1313 mcp->mb[6] = MSW(MSD(phys_addr));
1314 mcp->mb[7] = LSW(MSD(phys_addr));
1315 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1316 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001317 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001319 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
1321 if (rval != QLA_SUCCESS) {
1322 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001323 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001325 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1326
1327 /* Mask reserved bits. */
1328 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001329 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001330 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1331 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333
1334 return rval;
1335}
1336
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001337int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001338qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001339 size_t size)
1340{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001341 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001342 MBX_TOV_SECONDS);
1343}
1344
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345/*
1346 * qla2x00_abort_command
1347 * Abort command aborts a specified IOCB.
1348 *
1349 * Input:
1350 * ha = adapter block pointer.
1351 * sp = SB structure pointer.
1352 *
1353 * Returns:
1354 * qla2x00 local function return status code.
1355 *
1356 * Context:
1357 * Kernel context.
1358 */
1359int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001360qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361{
1362 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001364 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 mbx_cmd_t mc;
1366 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001367 fc_port_t *fcport = sp->fcport;
1368 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001369 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001370 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001371 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001373 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1374 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
Michael Hernandezd7459522016-12-12 14:40:07 -08001376 if (vha->flags.qpairs_available && sp->qpair)
1377 req = sp->qpair->req;
1378 else
1379 req = vha->req;
1380
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001381 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001382 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001383 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 break;
1385 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001386 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Chad Dupuis8d93f552013-01-30 03:34:37 -05001388 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 /* command not found */
1390 return QLA_FUNCTION_FAILED;
1391 }
1392
1393 mcp->mb[0] = MBC_ABORT_COMMAND;
1394 if (HAS_EXTENDED_IDS(ha))
1395 mcp->mb[1] = fcport->loop_id;
1396 else
1397 mcp->mb[1] = fcport->loop_id << 8;
1398 mcp->mb[2] = (uint16_t)handle;
1399 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001400 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1402 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001403 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001405 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406
1407 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001408 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001410 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1411 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413
1414 return rval;
1415}
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001418qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001420 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 mbx_cmd_t mc;
1422 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001423 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001424 struct req_que *req;
1425 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Andrew Vasquez523ec772008-04-03 13:13:24 -07001427 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001428 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001429
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001430 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1431 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001432
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001433 req = vha->hw->req_q_map[0];
1434 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001436 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001437 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 mcp->mb[1] = fcport->loop_id;
1439 mcp->mb[10] = 0;
1440 mcp->out_mb |= MBX_10;
1441 } else {
1442 mcp->mb[1] = fcport->loop_id << 8;
1443 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001444 mcp->mb[2] = vha->hw->loop_reset_delay;
1445 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001448 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001450 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001452 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1453 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001454 }
1455
1456 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001457 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1458 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001459 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001460 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1461 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001463 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1464 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001465 }
1466
1467 return rval;
1468}
1469
1470int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001471qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001472{
1473 int rval, rval2;
1474 mbx_cmd_t mc;
1475 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001476 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001477 struct req_que *req;
1478 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001479
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001480 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001481
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001482 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1483 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001484
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001485 req = vha->hw->req_q_map[0];
1486 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001487 mcp->mb[0] = MBC_LUN_RESET;
1488 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001489 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001490 mcp->mb[1] = fcport->loop_id;
1491 else
1492 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001493 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001494 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001495 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001496
1497 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001498 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001499 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001500 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001501 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001502 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001503 }
1504
1505 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001506 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1507 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001508 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001509 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1510 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001511 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001512 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1513 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
1515
1516 return rval;
1517}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 * qla2x00_get_adapter_id
1521 * Get adapter ID and topology.
1522 *
1523 * Input:
1524 * ha = adapter block pointer.
1525 * id = pointer for loop ID.
1526 * al_pa = pointer for AL_PA.
1527 * area = pointer for area.
1528 * domain = pointer for domain.
1529 * top = pointer for topology.
1530 * TARGET_QUEUE_LOCK must be released.
1531 * ADAPTER_STATE_LOCK must be released.
1532 *
1533 * Returns:
1534 * qla2x00 local function return status code.
1535 *
1536 * Context:
1537 * Kernel context.
1538 */
1539int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001540qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001541 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542{
1543 int rval;
1544 mbx_cmd_t mc;
1545 mbx_cmd_t *mcp = &mc;
1546
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001547 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1548 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549
1550 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001551 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001552 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001553 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001554 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001555 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001556 if (IS_FWI2_CAPABLE(vha->hw))
1557 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001558 if (IS_QLA27XX(vha->hw))
1559 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001560 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001562 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001563 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1564 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001565 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1566 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 /* Return data. */
1569 *id = mcp->mb[1];
1570 *al_pa = LSB(mcp->mb[2]);
1571 *area = MSB(mcp->mb[2]);
1572 *domain = LSB(mcp->mb[3]);
1573 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001574 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575
1576 if (rval != QLA_SUCCESS) {
1577 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001578 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1581 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001582
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001583 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001584 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1585 vha->fcoe_fcf_idx = mcp->mb[10];
1586 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1587 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1588 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1589 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1590 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1591 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1592 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001593 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001594 if (IS_FAWWN_CAPABLE(vha->hw)) {
1595 if (mcp->mb[7] & BIT_14) {
1596 vha->port_name[0] = MSB(mcp->mb[16]);
1597 vha->port_name[1] = LSB(mcp->mb[16]);
1598 vha->port_name[2] = MSB(mcp->mb[17]);
1599 vha->port_name[3] = LSB(mcp->mb[17]);
1600 vha->port_name[4] = MSB(mcp->mb[18]);
1601 vha->port_name[5] = LSB(mcp->mb[18]);
1602 vha->port_name[6] = MSB(mcp->mb[19]);
1603 vha->port_name[7] = LSB(mcp->mb[19]);
1604 fc_host_port_name(vha->host) =
1605 wwn_to_u64(vha->port_name);
1606 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1607 "FA-WWN acquired %016llx\n",
1608 wwn_to_u64(vha->port_name));
1609 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001610 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001611
1612 if (IS_QLA27XX(vha->hw))
1613 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 }
1615
1616 return rval;
1617}
1618
1619/*
1620 * qla2x00_get_retry_cnt
1621 * Get current firmware login retry count and delay.
1622 *
1623 * Input:
1624 * ha = adapter block pointer.
1625 * retry_cnt = pointer to login retry count.
1626 * tov = pointer to login timeout value.
1627 *
1628 * Returns:
1629 * qla2x00 local function return status code.
1630 *
1631 * Context:
1632 * Kernel context.
1633 */
1634int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001635qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 uint16_t *r_a_tov)
1637{
1638 int rval;
1639 uint16_t ratov;
1640 mbx_cmd_t mc;
1641 mbx_cmd_t *mcp = &mc;
1642
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001643 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1644 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
1646 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1647 mcp->out_mb = MBX_0;
1648 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001649 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001651 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
1653 if (rval != QLA_SUCCESS) {
1654 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001655 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1656 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 } else {
1658 /* Convert returned data and check our values. */
1659 *r_a_tov = mcp->mb[3] / 2;
1660 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1661 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1662 /* Update to the larger values */
1663 *retry_cnt = (uint8_t)mcp->mb[1];
1664 *tov = ratov;
1665 }
1666
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001667 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001668 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
1670
1671 return rval;
1672}
1673
1674/*
1675 * qla2x00_init_firmware
1676 * Initialize adapter firmware.
1677 *
1678 * Input:
1679 * ha = adapter block pointer.
1680 * dptr = Initialization control block pointer.
1681 * size = size of initialization control block.
1682 * TARGET_QUEUE_LOCK must be released.
1683 * ADAPTER_STATE_LOCK must be released.
1684 *
1685 * Returns:
1686 * qla2x00 local function return status code.
1687 *
1688 * Context:
1689 * Kernel context.
1690 */
1691int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001692qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693{
1694 int rval;
1695 mbx_cmd_t mc;
1696 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001697 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001699 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1700 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001702 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001703 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001704 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1705
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001706 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001707 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1708 else
1709 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1710
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001711 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 mcp->mb[2] = MSW(ha->init_cb_dma);
1713 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1715 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001716 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001717 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001718 mcp->mb[1] = BIT_0;
1719 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1720 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1721 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1722 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1723 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1724 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1725 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001726 /* 1 and 2 should normally be captured. */
1727 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001728 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001729 /* mb3 is additional info about the installed SFP. */
1730 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 mcp->buf_size = size;
1732 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001733 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001734 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
1736 if (rval != QLA_SUCCESS) {
1737 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001738 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001739 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1740 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 } else {
Sawan Chandak92d44082017-08-23 15:05:16 -07001742 if (IS_QLA27XX(ha)) {
1743 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1744 ql_dbg(ql_dbg_mbx, vha, 0x119d,
1745 "Invalid SFP/Validation Failed\n");
1746 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001747 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1748 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 }
1750
1751 return rval;
1752}
1753
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001754
1755/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 * qla2x00_get_port_database
1757 * Issue normal/enhanced get port database mailbox command
1758 * and copy device name as necessary.
1759 *
1760 * Input:
1761 * ha = adapter state pointer.
1762 * dev = structure pointer.
1763 * opt = enhanced cmd option byte.
1764 *
1765 * Returns:
1766 * qla2x00 local function return status code.
1767 *
1768 * Context:
1769 * Kernel context.
1770 */
1771int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001772qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773{
1774 int rval;
1775 mbx_cmd_t mc;
1776 mbx_cmd_t *mcp = &mc;
1777 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001778 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001780 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001782 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1783 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001785 pd24 = NULL;
Thomas Meyer08eb7f42017-09-21 08:15:26 +02001786 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001788 ql_log(ql_log_warn, vha, 0x1050,
1789 "Failed to allocate port database structure.\n");
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001790 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791 return QLA_MEMORY_ALLOC_FAILED;
1792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001794 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001795 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 mcp->mb[2] = MSW(pd_dma);
1798 mcp->mb[3] = LSW(pd_dma);
1799 mcp->mb[6] = MSW(MSD(pd_dma));
1800 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001801 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001802 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001804 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001805 mcp->mb[1] = fcport->loop_id;
1806 mcp->mb[10] = opt;
1807 mcp->out_mb |= MBX_10|MBX_1;
1808 mcp->in_mb |= MBX_1;
1809 } else if (HAS_EXTENDED_IDS(ha)) {
1810 mcp->mb[1] = fcport->loop_id;
1811 mcp->mb[10] = opt;
1812 mcp->out_mb |= MBX_10|MBX_1;
1813 } else {
1814 mcp->mb[1] = fcport->loop_id << 8 | opt;
1815 mcp->out_mb |= MBX_1;
1816 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001817 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1818 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 mcp->flags = MBX_DMA_IN;
1820 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001821 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 if (rval != QLA_SUCCESS)
1823 goto gpd_error_out;
1824
Andrew Vasqueze4289242007-07-19 15:05:56 -07001825 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001826 uint64_t zero = 0;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001827 u8 current_login_state, last_login_state;
1828
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001829 pd24 = (struct port_database_24xx *) pd;
1830
1831 /* Check for logged in state. */
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001832 if (fcport->fc4f_nvme) {
1833 current_login_state = pd24->current_login_state >> 4;
1834 last_login_state = pd24->last_login_state >> 4;
1835 } else {
1836 current_login_state = pd24->current_login_state & 0xf;
1837 last_login_state = pd24->last_login_state & 0xf;
1838 }
1839 fcport->current_login_state = pd24->current_login_state;
1840 fcport->last_login_state = pd24->last_login_state;
1841
1842 /* Check for logged in state. */
1843 if (current_login_state != PDS_PRLI_COMPLETE &&
1844 last_login_state != PDS_PRLI_COMPLETE) {
1845 ql_dbg(ql_dbg_mbx, vha, 0x119a,
1846 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
1847 current_login_state, last_login_state,
1848 fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001849 rval = QLA_FUNCTION_FAILED;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001850
1851 if (!fcport->query)
1852 goto gpd_error_out;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001853 }
1854
Arun Easi0eba25d2012-02-09 11:15:58 -08001855 if (fcport->loop_id == FC_NO_LOOP_ID ||
1856 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1857 memcmp(fcport->port_name, pd24->port_name, 8))) {
1858 /* We lost the device mid way. */
1859 rval = QLA_NOT_LOGGED_IN;
1860 goto gpd_error_out;
1861 }
1862
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001863 /* Names are little-endian. */
1864 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1865 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1866
1867 /* Get port_id of device. */
1868 fcport->d_id.b.domain = pd24->port_id[0];
1869 fcport->d_id.b.area = pd24->port_id[1];
1870 fcport->d_id.b.al_pa = pd24->port_id[2];
1871 fcport->d_id.b.rsvd_1 = 0;
1872
1873 /* If not target must be initiator or unknown type. */
1874 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1875 fcport->port_type = FCT_INITIATOR;
1876 else
1877 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001878
1879 /* Passback COS information. */
1880 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1881 FC_COS_CLASS2 : FC_COS_CLASS3;
1882
1883 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1884 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001885 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001886 uint64_t zero = 0;
1887
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001888 /* Check for logged in state. */
1889 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1890 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001891 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1892 "Unable to verify login-state (%x/%x) - "
1893 "portid=%02x%02x%02x.\n", pd->master_state,
1894 pd->slave_state, fcport->d_id.b.domain,
1895 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001896 rval = QLA_FUNCTION_FAILED;
1897 goto gpd_error_out;
1898 }
1899
Arun Easi0eba25d2012-02-09 11:15:58 -08001900 if (fcport->loop_id == FC_NO_LOOP_ID ||
1901 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1902 memcmp(fcport->port_name, pd->port_name, 8))) {
1903 /* We lost the device mid way. */
1904 rval = QLA_NOT_LOGGED_IN;
1905 goto gpd_error_out;
1906 }
1907
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001908 /* Names are little-endian. */
1909 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1910 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1911
1912 /* Get port_id of device. */
1913 fcport->d_id.b.domain = pd->port_id[0];
1914 fcport->d_id.b.area = pd->port_id[3];
1915 fcport->d_id.b.al_pa = pd->port_id[2];
1916 fcport->d_id.b.rsvd_1 = 0;
1917
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001918 /* If not target must be initiator or unknown type. */
1919 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1920 fcport->port_type = FCT_INITIATOR;
1921 else
1922 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001923
1924 /* Passback COS information. */
1925 fcport->supported_classes = (pd->options & BIT_4) ?
1926 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 }
1928
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929gpd_error_out:
1930 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001931 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
1933 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001934 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1935 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1936 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001938 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1939 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 }
1941
1942 return rval;
1943}
1944
1945/*
1946 * qla2x00_get_firmware_state
1947 * Get adapter firmware state.
1948 *
1949 * Input:
1950 * ha = adapter block pointer.
1951 * dptr = pointer for firmware state.
1952 * TARGET_QUEUE_LOCK must be released.
1953 * ADAPTER_STATE_LOCK must be released.
1954 *
1955 * Returns:
1956 * qla2x00 local function return status code.
1957 *
1958 * Context:
1959 * Kernel context.
1960 */
1961int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001962qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963{
1964 int rval;
1965 mbx_cmd_t mc;
1966 mbx_cmd_t *mcp = &mc;
Sawan Chandak92d44082017-08-23 15:05:16 -07001967 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001969 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1970 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971
1972 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1973 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001974 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001975 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001976 else
1977 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001978 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001980 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001982 /* Return firmware states. */
1983 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001984 if (IS_FWI2_CAPABLE(vha->hw)) {
1985 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04001986 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001987 states[3] = mcp->mb[4];
1988 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001989 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
1992 if (rval != QLA_SUCCESS) {
1993 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001994 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 } else {
Sawan Chandak92d44082017-08-23 15:05:16 -07001996 if (IS_QLA27XX(ha)) {
1997 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1998 ql_dbg(ql_dbg_mbx, vha, 0x119e,
1999 "Invalid SFP/Validation Failed\n");
2000 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002001 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
2002 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003 }
2004
2005 return rval;
2006}
2007
2008/*
2009 * qla2x00_get_port_name
2010 * Issue get port name mailbox command.
2011 * Returned name is in big endian format.
2012 *
2013 * Input:
2014 * ha = adapter block pointer.
2015 * loop_id = loop ID of device.
2016 * name = pointer for name.
2017 * TARGET_QUEUE_LOCK must be released.
2018 * ADAPTER_STATE_LOCK must be released.
2019 *
2020 * Returns:
2021 * qla2x00 local function return status code.
2022 *
2023 * Context:
2024 * Kernel context.
2025 */
2026int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002027qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 uint8_t opt)
2029{
2030 int rval;
2031 mbx_cmd_t mc;
2032 mbx_cmd_t *mcp = &mc;
2033
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002034 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
2035 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
2037 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002038 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002039 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002040 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 mcp->mb[1] = loop_id;
2042 mcp->mb[10] = opt;
2043 mcp->out_mb |= MBX_10;
2044 } else {
2045 mcp->mb[1] = loop_id << 8 | opt;
2046 }
2047
2048 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002049 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002051 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
2053 if (rval != QLA_SUCCESS) {
2054 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002055 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 } else {
2057 if (name != NULL) {
2058 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002059 name[0] = MSB(mcp->mb[2]);
2060 name[1] = LSB(mcp->mb[2]);
2061 name[2] = MSB(mcp->mb[3]);
2062 name[3] = LSB(mcp->mb[3]);
2063 name[4] = MSB(mcp->mb[6]);
2064 name[5] = LSB(mcp->mb[6]);
2065 name[6] = MSB(mcp->mb[7]);
2066 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 }
2068
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002069 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2070 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 }
2072
2073 return rval;
2074}
2075
2076/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002077 * qla24xx_link_initialization
2078 * Issue link initialization mailbox command.
2079 *
2080 * Input:
2081 * ha = adapter block pointer.
2082 * TARGET_QUEUE_LOCK must be released.
2083 * ADAPTER_STATE_LOCK must be released.
2084 *
2085 * Returns:
2086 * qla2x00 local function return status code.
2087 *
2088 * Context:
2089 * Kernel context.
2090 */
2091int
2092qla24xx_link_initialize(scsi_qla_host_t *vha)
2093{
2094 int rval;
2095 mbx_cmd_t mc;
2096 mbx_cmd_t *mcp = &mc;
2097
2098 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2099 "Entered %s.\n", __func__);
2100
2101 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2102 return QLA_FUNCTION_FAILED;
2103
2104 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002105 mcp->mb[1] = BIT_4;
2106 if (vha->hw->operating_mode == LOOP)
2107 mcp->mb[1] |= BIT_6;
2108 else
2109 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002110 mcp->mb[2] = 0;
2111 mcp->mb[3] = 0;
2112 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2113 mcp->in_mb = MBX_0;
2114 mcp->tov = MBX_TOV_SECONDS;
2115 mcp->flags = 0;
2116 rval = qla2x00_mailbox_command(vha, mcp);
2117
2118 if (rval != QLA_SUCCESS) {
2119 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2120 } else {
2121 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2122 "Done %s.\n", __func__);
2123 }
2124
2125 return rval;
2126}
2127
2128/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 * qla2x00_lip_reset
2130 * Issue LIP reset mailbox command.
2131 *
2132 * Input:
2133 * ha = adapter block pointer.
2134 * TARGET_QUEUE_LOCK must be released.
2135 * ADAPTER_STATE_LOCK must be released.
2136 *
2137 * Returns:
2138 * qla2x00 local function return status code.
2139 *
2140 * Context:
2141 * Kernel context.
2142 */
2143int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002144qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
2146 int rval;
2147 mbx_cmd_t mc;
2148 mbx_cmd_t *mcp = &mc;
2149
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002150 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2151 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002153 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002154 /* Logout across all FCFs. */
2155 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2156 mcp->mb[1] = BIT_1;
2157 mcp->mb[2] = 0;
2158 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2159 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002160 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002161 mcp->mb[1] = BIT_6;
2162 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002163 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002164 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002166 mcp->mb[0] = MBC_LIP_RESET;
2167 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002168 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002169 mcp->mb[1] = 0x00ff;
2170 mcp->mb[10] = 0;
2171 mcp->out_mb |= MBX_10;
2172 } else {
2173 mcp->mb[1] = 0xff00;
2174 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002175 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002176 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002179 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002181 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183 if (rval != QLA_SUCCESS) {
2184 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002185 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 } else {
2187 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2189 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 }
2191
2192 return rval;
2193}
2194
2195/*
2196 * qla2x00_send_sns
2197 * Send SNS command.
2198 *
2199 * Input:
2200 * ha = adapter block pointer.
2201 * sns = pointer for command.
2202 * cmd_size = command size.
2203 * buf_size = response/command size.
2204 * TARGET_QUEUE_LOCK must be released.
2205 * ADAPTER_STATE_LOCK must be released.
2206 *
2207 * Returns:
2208 * qla2x00 local function return status code.
2209 *
2210 * Context:
2211 * Kernel context.
2212 */
2213int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002214qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 uint16_t cmd_size, size_t buf_size)
2216{
2217 int rval;
2218 mbx_cmd_t mc;
2219 mbx_cmd_t *mcp = &mc;
2220
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002221 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2222 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002224 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002225 "Retry cnt=%d ratov=%d total tov=%d.\n",
2226 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2229 mcp->mb[1] = cmd_size;
2230 mcp->mb[2] = MSW(sns_phys_address);
2231 mcp->mb[3] = LSW(sns_phys_address);
2232 mcp->mb[6] = MSW(MSD(sns_phys_address));
2233 mcp->mb[7] = LSW(MSD(sns_phys_address));
2234 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2235 mcp->in_mb = MBX_0|MBX_1;
2236 mcp->buf_size = buf_size;
2237 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002238 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2239 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
2241 if (rval != QLA_SUCCESS) {
2242 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002243 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2244 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2245 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 } else {
2247 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002248 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2249 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 }
2251
2252 return rval;
2253}
2254
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002255int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002256qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002257 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2258{
2259 int rval;
2260
2261 struct logio_entry_24xx *lg;
2262 dma_addr_t lg_dma;
2263 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002264 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002265 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002266
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002267 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2268 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002269
Michael Hernandezd7459522016-12-12 14:40:07 -08002270 if (vha->vp_idx && vha->qpair)
2271 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002272 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002273 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002274
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002275 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002276 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002277 ql_log(ql_log_warn, vha, 0x1062,
2278 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002279 return QLA_MEMORY_ALLOC_FAILED;
2280 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002281
2282 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2283 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002284 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002285 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002286 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002287 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002288 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002289 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002290 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002291 lg->port_id[0] = al_pa;
2292 lg->port_id[1] = area;
2293 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002294 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002295 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2296 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002297 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002298 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2299 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002300 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002301 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2302 "Failed to complete IOCB -- error status (%x).\n",
2303 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002304 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002305 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002306 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2307 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2308
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002309 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2310 "Failed to complete IOCB -- completion status (%x) "
2311 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2312 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002313
2314 switch (iop[0]) {
2315 case LSC_SCODE_PORTID_USED:
2316 mb[0] = MBS_PORT_ID_USED;
2317 mb[1] = LSW(iop[1]);
2318 break;
2319 case LSC_SCODE_NPORT_USED:
2320 mb[0] = MBS_LOOP_ID_USED;
2321 break;
2322 case LSC_SCODE_NOLINK:
2323 case LSC_SCODE_NOIOCB:
2324 case LSC_SCODE_NOXCB:
2325 case LSC_SCODE_CMD_FAILED:
2326 case LSC_SCODE_NOFABRIC:
2327 case LSC_SCODE_FW_NOT_READY:
2328 case LSC_SCODE_NOT_LOGGED_IN:
2329 case LSC_SCODE_NOPCB:
2330 case LSC_SCODE_ELS_REJECT:
2331 case LSC_SCODE_CMD_PARAM_ERR:
2332 case LSC_SCODE_NONPORT:
2333 case LSC_SCODE_LOGGED_IN:
2334 case LSC_SCODE_NOFLOGI_ACC:
2335 default:
2336 mb[0] = MBS_COMMAND_ERROR;
2337 break;
2338 }
2339 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002340 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2341 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002342
2343 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2344
2345 mb[0] = MBS_COMMAND_COMPLETE;
2346 mb[1] = 0;
2347 if (iop[0] & BIT_4) {
2348 if (iop[0] & BIT_8)
2349 mb[1] |= BIT_1;
2350 } else
2351 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002352
2353 /* Passback COS information. */
2354 mb[10] = 0;
2355 if (lg->io_parameter[7] || lg->io_parameter[8])
2356 mb[10] |= BIT_0; /* Class 2. */
2357 if (lg->io_parameter[9] || lg->io_parameter[10])
2358 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002359 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002360 mb[10] |= BIT_7; /* Confirmed Completion
2361 * Allowed
2362 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002363 }
2364
2365 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2366
2367 return rval;
2368}
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370/*
2371 * qla2x00_login_fabric
2372 * Issue login fabric port mailbox command.
2373 *
2374 * Input:
2375 * ha = adapter block pointer.
2376 * loop_id = device loop ID.
2377 * domain = device domain.
2378 * area = device area.
2379 * al_pa = device AL_PA.
2380 * status = pointer for return status.
2381 * opt = command options.
2382 * TARGET_QUEUE_LOCK must be released.
2383 * ADAPTER_STATE_LOCK must be released.
2384 *
2385 * Returns:
2386 * qla2x00 local function return status code.
2387 *
2388 * Context:
2389 * Kernel context.
2390 */
2391int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002392qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2394{
2395 int rval;
2396 mbx_cmd_t mc;
2397 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002398 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002400 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2401 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
2403 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2404 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2405 if (HAS_EXTENDED_IDS(ha)) {
2406 mcp->mb[1] = loop_id;
2407 mcp->mb[10] = opt;
2408 mcp->out_mb |= MBX_10;
2409 } else {
2410 mcp->mb[1] = (loop_id << 8) | opt;
2411 }
2412 mcp->mb[2] = domain;
2413 mcp->mb[3] = area << 8 | al_pa;
2414
2415 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2416 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2417 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002418 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
2420 /* Return mailbox statuses. */
2421 if (mb != NULL) {
2422 mb[0] = mcp->mb[0];
2423 mb[1] = mcp->mb[1];
2424 mb[2] = mcp->mb[2];
2425 mb[6] = mcp->mb[6];
2426 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002427 /* COS retrieved from Get-Port-Database mailbox command. */
2428 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 }
2430
2431 if (rval != QLA_SUCCESS) {
2432 /* RLU tmp code: need to change main mailbox_command function to
2433 * return ok even when the mailbox completion value is not
2434 * SUCCESS. The caller needs to be responsible to interpret
2435 * the return values of this mailbox command if we're not
2436 * to change too much of the existing code.
2437 */
2438 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2439 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2440 mcp->mb[0] == 0x4006)
2441 rval = QLA_SUCCESS;
2442
2443 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002444 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2445 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2446 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 } else {
2448 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002449 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2450 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 }
2452
2453 return rval;
2454}
2455
2456/*
2457 * qla2x00_login_local_device
2458 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002459 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 * Input:
2461 * ha = adapter block pointer.
2462 * loop_id = device loop ID.
2463 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002464 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 * Returns:
2466 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002467 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 * Context:
2469 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002470 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 */
2472int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002473qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 uint16_t *mb_ret, uint8_t opt)
2475{
2476 int rval;
2477 mbx_cmd_t mc;
2478 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002479 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002481 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2482 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002483
Andrew Vasqueze4289242007-07-19 15:05:56 -07002484 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002485 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002486 fcport->d_id.b.domain, fcport->d_id.b.area,
2487 fcport->d_id.b.al_pa, mb_ret, opt);
2488
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2490 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002491 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002493 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 mcp->mb[2] = opt;
2495 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2496 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2497 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2498 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002499 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
2501 /* Return mailbox statuses. */
2502 if (mb_ret != NULL) {
2503 mb_ret[0] = mcp->mb[0];
2504 mb_ret[1] = mcp->mb[1];
2505 mb_ret[6] = mcp->mb[6];
2506 mb_ret[7] = mcp->mb[7];
2507 }
2508
2509 if (rval != QLA_SUCCESS) {
2510 /* AV tmp code: need to change main mailbox_command function to
2511 * return ok even when the mailbox completion value is not
2512 * SUCCESS. The caller needs to be responsible to interpret
2513 * the return values of this mailbox command if we're not
2514 * to change too much of the existing code.
2515 */
2516 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2517 rval = QLA_SUCCESS;
2518
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002519 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2520 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2521 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 } else {
2523 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002524 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2525 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 }
2527
2528 return (rval);
2529}
2530
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002531int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002532qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002533 uint8_t area, uint8_t al_pa)
2534{
2535 int rval;
2536 struct logio_entry_24xx *lg;
2537 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002538 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002539 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002540
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002541 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2542 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002543
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002544 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002545 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002546 ql_log(ql_log_warn, vha, 0x106e,
2547 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002548 return QLA_MEMORY_ALLOC_FAILED;
2549 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002550
Michael Hernandezd7459522016-12-12 14:40:07 -08002551 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002552 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2553 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002554 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002555 lg->nport_handle = cpu_to_le16(loop_id);
2556 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002557 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002558 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002559 lg->port_id[0] = al_pa;
2560 lg->port_id[1] = area;
2561 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002562 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002563 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2564 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002565 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002566 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2567 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002568 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002569 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2570 "Failed to complete IOCB -- error status (%x).\n",
2571 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002572 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002573 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002574 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2575 "Failed to complete IOCB -- completion status (%x) "
2576 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002577 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002578 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002579 } else {
2580 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002581 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2582 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002583 }
2584
2585 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2586
2587 return rval;
2588}
2589
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590/*
2591 * qla2x00_fabric_logout
2592 * Issue logout fabric port mailbox command.
2593 *
2594 * Input:
2595 * ha = adapter block pointer.
2596 * loop_id = device loop ID.
2597 * TARGET_QUEUE_LOCK must be released.
2598 * ADAPTER_STATE_LOCK must be released.
2599 *
2600 * Returns:
2601 * qla2x00 local function return status code.
2602 *
2603 * Context:
2604 * Kernel context.
2605 */
2606int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002607qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002608 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609{
2610 int rval;
2611 mbx_cmd_t mc;
2612 mbx_cmd_t *mcp = &mc;
2613
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002614 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2615 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616
2617 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2618 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002619 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 mcp->mb[1] = loop_id;
2621 mcp->mb[10] = 0;
2622 mcp->out_mb |= MBX_10;
2623 } else {
2624 mcp->mb[1] = loop_id << 8;
2625 }
2626
2627 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002628 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002630 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
2632 if (rval != QLA_SUCCESS) {
2633 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002634 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2635 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 } else {
2637 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002638 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2639 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 }
2641
2642 return rval;
2643}
2644
2645/*
2646 * qla2x00_full_login_lip
2647 * Issue full login LIP mailbox command.
2648 *
2649 * Input:
2650 * ha = adapter block pointer.
2651 * TARGET_QUEUE_LOCK must be released.
2652 * ADAPTER_STATE_LOCK must be released.
2653 *
2654 * Returns:
2655 * qla2x00 local function return status code.
2656 *
2657 * Context:
2658 * Kernel context.
2659 */
2660int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002661qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662{
2663 int rval;
2664 mbx_cmd_t mc;
2665 mbx_cmd_t *mcp = &mc;
2666
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002667 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2668 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
2670 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002671 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002672 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 mcp->mb[3] = 0;
2674 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2675 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002676 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002678 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
2680 if (rval != QLA_SUCCESS) {
2681 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002682 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 } else {
2684 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002685 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2686 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 }
2688
2689 return rval;
2690}
2691
2692/*
2693 * qla2x00_get_id_list
2694 *
2695 * Input:
2696 * ha = adapter block pointer.
2697 *
2698 * Returns:
2699 * qla2x00 local function return status code.
2700 *
2701 * Context:
2702 * Kernel context.
2703 */
2704int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002705qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 uint16_t *entries)
2707{
2708 int rval;
2709 mbx_cmd_t mc;
2710 mbx_cmd_t *mcp = &mc;
2711
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002712 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2713 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 if (id_list == NULL)
2716 return QLA_FUNCTION_FAILED;
2717
2718 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002719 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002720 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002721 mcp->mb[2] = MSW(id_list_dma);
2722 mcp->mb[3] = LSW(id_list_dma);
2723 mcp->mb[6] = MSW(MSD(id_list_dma));
2724 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002725 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002726 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002727 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002728 } else {
2729 mcp->mb[1] = MSW(id_list_dma);
2730 mcp->mb[2] = LSW(id_list_dma);
2731 mcp->mb[3] = MSW(MSD(id_list_dma));
2732 mcp->mb[6] = LSW(MSD(id_list_dma));
2733 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002736 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002738 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
2740 if (rval != QLA_SUCCESS) {
2741 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002742 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 } else {
2744 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2746 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 }
2748
2749 return rval;
2750}
2751
2752/*
2753 * qla2x00_get_resource_cnts
2754 * Get current firmware resource counts.
2755 *
2756 * Input:
2757 * ha = adapter block pointer.
2758 *
2759 * Returns:
2760 * qla2x00 local function return status code.
2761 *
2762 * Context:
2763 * Kernel context.
2764 */
2765int
Quinn Tran03e8c682015-12-17 14:56:59 -05002766qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767{
Quinn Tran03e8c682015-12-17 14:56:59 -05002768 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 int rval;
2770 mbx_cmd_t mc;
2771 mbx_cmd_t *mcp = &mc;
2772
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002773 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2774 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775
2776 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2777 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002778 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 -05002779 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002780 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002781 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002783 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 if (rval != QLA_SUCCESS) {
2786 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002787 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2788 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002790 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002791 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2792 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2793 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2794 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Quinn Tran03e8c682015-12-17 14:56:59 -05002796 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2797 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2798 ha->cur_fw_xcb_count = mcp->mb[3];
2799 ha->orig_fw_xcb_count = mcp->mb[6];
2800 ha->cur_fw_iocb_count = mcp->mb[7];
2801 ha->orig_fw_iocb_count = mcp->mb[10];
2802 if (ha->flags.npiv_supported)
2803 ha->max_npiv_vports = mcp->mb[11];
2804 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2805 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 }
2807
2808 return (rval);
2809}
2810
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811/*
2812 * qla2x00_get_fcal_position_map
2813 * Get FCAL (LILP) position map using mailbox command
2814 *
2815 * Input:
2816 * ha = adapter state pointer.
2817 * pos_map = buffer pointer (can be NULL).
2818 *
2819 * Returns:
2820 * qla2x00 local function return status code.
2821 *
2822 * Context:
2823 * Kernel context.
2824 */
2825int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002826qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827{
2828 int rval;
2829 mbx_cmd_t mc;
2830 mbx_cmd_t *mcp = &mc;
2831 char *pmap;
2832 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002833 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002835 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2836 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002837
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002838 pmap = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002840 ql_log(ql_log_warn, vha, 0x1080,
2841 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 return QLA_MEMORY_ALLOC_FAILED;
2843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2846 mcp->mb[2] = MSW(pmap_dma);
2847 mcp->mb[3] = LSW(pmap_dma);
2848 mcp->mb[6] = MSW(MSD(pmap_dma));
2849 mcp->mb[7] = LSW(MSD(pmap_dma));
2850 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2851 mcp->in_mb = MBX_1|MBX_0;
2852 mcp->buf_size = FCAL_MAP_SIZE;
2853 mcp->flags = MBX_DMA_IN;
2854 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002855 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856
2857 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002858 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002859 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2860 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2861 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2862 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863
2864 if (pos_map)
2865 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2866 }
2867 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2868
2869 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002870 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002872 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2873 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 }
2875
2876 return rval;
2877}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002878
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002879/*
2880 * qla2x00_get_link_status
2881 *
2882 * Input:
2883 * ha = adapter block pointer.
2884 * loop_id = device loop ID.
2885 * ret_buf = pointer to link status return buffer.
2886 *
2887 * Returns:
2888 * 0 = success.
2889 * BIT_0 = mem alloc error.
2890 * BIT_1 = mailbox error.
2891 */
2892int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002893qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002894 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002895{
2896 int rval;
2897 mbx_cmd_t mc;
2898 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002899 uint32_t *iter = (void *)stats;
2900 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002901 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002902
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002903 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2904 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002905
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002906 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002907 mcp->mb[2] = MSW(LSD(stats_dma));
2908 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002909 mcp->mb[6] = MSW(MSD(stats_dma));
2910 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002911 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2912 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002913 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002914 mcp->mb[1] = loop_id;
2915 mcp->mb[4] = 0;
2916 mcp->mb[10] = 0;
2917 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2918 mcp->in_mb |= MBX_1;
2919 } else if (HAS_EXTENDED_IDS(ha)) {
2920 mcp->mb[1] = loop_id;
2921 mcp->mb[10] = 0;
2922 mcp->out_mb |= MBX_10|MBX_1;
2923 } else {
2924 mcp->mb[1] = loop_id << 8;
2925 mcp->out_mb |= MBX_1;
2926 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002927 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002928 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002929 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002930
2931 if (rval == QLA_SUCCESS) {
2932 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002933 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2934 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002935 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002936 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002937 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002938 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2939 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002940 for ( ; dwords--; iter++)
2941 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002942 }
2943 } else {
2944 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002945 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002946 }
2947
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002948 return rval;
2949}
2950
2951int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002952qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07002953 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002954{
2955 int rval;
2956 mbx_cmd_t mc;
2957 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002958 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002959
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002960 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2961 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002962
Quinn Tran15f30a52017-03-15 09:48:52 -07002963 memset(&mc, 0, sizeof(mc));
2964 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
2965 mc.mb[2] = MSW(stats_dma);
2966 mc.mb[3] = LSW(stats_dma);
2967 mc.mb[6] = MSW(MSD(stats_dma));
2968 mc.mb[7] = LSW(MSD(stats_dma));
2969 mc.mb[8] = sizeof(struct link_statistics) / 4;
2970 mc.mb[9] = cpu_to_le16(vha->vp_idx);
2971 mc.mb[10] = cpu_to_le16(options);
2972
2973 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002974
2975 if (rval == QLA_SUCCESS) {
2976 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002977 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2978 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002979 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002980 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002981 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2982 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002983 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002984 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002985 iter = &stats->link_fail_cnt;
2986 for ( ; dwords--; iter++)
2987 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002988 }
2989 } else {
2990 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002991 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002992 }
2993
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002994 return rval;
2995}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002996
2997int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002998qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002999{
3000 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003001 unsigned long flags = 0;
3002
3003 struct abort_entry_24xx *abt;
3004 dma_addr_t abt_dma;
3005 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003006 fc_port_t *fcport = sp->fcport;
3007 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003008 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003009 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003010
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003011 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
3012 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003013
Michael Hernandezd7459522016-12-12 14:40:07 -08003014 if (vha->flags.qpairs_available && sp->qpair)
3015 req = sp->qpair->req;
3016
Armen Baloyan4440e462014-02-26 04:15:18 -05003017 if (ql2xasynctmfenable)
3018 return qla24xx_async_abort_command(sp);
3019
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003020 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003021 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003022 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003023 break;
3024 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003025 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003026 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003027 /* Command not found. */
3028 return QLA_FUNCTION_FAILED;
3029 }
3030
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003031 abt = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003032 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003033 ql_log(ql_log_warn, vha, 0x108d,
3034 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003035 return QLA_MEMORY_ALLOC_FAILED;
3036 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003037
3038 abt->entry_type = ABORT_IOCB_TYPE;
3039 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003040 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003041 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07003042 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003043 abt->port_id[0] = fcport->d_id.b.al_pa;
3044 abt->port_id[1] = fcport->d_id.b.area;
3045 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003046 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003047
3048 abt->req_que_no = cpu_to_le16(req->id);
3049
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003050 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003051 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3053 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003054 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003055 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3056 "Failed to complete IOCB -- error status (%x).\n",
3057 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003058 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003059 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003060 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3061 "Failed to complete IOCB -- completion status (%x).\n",
3062 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003063 if (abt->nport_handle == CS_IOCB_ERROR)
3064 rval = QLA_FUNCTION_PARAMETER_ERROR;
3065 else
3066 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003067 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003068 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3069 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003070 }
3071
3072 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3073
3074 return rval;
3075}
3076
3077struct tsk_mgmt_cmd {
3078 union {
3079 struct tsk_mgmt_entry tsk;
3080 struct sts_entry_24xx sts;
3081 } p;
3082};
3083
Andrew Vasquez523ec772008-04-03 13:13:24 -07003084static int
3085__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003086 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003087{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003088 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003089 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003090 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003091 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003092 scsi_qla_host_t *vha;
3093 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003094 struct req_que *req;
3095 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003096 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003097
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003098 vha = fcport->vha;
3099 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003100 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003101
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003102 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3103 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003104
Michael Hernandezd7459522016-12-12 14:40:07 -08003105 if (vha->vp_idx && vha->qpair) {
3106 /* NPIV port */
3107 qpair = vha->qpair;
3108 rsp = qpair->rsp;
3109 req = qpair->req;
3110 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003111 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003112 }
3113
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003114 tsk = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003115 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003116 ql_log(ql_log_warn, vha, 0x1093,
3117 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003118 return QLA_MEMORY_ALLOC_FAILED;
3119 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003120
3121 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3122 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003123 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003124 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003125 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003126 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003127 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3128 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3129 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003130 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003131 if (type == TCF_LUN_RESET) {
3132 int_to_scsilun(l, &tsk->p.tsk.lun);
3133 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3134 sizeof(tsk->p.tsk.lun));
3135 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003136
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003137 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003138 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003139 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003140 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3141 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003142 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003143 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3144 "Failed to complete IOCB -- error status (%x).\n",
3145 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003146 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003147 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003148 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3149 "Failed to complete IOCB -- completion status (%x).\n",
3150 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003151 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003152 } else if (le16_to_cpu(sts->scsi_status) &
3153 SS_RESPONSE_INFO_LEN_VALID) {
3154 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003155 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003156 "Ignoring inconsistent data length -- not enough "
3157 "response info (%d).\n",
3158 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003159 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003160 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3161 "Failed to complete IOCB -- response (%x).\n",
3162 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003163 rval = QLA_FUNCTION_FAILED;
3164 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003165 }
3166
3167 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003168 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003169 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3170 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003171 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3172 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003173 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003174 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3175 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003176 }
3177
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003178 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003179
3180 return rval;
3181}
3182
Andrew Vasquez523ec772008-04-03 13:13:24 -07003183int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003184qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003185{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003186 struct qla_hw_data *ha = fcport->vha->hw;
3187
3188 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3189 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3190
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003191 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003192}
3193
3194int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003195qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003196{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003197 struct qla_hw_data *ha = fcport->vha->hw;
3198
3199 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3200 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3201
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003202 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003203}
3204
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003205int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003206qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003207{
3208 int rval;
3209 mbx_cmd_t mc;
3210 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003211 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003212
Andrew Vasquez68af0812008-05-12 22:21:13 -07003213 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003214 return QLA_FUNCTION_FAILED;
3215
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003216 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3217 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003218
3219 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3220 mcp->out_mb = MBX_0;
3221 mcp->in_mb = MBX_0;
3222 mcp->tov = 5;
3223 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003224 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003225
3226 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003227 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003228 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003229 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3230 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003231 }
3232
3233 return rval;
3234}
3235
Joe Carnucciodb64e932013-10-30 03:38:18 -04003236int
3237qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3238{
3239 int rval;
3240 mbx_cmd_t mc;
3241 mbx_cmd_t *mcp = &mc;
3242
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003243 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3244 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003245 return QLA_FUNCTION_FAILED;
3246
3247 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3248 "Entered %s.\n", __func__);
3249
3250 mcp->mb[0] = MBC_WRITE_SERDES;
3251 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003252 if (IS_QLA2031(vha->hw))
3253 mcp->mb[2] = data & 0xff;
3254 else
3255 mcp->mb[2] = data;
3256
Joe Carnucciodb64e932013-10-30 03:38:18 -04003257 mcp->mb[3] = 0;
3258 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3259 mcp->in_mb = MBX_0;
3260 mcp->tov = MBX_TOV_SECONDS;
3261 mcp->flags = 0;
3262 rval = qla2x00_mailbox_command(vha, mcp);
3263
3264 if (rval != QLA_SUCCESS) {
3265 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3266 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3267 } else {
3268 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3269 "Done %s.\n", __func__);
3270 }
3271
3272 return rval;
3273}
3274
3275int
3276qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3277{
3278 int rval;
3279 mbx_cmd_t mc;
3280 mbx_cmd_t *mcp = &mc;
3281
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003282 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3283 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003284 return QLA_FUNCTION_FAILED;
3285
3286 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3287 "Entered %s.\n", __func__);
3288
3289 mcp->mb[0] = MBC_READ_SERDES;
3290 mcp->mb[1] = addr;
3291 mcp->mb[3] = 0;
3292 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3293 mcp->in_mb = MBX_1|MBX_0;
3294 mcp->tov = MBX_TOV_SECONDS;
3295 mcp->flags = 0;
3296 rval = qla2x00_mailbox_command(vha, mcp);
3297
Andrew Vasquez064135e2015-04-09 15:00:02 -04003298 if (IS_QLA2031(vha->hw))
3299 *data = mcp->mb[1] & 0xff;
3300 else
3301 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003302
3303 if (rval != QLA_SUCCESS) {
3304 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3305 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3306 } else {
3307 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3308 "Done %s.\n", __func__);
3309 }
3310
3311 return rval;
3312}
3313
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003314int
3315qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3316{
3317 int rval;
3318 mbx_cmd_t mc;
3319 mbx_cmd_t *mcp = &mc;
3320
3321 if (!IS_QLA8044(vha->hw))
3322 return QLA_FUNCTION_FAILED;
3323
Quinn Tran83548fe2017-06-02 09:12:01 -07003324 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003325 "Entered %s.\n", __func__);
3326
3327 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3328 mcp->mb[1] = HCS_WRITE_SERDES;
3329 mcp->mb[3] = LSW(addr);
3330 mcp->mb[4] = MSW(addr);
3331 mcp->mb[5] = LSW(data);
3332 mcp->mb[6] = MSW(data);
3333 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3334 mcp->in_mb = MBX_0;
3335 mcp->tov = MBX_TOV_SECONDS;
3336 mcp->flags = 0;
3337 rval = qla2x00_mailbox_command(vha, mcp);
3338
3339 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003340 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003341 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3342 } else {
3343 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3344 "Done %s.\n", __func__);
3345 }
3346
3347 return rval;
3348}
3349
3350int
3351qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3352{
3353 int rval;
3354 mbx_cmd_t mc;
3355 mbx_cmd_t *mcp = &mc;
3356
3357 if (!IS_QLA8044(vha->hw))
3358 return QLA_FUNCTION_FAILED;
3359
3360 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3361 "Entered %s.\n", __func__);
3362
3363 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3364 mcp->mb[1] = HCS_READ_SERDES;
3365 mcp->mb[3] = LSW(addr);
3366 mcp->mb[4] = MSW(addr);
3367 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3368 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3369 mcp->tov = MBX_TOV_SECONDS;
3370 mcp->flags = 0;
3371 rval = qla2x00_mailbox_command(vha, mcp);
3372
3373 *data = mcp->mb[2] << 16 | mcp->mb[1];
3374
3375 if (rval != QLA_SUCCESS) {
3376 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3377 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3378 } else {
3379 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3380 "Done %s.\n", __func__);
3381 }
3382
3383 return rval;
3384}
3385
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003386/**
3387 * qla2x00_set_serdes_params() -
Bart Van Assche2db62282018-01-23 16:33:51 -08003388 * @vha: HA context
3389 * @sw_em_1g:
3390 * @sw_em_2g:
3391 * @sw_em_4g:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003392 *
3393 * Returns
3394 */
3395int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003396qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003397 uint16_t sw_em_2g, uint16_t sw_em_4g)
3398{
3399 int rval;
3400 mbx_cmd_t mc;
3401 mbx_cmd_t *mcp = &mc;
3402
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003403 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3404 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003405
3406 mcp->mb[0] = MBC_SERDES_PARAMS;
3407 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003408 mcp->mb[2] = sw_em_1g | BIT_15;
3409 mcp->mb[3] = sw_em_2g | BIT_15;
3410 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003411 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3412 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003413 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003414 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003415 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003416
3417 if (rval != QLA_SUCCESS) {
3418 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003419 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3420 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003421 } else {
3422 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003423 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3424 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003425 }
3426
3427 return rval;
3428}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003429
3430int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003431qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003432{
3433 int rval;
3434 mbx_cmd_t mc;
3435 mbx_cmd_t *mcp = &mc;
3436
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003437 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003438 return QLA_FUNCTION_FAILED;
3439
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003440 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3441 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003442
3443 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003444 mcp->mb[1] = 0;
3445 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003446 mcp->in_mb = MBX_0;
3447 mcp->tov = 5;
3448 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003449 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003450
3451 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003452 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003453 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3454 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003455 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003456 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3457 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003458 }
3459
3460 return rval;
3461}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003462
3463int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003464qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003465 uint16_t buffers)
3466{
3467 int rval;
3468 mbx_cmd_t mc;
3469 mbx_cmd_t *mcp = &mc;
3470
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003471 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3472 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003473
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003474 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003475 return QLA_FUNCTION_FAILED;
3476
Andrew Vasquez85880802009-12-15 21:29:46 -08003477 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3478 return QLA_FUNCTION_FAILED;
3479
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003480 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003481 mcp->mb[1] = TC_EFT_ENABLE;
3482 mcp->mb[2] = LSW(eft_dma);
3483 mcp->mb[3] = MSW(eft_dma);
3484 mcp->mb[4] = LSW(MSD(eft_dma));
3485 mcp->mb[5] = MSW(MSD(eft_dma));
3486 mcp->mb[6] = buffers;
3487 mcp->mb[7] = TC_AEN_DISABLE;
3488 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 -07003489 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003490 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003491 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003492 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003493 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003494 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3495 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3496 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003497 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003498 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3499 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003500 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003501
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003502 return rval;
3503}
3504
3505int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003506qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003507{
3508 int rval;
3509 mbx_cmd_t mc;
3510 mbx_cmd_t *mcp = &mc;
3511
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003512 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3513 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003514
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003515 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003516 return QLA_FUNCTION_FAILED;
3517
Andrew Vasquez85880802009-12-15 21:29:46 -08003518 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3519 return QLA_FUNCTION_FAILED;
3520
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003521 mcp->mb[0] = MBC_TRACE_CONTROL;
3522 mcp->mb[1] = TC_EFT_DISABLE;
3523 mcp->out_mb = MBX_1|MBX_0;
3524 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003525 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003526 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003527 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003528 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003529 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3530 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3531 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003532 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3534 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003535 }
3536
3537 return rval;
3538}
3539
Andrew Vasquez88729e52006-06-23 16:10:50 -07003540int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003541qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003542 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3543{
3544 int rval;
3545 mbx_cmd_t mc;
3546 mbx_cmd_t *mcp = &mc;
3547
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003548 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3549 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003550
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003551 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003552 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003553 return QLA_FUNCTION_FAILED;
3554
Andrew Vasquez85880802009-12-15 21:29:46 -08003555 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3556 return QLA_FUNCTION_FAILED;
3557
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003558 mcp->mb[0] = MBC_TRACE_CONTROL;
3559 mcp->mb[1] = TC_FCE_ENABLE;
3560 mcp->mb[2] = LSW(fce_dma);
3561 mcp->mb[3] = MSW(fce_dma);
3562 mcp->mb[4] = LSW(MSD(fce_dma));
3563 mcp->mb[5] = MSW(MSD(fce_dma));
3564 mcp->mb[6] = buffers;
3565 mcp->mb[7] = TC_AEN_DISABLE;
3566 mcp->mb[8] = 0;
3567 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3568 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3569 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3570 MBX_1|MBX_0;
3571 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003572 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003573 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003574 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003575 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003576 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3577 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3578 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003579 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3581 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003582
3583 if (mb)
3584 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3585 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003586 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003587 }
3588
3589 return rval;
3590}
3591
3592int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003593qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003594{
3595 int rval;
3596 mbx_cmd_t mc;
3597 mbx_cmd_t *mcp = &mc;
3598
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003599 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3600 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003601
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003602 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003603 return QLA_FUNCTION_FAILED;
3604
Andrew Vasquez85880802009-12-15 21:29:46 -08003605 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3606 return QLA_FUNCTION_FAILED;
3607
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003608 mcp->mb[0] = MBC_TRACE_CONTROL;
3609 mcp->mb[1] = TC_FCE_DISABLE;
3610 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3611 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3612 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3613 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003614 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003615 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003616 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003617 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003618 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3619 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3620 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003621 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003622 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3623 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003624
3625 if (wr)
3626 *wr = (uint64_t) mcp->mb[5] << 48 |
3627 (uint64_t) mcp->mb[4] << 32 |
3628 (uint64_t) mcp->mb[3] << 16 |
3629 (uint64_t) mcp->mb[2];
3630 if (rd)
3631 *rd = (uint64_t) mcp->mb[9] << 48 |
3632 (uint64_t) mcp->mb[8] << 32 |
3633 (uint64_t) mcp->mb[7] << 16 |
3634 (uint64_t) mcp->mb[6];
3635 }
3636
3637 return rval;
3638}
3639
3640int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003641qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3642 uint16_t *port_speed, uint16_t *mb)
3643{
3644 int rval;
3645 mbx_cmd_t mc;
3646 mbx_cmd_t *mcp = &mc;
3647
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003648 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3649 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003650
Giridhar Malavali6e980162010-03-19 17:03:58 -07003651 if (!IS_IIDMA_CAPABLE(vha->hw))
3652 return QLA_FUNCTION_FAILED;
3653
Giridhar Malavali6e980162010-03-19 17:03:58 -07003654 mcp->mb[0] = MBC_PORT_PARAMS;
3655 mcp->mb[1] = loop_id;
3656 mcp->mb[2] = mcp->mb[3] = 0;
3657 mcp->mb[9] = vha->vp_idx;
3658 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3659 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3660 mcp->tov = MBX_TOV_SECONDS;
3661 mcp->flags = 0;
3662 rval = qla2x00_mailbox_command(vha, mcp);
3663
3664 /* Return mailbox statuses. */
3665 if (mb != NULL) {
3666 mb[0] = mcp->mb[0];
3667 mb[1] = mcp->mb[1];
3668 mb[3] = mcp->mb[3];
3669 }
3670
3671 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003672 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003673 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003674 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3675 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003676 if (port_speed)
3677 *port_speed = mcp->mb[3];
3678 }
3679
3680 return rval;
3681}
3682
3683int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003684qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003685 uint16_t port_speed, uint16_t *mb)
3686{
3687 int rval;
3688 mbx_cmd_t mc;
3689 mbx_cmd_t *mcp = &mc;
3690
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003691 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3692 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003693
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003694 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003695 return QLA_FUNCTION_FAILED;
3696
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003697 mcp->mb[0] = MBC_PORT_PARAMS;
3698 mcp->mb[1] = loop_id;
3699 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003700 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003701 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3702 else
3703 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3704 mcp->mb[9] = vha->vp_idx;
3705 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3706 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003707 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003708 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003709 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003710
3711 /* Return mailbox statuses. */
3712 if (mb != NULL) {
3713 mb[0] = mcp->mb[0];
3714 mb[1] = mcp->mb[1];
3715 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003716 }
3717
3718 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003719 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3720 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003721 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003722 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3723 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003724 }
3725
3726 return rval;
3727}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003728
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003729void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003730qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003731 struct vp_rpt_id_entry_24xx *rptid_entry)
3732{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003733 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003734 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003735 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003736 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003737 port_id_t id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08003738 struct fc_port *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003739
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003740 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3741 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003742
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003743 if (rptid_entry->entry_status != 0)
3744 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003745
Quinn Tran482c9dc2017-03-15 09:48:54 -07003746 id.b.domain = rptid_entry->port_id[2];
3747 id.b.area = rptid_entry->port_id[1];
3748 id.b.al_pa = rptid_entry->port_id[0];
3749 id.b.rsvd_1 = 0;
Darren Trapp1763c1f2018-03-20 23:09:34 -07003750 ha->flags.n2n_ae = 0;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003751
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003752 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003753 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003754 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003755 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003756 "VPs acquired %d.\n", rptid_entry->vp_setup,
3757 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003758 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003759 "Primary port id %02x%02x%02x.\n",
3760 rptid_entry->port_id[2], rptid_entry->port_id[1],
3761 rptid_entry->port_id[0]);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003762 ha->current_topology = ISP_CFG_NL;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003763 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003764
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003765 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003766 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003767 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003768 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003769 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3770 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003771 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003772 rptid_entry->port_id[0]);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003773 ql_dbg(ql_dbg_async, vha, 0x5075,
3774 "Format 1: Remote WWPN %8phC.\n",
3775 rptid_entry->u.f1.port_name);
3776
3777 ql_dbg(ql_dbg_async, vha, 0x5075,
3778 "Format 1: WWPN %8phC.\n",
3779 vha->port_name);
3780
3781 /* N2N. direct connect */
3782 if (IS_QLA27XX(ha) &&
3783 ((rptid_entry->u.f1.flags>>1) & 0x7) == 2) {
3784 /* if our portname is higher then initiate N2N login */
3785 if (wwn_to_u64(vha->port_name) >
3786 wwn_to_u64(rptid_entry->u.f1.port_name)) {
3787 // ??? qlt_update_host_map(vha, id);
3788 vha->n2n_id = 0x1;
3789 ql_dbg(ql_dbg_async, vha, 0x5075,
3790 "Format 1: Setting n2n_update_needed for id %d\n",
3791 vha->n2n_id);
3792 } else {
3793 ql_dbg(ql_dbg_async, vha, 0x5075,
3794 "Format 1: Remote login - Waiting for WWPN %8phC.\n",
3795 rptid_entry->u.f1.port_name);
3796 }
3797
3798 memcpy(vha->n2n_port_name, rptid_entry->u.f1.port_name,
3799 WWN_SIZE);
3800 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
3801 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3802 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Darren Trapp1763c1f2018-03-20 23:09:34 -07003803 ha->flags.n2n_ae = 1;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003804 return;
3805 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003806
Quinn Tran9cd883f2017-12-28 12:33:24 -08003807 ha->flags.gpsc_supported = 1;
3808 ha->current_topology = ISP_CFG_F;
Sawan Chandak969a6192016-01-27 12:03:32 -05003809 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003810 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003811
Quinn Tran41dc5292017-01-19 22:28:03 -08003812 if (rptid_entry->vp_idx == 0) {
3813 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3814 /* FA-WWN is only for physical port */
3815 if (qla_ini_mode_enabled(vha) &&
3816 ha->flags.fawwpn_enabled &&
3817 (rptid_entry->u.f1.flags &
Sawan Chandakfcc5b5c2017-08-23 15:05:02 -07003818 BIT_6)) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003819 memcpy(vha->port_name,
3820 rptid_entry->u.f1.port_name,
3821 WWN_SIZE);
3822 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003823
Quinn Tran482c9dc2017-03-15 09:48:54 -07003824 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003825 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003826
Quinn Tran41dc5292017-01-19 22:28:03 -08003827 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3828 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3829 } else {
3830 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3831 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3832 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3833 "Could not acquire ID for VP[%d].\n",
3834 rptid_entry->vp_idx);
3835 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003836 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003837
3838 found = 0;
3839 spin_lock_irqsave(&ha->vport_slock, flags);
3840 list_for_each_entry(vp, &ha->vp_list, list) {
3841 if (rptid_entry->vp_idx == vp->vp_idx) {
3842 found = 1;
3843 break;
3844 }
3845 }
3846 spin_unlock_irqrestore(&ha->vport_slock, flags);
3847
3848 if (!found)
3849 return;
3850
Quinn Tran482c9dc2017-03-15 09:48:54 -07003851 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003852
3853 /*
3854 * Cannot configure here as we are still sitting on the
3855 * response queue. Handle it in dpc context.
3856 */
3857 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3858 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3859 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003860 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003861 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003862 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003863 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003864 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08003865 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3866 rptid_entry->port_id[2], rptid_entry->port_id[1],
3867 rptid_entry->port_id[0]);
3868
Quinn Tran83548fe2017-06-02 09:12:01 -07003869 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08003870 "N2N: Remote WWPN %8phC.\n",
3871 rptid_entry->u.f2.port_name);
3872
3873 /* N2N. direct connect */
Quinn Tran9cd883f2017-12-28 12:33:24 -08003874 ha->current_topology = ISP_CFG_N;
3875 ha->flags.rida_fmt2 = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08003876 vha->d_id.b.domain = rptid_entry->port_id[2];
3877 vha->d_id.b.area = rptid_entry->port_id[1];
3878 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3879
Darren Trapp1763c1f2018-03-20 23:09:34 -07003880 ha->flags.n2n_ae = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08003881 spin_lock_irqsave(&ha->vport_slock, flags);
3882 qlt_update_vp_map(vha, SET_AL_PA);
3883 spin_unlock_irqrestore(&ha->vport_slock, flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003884
3885 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3886 fcport->scan_state = QLA_FCPORT_SCAN;
3887 }
3888
3889 fcport = qla2x00_find_fcport_by_wwpn(vha,
3890 rptid_entry->u.f2.port_name, 1);
3891
3892 if (fcport) {
3893 fcport->plogi_nack_done_deadline = jiffies + HZ;
3894 fcport->scan_state = QLA_FCPORT_FOUND;
3895 switch (fcport->disc_state) {
3896 case DSC_DELETED:
3897 ql_dbg(ql_dbg_disc, vha, 0x210d,
3898 "%s %d %8phC login\n",
3899 __func__, __LINE__, fcport->port_name);
3900 qla24xx_fcport_handle_login(vha, fcport);
3901 break;
3902 case DSC_DELETE_PEND:
3903 break;
3904 default:
Quinn Trand8630bb2017-12-28 12:33:43 -08003905 qlt_schedule_sess_for_deletion(fcport);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003906 break;
3907 }
3908 } else {
3909 id.b.al_pa = rptid_entry->u.f2.remote_nport_id[0];
3910 id.b.area = rptid_entry->u.f2.remote_nport_id[1];
3911 id.b.domain = rptid_entry->u.f2.remote_nport_id[2];
3912 qla24xx_post_newsess_work(vha, &id,
Quinn Trana4239942017-12-28 12:33:26 -08003913 rptid_entry->u.f2.port_name,
3914 rptid_entry->u.f2.node_name,
3915 NULL,
3916 FC4_TYPE_UNKNOWN);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003917 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003918 }
3919}
3920
3921/*
3922 * qla24xx_modify_vp_config
3923 * Change VP configuration for vha
3924 *
3925 * Input:
3926 * vha = adapter block pointer.
3927 *
3928 * Returns:
3929 * qla2xxx local function return status code.
3930 *
3931 * Context:
3932 * Kernel context.
3933 */
3934int
3935qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3936{
3937 int rval;
3938 struct vp_config_entry_24xx *vpmod;
3939 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003940 struct qla_hw_data *ha = vha->hw;
3941 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003942
3943 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003944
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003945 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3946 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003947
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003948 vpmod = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003949 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003950 ql_log(ql_log_warn, vha, 0x10bc,
3951 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003952 return QLA_MEMORY_ALLOC_FAILED;
3953 }
3954
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003955 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3956 vpmod->entry_count = 1;
3957 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3958 vpmod->vp_count = 1;
3959 vpmod->vp_index1 = vha->vp_idx;
3960 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003961
3962 qlt_modify_vp_config(vha, vpmod);
3963
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003964 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3965 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3966 vpmod->entry_count = 1;
3967
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003968 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003969 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003970 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3971 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003972 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003973 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3974 "Failed to complete IOCB -- error status (%x).\n",
3975 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003976 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003977 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003978 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3979 "Failed to complete IOCB -- completion status (%x).\n",
3980 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003981 rval = QLA_FUNCTION_FAILED;
3982 } else {
3983 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003984 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3985 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003986 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3987 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003988 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003989
3990 return rval;
3991}
3992
3993/*
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003994 * qla2x00_send_change_request
3995 * Receive or disable RSCN request from fabric controller
3996 *
3997 * Input:
3998 * ha = adapter block pointer
3999 * format = registration format:
4000 * 0 - Reserved
4001 * 1 - Fabric detected registration
4002 * 2 - N_port detected registration
4003 * 3 - Full registration
4004 * FF - clear registration
4005 * vp_idx = Virtual port index
4006 *
4007 * Returns:
4008 * qla2x00 local function return status code.
4009 *
4010 * Context:
4011 * Kernel Context
4012 */
4013
4014int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004015qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004016 uint16_t vp_idx)
4017{
4018 int rval;
4019 mbx_cmd_t mc;
4020 mbx_cmd_t *mcp = &mc;
4021
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004022 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
4023 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004024
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004025 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
4026 mcp->mb[1] = format;
4027 mcp->mb[9] = vp_idx;
4028 mcp->out_mb = MBX_9|MBX_1|MBX_0;
4029 mcp->in_mb = MBX_0|MBX_1;
4030 mcp->tov = MBX_TOV_SECONDS;
4031 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004032 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004033
4034 if (rval == QLA_SUCCESS) {
4035 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
4036 rval = BIT_1;
4037 }
4038 } else
4039 rval = BIT_1;
4040
4041 return rval;
4042}
Andrew Vasquez338c9162007-09-20 14:07:33 -07004043
4044int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004045qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07004046 uint32_t size)
4047{
4048 int rval;
4049 mbx_cmd_t mc;
4050 mbx_cmd_t *mcp = &mc;
4051
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004052 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
4053 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004054
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004055 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004056 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
4057 mcp->mb[8] = MSW(addr);
4058 mcp->out_mb = MBX_8|MBX_0;
4059 } else {
4060 mcp->mb[0] = MBC_DUMP_RISC_RAM;
4061 mcp->out_mb = MBX_0;
4062 }
4063 mcp->mb[1] = LSW(addr);
4064 mcp->mb[2] = MSW(req_dma);
4065 mcp->mb[3] = LSW(req_dma);
4066 mcp->mb[6] = MSW(MSD(req_dma));
4067 mcp->mb[7] = LSW(MSD(req_dma));
4068 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004069 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004070 mcp->mb[4] = MSW(size);
4071 mcp->mb[5] = LSW(size);
4072 mcp->out_mb |= MBX_5|MBX_4;
4073 } else {
4074 mcp->mb[4] = LSW(size);
4075 mcp->out_mb |= MBX_4;
4076 }
4077
4078 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004079 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004080 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004081 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004082
4083 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004084 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4085 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004086 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004087 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4088 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004089 }
4090
4091 return rval;
4092}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004093/* 84XX Support **************************************************************/
4094
4095struct cs84xx_mgmt_cmd {
4096 union {
4097 struct verify_chip_entry_84xx req;
4098 struct verify_chip_rsp_84xx rsp;
4099 } p;
4100};
4101
4102int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004103qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004104{
4105 int rval, retry;
4106 struct cs84xx_mgmt_cmd *mn;
4107 dma_addr_t mn_dma;
4108 uint16_t options;
4109 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004110 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004111
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004112 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4113 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004114
4115 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4116 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004117 return QLA_MEMORY_ALLOC_FAILED;
4118 }
4119
4120 /* Force Update? */
4121 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4122 /* Diagnostic firmware? */
4123 /* options |= MENLO_DIAG_FW; */
4124 /* We update the firmware with only one data sequence. */
4125 options |= VCO_END_OF_DATA;
4126
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004127 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004128 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004129 memset(mn, 0, sizeof(*mn));
4130 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4131 mn->p.req.entry_count = 1;
4132 mn->p.req.options = cpu_to_le16(options);
4133
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004134 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4135 "Dump of Verify Request.\n");
4136 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4137 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004138
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004139 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004140 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004141 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4142 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004143 goto verify_done;
4144 }
4145
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004146 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4147 "Dump of Verify Response.\n");
4148 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4149 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004150
4151 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4152 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4153 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004154 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004155 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004156
4157 if (status[0] != CS_COMPLETE) {
4158 rval = QLA_FUNCTION_FAILED;
4159 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004160 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4161 "Firmware update failed. Retrying "
4162 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004163 options |= VCO_DONT_UPDATE_FW;
4164 options &= ~VCO_FORCE_UPDATE;
4165 retry = 1;
4166 }
4167 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004169 "Firmware updated to %x.\n",
4170 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004171
4172 /* NOTE: we only update OP firmware. */
4173 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4174 ha->cs84xx->op_fw_version =
4175 le32_to_cpu(mn->p.rsp.fw_ver);
4176 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4177 flags);
4178 }
4179 } while (retry);
4180
4181verify_done:
4182 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4183
4184 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004185 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4186 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004187 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4189 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004190 }
4191
4192 return rval;
4193}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004194
4195int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004196qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004197{
4198 int rval;
4199 unsigned long flags;
4200 mbx_cmd_t mc;
4201 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004202 struct qla_hw_data *ha = vha->hw;
4203
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004204 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4205 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004206
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004207 if (IS_SHADOW_REG_CAPABLE(ha))
4208 req->options |= BIT_13;
4209
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004210 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004211 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004212 mcp->mb[2] = MSW(LSD(req->dma));
4213 mcp->mb[3] = LSW(LSD(req->dma));
4214 mcp->mb[6] = MSW(MSD(req->dma));
4215 mcp->mb[7] = LSW(MSD(req->dma));
4216 mcp->mb[5] = req->length;
4217 if (req->rsp)
4218 mcp->mb[10] = req->rsp->id;
4219 mcp->mb[12] = req->qos;
4220 mcp->mb[11] = req->vp_idx;
4221 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004222 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004223 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004224
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004225 mcp->mb[4] = req->id;
4226 /* que in ptr index */
4227 mcp->mb[8] = 0;
4228 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004229 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004230 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4231 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4232 mcp->in_mb = MBX_0;
4233 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004234 mcp->tov = MBX_TOV_SECONDS * 2;
4235
Chad Dupuisf73cb692014-02-26 04:15:06 -05004236 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004237 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004238 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004239 mcp->out_mb |= MBX_15;
4240 /* debug q create issue in SR-IOV */
4241 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4242 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004243
4244 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004245 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004246 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004247 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004248 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004249 }
4250 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4251
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004252 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004253 if (rval != QLA_SUCCESS) {
4254 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4255 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4256 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004257 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4258 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004259 }
4260
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004261 return rval;
4262}
4263
4264int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004265qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004266{
4267 int rval;
4268 unsigned long flags;
4269 mbx_cmd_t mc;
4270 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004271 struct qla_hw_data *ha = vha->hw;
4272
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004273 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4274 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004275
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004276 if (IS_SHADOW_REG_CAPABLE(ha))
4277 rsp->options |= BIT_13;
4278
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004279 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004280 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004281 mcp->mb[2] = MSW(LSD(rsp->dma));
4282 mcp->mb[3] = LSW(LSD(rsp->dma));
4283 mcp->mb[6] = MSW(MSD(rsp->dma));
4284 mcp->mb[7] = LSW(MSD(rsp->dma));
4285 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004286 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004287 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004288 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004289 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004290
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004291 mcp->mb[4] = rsp->id;
4292 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004293 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004294 /* que out ptr index */
4295 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004296 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004297 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4298 mcp->in_mb = MBX_0;
4299 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004300 mcp->tov = MBX_TOV_SECONDS * 2;
4301
4302 if (IS_QLA81XX(ha)) {
4303 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4304 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004305 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004306 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4307 mcp->in_mb |= MBX_1;
4308 /* debug q create issue in SR-IOV */
4309 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4310 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004311
4312 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004313 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004314 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004315 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004316 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004317 }
4318
4319 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4320
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004321 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004322 if (rval != QLA_SUCCESS) {
4323 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4324 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4325 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004326 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4327 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004328 }
4329
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004330 return rval;
4331}
4332
Andrew Vasquez8a659572009-02-08 20:50:12 -08004333int
4334qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4335{
4336 int rval;
4337 mbx_cmd_t mc;
4338 mbx_cmd_t *mcp = &mc;
4339
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004340 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4341 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004342
4343 mcp->mb[0] = MBC_IDC_ACK;
4344 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4345 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4346 mcp->in_mb = MBX_0;
4347 mcp->tov = MBX_TOV_SECONDS;
4348 mcp->flags = 0;
4349 rval = qla2x00_mailbox_command(vha, mcp);
4350
4351 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004352 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4353 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004354 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004355 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4356 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004357 }
4358
4359 return rval;
4360}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004361
4362int
4363qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4364{
4365 int rval;
4366 mbx_cmd_t mc;
4367 mbx_cmd_t *mcp = &mc;
4368
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004369 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4370 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004371
Chad Dupuisf73cb692014-02-26 04:15:06 -05004372 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4373 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004374 return QLA_FUNCTION_FAILED;
4375
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004376 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4377 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4378 mcp->out_mb = MBX_1|MBX_0;
4379 mcp->in_mb = MBX_1|MBX_0;
4380 mcp->tov = MBX_TOV_SECONDS;
4381 mcp->flags = 0;
4382 rval = qla2x00_mailbox_command(vha, mcp);
4383
4384 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004385 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4386 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4387 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004388 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004389 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4390 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004391 *sector_size = mcp->mb[1];
4392 }
4393
4394 return rval;
4395}
4396
4397int
4398qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4399{
4400 int rval;
4401 mbx_cmd_t mc;
4402 mbx_cmd_t *mcp = &mc;
4403
Chad Dupuisf73cb692014-02-26 04:15:06 -05004404 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4405 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004406 return QLA_FUNCTION_FAILED;
4407
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4409 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004410
4411 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4412 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4413 FAC_OPT_CMD_WRITE_PROTECT;
4414 mcp->out_mb = MBX_1|MBX_0;
4415 mcp->in_mb = MBX_1|MBX_0;
4416 mcp->tov = MBX_TOV_SECONDS;
4417 mcp->flags = 0;
4418 rval = qla2x00_mailbox_command(vha, mcp);
4419
4420 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004421 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4422 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4423 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004424 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004425 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4426 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004427 }
4428
4429 return rval;
4430}
4431
4432int
4433qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4434{
4435 int rval;
4436 mbx_cmd_t mc;
4437 mbx_cmd_t *mcp = &mc;
4438
Chad Dupuisf73cb692014-02-26 04:15:06 -05004439 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4440 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004441 return QLA_FUNCTION_FAILED;
4442
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004443 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4444 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004445
4446 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4447 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4448 mcp->mb[2] = LSW(start);
4449 mcp->mb[3] = MSW(start);
4450 mcp->mb[4] = LSW(finish);
4451 mcp->mb[5] = MSW(finish);
4452 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4453 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4454 mcp->tov = MBX_TOV_SECONDS;
4455 mcp->flags = 0;
4456 rval = qla2x00_mailbox_command(vha, mcp);
4457
4458 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004459 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4460 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4461 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004462 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004463 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4464 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004465 }
4466
4467 return rval;
4468}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004469
4470int
4471qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4472{
4473 int rval = 0;
4474 mbx_cmd_t mc;
4475 mbx_cmd_t *mcp = &mc;
4476
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004477 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4478 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004479
4480 mcp->mb[0] = MBC_RESTART_MPI_FW;
4481 mcp->out_mb = MBX_0;
4482 mcp->in_mb = MBX_0|MBX_1;
4483 mcp->tov = MBX_TOV_SECONDS;
4484 mcp->flags = 0;
4485 rval = qla2x00_mailbox_command(vha, mcp);
4486
4487 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004488 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4489 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4490 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004491 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004492 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4493 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004494 }
4495
4496 return rval;
4497}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004498
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004499int
4500qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4501{
4502 int rval;
4503 mbx_cmd_t mc;
4504 mbx_cmd_t *mcp = &mc;
4505 int i;
4506 int len;
4507 uint16_t *str;
4508 struct qla_hw_data *ha = vha->hw;
4509
4510 if (!IS_P3P_TYPE(ha))
4511 return QLA_FUNCTION_FAILED;
4512
4513 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4514 "Entered %s.\n", __func__);
4515
4516 str = (void *)version;
4517 len = strlen(version);
4518
4519 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4520 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4521 mcp->out_mb = MBX_1|MBX_0;
4522 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4523 mcp->mb[i] = cpu_to_le16p(str);
4524 mcp->out_mb |= 1<<i;
4525 }
4526 for (; i < 16; i++) {
4527 mcp->mb[i] = 0;
4528 mcp->out_mb |= 1<<i;
4529 }
4530 mcp->in_mb = MBX_1|MBX_0;
4531 mcp->tov = MBX_TOV_SECONDS;
4532 mcp->flags = 0;
4533 rval = qla2x00_mailbox_command(vha, mcp);
4534
4535 if (rval != QLA_SUCCESS) {
4536 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4537 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4538 } else {
4539 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4540 "Done %s.\n", __func__);
4541 }
4542
4543 return rval;
4544}
4545
4546int
4547qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4548{
4549 int rval;
4550 mbx_cmd_t mc;
4551 mbx_cmd_t *mcp = &mc;
4552 int len;
4553 uint16_t dwlen;
4554 uint8_t *str;
4555 dma_addr_t str_dma;
4556 struct qla_hw_data *ha = vha->hw;
4557
4558 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4559 IS_P3P_TYPE(ha))
4560 return QLA_FUNCTION_FAILED;
4561
4562 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4563 "Entered %s.\n", __func__);
4564
4565 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4566 if (!str) {
4567 ql_log(ql_log_warn, vha, 0x117f,
4568 "Failed to allocate driver version param.\n");
4569 return QLA_MEMORY_ALLOC_FAILED;
4570 }
4571
4572 memcpy(str, "\x7\x3\x11\x0", 4);
4573 dwlen = str[0];
4574 len = dwlen * 4 - 4;
4575 memset(str + 4, 0, len);
4576 if (len > strlen(version))
4577 len = strlen(version);
4578 memcpy(str + 4, version, len);
4579
4580 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4581 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4582 mcp->mb[2] = MSW(LSD(str_dma));
4583 mcp->mb[3] = LSW(LSD(str_dma));
4584 mcp->mb[6] = MSW(MSD(str_dma));
4585 mcp->mb[7] = LSW(MSD(str_dma));
4586 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4587 mcp->in_mb = MBX_1|MBX_0;
4588 mcp->tov = MBX_TOV_SECONDS;
4589 mcp->flags = 0;
4590 rval = qla2x00_mailbox_command(vha, mcp);
4591
4592 if (rval != QLA_SUCCESS) {
4593 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4594 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4595 } else {
4596 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4597 "Done %s.\n", __func__);
4598 }
4599
4600 dma_pool_free(ha->s_dma_pool, str, str_dma);
4601
4602 return rval;
4603}
4604
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004605int
4606qla24xx_get_port_login_templ(scsi_qla_host_t *vha, dma_addr_t buf_dma,
4607 void *buf, uint16_t bufsiz)
4608{
4609 int rval, i;
4610 mbx_cmd_t mc;
4611 mbx_cmd_t *mcp = &mc;
4612 uint32_t *bp;
4613
4614 if (!IS_FWI2_CAPABLE(vha->hw))
4615 return QLA_FUNCTION_FAILED;
4616
4617 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4618 "Entered %s.\n", __func__);
4619
4620 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4621 mcp->mb[1] = RNID_TYPE_PORT_LOGIN << 8;
4622 mcp->mb[2] = MSW(buf_dma);
4623 mcp->mb[3] = LSW(buf_dma);
4624 mcp->mb[6] = MSW(MSD(buf_dma));
4625 mcp->mb[7] = LSW(MSD(buf_dma));
4626 mcp->mb[8] = bufsiz/4;
4627 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4628 mcp->in_mb = MBX_1|MBX_0;
4629 mcp->tov = MBX_TOV_SECONDS;
4630 mcp->flags = 0;
4631 rval = qla2x00_mailbox_command(vha, mcp);
4632
4633 if (rval != QLA_SUCCESS) {
4634 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4635 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4636 } else {
4637 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4638 "Done %s.\n", __func__);
4639 bp = (uint32_t *) buf;
4640 for (i = 0; i < (bufsiz-4)/4; i++, bp++)
4641 *bp = cpu_to_be32(*bp);
4642 }
4643
4644 return rval;
4645}
4646
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004647static int
4648qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4649{
4650 int rval;
4651 mbx_cmd_t mc;
4652 mbx_cmd_t *mcp = &mc;
4653
4654 if (!IS_FWI2_CAPABLE(vha->hw))
4655 return QLA_FUNCTION_FAILED;
4656
4657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4658 "Entered %s.\n", __func__);
4659
4660 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4661 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4662 mcp->out_mb = MBX_1|MBX_0;
4663 mcp->in_mb = MBX_1|MBX_0;
4664 mcp->tov = MBX_TOV_SECONDS;
4665 mcp->flags = 0;
4666 rval = qla2x00_mailbox_command(vha, mcp);
4667 *temp = mcp->mb[1];
4668
4669 if (rval != QLA_SUCCESS) {
4670 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4671 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4672 } else {
4673 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4674 "Done %s.\n", __func__);
4675 }
4676
4677 return rval;
4678}
4679
Joe Carnuccio3a117112013-02-08 01:58:00 -05004680int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004681qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4682 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004683{
4684 int rval;
4685 mbx_cmd_t mc;
4686 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004687 struct qla_hw_data *ha = vha->hw;
4688
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004689 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4690 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004691
Joe Carnuccio6766df92011-05-10 11:30:15 -07004692 if (!IS_FWI2_CAPABLE(ha))
4693 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004694
Joe Carnuccio6766df92011-05-10 11:30:15 -07004695 if (len == 1)
4696 opt |= BIT_0;
4697
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004698 mcp->mb[0] = MBC_READ_SFP;
4699 mcp->mb[1] = dev;
4700 mcp->mb[2] = MSW(sfp_dma);
4701 mcp->mb[3] = LSW(sfp_dma);
4702 mcp->mb[6] = MSW(MSD(sfp_dma));
4703 mcp->mb[7] = LSW(MSD(sfp_dma));
4704 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004705 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004706 mcp->mb[10] = opt;
4707 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 -07004708 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004709 mcp->tov = MBX_TOV_SECONDS;
4710 mcp->flags = 0;
4711 rval = qla2x00_mailbox_command(vha, mcp);
4712
4713 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004714 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004715
4716 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004717 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4718 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004719 if (mcp->mb[0] == MBS_COMMAND_ERROR &&
4720 mcp->mb[1] == 0x22)
4721 /* sfp is not there */
4722 rval = QLA_INTERFACE_ERROR;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004723 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004724 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4725 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004726 }
4727
4728 return rval;
4729}
4730
4731int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004732qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4733 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004734{
4735 int rval;
4736 mbx_cmd_t mc;
4737 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004738 struct qla_hw_data *ha = vha->hw;
4739
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004740 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4741 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004742
Joe Carnuccio6766df92011-05-10 11:30:15 -07004743 if (!IS_FWI2_CAPABLE(ha))
4744 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004745
Joe Carnuccio6766df92011-05-10 11:30:15 -07004746 if (len == 1)
4747 opt |= BIT_0;
4748
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004749 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004750 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004751
4752 mcp->mb[0] = MBC_WRITE_SFP;
4753 mcp->mb[1] = dev;
4754 mcp->mb[2] = MSW(sfp_dma);
4755 mcp->mb[3] = LSW(sfp_dma);
4756 mcp->mb[6] = MSW(MSD(sfp_dma));
4757 mcp->mb[7] = LSW(MSD(sfp_dma));
4758 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004759 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004760 mcp->mb[10] = opt;
4761 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 -07004762 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004763 mcp->tov = MBX_TOV_SECONDS;
4764 mcp->flags = 0;
4765 rval = qla2x00_mailbox_command(vha, mcp);
4766
4767 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004768 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4769 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004770 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004771 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4772 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004773 }
4774
4775 return rval;
4776}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004777
4778int
4779qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4780 uint16_t size_in_bytes, uint16_t *actual_size)
4781{
4782 int rval;
4783 mbx_cmd_t mc;
4784 mbx_cmd_t *mcp = &mc;
4785
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004786 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4787 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004788
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004789 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004790 return QLA_FUNCTION_FAILED;
4791
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004792 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4793 mcp->mb[2] = MSW(stats_dma);
4794 mcp->mb[3] = LSW(stats_dma);
4795 mcp->mb[6] = MSW(MSD(stats_dma));
4796 mcp->mb[7] = LSW(MSD(stats_dma));
4797 mcp->mb[8] = size_in_bytes >> 2;
4798 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4799 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4800 mcp->tov = MBX_TOV_SECONDS;
4801 mcp->flags = 0;
4802 rval = qla2x00_mailbox_command(vha, mcp);
4803
4804 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004805 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4806 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4807 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004808 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4810 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004811
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004812
4813 *actual_size = mcp->mb[2] << 2;
4814 }
4815
4816 return rval;
4817}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004818
4819int
4820qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4821 uint16_t size)
4822{
4823 int rval;
4824 mbx_cmd_t mc;
4825 mbx_cmd_t *mcp = &mc;
4826
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004827 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4828 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004829
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004830 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004831 return QLA_FUNCTION_FAILED;
4832
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004833 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4834 mcp->mb[1] = 0;
4835 mcp->mb[2] = MSW(tlv_dma);
4836 mcp->mb[3] = LSW(tlv_dma);
4837 mcp->mb[6] = MSW(MSD(tlv_dma));
4838 mcp->mb[7] = LSW(MSD(tlv_dma));
4839 mcp->mb[8] = size;
4840 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4841 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4842 mcp->tov = MBX_TOV_SECONDS;
4843 mcp->flags = 0;
4844 rval = qla2x00_mailbox_command(vha, mcp);
4845
4846 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004847 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4848 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4849 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004850 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004851 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4852 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004853 }
4854
4855 return rval;
4856}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004857
4858int
4859qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4860{
4861 int rval;
4862 mbx_cmd_t mc;
4863 mbx_cmd_t *mcp = &mc;
4864
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004865 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4866 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004867
Andrew Vasquez18e75552009-06-03 09:55:30 -07004868 if (!IS_FWI2_CAPABLE(vha->hw))
4869 return QLA_FUNCTION_FAILED;
4870
Andrew Vasquez18e75552009-06-03 09:55:30 -07004871 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4872 mcp->mb[1] = LSW(risc_addr);
4873 mcp->mb[8] = MSW(risc_addr);
4874 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4875 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4876 mcp->tov = 30;
4877 mcp->flags = 0;
4878 rval = qla2x00_mailbox_command(vha, mcp);
4879 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004880 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4881 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004882 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004883 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4884 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004885 *data = mcp->mb[3] << 16 | mcp->mb[2];
4886 }
4887
4888 return rval;
4889}
4890
4891int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004892qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4893 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004894{
4895 int rval;
4896 mbx_cmd_t mc;
4897 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004898
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4900 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004901
4902 memset(mcp->mb, 0 , sizeof(mcp->mb));
4903 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4904 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4905
4906 /* transfer count */
4907 mcp->mb[10] = LSW(mreq->transfer_size);
4908 mcp->mb[11] = MSW(mreq->transfer_size);
4909
4910 /* send data address */
4911 mcp->mb[14] = LSW(mreq->send_dma);
4912 mcp->mb[15] = MSW(mreq->send_dma);
4913 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4914 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4915
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004916 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004917 mcp->mb[16] = LSW(mreq->rcv_dma);
4918 mcp->mb[17] = MSW(mreq->rcv_dma);
4919 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4920 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4921
4922 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004923 mcp->mb[18] = LSW(mreq->iteration_count);
4924 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004925
4926 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4927 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 -08004928 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004929 mcp->out_mb |= MBX_2;
4930 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4931
4932 mcp->buf_size = mreq->transfer_size;
4933 mcp->tov = MBX_TOV_SECONDS;
4934 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4935
4936 rval = qla2x00_mailbox_command(vha, mcp);
4937
4938 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004939 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4940 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4941 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4942 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004943 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004944 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4945 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004946 }
4947
4948 /* Copy mailbox information */
4949 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004950 return rval;
4951}
4952
4953int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004954qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4955 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004956{
4957 int rval;
4958 mbx_cmd_t mc;
4959 mbx_cmd_t *mcp = &mc;
4960 struct qla_hw_data *ha = vha->hw;
4961
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004962 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4963 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004964
4965 memset(mcp->mb, 0 , sizeof(mcp->mb));
4966 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07004967 /* BIT_6 specifies 64bit address */
4968 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004969 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004970 mcp->mb[2] = vha->fcoe_fcf_idx;
4971 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004972 mcp->mb[16] = LSW(mreq->rcv_dma);
4973 mcp->mb[17] = MSW(mreq->rcv_dma);
4974 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4975 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4976
4977 mcp->mb[10] = LSW(mreq->transfer_size);
4978
4979 mcp->mb[14] = LSW(mreq->send_dma);
4980 mcp->mb[15] = MSW(mreq->send_dma);
4981 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4982 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4983
4984 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4985 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004986 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004987 mcp->out_mb |= MBX_2;
4988
4989 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004990 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4991 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004992 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004993 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004994 mcp->in_mb |= MBX_3;
4995
4996 mcp->tov = MBX_TOV_SECONDS;
4997 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4998 mcp->buf_size = mreq->transfer_size;
4999
5000 rval = qla2x00_mailbox_command(vha, mcp);
5001
5002 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005003 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
5004 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5005 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005006 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
5008 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005009 }
5010
5011 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005012 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005013 return rval;
5014}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005015
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005016int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005017qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005018{
5019 int rval;
5020 mbx_cmd_t mc;
5021 mbx_cmd_t *mcp = &mc;
5022
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005023 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005024 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005025
5026 mcp->mb[0] = MBC_ISP84XX_RESET;
5027 mcp->mb[1] = enable_diagnostic;
5028 mcp->out_mb = MBX_1|MBX_0;
5029 mcp->in_mb = MBX_1|MBX_0;
5030 mcp->tov = MBX_TOV_SECONDS;
5031 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005032 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005033
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005034 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005035 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005036 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005037 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
5038 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005039
5040 return rval;
5041}
5042
5043int
Andrew Vasquez18e75552009-06-03 09:55:30 -07005044qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
5045{
5046 int rval;
5047 mbx_cmd_t mc;
5048 mbx_cmd_t *mcp = &mc;
5049
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005050 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
5051 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005052
Andrew Vasquez18e75552009-06-03 09:55:30 -07005053 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005054 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005055
Andrew Vasquez18e75552009-06-03 09:55:30 -07005056 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
5057 mcp->mb[1] = LSW(risc_addr);
5058 mcp->mb[2] = LSW(data);
5059 mcp->mb[3] = MSW(data);
5060 mcp->mb[8] = MSW(risc_addr);
5061 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
5062 mcp->in_mb = MBX_0;
5063 mcp->tov = 30;
5064 mcp->flags = 0;
5065 rval = qla2x00_mailbox_command(vha, mcp);
5066 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005067 ql_dbg(ql_dbg_mbx, vha, 0x1101,
5068 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005069 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005070 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
5071 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005072 }
5073
5074 return rval;
5075}
Michael Hernandez3064ff32009-12-15 21:29:44 -08005076
5077int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005078qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
5079{
5080 int rval;
5081 uint32_t stat, timer;
5082 uint16_t mb0 = 0;
5083 struct qla_hw_data *ha = vha->hw;
5084 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5085
5086 rval = QLA_SUCCESS;
5087
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005088 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
5089 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005090
5091 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
5092
5093 /* Write the MBC data to the registers */
5094 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
5095 WRT_REG_WORD(&reg->mailbox1, mb[0]);
5096 WRT_REG_WORD(&reg->mailbox2, mb[1]);
5097 WRT_REG_WORD(&reg->mailbox3, mb[2]);
5098 WRT_REG_WORD(&reg->mailbox4, mb[3]);
5099
5100 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
5101
5102 /* Poll for MBC interrupt */
5103 for (timer = 6000000; timer; timer--) {
5104 /* Check for pending interrupts. */
5105 stat = RD_REG_DWORD(&reg->host_status);
5106 if (stat & HSRX_RISC_INT) {
5107 stat &= 0xff;
5108
5109 if (stat == 0x1 || stat == 0x2 ||
5110 stat == 0x10 || stat == 0x11) {
5111 set_bit(MBX_INTERRUPT,
5112 &ha->mbx_cmd_flags);
5113 mb0 = RD_REG_WORD(&reg->mailbox0);
5114 WRT_REG_DWORD(&reg->hccr,
5115 HCCRX_CLR_RISC_INT);
5116 RD_REG_DWORD(&reg->hccr);
5117 break;
5118 }
5119 }
5120 udelay(5);
5121 }
5122
5123 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5124 rval = mb0 & MBS_MASK;
5125 else
5126 rval = QLA_FUNCTION_FAILED;
5127
5128 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005129 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5130 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005131 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005132 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5133 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005134 }
5135
5136 return rval;
5137}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005138
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005139int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005140qla2x00_get_data_rate(scsi_qla_host_t *vha)
5141{
5142 int rval;
5143 mbx_cmd_t mc;
5144 mbx_cmd_t *mcp = &mc;
5145 struct qla_hw_data *ha = vha->hw;
5146
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005147 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5148 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005149
Michael Hernandez3064ff32009-12-15 21:29:44 -08005150 if (!IS_FWI2_CAPABLE(ha))
5151 return QLA_FUNCTION_FAILED;
5152
Michael Hernandez3064ff32009-12-15 21:29:44 -08005153 mcp->mb[0] = MBC_DATA_RATE;
5154 mcp->mb[1] = 0;
5155 mcp->out_mb = MBX_1|MBX_0;
5156 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005157 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005158 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005159 mcp->tov = MBX_TOV_SECONDS;
5160 mcp->flags = 0;
5161 rval = qla2x00_mailbox_command(vha, mcp);
5162 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005163 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5164 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005165 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005166 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5167 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005168 if (mcp->mb[1] != 0x7)
5169 ha->link_data_rate = mcp->mb[1];
5170 }
5171
5172 return rval;
5173}
Sarang Radke09ff7012010-03-19 17:03:59 -07005174
5175int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005176qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5177{
5178 int rval;
5179 mbx_cmd_t mc;
5180 mbx_cmd_t *mcp = &mc;
5181 struct qla_hw_data *ha = vha->hw;
5182
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005183 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5184 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005185
Chad Dupuisf73cb692014-02-26 04:15:06 -05005186 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5187 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005188 return QLA_FUNCTION_FAILED;
5189 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5190 mcp->out_mb = MBX_0;
5191 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5192 mcp->tov = MBX_TOV_SECONDS;
5193 mcp->flags = 0;
5194
5195 rval = qla2x00_mailbox_command(vha, mcp);
5196
5197 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005198 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5199 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005200 } else {
5201 /* Copy all bits to preserve original value */
5202 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5203
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005204 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5205 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005206 }
5207 return rval;
5208}
5209
5210int
5211qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5212{
5213 int rval;
5214 mbx_cmd_t mc;
5215 mbx_cmd_t *mcp = &mc;
5216
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005217 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5218 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005219
5220 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5221 /* Copy all bits to preserve original setting */
5222 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5223 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5224 mcp->in_mb = MBX_0;
5225 mcp->tov = MBX_TOV_SECONDS;
5226 mcp->flags = 0;
5227 rval = qla2x00_mailbox_command(vha, mcp);
5228
5229 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005230 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5231 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005232 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005233 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5234 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005235
5236 return rval;
5237}
5238
5239
5240int
Sarang Radke09ff7012010-03-19 17:03:59 -07005241qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5242 uint16_t *mb)
5243{
5244 int rval;
5245 mbx_cmd_t mc;
5246 mbx_cmd_t *mcp = &mc;
5247 struct qla_hw_data *ha = vha->hw;
5248
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5250 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005251
Sarang Radke09ff7012010-03-19 17:03:59 -07005252 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5253 return QLA_FUNCTION_FAILED;
5254
Sarang Radke09ff7012010-03-19 17:03:59 -07005255 mcp->mb[0] = MBC_PORT_PARAMS;
5256 mcp->mb[1] = loop_id;
5257 if (ha->flags.fcp_prio_enabled)
5258 mcp->mb[2] = BIT_1;
5259 else
5260 mcp->mb[2] = BIT_2;
5261 mcp->mb[4] = priority & 0xf;
5262 mcp->mb[9] = vha->vp_idx;
5263 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5264 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5265 mcp->tov = 30;
5266 mcp->flags = 0;
5267 rval = qla2x00_mailbox_command(vha, mcp);
5268 if (mb != NULL) {
5269 mb[0] = mcp->mb[0];
5270 mb[1] = mcp->mb[1];
5271 mb[3] = mcp->mb[3];
5272 mb[4] = mcp->mb[4];
5273 }
5274
5275 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005276 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005277 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005278 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5279 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005280 }
5281
5282 return rval;
5283}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005284
5285int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005286qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005287{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005288 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005289 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005290 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005291
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005292 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5293 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5294 "Thermal not supported by this card.\n");
5295 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005296 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005297
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005298 if (IS_QLA25XX(ha)) {
5299 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5300 ha->pdev->subsystem_device == 0x0175) {
5301 rval = qla2x00_read_sfp(vha, 0, &byte,
5302 0x98, 0x1, 1, BIT_13|BIT_0);
5303 *temp = byte;
5304 return rval;
5305 }
5306 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5307 ha->pdev->subsystem_device == 0x338e) {
5308 rval = qla2x00_read_sfp(vha, 0, &byte,
5309 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5310 *temp = byte;
5311 return rval;
5312 }
5313 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5314 "Thermal not supported by this card.\n");
5315 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005316 }
5317
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005318 if (IS_QLA82XX(ha)) {
5319 *temp = qla82xx_read_temperature(vha);
5320 rval = QLA_SUCCESS;
5321 return rval;
5322 } else if (IS_QLA8044(ha)) {
5323 *temp = qla8044_read_temperature(vha);
5324 rval = QLA_SUCCESS;
5325 return rval;
5326 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005327
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005328 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005329 return rval;
5330}
5331
5332int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005333qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5334{
5335 int rval;
5336 struct qla_hw_data *ha = vha->hw;
5337 mbx_cmd_t mc;
5338 mbx_cmd_t *mcp = &mc;
5339
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005340 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5341 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005342
Giridhar Malavalia9083012010-04-12 17:59:55 -07005343 if (!IS_FWI2_CAPABLE(ha))
5344 return QLA_FUNCTION_FAILED;
5345
Giridhar Malavalia9083012010-04-12 17:59:55 -07005346 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005347 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005348 mcp->mb[1] = 1;
5349
5350 mcp->out_mb = MBX_1|MBX_0;
5351 mcp->in_mb = MBX_0;
5352 mcp->tov = 30;
5353 mcp->flags = 0;
5354
5355 rval = qla2x00_mailbox_command(vha, mcp);
5356 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005357 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5358 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005359 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005360 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5361 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005362 }
5363
5364 return rval;
5365}
5366
5367int
5368qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5369{
5370 int rval;
5371 struct qla_hw_data *ha = vha->hw;
5372 mbx_cmd_t mc;
5373 mbx_cmd_t *mcp = &mc;
5374
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005375 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5376 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005377
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005378 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005379 return QLA_FUNCTION_FAILED;
5380
Giridhar Malavalia9083012010-04-12 17:59:55 -07005381 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005382 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005383 mcp->mb[1] = 0;
5384
5385 mcp->out_mb = MBX_1|MBX_0;
5386 mcp->in_mb = MBX_0;
5387 mcp->tov = 30;
5388 mcp->flags = 0;
5389
5390 rval = qla2x00_mailbox_command(vha, mcp);
5391 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005392 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5393 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005394 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005395 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5396 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005397 }
5398
5399 return rval;
5400}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005401
5402int
5403qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5404{
5405 struct qla_hw_data *ha = vha->hw;
5406 mbx_cmd_t mc;
5407 mbx_cmd_t *mcp = &mc;
5408 int rval = QLA_FUNCTION_FAILED;
5409
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005410 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5411 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005412
5413 memset(mcp->mb, 0 , sizeof(mcp->mb));
5414 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5415 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5416 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5417 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5418
5419 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5420 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5421 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5422
5423 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5424 mcp->tov = MBX_TOV_SECONDS;
5425 rval = qla2x00_mailbox_command(vha, mcp);
5426
5427 /* Always copy back return mailbox values. */
5428 if (rval != QLA_SUCCESS) {
5429 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5430 "mailbox command FAILED=0x%x, subcode=%x.\n",
5431 (mcp->mb[1] << 16) | mcp->mb[0],
5432 (mcp->mb[3] << 16) | mcp->mb[2]);
5433 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005434 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5435 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005436 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5437 if (!ha->md_template_size) {
5438 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5439 "Null template size obtained.\n");
5440 rval = QLA_FUNCTION_FAILED;
5441 }
5442 }
5443 return rval;
5444}
5445
5446int
5447qla82xx_md_get_template(scsi_qla_host_t *vha)
5448{
5449 struct qla_hw_data *ha = vha->hw;
5450 mbx_cmd_t mc;
5451 mbx_cmd_t *mcp = &mc;
5452 int rval = QLA_FUNCTION_FAILED;
5453
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005454 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5455 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005456
5457 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5458 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5459 if (!ha->md_tmplt_hdr) {
5460 ql_log(ql_log_warn, vha, 0x1124,
5461 "Unable to allocate memory for Minidump template.\n");
5462 return rval;
5463 }
5464
5465 memset(mcp->mb, 0 , sizeof(mcp->mb));
5466 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5467 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5468 mcp->mb[2] = LSW(RQST_TMPLT);
5469 mcp->mb[3] = MSW(RQST_TMPLT);
5470 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5471 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5472 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5473 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5474 mcp->mb[8] = LSW(ha->md_template_size);
5475 mcp->mb[9] = MSW(ha->md_template_size);
5476
5477 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5478 mcp->tov = MBX_TOV_SECONDS;
5479 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5480 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5481 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5482 rval = qla2x00_mailbox_command(vha, mcp);
5483
5484 if (rval != QLA_SUCCESS) {
5485 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5486 "mailbox command FAILED=0x%x, subcode=%x.\n",
5487 ((mcp->mb[1] << 16) | mcp->mb[0]),
5488 ((mcp->mb[3] << 16) | mcp->mb[2]));
5489 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005490 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5491 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005492 return rval;
5493}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005494
5495int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005496qla8044_md_get_template(scsi_qla_host_t *vha)
5497{
5498 struct qla_hw_data *ha = vha->hw;
5499 mbx_cmd_t mc;
5500 mbx_cmd_t *mcp = &mc;
5501 int rval = QLA_FUNCTION_FAILED;
5502 int offset = 0, size = MINIDUMP_SIZE_36K;
5503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5504 "Entered %s.\n", __func__);
5505
5506 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5507 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5508 if (!ha->md_tmplt_hdr) {
5509 ql_log(ql_log_warn, vha, 0xb11b,
5510 "Unable to allocate memory for Minidump template.\n");
5511 return rval;
5512 }
5513
5514 memset(mcp->mb, 0 , sizeof(mcp->mb));
5515 while (offset < ha->md_template_size) {
5516 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5517 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5518 mcp->mb[2] = LSW(RQST_TMPLT);
5519 mcp->mb[3] = MSW(RQST_TMPLT);
5520 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5521 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5522 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5523 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5524 mcp->mb[8] = LSW(size);
5525 mcp->mb[9] = MSW(size);
5526 mcp->mb[10] = offset & 0x0000FFFF;
5527 mcp->mb[11] = offset & 0xFFFF0000;
5528 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5529 mcp->tov = MBX_TOV_SECONDS;
5530 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5531 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5532 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5533 rval = qla2x00_mailbox_command(vha, mcp);
5534
5535 if (rval != QLA_SUCCESS) {
5536 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5537 "mailbox command FAILED=0x%x, subcode=%x.\n",
5538 ((mcp->mb[1] << 16) | mcp->mb[0]),
5539 ((mcp->mb[3] << 16) | mcp->mb[2]));
5540 return rval;
5541 } else
5542 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5543 "Done %s.\n", __func__);
5544 offset = offset + size;
5545 }
5546 return rval;
5547}
5548
5549int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005550qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5551{
5552 int rval;
5553 struct qla_hw_data *ha = vha->hw;
5554 mbx_cmd_t mc;
5555 mbx_cmd_t *mcp = &mc;
5556
5557 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5558 return QLA_FUNCTION_FAILED;
5559
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5561 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005562
5563 memset(mcp, 0, sizeof(mbx_cmd_t));
5564 mcp->mb[0] = MBC_SET_LED_CONFIG;
5565 mcp->mb[1] = led_cfg[0];
5566 mcp->mb[2] = led_cfg[1];
5567 if (IS_QLA8031(ha)) {
5568 mcp->mb[3] = led_cfg[2];
5569 mcp->mb[4] = led_cfg[3];
5570 mcp->mb[5] = led_cfg[4];
5571 mcp->mb[6] = led_cfg[5];
5572 }
5573
5574 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5575 if (IS_QLA8031(ha))
5576 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5577 mcp->in_mb = MBX_0;
5578 mcp->tov = 30;
5579 mcp->flags = 0;
5580
5581 rval = qla2x00_mailbox_command(vha, mcp);
5582 if (rval != QLA_SUCCESS) {
5583 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5584 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5585 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005586 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5587 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005588 }
5589
5590 return rval;
5591}
5592
5593int
5594qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5595{
5596 int rval;
5597 struct qla_hw_data *ha = vha->hw;
5598 mbx_cmd_t mc;
5599 mbx_cmd_t *mcp = &mc;
5600
5601 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5602 return QLA_FUNCTION_FAILED;
5603
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005604 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5605 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005606
5607 memset(mcp, 0, sizeof(mbx_cmd_t));
5608 mcp->mb[0] = MBC_GET_LED_CONFIG;
5609
5610 mcp->out_mb = MBX_0;
5611 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5612 if (IS_QLA8031(ha))
5613 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5614 mcp->tov = 30;
5615 mcp->flags = 0;
5616
5617 rval = qla2x00_mailbox_command(vha, mcp);
5618 if (rval != QLA_SUCCESS) {
5619 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5620 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5621 } else {
5622 led_cfg[0] = mcp->mb[1];
5623 led_cfg[1] = mcp->mb[2];
5624 if (IS_QLA8031(ha)) {
5625 led_cfg[2] = mcp->mb[3];
5626 led_cfg[3] = mcp->mb[4];
5627 led_cfg[4] = mcp->mb[5];
5628 led_cfg[5] = mcp->mb[6];
5629 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005630 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5631 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005632 }
5633
5634 return rval;
5635}
5636
5637int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005638qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5639{
5640 int rval;
5641 struct qla_hw_data *ha = vha->hw;
5642 mbx_cmd_t mc;
5643 mbx_cmd_t *mcp = &mc;
5644
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005645 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005646 return QLA_FUNCTION_FAILED;
5647
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005648 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005649 "Entered %s.\n", __func__);
5650
5651 memset(mcp, 0, sizeof(mbx_cmd_t));
5652 mcp->mb[0] = MBC_SET_LED_CONFIG;
5653 if (enable)
5654 mcp->mb[7] = 0xE;
5655 else
5656 mcp->mb[7] = 0xD;
5657
5658 mcp->out_mb = MBX_7|MBX_0;
5659 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005660 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005661 mcp->flags = 0;
5662
5663 rval = qla2x00_mailbox_command(vha, mcp);
5664 if (rval != QLA_SUCCESS) {
5665 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5666 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5667 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005668 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005669 "Done %s.\n", __func__);
5670 }
5671
5672 return rval;
5673}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005674
5675int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005676qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005677{
5678 int rval;
5679 struct qla_hw_data *ha = vha->hw;
5680 mbx_cmd_t mc;
5681 mbx_cmd_t *mcp = &mc;
5682
Chad Dupuisf73cb692014-02-26 04:15:06 -05005683 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005684 return QLA_FUNCTION_FAILED;
5685
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005686 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5687 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005688
5689 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5690 mcp->mb[1] = LSW(reg);
5691 mcp->mb[2] = MSW(reg);
5692 mcp->mb[3] = LSW(data);
5693 mcp->mb[4] = MSW(data);
5694 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5695
5696 mcp->in_mb = MBX_1|MBX_0;
5697 mcp->tov = MBX_TOV_SECONDS;
5698 mcp->flags = 0;
5699 rval = qla2x00_mailbox_command(vha, mcp);
5700
5701 if (rval != QLA_SUCCESS) {
5702 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5703 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5704 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005705 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005706 "Done %s.\n", __func__);
5707 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005708
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005709 return rval;
5710}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005711
5712int
5713qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5714{
5715 int rval;
5716 struct qla_hw_data *ha = vha->hw;
5717 mbx_cmd_t mc;
5718 mbx_cmd_t *mcp = &mc;
5719
5720 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005721 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005722 "Implicit LOGO Unsupported.\n");
5723 return QLA_FUNCTION_FAILED;
5724 }
5725
5726
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005727 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5728 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005729
5730 /* Perform Implicit LOGO. */
5731 mcp->mb[0] = MBC_PORT_LOGOUT;
5732 mcp->mb[1] = fcport->loop_id;
5733 mcp->mb[10] = BIT_15;
5734 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5735 mcp->in_mb = MBX_0;
5736 mcp->tov = MBX_TOV_SECONDS;
5737 mcp->flags = 0;
5738 rval = qla2x00_mailbox_command(vha, mcp);
5739 if (rval != QLA_SUCCESS)
5740 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5741 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5742 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005743 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5744 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005745
5746 return rval;
5747}
5748
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005749int
5750qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5751{
5752 int rval;
5753 mbx_cmd_t mc;
5754 mbx_cmd_t *mcp = &mc;
5755 struct qla_hw_data *ha = vha->hw;
5756 unsigned long retry_max_time = jiffies + (2 * HZ);
5757
Chad Dupuisf73cb692014-02-26 04:15:06 -05005758 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005759 return QLA_FUNCTION_FAILED;
5760
5761 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5762
5763retry_rd_reg:
5764 mcp->mb[0] = MBC_READ_REMOTE_REG;
5765 mcp->mb[1] = LSW(reg);
5766 mcp->mb[2] = MSW(reg);
5767 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5768 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5769 mcp->tov = MBX_TOV_SECONDS;
5770 mcp->flags = 0;
5771 rval = qla2x00_mailbox_command(vha, mcp);
5772
5773 if (rval != QLA_SUCCESS) {
5774 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5775 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5776 rval, mcp->mb[0], mcp->mb[1]);
5777 } else {
5778 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5779 if (*data == QLA8XXX_BAD_VALUE) {
5780 /*
5781 * During soft-reset CAMRAM register reads might
5782 * return 0xbad0bad0. So retry for MAX of 2 sec
5783 * while reading camram registers.
5784 */
5785 if (time_after(jiffies, retry_max_time)) {
5786 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5787 "Failure to read CAMRAM register. "
5788 "data=0x%x.\n", *data);
5789 return QLA_FUNCTION_FAILED;
5790 }
5791 msleep(100);
5792 goto retry_rd_reg;
5793 }
5794 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5795 }
5796
5797 return rval;
5798}
5799
5800int
5801qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5802{
5803 int rval;
5804 mbx_cmd_t mc;
5805 mbx_cmd_t *mcp = &mc;
5806 struct qla_hw_data *ha = vha->hw;
5807
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005808 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005809 return QLA_FUNCTION_FAILED;
5810
5811 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5812
5813 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5814 mcp->out_mb = MBX_0;
5815 mcp->in_mb = MBX_1|MBX_0;
5816 mcp->tov = MBX_TOV_SECONDS;
5817 mcp->flags = 0;
5818 rval = qla2x00_mailbox_command(vha, mcp);
5819
5820 if (rval != QLA_SUCCESS) {
5821 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5822 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5823 rval, mcp->mb[0], mcp->mb[1]);
5824 ha->isp_ops->fw_dump(vha, 0);
5825 } else {
5826 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5827 }
5828
5829 return rval;
5830}
5831
5832int
5833qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5834 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5835{
5836 int rval;
5837 mbx_cmd_t mc;
5838 mbx_cmd_t *mcp = &mc;
5839 uint8_t subcode = (uint8_t)options;
5840 struct qla_hw_data *ha = vha->hw;
5841
5842 if (!IS_QLA8031(ha))
5843 return QLA_FUNCTION_FAILED;
5844
5845 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5846
5847 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5848 mcp->mb[1] = options;
5849 mcp->out_mb = MBX_1|MBX_0;
5850 if (subcode & BIT_2) {
5851 mcp->mb[2] = LSW(start_addr);
5852 mcp->mb[3] = MSW(start_addr);
5853 mcp->mb[4] = LSW(end_addr);
5854 mcp->mb[5] = MSW(end_addr);
5855 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5856 }
5857 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5858 if (!(subcode & (BIT_2 | BIT_5)))
5859 mcp->in_mb |= MBX_4|MBX_3;
5860 mcp->tov = MBX_TOV_SECONDS;
5861 mcp->flags = 0;
5862 rval = qla2x00_mailbox_command(vha, mcp);
5863
5864 if (rval != QLA_SUCCESS) {
5865 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5866 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5867 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5868 mcp->mb[4]);
5869 ha->isp_ops->fw_dump(vha, 0);
5870 } else {
5871 if (subcode & BIT_5)
5872 *sector_size = mcp->mb[1];
5873 else if (subcode & (BIT_6 | BIT_7)) {
5874 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5875 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5876 } else if (subcode & (BIT_3 | BIT_4)) {
5877 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5878 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5879 }
5880 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5881 }
5882
5883 return rval;
5884}
Saurav Kashyap81178772012-08-22 14:21:04 -04005885
5886int
5887qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5888 uint32_t size)
5889{
5890 int rval;
5891 mbx_cmd_t mc;
5892 mbx_cmd_t *mcp = &mc;
5893
5894 if (!IS_MCTP_CAPABLE(vha->hw))
5895 return QLA_FUNCTION_FAILED;
5896
5897 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5898 "Entered %s.\n", __func__);
5899
5900 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5901 mcp->mb[1] = LSW(addr);
5902 mcp->mb[2] = MSW(req_dma);
5903 mcp->mb[3] = LSW(req_dma);
5904 mcp->mb[4] = MSW(size);
5905 mcp->mb[5] = LSW(size);
5906 mcp->mb[6] = MSW(MSD(req_dma));
5907 mcp->mb[7] = LSW(MSD(req_dma));
5908 mcp->mb[8] = MSW(addr);
5909 /* Setting RAM ID to valid */
5910 mcp->mb[10] |= BIT_7;
5911 /* For MCTP RAM ID is 0x40 */
5912 mcp->mb[10] |= 0x40;
5913
5914 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5915 MBX_0;
5916
5917 mcp->in_mb = MBX_0;
5918 mcp->tov = MBX_TOV_SECONDS;
5919 mcp->flags = 0;
5920 rval = qla2x00_mailbox_command(vha, mcp);
5921
5922 if (rval != QLA_SUCCESS) {
5923 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5924 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5925 } else {
5926 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5927 "Done %s.\n", __func__);
5928 }
5929
5930 return rval;
5931}
Joe Carnuccioec891462016-07-06 11:14:26 -04005932
5933int
5934qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5935 void *dd_buf, uint size, uint options)
5936{
5937 int rval;
5938 mbx_cmd_t mc;
5939 mbx_cmd_t *mcp = &mc;
5940 dma_addr_t dd_dma;
5941
5942 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5943 return QLA_FUNCTION_FAILED;
5944
Quinn Tran83548fe2017-06-02 09:12:01 -07005945 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04005946 "Entered %s.\n", __func__);
5947
Joe Carnuccioec891462016-07-06 11:14:26 -04005948 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5949 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08005950 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04005951 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5952 return QLA_MEMORY_ALLOC_FAILED;
5953 }
5954
5955 memset(dd_buf, 0, size);
5956
5957 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5958 mcp->mb[1] = options;
5959 mcp->mb[2] = MSW(LSD(dd_dma));
5960 mcp->mb[3] = LSW(LSD(dd_dma));
5961 mcp->mb[6] = MSW(MSD(dd_dma));
5962 mcp->mb[7] = LSW(MSD(dd_dma));
5963 mcp->mb[8] = size;
5964 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5965 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5966 mcp->buf_size = size;
5967 mcp->flags = MBX_DMA_IN;
5968 mcp->tov = MBX_TOV_SECONDS * 4;
5969 rval = qla2x00_mailbox_command(vha, mcp);
5970
5971 if (rval != QLA_SUCCESS) {
5972 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5973 } else {
5974 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5975 "Done %s.\n", __func__);
5976 }
5977
5978 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5979 size, DMA_FROM_DEVICE);
5980
5981 return rval;
5982}
Quinn Tran15f30a52017-03-15 09:48:52 -07005983
5984static void qla2x00_async_mb_sp_done(void *s, int res)
5985{
5986 struct srb *sp = s;
5987
5988 sp->u.iocb_cmd.u.mbx.rc = res;
5989
5990 complete(&sp->u.iocb_cmd.u.mbx.comp);
5991 /* don't free sp here. Let the caller do the free */
5992}
5993
5994/*
5995 * This mailbox uses the iocb interface to send MB command.
5996 * This allows non-critial (non chip setup) command to go
5997 * out in parrallel.
5998 */
5999int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
6000{
6001 int rval = QLA_FUNCTION_FAILED;
6002 srb_t *sp;
6003 struct srb_iocb *c;
6004
6005 if (!vha->hw->flags.fw_started)
6006 goto done;
6007
6008 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
6009 if (!sp)
6010 goto done;
6011
6012 sp->type = SRB_MB_IOCB;
6013 sp->name = mb_to_str(mcp->mb[0]);
6014
6015 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
6016
6017 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
6018
6019 c = &sp->u.iocb_cmd;
6020 c->timeout = qla2x00_async_iocb_timeout;
6021 init_completion(&c->u.mbx.comp);
6022
6023 sp->done = qla2x00_async_mb_sp_done;
6024
6025 rval = qla2x00_start_sp(sp);
6026 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006027 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07006028 "%s: %s Failed submission. %x.\n",
6029 __func__, sp->name, rval);
6030 goto done_free_sp;
6031 }
6032
Quinn Tran83548fe2017-06-02 09:12:01 -07006033 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006034 sp->name, sp->handle);
6035
6036 wait_for_completion(&c->u.mbx.comp);
6037 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
6038
6039 rval = c->u.mbx.rc;
6040 switch (rval) {
6041 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07006042 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006043 __func__, sp->name, rval);
6044 break;
6045 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07006046 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006047 __func__, sp->name);
6048 sp->free(sp);
6049 break;
6050 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07006051 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006052 __func__, sp->name, rval);
6053 sp->free(sp);
6054 break;
6055 }
6056
6057 return rval;
6058
6059done_free_sp:
6060 sp->free(sp);
6061done:
6062 return rval;
6063}
6064
6065/*
6066 * qla24xx_gpdb_wait
6067 * NOTE: Do not call this routine from DPC thread
6068 */
6069int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
6070{
6071 int rval = QLA_FUNCTION_FAILED;
6072 dma_addr_t pd_dma;
6073 struct port_database_24xx *pd;
6074 struct qla_hw_data *ha = vha->hw;
6075 mbx_cmd_t mc;
6076
6077 if (!vha->hw->flags.fw_started)
6078 goto done;
6079
Thomas Meyer08eb7f42017-09-21 08:15:26 +02006080 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran15f30a52017-03-15 09:48:52 -07006081 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006082 ql_log(ql_log_warn, vha, 0xd047,
6083 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07006084 goto done_free_sp;
6085 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006086
6087 memset(&mc, 0, sizeof(mc));
6088 mc.mb[0] = MBC_GET_PORT_DATABASE;
6089 mc.mb[1] = cpu_to_le16(fcport->loop_id);
6090 mc.mb[2] = MSW(pd_dma);
6091 mc.mb[3] = LSW(pd_dma);
6092 mc.mb[6] = MSW(MSD(pd_dma));
6093 mc.mb[7] = LSW(MSD(pd_dma));
6094 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6095 mc.mb[10] = cpu_to_le16((uint16_t)opt);
6096
6097 rval = qla24xx_send_mb_cmd(vha, &mc);
6098 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006099 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07006100 "%s: %8phC fail\n", __func__, fcport->port_name);
6101 goto done_free_sp;
6102 }
6103
6104 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
6105
Quinn Tran83548fe2017-06-02 09:12:01 -07006106 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006107 __func__, fcport->port_name);
6108
6109done_free_sp:
6110 if (pd)
6111 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
6112done:
6113 return rval;
6114}
6115
6116int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
6117 struct port_database_24xx *pd)
6118{
6119 int rval = QLA_SUCCESS;
6120 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006121 u8 current_login_state, last_login_state;
6122
6123 if (fcport->fc4f_nvme) {
6124 current_login_state = pd->current_login_state >> 4;
6125 last_login_state = pd->last_login_state >> 4;
6126 } else {
6127 current_login_state = pd->current_login_state & 0xf;
6128 last_login_state = pd->last_login_state & 0xf;
6129 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006130
6131 /* Check for logged in state. */
Quinn Tran23c64552017-12-04 14:45:08 -08006132 if (current_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006133 ql_dbg(ql_dbg_mbx, vha, 0x119a,
6134 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006135 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006136 rval = QLA_FUNCTION_FAILED;
6137 goto gpd_error_out;
6138 }
6139
6140 if (fcport->loop_id == FC_NO_LOOP_ID ||
6141 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6142 memcmp(fcport->port_name, pd->port_name, 8))) {
6143 /* We lost the device mid way. */
6144 rval = QLA_NOT_LOGGED_IN;
6145 goto gpd_error_out;
6146 }
6147
6148 /* Names are little-endian. */
6149 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6150 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6151
6152 /* Get port_id of device. */
6153 fcport->d_id.b.domain = pd->port_id[0];
6154 fcport->d_id.b.area = pd->port_id[1];
6155 fcport->d_id.b.al_pa = pd->port_id[2];
6156 fcport->d_id.b.rsvd_1 = 0;
6157
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006158 if (fcport->fc4f_nvme) {
6159 fcport->nvme_prli_service_param =
6160 pd->prli_nvme_svc_param_word_3;
6161 fcport->port_type = FCT_NVME;
6162 } else {
6163 /* If not target must be initiator or unknown type. */
6164 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6165 fcport->port_type = FCT_INITIATOR;
6166 else
6167 fcport->port_type = FCT_TARGET;
6168 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006169 /* Passback COS information. */
6170 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6171 FC_COS_CLASS2 : FC_COS_CLASS3;
6172
6173 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6174 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6175 fcport->conf_compl_supported = 1;
6176 }
6177
6178gpd_error_out:
6179 return rval;
6180}
6181
6182/*
6183 * qla24xx_gidlist__wait
6184 * NOTE: don't call this routine from DPC thread.
6185 */
6186int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6187 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6188{
6189 int rval = QLA_FUNCTION_FAILED;
6190 mbx_cmd_t mc;
6191
6192 if (!vha->hw->flags.fw_started)
6193 goto done;
6194
6195 memset(&mc, 0, sizeof(mc));
6196 mc.mb[0] = MBC_GET_ID_LIST;
6197 mc.mb[2] = MSW(id_list_dma);
6198 mc.mb[3] = LSW(id_list_dma);
6199 mc.mb[6] = MSW(MSD(id_list_dma));
6200 mc.mb[7] = LSW(MSD(id_list_dma));
6201 mc.mb[8] = 0;
6202 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6203
6204 rval = qla24xx_send_mb_cmd(vha, &mc);
6205 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006206 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6207 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006208 } else {
6209 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006210 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6211 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006212 }
6213done:
6214 return rval;
6215}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006216
6217int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6218{
6219 int rval;
6220 mbx_cmd_t mc;
6221 mbx_cmd_t *mcp = &mc;
6222
6223 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6224 "Entered %s\n", __func__);
6225
6226 memset(mcp->mb, 0 , sizeof(mcp->mb));
6227 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6228 mcp->mb[1] = cpu_to_le16(1);
6229 mcp->mb[2] = cpu_to_le16(value);
6230 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6231 mcp->in_mb = MBX_2 | MBX_0;
6232 mcp->tov = MBX_TOV_SECONDS;
6233 mcp->flags = 0;
6234
6235 rval = qla2x00_mailbox_command(vha, mcp);
6236
6237 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6238 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6239
6240 return rval;
6241}
6242
6243int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6244{
6245 int rval;
6246 mbx_cmd_t mc;
6247 mbx_cmd_t *mcp = &mc;
6248
6249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6250 "Entered %s\n", __func__);
6251
6252 memset(mcp->mb, 0, sizeof(mcp->mb));
6253 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6254 mcp->mb[1] = cpu_to_le16(0);
6255 mcp->out_mb = MBX_1 | MBX_0;
6256 mcp->in_mb = MBX_2 | MBX_0;
6257 mcp->tov = MBX_TOV_SECONDS;
6258 mcp->flags = 0;
6259
6260 rval = qla2x00_mailbox_command(vha, mcp);
6261 if (rval == QLA_SUCCESS)
6262 *value = mc.mb[2];
6263
6264 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6265 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6266
6267 return rval;
6268}
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006269
6270int
6271qla2x00_read_sfp_dev(struct scsi_qla_host *vha, char *buf, int count)
6272{
6273 struct qla_hw_data *ha = vha->hw;
6274 uint16_t iter, addr, offset;
6275 dma_addr_t phys_addr;
6276 int rval, c;
6277 u8 *sfp_data;
6278
6279 memset(ha->sfp_data, 0, SFP_DEV_SIZE);
6280 addr = 0xa0;
6281 phys_addr = ha->sfp_data_dma;
6282 sfp_data = ha->sfp_data;
6283 offset = c = 0;
6284
6285 for (iter = 0; iter < SFP_DEV_SIZE / SFP_BLOCK_SIZE; iter++) {
6286 if (iter == 4) {
6287 /* Skip to next device address. */
6288 addr = 0xa2;
6289 offset = 0;
6290 }
6291
6292 rval = qla2x00_read_sfp(vha, phys_addr, sfp_data,
6293 addr, offset, SFP_BLOCK_SIZE, BIT_1);
6294 if (rval != QLA_SUCCESS) {
6295 ql_log(ql_log_warn, vha, 0x706d,
6296 "Unable to read SFP data (%x/%x/%x).\n", rval,
6297 addr, offset);
6298
6299 return rval;
6300 }
6301
6302 if (buf && (c < count)) {
6303 u16 sz;
6304
6305 if ((count - c) >= SFP_BLOCK_SIZE)
6306 sz = SFP_BLOCK_SIZE;
6307 else
6308 sz = count - c;
6309
6310 memcpy(buf, sfp_data, sz);
6311 buf += SFP_BLOCK_SIZE;
6312 c += sz;
6313 }
6314 phys_addr += SFP_BLOCK_SIZE;
6315 sfp_data += SFP_BLOCK_SIZE;
6316 offset += SFP_BLOCK_SIZE;
6317 }
6318
6319 return rval;
6320}
Quinn Tran94d83e32017-12-28 12:33:23 -08006321
6322int qla24xx_res_count_wait(struct scsi_qla_host *vha,
6323 uint16_t *out_mb, int out_mb_sz)
6324{
6325 int rval = QLA_FUNCTION_FAILED;
6326 mbx_cmd_t mc;
6327
6328 if (!vha->hw->flags.fw_started)
6329 goto done;
6330
6331 memset(&mc, 0, sizeof(mc));
6332 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
6333
6334 rval = qla24xx_send_mb_cmd(vha, &mc);
6335 if (rval != QLA_SUCCESS) {
6336 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6337 "%s: fail\n", __func__);
6338 } else {
6339 if (out_mb_sz <= SIZEOF_IOCB_MB_REG)
6340 memcpy(out_mb, mc.mb, out_mb_sz);
6341 else
6342 memcpy(out_mb, mc.mb, SIZEOF_IOCB_MB_REG);
6343
6344 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6345 "%s: done\n", __func__);
6346 }
6347done:
6348 return rval;
6349}