blob: 1f91b87b64162cb46649698b9949771c79252213 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Quinn Tran15f30a52017-03-15 09:48:52 -070013static struct mb_cmd_name {
14 uint16_t cmd;
15 const char *str;
16} mb_str[] = {
17 {MBC_GET_PORT_DATABASE, "GPDB"},
18 {MBC_GET_ID_LIST, "GIDList"},
19 {MBC_GET_LINK_PRIV_STATS, "Stats"},
20};
21
22static const char *mb_to_str(uint16_t cmd)
23{
24 int i;
25 struct mb_cmd_name *e;
26
27 for (i = 0; i < ARRAY_SIZE(mb_str); i++) {
28 e = mb_str + i;
29 if (cmd == e->cmd)
30 return e->str;
31 }
32 return "unknown";
33}
34
Bart Van Asscheca825822017-01-17 09:34:14 -080035static struct rom_cmd {
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080036 uint16_t cmd;
37} rom_cmds[] = {
38 { MBC_LOAD_RAM },
39 { MBC_EXECUTE_FIRMWARE },
40 { MBC_READ_RAM_WORD },
41 { MBC_MAILBOX_REGISTER_TEST },
42 { MBC_VERIFY_CHECKSUM },
43 { MBC_GET_FIRMWARE_VERSION },
44 { MBC_LOAD_RISC_RAM },
45 { MBC_DUMP_RISC_RAM },
46 { MBC_LOAD_RISC_RAM_EXTENDED },
47 { MBC_DUMP_RISC_RAM_EXTENDED },
48 { MBC_WRITE_RAM_WORD_EXTENDED },
49 { MBC_READ_RAM_EXTENDED },
50 { MBC_GET_RESOURCE_COUNTS },
51 { MBC_SET_FIRMWARE_OPTION },
52 { MBC_MID_INITIALIZE_FIRMWARE },
53 { MBC_GET_FIRMWARE_STATE },
54 { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
55 { MBC_GET_RETRY_COUNT },
56 { MBC_TRACE_CONTROL },
57};
58
59static int is_rom_cmd(uint16_t cmd)
60{
61 int i;
62 struct rom_cmd *wc;
63
64 for (i = 0; i < ARRAY_SIZE(rom_cmds); i++) {
65 wc = rom_cmds + i;
66 if (wc->cmd == cmd)
67 return 1;
68 }
69
70 return 0;
71}
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/*
74 * qla2x00_mailbox_command
75 * Issue mailbox command and waits for completion.
76 *
77 * Input:
78 * ha = adapter block pointer.
79 * mcp = driver internal mbx struct pointer.
80 *
81 * Output:
82 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
83 *
84 * Returns:
85 * 0 : QLA_SUCCESS = cmd performed success
86 * 1 : QLA_FUNCTION_FAILED (error encountered)
87 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
88 *
89 * Context:
90 * Kernel context.
91 */
92static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080093qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040095 int rval, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned long flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -050097 device_reg_t *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070098 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070099 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700100 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 uint16_t *iptr;
102 uint16_t __iomem *optr;
103 uint32_t cnt;
104 uint32_t mboxes;
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400105 uint16_t __iomem *mbx_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800107 struct qla_hw_data *ha = vha->hw;
108 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700109
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400110
Arun Easi5e19ed92012-02-09 11:15:51 -0800111 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700112
113 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800114 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700115 "error_state is greater than pci_channel_io_frozen, "
116 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -0700117 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700118 }
Seokmann Jub9b12f72009-03-24 09:08:18 -0700119
Giridhar Malavalia9083012010-04-12 17:59:55 -0700120 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800121 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700122 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700123 return QLA_FUNCTION_TIMEOUT;
124 }
125
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800126 /* if PCI error, then avoid mbx processing.*/
Sawan Chandakba175892017-06-02 09:11:58 -0700127 if (test_bit(PFLG_DISCONNECTED, &base_vha->dpc_flags) &&
128 test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700129 ql_log(ql_log_warn, vha, 0xd04e,
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400130 "PCI error, exiting.\n");
131 return QLA_FUNCTION_TIMEOUT;
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800132 }
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400133
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700134 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800135 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800138 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700140
Andrew Vasquez85880802009-12-15 21:29:46 -0800141 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800142 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700143 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800144 return QLA_FUNCTION_TIMEOUT;
145 }
146
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400147 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -0800148 /* Setting Link-Down error */
149 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -0800150 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700151 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -0800152 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -0800153 }
154
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800155 /* check if ISP abort is active and return cmd with timeout */
156 if ((test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
157 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
158 test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) &&
159 !is_rom_cmd(mcp->mb[0])) {
160 ql_log(ql_log_info, vha, 0x1005,
161 "Cmd 0x%x aborted with timeout since ISP Abort is pending\n",
162 mcp->mb[0]);
163 return QLA_FUNCTION_TIMEOUT;
164 }
165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700167 * Wait for active mailbox commands to finish by waiting at most tov
168 * seconds. This is to serialize actual issuing of mailbox cmds during
169 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800171 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
172 /* Timeout occurred. Return error. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700173 ql_log(ql_log_warn, vha, 0xd035,
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800174 "Cmd access timeout, cmd=0x%x, Exiting.\n",
175 mcp->mb[0]);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800176 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 }
178
179 ha->flags.mbox_busy = 1;
180 /* Save mailbox command for debug */
181 ha->mcp = mcp;
182
Arun Easi5e19ed92012-02-09 11:15:51 -0800183 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700184 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 spin_lock_irqsave(&ha->hardware_lock, flags);
187
188 /* Load mailbox registers. */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400189 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700190 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400191 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha)))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700192 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
193 else
194 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 iptr = mcp->mb;
197 command = mcp->mb[0];
198 mboxes = mcp->out_mb;
199
Joe Carnuccio7b711622014-09-25 05:16:43 -0400200 ql_dbg(ql_dbg_mbx, vha, 0x1111,
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700201 "Mailbox registers (OUT):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
203 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700204 optr =
205 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700206 if (mboxes & BIT_0) {
207 ql_dbg(ql_dbg_mbx, vha, 0x1112,
208 "mbox[%d]<-0x%04x\n", cnt, *iptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 WRT_REG_WORD(optr, *iptr);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 mboxes >>= 1;
213 optr++;
214 iptr++;
215 }
216
Arun Easi5e19ed92012-02-09 11:15:51 -0800217 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700218 "I/O Address = %p.\n", optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /* Issue set host interrupt command to send cmd out. */
221 ha->flags.mbox_int = 0;
222 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
223
224 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800225 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700226 "Going to unlock irq & waiting for interrupts. "
227 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* Wait for mbx cmd completion until timeout */
230
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800231 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
233
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400234 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700235 if (RD_REG_DWORD(&reg->isp82.hint) &
236 HINT_MBX_INT_PENDING) {
237 spin_unlock_irqrestore(&ha->hardware_lock,
238 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800239 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800240 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700241 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700242 rval = QLA_FUNCTION_TIMEOUT;
243 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700244 }
245 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
246 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700247 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
248 else
249 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 spin_unlock_irqrestore(&ha->hardware_lock, flags);
251
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800252 wait_time = jiffies;
Giridhar Malavali754d1242013-06-25 11:27:16 -0400253 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
254 mcp->tov * HZ)) {
255 ql_dbg(ql_dbg_mbx, vha, 0x117a,
256 "cmd=%x Timeout.\n", command);
257 spin_lock_irqsave(&ha->hardware_lock, flags);
258 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
259 spin_unlock_irqrestore(&ha->hardware_lock, flags);
260 }
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800261 if (time_after(jiffies, wait_time + 5 * HZ))
262 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
263 command, jiffies_to_msecs(jiffies - wait_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800265 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700266 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400268 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700269 if (RD_REG_DWORD(&reg->isp82.hint) &
270 HINT_MBX_INT_PENDING) {
271 spin_unlock_irqrestore(&ha->hardware_lock,
272 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800273 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800274 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700275 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700276 rval = QLA_FUNCTION_TIMEOUT;
277 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700278 }
279 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
280 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700281 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
282 else
283 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
287 while (!ha->flags.mbox_int) {
288 if (time_after(jiffies, wait_time))
289 break;
290
291 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800292 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Andrew Vasquez85880802009-12-15 21:29:46 -0800294 if (!ha->flags.mbox_int &&
295 !(IS_QLA2200(ha) &&
296 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800297 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800299 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700300 "Waited %d sec.\n",
301 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /* Check whether we timed out */
305 if (ha->flags.mbox_int) {
306 uint16_t *iptr2;
307
Arun Easi5e19ed92012-02-09 11:15:51 -0800308 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700309 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
311 /* Got interrupt. Clear the flag. */
312 ha->flags.mbox_int = 0;
313 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
314
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400315 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700316 ha->flags.mbox_busy = 0;
317 /* Setting Link-Down error */
318 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
319 ha->mcp = NULL;
320 rval = QLA_FUNCTION_FAILED;
Quinn Tran83548fe2017-06-02 09:12:01 -0700321 ql_log(ql_log_warn, vha, 0xd048,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700322 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700323 goto premature_exit;
324 }
325
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400326 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 /* Load return mailbox registers. */
330 iptr2 = mcp->mb;
331 iptr = (uint16_t *)&ha->mailbox_out[0];
332 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700333
334 ql_dbg(ql_dbg_mbx, vha, 0x1113,
335 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700337 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700339 ql_dbg(ql_dbg_mbx, vha, 0x1114,
340 "mbox[%d]->0x%04x\n", cnt, *iptr2);
341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 mboxes >>= 1;
344 iptr2++;
345 iptr++;
346 }
347 } else {
348
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800349 uint16_t mb[8];
350 uint32_t ictrl, host_status, hccr;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400351 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700352
Andrew Vasqueze4289242007-07-19 15:05:56 -0700353 if (IS_FWI2_CAPABLE(ha)) {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800354 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
355 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
356 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
357 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
358 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700359 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800360 host_status = RD_REG_DWORD(&reg->isp24.host_status);
361 hccr = RD_REG_DWORD(&reg->isp24.hccr);
362
Quinn Tran83548fe2017-06-02 09:12:01 -0700363 ql_log(ql_log_warn, vha, 0xd04c,
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800364 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
365 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
366 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
367 mb[7], host_status, hccr);
368
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700369 } else {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800370 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700371 ictrl = RD_REG_WORD(&reg->isp.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800372 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
373 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
374 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700375 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800376 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400378 /* Capture FW dump only, if PCI device active */
379 if (!pci_channel_offline(vha->hw->pdev)) {
380 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
381 if (w == 0xffff || ictrl == 0xffffffff) {
382 /* This is special case if there is unload
383 * of driver happening and if PCI device go
384 * into bad state due to PCI error condition
385 * then only PCI ERR flag would be set.
386 * we will do premature exit for above case.
387 */
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400388 ha->flags.mbox_busy = 0;
389 rval = QLA_FUNCTION_TIMEOUT;
390 goto premature_exit;
391 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800392
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400393 /* Attempt to capture firmware dump for further
394 * anallysis of the current formware state. we do not
395 * need to do this if we are intentionally generating
396 * a dump
397 */
398 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
399 ha->isp_ops->fw_dump(vha, 0);
400 rval = QLA_FUNCTION_TIMEOUT;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 }
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 ha->flags.mbox_busy = 0;
405
406 /* Clean up */
407 ha->mcp = NULL;
408
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800409 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800410 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700411 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800414 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700417 if (rval == QLA_FUNCTION_TIMEOUT &&
418 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800419 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
420 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800422 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700423 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700424
425 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
426 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
427 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800428 if (IS_QLA82XX(ha)) {
429 ql_dbg(ql_dbg_mbx, vha, 0x112a,
430 "disabling pause transmit on port "
431 "0 & 1.\n");
432 qla82xx_wr_32(ha,
433 QLA82XX_CRB_NIU + 0x98,
434 CRB_NIU_XG_PAUSE_CTL_P0|
435 CRB_NIU_XG_PAUSE_CTL_P1);
436 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700437 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400438 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800439 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
440 "abort.\n", command, mcp->mb[0],
441 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700442 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
443 qla2xxx_wake_dpc(vha);
444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800447 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700448 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700450 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
451 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
452 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800453 if (IS_QLA82XX(ha)) {
454 ql_dbg(ql_dbg_mbx, vha, 0x112b,
455 "disabling pause transmit on port "
456 "0 & 1.\n");
457 qla82xx_wr_32(ha,
458 QLA82XX_CRB_NIU + 0x98,
459 CRB_NIU_XG_PAUSE_CTL_P0|
460 CRB_NIU_XG_PAUSE_CTL_P1);
461 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700462 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400463 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800464 "mb[0]=0x%x. Scheduling ISP abort ",
465 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700466 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
467 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800468 /* Allow next mbx cmd to come in. */
469 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700470 if (ha->isp_ops->abort_isp(vha)) {
471 /* Failed. retry later. */
472 set_bit(ISP_ABORT_NEEDED,
473 &vha->dpc_flags);
474 }
475 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800476 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700477 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800478 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481 }
482
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700483premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800485 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Giridhar Malavalid3360962012-02-09 11:14:10 -0800487mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (rval) {
Chad Dupuis34c58012014-08-08 07:38:08 -0400489 ql_dbg(ql_dbg_disc, base_vha, 0x1020,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800490 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
491 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400492
Sawan Chandak75d560e2016-07-06 11:14:33 -0400493 ql_dbg(ql_dbg_mbx, vha, 0x1198,
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400494 "host status: 0x%x, flags:0x%lx, intr ctrl reg:0x%x, intr status:0x%x\n",
495 RD_REG_DWORD(&reg->isp24.host_status),
496 ha->fw_dump_cap_flags,
497 RD_REG_DWORD(&reg->isp24.ictrl),
498 RD_REG_DWORD(&reg->isp24.istatus));
499
500 mbx_reg = &reg->isp24.mailbox0;
501 for (i = 0; i < 6; i++)
Sawan Chandak75d560e2016-07-06 11:14:33 -0400502 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1199,
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400503 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700505 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 }
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return rval;
509}
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800512qla2x00_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 -0800513 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
515 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800516 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 mbx_cmd_t mc;
518 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400520 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
521 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
Andrew Vasqueze4289242007-07-19 15:05:56 -0700523 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800524 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
525 mcp->mb[8] = MSW(risc_addr);
526 mcp->out_mb = MBX_8|MBX_0;
527 } else {
528 mcp->mb[0] = MBC_LOAD_RISC_RAM;
529 mcp->out_mb = MBX_0;
530 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 mcp->mb[1] = LSW(risc_addr);
532 mcp->mb[2] = MSW(req_dma);
533 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 mcp->mb[6] = MSW(MSD(req_dma));
535 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800536 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700537 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700538 mcp->mb[4] = MSW(risc_code_size);
539 mcp->mb[5] = LSW(risc_code_size);
540 mcp->out_mb |= MBX_5|MBX_4;
541 } else {
542 mcp->mb[4] = LSW(risc_code_size);
543 mcp->out_mb |= MBX_4;
544 }
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700547 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800549 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700552 ql_dbg(ql_dbg_mbx, vha, 0x1023,
553 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400555 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
556 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
559 return rval;
560}
561
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700562#define EXTENDED_BB_CREDITS BIT_0
Duane Grigsbye84067d2017-06-21 13:48:43 -0700563#define NVME_ENABLE_FLAG BIT_3
564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565/*
566 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700567 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 *
569 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700570 * ha = adapter block pointer.
571 * TARGET_QUEUE_LOCK must be released.
572 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 *
574 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700575 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 *
577 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700578 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 */
580int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800581qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582{
583 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800584 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 mbx_cmd_t mc;
586 mbx_cmd_t *mcp = &mc;
587
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
589 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
591 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700592 mcp->out_mb = MBX_0;
593 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700594 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700595 mcp->mb[1] = MSW(risc_addr);
596 mcp->mb[2] = LSW(risc_addr);
597 mcp->mb[3] = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500598 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
599 IS_QLA27XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700600 struct nvram_81xx *nv = ha->nvram;
601 mcp->mb[4] = (nv->enhanced_features &
602 EXTENDED_BB_CREDITS);
603 } else
604 mcp->mb[4] = 0;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500605
Duane Grigsbye84067d2017-06-21 13:48:43 -0700606 if (ql2xnvmeenable && IS_QLA27XX(ha))
607 mcp->mb[4] |= NVME_ENABLE_FLAG;
608
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500609 if (ha->flags.exlogins_enabled)
610 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
611
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500612 if (ha->flags.exchoffld_enabled)
613 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
614
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700615 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700616 mcp->in_mb |= MBX_1;
617 } else {
618 mcp->mb[1] = LSW(risc_addr);
619 mcp->out_mb |= MBX_1;
620 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
621 mcp->mb[2] = 0;
622 mcp->out_mb |= MBX_2;
623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 }
625
Ravi Anandb93480e2008-04-03 13:13:25 -0700626 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800628 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700630 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700631 ql_dbg(ql_dbg_mbx, vha, 0x1026,
632 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700633 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700634 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400635 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700636 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700637 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400638 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
639 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700640 }
641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643 return rval;
644}
645
646/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500647 * qla_get_exlogin_status
648 * Get extended login status
649 * uses the memory offload control/status Mailbox
650 *
651 * Input:
652 * ha: adapter state pointer.
653 * fwopt: firmware options
654 *
655 * Returns:
656 * qla2x00 local function status
657 *
658 * Context:
659 * Kernel context.
660 */
661#define FETCH_XLOGINS_STAT 0x8
662int
663qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
664 uint16_t *ex_logins_cnt)
665{
666 int rval;
667 mbx_cmd_t mc;
668 mbx_cmd_t *mcp = &mc;
669
670 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
671 "Entered %s\n", __func__);
672
673 memset(mcp->mb, 0 , sizeof(mcp->mb));
674 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
675 mcp->mb[1] = FETCH_XLOGINS_STAT;
676 mcp->out_mb = MBX_1|MBX_0;
677 mcp->in_mb = MBX_10|MBX_4|MBX_0;
678 mcp->tov = MBX_TOV_SECONDS;
679 mcp->flags = 0;
680
681 rval = qla2x00_mailbox_command(vha, mcp);
682 if (rval != QLA_SUCCESS) {
683 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
684 } else {
685 *buf_sz = mcp->mb[4];
686 *ex_logins_cnt = mcp->mb[10];
687
688 ql_log(ql_log_info, vha, 0x1190,
689 "buffer size 0x%x, exchange login count=%d\n",
690 mcp->mb[4], mcp->mb[10]);
691
692 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
693 "Done %s.\n", __func__);
694 }
695
696 return rval;
697}
698
699/*
700 * qla_set_exlogin_mem_cfg
701 * set extended login memory configuration
702 * Mbx needs to be issues before init_cb is set
703 *
704 * Input:
705 * ha: adapter state pointer.
706 * buffer: buffer pointer
707 * phys_addr: physical address of buffer
708 * size: size of buffer
709 * TARGET_QUEUE_LOCK must be released
710 * ADAPTER_STATE_LOCK must be release
711 *
712 * Returns:
713 * qla2x00 local funxtion status code.
714 *
715 * Context:
716 * Kernel context.
717 */
718#define CONFIG_XLOGINS_MEM 0x3
719int
720qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
721{
722 int rval;
723 mbx_cmd_t mc;
724 mbx_cmd_t *mcp = &mc;
725 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500726
727 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
728 "Entered %s.\n", __func__);
729
730 memset(mcp->mb, 0 , sizeof(mcp->mb));
731 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
732 mcp->mb[1] = CONFIG_XLOGINS_MEM;
733 mcp->mb[2] = MSW(phys_addr);
734 mcp->mb[3] = LSW(phys_addr);
735 mcp->mb[6] = MSW(MSD(phys_addr));
736 mcp->mb[7] = LSW(MSD(phys_addr));
737 mcp->mb[8] = MSW(ha->exlogin_size);
738 mcp->mb[9] = LSW(ha->exlogin_size);
739 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
740 mcp->in_mb = MBX_11|MBX_0;
741 mcp->tov = MBX_TOV_SECONDS;
742 mcp->flags = 0;
743 rval = qla2x00_mailbox_command(vha, mcp);
744 if (rval != QLA_SUCCESS) {
745 /*EMPTY*/
746 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
747 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500748 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
749 "Done %s.\n", __func__);
750 }
751
752 return rval;
753}
754
755/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500756 * qla_get_exchoffld_status
757 * Get exchange offload status
758 * uses the memory offload control/status Mailbox
759 *
760 * Input:
761 * ha: adapter state pointer.
762 * fwopt: firmware options
763 *
764 * Returns:
765 * qla2x00 local function status
766 *
767 * Context:
768 * Kernel context.
769 */
770#define FETCH_XCHOFFLD_STAT 0x2
771int
772qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
773 uint16_t *ex_logins_cnt)
774{
775 int rval;
776 mbx_cmd_t mc;
777 mbx_cmd_t *mcp = &mc;
778
779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
780 "Entered %s\n", __func__);
781
782 memset(mcp->mb, 0 , sizeof(mcp->mb));
783 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
784 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
785 mcp->out_mb = MBX_1|MBX_0;
786 mcp->in_mb = MBX_10|MBX_4|MBX_0;
787 mcp->tov = MBX_TOV_SECONDS;
788 mcp->flags = 0;
789
790 rval = qla2x00_mailbox_command(vha, mcp);
791 if (rval != QLA_SUCCESS) {
792 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
793 } else {
794 *buf_sz = mcp->mb[4];
795 *ex_logins_cnt = mcp->mb[10];
796
797 ql_log(ql_log_info, vha, 0x118e,
798 "buffer size 0x%x, exchange offload count=%d\n",
799 mcp->mb[4], mcp->mb[10]);
800
801 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
802 "Done %s.\n", __func__);
803 }
804
805 return rval;
806}
807
808/*
809 * qla_set_exchoffld_mem_cfg
810 * Set exchange offload memory configuration
811 * Mbx needs to be issues before init_cb is set
812 *
813 * Input:
814 * ha: adapter state pointer.
815 * buffer: buffer pointer
816 * phys_addr: physical address of buffer
817 * size: size of buffer
818 * TARGET_QUEUE_LOCK must be released
819 * ADAPTER_STATE_LOCK must be release
820 *
821 * Returns:
822 * qla2x00 local funxtion status code.
823 *
824 * Context:
825 * Kernel context.
826 */
827#define CONFIG_XCHOFFLD_MEM 0x3
828int
Quinn Tran99e1b682017-06-02 09:12:03 -0700829qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500830{
831 int rval;
832 mbx_cmd_t mc;
833 mbx_cmd_t *mcp = &mc;
834 struct qla_hw_data *ha = vha->hw;
835
836 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
837 "Entered %s.\n", __func__);
838
839 memset(mcp->mb, 0 , sizeof(mcp->mb));
840 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
841 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -0700842 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
843 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
844 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
845 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
846 mcp->mb[8] = MSW(ha->exchoffld_size);
847 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500848 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
849 mcp->in_mb = MBX_11|MBX_0;
850 mcp->tov = MBX_TOV_SECONDS;
851 mcp->flags = 0;
852 rval = qla2x00_mailbox_command(vha, mcp);
853 if (rval != QLA_SUCCESS) {
854 /*EMPTY*/
855 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
856 } else {
857 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
858 "Done %s.\n", __func__);
859 }
860
861 return rval;
862}
863
864/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 * qla2x00_get_fw_version
866 * Get firmware version.
867 *
868 * Input:
869 * ha: adapter state pointer.
870 * major: pointer for major number.
871 * minor: pointer for minor number.
872 * subminor: pointer for subminor number.
873 *
874 * Returns:
875 * qla2x00 local function return status code.
876 *
877 * Context:
878 * Kernel context.
879 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700880int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800881qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
883 int rval;
884 mbx_cmd_t mc;
885 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800886 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400888 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
889 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890
891 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
892 mcp->out_mb = MBX_0;
893 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400894 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700895 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400896 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800897 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500898 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400899 mcp->in_mb |=
900 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
901 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -0400902
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700904 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800905 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700906 if (rval != QLA_SUCCESS)
907 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800910 ha->fw_major_version = mcp->mb[1];
911 ha->fw_minor_version = mcp->mb[2];
912 ha->fw_subminor_version = mcp->mb[3];
913 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800914 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800915 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800917 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -0400918
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400919 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800920 ha->mpi_version[0] = mcp->mb[10] & 0xff;
921 ha->mpi_version[1] = mcp->mb[11] >> 8;
922 ha->mpi_version[2] = mcp->mb[11] & 0xff;
923 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
924 ha->phy_version[0] = mcp->mb[8] & 0xff;
925 ha->phy_version[1] = mcp->mb[9] >> 8;
926 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800927 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400928
Saurav Kashyap81178772012-08-22 14:21:04 -0400929 if (IS_FWI2_CAPABLE(ha)) {
930 ha->fw_attributes_h = mcp->mb[15];
931 ha->fw_attributes_ext[0] = mcp->mb[16];
932 ha->fw_attributes_ext[1] = mcp->mb[17];
933 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
934 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
935 __func__, mcp->mb[15], mcp->mb[6]);
936 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
937 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
938 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500939
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500940 if (ha->fw_attributes_h & 0x4)
941 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
942 "%s: Firmware supports Extended Login 0x%x\n",
943 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500944
945 if (ha->fw_attributes_h & 0x8)
946 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
947 "%s: Firmware supports Exchange Offload 0x%x\n",
948 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -0700949
Duane Grigsbydeeae7a2017-07-21 09:32:25 -0700950 /*
951 * FW supports nvme and driver load parameter requested nvme.
952 * BIT 26 of fw_attributes indicates NVMe support.
953 */
954 if ((ha->fw_attributes_h & 0x400) && ql2xnvmeenable)
Duane Grigsbye84067d2017-06-21 13:48:43 -0700955 vha->flags.nvme_enabled = 1;
Duane Grigsbye84067d2017-06-21 13:48:43 -0700956
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800957 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400958
Chad Dupuisf73cb692014-02-26 04:15:06 -0500959 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -0400960 ha->mpi_version[0] = mcp->mb[10] & 0xff;
961 ha->mpi_version[1] = mcp->mb[11] >> 8;
962 ha->mpi_version[2] = mcp->mb[11] & 0xff;
963 ha->pep_version[0] = mcp->mb[13] & 0xff;
964 ha->pep_version[1] = mcp->mb[14] >> 8;
965 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500966 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
967 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400968 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
969 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -0500970 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800971
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700972failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 if (rval != QLA_SUCCESS) {
974 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700975 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 } else {
977 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400978 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
979 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700981 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982}
983
984/*
985 * qla2x00_get_fw_options
986 * Set firmware options.
987 *
988 * Input:
989 * ha = adapter block pointer.
990 * fwopt = pointer for firmware options.
991 *
992 * Returns:
993 * qla2x00 local function return status code.
994 *
995 * Context:
996 * Kernel context.
997 */
998int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800999qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000{
1001 int rval;
1002 mbx_cmd_t mc;
1003 mbx_cmd_t *mcp = &mc;
1004
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001005 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1006 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
1008 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1009 mcp->out_mb = MBX_0;
1010 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001011 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001013 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 if (rval != QLA_SUCCESS) {
1016 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001017 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001019 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 fwopts[1] = mcp->mb[1];
1021 fwopts[2] = mcp->mb[2];
1022 fwopts[3] = mcp->mb[3];
1023
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001024 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1025 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027
1028 return rval;
1029}
1030
1031
1032/*
1033 * qla2x00_set_fw_options
1034 * Set firmware options.
1035 *
1036 * Input:
1037 * ha = adapter block pointer.
1038 * fwopt = pointer for firmware options.
1039 *
1040 * Returns:
1041 * qla2x00 local function return status code.
1042 *
1043 * Context:
1044 * Kernel context.
1045 */
1046int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001047qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
1049 int rval;
1050 mbx_cmd_t mc;
1051 mbx_cmd_t *mcp = &mc;
1052
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001053 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1054 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
1056 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1057 mcp->mb[1] = fwopts[1];
1058 mcp->mb[2] = fwopts[2];
1059 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001060 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001062 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001063 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001064 mcp->mb[10] = fwopts[10];
1065 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001066 } else {
1067 mcp->mb[10] = fwopts[10];
1068 mcp->mb[11] = fwopts[11];
1069 mcp->mb[12] = 0; /* Undocumented, but used */
1070 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1071 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001072 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001074 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001076 fwopts[0] = mcp->mb[0];
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (rval != QLA_SUCCESS) {
1079 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001080 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1081 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 } else {
1083 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001084 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1085 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
1087
1088 return rval;
1089}
1090
1091/*
1092 * qla2x00_mbx_reg_test
1093 * Mailbox register wrap test.
1094 *
1095 * Input:
1096 * ha = adapter block pointer.
1097 * TARGET_QUEUE_LOCK must be released.
1098 * ADAPTER_STATE_LOCK must be released.
1099 *
1100 * Returns:
1101 * qla2x00 local function return status code.
1102 *
1103 * Context:
1104 * Kernel context.
1105 */
1106int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001107qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108{
1109 int rval;
1110 mbx_cmd_t mc;
1111 mbx_cmd_t *mcp = &mc;
1112
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001113 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1114 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
1116 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1117 mcp->mb[1] = 0xAAAA;
1118 mcp->mb[2] = 0x5555;
1119 mcp->mb[3] = 0xAA55;
1120 mcp->mb[4] = 0x55AA;
1121 mcp->mb[5] = 0xA5A5;
1122 mcp->mb[6] = 0x5A5A;
1123 mcp->mb[7] = 0x2525;
1124 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1125 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 -07001126 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001128 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
1130 if (rval == QLA_SUCCESS) {
1131 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1132 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1133 rval = QLA_FUNCTION_FAILED;
1134 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1135 mcp->mb[7] != 0x2525)
1136 rval = QLA_FUNCTION_FAILED;
1137 }
1138
1139 if (rval != QLA_SUCCESS) {
1140 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001141 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 } else {
1143 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001144 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1145 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 }
1147
1148 return rval;
1149}
1150
1151/*
1152 * qla2x00_verify_checksum
1153 * Verify firmware checksum.
1154 *
1155 * Input:
1156 * ha = adapter block pointer.
1157 * TARGET_QUEUE_LOCK must be released.
1158 * ADAPTER_STATE_LOCK must be released.
1159 *
1160 * Returns:
1161 * qla2x00 local function return status code.
1162 *
1163 * Context:
1164 * Kernel context.
1165 */
1166int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001167qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
1169 int rval;
1170 mbx_cmd_t mc;
1171 mbx_cmd_t *mcp = &mc;
1172
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001173 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1174 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001177 mcp->out_mb = MBX_0;
1178 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001179 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001180 mcp->mb[1] = MSW(risc_addr);
1181 mcp->mb[2] = LSW(risc_addr);
1182 mcp->out_mb |= MBX_2|MBX_1;
1183 mcp->in_mb |= MBX_2|MBX_1;
1184 } else {
1185 mcp->mb[1] = LSW(risc_addr);
1186 mcp->out_mb |= MBX_1;
1187 mcp->in_mb |= MBX_1;
1188 }
1189
Ravi Anandb93480e2008-04-03 13:13:25 -07001190 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001192 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001195 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1196 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1197 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001199 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1200 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 }
1202
1203 return rval;
1204}
1205
1206/*
1207 * qla2x00_issue_iocb
1208 * Issue IOCB using mailbox command
1209 *
1210 * Input:
1211 * ha = adapter state pointer.
1212 * buffer = buffer pointer.
1213 * phys_addr = physical address of buffer.
1214 * size = size of buffer.
1215 * TARGET_QUEUE_LOCK must be released.
1216 * ADAPTER_STATE_LOCK must be released.
1217 *
1218 * Returns:
1219 * qla2x00 local function return status code.
1220 *
1221 * Context:
1222 * Kernel context.
1223 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001224int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001225qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001226 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227{
1228 int rval;
1229 mbx_cmd_t mc;
1230 mbx_cmd_t *mcp = &mc;
1231
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001232 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1233 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001234
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1236 mcp->mb[1] = 0;
1237 mcp->mb[2] = MSW(phys_addr);
1238 mcp->mb[3] = LSW(phys_addr);
1239 mcp->mb[6] = MSW(MSD(phys_addr));
1240 mcp->mb[7] = LSW(MSD(phys_addr));
1241 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1242 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001243 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001245 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247 if (rval != QLA_SUCCESS) {
1248 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001249 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001251 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1252
1253 /* Mask reserved bits. */
1254 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001255 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001256 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1257 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
1259
1260 return rval;
1261}
1262
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001263int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001264qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001265 size_t size)
1266{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001267 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001268 MBX_TOV_SECONDS);
1269}
1270
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271/*
1272 * qla2x00_abort_command
1273 * Abort command aborts a specified IOCB.
1274 *
1275 * Input:
1276 * ha = adapter block pointer.
1277 * sp = SB structure pointer.
1278 *
1279 * Returns:
1280 * qla2x00 local function return status code.
1281 *
1282 * Context:
1283 * Kernel context.
1284 */
1285int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001286qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287{
1288 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001290 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 mbx_cmd_t mc;
1292 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001293 fc_port_t *fcport = sp->fcport;
1294 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001295 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001296 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001297 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001299 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1300 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301
Michael Hernandezd7459522016-12-12 14:40:07 -08001302 if (vha->flags.qpairs_available && sp->qpair)
1303 req = sp->qpair->req;
1304 else
1305 req = vha->req;
1306
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001307 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001308 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001309 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 break;
1311 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001312 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Chad Dupuis8d93f552013-01-30 03:34:37 -05001314 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 /* command not found */
1316 return QLA_FUNCTION_FAILED;
1317 }
1318
1319 mcp->mb[0] = MBC_ABORT_COMMAND;
1320 if (HAS_EXTENDED_IDS(ha))
1321 mcp->mb[1] = fcport->loop_id;
1322 else
1323 mcp->mb[1] = fcport->loop_id << 8;
1324 mcp->mb[2] = (uint16_t)handle;
1325 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001326 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1328 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001329 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001331 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001334 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001336 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1337 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
1339
1340 return rval;
1341}
1342
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001344qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001346 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 mbx_cmd_t mc;
1348 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001349 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001350 struct req_que *req;
1351 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Andrew Vasquez523ec772008-04-03 13:13:24 -07001353 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001354 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001355
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001356 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1357 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001358
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001359 req = vha->hw->req_q_map[0];
1360 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001362 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001363 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 mcp->mb[1] = fcport->loop_id;
1365 mcp->mb[10] = 0;
1366 mcp->out_mb |= MBX_10;
1367 } else {
1368 mcp->mb[1] = fcport->loop_id << 8;
1369 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001370 mcp->mb[2] = vha->hw->loop_reset_delay;
1371 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372
1373 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001374 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001376 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001378 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1379 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001380 }
1381
1382 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001383 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1384 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001385 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001386 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1387 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001389 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1390 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001391 }
1392
1393 return rval;
1394}
1395
1396int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001397qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001398{
1399 int rval, rval2;
1400 mbx_cmd_t mc;
1401 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001402 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001403 struct req_que *req;
1404 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001405
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001406 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001407
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1409 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001411 req = vha->hw->req_q_map[0];
1412 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001413 mcp->mb[0] = MBC_LUN_RESET;
1414 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001415 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001416 mcp->mb[1] = fcport->loop_id;
1417 else
1418 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001419 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001420 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001421 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001422
1423 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001424 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001425 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001426 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001427 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001428 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001429 }
1430
1431 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001432 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1433 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001434 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001435 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1436 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001437 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001438 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1439 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 }
1441
1442 return rval;
1443}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
1445/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 * qla2x00_get_adapter_id
1447 * Get adapter ID and topology.
1448 *
1449 * Input:
1450 * ha = adapter block pointer.
1451 * id = pointer for loop ID.
1452 * al_pa = pointer for AL_PA.
1453 * area = pointer for area.
1454 * domain = pointer for domain.
1455 * top = pointer for topology.
1456 * TARGET_QUEUE_LOCK must be released.
1457 * ADAPTER_STATE_LOCK must be released.
1458 *
1459 * Returns:
1460 * qla2x00 local function return status code.
1461 *
1462 * Context:
1463 * Kernel context.
1464 */
1465int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001466qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001467 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468{
1469 int rval;
1470 mbx_cmd_t mc;
1471 mbx_cmd_t *mcp = &mc;
1472
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001473 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1474 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001477 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001478 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001479 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001480 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001481 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001482 if (IS_FWI2_CAPABLE(vha->hw))
1483 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001484 if (IS_QLA27XX(vha->hw))
1485 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001486 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001488 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001489 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1490 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001491 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1492 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 /* Return data. */
1495 *id = mcp->mb[1];
1496 *al_pa = LSB(mcp->mb[2]);
1497 *area = MSB(mcp->mb[2]);
1498 *domain = LSB(mcp->mb[3]);
1499 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001500 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
1502 if (rval != QLA_SUCCESS) {
1503 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001504 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001506 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1507 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001508
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001509 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001510 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1511 vha->fcoe_fcf_idx = mcp->mb[10];
1512 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1513 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1514 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1515 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1516 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1517 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1518 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001519 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001520 if (IS_FAWWN_CAPABLE(vha->hw)) {
1521 if (mcp->mb[7] & BIT_14) {
1522 vha->port_name[0] = MSB(mcp->mb[16]);
1523 vha->port_name[1] = LSB(mcp->mb[16]);
1524 vha->port_name[2] = MSB(mcp->mb[17]);
1525 vha->port_name[3] = LSB(mcp->mb[17]);
1526 vha->port_name[4] = MSB(mcp->mb[18]);
1527 vha->port_name[5] = LSB(mcp->mb[18]);
1528 vha->port_name[6] = MSB(mcp->mb[19]);
1529 vha->port_name[7] = LSB(mcp->mb[19]);
1530 fc_host_port_name(vha->host) =
1531 wwn_to_u64(vha->port_name);
1532 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1533 "FA-WWN acquired %016llx\n",
1534 wwn_to_u64(vha->port_name));
1535 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001536 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001537
1538 if (IS_QLA27XX(vha->hw))
1539 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 }
1541
1542 return rval;
1543}
1544
1545/*
1546 * qla2x00_get_retry_cnt
1547 * Get current firmware login retry count and delay.
1548 *
1549 * Input:
1550 * ha = adapter block pointer.
1551 * retry_cnt = pointer to login retry count.
1552 * tov = pointer to login timeout value.
1553 *
1554 * Returns:
1555 * qla2x00 local function return status code.
1556 *
1557 * Context:
1558 * Kernel context.
1559 */
1560int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001561qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 uint16_t *r_a_tov)
1563{
1564 int rval;
1565 uint16_t ratov;
1566 mbx_cmd_t mc;
1567 mbx_cmd_t *mcp = &mc;
1568
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1570 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1573 mcp->out_mb = MBX_0;
1574 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001575 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001577 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 if (rval != QLA_SUCCESS) {
1580 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001581 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1582 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 } else {
1584 /* Convert returned data and check our values. */
1585 *r_a_tov = mcp->mb[3] / 2;
1586 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1587 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1588 /* Update to the larger values */
1589 *retry_cnt = (uint8_t)mcp->mb[1];
1590 *tov = ratov;
1591 }
1592
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001593 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001594 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 }
1596
1597 return rval;
1598}
1599
1600/*
1601 * qla2x00_init_firmware
1602 * Initialize adapter firmware.
1603 *
1604 * Input:
1605 * ha = adapter block pointer.
1606 * dptr = Initialization control block pointer.
1607 * size = size of initialization control block.
1608 * TARGET_QUEUE_LOCK must be released.
1609 * ADAPTER_STATE_LOCK must be released.
1610 *
1611 * Returns:
1612 * qla2x00 local function return status code.
1613 *
1614 * Context:
1615 * Kernel context.
1616 */
1617int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001618qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619{
1620 int rval;
1621 mbx_cmd_t mc;
1622 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001623 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001625 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1626 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001628 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001629 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001630 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1631
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001632 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001633 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1634 else
1635 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1636
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001637 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 mcp->mb[2] = MSW(ha->init_cb_dma);
1639 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1641 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001642 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001643 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001644 mcp->mb[1] = BIT_0;
1645 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1646 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1647 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1648 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1649 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1650 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1651 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001652 /* 1 and 2 should normally be captured. */
1653 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001654 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001655 /* mb3 is additional info about the installed SFP. */
1656 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 mcp->buf_size = size;
1658 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001659 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001660 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661
1662 if (rval != QLA_SUCCESS) {
1663 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001664 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001665 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1666 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 } else {
1668 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001669 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1670 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 }
1672
1673 return rval;
1674}
1675
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001676
1677/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678 * qla2x00_get_port_database
1679 * Issue normal/enhanced get port database mailbox command
1680 * and copy device name as necessary.
1681 *
1682 * Input:
1683 * ha = adapter state pointer.
1684 * dev = structure pointer.
1685 * opt = enhanced cmd option byte.
1686 *
1687 * Returns:
1688 * qla2x00 local function return status code.
1689 *
1690 * Context:
1691 * Kernel context.
1692 */
1693int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001694qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695{
1696 int rval;
1697 mbx_cmd_t mc;
1698 mbx_cmd_t *mcp = &mc;
1699 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001700 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001702 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001704 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1705 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001707 pd24 = NULL;
1708 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001710 ql_log(ql_log_warn, vha, 0x1050,
1711 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 return QLA_MEMORY_ALLOC_FAILED;
1713 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001714 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001716 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001717 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 mcp->mb[2] = MSW(pd_dma);
1720 mcp->mb[3] = LSW(pd_dma);
1721 mcp->mb[6] = MSW(MSD(pd_dma));
1722 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001723 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001724 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001726 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001727 mcp->mb[1] = fcport->loop_id;
1728 mcp->mb[10] = opt;
1729 mcp->out_mb |= MBX_10|MBX_1;
1730 mcp->in_mb |= MBX_1;
1731 } else if (HAS_EXTENDED_IDS(ha)) {
1732 mcp->mb[1] = fcport->loop_id;
1733 mcp->mb[10] = opt;
1734 mcp->out_mb |= MBX_10|MBX_1;
1735 } else {
1736 mcp->mb[1] = fcport->loop_id << 8 | opt;
1737 mcp->out_mb |= MBX_1;
1738 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001739 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1740 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 mcp->flags = MBX_DMA_IN;
1742 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001743 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 if (rval != QLA_SUCCESS)
1745 goto gpd_error_out;
1746
Andrew Vasqueze4289242007-07-19 15:05:56 -07001747 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001748 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001749 pd24 = (struct port_database_24xx *) pd;
1750
1751 /* Check for logged in state. */
1752 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1753 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001754 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1755 "Unable to verify login-state (%x/%x) for "
1756 "loop_id %x.\n", pd24->current_login_state,
1757 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001758 rval = QLA_FUNCTION_FAILED;
1759 goto gpd_error_out;
1760 }
1761
Arun Easi0eba25d2012-02-09 11:15:58 -08001762 if (fcport->loop_id == FC_NO_LOOP_ID ||
1763 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1764 memcmp(fcport->port_name, pd24->port_name, 8))) {
1765 /* We lost the device mid way. */
1766 rval = QLA_NOT_LOGGED_IN;
1767 goto gpd_error_out;
1768 }
1769
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001770 /* Names are little-endian. */
1771 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1772 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1773
1774 /* Get port_id of device. */
1775 fcport->d_id.b.domain = pd24->port_id[0];
1776 fcport->d_id.b.area = pd24->port_id[1];
1777 fcport->d_id.b.al_pa = pd24->port_id[2];
1778 fcport->d_id.b.rsvd_1 = 0;
1779
1780 /* If not target must be initiator or unknown type. */
1781 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1782 fcport->port_type = FCT_INITIATOR;
1783 else
1784 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001785
1786 /* Passback COS information. */
1787 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1788 FC_COS_CLASS2 : FC_COS_CLASS3;
1789
1790 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1791 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001792 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001793 uint64_t zero = 0;
1794
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001795 /* Check for logged in state. */
1796 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1797 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001798 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1799 "Unable to verify login-state (%x/%x) - "
1800 "portid=%02x%02x%02x.\n", pd->master_state,
1801 pd->slave_state, fcport->d_id.b.domain,
1802 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001803 rval = QLA_FUNCTION_FAILED;
1804 goto gpd_error_out;
1805 }
1806
Arun Easi0eba25d2012-02-09 11:15:58 -08001807 if (fcport->loop_id == FC_NO_LOOP_ID ||
1808 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1809 memcmp(fcport->port_name, pd->port_name, 8))) {
1810 /* We lost the device mid way. */
1811 rval = QLA_NOT_LOGGED_IN;
1812 goto gpd_error_out;
1813 }
1814
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001815 /* Names are little-endian. */
1816 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1817 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1818
1819 /* Get port_id of device. */
1820 fcport->d_id.b.domain = pd->port_id[0];
1821 fcport->d_id.b.area = pd->port_id[3];
1822 fcport->d_id.b.al_pa = pd->port_id[2];
1823 fcport->d_id.b.rsvd_1 = 0;
1824
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001825 /* If not target must be initiator or unknown type. */
1826 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1827 fcport->port_type = FCT_INITIATOR;
1828 else
1829 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001830
1831 /* Passback COS information. */
1832 fcport->supported_classes = (pd->options & BIT_4) ?
1833 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
1835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836gpd_error_out:
1837 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1838
1839 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001840 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1841 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1842 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001844 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1845 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846 }
1847
1848 return rval;
1849}
1850
1851/*
1852 * qla2x00_get_firmware_state
1853 * Get adapter firmware state.
1854 *
1855 * Input:
1856 * ha = adapter block pointer.
1857 * dptr = pointer for firmware state.
1858 * TARGET_QUEUE_LOCK must be released.
1859 * ADAPTER_STATE_LOCK must be released.
1860 *
1861 * Returns:
1862 * qla2x00 local function return status code.
1863 *
1864 * Context:
1865 * Kernel context.
1866 */
1867int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001868qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869{
1870 int rval;
1871 mbx_cmd_t mc;
1872 mbx_cmd_t *mcp = &mc;
1873
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001874 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1875 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
1877 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1878 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001879 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001880 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001881 else
1882 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001883 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001885 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001887 /* Return firmware states. */
1888 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001889 if (IS_FWI2_CAPABLE(vha->hw)) {
1890 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04001891 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001892 states[3] = mcp->mb[4];
1893 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001894 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
1897 if (rval != QLA_SUCCESS) {
1898 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001899 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 } else {
1901 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001902 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1903 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 }
1905
1906 return rval;
1907}
1908
1909/*
1910 * qla2x00_get_port_name
1911 * Issue get port name mailbox command.
1912 * Returned name is in big endian format.
1913 *
1914 * Input:
1915 * ha = adapter block pointer.
1916 * loop_id = loop ID of device.
1917 * name = pointer for name.
1918 * TARGET_QUEUE_LOCK must be released.
1919 * ADAPTER_STATE_LOCK must be released.
1920 *
1921 * Returns:
1922 * qla2x00 local function return status code.
1923 *
1924 * Context:
1925 * Kernel context.
1926 */
1927int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001928qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 uint8_t opt)
1930{
1931 int rval;
1932 mbx_cmd_t mc;
1933 mbx_cmd_t *mcp = &mc;
1934
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001935 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1936 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
1938 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001939 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001940 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001941 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 mcp->mb[1] = loop_id;
1943 mcp->mb[10] = opt;
1944 mcp->out_mb |= MBX_10;
1945 } else {
1946 mcp->mb[1] = loop_id << 8 | opt;
1947 }
1948
1949 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001950 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001952 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
1954 if (rval != QLA_SUCCESS) {
1955 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001956 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 } else {
1958 if (name != NULL) {
1959 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001960 name[0] = MSB(mcp->mb[2]);
1961 name[1] = LSB(mcp->mb[2]);
1962 name[2] = MSB(mcp->mb[3]);
1963 name[3] = LSB(mcp->mb[3]);
1964 name[4] = MSB(mcp->mb[6]);
1965 name[5] = LSB(mcp->mb[6]);
1966 name[6] = MSB(mcp->mb[7]);
1967 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
1969
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001970 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1971 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 }
1973
1974 return rval;
1975}
1976
1977/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001978 * qla24xx_link_initialization
1979 * Issue link initialization mailbox command.
1980 *
1981 * Input:
1982 * ha = adapter block pointer.
1983 * TARGET_QUEUE_LOCK must be released.
1984 * ADAPTER_STATE_LOCK must be released.
1985 *
1986 * Returns:
1987 * qla2x00 local function return status code.
1988 *
1989 * Context:
1990 * Kernel context.
1991 */
1992int
1993qla24xx_link_initialize(scsi_qla_host_t *vha)
1994{
1995 int rval;
1996 mbx_cmd_t mc;
1997 mbx_cmd_t *mcp = &mc;
1998
1999 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2000 "Entered %s.\n", __func__);
2001
2002 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2003 return QLA_FUNCTION_FAILED;
2004
2005 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002006 mcp->mb[1] = BIT_4;
2007 if (vha->hw->operating_mode == LOOP)
2008 mcp->mb[1] |= BIT_6;
2009 else
2010 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002011 mcp->mb[2] = 0;
2012 mcp->mb[3] = 0;
2013 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2014 mcp->in_mb = MBX_0;
2015 mcp->tov = MBX_TOV_SECONDS;
2016 mcp->flags = 0;
2017 rval = qla2x00_mailbox_command(vha, mcp);
2018
2019 if (rval != QLA_SUCCESS) {
2020 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2021 } else {
2022 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2023 "Done %s.\n", __func__);
2024 }
2025
2026 return rval;
2027}
2028
2029/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 * qla2x00_lip_reset
2031 * Issue LIP reset mailbox command.
2032 *
2033 * Input:
2034 * ha = adapter block pointer.
2035 * TARGET_QUEUE_LOCK must be released.
2036 * ADAPTER_STATE_LOCK must be released.
2037 *
2038 * Returns:
2039 * qla2x00 local function return status code.
2040 *
2041 * Context:
2042 * Kernel context.
2043 */
2044int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002045qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046{
2047 int rval;
2048 mbx_cmd_t mc;
2049 mbx_cmd_t *mcp = &mc;
2050
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002051 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2052 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002054 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002055 /* Logout across all FCFs. */
2056 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2057 mcp->mb[1] = BIT_1;
2058 mcp->mb[2] = 0;
2059 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2060 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002061 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002062 mcp->mb[1] = BIT_6;
2063 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002064 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002065 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002067 mcp->mb[0] = MBC_LIP_RESET;
2068 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002069 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002070 mcp->mb[1] = 0x00ff;
2071 mcp->mb[10] = 0;
2072 mcp->out_mb |= MBX_10;
2073 } else {
2074 mcp->mb[1] = 0xff00;
2075 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002076 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002077 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002080 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002082 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
2084 if (rval != QLA_SUCCESS) {
2085 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002086 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 } else {
2088 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002089 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2090 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 }
2092
2093 return rval;
2094}
2095
2096/*
2097 * qla2x00_send_sns
2098 * Send SNS command.
2099 *
2100 * Input:
2101 * ha = adapter block pointer.
2102 * sns = pointer for command.
2103 * cmd_size = command size.
2104 * buf_size = response/command size.
2105 * TARGET_QUEUE_LOCK must be released.
2106 * ADAPTER_STATE_LOCK must be released.
2107 *
2108 * Returns:
2109 * qla2x00 local function return status code.
2110 *
2111 * Context:
2112 * Kernel context.
2113 */
2114int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002115qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 uint16_t cmd_size, size_t buf_size)
2117{
2118 int rval;
2119 mbx_cmd_t mc;
2120 mbx_cmd_t *mcp = &mc;
2121
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002122 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2123 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002125 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002126 "Retry cnt=%d ratov=%d total tov=%d.\n",
2127 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
2129 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2130 mcp->mb[1] = cmd_size;
2131 mcp->mb[2] = MSW(sns_phys_address);
2132 mcp->mb[3] = LSW(sns_phys_address);
2133 mcp->mb[6] = MSW(MSD(sns_phys_address));
2134 mcp->mb[7] = LSW(MSD(sns_phys_address));
2135 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2136 mcp->in_mb = MBX_0|MBX_1;
2137 mcp->buf_size = buf_size;
2138 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002139 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2140 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 if (rval != QLA_SUCCESS) {
2143 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002144 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2145 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2146 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 } else {
2148 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002149 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2150 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 }
2152
2153 return rval;
2154}
2155
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002156int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002157qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002158 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2159{
2160 int rval;
2161
2162 struct logio_entry_24xx *lg;
2163 dma_addr_t lg_dma;
2164 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002165 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002166 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002167
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2169 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002170
Michael Hernandezd7459522016-12-12 14:40:07 -08002171 if (vha->vp_idx && vha->qpair)
2172 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002173 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002174 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002175
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002176 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2177 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002178 ql_log(ql_log_warn, vha, 0x1062,
2179 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002180 return QLA_MEMORY_ALLOC_FAILED;
2181 }
2182 memset(lg, 0, sizeof(struct logio_entry_24xx));
2183
2184 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2185 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002186 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002187 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002188 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002189 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002190 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002191 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002192 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002193 lg->port_id[0] = al_pa;
2194 lg->port_id[1] = area;
2195 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002196 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002197 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2198 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002199 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002200 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2201 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002202 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002203 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2204 "Failed to complete IOCB -- error status (%x).\n",
2205 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002206 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002207 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002208 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2209 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2210
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002211 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2212 "Failed to complete IOCB -- completion status (%x) "
2213 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2214 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002215
2216 switch (iop[0]) {
2217 case LSC_SCODE_PORTID_USED:
2218 mb[0] = MBS_PORT_ID_USED;
2219 mb[1] = LSW(iop[1]);
2220 break;
2221 case LSC_SCODE_NPORT_USED:
2222 mb[0] = MBS_LOOP_ID_USED;
2223 break;
2224 case LSC_SCODE_NOLINK:
2225 case LSC_SCODE_NOIOCB:
2226 case LSC_SCODE_NOXCB:
2227 case LSC_SCODE_CMD_FAILED:
2228 case LSC_SCODE_NOFABRIC:
2229 case LSC_SCODE_FW_NOT_READY:
2230 case LSC_SCODE_NOT_LOGGED_IN:
2231 case LSC_SCODE_NOPCB:
2232 case LSC_SCODE_ELS_REJECT:
2233 case LSC_SCODE_CMD_PARAM_ERR:
2234 case LSC_SCODE_NONPORT:
2235 case LSC_SCODE_LOGGED_IN:
2236 case LSC_SCODE_NOFLOGI_ACC:
2237 default:
2238 mb[0] = MBS_COMMAND_ERROR;
2239 break;
2240 }
2241 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2243 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002244
2245 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2246
2247 mb[0] = MBS_COMMAND_COMPLETE;
2248 mb[1] = 0;
2249 if (iop[0] & BIT_4) {
2250 if (iop[0] & BIT_8)
2251 mb[1] |= BIT_1;
2252 } else
2253 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002254
2255 /* Passback COS information. */
2256 mb[10] = 0;
2257 if (lg->io_parameter[7] || lg->io_parameter[8])
2258 mb[10] |= BIT_0; /* Class 2. */
2259 if (lg->io_parameter[9] || lg->io_parameter[10])
2260 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002261 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002262 mb[10] |= BIT_7; /* Confirmed Completion
2263 * Allowed
2264 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002265 }
2266
2267 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2268
2269 return rval;
2270}
2271
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272/*
2273 * qla2x00_login_fabric
2274 * Issue login fabric port mailbox command.
2275 *
2276 * Input:
2277 * ha = adapter block pointer.
2278 * loop_id = device loop ID.
2279 * domain = device domain.
2280 * area = device area.
2281 * al_pa = device AL_PA.
2282 * status = pointer for return status.
2283 * opt = command options.
2284 * TARGET_QUEUE_LOCK must be released.
2285 * ADAPTER_STATE_LOCK must be released.
2286 *
2287 * Returns:
2288 * qla2x00 local function return status code.
2289 *
2290 * Context:
2291 * Kernel context.
2292 */
2293int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002294qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2296{
2297 int rval;
2298 mbx_cmd_t mc;
2299 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002300 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2303 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
2305 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2306 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2307 if (HAS_EXTENDED_IDS(ha)) {
2308 mcp->mb[1] = loop_id;
2309 mcp->mb[10] = opt;
2310 mcp->out_mb |= MBX_10;
2311 } else {
2312 mcp->mb[1] = (loop_id << 8) | opt;
2313 }
2314 mcp->mb[2] = domain;
2315 mcp->mb[3] = area << 8 | al_pa;
2316
2317 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2318 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2319 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002320 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321
2322 /* Return mailbox statuses. */
2323 if (mb != NULL) {
2324 mb[0] = mcp->mb[0];
2325 mb[1] = mcp->mb[1];
2326 mb[2] = mcp->mb[2];
2327 mb[6] = mcp->mb[6];
2328 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002329 /* COS retrieved from Get-Port-Database mailbox command. */
2330 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332
2333 if (rval != QLA_SUCCESS) {
2334 /* RLU tmp code: need to change main mailbox_command function to
2335 * return ok even when the mailbox completion value is not
2336 * SUCCESS. The caller needs to be responsible to interpret
2337 * the return values of this mailbox command if we're not
2338 * to change too much of the existing code.
2339 */
2340 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2341 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2342 mcp->mb[0] == 0x4006)
2343 rval = QLA_SUCCESS;
2344
2345 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002346 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2347 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2348 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 } else {
2350 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2352 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 }
2354
2355 return rval;
2356}
2357
2358/*
2359 * qla2x00_login_local_device
2360 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002361 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 * Input:
2363 * ha = adapter block pointer.
2364 * loop_id = device loop ID.
2365 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002366 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 * Returns:
2368 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002369 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 * Context:
2371 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002372 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 */
2374int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002375qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 uint16_t *mb_ret, uint8_t opt)
2377{
2378 int rval;
2379 mbx_cmd_t mc;
2380 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002381 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002383 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2384 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002385
Andrew Vasqueze4289242007-07-19 15:05:56 -07002386 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002387 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002388 fcport->d_id.b.domain, fcport->d_id.b.area,
2389 fcport->d_id.b.al_pa, mb_ret, opt);
2390
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2392 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002393 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002395 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 mcp->mb[2] = opt;
2397 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2398 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2399 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2400 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002401 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402
2403 /* Return mailbox statuses. */
2404 if (mb_ret != NULL) {
2405 mb_ret[0] = mcp->mb[0];
2406 mb_ret[1] = mcp->mb[1];
2407 mb_ret[6] = mcp->mb[6];
2408 mb_ret[7] = mcp->mb[7];
2409 }
2410
2411 if (rval != QLA_SUCCESS) {
2412 /* AV tmp code: need to change main mailbox_command function to
2413 * return ok even when the mailbox completion value is not
2414 * SUCCESS. The caller needs to be responsible to interpret
2415 * the return values of this mailbox command if we're not
2416 * to change too much of the existing code.
2417 */
2418 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2419 rval = QLA_SUCCESS;
2420
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002421 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2422 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2423 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 } else {
2425 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002426 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2427 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
2429
2430 return (rval);
2431}
2432
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002433int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002434qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002435 uint8_t area, uint8_t al_pa)
2436{
2437 int rval;
2438 struct logio_entry_24xx *lg;
2439 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002440 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002441 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002442
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002443 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2444 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002445
2446 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2447 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002448 ql_log(ql_log_warn, vha, 0x106e,
2449 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002450 return QLA_MEMORY_ALLOC_FAILED;
2451 }
2452 memset(lg, 0, sizeof(struct logio_entry_24xx));
2453
Michael Hernandezd7459522016-12-12 14:40:07 -08002454 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002455 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2456 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002457 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002458 lg->nport_handle = cpu_to_le16(loop_id);
2459 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002460 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002461 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002462 lg->port_id[0] = al_pa;
2463 lg->port_id[1] = area;
2464 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002465 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002466 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2467 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002468 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002469 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2470 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002471 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002472 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2473 "Failed to complete IOCB -- error status (%x).\n",
2474 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002475 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002476 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002477 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2478 "Failed to complete IOCB -- completion status (%x) "
2479 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002480 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002481 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002482 } else {
2483 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002484 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2485 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002486 }
2487
2488 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2489
2490 return rval;
2491}
2492
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493/*
2494 * qla2x00_fabric_logout
2495 * Issue logout fabric port mailbox command.
2496 *
2497 * Input:
2498 * ha = adapter block pointer.
2499 * loop_id = device loop ID.
2500 * TARGET_QUEUE_LOCK must be released.
2501 * ADAPTER_STATE_LOCK must be released.
2502 *
2503 * Returns:
2504 * qla2x00 local function return status code.
2505 *
2506 * Context:
2507 * Kernel context.
2508 */
2509int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002510qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002511 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512{
2513 int rval;
2514 mbx_cmd_t mc;
2515 mbx_cmd_t *mcp = &mc;
2516
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002517 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2518 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519
2520 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2521 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002522 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 mcp->mb[1] = loop_id;
2524 mcp->mb[10] = 0;
2525 mcp->out_mb |= MBX_10;
2526 } else {
2527 mcp->mb[1] = loop_id << 8;
2528 }
2529
2530 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002531 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002533 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
2535 if (rval != QLA_SUCCESS) {
2536 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002537 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2538 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 } else {
2540 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002541 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2542 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 }
2544
2545 return rval;
2546}
2547
2548/*
2549 * qla2x00_full_login_lip
2550 * Issue full login LIP mailbox command.
2551 *
2552 * Input:
2553 * ha = adapter block pointer.
2554 * TARGET_QUEUE_LOCK must be released.
2555 * ADAPTER_STATE_LOCK must be released.
2556 *
2557 * Returns:
2558 * qla2x00 local function return status code.
2559 *
2560 * Context:
2561 * Kernel context.
2562 */
2563int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002564qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565{
2566 int rval;
2567 mbx_cmd_t mc;
2568 mbx_cmd_t *mcp = &mc;
2569
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002570 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2571 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572
2573 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002574 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002575 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 mcp->mb[3] = 0;
2577 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2578 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002579 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002581 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
2583 if (rval != QLA_SUCCESS) {
2584 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002585 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 } else {
2587 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2589 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 }
2591
2592 return rval;
2593}
2594
2595/*
2596 * qla2x00_get_id_list
2597 *
2598 * Input:
2599 * ha = adapter block pointer.
2600 *
2601 * Returns:
2602 * qla2x00 local function return status code.
2603 *
2604 * Context:
2605 * Kernel context.
2606 */
2607int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002608qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 uint16_t *entries)
2610{
2611 int rval;
2612 mbx_cmd_t mc;
2613 mbx_cmd_t *mcp = &mc;
2614
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002615 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2616 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
2618 if (id_list == NULL)
2619 return QLA_FUNCTION_FAILED;
2620
2621 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002622 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002623 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002624 mcp->mb[2] = MSW(id_list_dma);
2625 mcp->mb[3] = LSW(id_list_dma);
2626 mcp->mb[6] = MSW(MSD(id_list_dma));
2627 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002628 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002629 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002630 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002631 } else {
2632 mcp->mb[1] = MSW(id_list_dma);
2633 mcp->mb[2] = LSW(id_list_dma);
2634 mcp->mb[3] = MSW(MSD(id_list_dma));
2635 mcp->mb[6] = LSW(MSD(id_list_dma));
2636 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002639 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002641 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
2643 if (rval != QLA_SUCCESS) {
2644 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002645 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 } else {
2647 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002648 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2649 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 }
2651
2652 return rval;
2653}
2654
2655/*
2656 * qla2x00_get_resource_cnts
2657 * Get current firmware resource counts.
2658 *
2659 * Input:
2660 * ha = adapter block pointer.
2661 *
2662 * Returns:
2663 * qla2x00 local function return status code.
2664 *
2665 * Context:
2666 * Kernel context.
2667 */
2668int
Quinn Tran03e8c682015-12-17 14:56:59 -05002669qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
Quinn Tran03e8c682015-12-17 14:56:59 -05002671 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 int rval;
2673 mbx_cmd_t mc;
2674 mbx_cmd_t *mcp = &mc;
2675
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2677 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678
2679 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2680 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002681 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 -05002682 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002683 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002684 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002686 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687
2688 if (rval != QLA_SUCCESS) {
2689 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002690 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2691 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002693 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002694 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2695 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2696 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2697 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
Quinn Tran03e8c682015-12-17 14:56:59 -05002699 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2700 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2701 ha->cur_fw_xcb_count = mcp->mb[3];
2702 ha->orig_fw_xcb_count = mcp->mb[6];
2703 ha->cur_fw_iocb_count = mcp->mb[7];
2704 ha->orig_fw_iocb_count = mcp->mb[10];
2705 if (ha->flags.npiv_supported)
2706 ha->max_npiv_vports = mcp->mb[11];
2707 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2708 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 }
2710
2711 return (rval);
2712}
2713
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714/*
2715 * qla2x00_get_fcal_position_map
2716 * Get FCAL (LILP) position map using mailbox command
2717 *
2718 * Input:
2719 * ha = adapter state pointer.
2720 * pos_map = buffer pointer (can be NULL).
2721 *
2722 * Returns:
2723 * qla2x00 local function return status code.
2724 *
2725 * Context:
2726 * Kernel context.
2727 */
2728int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002729qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730{
2731 int rval;
2732 mbx_cmd_t mc;
2733 mbx_cmd_t *mcp = &mc;
2734 char *pmap;
2735 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002736 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002738 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2739 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002740
Andrew Vasquez4b892582008-09-11 21:22:48 -07002741 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002743 ql_log(ql_log_warn, vha, 0x1080,
2744 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return QLA_MEMORY_ALLOC_FAILED;
2746 }
2747 memset(pmap, 0, FCAL_MAP_SIZE);
2748
2749 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2750 mcp->mb[2] = MSW(pmap_dma);
2751 mcp->mb[3] = LSW(pmap_dma);
2752 mcp->mb[6] = MSW(MSD(pmap_dma));
2753 mcp->mb[7] = LSW(MSD(pmap_dma));
2754 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2755 mcp->in_mb = MBX_1|MBX_0;
2756 mcp->buf_size = FCAL_MAP_SIZE;
2757 mcp->flags = MBX_DMA_IN;
2758 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002759 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
2761 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002762 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002763 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2764 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2765 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2766 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767
2768 if (pos_map)
2769 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2770 }
2771 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2772
2773 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002774 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2777 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 }
2779
2780 return rval;
2781}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002782
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002783/*
2784 * qla2x00_get_link_status
2785 *
2786 * Input:
2787 * ha = adapter block pointer.
2788 * loop_id = device loop ID.
2789 * ret_buf = pointer to link status return buffer.
2790 *
2791 * Returns:
2792 * 0 = success.
2793 * BIT_0 = mem alloc error.
2794 * BIT_1 = mailbox error.
2795 */
2796int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002797qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002798 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002799{
2800 int rval;
2801 mbx_cmd_t mc;
2802 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002803 uint32_t *iter = (void *)stats;
2804 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002805 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002806
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002807 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2808 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002809
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002810 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002811 mcp->mb[2] = MSW(LSD(stats_dma));
2812 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002813 mcp->mb[6] = MSW(MSD(stats_dma));
2814 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002815 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2816 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002817 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002818 mcp->mb[1] = loop_id;
2819 mcp->mb[4] = 0;
2820 mcp->mb[10] = 0;
2821 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2822 mcp->in_mb |= MBX_1;
2823 } else if (HAS_EXTENDED_IDS(ha)) {
2824 mcp->mb[1] = loop_id;
2825 mcp->mb[10] = 0;
2826 mcp->out_mb |= MBX_10|MBX_1;
2827 } else {
2828 mcp->mb[1] = loop_id << 8;
2829 mcp->out_mb |= MBX_1;
2830 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002831 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002832 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002833 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002834
2835 if (rval == QLA_SUCCESS) {
2836 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002837 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2838 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002839 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002840 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002841 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002842 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2843 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002844 for ( ; dwords--; iter++)
2845 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002846 }
2847 } else {
2848 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002849 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002850 }
2851
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002852 return rval;
2853}
2854
2855int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002856qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07002857 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002858{
2859 int rval;
2860 mbx_cmd_t mc;
2861 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002862 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002863
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002864 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2865 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002866
Quinn Tran15f30a52017-03-15 09:48:52 -07002867 memset(&mc, 0, sizeof(mc));
2868 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
2869 mc.mb[2] = MSW(stats_dma);
2870 mc.mb[3] = LSW(stats_dma);
2871 mc.mb[6] = MSW(MSD(stats_dma));
2872 mc.mb[7] = LSW(MSD(stats_dma));
2873 mc.mb[8] = sizeof(struct link_statistics) / 4;
2874 mc.mb[9] = cpu_to_le16(vha->vp_idx);
2875 mc.mb[10] = cpu_to_le16(options);
2876
2877 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002878
2879 if (rval == QLA_SUCCESS) {
2880 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002881 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2882 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002883 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002884 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2886 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002887 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002888 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002889 iter = &stats->link_fail_cnt;
2890 for ( ; dwords--; iter++)
2891 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002892 }
2893 } else {
2894 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002895 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002896 }
2897
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002898 return rval;
2899}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002900
2901int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002902qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002903{
2904 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002905 unsigned long flags = 0;
2906
2907 struct abort_entry_24xx *abt;
2908 dma_addr_t abt_dma;
2909 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002910 fc_port_t *fcport = sp->fcport;
2911 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002912 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002913 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002914
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002915 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2916 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002917
Michael Hernandezd7459522016-12-12 14:40:07 -08002918 if (vha->flags.qpairs_available && sp->qpair)
2919 req = sp->qpair->req;
2920
Armen Baloyan4440e462014-02-26 04:15:18 -05002921 if (ql2xasynctmfenable)
2922 return qla24xx_async_abort_command(sp);
2923
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002924 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002925 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002926 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002927 break;
2928 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002929 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002930 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002931 /* Command not found. */
2932 return QLA_FUNCTION_FAILED;
2933 }
2934
2935 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2936 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002937 ql_log(ql_log_warn, vha, 0x108d,
2938 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002939 return QLA_MEMORY_ALLOC_FAILED;
2940 }
2941 memset(abt, 0, sizeof(struct abort_entry_24xx));
2942
2943 abt->entry_type = ABORT_IOCB_TYPE;
2944 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002945 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002946 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002947 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002948 abt->port_id[0] = fcport->d_id.b.al_pa;
2949 abt->port_id[1] = fcport->d_id.b.area;
2950 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002951 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002952
2953 abt->req_que_no = cpu_to_le16(req->id);
2954
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002955 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002956 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002957 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2958 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002959 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002960 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2961 "Failed to complete IOCB -- error status (%x).\n",
2962 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002963 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002964 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002965 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2966 "Failed to complete IOCB -- completion status (%x).\n",
2967 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04002968 if (abt->nport_handle == CS_IOCB_ERROR)
2969 rval = QLA_FUNCTION_PARAMETER_ERROR;
2970 else
2971 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002972 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002973 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2974 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002975 }
2976
2977 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2978
2979 return rval;
2980}
2981
2982struct tsk_mgmt_cmd {
2983 union {
2984 struct tsk_mgmt_entry tsk;
2985 struct sts_entry_24xx sts;
2986 } p;
2987};
2988
Andrew Vasquez523ec772008-04-03 13:13:24 -07002989static int
2990__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002991 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002992{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002993 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002994 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002995 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002996 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002997 scsi_qla_host_t *vha;
2998 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002999 struct req_que *req;
3000 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003001 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003002
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003003 vha = fcport->vha;
3004 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003005 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003006
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3008 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003009
Michael Hernandezd7459522016-12-12 14:40:07 -08003010 if (vha->vp_idx && vha->qpair) {
3011 /* NPIV port */
3012 qpair = vha->qpair;
3013 rsp = qpair->rsp;
3014 req = qpair->req;
3015 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003016 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003017 }
3018
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003019 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003020 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003021 ql_log(ql_log_warn, vha, 0x1093,
3022 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003023 return QLA_MEMORY_ALLOC_FAILED;
3024 }
3025 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
3026
3027 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3028 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003029 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003030 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003031 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003032 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003033 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3034 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3035 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003036 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003037 if (type == TCF_LUN_RESET) {
3038 int_to_scsilun(l, &tsk->p.tsk.lun);
3039 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3040 sizeof(tsk->p.tsk.lun));
3041 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003042
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003043 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003044 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003045 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003046 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3047 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003048 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003049 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3050 "Failed to complete IOCB -- error status (%x).\n",
3051 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003052 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003053 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003054 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3055 "Failed to complete IOCB -- completion status (%x).\n",
3056 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003057 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003058 } else if (le16_to_cpu(sts->scsi_status) &
3059 SS_RESPONSE_INFO_LEN_VALID) {
3060 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003061 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003062 "Ignoring inconsistent data length -- not enough "
3063 "response info (%d).\n",
3064 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003065 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003066 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3067 "Failed to complete IOCB -- response (%x).\n",
3068 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003069 rval = QLA_FUNCTION_FAILED;
3070 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003071 }
3072
3073 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003074 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003075 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3076 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003077 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3078 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003079 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003080 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3081 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003082 }
3083
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003084 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003085
3086 return rval;
3087}
3088
Andrew Vasquez523ec772008-04-03 13:13:24 -07003089int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003090qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003091{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003092 struct qla_hw_data *ha = fcport->vha->hw;
3093
3094 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3095 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3096
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003097 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003098}
3099
3100int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003101qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003102{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003103 struct qla_hw_data *ha = fcport->vha->hw;
3104
3105 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3106 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3107
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003108 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003109}
3110
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003111int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003112qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003113{
3114 int rval;
3115 mbx_cmd_t mc;
3116 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003117 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003118
Andrew Vasquez68af0812008-05-12 22:21:13 -07003119 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003120 return QLA_FUNCTION_FAILED;
3121
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003122 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3123 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003124
3125 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3126 mcp->out_mb = MBX_0;
3127 mcp->in_mb = MBX_0;
3128 mcp->tov = 5;
3129 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003130 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003131
3132 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003133 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003134 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003135 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3136 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003137 }
3138
3139 return rval;
3140}
3141
Joe Carnucciodb64e932013-10-30 03:38:18 -04003142int
3143qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3144{
3145 int rval;
3146 mbx_cmd_t mc;
3147 mbx_cmd_t *mcp = &mc;
3148
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003149 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3150 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003151 return QLA_FUNCTION_FAILED;
3152
3153 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3154 "Entered %s.\n", __func__);
3155
3156 mcp->mb[0] = MBC_WRITE_SERDES;
3157 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003158 if (IS_QLA2031(vha->hw))
3159 mcp->mb[2] = data & 0xff;
3160 else
3161 mcp->mb[2] = data;
3162
Joe Carnucciodb64e932013-10-30 03:38:18 -04003163 mcp->mb[3] = 0;
3164 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3165 mcp->in_mb = MBX_0;
3166 mcp->tov = MBX_TOV_SECONDS;
3167 mcp->flags = 0;
3168 rval = qla2x00_mailbox_command(vha, mcp);
3169
3170 if (rval != QLA_SUCCESS) {
3171 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3172 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3173 } else {
3174 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3175 "Done %s.\n", __func__);
3176 }
3177
3178 return rval;
3179}
3180
3181int
3182qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3183{
3184 int rval;
3185 mbx_cmd_t mc;
3186 mbx_cmd_t *mcp = &mc;
3187
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003188 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3189 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003190 return QLA_FUNCTION_FAILED;
3191
3192 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3193 "Entered %s.\n", __func__);
3194
3195 mcp->mb[0] = MBC_READ_SERDES;
3196 mcp->mb[1] = addr;
3197 mcp->mb[3] = 0;
3198 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3199 mcp->in_mb = MBX_1|MBX_0;
3200 mcp->tov = MBX_TOV_SECONDS;
3201 mcp->flags = 0;
3202 rval = qla2x00_mailbox_command(vha, mcp);
3203
Andrew Vasquez064135e2015-04-09 15:00:02 -04003204 if (IS_QLA2031(vha->hw))
3205 *data = mcp->mb[1] & 0xff;
3206 else
3207 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003208
3209 if (rval != QLA_SUCCESS) {
3210 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3211 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3212 } else {
3213 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3214 "Done %s.\n", __func__);
3215 }
3216
3217 return rval;
3218}
3219
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003220int
3221qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3222{
3223 int rval;
3224 mbx_cmd_t mc;
3225 mbx_cmd_t *mcp = &mc;
3226
3227 if (!IS_QLA8044(vha->hw))
3228 return QLA_FUNCTION_FAILED;
3229
Quinn Tran83548fe2017-06-02 09:12:01 -07003230 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003231 "Entered %s.\n", __func__);
3232
3233 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3234 mcp->mb[1] = HCS_WRITE_SERDES;
3235 mcp->mb[3] = LSW(addr);
3236 mcp->mb[4] = MSW(addr);
3237 mcp->mb[5] = LSW(data);
3238 mcp->mb[6] = MSW(data);
3239 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3240 mcp->in_mb = MBX_0;
3241 mcp->tov = MBX_TOV_SECONDS;
3242 mcp->flags = 0;
3243 rval = qla2x00_mailbox_command(vha, mcp);
3244
3245 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003246 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003247 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3248 } else {
3249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3250 "Done %s.\n", __func__);
3251 }
3252
3253 return rval;
3254}
3255
3256int
3257qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3258{
3259 int rval;
3260 mbx_cmd_t mc;
3261 mbx_cmd_t *mcp = &mc;
3262
3263 if (!IS_QLA8044(vha->hw))
3264 return QLA_FUNCTION_FAILED;
3265
3266 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3267 "Entered %s.\n", __func__);
3268
3269 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3270 mcp->mb[1] = HCS_READ_SERDES;
3271 mcp->mb[3] = LSW(addr);
3272 mcp->mb[4] = MSW(addr);
3273 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3274 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3275 mcp->tov = MBX_TOV_SECONDS;
3276 mcp->flags = 0;
3277 rval = qla2x00_mailbox_command(vha, mcp);
3278
3279 *data = mcp->mb[2] << 16 | mcp->mb[1];
3280
3281 if (rval != QLA_SUCCESS) {
3282 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3283 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3284 } else {
3285 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3286 "Done %s.\n", __func__);
3287 }
3288
3289 return rval;
3290}
3291
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003292/**
3293 * qla2x00_set_serdes_params() -
3294 * @ha: HA context
3295 *
3296 * Returns
3297 */
3298int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003299qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003300 uint16_t sw_em_2g, uint16_t sw_em_4g)
3301{
3302 int rval;
3303 mbx_cmd_t mc;
3304 mbx_cmd_t *mcp = &mc;
3305
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003306 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3307 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003308
3309 mcp->mb[0] = MBC_SERDES_PARAMS;
3310 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003311 mcp->mb[2] = sw_em_1g | BIT_15;
3312 mcp->mb[3] = sw_em_2g | BIT_15;
3313 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003314 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3315 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003316 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003317 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003318 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003319
3320 if (rval != QLA_SUCCESS) {
3321 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003322 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3323 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003324 } else {
3325 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003326 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3327 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003328 }
3329
3330 return rval;
3331}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003332
3333int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003334qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003335{
3336 int rval;
3337 mbx_cmd_t mc;
3338 mbx_cmd_t *mcp = &mc;
3339
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003340 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003341 return QLA_FUNCTION_FAILED;
3342
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003343 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3344 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003345
3346 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003347 mcp->mb[1] = 0;
3348 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003349 mcp->in_mb = MBX_0;
3350 mcp->tov = 5;
3351 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003352 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003353
3354 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003355 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003356 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3357 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003358 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003359 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3360 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003361 }
3362
3363 return rval;
3364}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003365
3366int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003367qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003368 uint16_t buffers)
3369{
3370 int rval;
3371 mbx_cmd_t mc;
3372 mbx_cmd_t *mcp = &mc;
3373
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003374 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3375 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003376
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003377 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003378 return QLA_FUNCTION_FAILED;
3379
Andrew Vasquez85880802009-12-15 21:29:46 -08003380 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3381 return QLA_FUNCTION_FAILED;
3382
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003383 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003384 mcp->mb[1] = TC_EFT_ENABLE;
3385 mcp->mb[2] = LSW(eft_dma);
3386 mcp->mb[3] = MSW(eft_dma);
3387 mcp->mb[4] = LSW(MSD(eft_dma));
3388 mcp->mb[5] = MSW(MSD(eft_dma));
3389 mcp->mb[6] = buffers;
3390 mcp->mb[7] = TC_AEN_DISABLE;
3391 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 -07003392 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003393 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003394 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003395 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003396 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003397 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3398 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3399 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003400 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003401 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3402 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003403 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003404
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003405 return rval;
3406}
3407
3408int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003409qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003410{
3411 int rval;
3412 mbx_cmd_t mc;
3413 mbx_cmd_t *mcp = &mc;
3414
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003415 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3416 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003417
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003418 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003419 return QLA_FUNCTION_FAILED;
3420
Andrew Vasquez85880802009-12-15 21:29:46 -08003421 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3422 return QLA_FUNCTION_FAILED;
3423
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003424 mcp->mb[0] = MBC_TRACE_CONTROL;
3425 mcp->mb[1] = TC_EFT_DISABLE;
3426 mcp->out_mb = MBX_1|MBX_0;
3427 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003428 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003429 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003430 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003431 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003432 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3433 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3434 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003435 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003436 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3437 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003438 }
3439
3440 return rval;
3441}
3442
Andrew Vasquez88729e52006-06-23 16:10:50 -07003443int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003444qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003445 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3446{
3447 int rval;
3448 mbx_cmd_t mc;
3449 mbx_cmd_t *mcp = &mc;
3450
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003451 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3452 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003453
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003454 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003455 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003456 return QLA_FUNCTION_FAILED;
3457
Andrew Vasquez85880802009-12-15 21:29:46 -08003458 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3459 return QLA_FUNCTION_FAILED;
3460
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003461 mcp->mb[0] = MBC_TRACE_CONTROL;
3462 mcp->mb[1] = TC_FCE_ENABLE;
3463 mcp->mb[2] = LSW(fce_dma);
3464 mcp->mb[3] = MSW(fce_dma);
3465 mcp->mb[4] = LSW(MSD(fce_dma));
3466 mcp->mb[5] = MSW(MSD(fce_dma));
3467 mcp->mb[6] = buffers;
3468 mcp->mb[7] = TC_AEN_DISABLE;
3469 mcp->mb[8] = 0;
3470 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3471 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3472 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3473 MBX_1|MBX_0;
3474 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003475 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003476 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003477 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003478 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003479 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3480 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3481 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003482 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003483 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3484 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003485
3486 if (mb)
3487 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3488 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003489 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003490 }
3491
3492 return rval;
3493}
3494
3495int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003496qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003497{
3498 int rval;
3499 mbx_cmd_t mc;
3500 mbx_cmd_t *mcp = &mc;
3501
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003502 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3503 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003504
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003505 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003506 return QLA_FUNCTION_FAILED;
3507
Andrew Vasquez85880802009-12-15 21:29:46 -08003508 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3509 return QLA_FUNCTION_FAILED;
3510
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003511 mcp->mb[0] = MBC_TRACE_CONTROL;
3512 mcp->mb[1] = TC_FCE_DISABLE;
3513 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3514 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3515 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3516 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003517 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003518 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003519 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003520 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003521 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3522 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3523 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003524 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003525 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3526 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003527
3528 if (wr)
3529 *wr = (uint64_t) mcp->mb[5] << 48 |
3530 (uint64_t) mcp->mb[4] << 32 |
3531 (uint64_t) mcp->mb[3] << 16 |
3532 (uint64_t) mcp->mb[2];
3533 if (rd)
3534 *rd = (uint64_t) mcp->mb[9] << 48 |
3535 (uint64_t) mcp->mb[8] << 32 |
3536 (uint64_t) mcp->mb[7] << 16 |
3537 (uint64_t) mcp->mb[6];
3538 }
3539
3540 return rval;
3541}
3542
3543int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003544qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3545 uint16_t *port_speed, uint16_t *mb)
3546{
3547 int rval;
3548 mbx_cmd_t mc;
3549 mbx_cmd_t *mcp = &mc;
3550
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003551 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3552 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003553
Giridhar Malavali6e980162010-03-19 17:03:58 -07003554 if (!IS_IIDMA_CAPABLE(vha->hw))
3555 return QLA_FUNCTION_FAILED;
3556
Giridhar Malavali6e980162010-03-19 17:03:58 -07003557 mcp->mb[0] = MBC_PORT_PARAMS;
3558 mcp->mb[1] = loop_id;
3559 mcp->mb[2] = mcp->mb[3] = 0;
3560 mcp->mb[9] = vha->vp_idx;
3561 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3562 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3563 mcp->tov = MBX_TOV_SECONDS;
3564 mcp->flags = 0;
3565 rval = qla2x00_mailbox_command(vha, mcp);
3566
3567 /* Return mailbox statuses. */
3568 if (mb != NULL) {
3569 mb[0] = mcp->mb[0];
3570 mb[1] = mcp->mb[1];
3571 mb[3] = mcp->mb[3];
3572 }
3573
3574 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003575 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003576 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003577 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3578 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003579 if (port_speed)
3580 *port_speed = mcp->mb[3];
3581 }
3582
3583 return rval;
3584}
3585
3586int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003587qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003588 uint16_t port_speed, uint16_t *mb)
3589{
3590 int rval;
3591 mbx_cmd_t mc;
3592 mbx_cmd_t *mcp = &mc;
3593
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003594 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3595 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003596
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003597 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003598 return QLA_FUNCTION_FAILED;
3599
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003600 mcp->mb[0] = MBC_PORT_PARAMS;
3601 mcp->mb[1] = loop_id;
3602 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003603 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003604 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3605 else
3606 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3607 mcp->mb[9] = vha->vp_idx;
3608 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3609 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003610 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003611 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003612 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003613
3614 /* Return mailbox statuses. */
3615 if (mb != NULL) {
3616 mb[0] = mcp->mb[0];
3617 mb[1] = mcp->mb[1];
3618 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003619 }
3620
3621 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003622 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3623 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003624 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003625 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3626 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003627 }
3628
3629 return rval;
3630}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003631
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003632void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003633qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003634 struct vp_rpt_id_entry_24xx *rptid_entry)
3635{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003636 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003637 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003638 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003639 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003640 port_id_t id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003641
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003642 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3643 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003644
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003645 if (rptid_entry->entry_status != 0)
3646 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003647
Quinn Tran482c9dc2017-03-15 09:48:54 -07003648 id.b.domain = rptid_entry->port_id[2];
3649 id.b.area = rptid_entry->port_id[1];
3650 id.b.al_pa = rptid_entry->port_id[0];
3651 id.b.rsvd_1 = 0;
3652
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003653 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003654 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003655 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003656 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003657 "VPs acquired %d.\n", rptid_entry->vp_setup,
3658 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003659 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003660 "Primary port id %02x%02x%02x.\n",
3661 rptid_entry->port_id[2], rptid_entry->port_id[1],
3662 rptid_entry->port_id[0]);
Quinn Tran41dc5292017-01-19 22:28:03 -08003663
Quinn Tran482c9dc2017-03-15 09:48:54 -07003664 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003665
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003666 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003667 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003668 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003669 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003670 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3671 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003672 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003673 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003674
Sawan Chandak969a6192016-01-27 12:03:32 -05003675 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003676 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003677
Quinn Tran41dc5292017-01-19 22:28:03 -08003678 if (rptid_entry->vp_idx == 0) {
3679 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3680 /* FA-WWN is only for physical port */
3681 if (qla_ini_mode_enabled(vha) &&
3682 ha->flags.fawwpn_enabled &&
3683 (rptid_entry->u.f1.flags &
3684 VP_FLAGS_NAME_VALID)) {
3685 memcpy(vha->port_name,
3686 rptid_entry->u.f1.port_name,
3687 WWN_SIZE);
3688 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003689
Quinn Tran482c9dc2017-03-15 09:48:54 -07003690 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003691 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003692
Quinn Tran41dc5292017-01-19 22:28:03 -08003693 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3694 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3695 } else {
3696 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3697 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3698 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3699 "Could not acquire ID for VP[%d].\n",
3700 rptid_entry->vp_idx);
3701 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003702 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003703
3704 found = 0;
3705 spin_lock_irqsave(&ha->vport_slock, flags);
3706 list_for_each_entry(vp, &ha->vp_list, list) {
3707 if (rptid_entry->vp_idx == vp->vp_idx) {
3708 found = 1;
3709 break;
3710 }
3711 }
3712 spin_unlock_irqrestore(&ha->vport_slock, flags);
3713
3714 if (!found)
3715 return;
3716
Quinn Tran482c9dc2017-03-15 09:48:54 -07003717 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003718
3719 /*
3720 * Cannot configure here as we are still sitting on the
3721 * response queue. Handle it in dpc context.
3722 */
3723 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3724 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3725 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003726 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003727 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003728 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003729 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003730 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08003731 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3732 rptid_entry->port_id[2], rptid_entry->port_id[1],
3733 rptid_entry->port_id[0]);
3734
Quinn Tran83548fe2017-06-02 09:12:01 -07003735 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08003736 "N2N: Remote WWPN %8phC.\n",
3737 rptid_entry->u.f2.port_name);
3738
3739 /* N2N. direct connect */
3740 vha->d_id.b.domain = rptid_entry->port_id[2];
3741 vha->d_id.b.area = rptid_entry->port_id[1];
3742 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3743
3744 spin_lock_irqsave(&ha->vport_slock, flags);
3745 qlt_update_vp_map(vha, SET_AL_PA);
3746 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003747 }
3748}
3749
3750/*
3751 * qla24xx_modify_vp_config
3752 * Change VP configuration for vha
3753 *
3754 * Input:
3755 * vha = adapter block pointer.
3756 *
3757 * Returns:
3758 * qla2xxx local function return status code.
3759 *
3760 * Context:
3761 * Kernel context.
3762 */
3763int
3764qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3765{
3766 int rval;
3767 struct vp_config_entry_24xx *vpmod;
3768 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003769 struct qla_hw_data *ha = vha->hw;
3770 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003771
3772 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003773
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003774 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3775 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003776
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003777 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003778 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003779 ql_log(ql_log_warn, vha, 0x10bc,
3780 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003781 return QLA_MEMORY_ALLOC_FAILED;
3782 }
3783
3784 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3785 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3786 vpmod->entry_count = 1;
3787 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3788 vpmod->vp_count = 1;
3789 vpmod->vp_index1 = vha->vp_idx;
3790 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003791
3792 qlt_modify_vp_config(vha, vpmod);
3793
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003794 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3795 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3796 vpmod->entry_count = 1;
3797
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003798 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003799 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003800 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3801 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003802 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003803 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3804 "Failed to complete IOCB -- error status (%x).\n",
3805 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003806 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003807 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003808 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3809 "Failed to complete IOCB -- completion status (%x).\n",
3810 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003811 rval = QLA_FUNCTION_FAILED;
3812 } else {
3813 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003814 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3815 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003816 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3817 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003818 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003819
3820 return rval;
3821}
3822
3823/*
3824 * qla24xx_control_vp
3825 * Enable a virtual port for given host
3826 *
3827 * Input:
3828 * ha = adapter block pointer.
3829 * vhba = virtual adapter (unused)
3830 * index = index number for enabled VP
3831 *
3832 * Returns:
3833 * qla2xxx local function return status code.
3834 *
3835 * Context:
3836 * Kernel context.
3837 */
3838int
3839qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3840{
3841 int rval;
3842 int map, pos;
3843 struct vp_ctrl_entry_24xx *vce;
3844 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003845 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003846 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003847 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003848
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003849 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003850 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003851
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003852 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003853 return QLA_PARAMETER_ERROR;
3854
3855 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3856 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003857 ql_log(ql_log_warn, vha, 0x10c2,
3858 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003859 return QLA_MEMORY_ALLOC_FAILED;
3860 }
3861 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3862
3863 vce->entry_type = VP_CTRL_IOCB_TYPE;
3864 vce->entry_count = 1;
3865 vce->command = cpu_to_le16(cmd);
Bart Van Asschead950362015-07-09 07:24:08 -07003866 vce->vp_count = cpu_to_le16(1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003867
3868 /* index map in firmware starts with 1; decrement index
3869 * this is ok as we never use index 0
3870 */
3871 map = (vp_index - 1) / 8;
3872 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003873 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003874 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003875 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003876
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003877 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003878 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003879 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3880 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003881 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003882 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3883 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003884 vce->entry_status);
3885 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003886 } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003887 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
Colin Ian King0bf0efa2017-06-30 14:47:41 +01003888 "Failed to complete IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003889 le16_to_cpu(vce->comp_status));
3890 rval = QLA_FUNCTION_FAILED;
3891 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003892 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3893 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003894 }
3895
3896 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3897
3898 return rval;
3899}
3900
3901/*
3902 * qla2x00_send_change_request
3903 * Receive or disable RSCN request from fabric controller
3904 *
3905 * Input:
3906 * ha = adapter block pointer
3907 * format = registration format:
3908 * 0 - Reserved
3909 * 1 - Fabric detected registration
3910 * 2 - N_port detected registration
3911 * 3 - Full registration
3912 * FF - clear registration
3913 * vp_idx = Virtual port index
3914 *
3915 * Returns:
3916 * qla2x00 local function return status code.
3917 *
3918 * Context:
3919 * Kernel Context
3920 */
3921
3922int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003923qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003924 uint16_t vp_idx)
3925{
3926 int rval;
3927 mbx_cmd_t mc;
3928 mbx_cmd_t *mcp = &mc;
3929
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003930 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3931 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003932
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003933 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3934 mcp->mb[1] = format;
3935 mcp->mb[9] = vp_idx;
3936 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3937 mcp->in_mb = MBX_0|MBX_1;
3938 mcp->tov = MBX_TOV_SECONDS;
3939 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003940 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003941
3942 if (rval == QLA_SUCCESS) {
3943 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3944 rval = BIT_1;
3945 }
3946 } else
3947 rval = BIT_1;
3948
3949 return rval;
3950}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003951
3952int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003953qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003954 uint32_t size)
3955{
3956 int rval;
3957 mbx_cmd_t mc;
3958 mbx_cmd_t *mcp = &mc;
3959
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003960 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3961 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003962
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003963 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003964 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3965 mcp->mb[8] = MSW(addr);
3966 mcp->out_mb = MBX_8|MBX_0;
3967 } else {
3968 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3969 mcp->out_mb = MBX_0;
3970 }
3971 mcp->mb[1] = LSW(addr);
3972 mcp->mb[2] = MSW(req_dma);
3973 mcp->mb[3] = LSW(req_dma);
3974 mcp->mb[6] = MSW(MSD(req_dma));
3975 mcp->mb[7] = LSW(MSD(req_dma));
3976 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003977 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003978 mcp->mb[4] = MSW(size);
3979 mcp->mb[5] = LSW(size);
3980 mcp->out_mb |= MBX_5|MBX_4;
3981 } else {
3982 mcp->mb[4] = LSW(size);
3983 mcp->out_mb |= MBX_4;
3984 }
3985
3986 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003987 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003988 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003989 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003990
3991 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003992 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3993 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003994 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003995 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3996 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003997 }
3998
3999 return rval;
4000}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004001/* 84XX Support **************************************************************/
4002
4003struct cs84xx_mgmt_cmd {
4004 union {
4005 struct verify_chip_entry_84xx req;
4006 struct verify_chip_rsp_84xx rsp;
4007 } p;
4008};
4009
4010int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004011qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004012{
4013 int rval, retry;
4014 struct cs84xx_mgmt_cmd *mn;
4015 dma_addr_t mn_dma;
4016 uint16_t options;
4017 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004018 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004019
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004020 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4021 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004022
4023 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4024 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004025 return QLA_MEMORY_ALLOC_FAILED;
4026 }
4027
4028 /* Force Update? */
4029 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4030 /* Diagnostic firmware? */
4031 /* options |= MENLO_DIAG_FW; */
4032 /* We update the firmware with only one data sequence. */
4033 options |= VCO_END_OF_DATA;
4034
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004035 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004036 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004037 memset(mn, 0, sizeof(*mn));
4038 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4039 mn->p.req.entry_count = 1;
4040 mn->p.req.options = cpu_to_le16(options);
4041
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004042 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4043 "Dump of Verify Request.\n");
4044 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4045 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004046
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004047 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004048 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004049 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4050 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004051 goto verify_done;
4052 }
4053
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004054 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4055 "Dump of Verify Response.\n");
4056 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4057 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004058
4059 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4060 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4061 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004062 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004063 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004064
4065 if (status[0] != CS_COMPLETE) {
4066 rval = QLA_FUNCTION_FAILED;
4067 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004068 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4069 "Firmware update failed. Retrying "
4070 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004071 options |= VCO_DONT_UPDATE_FW;
4072 options &= ~VCO_FORCE_UPDATE;
4073 retry = 1;
4074 }
4075 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004076 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004077 "Firmware updated to %x.\n",
4078 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004079
4080 /* NOTE: we only update OP firmware. */
4081 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4082 ha->cs84xx->op_fw_version =
4083 le32_to_cpu(mn->p.rsp.fw_ver);
4084 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4085 flags);
4086 }
4087 } while (retry);
4088
4089verify_done:
4090 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4091
4092 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004093 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4094 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004095 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004096 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4097 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004098 }
4099
4100 return rval;
4101}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004102
4103int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004104qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004105{
4106 int rval;
4107 unsigned long flags;
4108 mbx_cmd_t mc;
4109 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004110 struct qla_hw_data *ha = vha->hw;
4111
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004112 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4113 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004114
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004115 if (IS_SHADOW_REG_CAPABLE(ha))
4116 req->options |= BIT_13;
4117
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004118 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004119 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004120 mcp->mb[2] = MSW(LSD(req->dma));
4121 mcp->mb[3] = LSW(LSD(req->dma));
4122 mcp->mb[6] = MSW(MSD(req->dma));
4123 mcp->mb[7] = LSW(MSD(req->dma));
4124 mcp->mb[5] = req->length;
4125 if (req->rsp)
4126 mcp->mb[10] = req->rsp->id;
4127 mcp->mb[12] = req->qos;
4128 mcp->mb[11] = req->vp_idx;
4129 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004130 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004131 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004132
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004133 mcp->mb[4] = req->id;
4134 /* que in ptr index */
4135 mcp->mb[8] = 0;
4136 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004137 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004138 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4139 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4140 mcp->in_mb = MBX_0;
4141 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004142 mcp->tov = MBX_TOV_SECONDS * 2;
4143
Chad Dupuisf73cb692014-02-26 04:15:06 -05004144 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004145 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004146 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004147 mcp->out_mb |= MBX_15;
4148 /* debug q create issue in SR-IOV */
4149 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4150 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004151
4152 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004153 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004154 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004155 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004156 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004157 }
4158 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4159
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004160 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004161 if (rval != QLA_SUCCESS) {
4162 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4163 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4164 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004165 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4166 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004167 }
4168
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004169 return rval;
4170}
4171
4172int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004173qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004174{
4175 int rval;
4176 unsigned long flags;
4177 mbx_cmd_t mc;
4178 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004179 struct qla_hw_data *ha = vha->hw;
4180
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004181 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4182 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004183
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004184 if (IS_SHADOW_REG_CAPABLE(ha))
4185 rsp->options |= BIT_13;
4186
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004187 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004188 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004189 mcp->mb[2] = MSW(LSD(rsp->dma));
4190 mcp->mb[3] = LSW(LSD(rsp->dma));
4191 mcp->mb[6] = MSW(MSD(rsp->dma));
4192 mcp->mb[7] = LSW(MSD(rsp->dma));
4193 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004194 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004195 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004196 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004197 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004198
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004199 mcp->mb[4] = rsp->id;
4200 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004201 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004202 /* que out ptr index */
4203 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004204 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004205 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4206 mcp->in_mb = MBX_0;
4207 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004208 mcp->tov = MBX_TOV_SECONDS * 2;
4209
4210 if (IS_QLA81XX(ha)) {
4211 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4212 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004213 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004214 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4215 mcp->in_mb |= MBX_1;
4216 /* debug q create issue in SR-IOV */
4217 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4218 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004219
4220 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004221 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004222 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004223 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004224 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004225 }
4226
4227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4228
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004229 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004230 if (rval != QLA_SUCCESS) {
4231 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4232 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4233 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004234 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4235 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004236 }
4237
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004238 return rval;
4239}
4240
Andrew Vasquez8a659572009-02-08 20:50:12 -08004241int
4242qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4243{
4244 int rval;
4245 mbx_cmd_t mc;
4246 mbx_cmd_t *mcp = &mc;
4247
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004248 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4249 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004250
4251 mcp->mb[0] = MBC_IDC_ACK;
4252 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4253 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4254 mcp->in_mb = MBX_0;
4255 mcp->tov = MBX_TOV_SECONDS;
4256 mcp->flags = 0;
4257 rval = qla2x00_mailbox_command(vha, mcp);
4258
4259 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004260 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4261 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004262 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004263 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4264 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004265 }
4266
4267 return rval;
4268}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004269
4270int
4271qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4272{
4273 int rval;
4274 mbx_cmd_t mc;
4275 mbx_cmd_t *mcp = &mc;
4276
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004277 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4278 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004279
Chad Dupuisf73cb692014-02-26 04:15:06 -05004280 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4281 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004282 return QLA_FUNCTION_FAILED;
4283
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004284 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4285 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4286 mcp->out_mb = MBX_1|MBX_0;
4287 mcp->in_mb = MBX_1|MBX_0;
4288 mcp->tov = MBX_TOV_SECONDS;
4289 mcp->flags = 0;
4290 rval = qla2x00_mailbox_command(vha, mcp);
4291
4292 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004293 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4294 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4295 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004296 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004297 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4298 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004299 *sector_size = mcp->mb[1];
4300 }
4301
4302 return rval;
4303}
4304
4305int
4306qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4307{
4308 int rval;
4309 mbx_cmd_t mc;
4310 mbx_cmd_t *mcp = &mc;
4311
Chad Dupuisf73cb692014-02-26 04:15:06 -05004312 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4313 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004314 return QLA_FUNCTION_FAILED;
4315
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004316 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4317 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004318
4319 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4320 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4321 FAC_OPT_CMD_WRITE_PROTECT;
4322 mcp->out_mb = MBX_1|MBX_0;
4323 mcp->in_mb = MBX_1|MBX_0;
4324 mcp->tov = MBX_TOV_SECONDS;
4325 mcp->flags = 0;
4326 rval = qla2x00_mailbox_command(vha, mcp);
4327
4328 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004329 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4330 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4331 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004332 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004333 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4334 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004335 }
4336
4337 return rval;
4338}
4339
4340int
4341qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4342{
4343 int rval;
4344 mbx_cmd_t mc;
4345 mbx_cmd_t *mcp = &mc;
4346
Chad Dupuisf73cb692014-02-26 04:15:06 -05004347 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4348 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004349 return QLA_FUNCTION_FAILED;
4350
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4352 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004353
4354 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4355 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4356 mcp->mb[2] = LSW(start);
4357 mcp->mb[3] = MSW(start);
4358 mcp->mb[4] = LSW(finish);
4359 mcp->mb[5] = MSW(finish);
4360 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4361 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4362 mcp->tov = MBX_TOV_SECONDS;
4363 mcp->flags = 0;
4364 rval = qla2x00_mailbox_command(vha, mcp);
4365
4366 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004367 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4368 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4369 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004370 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4372 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004373 }
4374
4375 return rval;
4376}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004377
4378int
4379qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4380{
4381 int rval = 0;
4382 mbx_cmd_t mc;
4383 mbx_cmd_t *mcp = &mc;
4384
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004385 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4386 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004387
4388 mcp->mb[0] = MBC_RESTART_MPI_FW;
4389 mcp->out_mb = MBX_0;
4390 mcp->in_mb = MBX_0|MBX_1;
4391 mcp->tov = MBX_TOV_SECONDS;
4392 mcp->flags = 0;
4393 rval = qla2x00_mailbox_command(vha, mcp);
4394
4395 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004396 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4397 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4398 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004399 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004400 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4401 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004402 }
4403
4404 return rval;
4405}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004406
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004407int
4408qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4409{
4410 int rval;
4411 mbx_cmd_t mc;
4412 mbx_cmd_t *mcp = &mc;
4413 int i;
4414 int len;
4415 uint16_t *str;
4416 struct qla_hw_data *ha = vha->hw;
4417
4418 if (!IS_P3P_TYPE(ha))
4419 return QLA_FUNCTION_FAILED;
4420
4421 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4422 "Entered %s.\n", __func__);
4423
4424 str = (void *)version;
4425 len = strlen(version);
4426
4427 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4428 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4429 mcp->out_mb = MBX_1|MBX_0;
4430 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4431 mcp->mb[i] = cpu_to_le16p(str);
4432 mcp->out_mb |= 1<<i;
4433 }
4434 for (; i < 16; i++) {
4435 mcp->mb[i] = 0;
4436 mcp->out_mb |= 1<<i;
4437 }
4438 mcp->in_mb = MBX_1|MBX_0;
4439 mcp->tov = MBX_TOV_SECONDS;
4440 mcp->flags = 0;
4441 rval = qla2x00_mailbox_command(vha, mcp);
4442
4443 if (rval != QLA_SUCCESS) {
4444 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4445 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4446 } else {
4447 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4448 "Done %s.\n", __func__);
4449 }
4450
4451 return rval;
4452}
4453
4454int
4455qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4456{
4457 int rval;
4458 mbx_cmd_t mc;
4459 mbx_cmd_t *mcp = &mc;
4460 int len;
4461 uint16_t dwlen;
4462 uint8_t *str;
4463 dma_addr_t str_dma;
4464 struct qla_hw_data *ha = vha->hw;
4465
4466 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4467 IS_P3P_TYPE(ha))
4468 return QLA_FUNCTION_FAILED;
4469
4470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4471 "Entered %s.\n", __func__);
4472
4473 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4474 if (!str) {
4475 ql_log(ql_log_warn, vha, 0x117f,
4476 "Failed to allocate driver version param.\n");
4477 return QLA_MEMORY_ALLOC_FAILED;
4478 }
4479
4480 memcpy(str, "\x7\x3\x11\x0", 4);
4481 dwlen = str[0];
4482 len = dwlen * 4 - 4;
4483 memset(str + 4, 0, len);
4484 if (len > strlen(version))
4485 len = strlen(version);
4486 memcpy(str + 4, version, len);
4487
4488 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4489 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4490 mcp->mb[2] = MSW(LSD(str_dma));
4491 mcp->mb[3] = LSW(LSD(str_dma));
4492 mcp->mb[6] = MSW(MSD(str_dma));
4493 mcp->mb[7] = LSW(MSD(str_dma));
4494 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4495 mcp->in_mb = MBX_1|MBX_0;
4496 mcp->tov = MBX_TOV_SECONDS;
4497 mcp->flags = 0;
4498 rval = qla2x00_mailbox_command(vha, mcp);
4499
4500 if (rval != QLA_SUCCESS) {
4501 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4502 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4503 } else {
4504 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4505 "Done %s.\n", __func__);
4506 }
4507
4508 dma_pool_free(ha->s_dma_pool, str, str_dma);
4509
4510 return rval;
4511}
4512
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004513static int
4514qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4515{
4516 int rval;
4517 mbx_cmd_t mc;
4518 mbx_cmd_t *mcp = &mc;
4519
4520 if (!IS_FWI2_CAPABLE(vha->hw))
4521 return QLA_FUNCTION_FAILED;
4522
4523 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4524 "Entered %s.\n", __func__);
4525
4526 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4527 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4528 mcp->out_mb = MBX_1|MBX_0;
4529 mcp->in_mb = MBX_1|MBX_0;
4530 mcp->tov = MBX_TOV_SECONDS;
4531 mcp->flags = 0;
4532 rval = qla2x00_mailbox_command(vha, mcp);
4533 *temp = mcp->mb[1];
4534
4535 if (rval != QLA_SUCCESS) {
4536 ql_dbg(ql_dbg_mbx, vha, 0x115a,
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, 0x115b,
4540 "Done %s.\n", __func__);
4541 }
4542
4543 return rval;
4544}
4545
Joe Carnuccio3a117112013-02-08 01:58:00 -05004546int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004547qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4548 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004549{
4550 int rval;
4551 mbx_cmd_t mc;
4552 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004553 struct qla_hw_data *ha = vha->hw;
4554
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004555 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4556 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004557
Joe Carnuccio6766df92011-05-10 11:30:15 -07004558 if (!IS_FWI2_CAPABLE(ha))
4559 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004560
Joe Carnuccio6766df92011-05-10 11:30:15 -07004561 if (len == 1)
4562 opt |= BIT_0;
4563
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004564 mcp->mb[0] = MBC_READ_SFP;
4565 mcp->mb[1] = dev;
4566 mcp->mb[2] = MSW(sfp_dma);
4567 mcp->mb[3] = LSW(sfp_dma);
4568 mcp->mb[6] = MSW(MSD(sfp_dma));
4569 mcp->mb[7] = LSW(MSD(sfp_dma));
4570 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004571 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004572 mcp->mb[10] = opt;
4573 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 -07004574 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004575 mcp->tov = MBX_TOV_SECONDS;
4576 mcp->flags = 0;
4577 rval = qla2x00_mailbox_command(vha, mcp);
4578
4579 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004580 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004581
4582 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004583 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4584 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004585 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004586 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4587 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004588 }
4589
4590 return rval;
4591}
4592
4593int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004594qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4595 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004596{
4597 int rval;
4598 mbx_cmd_t mc;
4599 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004600 struct qla_hw_data *ha = vha->hw;
4601
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004602 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4603 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004604
Joe Carnuccio6766df92011-05-10 11:30:15 -07004605 if (!IS_FWI2_CAPABLE(ha))
4606 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004607
Joe Carnuccio6766df92011-05-10 11:30:15 -07004608 if (len == 1)
4609 opt |= BIT_0;
4610
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004611 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004612 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004613
4614 mcp->mb[0] = MBC_WRITE_SFP;
4615 mcp->mb[1] = dev;
4616 mcp->mb[2] = MSW(sfp_dma);
4617 mcp->mb[3] = LSW(sfp_dma);
4618 mcp->mb[6] = MSW(MSD(sfp_dma));
4619 mcp->mb[7] = LSW(MSD(sfp_dma));
4620 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004621 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004622 mcp->mb[10] = opt;
4623 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 -07004624 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004625 mcp->tov = MBX_TOV_SECONDS;
4626 mcp->flags = 0;
4627 rval = qla2x00_mailbox_command(vha, mcp);
4628
4629 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004630 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4631 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004632 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004633 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4634 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004635 }
4636
4637 return rval;
4638}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004639
4640int
4641qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4642 uint16_t size_in_bytes, uint16_t *actual_size)
4643{
4644 int rval;
4645 mbx_cmd_t mc;
4646 mbx_cmd_t *mcp = &mc;
4647
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004648 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4649 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004650
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004651 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004652 return QLA_FUNCTION_FAILED;
4653
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004654 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4655 mcp->mb[2] = MSW(stats_dma);
4656 mcp->mb[3] = LSW(stats_dma);
4657 mcp->mb[6] = MSW(MSD(stats_dma));
4658 mcp->mb[7] = LSW(MSD(stats_dma));
4659 mcp->mb[8] = size_in_bytes >> 2;
4660 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4661 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4662 mcp->tov = MBX_TOV_SECONDS;
4663 mcp->flags = 0;
4664 rval = qla2x00_mailbox_command(vha, mcp);
4665
4666 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004667 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4668 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4669 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004670 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004671 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4672 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004673
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004674
4675 *actual_size = mcp->mb[2] << 2;
4676 }
4677
4678 return rval;
4679}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004680
4681int
4682qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4683 uint16_t size)
4684{
4685 int rval;
4686 mbx_cmd_t mc;
4687 mbx_cmd_t *mcp = &mc;
4688
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004689 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4690 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004691
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004692 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004693 return QLA_FUNCTION_FAILED;
4694
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004695 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4696 mcp->mb[1] = 0;
4697 mcp->mb[2] = MSW(tlv_dma);
4698 mcp->mb[3] = LSW(tlv_dma);
4699 mcp->mb[6] = MSW(MSD(tlv_dma));
4700 mcp->mb[7] = LSW(MSD(tlv_dma));
4701 mcp->mb[8] = size;
4702 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4703 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4704 mcp->tov = MBX_TOV_SECONDS;
4705 mcp->flags = 0;
4706 rval = qla2x00_mailbox_command(vha, mcp);
4707
4708 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004709 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4710 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4711 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004712 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4714 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004715 }
4716
4717 return rval;
4718}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004719
4720int
4721qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4722{
4723 int rval;
4724 mbx_cmd_t mc;
4725 mbx_cmd_t *mcp = &mc;
4726
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004727 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4728 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004729
Andrew Vasquez18e75552009-06-03 09:55:30 -07004730 if (!IS_FWI2_CAPABLE(vha->hw))
4731 return QLA_FUNCTION_FAILED;
4732
Andrew Vasquez18e75552009-06-03 09:55:30 -07004733 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4734 mcp->mb[1] = LSW(risc_addr);
4735 mcp->mb[8] = MSW(risc_addr);
4736 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4737 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4738 mcp->tov = 30;
4739 mcp->flags = 0;
4740 rval = qla2x00_mailbox_command(vha, mcp);
4741 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004742 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4743 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004744 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4746 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004747 *data = mcp->mb[3] << 16 | mcp->mb[2];
4748 }
4749
4750 return rval;
4751}
4752
4753int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004754qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4755 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004756{
4757 int rval;
4758 mbx_cmd_t mc;
4759 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004760
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004761 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4762 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004763
4764 memset(mcp->mb, 0 , sizeof(mcp->mb));
4765 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4766 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4767
4768 /* transfer count */
4769 mcp->mb[10] = LSW(mreq->transfer_size);
4770 mcp->mb[11] = MSW(mreq->transfer_size);
4771
4772 /* send data address */
4773 mcp->mb[14] = LSW(mreq->send_dma);
4774 mcp->mb[15] = MSW(mreq->send_dma);
4775 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4776 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4777
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004778 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004779 mcp->mb[16] = LSW(mreq->rcv_dma);
4780 mcp->mb[17] = MSW(mreq->rcv_dma);
4781 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4782 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4783
4784 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004785 mcp->mb[18] = LSW(mreq->iteration_count);
4786 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004787
4788 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4789 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 -08004790 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004791 mcp->out_mb |= MBX_2;
4792 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4793
4794 mcp->buf_size = mreq->transfer_size;
4795 mcp->tov = MBX_TOV_SECONDS;
4796 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4797
4798 rval = qla2x00_mailbox_command(vha, mcp);
4799
4800 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004801 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4802 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4803 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4804 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004805 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004806 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4807 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004808 }
4809
4810 /* Copy mailbox information */
4811 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004812 return rval;
4813}
4814
4815int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004816qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4817 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004818{
4819 int rval;
4820 mbx_cmd_t mc;
4821 mbx_cmd_t *mcp = &mc;
4822 struct qla_hw_data *ha = vha->hw;
4823
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004824 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4825 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004826
4827 memset(mcp->mb, 0 , sizeof(mcp->mb));
4828 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07004829 /* BIT_6 specifies 64bit address */
4830 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004831 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004832 mcp->mb[2] = vha->fcoe_fcf_idx;
4833 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004834 mcp->mb[16] = LSW(mreq->rcv_dma);
4835 mcp->mb[17] = MSW(mreq->rcv_dma);
4836 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4837 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4838
4839 mcp->mb[10] = LSW(mreq->transfer_size);
4840
4841 mcp->mb[14] = LSW(mreq->send_dma);
4842 mcp->mb[15] = MSW(mreq->send_dma);
4843 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4844 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4845
4846 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4847 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004848 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004849 mcp->out_mb |= MBX_2;
4850
4851 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004852 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4853 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004854 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004855 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004856 mcp->in_mb |= MBX_3;
4857
4858 mcp->tov = MBX_TOV_SECONDS;
4859 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4860 mcp->buf_size = mreq->transfer_size;
4861
4862 rval = qla2x00_mailbox_command(vha, mcp);
4863
4864 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004865 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4866 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4867 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004868 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004869 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4870 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004871 }
4872
4873 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004874 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004875 return rval;
4876}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004877
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004878int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004879qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004880{
4881 int rval;
4882 mbx_cmd_t mc;
4883 mbx_cmd_t *mcp = &mc;
4884
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004886 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004887
4888 mcp->mb[0] = MBC_ISP84XX_RESET;
4889 mcp->mb[1] = enable_diagnostic;
4890 mcp->out_mb = MBX_1|MBX_0;
4891 mcp->in_mb = MBX_1|MBX_0;
4892 mcp->tov = MBX_TOV_SECONDS;
4893 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004894 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004895
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004896 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004897 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004898 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4900 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004901
4902 return rval;
4903}
4904
4905int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004906qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4907{
4908 int rval;
4909 mbx_cmd_t mc;
4910 mbx_cmd_t *mcp = &mc;
4911
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004912 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4913 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004914
Andrew Vasquez18e75552009-06-03 09:55:30 -07004915 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004916 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004917
Andrew Vasquez18e75552009-06-03 09:55:30 -07004918 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4919 mcp->mb[1] = LSW(risc_addr);
4920 mcp->mb[2] = LSW(data);
4921 mcp->mb[3] = MSW(data);
4922 mcp->mb[8] = MSW(risc_addr);
4923 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4924 mcp->in_mb = MBX_0;
4925 mcp->tov = 30;
4926 mcp->flags = 0;
4927 rval = qla2x00_mailbox_command(vha, mcp);
4928 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004929 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4930 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004931 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004932 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4933 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004934 }
4935
4936 return rval;
4937}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004938
4939int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004940qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4941{
4942 int rval;
4943 uint32_t stat, timer;
4944 uint16_t mb0 = 0;
4945 struct qla_hw_data *ha = vha->hw;
4946 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4947
4948 rval = QLA_SUCCESS;
4949
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004950 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4951 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004952
4953 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4954
4955 /* Write the MBC data to the registers */
4956 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4957 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4958 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4959 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4960 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4961
4962 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4963
4964 /* Poll for MBC interrupt */
4965 for (timer = 6000000; timer; timer--) {
4966 /* Check for pending interrupts. */
4967 stat = RD_REG_DWORD(&reg->host_status);
4968 if (stat & HSRX_RISC_INT) {
4969 stat &= 0xff;
4970
4971 if (stat == 0x1 || stat == 0x2 ||
4972 stat == 0x10 || stat == 0x11) {
4973 set_bit(MBX_INTERRUPT,
4974 &ha->mbx_cmd_flags);
4975 mb0 = RD_REG_WORD(&reg->mailbox0);
4976 WRT_REG_DWORD(&reg->hccr,
4977 HCCRX_CLR_RISC_INT);
4978 RD_REG_DWORD(&reg->hccr);
4979 break;
4980 }
4981 }
4982 udelay(5);
4983 }
4984
4985 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4986 rval = mb0 & MBS_MASK;
4987 else
4988 rval = QLA_FUNCTION_FAILED;
4989
4990 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004991 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4992 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004993 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004994 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4995 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004996 }
4997
4998 return rval;
4999}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005000
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005001int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005002qla2x00_get_data_rate(scsi_qla_host_t *vha)
5003{
5004 int rval;
5005 mbx_cmd_t mc;
5006 mbx_cmd_t *mcp = &mc;
5007 struct qla_hw_data *ha = vha->hw;
5008
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005009 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5010 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005011
Michael Hernandez3064ff32009-12-15 21:29:44 -08005012 if (!IS_FWI2_CAPABLE(ha))
5013 return QLA_FUNCTION_FAILED;
5014
Michael Hernandez3064ff32009-12-15 21:29:44 -08005015 mcp->mb[0] = MBC_DATA_RATE;
5016 mcp->mb[1] = 0;
5017 mcp->out_mb = MBX_1|MBX_0;
5018 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005019 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005020 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005021 mcp->tov = MBX_TOV_SECONDS;
5022 mcp->flags = 0;
5023 rval = qla2x00_mailbox_command(vha, mcp);
5024 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005025 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5026 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005027 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005028 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5029 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005030 if (mcp->mb[1] != 0x7)
5031 ha->link_data_rate = mcp->mb[1];
5032 }
5033
5034 return rval;
5035}
Sarang Radke09ff7012010-03-19 17:03:59 -07005036
5037int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005038qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5039{
5040 int rval;
5041 mbx_cmd_t mc;
5042 mbx_cmd_t *mcp = &mc;
5043 struct qla_hw_data *ha = vha->hw;
5044
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005045 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5046 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005047
Chad Dupuisf73cb692014-02-26 04:15:06 -05005048 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5049 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005050 return QLA_FUNCTION_FAILED;
5051 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5052 mcp->out_mb = MBX_0;
5053 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5054 mcp->tov = MBX_TOV_SECONDS;
5055 mcp->flags = 0;
5056
5057 rval = qla2x00_mailbox_command(vha, mcp);
5058
5059 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005060 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5061 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005062 } else {
5063 /* Copy all bits to preserve original value */
5064 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5065
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005066 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5067 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005068 }
5069 return rval;
5070}
5071
5072int
5073qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5074{
5075 int rval;
5076 mbx_cmd_t mc;
5077 mbx_cmd_t *mcp = &mc;
5078
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005079 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5080 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005081
5082 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5083 /* Copy all bits to preserve original setting */
5084 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5085 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5086 mcp->in_mb = MBX_0;
5087 mcp->tov = MBX_TOV_SECONDS;
5088 mcp->flags = 0;
5089 rval = qla2x00_mailbox_command(vha, mcp);
5090
5091 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005092 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5093 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005094 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005095 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5096 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005097
5098 return rval;
5099}
5100
5101
5102int
Sarang Radke09ff7012010-03-19 17:03:59 -07005103qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5104 uint16_t *mb)
5105{
5106 int rval;
5107 mbx_cmd_t mc;
5108 mbx_cmd_t *mcp = &mc;
5109 struct qla_hw_data *ha = vha->hw;
5110
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005111 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5112 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005113
Sarang Radke09ff7012010-03-19 17:03:59 -07005114 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5115 return QLA_FUNCTION_FAILED;
5116
Sarang Radke09ff7012010-03-19 17:03:59 -07005117 mcp->mb[0] = MBC_PORT_PARAMS;
5118 mcp->mb[1] = loop_id;
5119 if (ha->flags.fcp_prio_enabled)
5120 mcp->mb[2] = BIT_1;
5121 else
5122 mcp->mb[2] = BIT_2;
5123 mcp->mb[4] = priority & 0xf;
5124 mcp->mb[9] = vha->vp_idx;
5125 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5126 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5127 mcp->tov = 30;
5128 mcp->flags = 0;
5129 rval = qla2x00_mailbox_command(vha, mcp);
5130 if (mb != NULL) {
5131 mb[0] = mcp->mb[0];
5132 mb[1] = mcp->mb[1];
5133 mb[3] = mcp->mb[3];
5134 mb[4] = mcp->mb[4];
5135 }
5136
5137 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005138 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005139 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005140 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5141 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005142 }
5143
5144 return rval;
5145}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005146
5147int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005148qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005149{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005150 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005151 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005152 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005153
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005154 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5155 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5156 "Thermal not supported by this card.\n");
5157 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005158 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005159
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005160 if (IS_QLA25XX(ha)) {
5161 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5162 ha->pdev->subsystem_device == 0x0175) {
5163 rval = qla2x00_read_sfp(vha, 0, &byte,
5164 0x98, 0x1, 1, BIT_13|BIT_0);
5165 *temp = byte;
5166 return rval;
5167 }
5168 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5169 ha->pdev->subsystem_device == 0x338e) {
5170 rval = qla2x00_read_sfp(vha, 0, &byte,
5171 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5172 *temp = byte;
5173 return rval;
5174 }
5175 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5176 "Thermal not supported by this card.\n");
5177 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005178 }
5179
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005180 if (IS_QLA82XX(ha)) {
5181 *temp = qla82xx_read_temperature(vha);
5182 rval = QLA_SUCCESS;
5183 return rval;
5184 } else if (IS_QLA8044(ha)) {
5185 *temp = qla8044_read_temperature(vha);
5186 rval = QLA_SUCCESS;
5187 return rval;
5188 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005189
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005190 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005191 return rval;
5192}
5193
5194int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005195qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5196{
5197 int rval;
5198 struct qla_hw_data *ha = vha->hw;
5199 mbx_cmd_t mc;
5200 mbx_cmd_t *mcp = &mc;
5201
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005202 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5203 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005204
Giridhar Malavalia9083012010-04-12 17:59:55 -07005205 if (!IS_FWI2_CAPABLE(ha))
5206 return QLA_FUNCTION_FAILED;
5207
Giridhar Malavalia9083012010-04-12 17:59:55 -07005208 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005209 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005210 mcp->mb[1] = 1;
5211
5212 mcp->out_mb = MBX_1|MBX_0;
5213 mcp->in_mb = MBX_0;
5214 mcp->tov = 30;
5215 mcp->flags = 0;
5216
5217 rval = qla2x00_mailbox_command(vha, mcp);
5218 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005219 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5220 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005221 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005222 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5223 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005224 }
5225
5226 return rval;
5227}
5228
5229int
5230qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5231{
5232 int rval;
5233 struct qla_hw_data *ha = vha->hw;
5234 mbx_cmd_t mc;
5235 mbx_cmd_t *mcp = &mc;
5236
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005237 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5238 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005239
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005240 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005241 return QLA_FUNCTION_FAILED;
5242
Giridhar Malavalia9083012010-04-12 17:59:55 -07005243 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005244 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005245 mcp->mb[1] = 0;
5246
5247 mcp->out_mb = MBX_1|MBX_0;
5248 mcp->in_mb = MBX_0;
5249 mcp->tov = 30;
5250 mcp->flags = 0;
5251
5252 rval = qla2x00_mailbox_command(vha, mcp);
5253 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005254 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5255 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005256 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005257 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5258 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005259 }
5260
5261 return rval;
5262}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005263
5264int
5265qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5266{
5267 struct qla_hw_data *ha = vha->hw;
5268 mbx_cmd_t mc;
5269 mbx_cmd_t *mcp = &mc;
5270 int rval = QLA_FUNCTION_FAILED;
5271
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005272 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5273 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005274
5275 memset(mcp->mb, 0 , sizeof(mcp->mb));
5276 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5277 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5278 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5279 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5280
5281 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5282 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5283 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5284
5285 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5286 mcp->tov = MBX_TOV_SECONDS;
5287 rval = qla2x00_mailbox_command(vha, mcp);
5288
5289 /* Always copy back return mailbox values. */
5290 if (rval != QLA_SUCCESS) {
5291 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5292 "mailbox command FAILED=0x%x, subcode=%x.\n",
5293 (mcp->mb[1] << 16) | mcp->mb[0],
5294 (mcp->mb[3] << 16) | mcp->mb[2]);
5295 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005296 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5297 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005298 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5299 if (!ha->md_template_size) {
5300 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5301 "Null template size obtained.\n");
5302 rval = QLA_FUNCTION_FAILED;
5303 }
5304 }
5305 return rval;
5306}
5307
5308int
5309qla82xx_md_get_template(scsi_qla_host_t *vha)
5310{
5311 struct qla_hw_data *ha = vha->hw;
5312 mbx_cmd_t mc;
5313 mbx_cmd_t *mcp = &mc;
5314 int rval = QLA_FUNCTION_FAILED;
5315
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005316 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5317 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005318
5319 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5320 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5321 if (!ha->md_tmplt_hdr) {
5322 ql_log(ql_log_warn, vha, 0x1124,
5323 "Unable to allocate memory for Minidump template.\n");
5324 return rval;
5325 }
5326
5327 memset(mcp->mb, 0 , sizeof(mcp->mb));
5328 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5329 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5330 mcp->mb[2] = LSW(RQST_TMPLT);
5331 mcp->mb[3] = MSW(RQST_TMPLT);
5332 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5333 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5334 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5335 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5336 mcp->mb[8] = LSW(ha->md_template_size);
5337 mcp->mb[9] = MSW(ha->md_template_size);
5338
5339 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5340 mcp->tov = MBX_TOV_SECONDS;
5341 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5342 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5343 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5344 rval = qla2x00_mailbox_command(vha, mcp);
5345
5346 if (rval != QLA_SUCCESS) {
5347 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5348 "mailbox command FAILED=0x%x, subcode=%x.\n",
5349 ((mcp->mb[1] << 16) | mcp->mb[0]),
5350 ((mcp->mb[3] << 16) | mcp->mb[2]));
5351 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005352 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5353 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005354 return rval;
5355}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005356
5357int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005358qla8044_md_get_template(scsi_qla_host_t *vha)
5359{
5360 struct qla_hw_data *ha = vha->hw;
5361 mbx_cmd_t mc;
5362 mbx_cmd_t *mcp = &mc;
5363 int rval = QLA_FUNCTION_FAILED;
5364 int offset = 0, size = MINIDUMP_SIZE_36K;
5365 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5366 "Entered %s.\n", __func__);
5367
5368 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5369 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5370 if (!ha->md_tmplt_hdr) {
5371 ql_log(ql_log_warn, vha, 0xb11b,
5372 "Unable to allocate memory for Minidump template.\n");
5373 return rval;
5374 }
5375
5376 memset(mcp->mb, 0 , sizeof(mcp->mb));
5377 while (offset < ha->md_template_size) {
5378 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5379 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5380 mcp->mb[2] = LSW(RQST_TMPLT);
5381 mcp->mb[3] = MSW(RQST_TMPLT);
5382 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5383 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5384 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5385 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5386 mcp->mb[8] = LSW(size);
5387 mcp->mb[9] = MSW(size);
5388 mcp->mb[10] = offset & 0x0000FFFF;
5389 mcp->mb[11] = offset & 0xFFFF0000;
5390 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5391 mcp->tov = MBX_TOV_SECONDS;
5392 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5393 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5394 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5395 rval = qla2x00_mailbox_command(vha, mcp);
5396
5397 if (rval != QLA_SUCCESS) {
5398 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5399 "mailbox command FAILED=0x%x, subcode=%x.\n",
5400 ((mcp->mb[1] << 16) | mcp->mb[0]),
5401 ((mcp->mb[3] << 16) | mcp->mb[2]));
5402 return rval;
5403 } else
5404 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5405 "Done %s.\n", __func__);
5406 offset = offset + size;
5407 }
5408 return rval;
5409}
5410
5411int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005412qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5413{
5414 int rval;
5415 struct qla_hw_data *ha = vha->hw;
5416 mbx_cmd_t mc;
5417 mbx_cmd_t *mcp = &mc;
5418
5419 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5420 return QLA_FUNCTION_FAILED;
5421
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005422 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5423 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005424
5425 memset(mcp, 0, sizeof(mbx_cmd_t));
5426 mcp->mb[0] = MBC_SET_LED_CONFIG;
5427 mcp->mb[1] = led_cfg[0];
5428 mcp->mb[2] = led_cfg[1];
5429 if (IS_QLA8031(ha)) {
5430 mcp->mb[3] = led_cfg[2];
5431 mcp->mb[4] = led_cfg[3];
5432 mcp->mb[5] = led_cfg[4];
5433 mcp->mb[6] = led_cfg[5];
5434 }
5435
5436 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5437 if (IS_QLA8031(ha))
5438 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5439 mcp->in_mb = MBX_0;
5440 mcp->tov = 30;
5441 mcp->flags = 0;
5442
5443 rval = qla2x00_mailbox_command(vha, mcp);
5444 if (rval != QLA_SUCCESS) {
5445 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5446 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5447 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005448 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5449 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005450 }
5451
5452 return rval;
5453}
5454
5455int
5456qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5457{
5458 int rval;
5459 struct qla_hw_data *ha = vha->hw;
5460 mbx_cmd_t mc;
5461 mbx_cmd_t *mcp = &mc;
5462
5463 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5464 return QLA_FUNCTION_FAILED;
5465
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005466 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5467 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005468
5469 memset(mcp, 0, sizeof(mbx_cmd_t));
5470 mcp->mb[0] = MBC_GET_LED_CONFIG;
5471
5472 mcp->out_mb = MBX_0;
5473 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5474 if (IS_QLA8031(ha))
5475 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5476 mcp->tov = 30;
5477 mcp->flags = 0;
5478
5479 rval = qla2x00_mailbox_command(vha, mcp);
5480 if (rval != QLA_SUCCESS) {
5481 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5482 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5483 } else {
5484 led_cfg[0] = mcp->mb[1];
5485 led_cfg[1] = mcp->mb[2];
5486 if (IS_QLA8031(ha)) {
5487 led_cfg[2] = mcp->mb[3];
5488 led_cfg[3] = mcp->mb[4];
5489 led_cfg[4] = mcp->mb[5];
5490 led_cfg[5] = mcp->mb[6];
5491 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005492 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5493 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005494 }
5495
5496 return rval;
5497}
5498
5499int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005500qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5501{
5502 int rval;
5503 struct qla_hw_data *ha = vha->hw;
5504 mbx_cmd_t mc;
5505 mbx_cmd_t *mcp = &mc;
5506
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005507 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005508 return QLA_FUNCTION_FAILED;
5509
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005510 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005511 "Entered %s.\n", __func__);
5512
5513 memset(mcp, 0, sizeof(mbx_cmd_t));
5514 mcp->mb[0] = MBC_SET_LED_CONFIG;
5515 if (enable)
5516 mcp->mb[7] = 0xE;
5517 else
5518 mcp->mb[7] = 0xD;
5519
5520 mcp->out_mb = MBX_7|MBX_0;
5521 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005522 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005523 mcp->flags = 0;
5524
5525 rval = qla2x00_mailbox_command(vha, mcp);
5526 if (rval != QLA_SUCCESS) {
5527 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5528 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5529 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005530 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005531 "Done %s.\n", __func__);
5532 }
5533
5534 return rval;
5535}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005536
5537int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005538qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005539{
5540 int rval;
5541 struct qla_hw_data *ha = vha->hw;
5542 mbx_cmd_t mc;
5543 mbx_cmd_t *mcp = &mc;
5544
Chad Dupuisf73cb692014-02-26 04:15:06 -05005545 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005546 return QLA_FUNCTION_FAILED;
5547
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005548 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5549 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005550
5551 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5552 mcp->mb[1] = LSW(reg);
5553 mcp->mb[2] = MSW(reg);
5554 mcp->mb[3] = LSW(data);
5555 mcp->mb[4] = MSW(data);
5556 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5557
5558 mcp->in_mb = MBX_1|MBX_0;
5559 mcp->tov = MBX_TOV_SECONDS;
5560 mcp->flags = 0;
5561 rval = qla2x00_mailbox_command(vha, mcp);
5562
5563 if (rval != QLA_SUCCESS) {
5564 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5565 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5566 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005567 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005568 "Done %s.\n", __func__);
5569 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005570
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005571 return rval;
5572}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005573
5574int
5575qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5576{
5577 int rval;
5578 struct qla_hw_data *ha = vha->hw;
5579 mbx_cmd_t mc;
5580 mbx_cmd_t *mcp = &mc;
5581
5582 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005583 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005584 "Implicit LOGO Unsupported.\n");
5585 return QLA_FUNCTION_FAILED;
5586 }
5587
5588
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005589 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5590 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005591
5592 /* Perform Implicit LOGO. */
5593 mcp->mb[0] = MBC_PORT_LOGOUT;
5594 mcp->mb[1] = fcport->loop_id;
5595 mcp->mb[10] = BIT_15;
5596 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5597 mcp->in_mb = MBX_0;
5598 mcp->tov = MBX_TOV_SECONDS;
5599 mcp->flags = 0;
5600 rval = qla2x00_mailbox_command(vha, mcp);
5601 if (rval != QLA_SUCCESS)
5602 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5603 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5604 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005605 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5606 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005607
5608 return rval;
5609}
5610
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005611int
5612qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5613{
5614 int rval;
5615 mbx_cmd_t mc;
5616 mbx_cmd_t *mcp = &mc;
5617 struct qla_hw_data *ha = vha->hw;
5618 unsigned long retry_max_time = jiffies + (2 * HZ);
5619
Chad Dupuisf73cb692014-02-26 04:15:06 -05005620 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005621 return QLA_FUNCTION_FAILED;
5622
5623 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5624
5625retry_rd_reg:
5626 mcp->mb[0] = MBC_READ_REMOTE_REG;
5627 mcp->mb[1] = LSW(reg);
5628 mcp->mb[2] = MSW(reg);
5629 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5630 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5631 mcp->tov = MBX_TOV_SECONDS;
5632 mcp->flags = 0;
5633 rval = qla2x00_mailbox_command(vha, mcp);
5634
5635 if (rval != QLA_SUCCESS) {
5636 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5637 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5638 rval, mcp->mb[0], mcp->mb[1]);
5639 } else {
5640 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5641 if (*data == QLA8XXX_BAD_VALUE) {
5642 /*
5643 * During soft-reset CAMRAM register reads might
5644 * return 0xbad0bad0. So retry for MAX of 2 sec
5645 * while reading camram registers.
5646 */
5647 if (time_after(jiffies, retry_max_time)) {
5648 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5649 "Failure to read CAMRAM register. "
5650 "data=0x%x.\n", *data);
5651 return QLA_FUNCTION_FAILED;
5652 }
5653 msleep(100);
5654 goto retry_rd_reg;
5655 }
5656 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5657 }
5658
5659 return rval;
5660}
5661
5662int
5663qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5664{
5665 int rval;
5666 mbx_cmd_t mc;
5667 mbx_cmd_t *mcp = &mc;
5668 struct qla_hw_data *ha = vha->hw;
5669
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005670 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005671 return QLA_FUNCTION_FAILED;
5672
5673 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5674
5675 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5676 mcp->out_mb = MBX_0;
5677 mcp->in_mb = MBX_1|MBX_0;
5678 mcp->tov = MBX_TOV_SECONDS;
5679 mcp->flags = 0;
5680 rval = qla2x00_mailbox_command(vha, mcp);
5681
5682 if (rval != QLA_SUCCESS) {
5683 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5684 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5685 rval, mcp->mb[0], mcp->mb[1]);
5686 ha->isp_ops->fw_dump(vha, 0);
5687 } else {
5688 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5689 }
5690
5691 return rval;
5692}
5693
5694int
5695qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5696 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5697{
5698 int rval;
5699 mbx_cmd_t mc;
5700 mbx_cmd_t *mcp = &mc;
5701 uint8_t subcode = (uint8_t)options;
5702 struct qla_hw_data *ha = vha->hw;
5703
5704 if (!IS_QLA8031(ha))
5705 return QLA_FUNCTION_FAILED;
5706
5707 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5708
5709 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5710 mcp->mb[1] = options;
5711 mcp->out_mb = MBX_1|MBX_0;
5712 if (subcode & BIT_2) {
5713 mcp->mb[2] = LSW(start_addr);
5714 mcp->mb[3] = MSW(start_addr);
5715 mcp->mb[4] = LSW(end_addr);
5716 mcp->mb[5] = MSW(end_addr);
5717 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5718 }
5719 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5720 if (!(subcode & (BIT_2 | BIT_5)))
5721 mcp->in_mb |= MBX_4|MBX_3;
5722 mcp->tov = MBX_TOV_SECONDS;
5723 mcp->flags = 0;
5724 rval = qla2x00_mailbox_command(vha, mcp);
5725
5726 if (rval != QLA_SUCCESS) {
5727 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5728 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5729 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5730 mcp->mb[4]);
5731 ha->isp_ops->fw_dump(vha, 0);
5732 } else {
5733 if (subcode & BIT_5)
5734 *sector_size = mcp->mb[1];
5735 else if (subcode & (BIT_6 | BIT_7)) {
5736 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5737 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5738 } else if (subcode & (BIT_3 | BIT_4)) {
5739 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5740 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5741 }
5742 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5743 }
5744
5745 return rval;
5746}
Saurav Kashyap81178772012-08-22 14:21:04 -04005747
5748int
5749qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5750 uint32_t size)
5751{
5752 int rval;
5753 mbx_cmd_t mc;
5754 mbx_cmd_t *mcp = &mc;
5755
5756 if (!IS_MCTP_CAPABLE(vha->hw))
5757 return QLA_FUNCTION_FAILED;
5758
5759 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5760 "Entered %s.\n", __func__);
5761
5762 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5763 mcp->mb[1] = LSW(addr);
5764 mcp->mb[2] = MSW(req_dma);
5765 mcp->mb[3] = LSW(req_dma);
5766 mcp->mb[4] = MSW(size);
5767 mcp->mb[5] = LSW(size);
5768 mcp->mb[6] = MSW(MSD(req_dma));
5769 mcp->mb[7] = LSW(MSD(req_dma));
5770 mcp->mb[8] = MSW(addr);
5771 /* Setting RAM ID to valid */
5772 mcp->mb[10] |= BIT_7;
5773 /* For MCTP RAM ID is 0x40 */
5774 mcp->mb[10] |= 0x40;
5775
5776 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5777 MBX_0;
5778
5779 mcp->in_mb = MBX_0;
5780 mcp->tov = MBX_TOV_SECONDS;
5781 mcp->flags = 0;
5782 rval = qla2x00_mailbox_command(vha, mcp);
5783
5784 if (rval != QLA_SUCCESS) {
5785 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5786 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5787 } else {
5788 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5789 "Done %s.\n", __func__);
5790 }
5791
5792 return rval;
5793}
Joe Carnuccioec891462016-07-06 11:14:26 -04005794
5795int
5796qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5797 void *dd_buf, uint size, uint options)
5798{
5799 int rval;
5800 mbx_cmd_t mc;
5801 mbx_cmd_t *mcp = &mc;
5802 dma_addr_t dd_dma;
5803
5804 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5805 return QLA_FUNCTION_FAILED;
5806
Quinn Tran83548fe2017-06-02 09:12:01 -07005807 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04005808 "Entered %s.\n", __func__);
5809
Joe Carnuccioec891462016-07-06 11:14:26 -04005810 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5811 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08005812 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04005813 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5814 return QLA_MEMORY_ALLOC_FAILED;
5815 }
5816
5817 memset(dd_buf, 0, size);
5818
5819 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5820 mcp->mb[1] = options;
5821 mcp->mb[2] = MSW(LSD(dd_dma));
5822 mcp->mb[3] = LSW(LSD(dd_dma));
5823 mcp->mb[6] = MSW(MSD(dd_dma));
5824 mcp->mb[7] = LSW(MSD(dd_dma));
5825 mcp->mb[8] = size;
5826 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5827 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5828 mcp->buf_size = size;
5829 mcp->flags = MBX_DMA_IN;
5830 mcp->tov = MBX_TOV_SECONDS * 4;
5831 rval = qla2x00_mailbox_command(vha, mcp);
5832
5833 if (rval != QLA_SUCCESS) {
5834 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5835 } else {
5836 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5837 "Done %s.\n", __func__);
5838 }
5839
5840 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5841 size, DMA_FROM_DEVICE);
5842
5843 return rval;
5844}
Quinn Tran15f30a52017-03-15 09:48:52 -07005845
5846static void qla2x00_async_mb_sp_done(void *s, int res)
5847{
5848 struct srb *sp = s;
5849
5850 sp->u.iocb_cmd.u.mbx.rc = res;
5851
5852 complete(&sp->u.iocb_cmd.u.mbx.comp);
5853 /* don't free sp here. Let the caller do the free */
5854}
5855
5856/*
5857 * This mailbox uses the iocb interface to send MB command.
5858 * This allows non-critial (non chip setup) command to go
5859 * out in parrallel.
5860 */
5861int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
5862{
5863 int rval = QLA_FUNCTION_FAILED;
5864 srb_t *sp;
5865 struct srb_iocb *c;
5866
5867 if (!vha->hw->flags.fw_started)
5868 goto done;
5869
5870 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
5871 if (!sp)
5872 goto done;
5873
5874 sp->type = SRB_MB_IOCB;
5875 sp->name = mb_to_str(mcp->mb[0]);
5876
5877 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
5878
5879 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
5880
5881 c = &sp->u.iocb_cmd;
5882 c->timeout = qla2x00_async_iocb_timeout;
5883 init_completion(&c->u.mbx.comp);
5884
5885 sp->done = qla2x00_async_mb_sp_done;
5886
5887 rval = qla2x00_start_sp(sp);
5888 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005889 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07005890 "%s: %s Failed submission. %x.\n",
5891 __func__, sp->name, rval);
5892 goto done_free_sp;
5893 }
5894
Quinn Tran83548fe2017-06-02 09:12:01 -07005895 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005896 sp->name, sp->handle);
5897
5898 wait_for_completion(&c->u.mbx.comp);
5899 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
5900
5901 rval = c->u.mbx.rc;
5902 switch (rval) {
5903 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07005904 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005905 __func__, sp->name, rval);
5906 break;
5907 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07005908 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005909 __func__, sp->name);
5910 sp->free(sp);
5911 break;
5912 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07005913 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005914 __func__, sp->name, rval);
5915 sp->free(sp);
5916 break;
5917 }
5918
5919 return rval;
5920
5921done_free_sp:
5922 sp->free(sp);
5923done:
5924 return rval;
5925}
5926
5927/*
5928 * qla24xx_gpdb_wait
5929 * NOTE: Do not call this routine from DPC thread
5930 */
5931int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
5932{
5933 int rval = QLA_FUNCTION_FAILED;
5934 dma_addr_t pd_dma;
5935 struct port_database_24xx *pd;
5936 struct qla_hw_data *ha = vha->hw;
5937 mbx_cmd_t mc;
5938
5939 if (!vha->hw->flags.fw_started)
5940 goto done;
5941
5942 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
5943 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005944 ql_log(ql_log_warn, vha, 0xd047,
5945 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07005946 goto done_free_sp;
5947 }
5948 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
5949
5950 memset(&mc, 0, sizeof(mc));
5951 mc.mb[0] = MBC_GET_PORT_DATABASE;
5952 mc.mb[1] = cpu_to_le16(fcport->loop_id);
5953 mc.mb[2] = MSW(pd_dma);
5954 mc.mb[3] = LSW(pd_dma);
5955 mc.mb[6] = MSW(MSD(pd_dma));
5956 mc.mb[7] = LSW(MSD(pd_dma));
5957 mc.mb[9] = cpu_to_le16(vha->vp_idx);
5958 mc.mb[10] = cpu_to_le16((uint16_t)opt);
5959
5960 rval = qla24xx_send_mb_cmd(vha, &mc);
5961 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005962 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07005963 "%s: %8phC fail\n", __func__, fcport->port_name);
5964 goto done_free_sp;
5965 }
5966
5967 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
5968
Quinn Tran83548fe2017-06-02 09:12:01 -07005969 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005970 __func__, fcport->port_name);
5971
5972done_free_sp:
5973 if (pd)
5974 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
5975done:
5976 return rval;
5977}
5978
5979int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
5980 struct port_database_24xx *pd)
5981{
5982 int rval = QLA_SUCCESS;
5983 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005984 u8 current_login_state, last_login_state;
5985
5986 if (fcport->fc4f_nvme) {
5987 current_login_state = pd->current_login_state >> 4;
5988 last_login_state = pd->last_login_state >> 4;
5989 } else {
5990 current_login_state = pd->current_login_state & 0xf;
5991 last_login_state = pd->last_login_state & 0xf;
5992 }
Quinn Tran15f30a52017-03-15 09:48:52 -07005993
5994 /* Check for logged in state. */
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005995 if (current_login_state != PDS_PRLI_COMPLETE &&
5996 last_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005997 ql_dbg(ql_dbg_mbx, vha, 0x119a,
5998 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07005999 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006000 rval = QLA_FUNCTION_FAILED;
6001 goto gpd_error_out;
6002 }
6003
6004 if (fcport->loop_id == FC_NO_LOOP_ID ||
6005 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6006 memcmp(fcport->port_name, pd->port_name, 8))) {
6007 /* We lost the device mid way. */
6008 rval = QLA_NOT_LOGGED_IN;
6009 goto gpd_error_out;
6010 }
6011
6012 /* Names are little-endian. */
6013 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6014 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6015
6016 /* Get port_id of device. */
6017 fcport->d_id.b.domain = pd->port_id[0];
6018 fcport->d_id.b.area = pd->port_id[1];
6019 fcport->d_id.b.al_pa = pd->port_id[2];
6020 fcport->d_id.b.rsvd_1 = 0;
6021
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006022 if (fcport->fc4f_nvme) {
6023 fcport->nvme_prli_service_param =
6024 pd->prli_nvme_svc_param_word_3;
6025 fcport->port_type = FCT_NVME;
6026 } else {
6027 /* If not target must be initiator or unknown type. */
6028 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6029 fcport->port_type = FCT_INITIATOR;
6030 else
6031 fcport->port_type = FCT_TARGET;
6032 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006033 /* Passback COS information. */
6034 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6035 FC_COS_CLASS2 : FC_COS_CLASS3;
6036
6037 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6038 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6039 fcport->conf_compl_supported = 1;
6040 }
6041
6042gpd_error_out:
6043 return rval;
6044}
6045
6046/*
6047 * qla24xx_gidlist__wait
6048 * NOTE: don't call this routine from DPC thread.
6049 */
6050int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6051 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6052{
6053 int rval = QLA_FUNCTION_FAILED;
6054 mbx_cmd_t mc;
6055
6056 if (!vha->hw->flags.fw_started)
6057 goto done;
6058
6059 memset(&mc, 0, sizeof(mc));
6060 mc.mb[0] = MBC_GET_ID_LIST;
6061 mc.mb[2] = MSW(id_list_dma);
6062 mc.mb[3] = LSW(id_list_dma);
6063 mc.mb[6] = MSW(MSD(id_list_dma));
6064 mc.mb[7] = LSW(MSD(id_list_dma));
6065 mc.mb[8] = 0;
6066 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6067
6068 rval = qla24xx_send_mb_cmd(vha, &mc);
6069 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006070 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6071 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006072 } else {
6073 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006074 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6075 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006076 }
6077done:
6078 return rval;
6079}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006080
6081int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6082{
6083 int rval;
6084 mbx_cmd_t mc;
6085 mbx_cmd_t *mcp = &mc;
6086
6087 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6088 "Entered %s\n", __func__);
6089
6090 memset(mcp->mb, 0 , sizeof(mcp->mb));
6091 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6092 mcp->mb[1] = cpu_to_le16(1);
6093 mcp->mb[2] = cpu_to_le16(value);
6094 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6095 mcp->in_mb = MBX_2 | MBX_0;
6096 mcp->tov = MBX_TOV_SECONDS;
6097 mcp->flags = 0;
6098
6099 rval = qla2x00_mailbox_command(vha, mcp);
6100
6101 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6102 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6103
6104 return rval;
6105}
6106
6107int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6108{
6109 int rval;
6110 mbx_cmd_t mc;
6111 mbx_cmd_t *mcp = &mc;
6112
6113 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6114 "Entered %s\n", __func__);
6115
6116 memset(mcp->mb, 0, sizeof(mcp->mb));
6117 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6118 mcp->mb[1] = cpu_to_le16(0);
6119 mcp->out_mb = MBX_1 | MBX_0;
6120 mcp->in_mb = MBX_2 | MBX_0;
6121 mcp->tov = MBX_TOV_SECONDS;
6122 mcp->flags = 0;
6123
6124 rval = qla2x00_mailbox_command(vha, mcp);
6125 if (rval == QLA_SUCCESS)
6126 *value = mc.mb[2];
6127
6128 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6129 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6130
6131 return rval;
6132}