blob: f02a2baffb5b4953809d472fb44753f7607fd416 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563/*
564 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700565 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 *
567 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700568 * ha = adapter block pointer.
569 * TARGET_QUEUE_LOCK must be released.
570 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 *
572 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700573 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 *
575 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700576 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 */
578int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800579qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580{
581 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800582 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 mbx_cmd_t mc;
584 mbx_cmd_t *mcp = &mc;
585
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400586 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
587 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700590 mcp->out_mb = MBX_0;
591 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700592 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700593 mcp->mb[1] = MSW(risc_addr);
594 mcp->mb[2] = LSW(risc_addr);
595 mcp->mb[3] = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500596 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
597 IS_QLA27XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700598 struct nvram_81xx *nv = ha->nvram;
599 mcp->mb[4] = (nv->enhanced_features &
600 EXTENDED_BB_CREDITS);
601 } else
602 mcp->mb[4] = 0;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500603
604 if (ha->flags.exlogins_enabled)
605 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
606
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500607 if (ha->flags.exchoffld_enabled)
608 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
609
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700610 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700611 mcp->in_mb |= MBX_1;
612 } else {
613 mcp->mb[1] = LSW(risc_addr);
614 mcp->out_mb |= MBX_1;
615 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
616 mcp->mb[2] = 0;
617 mcp->out_mb |= MBX_2;
618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 }
620
Ravi Anandb93480e2008-04-03 13:13:25 -0700621 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800623 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700625 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700626 ql_dbg(ql_dbg_mbx, vha, 0x1026,
627 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700628 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700629 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400630 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700631 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700632 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400633 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
634 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700635 }
636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
638 return rval;
639}
640
641/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500642 * qla_get_exlogin_status
643 * Get extended login status
644 * uses the memory offload control/status Mailbox
645 *
646 * Input:
647 * ha: adapter state pointer.
648 * fwopt: firmware options
649 *
650 * Returns:
651 * qla2x00 local function status
652 *
653 * Context:
654 * Kernel context.
655 */
656#define FETCH_XLOGINS_STAT 0x8
657int
658qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
659 uint16_t *ex_logins_cnt)
660{
661 int rval;
662 mbx_cmd_t mc;
663 mbx_cmd_t *mcp = &mc;
664
665 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
666 "Entered %s\n", __func__);
667
668 memset(mcp->mb, 0 , sizeof(mcp->mb));
669 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
670 mcp->mb[1] = FETCH_XLOGINS_STAT;
671 mcp->out_mb = MBX_1|MBX_0;
672 mcp->in_mb = MBX_10|MBX_4|MBX_0;
673 mcp->tov = MBX_TOV_SECONDS;
674 mcp->flags = 0;
675
676 rval = qla2x00_mailbox_command(vha, mcp);
677 if (rval != QLA_SUCCESS) {
678 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
679 } else {
680 *buf_sz = mcp->mb[4];
681 *ex_logins_cnt = mcp->mb[10];
682
683 ql_log(ql_log_info, vha, 0x1190,
684 "buffer size 0x%x, exchange login count=%d\n",
685 mcp->mb[4], mcp->mb[10]);
686
687 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
688 "Done %s.\n", __func__);
689 }
690
691 return rval;
692}
693
694/*
695 * qla_set_exlogin_mem_cfg
696 * set extended login memory configuration
697 * Mbx needs to be issues before init_cb is set
698 *
699 * Input:
700 * ha: adapter state pointer.
701 * buffer: buffer pointer
702 * phys_addr: physical address of buffer
703 * size: size of buffer
704 * TARGET_QUEUE_LOCK must be released
705 * ADAPTER_STATE_LOCK must be release
706 *
707 * Returns:
708 * qla2x00 local funxtion status code.
709 *
710 * Context:
711 * Kernel context.
712 */
713#define CONFIG_XLOGINS_MEM 0x3
714int
715qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
716{
717 int rval;
718 mbx_cmd_t mc;
719 mbx_cmd_t *mcp = &mc;
720 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500721
722 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
723 "Entered %s.\n", __func__);
724
725 memset(mcp->mb, 0 , sizeof(mcp->mb));
726 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
727 mcp->mb[1] = CONFIG_XLOGINS_MEM;
728 mcp->mb[2] = MSW(phys_addr);
729 mcp->mb[3] = LSW(phys_addr);
730 mcp->mb[6] = MSW(MSD(phys_addr));
731 mcp->mb[7] = LSW(MSD(phys_addr));
732 mcp->mb[8] = MSW(ha->exlogin_size);
733 mcp->mb[9] = LSW(ha->exlogin_size);
734 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
735 mcp->in_mb = MBX_11|MBX_0;
736 mcp->tov = MBX_TOV_SECONDS;
737 mcp->flags = 0;
738 rval = qla2x00_mailbox_command(vha, mcp);
739 if (rval != QLA_SUCCESS) {
740 /*EMPTY*/
741 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
742 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500743 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
744 "Done %s.\n", __func__);
745 }
746
747 return rval;
748}
749
750/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500751 * qla_get_exchoffld_status
752 * Get exchange offload status
753 * uses the memory offload control/status Mailbox
754 *
755 * Input:
756 * ha: adapter state pointer.
757 * fwopt: firmware options
758 *
759 * Returns:
760 * qla2x00 local function status
761 *
762 * Context:
763 * Kernel context.
764 */
765#define FETCH_XCHOFFLD_STAT 0x2
766int
767qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
768 uint16_t *ex_logins_cnt)
769{
770 int rval;
771 mbx_cmd_t mc;
772 mbx_cmd_t *mcp = &mc;
773
774 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
775 "Entered %s\n", __func__);
776
777 memset(mcp->mb, 0 , sizeof(mcp->mb));
778 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
779 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
780 mcp->out_mb = MBX_1|MBX_0;
781 mcp->in_mb = MBX_10|MBX_4|MBX_0;
782 mcp->tov = MBX_TOV_SECONDS;
783 mcp->flags = 0;
784
785 rval = qla2x00_mailbox_command(vha, mcp);
786 if (rval != QLA_SUCCESS) {
787 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
788 } else {
789 *buf_sz = mcp->mb[4];
790 *ex_logins_cnt = mcp->mb[10];
791
792 ql_log(ql_log_info, vha, 0x118e,
793 "buffer size 0x%x, exchange offload count=%d\n",
794 mcp->mb[4], mcp->mb[10]);
795
796 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
797 "Done %s.\n", __func__);
798 }
799
800 return rval;
801}
802
803/*
804 * qla_set_exchoffld_mem_cfg
805 * Set exchange offload memory configuration
806 * Mbx needs to be issues before init_cb is set
807 *
808 * Input:
809 * ha: adapter state pointer.
810 * buffer: buffer pointer
811 * phys_addr: physical address of buffer
812 * size: size of buffer
813 * TARGET_QUEUE_LOCK must be released
814 * ADAPTER_STATE_LOCK must be release
815 *
816 * Returns:
817 * qla2x00 local funxtion status code.
818 *
819 * Context:
820 * Kernel context.
821 */
822#define CONFIG_XCHOFFLD_MEM 0x3
823int
Quinn Tran99e1b682017-06-02 09:12:03 -0700824qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500825{
826 int rval;
827 mbx_cmd_t mc;
828 mbx_cmd_t *mcp = &mc;
829 struct qla_hw_data *ha = vha->hw;
830
831 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
832 "Entered %s.\n", __func__);
833
834 memset(mcp->mb, 0 , sizeof(mcp->mb));
835 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
836 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -0700837 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
838 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
839 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
840 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
841 mcp->mb[8] = MSW(ha->exchoffld_size);
842 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500843 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
844 mcp->in_mb = MBX_11|MBX_0;
845 mcp->tov = MBX_TOV_SECONDS;
846 mcp->flags = 0;
847 rval = qla2x00_mailbox_command(vha, mcp);
848 if (rval != QLA_SUCCESS) {
849 /*EMPTY*/
850 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
851 } else {
852 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
853 "Done %s.\n", __func__);
854 }
855
856 return rval;
857}
858
859/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 * qla2x00_get_fw_version
861 * Get firmware version.
862 *
863 * Input:
864 * ha: adapter state pointer.
865 * major: pointer for major number.
866 * minor: pointer for minor number.
867 * subminor: pointer for subminor number.
868 *
869 * Returns:
870 * qla2x00 local function return status code.
871 *
872 * Context:
873 * Kernel context.
874 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700875int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800876qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 int rval;
879 mbx_cmd_t mc;
880 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800881 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400883 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
884 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
886 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
887 mcp->out_mb = MBX_0;
888 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400889 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700890 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400891 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800892 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500893 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400894 mcp->in_mb |=
895 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
896 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -0400897
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700899 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800900 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700901 if (rval != QLA_SUCCESS)
902 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800905 ha->fw_major_version = mcp->mb[1];
906 ha->fw_minor_version = mcp->mb[2];
907 ha->fw_subminor_version = mcp->mb[3];
908 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800909 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800910 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800912 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -0400913
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400914 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800915 ha->mpi_version[0] = mcp->mb[10] & 0xff;
916 ha->mpi_version[1] = mcp->mb[11] >> 8;
917 ha->mpi_version[2] = mcp->mb[11] & 0xff;
918 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
919 ha->phy_version[0] = mcp->mb[8] & 0xff;
920 ha->phy_version[1] = mcp->mb[9] >> 8;
921 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800922 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400923
Saurav Kashyap81178772012-08-22 14:21:04 -0400924 if (IS_FWI2_CAPABLE(ha)) {
925 ha->fw_attributes_h = mcp->mb[15];
926 ha->fw_attributes_ext[0] = mcp->mb[16];
927 ha->fw_attributes_ext[1] = mcp->mb[17];
928 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
929 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
930 __func__, mcp->mb[15], mcp->mb[6]);
931 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
932 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
933 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500934
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500935 if (ha->fw_attributes_h & 0x4)
936 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
937 "%s: Firmware supports Extended Login 0x%x\n",
938 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500939
940 if (ha->fw_attributes_h & 0x8)
941 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
942 "%s: Firmware supports Exchange Offload 0x%x\n",
943 __func__, ha->fw_attributes_h);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800944 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400945
Chad Dupuisf73cb692014-02-26 04:15:06 -0500946 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -0400947 ha->mpi_version[0] = mcp->mb[10] & 0xff;
948 ha->mpi_version[1] = mcp->mb[11] >> 8;
949 ha->mpi_version[2] = mcp->mb[11] & 0xff;
950 ha->pep_version[0] = mcp->mb[13] & 0xff;
951 ha->pep_version[1] = mcp->mb[14] >> 8;
952 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500953 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
954 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400955 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
956 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -0500957 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800958
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700959failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 if (rval != QLA_SUCCESS) {
961 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700962 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 } else {
964 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400965 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
966 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700968 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}
970
971/*
972 * qla2x00_get_fw_options
973 * Set firmware options.
974 *
975 * Input:
976 * ha = adapter block pointer.
977 * fwopt = pointer for firmware options.
978 *
979 * Returns:
980 * qla2x00 local function return status code.
981 *
982 * Context:
983 * Kernel context.
984 */
985int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800986qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987{
988 int rval;
989 mbx_cmd_t mc;
990 mbx_cmd_t *mcp = &mc;
991
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400992 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
993 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
995 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
996 mcp->out_mb = MBX_0;
997 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700998 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001000 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 if (rval != QLA_SUCCESS) {
1003 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001004 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001006 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 fwopts[1] = mcp->mb[1];
1008 fwopts[2] = mcp->mb[2];
1009 fwopts[3] = mcp->mb[3];
1010
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001011 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1012 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 }
1014
1015 return rval;
1016}
1017
1018
1019/*
1020 * qla2x00_set_fw_options
1021 * Set firmware options.
1022 *
1023 * Input:
1024 * ha = adapter block pointer.
1025 * fwopt = pointer for firmware options.
1026 *
1027 * Returns:
1028 * qla2x00 local function return status code.
1029 *
1030 * Context:
1031 * Kernel context.
1032 */
1033int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001034qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
1036 int rval;
1037 mbx_cmd_t mc;
1038 mbx_cmd_t *mcp = &mc;
1039
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001040 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1041 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1044 mcp->mb[1] = fwopts[1];
1045 mcp->mb[2] = fwopts[2];
1046 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001047 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001049 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001050 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001051 mcp->mb[10] = fwopts[10];
1052 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001053 } else {
1054 mcp->mb[10] = fwopts[10];
1055 mcp->mb[11] = fwopts[11];
1056 mcp->mb[12] = 0; /* Undocumented, but used */
1057 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1058 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001059 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001061 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001063 fwopts[0] = mcp->mb[0];
1064
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 if (rval != QLA_SUCCESS) {
1066 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001067 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1068 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 } else {
1070 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001071 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1072 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 }
1074
1075 return rval;
1076}
1077
1078/*
1079 * qla2x00_mbx_reg_test
1080 * Mailbox register wrap test.
1081 *
1082 * Input:
1083 * ha = adapter block pointer.
1084 * TARGET_QUEUE_LOCK must be released.
1085 * ADAPTER_STATE_LOCK must be released.
1086 *
1087 * Returns:
1088 * qla2x00 local function return status code.
1089 *
1090 * Context:
1091 * Kernel context.
1092 */
1093int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001094qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
1096 int rval;
1097 mbx_cmd_t mc;
1098 mbx_cmd_t *mcp = &mc;
1099
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001100 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1101 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1104 mcp->mb[1] = 0xAAAA;
1105 mcp->mb[2] = 0x5555;
1106 mcp->mb[3] = 0xAA55;
1107 mcp->mb[4] = 0x55AA;
1108 mcp->mb[5] = 0xA5A5;
1109 mcp->mb[6] = 0x5A5A;
1110 mcp->mb[7] = 0x2525;
1111 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1112 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 -07001113 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001115 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 if (rval == QLA_SUCCESS) {
1118 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1119 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1120 rval = QLA_FUNCTION_FAILED;
1121 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1122 mcp->mb[7] != 0x2525)
1123 rval = QLA_FUNCTION_FAILED;
1124 }
1125
1126 if (rval != QLA_SUCCESS) {
1127 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001128 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 } else {
1130 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001131 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1132 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 }
1134
1135 return rval;
1136}
1137
1138/*
1139 * qla2x00_verify_checksum
1140 * Verify firmware checksum.
1141 *
1142 * Input:
1143 * ha = adapter block pointer.
1144 * TARGET_QUEUE_LOCK must be released.
1145 * ADAPTER_STATE_LOCK must be released.
1146 *
1147 * Returns:
1148 * qla2x00 local function return status code.
1149 *
1150 * Context:
1151 * Kernel context.
1152 */
1153int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001154qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155{
1156 int rval;
1157 mbx_cmd_t mc;
1158 mbx_cmd_t *mcp = &mc;
1159
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1161 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001164 mcp->out_mb = MBX_0;
1165 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001166 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001167 mcp->mb[1] = MSW(risc_addr);
1168 mcp->mb[2] = LSW(risc_addr);
1169 mcp->out_mb |= MBX_2|MBX_1;
1170 mcp->in_mb |= MBX_2|MBX_1;
1171 } else {
1172 mcp->mb[1] = LSW(risc_addr);
1173 mcp->out_mb |= MBX_1;
1174 mcp->in_mb |= MBX_1;
1175 }
1176
Ravi Anandb93480e2008-04-03 13:13:25 -07001177 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001179 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001182 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1183 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1184 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001186 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1187 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
1189
1190 return rval;
1191}
1192
1193/*
1194 * qla2x00_issue_iocb
1195 * Issue IOCB using mailbox command
1196 *
1197 * Input:
1198 * ha = adapter state pointer.
1199 * buffer = buffer pointer.
1200 * phys_addr = physical address of buffer.
1201 * size = size of buffer.
1202 * TARGET_QUEUE_LOCK must be released.
1203 * ADAPTER_STATE_LOCK must be released.
1204 *
1205 * Returns:
1206 * qla2x00 local function return status code.
1207 *
1208 * Context:
1209 * Kernel context.
1210 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001211int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001212qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001213 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
1215 int rval;
1216 mbx_cmd_t mc;
1217 mbx_cmd_t *mcp = &mc;
1218
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001219 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1220 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001221
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1223 mcp->mb[1] = 0;
1224 mcp->mb[2] = MSW(phys_addr);
1225 mcp->mb[3] = LSW(phys_addr);
1226 mcp->mb[6] = MSW(MSD(phys_addr));
1227 mcp->mb[7] = LSW(MSD(phys_addr));
1228 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1229 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001230 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001232 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 if (rval != QLA_SUCCESS) {
1235 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001236 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001238 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1239
1240 /* Mask reserved bits. */
1241 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001242 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001243 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1244 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 }
1246
1247 return rval;
1248}
1249
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001250int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001251qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001252 size_t size)
1253{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001254 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001255 MBX_TOV_SECONDS);
1256}
1257
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258/*
1259 * qla2x00_abort_command
1260 * Abort command aborts a specified IOCB.
1261 *
1262 * Input:
1263 * ha = adapter block pointer.
1264 * sp = SB structure pointer.
1265 *
1266 * Returns:
1267 * qla2x00 local function return status code.
1268 *
1269 * Context:
1270 * Kernel context.
1271 */
1272int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001273qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
1275 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001277 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 mbx_cmd_t mc;
1279 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001280 fc_port_t *fcport = sp->fcport;
1281 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001282 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001283 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001284 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001286 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1287 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
Michael Hernandezd7459522016-12-12 14:40:07 -08001289 if (vha->flags.qpairs_available && sp->qpair)
1290 req = sp->qpair->req;
1291 else
1292 req = vha->req;
1293
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001294 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001295 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001296 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 break;
1298 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001299 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Chad Dupuis8d93f552013-01-30 03:34:37 -05001301 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 /* command not found */
1303 return QLA_FUNCTION_FAILED;
1304 }
1305
1306 mcp->mb[0] = MBC_ABORT_COMMAND;
1307 if (HAS_EXTENDED_IDS(ha))
1308 mcp->mb[1] = fcport->loop_id;
1309 else
1310 mcp->mb[1] = fcport->loop_id << 8;
1311 mcp->mb[2] = (uint16_t)handle;
1312 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001313 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1315 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001316 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001318 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001321 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001323 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1324 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 }
1326
1327 return rval;
1328}
1329
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001331qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001333 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 mbx_cmd_t mc;
1335 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001336 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001337 struct req_que *req;
1338 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
Andrew Vasquez523ec772008-04-03 13:13:24 -07001340 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001341 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001342
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001343 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1344 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001345
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001346 req = vha->hw->req_q_map[0];
1347 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001349 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001350 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 mcp->mb[1] = fcport->loop_id;
1352 mcp->mb[10] = 0;
1353 mcp->out_mb |= MBX_10;
1354 } else {
1355 mcp->mb[1] = fcport->loop_id << 8;
1356 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001357 mcp->mb[2] = vha->hw->loop_reset_delay;
1358 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001361 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001363 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001365 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1366 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001367 }
1368
1369 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001370 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1371 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001372 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001373 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1374 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001376 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1377 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001378 }
1379
1380 return rval;
1381}
1382
1383int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001384qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001385{
1386 int rval, rval2;
1387 mbx_cmd_t mc;
1388 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001389 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001390 struct req_que *req;
1391 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001392
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001393 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001394
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001395 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1396 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001397
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001398 req = vha->hw->req_q_map[0];
1399 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001400 mcp->mb[0] = MBC_LUN_RESET;
1401 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001402 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001403 mcp->mb[1] = fcport->loop_id;
1404 else
1405 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001406 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001407 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001408 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001409
1410 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001411 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001412 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001413 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001414 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001415 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001416 }
1417
1418 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001419 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1420 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001421 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001422 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1423 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001424 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001425 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1426 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 }
1428
1429 return rval;
1430}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431
1432/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 * qla2x00_get_adapter_id
1434 * Get adapter ID and topology.
1435 *
1436 * Input:
1437 * ha = adapter block pointer.
1438 * id = pointer for loop ID.
1439 * al_pa = pointer for AL_PA.
1440 * area = pointer for area.
1441 * domain = pointer for domain.
1442 * top = pointer for topology.
1443 * TARGET_QUEUE_LOCK must be released.
1444 * ADAPTER_STATE_LOCK must be released.
1445 *
1446 * Returns:
1447 * qla2x00 local function return status code.
1448 *
1449 * Context:
1450 * Kernel context.
1451 */
1452int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001453qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001454 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
1456 int rval;
1457 mbx_cmd_t mc;
1458 mbx_cmd_t *mcp = &mc;
1459
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001460 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1461 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001464 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001465 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001466 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001467 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001468 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001469 if (IS_FWI2_CAPABLE(vha->hw))
1470 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001471 if (IS_QLA27XX(vha->hw))
1472 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001473 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001475 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001476 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1477 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001478 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1479 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 /* Return data. */
1482 *id = mcp->mb[1];
1483 *al_pa = LSB(mcp->mb[2]);
1484 *area = MSB(mcp->mb[2]);
1485 *domain = LSB(mcp->mb[3]);
1486 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001487 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 if (rval != QLA_SUCCESS) {
1490 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001491 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001493 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1494 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001495
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001496 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001497 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1498 vha->fcoe_fcf_idx = mcp->mb[10];
1499 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1500 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1501 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1502 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1503 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1504 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1505 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001506 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001507 if (IS_FAWWN_CAPABLE(vha->hw)) {
1508 if (mcp->mb[7] & BIT_14) {
1509 vha->port_name[0] = MSB(mcp->mb[16]);
1510 vha->port_name[1] = LSB(mcp->mb[16]);
1511 vha->port_name[2] = MSB(mcp->mb[17]);
1512 vha->port_name[3] = LSB(mcp->mb[17]);
1513 vha->port_name[4] = MSB(mcp->mb[18]);
1514 vha->port_name[5] = LSB(mcp->mb[18]);
1515 vha->port_name[6] = MSB(mcp->mb[19]);
1516 vha->port_name[7] = LSB(mcp->mb[19]);
1517 fc_host_port_name(vha->host) =
1518 wwn_to_u64(vha->port_name);
1519 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1520 "FA-WWN acquired %016llx\n",
1521 wwn_to_u64(vha->port_name));
1522 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001523 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001524
1525 if (IS_QLA27XX(vha->hw))
1526 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 }
1528
1529 return rval;
1530}
1531
1532/*
1533 * qla2x00_get_retry_cnt
1534 * Get current firmware login retry count and delay.
1535 *
1536 * Input:
1537 * ha = adapter block pointer.
1538 * retry_cnt = pointer to login retry count.
1539 * tov = pointer to login timeout value.
1540 *
1541 * Returns:
1542 * qla2x00 local function return status code.
1543 *
1544 * Context:
1545 * Kernel context.
1546 */
1547int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001548qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 uint16_t *r_a_tov)
1550{
1551 int rval;
1552 uint16_t ratov;
1553 mbx_cmd_t mc;
1554 mbx_cmd_t *mcp = &mc;
1555
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001556 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1557 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1560 mcp->out_mb = MBX_0;
1561 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001562 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001564 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 if (rval != QLA_SUCCESS) {
1567 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001568 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1569 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 } else {
1571 /* Convert returned data and check our values. */
1572 *r_a_tov = mcp->mb[3] / 2;
1573 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1574 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1575 /* Update to the larger values */
1576 *retry_cnt = (uint8_t)mcp->mb[1];
1577 *tov = ratov;
1578 }
1579
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001581 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 }
1583
1584 return rval;
1585}
1586
1587/*
1588 * qla2x00_init_firmware
1589 * Initialize adapter firmware.
1590 *
1591 * Input:
1592 * ha = adapter block pointer.
1593 * dptr = Initialization control block pointer.
1594 * size = size of initialization control block.
1595 * TARGET_QUEUE_LOCK must be released.
1596 * ADAPTER_STATE_LOCK must be released.
1597 *
1598 * Returns:
1599 * qla2x00 local function return status code.
1600 *
1601 * Context:
1602 * Kernel context.
1603 */
1604int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001605qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606{
1607 int rval;
1608 mbx_cmd_t mc;
1609 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001610 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001612 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1613 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001615 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001616 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001617 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1618
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001619 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001620 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1621 else
1622 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1623
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001624 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 mcp->mb[2] = MSW(ha->init_cb_dma);
1626 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1628 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001629 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001630 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001631 mcp->mb[1] = BIT_0;
1632 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1633 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1634 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1635 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1636 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1637 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1638 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001639 /* 1 and 2 should normally be captured. */
1640 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001641 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001642 /* mb3 is additional info about the installed SFP. */
1643 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 mcp->buf_size = size;
1645 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001646 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001647 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
1649 if (rval != QLA_SUCCESS) {
1650 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001651 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001652 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1653 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 } else {
1655 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001656 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1657 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 }
1659
1660 return rval;
1661}
1662
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001663
1664/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 * qla2x00_get_port_database
1666 * Issue normal/enhanced get port database mailbox command
1667 * and copy device name as necessary.
1668 *
1669 * Input:
1670 * ha = adapter state pointer.
1671 * dev = structure pointer.
1672 * opt = enhanced cmd option byte.
1673 *
1674 * Returns:
1675 * qla2x00 local function return status code.
1676 *
1677 * Context:
1678 * Kernel context.
1679 */
1680int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001681qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682{
1683 int rval;
1684 mbx_cmd_t mc;
1685 mbx_cmd_t *mcp = &mc;
1686 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001687 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001689 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001691 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1692 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001694 pd24 = NULL;
1695 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001697 ql_log(ql_log_warn, vha, 0x1050,
1698 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 return QLA_MEMORY_ALLOC_FAILED;
1700 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001701 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001703 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001704 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 mcp->mb[2] = MSW(pd_dma);
1707 mcp->mb[3] = LSW(pd_dma);
1708 mcp->mb[6] = MSW(MSD(pd_dma));
1709 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001710 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001711 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001713 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001714 mcp->mb[1] = fcport->loop_id;
1715 mcp->mb[10] = opt;
1716 mcp->out_mb |= MBX_10|MBX_1;
1717 mcp->in_mb |= MBX_1;
1718 } else if (HAS_EXTENDED_IDS(ha)) {
1719 mcp->mb[1] = fcport->loop_id;
1720 mcp->mb[10] = opt;
1721 mcp->out_mb |= MBX_10|MBX_1;
1722 } else {
1723 mcp->mb[1] = fcport->loop_id << 8 | opt;
1724 mcp->out_mb |= MBX_1;
1725 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001726 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1727 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 mcp->flags = MBX_DMA_IN;
1729 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001730 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 if (rval != QLA_SUCCESS)
1732 goto gpd_error_out;
1733
Andrew Vasqueze4289242007-07-19 15:05:56 -07001734 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001735 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001736 pd24 = (struct port_database_24xx *) pd;
1737
1738 /* Check for logged in state. */
1739 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1740 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001741 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1742 "Unable to verify login-state (%x/%x) for "
1743 "loop_id %x.\n", pd24->current_login_state,
1744 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001745 rval = QLA_FUNCTION_FAILED;
1746 goto gpd_error_out;
1747 }
1748
Arun Easi0eba25d2012-02-09 11:15:58 -08001749 if (fcport->loop_id == FC_NO_LOOP_ID ||
1750 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1751 memcmp(fcport->port_name, pd24->port_name, 8))) {
1752 /* We lost the device mid way. */
1753 rval = QLA_NOT_LOGGED_IN;
1754 goto gpd_error_out;
1755 }
1756
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001757 /* Names are little-endian. */
1758 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1759 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1760
1761 /* Get port_id of device. */
1762 fcport->d_id.b.domain = pd24->port_id[0];
1763 fcport->d_id.b.area = pd24->port_id[1];
1764 fcport->d_id.b.al_pa = pd24->port_id[2];
1765 fcport->d_id.b.rsvd_1 = 0;
1766
1767 /* If not target must be initiator or unknown type. */
1768 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1769 fcport->port_type = FCT_INITIATOR;
1770 else
1771 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001772
1773 /* Passback COS information. */
1774 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1775 FC_COS_CLASS2 : FC_COS_CLASS3;
1776
1777 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1778 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001779 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001780 uint64_t zero = 0;
1781
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001782 /* Check for logged in state. */
1783 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1784 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001785 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1786 "Unable to verify login-state (%x/%x) - "
1787 "portid=%02x%02x%02x.\n", pd->master_state,
1788 pd->slave_state, fcport->d_id.b.domain,
1789 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001790 rval = QLA_FUNCTION_FAILED;
1791 goto gpd_error_out;
1792 }
1793
Arun Easi0eba25d2012-02-09 11:15:58 -08001794 if (fcport->loop_id == FC_NO_LOOP_ID ||
1795 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1796 memcmp(fcport->port_name, pd->port_name, 8))) {
1797 /* We lost the device mid way. */
1798 rval = QLA_NOT_LOGGED_IN;
1799 goto gpd_error_out;
1800 }
1801
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001802 /* Names are little-endian. */
1803 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1804 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1805
1806 /* Get port_id of device. */
1807 fcport->d_id.b.domain = pd->port_id[0];
1808 fcport->d_id.b.area = pd->port_id[3];
1809 fcport->d_id.b.al_pa = pd->port_id[2];
1810 fcport->d_id.b.rsvd_1 = 0;
1811
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001812 /* If not target must be initiator or unknown type. */
1813 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1814 fcport->port_type = FCT_INITIATOR;
1815 else
1816 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001817
1818 /* Passback COS information. */
1819 fcport->supported_classes = (pd->options & BIT_4) ?
1820 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 }
1822
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823gpd_error_out:
1824 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1825
1826 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001827 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1828 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1829 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001831 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1832 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 }
1834
1835 return rval;
1836}
1837
1838/*
1839 * qla2x00_get_firmware_state
1840 * Get adapter firmware state.
1841 *
1842 * Input:
1843 * ha = adapter block pointer.
1844 * dptr = pointer for firmware state.
1845 * TARGET_QUEUE_LOCK must be released.
1846 * ADAPTER_STATE_LOCK must be released.
1847 *
1848 * Returns:
1849 * qla2x00 local function return status code.
1850 *
1851 * Context:
1852 * Kernel context.
1853 */
1854int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001855qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
1857 int rval;
1858 mbx_cmd_t mc;
1859 mbx_cmd_t *mcp = &mc;
1860
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001861 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1862 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863
1864 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1865 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001866 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001867 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001868 else
1869 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001870 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001872 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001874 /* Return firmware states. */
1875 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001876 if (IS_FWI2_CAPABLE(vha->hw)) {
1877 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04001878 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001879 states[3] = mcp->mb[4];
1880 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001881 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001882 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 if (rval != QLA_SUCCESS) {
1885 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001886 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 } else {
1888 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001889 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1890 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 }
1892
1893 return rval;
1894}
1895
1896/*
1897 * qla2x00_get_port_name
1898 * Issue get port name mailbox command.
1899 * Returned name is in big endian format.
1900 *
1901 * Input:
1902 * ha = adapter block pointer.
1903 * loop_id = loop ID of device.
1904 * name = pointer for name.
1905 * TARGET_QUEUE_LOCK must be released.
1906 * ADAPTER_STATE_LOCK must be released.
1907 *
1908 * Returns:
1909 * qla2x00 local function return status code.
1910 *
1911 * Context:
1912 * Kernel context.
1913 */
1914int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001915qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 uint8_t opt)
1917{
1918 int rval;
1919 mbx_cmd_t mc;
1920 mbx_cmd_t *mcp = &mc;
1921
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001922 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1923 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
1925 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001926 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001927 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001928 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 mcp->mb[1] = loop_id;
1930 mcp->mb[10] = opt;
1931 mcp->out_mb |= MBX_10;
1932 } else {
1933 mcp->mb[1] = loop_id << 8 | opt;
1934 }
1935
1936 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001937 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001939 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
1941 if (rval != QLA_SUCCESS) {
1942 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001943 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 } else {
1945 if (name != NULL) {
1946 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001947 name[0] = MSB(mcp->mb[2]);
1948 name[1] = LSB(mcp->mb[2]);
1949 name[2] = MSB(mcp->mb[3]);
1950 name[3] = LSB(mcp->mb[3]);
1951 name[4] = MSB(mcp->mb[6]);
1952 name[5] = LSB(mcp->mb[6]);
1953 name[6] = MSB(mcp->mb[7]);
1954 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 }
1956
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001957 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1958 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
1960
1961 return rval;
1962}
1963
1964/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001965 * qla24xx_link_initialization
1966 * Issue link initialization mailbox command.
1967 *
1968 * Input:
1969 * ha = adapter block pointer.
1970 * TARGET_QUEUE_LOCK must be released.
1971 * ADAPTER_STATE_LOCK must be released.
1972 *
1973 * Returns:
1974 * qla2x00 local function return status code.
1975 *
1976 * Context:
1977 * Kernel context.
1978 */
1979int
1980qla24xx_link_initialize(scsi_qla_host_t *vha)
1981{
1982 int rval;
1983 mbx_cmd_t mc;
1984 mbx_cmd_t *mcp = &mc;
1985
1986 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
1987 "Entered %s.\n", __func__);
1988
1989 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
1990 return QLA_FUNCTION_FAILED;
1991
1992 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04001993 mcp->mb[1] = BIT_4;
1994 if (vha->hw->operating_mode == LOOP)
1995 mcp->mb[1] |= BIT_6;
1996 else
1997 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001998 mcp->mb[2] = 0;
1999 mcp->mb[3] = 0;
2000 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2001 mcp->in_mb = MBX_0;
2002 mcp->tov = MBX_TOV_SECONDS;
2003 mcp->flags = 0;
2004 rval = qla2x00_mailbox_command(vha, mcp);
2005
2006 if (rval != QLA_SUCCESS) {
2007 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2008 } else {
2009 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2010 "Done %s.\n", __func__);
2011 }
2012
2013 return rval;
2014}
2015
2016/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 * qla2x00_lip_reset
2018 * Issue LIP reset mailbox command.
2019 *
2020 * Input:
2021 * ha = adapter block pointer.
2022 * TARGET_QUEUE_LOCK must be released.
2023 * ADAPTER_STATE_LOCK must be released.
2024 *
2025 * Returns:
2026 * qla2x00 local function return status code.
2027 *
2028 * Context:
2029 * Kernel context.
2030 */
2031int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002032qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033{
2034 int rval;
2035 mbx_cmd_t mc;
2036 mbx_cmd_t *mcp = &mc;
2037
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002038 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2039 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002041 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002042 /* Logout across all FCFs. */
2043 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2044 mcp->mb[1] = BIT_1;
2045 mcp->mb[2] = 0;
2046 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2047 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002048 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002049 mcp->mb[1] = BIT_6;
2050 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002051 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002052 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002054 mcp->mb[0] = MBC_LIP_RESET;
2055 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002056 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002057 mcp->mb[1] = 0x00ff;
2058 mcp->mb[10] = 0;
2059 mcp->out_mb |= MBX_10;
2060 } else {
2061 mcp->mb[1] = 0xff00;
2062 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002063 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002064 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002067 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002069 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
2071 if (rval != QLA_SUCCESS) {
2072 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002073 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 } else {
2075 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002076 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2077 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 }
2079
2080 return rval;
2081}
2082
2083/*
2084 * qla2x00_send_sns
2085 * Send SNS command.
2086 *
2087 * Input:
2088 * ha = adapter block pointer.
2089 * sns = pointer for command.
2090 * cmd_size = command size.
2091 * buf_size = response/command size.
2092 * TARGET_QUEUE_LOCK must be released.
2093 * ADAPTER_STATE_LOCK must be released.
2094 *
2095 * Returns:
2096 * qla2x00 local function return status code.
2097 *
2098 * Context:
2099 * Kernel context.
2100 */
2101int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002102qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 uint16_t cmd_size, size_t buf_size)
2104{
2105 int rval;
2106 mbx_cmd_t mc;
2107 mbx_cmd_t *mcp = &mc;
2108
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002109 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2110 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002112 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002113 "Retry cnt=%d ratov=%d total tov=%d.\n",
2114 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2117 mcp->mb[1] = cmd_size;
2118 mcp->mb[2] = MSW(sns_phys_address);
2119 mcp->mb[3] = LSW(sns_phys_address);
2120 mcp->mb[6] = MSW(MSD(sns_phys_address));
2121 mcp->mb[7] = LSW(MSD(sns_phys_address));
2122 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2123 mcp->in_mb = MBX_0|MBX_1;
2124 mcp->buf_size = buf_size;
2125 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002126 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2127 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128
2129 if (rval != QLA_SUCCESS) {
2130 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002131 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2132 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2133 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 } else {
2135 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002136 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2137 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 }
2139
2140 return rval;
2141}
2142
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002143int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002144qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002145 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2146{
2147 int rval;
2148
2149 struct logio_entry_24xx *lg;
2150 dma_addr_t lg_dma;
2151 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002152 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002153 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002154
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002155 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2156 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002157
Michael Hernandezd7459522016-12-12 14:40:07 -08002158 if (vha->vp_idx && vha->qpair)
2159 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002160 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002161 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002162
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002163 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2164 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002165 ql_log(ql_log_warn, vha, 0x1062,
2166 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002167 return QLA_MEMORY_ALLOC_FAILED;
2168 }
2169 memset(lg, 0, sizeof(struct logio_entry_24xx));
2170
2171 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2172 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002173 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002174 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002175 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002176 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002177 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002178 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002179 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002180 lg->port_id[0] = al_pa;
2181 lg->port_id[1] = area;
2182 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002183 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002184 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2185 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002186 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002187 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2188 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002189 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002190 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2191 "Failed to complete IOCB -- error status (%x).\n",
2192 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002193 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002194 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002195 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2196 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2197
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002198 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2199 "Failed to complete IOCB -- completion status (%x) "
2200 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2201 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002202
2203 switch (iop[0]) {
2204 case LSC_SCODE_PORTID_USED:
2205 mb[0] = MBS_PORT_ID_USED;
2206 mb[1] = LSW(iop[1]);
2207 break;
2208 case LSC_SCODE_NPORT_USED:
2209 mb[0] = MBS_LOOP_ID_USED;
2210 break;
2211 case LSC_SCODE_NOLINK:
2212 case LSC_SCODE_NOIOCB:
2213 case LSC_SCODE_NOXCB:
2214 case LSC_SCODE_CMD_FAILED:
2215 case LSC_SCODE_NOFABRIC:
2216 case LSC_SCODE_FW_NOT_READY:
2217 case LSC_SCODE_NOT_LOGGED_IN:
2218 case LSC_SCODE_NOPCB:
2219 case LSC_SCODE_ELS_REJECT:
2220 case LSC_SCODE_CMD_PARAM_ERR:
2221 case LSC_SCODE_NONPORT:
2222 case LSC_SCODE_LOGGED_IN:
2223 case LSC_SCODE_NOFLOGI_ACC:
2224 default:
2225 mb[0] = MBS_COMMAND_ERROR;
2226 break;
2227 }
2228 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002229 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2230 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002231
2232 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2233
2234 mb[0] = MBS_COMMAND_COMPLETE;
2235 mb[1] = 0;
2236 if (iop[0] & BIT_4) {
2237 if (iop[0] & BIT_8)
2238 mb[1] |= BIT_1;
2239 } else
2240 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002241
2242 /* Passback COS information. */
2243 mb[10] = 0;
2244 if (lg->io_parameter[7] || lg->io_parameter[8])
2245 mb[10] |= BIT_0; /* Class 2. */
2246 if (lg->io_parameter[9] || lg->io_parameter[10])
2247 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002248 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002249 mb[10] |= BIT_7; /* Confirmed Completion
2250 * Allowed
2251 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002252 }
2253
2254 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2255
2256 return rval;
2257}
2258
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259/*
2260 * qla2x00_login_fabric
2261 * Issue login fabric port mailbox command.
2262 *
2263 * Input:
2264 * ha = adapter block pointer.
2265 * loop_id = device loop ID.
2266 * domain = device domain.
2267 * area = device area.
2268 * al_pa = device AL_PA.
2269 * status = pointer for return status.
2270 * opt = command options.
2271 * TARGET_QUEUE_LOCK must be released.
2272 * ADAPTER_STATE_LOCK must be released.
2273 *
2274 * Returns:
2275 * qla2x00 local function return status code.
2276 *
2277 * Context:
2278 * Kernel context.
2279 */
2280int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002281qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2283{
2284 int rval;
2285 mbx_cmd_t mc;
2286 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002287 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002289 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2290 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2293 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2294 if (HAS_EXTENDED_IDS(ha)) {
2295 mcp->mb[1] = loop_id;
2296 mcp->mb[10] = opt;
2297 mcp->out_mb |= MBX_10;
2298 } else {
2299 mcp->mb[1] = (loop_id << 8) | opt;
2300 }
2301 mcp->mb[2] = domain;
2302 mcp->mb[3] = area << 8 | al_pa;
2303
2304 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2305 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2306 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002307 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
2309 /* Return mailbox statuses. */
2310 if (mb != NULL) {
2311 mb[0] = mcp->mb[0];
2312 mb[1] = mcp->mb[1];
2313 mb[2] = mcp->mb[2];
2314 mb[6] = mcp->mb[6];
2315 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002316 /* COS retrieved from Get-Port-Database mailbox command. */
2317 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
2319
2320 if (rval != QLA_SUCCESS) {
2321 /* RLU tmp code: need to change main mailbox_command function to
2322 * return ok even when the mailbox completion value is not
2323 * SUCCESS. The caller needs to be responsible to interpret
2324 * the return values of this mailbox command if we're not
2325 * to change too much of the existing code.
2326 */
2327 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2328 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2329 mcp->mb[0] == 0x4006)
2330 rval = QLA_SUCCESS;
2331
2332 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002333 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2334 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2335 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 } else {
2337 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2339 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 }
2341
2342 return rval;
2343}
2344
2345/*
2346 * qla2x00_login_local_device
2347 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002348 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 * Input:
2350 * ha = adapter block pointer.
2351 * loop_id = device loop ID.
2352 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002353 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 * Returns:
2355 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002356 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 * Context:
2358 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002359 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 */
2361int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002362qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 uint16_t *mb_ret, uint8_t opt)
2364{
2365 int rval;
2366 mbx_cmd_t mc;
2367 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002368 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002370 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2371 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002372
Andrew Vasqueze4289242007-07-19 15:05:56 -07002373 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002374 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002375 fcport->d_id.b.domain, fcport->d_id.b.area,
2376 fcport->d_id.b.al_pa, mb_ret, opt);
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2379 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002380 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002382 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 mcp->mb[2] = opt;
2384 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2385 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2386 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2387 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002388 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
2390 /* Return mailbox statuses. */
2391 if (mb_ret != NULL) {
2392 mb_ret[0] = mcp->mb[0];
2393 mb_ret[1] = mcp->mb[1];
2394 mb_ret[6] = mcp->mb[6];
2395 mb_ret[7] = mcp->mb[7];
2396 }
2397
2398 if (rval != QLA_SUCCESS) {
2399 /* AV tmp code: need to change main mailbox_command function to
2400 * return ok even when the mailbox completion value is not
2401 * SUCCESS. The caller needs to be responsible to interpret
2402 * the return values of this mailbox command if we're not
2403 * to change too much of the existing code.
2404 */
2405 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2406 rval = QLA_SUCCESS;
2407
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002408 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2409 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2410 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 } else {
2412 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002413 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2414 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 }
2416
2417 return (rval);
2418}
2419
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002420int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002421qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002422 uint8_t area, uint8_t al_pa)
2423{
2424 int rval;
2425 struct logio_entry_24xx *lg;
2426 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002427 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002428 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002429
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002430 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2431 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002432
2433 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2434 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002435 ql_log(ql_log_warn, vha, 0x106e,
2436 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002437 return QLA_MEMORY_ALLOC_FAILED;
2438 }
2439 memset(lg, 0, sizeof(struct logio_entry_24xx));
2440
Michael Hernandezd7459522016-12-12 14:40:07 -08002441 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002442 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2443 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002444 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002445 lg->nport_handle = cpu_to_le16(loop_id);
2446 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002447 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002448 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002449 lg->port_id[0] = al_pa;
2450 lg->port_id[1] = area;
2451 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002452 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002453 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2454 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002455 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002456 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2457 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002458 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002459 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2460 "Failed to complete IOCB -- error status (%x).\n",
2461 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002462 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002463 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002464 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2465 "Failed to complete IOCB -- completion status (%x) "
2466 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002467 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002468 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002469 } else {
2470 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002471 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2472 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002473 }
2474
2475 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2476
2477 return rval;
2478}
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/*
2481 * qla2x00_fabric_logout
2482 * Issue logout fabric port mailbox command.
2483 *
2484 * Input:
2485 * ha = adapter block pointer.
2486 * loop_id = device loop ID.
2487 * TARGET_QUEUE_LOCK must be released.
2488 * ADAPTER_STATE_LOCK must be released.
2489 *
2490 * Returns:
2491 * qla2x00 local function return status code.
2492 *
2493 * Context:
2494 * Kernel context.
2495 */
2496int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002497qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002498 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499{
2500 int rval;
2501 mbx_cmd_t mc;
2502 mbx_cmd_t *mcp = &mc;
2503
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002504 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2505 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
2507 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2508 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002509 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 mcp->mb[1] = loop_id;
2511 mcp->mb[10] = 0;
2512 mcp->out_mb |= MBX_10;
2513 } else {
2514 mcp->mb[1] = loop_id << 8;
2515 }
2516
2517 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002518 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002520 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
2522 if (rval != QLA_SUCCESS) {
2523 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002524 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2525 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 } else {
2527 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002528 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2529 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 }
2531
2532 return rval;
2533}
2534
2535/*
2536 * qla2x00_full_login_lip
2537 * Issue full login LIP mailbox command.
2538 *
2539 * Input:
2540 * ha = adapter block pointer.
2541 * TARGET_QUEUE_LOCK must be released.
2542 * ADAPTER_STATE_LOCK must be released.
2543 *
2544 * Returns:
2545 * qla2x00 local function return status code.
2546 *
2547 * Context:
2548 * Kernel context.
2549 */
2550int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002551qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
2553 int rval;
2554 mbx_cmd_t mc;
2555 mbx_cmd_t *mcp = &mc;
2556
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002557 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2558 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559
2560 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002561 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002562 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 mcp->mb[3] = 0;
2564 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2565 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002566 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002568 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
2570 if (rval != QLA_SUCCESS) {
2571 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002572 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 } else {
2574 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002575 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2576 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 }
2578
2579 return rval;
2580}
2581
2582/*
2583 * qla2x00_get_id_list
2584 *
2585 * Input:
2586 * ha = adapter block pointer.
2587 *
2588 * Returns:
2589 * qla2x00 local function return status code.
2590 *
2591 * Context:
2592 * Kernel context.
2593 */
2594int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002595qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 uint16_t *entries)
2597{
2598 int rval;
2599 mbx_cmd_t mc;
2600 mbx_cmd_t *mcp = &mc;
2601
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002602 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2603 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604
2605 if (id_list == NULL)
2606 return QLA_FUNCTION_FAILED;
2607
2608 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002609 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002610 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002611 mcp->mb[2] = MSW(id_list_dma);
2612 mcp->mb[3] = LSW(id_list_dma);
2613 mcp->mb[6] = MSW(MSD(id_list_dma));
2614 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002615 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002616 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002617 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002618 } else {
2619 mcp->mb[1] = MSW(id_list_dma);
2620 mcp->mb[2] = LSW(id_list_dma);
2621 mcp->mb[3] = MSW(MSD(id_list_dma));
2622 mcp->mb[6] = LSW(MSD(id_list_dma));
2623 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2624 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002626 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002628 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
2630 if (rval != QLA_SUCCESS) {
2631 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002632 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 } else {
2634 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002635 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2636 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 }
2638
2639 return rval;
2640}
2641
2642/*
2643 * qla2x00_get_resource_cnts
2644 * Get current firmware resource counts.
2645 *
2646 * Input:
2647 * ha = adapter block pointer.
2648 *
2649 * Returns:
2650 * qla2x00 local function return status code.
2651 *
2652 * Context:
2653 * Kernel context.
2654 */
2655int
Quinn Tran03e8c682015-12-17 14:56:59 -05002656qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657{
Quinn Tran03e8c682015-12-17 14:56:59 -05002658 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 int rval;
2660 mbx_cmd_t mc;
2661 mbx_cmd_t *mcp = &mc;
2662
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002663 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2664 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665
2666 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2667 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002668 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 -05002669 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002670 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002671 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002673 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674
2675 if (rval != QLA_SUCCESS) {
2676 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002677 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2678 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002680 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002681 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2682 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2683 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2684 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685
Quinn Tran03e8c682015-12-17 14:56:59 -05002686 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2687 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2688 ha->cur_fw_xcb_count = mcp->mb[3];
2689 ha->orig_fw_xcb_count = mcp->mb[6];
2690 ha->cur_fw_iocb_count = mcp->mb[7];
2691 ha->orig_fw_iocb_count = mcp->mb[10];
2692 if (ha->flags.npiv_supported)
2693 ha->max_npiv_vports = mcp->mb[11];
2694 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2695 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 }
2697
2698 return (rval);
2699}
2700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701/*
2702 * qla2x00_get_fcal_position_map
2703 * Get FCAL (LILP) position map using mailbox command
2704 *
2705 * Input:
2706 * ha = adapter state pointer.
2707 * pos_map = buffer pointer (can be NULL).
2708 *
2709 * Returns:
2710 * qla2x00 local function return status code.
2711 *
2712 * Context:
2713 * Kernel context.
2714 */
2715int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002716qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717{
2718 int rval;
2719 mbx_cmd_t mc;
2720 mbx_cmd_t *mcp = &mc;
2721 char *pmap;
2722 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002723 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002725 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2726 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002727
Andrew Vasquez4b892582008-09-11 21:22:48 -07002728 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002730 ql_log(ql_log_warn, vha, 0x1080,
2731 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 return QLA_MEMORY_ALLOC_FAILED;
2733 }
2734 memset(pmap, 0, FCAL_MAP_SIZE);
2735
2736 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2737 mcp->mb[2] = MSW(pmap_dma);
2738 mcp->mb[3] = LSW(pmap_dma);
2739 mcp->mb[6] = MSW(MSD(pmap_dma));
2740 mcp->mb[7] = LSW(MSD(pmap_dma));
2741 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2742 mcp->in_mb = MBX_1|MBX_0;
2743 mcp->buf_size = FCAL_MAP_SIZE;
2744 mcp->flags = MBX_DMA_IN;
2745 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002746 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002749 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002750 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2751 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2752 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2753 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754
2755 if (pos_map)
2756 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2757 }
2758 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2759
2760 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002761 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002763 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2764 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 }
2766
2767 return rval;
2768}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002769
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002770/*
2771 * qla2x00_get_link_status
2772 *
2773 * Input:
2774 * ha = adapter block pointer.
2775 * loop_id = device loop ID.
2776 * ret_buf = pointer to link status return buffer.
2777 *
2778 * Returns:
2779 * 0 = success.
2780 * BIT_0 = mem alloc error.
2781 * BIT_1 = mailbox error.
2782 */
2783int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002784qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002785 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002786{
2787 int rval;
2788 mbx_cmd_t mc;
2789 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002790 uint32_t *iter = (void *)stats;
2791 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002792 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002793
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002794 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2795 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002796
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002797 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002798 mcp->mb[2] = MSW(LSD(stats_dma));
2799 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002800 mcp->mb[6] = MSW(MSD(stats_dma));
2801 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002802 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2803 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002804 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002805 mcp->mb[1] = loop_id;
2806 mcp->mb[4] = 0;
2807 mcp->mb[10] = 0;
2808 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2809 mcp->in_mb |= MBX_1;
2810 } else if (HAS_EXTENDED_IDS(ha)) {
2811 mcp->mb[1] = loop_id;
2812 mcp->mb[10] = 0;
2813 mcp->out_mb |= MBX_10|MBX_1;
2814 } else {
2815 mcp->mb[1] = loop_id << 8;
2816 mcp->out_mb |= MBX_1;
2817 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002818 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002819 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002820 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002821
2822 if (rval == QLA_SUCCESS) {
2823 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002824 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2825 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002826 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002827 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002828 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2830 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002831 for ( ; dwords--; iter++)
2832 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002833 }
2834 } else {
2835 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002836 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002837 }
2838
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002839 return rval;
2840}
2841
2842int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002843qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07002844 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002845{
2846 int rval;
2847 mbx_cmd_t mc;
2848 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002849 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002850
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002851 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2852 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002853
Quinn Tran15f30a52017-03-15 09:48:52 -07002854 memset(&mc, 0, sizeof(mc));
2855 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
2856 mc.mb[2] = MSW(stats_dma);
2857 mc.mb[3] = LSW(stats_dma);
2858 mc.mb[6] = MSW(MSD(stats_dma));
2859 mc.mb[7] = LSW(MSD(stats_dma));
2860 mc.mb[8] = sizeof(struct link_statistics) / 4;
2861 mc.mb[9] = cpu_to_le16(vha->vp_idx);
2862 mc.mb[10] = cpu_to_le16(options);
2863
2864 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002865
2866 if (rval == QLA_SUCCESS) {
2867 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002868 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2869 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002870 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002871 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002872 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2873 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002874 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002875 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002876 iter = &stats->link_fail_cnt;
2877 for ( ; dwords--; iter++)
2878 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002879 }
2880 } else {
2881 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002882 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002883 }
2884
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002885 return rval;
2886}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002887
2888int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002889qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002890{
2891 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002892 unsigned long flags = 0;
2893
2894 struct abort_entry_24xx *abt;
2895 dma_addr_t abt_dma;
2896 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002897 fc_port_t *fcport = sp->fcport;
2898 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002899 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002900 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002901
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002902 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2903 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002904
Michael Hernandezd7459522016-12-12 14:40:07 -08002905 if (vha->flags.qpairs_available && sp->qpair)
2906 req = sp->qpair->req;
2907
Armen Baloyan4440e462014-02-26 04:15:18 -05002908 if (ql2xasynctmfenable)
2909 return qla24xx_async_abort_command(sp);
2910
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002911 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002912 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002913 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002914 break;
2915 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002916 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002917 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002918 /* Command not found. */
2919 return QLA_FUNCTION_FAILED;
2920 }
2921
2922 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2923 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002924 ql_log(ql_log_warn, vha, 0x108d,
2925 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002926 return QLA_MEMORY_ALLOC_FAILED;
2927 }
2928 memset(abt, 0, sizeof(struct abort_entry_24xx));
2929
2930 abt->entry_type = ABORT_IOCB_TYPE;
2931 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002932 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002933 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002934 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002935 abt->port_id[0] = fcport->d_id.b.al_pa;
2936 abt->port_id[1] = fcport->d_id.b.area;
2937 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002938 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002939
2940 abt->req_que_no = cpu_to_le16(req->id);
2941
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002942 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002943 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002944 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2945 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002946 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002947 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2948 "Failed to complete IOCB -- error status (%x).\n",
2949 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002950 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002951 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002952 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2953 "Failed to complete IOCB -- completion status (%x).\n",
2954 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04002955 if (abt->nport_handle == CS_IOCB_ERROR)
2956 rval = QLA_FUNCTION_PARAMETER_ERROR;
2957 else
2958 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002959 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002960 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2961 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002962 }
2963
2964 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2965
2966 return rval;
2967}
2968
2969struct tsk_mgmt_cmd {
2970 union {
2971 struct tsk_mgmt_entry tsk;
2972 struct sts_entry_24xx sts;
2973 } p;
2974};
2975
Andrew Vasquez523ec772008-04-03 13:13:24 -07002976static int
2977__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02002978 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002979{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002980 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002981 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002982 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002983 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002984 scsi_qla_host_t *vha;
2985 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002986 struct req_que *req;
2987 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08002988 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002989
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002990 vha = fcport->vha;
2991 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002992 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002993
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002994 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
2995 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002996
Michael Hernandezd7459522016-12-12 14:40:07 -08002997 if (vha->vp_idx && vha->qpair) {
2998 /* NPIV port */
2999 qpair = vha->qpair;
3000 rsp = qpair->rsp;
3001 req = qpair->req;
3002 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003003 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003004 }
3005
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003006 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003007 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003008 ql_log(ql_log_warn, vha, 0x1093,
3009 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003010 return QLA_MEMORY_ALLOC_FAILED;
3011 }
3012 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
3013
3014 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3015 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003016 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003017 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003018 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003019 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003020 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3021 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3022 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003023 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003024 if (type == TCF_LUN_RESET) {
3025 int_to_scsilun(l, &tsk->p.tsk.lun);
3026 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3027 sizeof(tsk->p.tsk.lun));
3028 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003029
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003030 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003031 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003032 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003033 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3034 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003035 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003036 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3037 "Failed to complete IOCB -- error status (%x).\n",
3038 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003039 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003040 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003041 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3042 "Failed to complete IOCB -- completion status (%x).\n",
3043 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003044 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003045 } else if (le16_to_cpu(sts->scsi_status) &
3046 SS_RESPONSE_INFO_LEN_VALID) {
3047 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003048 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003049 "Ignoring inconsistent data length -- not enough "
3050 "response info (%d).\n",
3051 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003052 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003053 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3054 "Failed to complete IOCB -- response (%x).\n",
3055 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003056 rval = QLA_FUNCTION_FAILED;
3057 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003058 }
3059
3060 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003061 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003062 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3063 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003064 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3065 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003066 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003067 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3068 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003069 }
3070
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003071 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003072
3073 return rval;
3074}
3075
Andrew Vasquez523ec772008-04-03 13:13:24 -07003076int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003077qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003078{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003079 struct qla_hw_data *ha = fcport->vha->hw;
3080
3081 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3082 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3083
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003084 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003085}
3086
3087int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003088qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003089{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003090 struct qla_hw_data *ha = fcport->vha->hw;
3091
3092 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3093 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3094
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003095 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003096}
3097
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003098int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003099qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003100{
3101 int rval;
3102 mbx_cmd_t mc;
3103 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003104 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003105
Andrew Vasquez68af0812008-05-12 22:21:13 -07003106 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003107 return QLA_FUNCTION_FAILED;
3108
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003109 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3110 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003111
3112 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3113 mcp->out_mb = MBX_0;
3114 mcp->in_mb = MBX_0;
3115 mcp->tov = 5;
3116 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003117 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003118
3119 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003120 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003121 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003122 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3123 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003124 }
3125
3126 return rval;
3127}
3128
Joe Carnucciodb64e932013-10-30 03:38:18 -04003129int
3130qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3131{
3132 int rval;
3133 mbx_cmd_t mc;
3134 mbx_cmd_t *mcp = &mc;
3135
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003136 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3137 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003138 return QLA_FUNCTION_FAILED;
3139
3140 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3141 "Entered %s.\n", __func__);
3142
3143 mcp->mb[0] = MBC_WRITE_SERDES;
3144 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003145 if (IS_QLA2031(vha->hw))
3146 mcp->mb[2] = data & 0xff;
3147 else
3148 mcp->mb[2] = data;
3149
Joe Carnucciodb64e932013-10-30 03:38:18 -04003150 mcp->mb[3] = 0;
3151 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3152 mcp->in_mb = MBX_0;
3153 mcp->tov = MBX_TOV_SECONDS;
3154 mcp->flags = 0;
3155 rval = qla2x00_mailbox_command(vha, mcp);
3156
3157 if (rval != QLA_SUCCESS) {
3158 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3159 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3160 } else {
3161 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3162 "Done %s.\n", __func__);
3163 }
3164
3165 return rval;
3166}
3167
3168int
3169qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3170{
3171 int rval;
3172 mbx_cmd_t mc;
3173 mbx_cmd_t *mcp = &mc;
3174
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003175 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3176 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003177 return QLA_FUNCTION_FAILED;
3178
3179 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3180 "Entered %s.\n", __func__);
3181
3182 mcp->mb[0] = MBC_READ_SERDES;
3183 mcp->mb[1] = addr;
3184 mcp->mb[3] = 0;
3185 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3186 mcp->in_mb = MBX_1|MBX_0;
3187 mcp->tov = MBX_TOV_SECONDS;
3188 mcp->flags = 0;
3189 rval = qla2x00_mailbox_command(vha, mcp);
3190
Andrew Vasquez064135e2015-04-09 15:00:02 -04003191 if (IS_QLA2031(vha->hw))
3192 *data = mcp->mb[1] & 0xff;
3193 else
3194 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003195
3196 if (rval != QLA_SUCCESS) {
3197 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3198 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3199 } else {
3200 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3201 "Done %s.\n", __func__);
3202 }
3203
3204 return rval;
3205}
3206
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003207int
3208qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3209{
3210 int rval;
3211 mbx_cmd_t mc;
3212 mbx_cmd_t *mcp = &mc;
3213
3214 if (!IS_QLA8044(vha->hw))
3215 return QLA_FUNCTION_FAILED;
3216
Quinn Tran83548fe2017-06-02 09:12:01 -07003217 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003218 "Entered %s.\n", __func__);
3219
3220 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3221 mcp->mb[1] = HCS_WRITE_SERDES;
3222 mcp->mb[3] = LSW(addr);
3223 mcp->mb[4] = MSW(addr);
3224 mcp->mb[5] = LSW(data);
3225 mcp->mb[6] = MSW(data);
3226 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3227 mcp->in_mb = MBX_0;
3228 mcp->tov = MBX_TOV_SECONDS;
3229 mcp->flags = 0;
3230 rval = qla2x00_mailbox_command(vha, mcp);
3231
3232 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003233 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003234 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3235 } else {
3236 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3237 "Done %s.\n", __func__);
3238 }
3239
3240 return rval;
3241}
3242
3243int
3244qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3245{
3246 int rval;
3247 mbx_cmd_t mc;
3248 mbx_cmd_t *mcp = &mc;
3249
3250 if (!IS_QLA8044(vha->hw))
3251 return QLA_FUNCTION_FAILED;
3252
3253 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3254 "Entered %s.\n", __func__);
3255
3256 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3257 mcp->mb[1] = HCS_READ_SERDES;
3258 mcp->mb[3] = LSW(addr);
3259 mcp->mb[4] = MSW(addr);
3260 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3261 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3262 mcp->tov = MBX_TOV_SECONDS;
3263 mcp->flags = 0;
3264 rval = qla2x00_mailbox_command(vha, mcp);
3265
3266 *data = mcp->mb[2] << 16 | mcp->mb[1];
3267
3268 if (rval != QLA_SUCCESS) {
3269 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3270 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3271 } else {
3272 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3273 "Done %s.\n", __func__);
3274 }
3275
3276 return rval;
3277}
3278
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003279/**
3280 * qla2x00_set_serdes_params() -
3281 * @ha: HA context
3282 *
3283 * Returns
3284 */
3285int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003286qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003287 uint16_t sw_em_2g, uint16_t sw_em_4g)
3288{
3289 int rval;
3290 mbx_cmd_t mc;
3291 mbx_cmd_t *mcp = &mc;
3292
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003293 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3294 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003295
3296 mcp->mb[0] = MBC_SERDES_PARAMS;
3297 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003298 mcp->mb[2] = sw_em_1g | BIT_15;
3299 mcp->mb[3] = sw_em_2g | BIT_15;
3300 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003301 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3302 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003303 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003304 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003305 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003306
3307 if (rval != QLA_SUCCESS) {
3308 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003309 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3310 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003311 } else {
3312 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003313 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3314 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003315 }
3316
3317 return rval;
3318}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003319
3320int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003321qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003322{
3323 int rval;
3324 mbx_cmd_t mc;
3325 mbx_cmd_t *mcp = &mc;
3326
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003327 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003328 return QLA_FUNCTION_FAILED;
3329
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003330 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3331 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003332
3333 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003334 mcp->mb[1] = 0;
3335 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003336 mcp->in_mb = MBX_0;
3337 mcp->tov = 5;
3338 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003339 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003340
3341 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003342 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003343 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3344 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003345 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003346 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3347 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003348 }
3349
3350 return rval;
3351}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003352
3353int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003354qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003355 uint16_t buffers)
3356{
3357 int rval;
3358 mbx_cmd_t mc;
3359 mbx_cmd_t *mcp = &mc;
3360
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003361 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3362 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003363
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003364 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003365 return QLA_FUNCTION_FAILED;
3366
Andrew Vasquez85880802009-12-15 21:29:46 -08003367 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3368 return QLA_FUNCTION_FAILED;
3369
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003370 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003371 mcp->mb[1] = TC_EFT_ENABLE;
3372 mcp->mb[2] = LSW(eft_dma);
3373 mcp->mb[3] = MSW(eft_dma);
3374 mcp->mb[4] = LSW(MSD(eft_dma));
3375 mcp->mb[5] = MSW(MSD(eft_dma));
3376 mcp->mb[6] = buffers;
3377 mcp->mb[7] = TC_AEN_DISABLE;
3378 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 -07003379 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003380 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003381 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003382 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003383 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003384 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3385 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3386 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003387 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003388 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3389 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003390 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003391
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003392 return rval;
3393}
3394
3395int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003396qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003397{
3398 int rval;
3399 mbx_cmd_t mc;
3400 mbx_cmd_t *mcp = &mc;
3401
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003402 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3403 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003404
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003405 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003406 return QLA_FUNCTION_FAILED;
3407
Andrew Vasquez85880802009-12-15 21:29:46 -08003408 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3409 return QLA_FUNCTION_FAILED;
3410
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003411 mcp->mb[0] = MBC_TRACE_CONTROL;
3412 mcp->mb[1] = TC_EFT_DISABLE;
3413 mcp->out_mb = MBX_1|MBX_0;
3414 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003415 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003416 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003417 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003418 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003419 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3420 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3421 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003422 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003423 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3424 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003425 }
3426
3427 return rval;
3428}
3429
Andrew Vasquez88729e52006-06-23 16:10:50 -07003430int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003431qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003432 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3433{
3434 int rval;
3435 mbx_cmd_t mc;
3436 mbx_cmd_t *mcp = &mc;
3437
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003438 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3439 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003441 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003442 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003443 return QLA_FUNCTION_FAILED;
3444
Andrew Vasquez85880802009-12-15 21:29:46 -08003445 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3446 return QLA_FUNCTION_FAILED;
3447
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003448 mcp->mb[0] = MBC_TRACE_CONTROL;
3449 mcp->mb[1] = TC_FCE_ENABLE;
3450 mcp->mb[2] = LSW(fce_dma);
3451 mcp->mb[3] = MSW(fce_dma);
3452 mcp->mb[4] = LSW(MSD(fce_dma));
3453 mcp->mb[5] = MSW(MSD(fce_dma));
3454 mcp->mb[6] = buffers;
3455 mcp->mb[7] = TC_AEN_DISABLE;
3456 mcp->mb[8] = 0;
3457 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3458 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3459 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3460 MBX_1|MBX_0;
3461 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003462 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003463 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003464 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003465 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003466 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3467 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3468 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003469 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3471 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003472
3473 if (mb)
3474 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3475 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003476 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003477 }
3478
3479 return rval;
3480}
3481
3482int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003483qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003484{
3485 int rval;
3486 mbx_cmd_t mc;
3487 mbx_cmd_t *mcp = &mc;
3488
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003489 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3490 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003491
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003492 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003493 return QLA_FUNCTION_FAILED;
3494
Andrew Vasquez85880802009-12-15 21:29:46 -08003495 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3496 return QLA_FUNCTION_FAILED;
3497
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003498 mcp->mb[0] = MBC_TRACE_CONTROL;
3499 mcp->mb[1] = TC_FCE_DISABLE;
3500 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3501 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3502 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3503 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003504 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003505 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003506 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003507 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003508 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3509 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3510 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003511 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003512 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3513 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003514
3515 if (wr)
3516 *wr = (uint64_t) mcp->mb[5] << 48 |
3517 (uint64_t) mcp->mb[4] << 32 |
3518 (uint64_t) mcp->mb[3] << 16 |
3519 (uint64_t) mcp->mb[2];
3520 if (rd)
3521 *rd = (uint64_t) mcp->mb[9] << 48 |
3522 (uint64_t) mcp->mb[8] << 32 |
3523 (uint64_t) mcp->mb[7] << 16 |
3524 (uint64_t) mcp->mb[6];
3525 }
3526
3527 return rval;
3528}
3529
3530int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003531qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3532 uint16_t *port_speed, uint16_t *mb)
3533{
3534 int rval;
3535 mbx_cmd_t mc;
3536 mbx_cmd_t *mcp = &mc;
3537
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003538 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3539 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003540
Giridhar Malavali6e980162010-03-19 17:03:58 -07003541 if (!IS_IIDMA_CAPABLE(vha->hw))
3542 return QLA_FUNCTION_FAILED;
3543
Giridhar Malavali6e980162010-03-19 17:03:58 -07003544 mcp->mb[0] = MBC_PORT_PARAMS;
3545 mcp->mb[1] = loop_id;
3546 mcp->mb[2] = mcp->mb[3] = 0;
3547 mcp->mb[9] = vha->vp_idx;
3548 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3549 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3550 mcp->tov = MBX_TOV_SECONDS;
3551 mcp->flags = 0;
3552 rval = qla2x00_mailbox_command(vha, mcp);
3553
3554 /* Return mailbox statuses. */
3555 if (mb != NULL) {
3556 mb[0] = mcp->mb[0];
3557 mb[1] = mcp->mb[1];
3558 mb[3] = mcp->mb[3];
3559 }
3560
3561 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003562 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003563 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003564 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3565 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003566 if (port_speed)
3567 *port_speed = mcp->mb[3];
3568 }
3569
3570 return rval;
3571}
3572
3573int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003574qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003575 uint16_t port_speed, uint16_t *mb)
3576{
3577 int rval;
3578 mbx_cmd_t mc;
3579 mbx_cmd_t *mcp = &mc;
3580
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003581 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3582 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003583
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003584 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003585 return QLA_FUNCTION_FAILED;
3586
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003587 mcp->mb[0] = MBC_PORT_PARAMS;
3588 mcp->mb[1] = loop_id;
3589 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003590 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003591 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3592 else
3593 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3594 mcp->mb[9] = vha->vp_idx;
3595 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3596 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003597 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003598 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003599 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003600
3601 /* Return mailbox statuses. */
3602 if (mb != NULL) {
3603 mb[0] = mcp->mb[0];
3604 mb[1] = mcp->mb[1];
3605 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003606 }
3607
3608 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003609 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3610 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003611 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003612 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3613 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003614 }
3615
3616 return rval;
3617}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003618
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003619void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003620qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003621 struct vp_rpt_id_entry_24xx *rptid_entry)
3622{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003623 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003624 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003625 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003626 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003627 port_id_t id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003628
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003629 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3630 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003631
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003632 if (rptid_entry->entry_status != 0)
3633 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003634
Quinn Tran482c9dc2017-03-15 09:48:54 -07003635 id.b.domain = rptid_entry->port_id[2];
3636 id.b.area = rptid_entry->port_id[1];
3637 id.b.al_pa = rptid_entry->port_id[0];
3638 id.b.rsvd_1 = 0;
3639
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003640 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003641 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003642 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003643 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003644 "VPs acquired %d.\n", rptid_entry->vp_setup,
3645 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003646 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003647 "Primary port id %02x%02x%02x.\n",
3648 rptid_entry->port_id[2], rptid_entry->port_id[1],
3649 rptid_entry->port_id[0]);
Quinn Tran41dc5292017-01-19 22:28:03 -08003650
Quinn Tran482c9dc2017-03-15 09:48:54 -07003651 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003652
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003653 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003654 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003655 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003656 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003657 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3658 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003659 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003660 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003661
Sawan Chandak969a6192016-01-27 12:03:32 -05003662 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003663 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003664
Quinn Tran41dc5292017-01-19 22:28:03 -08003665 if (rptid_entry->vp_idx == 0) {
3666 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3667 /* FA-WWN is only for physical port */
3668 if (qla_ini_mode_enabled(vha) &&
3669 ha->flags.fawwpn_enabled &&
3670 (rptid_entry->u.f1.flags &
3671 VP_FLAGS_NAME_VALID)) {
3672 memcpy(vha->port_name,
3673 rptid_entry->u.f1.port_name,
3674 WWN_SIZE);
3675 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003676
Quinn Tran482c9dc2017-03-15 09:48:54 -07003677 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003678 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003679
Quinn Tran41dc5292017-01-19 22:28:03 -08003680 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3681 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3682 } else {
3683 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3684 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3685 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3686 "Could not acquire ID for VP[%d].\n",
3687 rptid_entry->vp_idx);
3688 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003689 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003690
3691 found = 0;
3692 spin_lock_irqsave(&ha->vport_slock, flags);
3693 list_for_each_entry(vp, &ha->vp_list, list) {
3694 if (rptid_entry->vp_idx == vp->vp_idx) {
3695 found = 1;
3696 break;
3697 }
3698 }
3699 spin_unlock_irqrestore(&ha->vport_slock, flags);
3700
3701 if (!found)
3702 return;
3703
Quinn Tran482c9dc2017-03-15 09:48:54 -07003704 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003705
3706 /*
3707 * Cannot configure here as we are still sitting on the
3708 * response queue. Handle it in dpc context.
3709 */
3710 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3711 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3712 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003713 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003714 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003715 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003716 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003717 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08003718 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3719 rptid_entry->port_id[2], rptid_entry->port_id[1],
3720 rptid_entry->port_id[0]);
3721
Quinn Tran83548fe2017-06-02 09:12:01 -07003722 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08003723 "N2N: Remote WWPN %8phC.\n",
3724 rptid_entry->u.f2.port_name);
3725
3726 /* N2N. direct connect */
3727 vha->d_id.b.domain = rptid_entry->port_id[2];
3728 vha->d_id.b.area = rptid_entry->port_id[1];
3729 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3730
3731 spin_lock_irqsave(&ha->vport_slock, flags);
3732 qlt_update_vp_map(vha, SET_AL_PA);
3733 spin_unlock_irqrestore(&ha->vport_slock, flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003734 }
3735}
3736
3737/*
3738 * qla24xx_modify_vp_config
3739 * Change VP configuration for vha
3740 *
3741 * Input:
3742 * vha = adapter block pointer.
3743 *
3744 * Returns:
3745 * qla2xxx local function return status code.
3746 *
3747 * Context:
3748 * Kernel context.
3749 */
3750int
3751qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3752{
3753 int rval;
3754 struct vp_config_entry_24xx *vpmod;
3755 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003756 struct qla_hw_data *ha = vha->hw;
3757 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003758
3759 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003760
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003761 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3762 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003763
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003764 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003765 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003766 ql_log(ql_log_warn, vha, 0x10bc,
3767 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003768 return QLA_MEMORY_ALLOC_FAILED;
3769 }
3770
3771 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3772 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3773 vpmod->entry_count = 1;
3774 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3775 vpmod->vp_count = 1;
3776 vpmod->vp_index1 = vha->vp_idx;
3777 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003778
3779 qlt_modify_vp_config(vha, vpmod);
3780
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003781 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3782 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3783 vpmod->entry_count = 1;
3784
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003785 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003786 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003787 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3788 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003789 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003790 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3791 "Failed to complete IOCB -- error status (%x).\n",
3792 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003793 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003794 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003795 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3796 "Failed to complete IOCB -- completion status (%x).\n",
3797 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003798 rval = QLA_FUNCTION_FAILED;
3799 } else {
3800 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003801 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3802 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003803 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3804 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003805 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003806
3807 return rval;
3808}
3809
3810/*
3811 * qla24xx_control_vp
3812 * Enable a virtual port for given host
3813 *
3814 * Input:
3815 * ha = adapter block pointer.
3816 * vhba = virtual adapter (unused)
3817 * index = index number for enabled VP
3818 *
3819 * Returns:
3820 * qla2xxx local function return status code.
3821 *
3822 * Context:
3823 * Kernel context.
3824 */
3825int
3826qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3827{
3828 int rval;
3829 int map, pos;
3830 struct vp_ctrl_entry_24xx *vce;
3831 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003832 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003833 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003834 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003835
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003836 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003837 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003838
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003839 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003840 return QLA_PARAMETER_ERROR;
3841
3842 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3843 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003844 ql_log(ql_log_warn, vha, 0x10c2,
3845 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003846 return QLA_MEMORY_ALLOC_FAILED;
3847 }
3848 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3849
3850 vce->entry_type = VP_CTRL_IOCB_TYPE;
3851 vce->entry_count = 1;
3852 vce->command = cpu_to_le16(cmd);
Bart Van Asschead950362015-07-09 07:24:08 -07003853 vce->vp_count = cpu_to_le16(1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003854
3855 /* index map in firmware starts with 1; decrement index
3856 * this is ok as we never use index 0
3857 */
3858 map = (vp_index - 1) / 8;
3859 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003860 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003861 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003862 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003863
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003864 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003865 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003866 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3867 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003868 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003869 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3870 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003871 vce->entry_status);
3872 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003873 } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003874 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3875 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003876 le16_to_cpu(vce->comp_status));
3877 rval = QLA_FUNCTION_FAILED;
3878 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003879 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3880 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003881 }
3882
3883 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3884
3885 return rval;
3886}
3887
3888/*
3889 * qla2x00_send_change_request
3890 * Receive or disable RSCN request from fabric controller
3891 *
3892 * Input:
3893 * ha = adapter block pointer
3894 * format = registration format:
3895 * 0 - Reserved
3896 * 1 - Fabric detected registration
3897 * 2 - N_port detected registration
3898 * 3 - Full registration
3899 * FF - clear registration
3900 * vp_idx = Virtual port index
3901 *
3902 * Returns:
3903 * qla2x00 local function return status code.
3904 *
3905 * Context:
3906 * Kernel Context
3907 */
3908
3909int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003910qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003911 uint16_t vp_idx)
3912{
3913 int rval;
3914 mbx_cmd_t mc;
3915 mbx_cmd_t *mcp = &mc;
3916
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003917 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3918 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003919
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003920 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3921 mcp->mb[1] = format;
3922 mcp->mb[9] = vp_idx;
3923 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3924 mcp->in_mb = MBX_0|MBX_1;
3925 mcp->tov = MBX_TOV_SECONDS;
3926 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003927 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003928
3929 if (rval == QLA_SUCCESS) {
3930 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3931 rval = BIT_1;
3932 }
3933 } else
3934 rval = BIT_1;
3935
3936 return rval;
3937}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003938
3939int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003940qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003941 uint32_t size)
3942{
3943 int rval;
3944 mbx_cmd_t mc;
3945 mbx_cmd_t *mcp = &mc;
3946
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003947 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3948 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003949
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003950 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003951 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3952 mcp->mb[8] = MSW(addr);
3953 mcp->out_mb = MBX_8|MBX_0;
3954 } else {
3955 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3956 mcp->out_mb = MBX_0;
3957 }
3958 mcp->mb[1] = LSW(addr);
3959 mcp->mb[2] = MSW(req_dma);
3960 mcp->mb[3] = LSW(req_dma);
3961 mcp->mb[6] = MSW(MSD(req_dma));
3962 mcp->mb[7] = LSW(MSD(req_dma));
3963 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003964 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003965 mcp->mb[4] = MSW(size);
3966 mcp->mb[5] = LSW(size);
3967 mcp->out_mb |= MBX_5|MBX_4;
3968 } else {
3969 mcp->mb[4] = LSW(size);
3970 mcp->out_mb |= MBX_4;
3971 }
3972
3973 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003974 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003975 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003976 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003977
3978 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003979 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3980 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003981 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003982 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3983 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003984 }
3985
3986 return rval;
3987}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003988/* 84XX Support **************************************************************/
3989
3990struct cs84xx_mgmt_cmd {
3991 union {
3992 struct verify_chip_entry_84xx req;
3993 struct verify_chip_rsp_84xx rsp;
3994 } p;
3995};
3996
3997int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003998qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003999{
4000 int rval, retry;
4001 struct cs84xx_mgmt_cmd *mn;
4002 dma_addr_t mn_dma;
4003 uint16_t options;
4004 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004005 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004006
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4008 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004009
4010 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4011 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004012 return QLA_MEMORY_ALLOC_FAILED;
4013 }
4014
4015 /* Force Update? */
4016 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4017 /* Diagnostic firmware? */
4018 /* options |= MENLO_DIAG_FW; */
4019 /* We update the firmware with only one data sequence. */
4020 options |= VCO_END_OF_DATA;
4021
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004022 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004023 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004024 memset(mn, 0, sizeof(*mn));
4025 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4026 mn->p.req.entry_count = 1;
4027 mn->p.req.options = cpu_to_le16(options);
4028
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004029 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4030 "Dump of Verify Request.\n");
4031 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4032 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004033
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004034 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004035 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004036 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4037 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004038 goto verify_done;
4039 }
4040
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004041 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4042 "Dump of Verify Response.\n");
4043 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4044 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004045
4046 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4047 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4048 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004049 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004050 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004051
4052 if (status[0] != CS_COMPLETE) {
4053 rval = QLA_FUNCTION_FAILED;
4054 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004055 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4056 "Firmware update failed. Retrying "
4057 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004058 options |= VCO_DONT_UPDATE_FW;
4059 options &= ~VCO_FORCE_UPDATE;
4060 retry = 1;
4061 }
4062 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004063 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004064 "Firmware updated to %x.\n",
4065 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004066
4067 /* NOTE: we only update OP firmware. */
4068 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4069 ha->cs84xx->op_fw_version =
4070 le32_to_cpu(mn->p.rsp.fw_ver);
4071 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4072 flags);
4073 }
4074 } while (retry);
4075
4076verify_done:
4077 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4078
4079 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004080 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4081 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004082 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004083 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4084 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004085 }
4086
4087 return rval;
4088}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004089
4090int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004091qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004092{
4093 int rval;
4094 unsigned long flags;
4095 mbx_cmd_t mc;
4096 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004097 struct qla_hw_data *ha = vha->hw;
4098
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004099 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4100 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004101
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004102 if (IS_SHADOW_REG_CAPABLE(ha))
4103 req->options |= BIT_13;
4104
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004105 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004106 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004107 mcp->mb[2] = MSW(LSD(req->dma));
4108 mcp->mb[3] = LSW(LSD(req->dma));
4109 mcp->mb[6] = MSW(MSD(req->dma));
4110 mcp->mb[7] = LSW(MSD(req->dma));
4111 mcp->mb[5] = req->length;
4112 if (req->rsp)
4113 mcp->mb[10] = req->rsp->id;
4114 mcp->mb[12] = req->qos;
4115 mcp->mb[11] = req->vp_idx;
4116 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004117 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004118 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004119
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004120 mcp->mb[4] = req->id;
4121 /* que in ptr index */
4122 mcp->mb[8] = 0;
4123 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004124 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004125 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4126 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4127 mcp->in_mb = MBX_0;
4128 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004129 mcp->tov = MBX_TOV_SECONDS * 2;
4130
Chad Dupuisf73cb692014-02-26 04:15:06 -05004131 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004132 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004133 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004134 mcp->out_mb |= MBX_15;
4135 /* debug q create issue in SR-IOV */
4136 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4137 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004138
4139 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004140 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004141 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004142 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004143 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004144 }
4145 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4146
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004147 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004148 if (rval != QLA_SUCCESS) {
4149 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4150 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4151 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004152 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4153 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004154 }
4155
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004156 return rval;
4157}
4158
4159int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004160qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004161{
4162 int rval;
4163 unsigned long flags;
4164 mbx_cmd_t mc;
4165 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004166 struct qla_hw_data *ha = vha->hw;
4167
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4169 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004170
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004171 if (IS_SHADOW_REG_CAPABLE(ha))
4172 rsp->options |= BIT_13;
4173
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004174 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004175 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004176 mcp->mb[2] = MSW(LSD(rsp->dma));
4177 mcp->mb[3] = LSW(LSD(rsp->dma));
4178 mcp->mb[6] = MSW(MSD(rsp->dma));
4179 mcp->mb[7] = LSW(MSD(rsp->dma));
4180 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004181 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004182 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004183 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004184 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004185
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004186 mcp->mb[4] = rsp->id;
4187 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004188 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004189 /* que out ptr index */
4190 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004191 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004192 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4193 mcp->in_mb = MBX_0;
4194 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004195 mcp->tov = MBX_TOV_SECONDS * 2;
4196
4197 if (IS_QLA81XX(ha)) {
4198 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4199 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004200 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004201 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4202 mcp->in_mb |= MBX_1;
4203 /* debug q create issue in SR-IOV */
4204 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4205 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004206
4207 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004208 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004209 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004210 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004211 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004212 }
4213
4214 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4215
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004216 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004217 if (rval != QLA_SUCCESS) {
4218 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4219 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4220 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004221 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4222 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004223 }
4224
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004225 return rval;
4226}
4227
Andrew Vasquez8a659572009-02-08 20:50:12 -08004228int
4229qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4230{
4231 int rval;
4232 mbx_cmd_t mc;
4233 mbx_cmd_t *mcp = &mc;
4234
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4236 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004237
4238 mcp->mb[0] = MBC_IDC_ACK;
4239 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4240 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4241 mcp->in_mb = MBX_0;
4242 mcp->tov = MBX_TOV_SECONDS;
4243 mcp->flags = 0;
4244 rval = qla2x00_mailbox_command(vha, mcp);
4245
4246 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004247 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4248 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004249 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004250 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4251 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004252 }
4253
4254 return rval;
4255}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004256
4257int
4258qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4259{
4260 int rval;
4261 mbx_cmd_t mc;
4262 mbx_cmd_t *mcp = &mc;
4263
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004264 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4265 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004266
Chad Dupuisf73cb692014-02-26 04:15:06 -05004267 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4268 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004269 return QLA_FUNCTION_FAILED;
4270
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004271 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4272 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4273 mcp->out_mb = MBX_1|MBX_0;
4274 mcp->in_mb = MBX_1|MBX_0;
4275 mcp->tov = MBX_TOV_SECONDS;
4276 mcp->flags = 0;
4277 rval = qla2x00_mailbox_command(vha, mcp);
4278
4279 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004280 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4281 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4282 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004283 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004284 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4285 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004286 *sector_size = mcp->mb[1];
4287 }
4288
4289 return rval;
4290}
4291
4292int
4293qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4294{
4295 int rval;
4296 mbx_cmd_t mc;
4297 mbx_cmd_t *mcp = &mc;
4298
Chad Dupuisf73cb692014-02-26 04:15:06 -05004299 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4300 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004301 return QLA_FUNCTION_FAILED;
4302
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004303 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4304 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004305
4306 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4307 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4308 FAC_OPT_CMD_WRITE_PROTECT;
4309 mcp->out_mb = MBX_1|MBX_0;
4310 mcp->in_mb = MBX_1|MBX_0;
4311 mcp->tov = MBX_TOV_SECONDS;
4312 mcp->flags = 0;
4313 rval = qla2x00_mailbox_command(vha, mcp);
4314
4315 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004316 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4317 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4318 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004319 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004320 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4321 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004322 }
4323
4324 return rval;
4325}
4326
4327int
4328qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4329{
4330 int rval;
4331 mbx_cmd_t mc;
4332 mbx_cmd_t *mcp = &mc;
4333
Chad Dupuisf73cb692014-02-26 04:15:06 -05004334 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4335 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004336 return QLA_FUNCTION_FAILED;
4337
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4339 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004340
4341 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4342 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4343 mcp->mb[2] = LSW(start);
4344 mcp->mb[3] = MSW(start);
4345 mcp->mb[4] = LSW(finish);
4346 mcp->mb[5] = MSW(finish);
4347 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4348 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4349 mcp->tov = MBX_TOV_SECONDS;
4350 mcp->flags = 0;
4351 rval = qla2x00_mailbox_command(vha, mcp);
4352
4353 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004354 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4355 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4356 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004357 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004358 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4359 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004360 }
4361
4362 return rval;
4363}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004364
4365int
4366qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4367{
4368 int rval = 0;
4369 mbx_cmd_t mc;
4370 mbx_cmd_t *mcp = &mc;
4371
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004372 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4373 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004374
4375 mcp->mb[0] = MBC_RESTART_MPI_FW;
4376 mcp->out_mb = MBX_0;
4377 mcp->in_mb = MBX_0|MBX_1;
4378 mcp->tov = MBX_TOV_SECONDS;
4379 mcp->flags = 0;
4380 rval = qla2x00_mailbox_command(vha, mcp);
4381
4382 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004383 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4384 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4385 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004386 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004387 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4388 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004389 }
4390
4391 return rval;
4392}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004393
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004394int
4395qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4396{
4397 int rval;
4398 mbx_cmd_t mc;
4399 mbx_cmd_t *mcp = &mc;
4400 int i;
4401 int len;
4402 uint16_t *str;
4403 struct qla_hw_data *ha = vha->hw;
4404
4405 if (!IS_P3P_TYPE(ha))
4406 return QLA_FUNCTION_FAILED;
4407
4408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4409 "Entered %s.\n", __func__);
4410
4411 str = (void *)version;
4412 len = strlen(version);
4413
4414 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4415 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4416 mcp->out_mb = MBX_1|MBX_0;
4417 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4418 mcp->mb[i] = cpu_to_le16p(str);
4419 mcp->out_mb |= 1<<i;
4420 }
4421 for (; i < 16; i++) {
4422 mcp->mb[i] = 0;
4423 mcp->out_mb |= 1<<i;
4424 }
4425 mcp->in_mb = MBX_1|MBX_0;
4426 mcp->tov = MBX_TOV_SECONDS;
4427 mcp->flags = 0;
4428 rval = qla2x00_mailbox_command(vha, mcp);
4429
4430 if (rval != QLA_SUCCESS) {
4431 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4432 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4433 } else {
4434 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4435 "Done %s.\n", __func__);
4436 }
4437
4438 return rval;
4439}
4440
4441int
4442qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4443{
4444 int rval;
4445 mbx_cmd_t mc;
4446 mbx_cmd_t *mcp = &mc;
4447 int len;
4448 uint16_t dwlen;
4449 uint8_t *str;
4450 dma_addr_t str_dma;
4451 struct qla_hw_data *ha = vha->hw;
4452
4453 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4454 IS_P3P_TYPE(ha))
4455 return QLA_FUNCTION_FAILED;
4456
4457 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4458 "Entered %s.\n", __func__);
4459
4460 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4461 if (!str) {
4462 ql_log(ql_log_warn, vha, 0x117f,
4463 "Failed to allocate driver version param.\n");
4464 return QLA_MEMORY_ALLOC_FAILED;
4465 }
4466
4467 memcpy(str, "\x7\x3\x11\x0", 4);
4468 dwlen = str[0];
4469 len = dwlen * 4 - 4;
4470 memset(str + 4, 0, len);
4471 if (len > strlen(version))
4472 len = strlen(version);
4473 memcpy(str + 4, version, len);
4474
4475 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4476 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4477 mcp->mb[2] = MSW(LSD(str_dma));
4478 mcp->mb[3] = LSW(LSD(str_dma));
4479 mcp->mb[6] = MSW(MSD(str_dma));
4480 mcp->mb[7] = LSW(MSD(str_dma));
4481 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4482 mcp->in_mb = MBX_1|MBX_0;
4483 mcp->tov = MBX_TOV_SECONDS;
4484 mcp->flags = 0;
4485 rval = qla2x00_mailbox_command(vha, mcp);
4486
4487 if (rval != QLA_SUCCESS) {
4488 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4489 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4490 } else {
4491 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4492 "Done %s.\n", __func__);
4493 }
4494
4495 dma_pool_free(ha->s_dma_pool, str, str_dma);
4496
4497 return rval;
4498}
4499
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004500static int
4501qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4502{
4503 int rval;
4504 mbx_cmd_t mc;
4505 mbx_cmd_t *mcp = &mc;
4506
4507 if (!IS_FWI2_CAPABLE(vha->hw))
4508 return QLA_FUNCTION_FAILED;
4509
4510 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4511 "Entered %s.\n", __func__);
4512
4513 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4514 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4515 mcp->out_mb = MBX_1|MBX_0;
4516 mcp->in_mb = MBX_1|MBX_0;
4517 mcp->tov = MBX_TOV_SECONDS;
4518 mcp->flags = 0;
4519 rval = qla2x00_mailbox_command(vha, mcp);
4520 *temp = mcp->mb[1];
4521
4522 if (rval != QLA_SUCCESS) {
4523 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4524 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4525 } else {
4526 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4527 "Done %s.\n", __func__);
4528 }
4529
4530 return rval;
4531}
4532
Joe Carnuccio3a117112013-02-08 01:58:00 -05004533int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004534qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4535 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004536{
4537 int rval;
4538 mbx_cmd_t mc;
4539 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004540 struct qla_hw_data *ha = vha->hw;
4541
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004542 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4543 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004544
Joe Carnuccio6766df92011-05-10 11:30:15 -07004545 if (!IS_FWI2_CAPABLE(ha))
4546 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004547
Joe Carnuccio6766df92011-05-10 11:30:15 -07004548 if (len == 1)
4549 opt |= BIT_0;
4550
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004551 mcp->mb[0] = MBC_READ_SFP;
4552 mcp->mb[1] = dev;
4553 mcp->mb[2] = MSW(sfp_dma);
4554 mcp->mb[3] = LSW(sfp_dma);
4555 mcp->mb[6] = MSW(MSD(sfp_dma));
4556 mcp->mb[7] = LSW(MSD(sfp_dma));
4557 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004558 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004559 mcp->mb[10] = opt;
4560 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 -07004561 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004562 mcp->tov = MBX_TOV_SECONDS;
4563 mcp->flags = 0;
4564 rval = qla2x00_mailbox_command(vha, mcp);
4565
4566 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004567 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004568
4569 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004570 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4571 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004572 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004573 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4574 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004575 }
4576
4577 return rval;
4578}
4579
4580int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004581qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4582 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004583{
4584 int rval;
4585 mbx_cmd_t mc;
4586 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004587 struct qla_hw_data *ha = vha->hw;
4588
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004589 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4590 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004591
Joe Carnuccio6766df92011-05-10 11:30:15 -07004592 if (!IS_FWI2_CAPABLE(ha))
4593 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004594
Joe Carnuccio6766df92011-05-10 11:30:15 -07004595 if (len == 1)
4596 opt |= BIT_0;
4597
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004598 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004599 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004600
4601 mcp->mb[0] = MBC_WRITE_SFP;
4602 mcp->mb[1] = dev;
4603 mcp->mb[2] = MSW(sfp_dma);
4604 mcp->mb[3] = LSW(sfp_dma);
4605 mcp->mb[6] = MSW(MSD(sfp_dma));
4606 mcp->mb[7] = LSW(MSD(sfp_dma));
4607 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004608 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004609 mcp->mb[10] = opt;
4610 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 -07004611 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004612 mcp->tov = MBX_TOV_SECONDS;
4613 mcp->flags = 0;
4614 rval = qla2x00_mailbox_command(vha, mcp);
4615
4616 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004617 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4618 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004619 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004620 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4621 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004622 }
4623
4624 return rval;
4625}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004626
4627int
4628qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4629 uint16_t size_in_bytes, uint16_t *actual_size)
4630{
4631 int rval;
4632 mbx_cmd_t mc;
4633 mbx_cmd_t *mcp = &mc;
4634
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004635 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4636 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004637
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004638 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004639 return QLA_FUNCTION_FAILED;
4640
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004641 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4642 mcp->mb[2] = MSW(stats_dma);
4643 mcp->mb[3] = LSW(stats_dma);
4644 mcp->mb[6] = MSW(MSD(stats_dma));
4645 mcp->mb[7] = LSW(MSD(stats_dma));
4646 mcp->mb[8] = size_in_bytes >> 2;
4647 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4648 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4649 mcp->tov = MBX_TOV_SECONDS;
4650 mcp->flags = 0;
4651 rval = qla2x00_mailbox_command(vha, mcp);
4652
4653 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004654 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4655 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4656 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004657 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004658 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4659 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004660
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004661
4662 *actual_size = mcp->mb[2] << 2;
4663 }
4664
4665 return rval;
4666}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004667
4668int
4669qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4670 uint16_t size)
4671{
4672 int rval;
4673 mbx_cmd_t mc;
4674 mbx_cmd_t *mcp = &mc;
4675
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4677 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004678
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004679 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004680 return QLA_FUNCTION_FAILED;
4681
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004682 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4683 mcp->mb[1] = 0;
4684 mcp->mb[2] = MSW(tlv_dma);
4685 mcp->mb[3] = LSW(tlv_dma);
4686 mcp->mb[6] = MSW(MSD(tlv_dma));
4687 mcp->mb[7] = LSW(MSD(tlv_dma));
4688 mcp->mb[8] = size;
4689 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4690 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4691 mcp->tov = MBX_TOV_SECONDS;
4692 mcp->flags = 0;
4693 rval = qla2x00_mailbox_command(vha, mcp);
4694
4695 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004696 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4697 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4698 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004699 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004700 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4701 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004702 }
4703
4704 return rval;
4705}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004706
4707int
4708qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4709{
4710 int rval;
4711 mbx_cmd_t mc;
4712 mbx_cmd_t *mcp = &mc;
4713
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004714 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4715 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004716
Andrew Vasquez18e75552009-06-03 09:55:30 -07004717 if (!IS_FWI2_CAPABLE(vha->hw))
4718 return QLA_FUNCTION_FAILED;
4719
Andrew Vasquez18e75552009-06-03 09:55:30 -07004720 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4721 mcp->mb[1] = LSW(risc_addr);
4722 mcp->mb[8] = MSW(risc_addr);
4723 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4724 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4725 mcp->tov = 30;
4726 mcp->flags = 0;
4727 rval = qla2x00_mailbox_command(vha, mcp);
4728 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004729 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4730 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004731 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004732 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4733 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004734 *data = mcp->mb[3] << 16 | mcp->mb[2];
4735 }
4736
4737 return rval;
4738}
4739
4740int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004741qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4742 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004743{
4744 int rval;
4745 mbx_cmd_t mc;
4746 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004747
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004748 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4749 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004750
4751 memset(mcp->mb, 0 , sizeof(mcp->mb));
4752 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4753 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4754
4755 /* transfer count */
4756 mcp->mb[10] = LSW(mreq->transfer_size);
4757 mcp->mb[11] = MSW(mreq->transfer_size);
4758
4759 /* send data address */
4760 mcp->mb[14] = LSW(mreq->send_dma);
4761 mcp->mb[15] = MSW(mreq->send_dma);
4762 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4763 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4764
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004765 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004766 mcp->mb[16] = LSW(mreq->rcv_dma);
4767 mcp->mb[17] = MSW(mreq->rcv_dma);
4768 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4769 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4770
4771 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004772 mcp->mb[18] = LSW(mreq->iteration_count);
4773 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004774
4775 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4776 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 -08004777 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004778 mcp->out_mb |= MBX_2;
4779 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4780
4781 mcp->buf_size = mreq->transfer_size;
4782 mcp->tov = MBX_TOV_SECONDS;
4783 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4784
4785 rval = qla2x00_mailbox_command(vha, mcp);
4786
4787 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004788 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4789 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4790 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4791 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004792 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004793 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4794 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004795 }
4796
4797 /* Copy mailbox information */
4798 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004799 return rval;
4800}
4801
4802int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004803qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4804 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004805{
4806 int rval;
4807 mbx_cmd_t mc;
4808 mbx_cmd_t *mcp = &mc;
4809 struct qla_hw_data *ha = vha->hw;
4810
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004811 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4812 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004813
4814 memset(mcp->mb, 0 , sizeof(mcp->mb));
4815 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07004816 /* BIT_6 specifies 64bit address */
4817 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004818 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004819 mcp->mb[2] = vha->fcoe_fcf_idx;
4820 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004821 mcp->mb[16] = LSW(mreq->rcv_dma);
4822 mcp->mb[17] = MSW(mreq->rcv_dma);
4823 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4824 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4825
4826 mcp->mb[10] = LSW(mreq->transfer_size);
4827
4828 mcp->mb[14] = LSW(mreq->send_dma);
4829 mcp->mb[15] = MSW(mreq->send_dma);
4830 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4831 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4832
4833 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4834 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004835 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004836 mcp->out_mb |= MBX_2;
4837
4838 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004839 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4840 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004841 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004842 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004843 mcp->in_mb |= MBX_3;
4844
4845 mcp->tov = MBX_TOV_SECONDS;
4846 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4847 mcp->buf_size = mreq->transfer_size;
4848
4849 rval = qla2x00_mailbox_command(vha, mcp);
4850
4851 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004852 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4853 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4854 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004855 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004856 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4857 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004858 }
4859
4860 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004861 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004862 return rval;
4863}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004864
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004865int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004866qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004867{
4868 int rval;
4869 mbx_cmd_t mc;
4870 mbx_cmd_t *mcp = &mc;
4871
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004872 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004873 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004874
4875 mcp->mb[0] = MBC_ISP84XX_RESET;
4876 mcp->mb[1] = enable_diagnostic;
4877 mcp->out_mb = MBX_1|MBX_0;
4878 mcp->in_mb = MBX_1|MBX_0;
4879 mcp->tov = MBX_TOV_SECONDS;
4880 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004881 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004882
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004883 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004884 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004885 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004886 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4887 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004888
4889 return rval;
4890}
4891
4892int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004893qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4894{
4895 int rval;
4896 mbx_cmd_t mc;
4897 mbx_cmd_t *mcp = &mc;
4898
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4900 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004901
Andrew Vasquez18e75552009-06-03 09:55:30 -07004902 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004903 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004904
Andrew Vasquez18e75552009-06-03 09:55:30 -07004905 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4906 mcp->mb[1] = LSW(risc_addr);
4907 mcp->mb[2] = LSW(data);
4908 mcp->mb[3] = MSW(data);
4909 mcp->mb[8] = MSW(risc_addr);
4910 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4911 mcp->in_mb = MBX_0;
4912 mcp->tov = 30;
4913 mcp->flags = 0;
4914 rval = qla2x00_mailbox_command(vha, mcp);
4915 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004916 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4917 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004918 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004919 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4920 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004921 }
4922
4923 return rval;
4924}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004925
4926int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004927qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4928{
4929 int rval;
4930 uint32_t stat, timer;
4931 uint16_t mb0 = 0;
4932 struct qla_hw_data *ha = vha->hw;
4933 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4934
4935 rval = QLA_SUCCESS;
4936
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004937 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4938 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004939
4940 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4941
4942 /* Write the MBC data to the registers */
4943 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4944 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4945 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4946 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4947 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4948
4949 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4950
4951 /* Poll for MBC interrupt */
4952 for (timer = 6000000; timer; timer--) {
4953 /* Check for pending interrupts. */
4954 stat = RD_REG_DWORD(&reg->host_status);
4955 if (stat & HSRX_RISC_INT) {
4956 stat &= 0xff;
4957
4958 if (stat == 0x1 || stat == 0x2 ||
4959 stat == 0x10 || stat == 0x11) {
4960 set_bit(MBX_INTERRUPT,
4961 &ha->mbx_cmd_flags);
4962 mb0 = RD_REG_WORD(&reg->mailbox0);
4963 WRT_REG_DWORD(&reg->hccr,
4964 HCCRX_CLR_RISC_INT);
4965 RD_REG_DWORD(&reg->hccr);
4966 break;
4967 }
4968 }
4969 udelay(5);
4970 }
4971
4972 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4973 rval = mb0 & MBS_MASK;
4974 else
4975 rval = QLA_FUNCTION_FAILED;
4976
4977 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004978 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4979 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004980 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004981 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4982 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004983 }
4984
4985 return rval;
4986}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004987
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004988int
Michael Hernandez3064ff32009-12-15 21:29:44 -08004989qla2x00_get_data_rate(scsi_qla_host_t *vha)
4990{
4991 int rval;
4992 mbx_cmd_t mc;
4993 mbx_cmd_t *mcp = &mc;
4994 struct qla_hw_data *ha = vha->hw;
4995
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004996 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
4997 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004998
Michael Hernandez3064ff32009-12-15 21:29:44 -08004999 if (!IS_FWI2_CAPABLE(ha))
5000 return QLA_FUNCTION_FAILED;
5001
Michael Hernandez3064ff32009-12-15 21:29:44 -08005002 mcp->mb[0] = MBC_DATA_RATE;
5003 mcp->mb[1] = 0;
5004 mcp->out_mb = MBX_1|MBX_0;
5005 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005006 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005007 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005008 mcp->tov = MBX_TOV_SECONDS;
5009 mcp->flags = 0;
5010 rval = qla2x00_mailbox_command(vha, mcp);
5011 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005012 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5013 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005014 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5016 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005017 if (mcp->mb[1] != 0x7)
5018 ha->link_data_rate = mcp->mb[1];
5019 }
5020
5021 return rval;
5022}
Sarang Radke09ff7012010-03-19 17:03:59 -07005023
5024int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005025qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5026{
5027 int rval;
5028 mbx_cmd_t mc;
5029 mbx_cmd_t *mcp = &mc;
5030 struct qla_hw_data *ha = vha->hw;
5031
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005032 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5033 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005034
Chad Dupuisf73cb692014-02-26 04:15:06 -05005035 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5036 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005037 return QLA_FUNCTION_FAILED;
5038 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5039 mcp->out_mb = MBX_0;
5040 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5041 mcp->tov = MBX_TOV_SECONDS;
5042 mcp->flags = 0;
5043
5044 rval = qla2x00_mailbox_command(vha, mcp);
5045
5046 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005047 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5048 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005049 } else {
5050 /* Copy all bits to preserve original value */
5051 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5052
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005053 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5054 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005055 }
5056 return rval;
5057}
5058
5059int
5060qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5061{
5062 int rval;
5063 mbx_cmd_t mc;
5064 mbx_cmd_t *mcp = &mc;
5065
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005066 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5067 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005068
5069 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5070 /* Copy all bits to preserve original setting */
5071 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5072 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5073 mcp->in_mb = MBX_0;
5074 mcp->tov = MBX_TOV_SECONDS;
5075 mcp->flags = 0;
5076 rval = qla2x00_mailbox_command(vha, mcp);
5077
5078 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005079 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5080 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005081 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5083 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005084
5085 return rval;
5086}
5087
5088
5089int
Sarang Radke09ff7012010-03-19 17:03:59 -07005090qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5091 uint16_t *mb)
5092{
5093 int rval;
5094 mbx_cmd_t mc;
5095 mbx_cmd_t *mcp = &mc;
5096 struct qla_hw_data *ha = vha->hw;
5097
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005098 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5099 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005100
Sarang Radke09ff7012010-03-19 17:03:59 -07005101 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5102 return QLA_FUNCTION_FAILED;
5103
Sarang Radke09ff7012010-03-19 17:03:59 -07005104 mcp->mb[0] = MBC_PORT_PARAMS;
5105 mcp->mb[1] = loop_id;
5106 if (ha->flags.fcp_prio_enabled)
5107 mcp->mb[2] = BIT_1;
5108 else
5109 mcp->mb[2] = BIT_2;
5110 mcp->mb[4] = priority & 0xf;
5111 mcp->mb[9] = vha->vp_idx;
5112 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5113 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5114 mcp->tov = 30;
5115 mcp->flags = 0;
5116 rval = qla2x00_mailbox_command(vha, mcp);
5117 if (mb != NULL) {
5118 mb[0] = mcp->mb[0];
5119 mb[1] = mcp->mb[1];
5120 mb[3] = mcp->mb[3];
5121 mb[4] = mcp->mb[4];
5122 }
5123
5124 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005125 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005126 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005127 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5128 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005129 }
5130
5131 return rval;
5132}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005133
5134int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005135qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005136{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005137 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005138 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005139 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005140
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005141 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5142 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5143 "Thermal not supported by this card.\n");
5144 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005145 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005146
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005147 if (IS_QLA25XX(ha)) {
5148 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5149 ha->pdev->subsystem_device == 0x0175) {
5150 rval = qla2x00_read_sfp(vha, 0, &byte,
5151 0x98, 0x1, 1, BIT_13|BIT_0);
5152 *temp = byte;
5153 return rval;
5154 }
5155 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5156 ha->pdev->subsystem_device == 0x338e) {
5157 rval = qla2x00_read_sfp(vha, 0, &byte,
5158 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5159 *temp = byte;
5160 return rval;
5161 }
5162 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5163 "Thermal not supported by this card.\n");
5164 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005165 }
5166
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005167 if (IS_QLA82XX(ha)) {
5168 *temp = qla82xx_read_temperature(vha);
5169 rval = QLA_SUCCESS;
5170 return rval;
5171 } else if (IS_QLA8044(ha)) {
5172 *temp = qla8044_read_temperature(vha);
5173 rval = QLA_SUCCESS;
5174 return rval;
5175 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005176
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005177 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005178 return rval;
5179}
5180
5181int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005182qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5183{
5184 int rval;
5185 struct qla_hw_data *ha = vha->hw;
5186 mbx_cmd_t mc;
5187 mbx_cmd_t *mcp = &mc;
5188
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005189 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5190 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005191
Giridhar Malavalia9083012010-04-12 17:59:55 -07005192 if (!IS_FWI2_CAPABLE(ha))
5193 return QLA_FUNCTION_FAILED;
5194
Giridhar Malavalia9083012010-04-12 17:59:55 -07005195 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005196 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005197 mcp->mb[1] = 1;
5198
5199 mcp->out_mb = MBX_1|MBX_0;
5200 mcp->in_mb = MBX_0;
5201 mcp->tov = 30;
5202 mcp->flags = 0;
5203
5204 rval = qla2x00_mailbox_command(vha, mcp);
5205 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005206 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5207 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005208 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005209 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5210 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005211 }
5212
5213 return rval;
5214}
5215
5216int
5217qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5218{
5219 int rval;
5220 struct qla_hw_data *ha = vha->hw;
5221 mbx_cmd_t mc;
5222 mbx_cmd_t *mcp = &mc;
5223
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005224 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5225 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005226
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005227 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005228 return QLA_FUNCTION_FAILED;
5229
Giridhar Malavalia9083012010-04-12 17:59:55 -07005230 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005231 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005232 mcp->mb[1] = 0;
5233
5234 mcp->out_mb = MBX_1|MBX_0;
5235 mcp->in_mb = MBX_0;
5236 mcp->tov = 30;
5237 mcp->flags = 0;
5238
5239 rval = qla2x00_mailbox_command(vha, mcp);
5240 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005241 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5242 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005243 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005244 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5245 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005246 }
5247
5248 return rval;
5249}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005250
5251int
5252qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5253{
5254 struct qla_hw_data *ha = vha->hw;
5255 mbx_cmd_t mc;
5256 mbx_cmd_t *mcp = &mc;
5257 int rval = QLA_FUNCTION_FAILED;
5258
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005259 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5260 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005261
5262 memset(mcp->mb, 0 , sizeof(mcp->mb));
5263 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5264 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5265 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5266 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5267
5268 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5269 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5270 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5271
5272 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5273 mcp->tov = MBX_TOV_SECONDS;
5274 rval = qla2x00_mailbox_command(vha, mcp);
5275
5276 /* Always copy back return mailbox values. */
5277 if (rval != QLA_SUCCESS) {
5278 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5279 "mailbox command FAILED=0x%x, subcode=%x.\n",
5280 (mcp->mb[1] << 16) | mcp->mb[0],
5281 (mcp->mb[3] << 16) | mcp->mb[2]);
5282 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005283 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5284 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005285 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5286 if (!ha->md_template_size) {
5287 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5288 "Null template size obtained.\n");
5289 rval = QLA_FUNCTION_FAILED;
5290 }
5291 }
5292 return rval;
5293}
5294
5295int
5296qla82xx_md_get_template(scsi_qla_host_t *vha)
5297{
5298 struct qla_hw_data *ha = vha->hw;
5299 mbx_cmd_t mc;
5300 mbx_cmd_t *mcp = &mc;
5301 int rval = QLA_FUNCTION_FAILED;
5302
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005303 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5304 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005305
5306 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5307 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5308 if (!ha->md_tmplt_hdr) {
5309 ql_log(ql_log_warn, vha, 0x1124,
5310 "Unable to allocate memory for Minidump template.\n");
5311 return rval;
5312 }
5313
5314 memset(mcp->mb, 0 , sizeof(mcp->mb));
5315 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5316 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5317 mcp->mb[2] = LSW(RQST_TMPLT);
5318 mcp->mb[3] = MSW(RQST_TMPLT);
5319 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5320 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5321 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5322 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5323 mcp->mb[8] = LSW(ha->md_template_size);
5324 mcp->mb[9] = MSW(ha->md_template_size);
5325
5326 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5327 mcp->tov = MBX_TOV_SECONDS;
5328 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5329 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5330 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5331 rval = qla2x00_mailbox_command(vha, mcp);
5332
5333 if (rval != QLA_SUCCESS) {
5334 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5335 "mailbox command FAILED=0x%x, subcode=%x.\n",
5336 ((mcp->mb[1] << 16) | mcp->mb[0]),
5337 ((mcp->mb[3] << 16) | mcp->mb[2]));
5338 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005339 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5340 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005341 return rval;
5342}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005343
5344int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005345qla8044_md_get_template(scsi_qla_host_t *vha)
5346{
5347 struct qla_hw_data *ha = vha->hw;
5348 mbx_cmd_t mc;
5349 mbx_cmd_t *mcp = &mc;
5350 int rval = QLA_FUNCTION_FAILED;
5351 int offset = 0, size = MINIDUMP_SIZE_36K;
5352 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5353 "Entered %s.\n", __func__);
5354
5355 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5356 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5357 if (!ha->md_tmplt_hdr) {
5358 ql_log(ql_log_warn, vha, 0xb11b,
5359 "Unable to allocate memory for Minidump template.\n");
5360 return rval;
5361 }
5362
5363 memset(mcp->mb, 0 , sizeof(mcp->mb));
5364 while (offset < ha->md_template_size) {
5365 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5366 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5367 mcp->mb[2] = LSW(RQST_TMPLT);
5368 mcp->mb[3] = MSW(RQST_TMPLT);
5369 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5370 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5371 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5372 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5373 mcp->mb[8] = LSW(size);
5374 mcp->mb[9] = MSW(size);
5375 mcp->mb[10] = offset & 0x0000FFFF;
5376 mcp->mb[11] = offset & 0xFFFF0000;
5377 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5378 mcp->tov = MBX_TOV_SECONDS;
5379 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5380 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5381 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5382 rval = qla2x00_mailbox_command(vha, mcp);
5383
5384 if (rval != QLA_SUCCESS) {
5385 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5386 "mailbox command FAILED=0x%x, subcode=%x.\n",
5387 ((mcp->mb[1] << 16) | mcp->mb[0]),
5388 ((mcp->mb[3] << 16) | mcp->mb[2]));
5389 return rval;
5390 } else
5391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5392 "Done %s.\n", __func__);
5393 offset = offset + size;
5394 }
5395 return rval;
5396}
5397
5398int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005399qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5400{
5401 int rval;
5402 struct qla_hw_data *ha = vha->hw;
5403 mbx_cmd_t mc;
5404 mbx_cmd_t *mcp = &mc;
5405
5406 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5407 return QLA_FUNCTION_FAILED;
5408
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005409 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5410 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005411
5412 memset(mcp, 0, sizeof(mbx_cmd_t));
5413 mcp->mb[0] = MBC_SET_LED_CONFIG;
5414 mcp->mb[1] = led_cfg[0];
5415 mcp->mb[2] = led_cfg[1];
5416 if (IS_QLA8031(ha)) {
5417 mcp->mb[3] = led_cfg[2];
5418 mcp->mb[4] = led_cfg[3];
5419 mcp->mb[5] = led_cfg[4];
5420 mcp->mb[6] = led_cfg[5];
5421 }
5422
5423 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5424 if (IS_QLA8031(ha))
5425 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5426 mcp->in_mb = MBX_0;
5427 mcp->tov = 30;
5428 mcp->flags = 0;
5429
5430 rval = qla2x00_mailbox_command(vha, mcp);
5431 if (rval != QLA_SUCCESS) {
5432 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5433 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5434 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005435 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5436 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005437 }
5438
5439 return rval;
5440}
5441
5442int
5443qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5444{
5445 int rval;
5446 struct qla_hw_data *ha = vha->hw;
5447 mbx_cmd_t mc;
5448 mbx_cmd_t *mcp = &mc;
5449
5450 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5451 return QLA_FUNCTION_FAILED;
5452
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005453 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5454 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005455
5456 memset(mcp, 0, sizeof(mbx_cmd_t));
5457 mcp->mb[0] = MBC_GET_LED_CONFIG;
5458
5459 mcp->out_mb = MBX_0;
5460 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5461 if (IS_QLA8031(ha))
5462 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5463 mcp->tov = 30;
5464 mcp->flags = 0;
5465
5466 rval = qla2x00_mailbox_command(vha, mcp);
5467 if (rval != QLA_SUCCESS) {
5468 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5469 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5470 } else {
5471 led_cfg[0] = mcp->mb[1];
5472 led_cfg[1] = mcp->mb[2];
5473 if (IS_QLA8031(ha)) {
5474 led_cfg[2] = mcp->mb[3];
5475 led_cfg[3] = mcp->mb[4];
5476 led_cfg[4] = mcp->mb[5];
5477 led_cfg[5] = mcp->mb[6];
5478 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005479 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5480 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005481 }
5482
5483 return rval;
5484}
5485
5486int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005487qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5488{
5489 int rval;
5490 struct qla_hw_data *ha = vha->hw;
5491 mbx_cmd_t mc;
5492 mbx_cmd_t *mcp = &mc;
5493
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005494 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005495 return QLA_FUNCTION_FAILED;
5496
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005497 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005498 "Entered %s.\n", __func__);
5499
5500 memset(mcp, 0, sizeof(mbx_cmd_t));
5501 mcp->mb[0] = MBC_SET_LED_CONFIG;
5502 if (enable)
5503 mcp->mb[7] = 0xE;
5504 else
5505 mcp->mb[7] = 0xD;
5506
5507 mcp->out_mb = MBX_7|MBX_0;
5508 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005509 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005510 mcp->flags = 0;
5511
5512 rval = qla2x00_mailbox_command(vha, mcp);
5513 if (rval != QLA_SUCCESS) {
5514 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5515 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5516 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005517 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005518 "Done %s.\n", __func__);
5519 }
5520
5521 return rval;
5522}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005523
5524int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005525qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005526{
5527 int rval;
5528 struct qla_hw_data *ha = vha->hw;
5529 mbx_cmd_t mc;
5530 mbx_cmd_t *mcp = &mc;
5531
Chad Dupuisf73cb692014-02-26 04:15:06 -05005532 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005533 return QLA_FUNCTION_FAILED;
5534
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005535 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5536 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005537
5538 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5539 mcp->mb[1] = LSW(reg);
5540 mcp->mb[2] = MSW(reg);
5541 mcp->mb[3] = LSW(data);
5542 mcp->mb[4] = MSW(data);
5543 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5544
5545 mcp->in_mb = MBX_1|MBX_0;
5546 mcp->tov = MBX_TOV_SECONDS;
5547 mcp->flags = 0;
5548 rval = qla2x00_mailbox_command(vha, mcp);
5549
5550 if (rval != QLA_SUCCESS) {
5551 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5552 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5553 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005554 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005555 "Done %s.\n", __func__);
5556 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005557
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005558 return rval;
5559}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005560
5561int
5562qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5563{
5564 int rval;
5565 struct qla_hw_data *ha = vha->hw;
5566 mbx_cmd_t mc;
5567 mbx_cmd_t *mcp = &mc;
5568
5569 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005570 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005571 "Implicit LOGO Unsupported.\n");
5572 return QLA_FUNCTION_FAILED;
5573 }
5574
5575
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005576 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5577 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005578
5579 /* Perform Implicit LOGO. */
5580 mcp->mb[0] = MBC_PORT_LOGOUT;
5581 mcp->mb[1] = fcport->loop_id;
5582 mcp->mb[10] = BIT_15;
5583 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5584 mcp->in_mb = MBX_0;
5585 mcp->tov = MBX_TOV_SECONDS;
5586 mcp->flags = 0;
5587 rval = qla2x00_mailbox_command(vha, mcp);
5588 if (rval != QLA_SUCCESS)
5589 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5590 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5591 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005592 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5593 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005594
5595 return rval;
5596}
5597
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005598int
5599qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5600{
5601 int rval;
5602 mbx_cmd_t mc;
5603 mbx_cmd_t *mcp = &mc;
5604 struct qla_hw_data *ha = vha->hw;
5605 unsigned long retry_max_time = jiffies + (2 * HZ);
5606
Chad Dupuisf73cb692014-02-26 04:15:06 -05005607 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005608 return QLA_FUNCTION_FAILED;
5609
5610 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5611
5612retry_rd_reg:
5613 mcp->mb[0] = MBC_READ_REMOTE_REG;
5614 mcp->mb[1] = LSW(reg);
5615 mcp->mb[2] = MSW(reg);
5616 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5617 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5618 mcp->tov = MBX_TOV_SECONDS;
5619 mcp->flags = 0;
5620 rval = qla2x00_mailbox_command(vha, mcp);
5621
5622 if (rval != QLA_SUCCESS) {
5623 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5624 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5625 rval, mcp->mb[0], mcp->mb[1]);
5626 } else {
5627 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5628 if (*data == QLA8XXX_BAD_VALUE) {
5629 /*
5630 * During soft-reset CAMRAM register reads might
5631 * return 0xbad0bad0. So retry for MAX of 2 sec
5632 * while reading camram registers.
5633 */
5634 if (time_after(jiffies, retry_max_time)) {
5635 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5636 "Failure to read CAMRAM register. "
5637 "data=0x%x.\n", *data);
5638 return QLA_FUNCTION_FAILED;
5639 }
5640 msleep(100);
5641 goto retry_rd_reg;
5642 }
5643 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5644 }
5645
5646 return rval;
5647}
5648
5649int
5650qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5651{
5652 int rval;
5653 mbx_cmd_t mc;
5654 mbx_cmd_t *mcp = &mc;
5655 struct qla_hw_data *ha = vha->hw;
5656
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005657 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005658 return QLA_FUNCTION_FAILED;
5659
5660 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5661
5662 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5663 mcp->out_mb = MBX_0;
5664 mcp->in_mb = MBX_1|MBX_0;
5665 mcp->tov = MBX_TOV_SECONDS;
5666 mcp->flags = 0;
5667 rval = qla2x00_mailbox_command(vha, mcp);
5668
5669 if (rval != QLA_SUCCESS) {
5670 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5671 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5672 rval, mcp->mb[0], mcp->mb[1]);
5673 ha->isp_ops->fw_dump(vha, 0);
5674 } else {
5675 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5676 }
5677
5678 return rval;
5679}
5680
5681int
5682qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5683 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5684{
5685 int rval;
5686 mbx_cmd_t mc;
5687 mbx_cmd_t *mcp = &mc;
5688 uint8_t subcode = (uint8_t)options;
5689 struct qla_hw_data *ha = vha->hw;
5690
5691 if (!IS_QLA8031(ha))
5692 return QLA_FUNCTION_FAILED;
5693
5694 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5695
5696 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5697 mcp->mb[1] = options;
5698 mcp->out_mb = MBX_1|MBX_0;
5699 if (subcode & BIT_2) {
5700 mcp->mb[2] = LSW(start_addr);
5701 mcp->mb[3] = MSW(start_addr);
5702 mcp->mb[4] = LSW(end_addr);
5703 mcp->mb[5] = MSW(end_addr);
5704 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5705 }
5706 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5707 if (!(subcode & (BIT_2 | BIT_5)))
5708 mcp->in_mb |= MBX_4|MBX_3;
5709 mcp->tov = MBX_TOV_SECONDS;
5710 mcp->flags = 0;
5711 rval = qla2x00_mailbox_command(vha, mcp);
5712
5713 if (rval != QLA_SUCCESS) {
5714 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5715 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5716 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5717 mcp->mb[4]);
5718 ha->isp_ops->fw_dump(vha, 0);
5719 } else {
5720 if (subcode & BIT_5)
5721 *sector_size = mcp->mb[1];
5722 else if (subcode & (BIT_6 | BIT_7)) {
5723 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5724 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5725 } else if (subcode & (BIT_3 | BIT_4)) {
5726 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5727 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5728 }
5729 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5730 }
5731
5732 return rval;
5733}
Saurav Kashyap81178772012-08-22 14:21:04 -04005734
5735int
5736qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5737 uint32_t size)
5738{
5739 int rval;
5740 mbx_cmd_t mc;
5741 mbx_cmd_t *mcp = &mc;
5742
5743 if (!IS_MCTP_CAPABLE(vha->hw))
5744 return QLA_FUNCTION_FAILED;
5745
5746 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5747 "Entered %s.\n", __func__);
5748
5749 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5750 mcp->mb[1] = LSW(addr);
5751 mcp->mb[2] = MSW(req_dma);
5752 mcp->mb[3] = LSW(req_dma);
5753 mcp->mb[4] = MSW(size);
5754 mcp->mb[5] = LSW(size);
5755 mcp->mb[6] = MSW(MSD(req_dma));
5756 mcp->mb[7] = LSW(MSD(req_dma));
5757 mcp->mb[8] = MSW(addr);
5758 /* Setting RAM ID to valid */
5759 mcp->mb[10] |= BIT_7;
5760 /* For MCTP RAM ID is 0x40 */
5761 mcp->mb[10] |= 0x40;
5762
5763 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5764 MBX_0;
5765
5766 mcp->in_mb = MBX_0;
5767 mcp->tov = MBX_TOV_SECONDS;
5768 mcp->flags = 0;
5769 rval = qla2x00_mailbox_command(vha, mcp);
5770
5771 if (rval != QLA_SUCCESS) {
5772 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5773 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5774 } else {
5775 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5776 "Done %s.\n", __func__);
5777 }
5778
5779 return rval;
5780}
Joe Carnuccioec891462016-07-06 11:14:26 -04005781
5782int
5783qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5784 void *dd_buf, uint size, uint options)
5785{
5786 int rval;
5787 mbx_cmd_t mc;
5788 mbx_cmd_t *mcp = &mc;
5789 dma_addr_t dd_dma;
5790
5791 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5792 return QLA_FUNCTION_FAILED;
5793
Quinn Tran83548fe2017-06-02 09:12:01 -07005794 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04005795 "Entered %s.\n", __func__);
5796
Joe Carnuccioec891462016-07-06 11:14:26 -04005797 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5798 dd_buf, size, DMA_FROM_DEVICE);
5799 if (!dd_dma) {
5800 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5801 return QLA_MEMORY_ALLOC_FAILED;
5802 }
5803
5804 memset(dd_buf, 0, size);
5805
5806 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5807 mcp->mb[1] = options;
5808 mcp->mb[2] = MSW(LSD(dd_dma));
5809 mcp->mb[3] = LSW(LSD(dd_dma));
5810 mcp->mb[6] = MSW(MSD(dd_dma));
5811 mcp->mb[7] = LSW(MSD(dd_dma));
5812 mcp->mb[8] = size;
5813 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5814 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5815 mcp->buf_size = size;
5816 mcp->flags = MBX_DMA_IN;
5817 mcp->tov = MBX_TOV_SECONDS * 4;
5818 rval = qla2x00_mailbox_command(vha, mcp);
5819
5820 if (rval != QLA_SUCCESS) {
5821 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5822 } else {
5823 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5824 "Done %s.\n", __func__);
5825 }
5826
5827 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5828 size, DMA_FROM_DEVICE);
5829
5830 return rval;
5831}
Quinn Tran15f30a52017-03-15 09:48:52 -07005832
5833static void qla2x00_async_mb_sp_done(void *s, int res)
5834{
5835 struct srb *sp = s;
5836
5837 sp->u.iocb_cmd.u.mbx.rc = res;
5838
5839 complete(&sp->u.iocb_cmd.u.mbx.comp);
5840 /* don't free sp here. Let the caller do the free */
5841}
5842
5843/*
5844 * This mailbox uses the iocb interface to send MB command.
5845 * This allows non-critial (non chip setup) command to go
5846 * out in parrallel.
5847 */
5848int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
5849{
5850 int rval = QLA_FUNCTION_FAILED;
5851 srb_t *sp;
5852 struct srb_iocb *c;
5853
5854 if (!vha->hw->flags.fw_started)
5855 goto done;
5856
5857 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
5858 if (!sp)
5859 goto done;
5860
5861 sp->type = SRB_MB_IOCB;
5862 sp->name = mb_to_str(mcp->mb[0]);
5863
5864 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
5865
5866 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
5867
5868 c = &sp->u.iocb_cmd;
5869 c->timeout = qla2x00_async_iocb_timeout;
5870 init_completion(&c->u.mbx.comp);
5871
5872 sp->done = qla2x00_async_mb_sp_done;
5873
5874 rval = qla2x00_start_sp(sp);
5875 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005876 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07005877 "%s: %s Failed submission. %x.\n",
5878 __func__, sp->name, rval);
5879 goto done_free_sp;
5880 }
5881
Quinn Tran83548fe2017-06-02 09:12:01 -07005882 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005883 sp->name, sp->handle);
5884
5885 wait_for_completion(&c->u.mbx.comp);
5886 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
5887
5888 rval = c->u.mbx.rc;
5889 switch (rval) {
5890 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07005891 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005892 __func__, sp->name, rval);
5893 break;
5894 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07005895 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005896 __func__, sp->name);
5897 sp->free(sp);
5898 break;
5899 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07005900 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005901 __func__, sp->name, rval);
5902 sp->free(sp);
5903 break;
5904 }
5905
5906 return rval;
5907
5908done_free_sp:
5909 sp->free(sp);
5910done:
5911 return rval;
5912}
5913
5914/*
5915 * qla24xx_gpdb_wait
5916 * NOTE: Do not call this routine from DPC thread
5917 */
5918int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
5919{
5920 int rval = QLA_FUNCTION_FAILED;
5921 dma_addr_t pd_dma;
5922 struct port_database_24xx *pd;
5923 struct qla_hw_data *ha = vha->hw;
5924 mbx_cmd_t mc;
5925
5926 if (!vha->hw->flags.fw_started)
5927 goto done;
5928
5929 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
5930 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005931 ql_log(ql_log_warn, vha, 0xd047,
5932 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07005933 goto done_free_sp;
5934 }
5935 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
5936
5937 memset(&mc, 0, sizeof(mc));
5938 mc.mb[0] = MBC_GET_PORT_DATABASE;
5939 mc.mb[1] = cpu_to_le16(fcport->loop_id);
5940 mc.mb[2] = MSW(pd_dma);
5941 mc.mb[3] = LSW(pd_dma);
5942 mc.mb[6] = MSW(MSD(pd_dma));
5943 mc.mb[7] = LSW(MSD(pd_dma));
5944 mc.mb[9] = cpu_to_le16(vha->vp_idx);
5945 mc.mb[10] = cpu_to_le16((uint16_t)opt);
5946
5947 rval = qla24xx_send_mb_cmd(vha, &mc);
5948 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005949 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07005950 "%s: %8phC fail\n", __func__, fcport->port_name);
5951 goto done_free_sp;
5952 }
5953
5954 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
5955
Quinn Tran83548fe2017-06-02 09:12:01 -07005956 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07005957 __func__, fcport->port_name);
5958
5959done_free_sp:
5960 if (pd)
5961 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
5962done:
5963 return rval;
5964}
5965
5966int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
5967 struct port_database_24xx *pd)
5968{
5969 int rval = QLA_SUCCESS;
5970 uint64_t zero = 0;
5971
5972 /* Check for logged in state. */
5973 if (pd->current_login_state != PDS_PRLI_COMPLETE &&
5974 pd->last_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07005975 ql_dbg(ql_dbg_mbx, vha, 0x119a,
5976 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
5977 pd->current_login_state, pd->last_login_state,
5978 fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07005979 rval = QLA_FUNCTION_FAILED;
5980 goto gpd_error_out;
5981 }
5982
5983 if (fcport->loop_id == FC_NO_LOOP_ID ||
5984 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
5985 memcmp(fcport->port_name, pd->port_name, 8))) {
5986 /* We lost the device mid way. */
5987 rval = QLA_NOT_LOGGED_IN;
5988 goto gpd_error_out;
5989 }
5990
5991 /* Names are little-endian. */
5992 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
5993 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
5994
5995 /* Get port_id of device. */
5996 fcport->d_id.b.domain = pd->port_id[0];
5997 fcport->d_id.b.area = pd->port_id[1];
5998 fcport->d_id.b.al_pa = pd->port_id[2];
5999 fcport->d_id.b.rsvd_1 = 0;
6000
6001 /* If not target must be initiator or unknown type. */
6002 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6003 fcport->port_type = FCT_INITIATOR;
6004 else
6005 fcport->port_type = FCT_TARGET;
6006
6007 /* Passback COS information. */
6008 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6009 FC_COS_CLASS2 : FC_COS_CLASS3;
6010
6011 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6012 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6013 fcport->conf_compl_supported = 1;
6014 }
6015
6016gpd_error_out:
6017 return rval;
6018}
6019
6020/*
6021 * qla24xx_gidlist__wait
6022 * NOTE: don't call this routine from DPC thread.
6023 */
6024int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6025 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6026{
6027 int rval = QLA_FUNCTION_FAILED;
6028 mbx_cmd_t mc;
6029
6030 if (!vha->hw->flags.fw_started)
6031 goto done;
6032
6033 memset(&mc, 0, sizeof(mc));
6034 mc.mb[0] = MBC_GET_ID_LIST;
6035 mc.mb[2] = MSW(id_list_dma);
6036 mc.mb[3] = LSW(id_list_dma);
6037 mc.mb[6] = MSW(MSD(id_list_dma));
6038 mc.mb[7] = LSW(MSD(id_list_dma));
6039 mc.mb[8] = 0;
6040 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6041
6042 rval = qla24xx_send_mb_cmd(vha, &mc);
6043 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006044 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6045 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006046 } else {
6047 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006048 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6049 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006050 }
6051done:
6052 return rval;
6053}