blob: b3a9f6a40a448b2421207aa4810b37ca9eb93a10 [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
Bart Van Asscheca825822017-01-17 09:34:14 -080013static struct rom_cmd {
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080014 uint16_t cmd;
15} rom_cmds[] = {
16 { MBC_LOAD_RAM },
17 { MBC_EXECUTE_FIRMWARE },
18 { MBC_READ_RAM_WORD },
19 { MBC_MAILBOX_REGISTER_TEST },
20 { MBC_VERIFY_CHECKSUM },
21 { MBC_GET_FIRMWARE_VERSION },
22 { MBC_LOAD_RISC_RAM },
23 { MBC_DUMP_RISC_RAM },
24 { MBC_LOAD_RISC_RAM_EXTENDED },
25 { MBC_DUMP_RISC_RAM_EXTENDED },
26 { MBC_WRITE_RAM_WORD_EXTENDED },
27 { MBC_READ_RAM_EXTENDED },
28 { MBC_GET_RESOURCE_COUNTS },
29 { MBC_SET_FIRMWARE_OPTION },
30 { MBC_MID_INITIALIZE_FIRMWARE },
31 { MBC_GET_FIRMWARE_STATE },
32 { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
33 { MBC_GET_RETRY_COUNT },
34 { MBC_TRACE_CONTROL },
35};
36
37static int is_rom_cmd(uint16_t cmd)
38{
39 int i;
40 struct rom_cmd *wc;
41
42 for (i = 0; i < ARRAY_SIZE(rom_cmds); i++) {
43 wc = rom_cmds + i;
44 if (wc->cmd == cmd)
45 return 1;
46 }
47
48 return 0;
49}
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/*
52 * qla2x00_mailbox_command
53 * Issue mailbox command and waits for completion.
54 *
55 * Input:
56 * ha = adapter block pointer.
57 * mcp = driver internal mbx struct pointer.
58 *
59 * Output:
60 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
61 *
62 * Returns:
63 * 0 : QLA_SUCCESS = cmd performed success
64 * 1 : QLA_FUNCTION_FAILED (error encountered)
65 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
66 *
67 * Context:
68 * Kernel context.
69 */
70static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080071qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040073 int rval, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 unsigned long flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -050075 device_reg_t *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070076 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070077 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -070078 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 uint16_t *iptr;
80 uint16_t __iomem *optr;
81 uint32_t cnt;
82 uint32_t mboxes;
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040083 uint16_t __iomem *mbx_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080085 struct qla_hw_data *ha = vha->hw;
86 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070087
Himanshu Madhanid14e72f2015-04-09 15:00:03 -040088
Arun Easi5e19ed92012-02-09 11:15:51 -080089 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -070090
91 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -080092 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070093 "error_state is greater than pci_channel_io_frozen, "
94 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -070095 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -070096 }
Seokmann Jub9b12f72009-03-24 09:08:18 -070097
Giridhar Malavalia9083012010-04-12 17:59:55 -070098 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -080099 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700100 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700101 return QLA_FUNCTION_TIMEOUT;
102 }
103
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800104 /* if PCI error, then avoid mbx processing.*/
105 if (test_bit(PCI_ERR, &base_vha->dpc_flags)) {
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400106 ql_log(ql_log_warn, vha, 0x1191,
107 "PCI error, exiting.\n");
108 return QLA_FUNCTION_TIMEOUT;
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800109 }
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400110
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700111 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800112 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800115 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700117
Andrew Vasquez85880802009-12-15 21:29:46 -0800118 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800119 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700120 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800121 return QLA_FUNCTION_TIMEOUT;
122 }
123
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400124 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -0800125 /* Setting Link-Down error */
126 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -0800127 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700128 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -0800129 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -0800130 }
131
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800132 /* check if ISP abort is active and return cmd with timeout */
133 if ((test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
134 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
135 test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) &&
136 !is_rom_cmd(mcp->mb[0])) {
137 ql_log(ql_log_info, vha, 0x1005,
138 "Cmd 0x%x aborted with timeout since ISP Abort is pending\n",
139 mcp->mb[0]);
140 return QLA_FUNCTION_TIMEOUT;
141 }
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700144 * Wait for active mailbox commands to finish by waiting at most tov
145 * seconds. This is to serialize actual issuing of mailbox cmds during
146 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800148 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
149 /* Timeout occurred. Return error. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800150 ql_log(ql_log_warn, vha, 0x1005,
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800151 "Cmd access timeout, cmd=0x%x, Exiting.\n",
152 mcp->mb[0]);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800153 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155
156 ha->flags.mbox_busy = 1;
157 /* Save mailbox command for debug */
158 ha->mcp = mcp;
159
Arun Easi5e19ed92012-02-09 11:15:51 -0800160 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700161 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 spin_lock_irqsave(&ha->hardware_lock, flags);
164
165 /* Load mailbox registers. */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400166 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700167 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400168 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha)))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700169 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
170 else
171 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173 iptr = mcp->mb;
174 command = mcp->mb[0];
175 mboxes = mcp->out_mb;
176
Joe Carnuccio7b711622014-09-25 05:16:43 -0400177 ql_dbg(ql_dbg_mbx, vha, 0x1111,
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700178 "Mailbox registers (OUT):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
180 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700181 optr =
182 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700183 if (mboxes & BIT_0) {
184 ql_dbg(ql_dbg_mbx, vha, 0x1112,
185 "mbox[%d]<-0x%04x\n", cnt, *iptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 WRT_REG_WORD(optr, *iptr);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 mboxes >>= 1;
190 optr++;
191 iptr++;
192 }
193
Arun Easi5e19ed92012-02-09 11:15:51 -0800194 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700195 "I/O Address = %p.\n", optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 /* Issue set host interrupt command to send cmd out. */
198 ha->flags.mbox_int = 0;
199 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
200
201 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800202 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700203 "Going to unlock irq & waiting for interrupts. "
204 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 /* Wait for mbx cmd completion until timeout */
207
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800208 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
210
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400211 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700212 if (RD_REG_DWORD(&reg->isp82.hint) &
213 HINT_MBX_INT_PENDING) {
214 spin_unlock_irqrestore(&ha->hardware_lock,
215 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800216 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800217 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700218 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700219 rval = QLA_FUNCTION_TIMEOUT;
220 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700221 }
222 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
223 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700224 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
225 else
226 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 spin_unlock_irqrestore(&ha->hardware_lock, flags);
228
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800229 wait_time = jiffies;
Giridhar Malavali754d1242013-06-25 11:27:16 -0400230 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
231 mcp->tov * HZ)) {
232 ql_dbg(ql_dbg_mbx, vha, 0x117a,
233 "cmd=%x Timeout.\n", command);
234 spin_lock_irqsave(&ha->hardware_lock, flags);
235 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
236 spin_unlock_irqrestore(&ha->hardware_lock, flags);
237 }
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800238 if (time_after(jiffies, wait_time + 5 * HZ))
239 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
240 command, jiffies_to_msecs(jiffies - wait_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800242 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700243 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400245 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700246 if (RD_REG_DWORD(&reg->isp82.hint) &
247 HINT_MBX_INT_PENDING) {
248 spin_unlock_irqrestore(&ha->hardware_lock,
249 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800250 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800251 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700252 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700253 rval = QLA_FUNCTION_TIMEOUT;
254 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700255 }
256 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
257 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700258 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
259 else
260 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
264 while (!ha->flags.mbox_int) {
265 if (time_after(jiffies, wait_time))
266 break;
267
268 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800269 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Andrew Vasquez85880802009-12-15 21:29:46 -0800271 if (!ha->flags.mbox_int &&
272 !(IS_QLA2200(ha) &&
273 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800274 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800276 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700277 "Waited %d sec.\n",
278 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 /* Check whether we timed out */
282 if (ha->flags.mbox_int) {
283 uint16_t *iptr2;
284
Arun Easi5e19ed92012-02-09 11:15:51 -0800285 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700286 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
288 /* Got interrupt. Clear the flag. */
289 ha->flags.mbox_int = 0;
290 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
291
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400292 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700293 ha->flags.mbox_busy = 0;
294 /* Setting Link-Down error */
295 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
296 ha->mcp = NULL;
297 rval = QLA_FUNCTION_FAILED;
Arun Easi5e19ed92012-02-09 11:15:51 -0800298 ql_log(ql_log_warn, vha, 0x1015,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700299 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700300 goto premature_exit;
301 }
302
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400303 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
306 /* Load return mailbox registers. */
307 iptr2 = mcp->mb;
308 iptr = (uint16_t *)&ha->mailbox_out[0];
309 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700310
311 ql_dbg(ql_dbg_mbx, vha, 0x1113,
312 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700314 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700316 ql_dbg(ql_dbg_mbx, vha, 0x1114,
317 "mbox[%d]->0x%04x\n", cnt, *iptr2);
318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
320 mboxes >>= 1;
321 iptr2++;
322 iptr++;
323 }
324 } else {
325
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700326 uint16_t mb0;
327 uint32_t ictrl;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400328 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700329
Andrew Vasqueze4289242007-07-19 15:05:56 -0700330 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700331 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
332 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
333 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700334 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700335 ictrl = RD_REG_WORD(&reg->isp.ictrl);
336 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800337 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400338 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
339 "mb[0]=0x%x\n", command, ictrl, jiffies, mb0);
Arun Easi5e19ed92012-02-09 11:15:51 -0800340 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400342 /* Capture FW dump only, if PCI device active */
343 if (!pci_channel_offline(vha->hw->pdev)) {
344 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
345 if (w == 0xffff || ictrl == 0xffffffff) {
346 /* This is special case if there is unload
347 * of driver happening and if PCI device go
348 * into bad state due to PCI error condition
349 * then only PCI ERR flag would be set.
350 * we will do premature exit for above case.
351 */
352 if (test_bit(UNLOADING, &base_vha->dpc_flags))
353 set_bit(PCI_ERR, &base_vha->dpc_flags);
354 ha->flags.mbox_busy = 0;
355 rval = QLA_FUNCTION_TIMEOUT;
356 goto premature_exit;
357 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800358
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400359 /* Attempt to capture firmware dump for further
360 * anallysis of the current formware state. we do not
361 * need to do this if we are intentionally generating
362 * a dump
363 */
364 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
365 ha->isp_ops->fw_dump(vha, 0);
366 rval = QLA_FUNCTION_TIMEOUT;
367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 }
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 ha->flags.mbox_busy = 0;
371
372 /* Clean up */
373 ha->mcp = NULL;
374
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800375 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800376 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700377 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800380 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 }
382
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700383 if (rval == QLA_FUNCTION_TIMEOUT &&
384 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800385 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
386 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800388 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700389 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700390
391 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
392 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
393 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800394 if (IS_QLA82XX(ha)) {
395 ql_dbg(ql_dbg_mbx, vha, 0x112a,
396 "disabling pause transmit on port "
397 "0 & 1.\n");
398 qla82xx_wr_32(ha,
399 QLA82XX_CRB_NIU + 0x98,
400 CRB_NIU_XG_PAUSE_CTL_P0|
401 CRB_NIU_XG_PAUSE_CTL_P1);
402 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700403 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400404 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800405 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
406 "abort.\n", command, mcp->mb[0],
407 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700408 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
409 qla2xxx_wake_dpc(vha);
410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800413 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700414 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700416 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
417 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
418 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800419 if (IS_QLA82XX(ha)) {
420 ql_dbg(ql_dbg_mbx, vha, 0x112b,
421 "disabling pause transmit on port "
422 "0 & 1.\n");
423 qla82xx_wr_32(ha,
424 QLA82XX_CRB_NIU + 0x98,
425 CRB_NIU_XG_PAUSE_CTL_P0|
426 CRB_NIU_XG_PAUSE_CTL_P1);
427 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700428 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400429 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800430 "mb[0]=0x%x. Scheduling ISP abort ",
431 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700432 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
433 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800434 /* Allow next mbx cmd to come in. */
435 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700436 if (ha->isp_ops->abort_isp(vha)) {
437 /* Failed. retry later. */
438 set_bit(ISP_ABORT_NEEDED,
439 &vha->dpc_flags);
440 }
441 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800442 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700443 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800444 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
447 }
448
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700449premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800451 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Giridhar Malavalid3360962012-02-09 11:14:10 -0800453mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 if (rval) {
Chad Dupuis34c58012014-08-08 07:38:08 -0400455 ql_dbg(ql_dbg_disc, base_vha, 0x1020,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800456 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
457 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400458
Sawan Chandak75d560e2016-07-06 11:14:33 -0400459 ql_dbg(ql_dbg_mbx, vha, 0x1198,
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400460 "host status: 0x%x, flags:0x%lx, intr ctrl reg:0x%x, intr status:0x%x\n",
461 RD_REG_DWORD(&reg->isp24.host_status),
462 ha->fw_dump_cap_flags,
463 RD_REG_DWORD(&reg->isp24.ictrl),
464 RD_REG_DWORD(&reg->isp24.istatus));
465
466 mbx_reg = &reg->isp24.mailbox0;
467 for (i = 0; i < 6; i++)
Sawan Chandak75d560e2016-07-06 11:14:33 -0400468 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1199,
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400469 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700471 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return rval;
475}
476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800478qla2x00_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 -0800479 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800482 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 mbx_cmd_t mc;
484 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400486 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
487 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
Andrew Vasqueze4289242007-07-19 15:05:56 -0700489 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800490 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
491 mcp->mb[8] = MSW(risc_addr);
492 mcp->out_mb = MBX_8|MBX_0;
493 } else {
494 mcp->mb[0] = MBC_LOAD_RISC_RAM;
495 mcp->out_mb = MBX_0;
496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 mcp->mb[1] = LSW(risc_addr);
498 mcp->mb[2] = MSW(req_dma);
499 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 mcp->mb[6] = MSW(MSD(req_dma));
501 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800502 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700503 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700504 mcp->mb[4] = MSW(risc_code_size);
505 mcp->mb[5] = LSW(risc_code_size);
506 mcp->out_mb |= MBX_5|MBX_4;
507 } else {
508 mcp->mb[4] = LSW(risc_code_size);
509 mcp->out_mb |= MBX_4;
510 }
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700513 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800515 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700518 ql_dbg(ql_dbg_mbx, vha, 0x1023,
519 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400521 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
522 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
525 return rval;
526}
527
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700528#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529/*
530 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700531 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 *
533 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700534 * ha = adapter block pointer.
535 * TARGET_QUEUE_LOCK must be released.
536 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 *
538 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700539 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 *
541 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700542 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 */
544int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800545qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
547 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800548 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 mbx_cmd_t mc;
550 mbx_cmd_t *mcp = &mc;
551
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400552 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
553 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
555 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700556 mcp->out_mb = MBX_0;
557 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700558 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700559 mcp->mb[1] = MSW(risc_addr);
560 mcp->mb[2] = LSW(risc_addr);
561 mcp->mb[3] = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500562 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
563 IS_QLA27XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700564 struct nvram_81xx *nv = ha->nvram;
565 mcp->mb[4] = (nv->enhanced_features &
566 EXTENDED_BB_CREDITS);
567 } else
568 mcp->mb[4] = 0;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500569
570 if (ha->flags.exlogins_enabled)
571 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
572
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500573 if (ha->flags.exchoffld_enabled)
574 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
575
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700576 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700577 mcp->in_mb |= MBX_1;
578 } else {
579 mcp->mb[1] = LSW(risc_addr);
580 mcp->out_mb |= MBX_1;
581 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
582 mcp->mb[2] = 0;
583 mcp->out_mb |= MBX_2;
584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586
Ravi Anandb93480e2008-04-03 13:13:25 -0700587 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800589 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700591 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700592 ql_dbg(ql_dbg_mbx, vha, 0x1026,
593 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700594 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700595 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400596 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700597 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700598 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400599 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
600 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700601 }
602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 return rval;
605}
606
607/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500608 * qla_get_exlogin_status
609 * Get extended login status
610 * uses the memory offload control/status Mailbox
611 *
612 * Input:
613 * ha: adapter state pointer.
614 * fwopt: firmware options
615 *
616 * Returns:
617 * qla2x00 local function status
618 *
619 * Context:
620 * Kernel context.
621 */
622#define FETCH_XLOGINS_STAT 0x8
623int
624qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
625 uint16_t *ex_logins_cnt)
626{
627 int rval;
628 mbx_cmd_t mc;
629 mbx_cmd_t *mcp = &mc;
630
631 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
632 "Entered %s\n", __func__);
633
634 memset(mcp->mb, 0 , sizeof(mcp->mb));
635 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
636 mcp->mb[1] = FETCH_XLOGINS_STAT;
637 mcp->out_mb = MBX_1|MBX_0;
638 mcp->in_mb = MBX_10|MBX_4|MBX_0;
639 mcp->tov = MBX_TOV_SECONDS;
640 mcp->flags = 0;
641
642 rval = qla2x00_mailbox_command(vha, mcp);
643 if (rval != QLA_SUCCESS) {
644 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
645 } else {
646 *buf_sz = mcp->mb[4];
647 *ex_logins_cnt = mcp->mb[10];
648
649 ql_log(ql_log_info, vha, 0x1190,
650 "buffer size 0x%x, exchange login count=%d\n",
651 mcp->mb[4], mcp->mb[10]);
652
653 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
654 "Done %s.\n", __func__);
655 }
656
657 return rval;
658}
659
660/*
661 * qla_set_exlogin_mem_cfg
662 * set extended login memory configuration
663 * Mbx needs to be issues before init_cb is set
664 *
665 * Input:
666 * ha: adapter state pointer.
667 * buffer: buffer pointer
668 * phys_addr: physical address of buffer
669 * size: size of buffer
670 * TARGET_QUEUE_LOCK must be released
671 * ADAPTER_STATE_LOCK must be release
672 *
673 * Returns:
674 * qla2x00 local funxtion status code.
675 *
676 * Context:
677 * Kernel context.
678 */
679#define CONFIG_XLOGINS_MEM 0x3
680int
681qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
682{
683 int rval;
684 mbx_cmd_t mc;
685 mbx_cmd_t *mcp = &mc;
686 struct qla_hw_data *ha = vha->hw;
687 int configured_count;
688
689 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
690 "Entered %s.\n", __func__);
691
692 memset(mcp->mb, 0 , sizeof(mcp->mb));
693 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
694 mcp->mb[1] = CONFIG_XLOGINS_MEM;
695 mcp->mb[2] = MSW(phys_addr);
696 mcp->mb[3] = LSW(phys_addr);
697 mcp->mb[6] = MSW(MSD(phys_addr));
698 mcp->mb[7] = LSW(MSD(phys_addr));
699 mcp->mb[8] = MSW(ha->exlogin_size);
700 mcp->mb[9] = LSW(ha->exlogin_size);
701 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
702 mcp->in_mb = MBX_11|MBX_0;
703 mcp->tov = MBX_TOV_SECONDS;
704 mcp->flags = 0;
705 rval = qla2x00_mailbox_command(vha, mcp);
706 if (rval != QLA_SUCCESS) {
707 /*EMPTY*/
708 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
709 } else {
710 configured_count = mcp->mb[11];
711 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
712 "Done %s.\n", __func__);
713 }
714
715 return rval;
716}
717
718/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500719 * qla_get_exchoffld_status
720 * Get exchange offload status
721 * uses the memory offload control/status Mailbox
722 *
723 * Input:
724 * ha: adapter state pointer.
725 * fwopt: firmware options
726 *
727 * Returns:
728 * qla2x00 local function status
729 *
730 * Context:
731 * Kernel context.
732 */
733#define FETCH_XCHOFFLD_STAT 0x2
734int
735qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
736 uint16_t *ex_logins_cnt)
737{
738 int rval;
739 mbx_cmd_t mc;
740 mbx_cmd_t *mcp = &mc;
741
742 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
743 "Entered %s\n", __func__);
744
745 memset(mcp->mb, 0 , sizeof(mcp->mb));
746 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
747 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
748 mcp->out_mb = MBX_1|MBX_0;
749 mcp->in_mb = MBX_10|MBX_4|MBX_0;
750 mcp->tov = MBX_TOV_SECONDS;
751 mcp->flags = 0;
752
753 rval = qla2x00_mailbox_command(vha, mcp);
754 if (rval != QLA_SUCCESS) {
755 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
756 } else {
757 *buf_sz = mcp->mb[4];
758 *ex_logins_cnt = mcp->mb[10];
759
760 ql_log(ql_log_info, vha, 0x118e,
761 "buffer size 0x%x, exchange offload count=%d\n",
762 mcp->mb[4], mcp->mb[10]);
763
764 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
765 "Done %s.\n", __func__);
766 }
767
768 return rval;
769}
770
771/*
772 * qla_set_exchoffld_mem_cfg
773 * Set exchange offload memory configuration
774 * Mbx needs to be issues before init_cb is set
775 *
776 * Input:
777 * ha: adapter state pointer.
778 * buffer: buffer pointer
779 * phys_addr: physical address of buffer
780 * size: size of buffer
781 * TARGET_QUEUE_LOCK must be released
782 * ADAPTER_STATE_LOCK must be release
783 *
784 * Returns:
785 * qla2x00 local funxtion status code.
786 *
787 * Context:
788 * Kernel context.
789 */
790#define CONFIG_XCHOFFLD_MEM 0x3
791int
792qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
793{
794 int rval;
795 mbx_cmd_t mc;
796 mbx_cmd_t *mcp = &mc;
797 struct qla_hw_data *ha = vha->hw;
798
799 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
800 "Entered %s.\n", __func__);
801
802 memset(mcp->mb, 0 , sizeof(mcp->mb));
803 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
804 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
805 mcp->mb[2] = MSW(phys_addr);
806 mcp->mb[3] = LSW(phys_addr);
807 mcp->mb[6] = MSW(MSD(phys_addr));
808 mcp->mb[7] = LSW(MSD(phys_addr));
809 mcp->mb[8] = MSW(ha->exlogin_size);
810 mcp->mb[9] = LSW(ha->exlogin_size);
811 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
812 mcp->in_mb = MBX_11|MBX_0;
813 mcp->tov = MBX_TOV_SECONDS;
814 mcp->flags = 0;
815 rval = qla2x00_mailbox_command(vha, mcp);
816 if (rval != QLA_SUCCESS) {
817 /*EMPTY*/
818 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
819 } else {
820 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
821 "Done %s.\n", __func__);
822 }
823
824 return rval;
825}
826
827/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 * qla2x00_get_fw_version
829 * Get firmware version.
830 *
831 * Input:
832 * ha: adapter state pointer.
833 * major: pointer for major number.
834 * minor: pointer for minor number.
835 * subminor: pointer for subminor number.
836 *
837 * Returns:
838 * qla2x00 local function return status code.
839 *
840 * Context:
841 * Kernel context.
842 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700843int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800844qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845{
846 int rval;
847 mbx_cmd_t mc;
848 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800849 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400851 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
852 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
854 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
855 mcp->out_mb = MBX_0;
856 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400857 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700858 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400859 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800860 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500861 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400862 mcp->in_mb |=
863 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
864 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -0400865
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700867 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800868 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700869 if (rval != QLA_SUCCESS)
870 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800873 ha->fw_major_version = mcp->mb[1];
874 ha->fw_minor_version = mcp->mb[2];
875 ha->fw_subminor_version = mcp->mb[3];
876 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800877 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800878 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800880 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -0400881
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400882 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800883 ha->mpi_version[0] = mcp->mb[10] & 0xff;
884 ha->mpi_version[1] = mcp->mb[11] >> 8;
885 ha->mpi_version[2] = mcp->mb[11] & 0xff;
886 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
887 ha->phy_version[0] = mcp->mb[8] & 0xff;
888 ha->phy_version[1] = mcp->mb[9] >> 8;
889 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800890 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400891
Saurav Kashyap81178772012-08-22 14:21:04 -0400892 if (IS_FWI2_CAPABLE(ha)) {
893 ha->fw_attributes_h = mcp->mb[15];
894 ha->fw_attributes_ext[0] = mcp->mb[16];
895 ha->fw_attributes_ext[1] = mcp->mb[17];
896 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
897 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
898 __func__, mcp->mb[15], mcp->mb[6]);
899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
900 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
901 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500902
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500903 if (ha->fw_attributes_h & 0x4)
904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
905 "%s: Firmware supports Extended Login 0x%x\n",
906 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500907
908 if (ha->fw_attributes_h & 0x8)
909 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
910 "%s: Firmware supports Exchange Offload 0x%x\n",
911 __func__, ha->fw_attributes_h);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800912 }
Sawan Chandak03aa8682015-08-04 13:37:59 -0400913
Chad Dupuisf73cb692014-02-26 04:15:06 -0500914 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -0400915 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->pep_version[0] = mcp->mb[13] & 0xff;
919 ha->pep_version[1] = mcp->mb[14] >> 8;
920 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500921 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
922 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -0400923 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
924 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -0500925 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800926
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700927failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 if (rval != QLA_SUCCESS) {
929 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700930 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 } else {
932 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400933 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
934 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700936 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939/*
940 * qla2x00_get_fw_options
941 * Set firmware options.
942 *
943 * Input:
944 * ha = adapter block pointer.
945 * fwopt = pointer for firmware options.
946 *
947 * Returns:
948 * qla2x00 local function return status code.
949 *
950 * Context:
951 * Kernel context.
952 */
953int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800954qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955{
956 int rval;
957 mbx_cmd_t mc;
958 mbx_cmd_t *mcp = &mc;
959
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400960 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
961 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
964 mcp->out_mb = MBX_0;
965 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700966 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800968 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 if (rval != QLA_SUCCESS) {
971 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700972 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700974 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 fwopts[1] = mcp->mb[1];
976 fwopts[2] = mcp->mb[2];
977 fwopts[3] = mcp->mb[3];
978
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400979 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
980 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
982
983 return rval;
984}
985
986
987/*
988 * qla2x00_set_fw_options
989 * Set firmware options.
990 *
991 * Input:
992 * ha = adapter block pointer.
993 * fwopt = pointer for firmware options.
994 *
995 * Returns:
996 * qla2x00 local function return status code.
997 *
998 * Context:
999 * Kernel context.
1000 */
1001int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001002qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003{
1004 int rval;
1005 mbx_cmd_t mc;
1006 mbx_cmd_t *mcp = &mc;
1007
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001008 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1009 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
1011 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1012 mcp->mb[1] = fwopts[1];
1013 mcp->mb[2] = fwopts[2];
1014 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001015 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001017 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001018 mcp->in_mb |= MBX_1;
1019 } else {
1020 mcp->mb[10] = fwopts[10];
1021 mcp->mb[11] = fwopts[11];
1022 mcp->mb[12] = 0; /* Undocumented, but used */
1023 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1024 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001025 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001027 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001029 fwopts[0] = mcp->mb[0];
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (rval != QLA_SUCCESS) {
1032 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001033 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1034 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 } else {
1036 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001037 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1038 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040
1041 return rval;
1042}
1043
1044/*
1045 * qla2x00_mbx_reg_test
1046 * Mailbox register wrap test.
1047 *
1048 * Input:
1049 * ha = adapter block pointer.
1050 * TARGET_QUEUE_LOCK must be released.
1051 * ADAPTER_STATE_LOCK must be released.
1052 *
1053 * Returns:
1054 * qla2x00 local function return status code.
1055 *
1056 * Context:
1057 * Kernel context.
1058 */
1059int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001060qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 int rval;
1063 mbx_cmd_t mc;
1064 mbx_cmd_t *mcp = &mc;
1065
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001066 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1067 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1070 mcp->mb[1] = 0xAAAA;
1071 mcp->mb[2] = 0x5555;
1072 mcp->mb[3] = 0xAA55;
1073 mcp->mb[4] = 0x55AA;
1074 mcp->mb[5] = 0xA5A5;
1075 mcp->mb[6] = 0x5A5A;
1076 mcp->mb[7] = 0x2525;
1077 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1078 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 -07001079 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001081 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082
1083 if (rval == QLA_SUCCESS) {
1084 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1085 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1086 rval = QLA_FUNCTION_FAILED;
1087 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1088 mcp->mb[7] != 0x2525)
1089 rval = QLA_FUNCTION_FAILED;
1090 }
1091
1092 if (rval != QLA_SUCCESS) {
1093 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001094 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 } else {
1096 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1098 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 }
1100
1101 return rval;
1102}
1103
1104/*
1105 * qla2x00_verify_checksum
1106 * Verify firmware checksum.
1107 *
1108 * Input:
1109 * ha = adapter block pointer.
1110 * TARGET_QUEUE_LOCK must be released.
1111 * ADAPTER_STATE_LOCK must be released.
1112 *
1113 * Returns:
1114 * qla2x00 local function return status code.
1115 *
1116 * Context:
1117 * Kernel context.
1118 */
1119int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001120qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121{
1122 int rval;
1123 mbx_cmd_t mc;
1124 mbx_cmd_t *mcp = &mc;
1125
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001126 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1127 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128
1129 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001130 mcp->out_mb = MBX_0;
1131 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001132 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001133 mcp->mb[1] = MSW(risc_addr);
1134 mcp->mb[2] = LSW(risc_addr);
1135 mcp->out_mb |= MBX_2|MBX_1;
1136 mcp->in_mb |= MBX_2|MBX_1;
1137 } else {
1138 mcp->mb[1] = LSW(risc_addr);
1139 mcp->out_mb |= MBX_1;
1140 mcp->in_mb |= MBX_1;
1141 }
1142
Ravi Anandb93480e2008-04-03 13:13:25 -07001143 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001145 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
1147 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001148 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1149 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1150 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001152 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1153 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 }
1155
1156 return rval;
1157}
1158
1159/*
1160 * qla2x00_issue_iocb
1161 * Issue IOCB using mailbox command
1162 *
1163 * Input:
1164 * ha = adapter state pointer.
1165 * buffer = buffer pointer.
1166 * phys_addr = physical address of buffer.
1167 * size = size of buffer.
1168 * TARGET_QUEUE_LOCK must be released.
1169 * ADAPTER_STATE_LOCK must be released.
1170 *
1171 * Returns:
1172 * qla2x00 local function return status code.
1173 *
1174 * Context:
1175 * Kernel context.
1176 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001177int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001178qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001179 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
1181 int rval;
1182 mbx_cmd_t mc;
1183 mbx_cmd_t *mcp = &mc;
1184
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001185 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1186 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1189 mcp->mb[1] = 0;
1190 mcp->mb[2] = MSW(phys_addr);
1191 mcp->mb[3] = LSW(phys_addr);
1192 mcp->mb[6] = MSW(MSD(phys_addr));
1193 mcp->mb[7] = LSW(MSD(phys_addr));
1194 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1195 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001196 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001198 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 if (rval != QLA_SUCCESS) {
1201 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001202 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001204 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1205
1206 /* Mask reserved bits. */
1207 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001208 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001209 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1210 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 }
1212
1213 return rval;
1214}
1215
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001216int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001217qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001218 size_t size)
1219{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001220 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001221 MBX_TOV_SECONDS);
1222}
1223
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224/*
1225 * qla2x00_abort_command
1226 * Abort command aborts a specified IOCB.
1227 *
1228 * Input:
1229 * ha = adapter block pointer.
1230 * sp = SB structure pointer.
1231 *
1232 * Returns:
1233 * qla2x00 local function return status code.
1234 *
1235 * Context:
1236 * Kernel context.
1237 */
1238int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001239qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240{
1241 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001243 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 mbx_cmd_t mc;
1245 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001246 fc_port_t *fcport = sp->fcport;
1247 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001248 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001249 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001250 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001252 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1253 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Michael Hernandezd7459522016-12-12 14:40:07 -08001255 if (vha->flags.qpairs_available && sp->qpair)
1256 req = sp->qpair->req;
1257 else
1258 req = vha->req;
1259
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001260 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001261 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001262 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 break;
1264 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001265 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
Chad Dupuis8d93f552013-01-30 03:34:37 -05001267 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 /* command not found */
1269 return QLA_FUNCTION_FAILED;
1270 }
1271
1272 mcp->mb[0] = MBC_ABORT_COMMAND;
1273 if (HAS_EXTENDED_IDS(ha))
1274 mcp->mb[1] = fcport->loop_id;
1275 else
1276 mcp->mb[1] = fcport->loop_id << 8;
1277 mcp->mb[2] = (uint16_t)handle;
1278 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001279 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1281 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001282 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001284 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001287 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001289 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1290 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 }
1292
1293 return rval;
1294}
1295
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001297qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001299 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 mbx_cmd_t mc;
1301 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001302 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001303 struct req_que *req;
1304 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Andrew Vasquez523ec772008-04-03 13:13:24 -07001306 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001307 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001308
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001309 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1310 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001311
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001312 req = vha->hw->req_q_map[0];
1313 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001315 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001316 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 mcp->mb[1] = fcport->loop_id;
1318 mcp->mb[10] = 0;
1319 mcp->out_mb |= MBX_10;
1320 } else {
1321 mcp->mb[1] = fcport->loop_id << 8;
1322 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001323 mcp->mb[2] = vha->hw->loop_reset_delay;
1324 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
1326 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001327 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001329 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001331 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1332 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001333 }
1334
1335 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001336 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1337 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001338 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001339 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1340 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001342 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1343 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001344 }
1345
1346 return rval;
1347}
1348
1349int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001350qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001351{
1352 int rval, rval2;
1353 mbx_cmd_t mc;
1354 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001355 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001356 struct req_que *req;
1357 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001358
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001359 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001360
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001361 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1362 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001363
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001364 req = vha->hw->req_q_map[0];
1365 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001366 mcp->mb[0] = MBC_LUN_RESET;
1367 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001368 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001369 mcp->mb[1] = fcport->loop_id;
1370 else
1371 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001372 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001373 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001374 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001375
1376 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001377 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001378 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001379 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001380 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001381 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001382 }
1383
1384 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001385 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1386 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001387 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001388 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1389 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001390 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1392 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 }
1394
1395 return rval;
1396}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 * qla2x00_get_adapter_id
1400 * Get adapter ID and topology.
1401 *
1402 * Input:
1403 * ha = adapter block pointer.
1404 * id = pointer for loop ID.
1405 * al_pa = pointer for AL_PA.
1406 * area = pointer for area.
1407 * domain = pointer for domain.
1408 * top = pointer for topology.
1409 * TARGET_QUEUE_LOCK must be released.
1410 * ADAPTER_STATE_LOCK must be released.
1411 *
1412 * Returns:
1413 * qla2x00 local function return status code.
1414 *
1415 * Context:
1416 * Kernel context.
1417 */
1418int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001419qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001420 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
1422 int rval;
1423 mbx_cmd_t mc;
1424 mbx_cmd_t *mcp = &mc;
1425
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001426 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1427 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
1429 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001430 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001431 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001432 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001433 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001434 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001435 if (IS_FWI2_CAPABLE(vha->hw))
1436 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001437 if (IS_QLA27XX(vha->hw))
1438 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001439 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001441 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001442 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1443 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001444 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1445 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
1447 /* Return data. */
1448 *id = mcp->mb[1];
1449 *al_pa = LSB(mcp->mb[2]);
1450 *area = MSB(mcp->mb[2]);
1451 *domain = LSB(mcp->mb[3]);
1452 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001453 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
1455 if (rval != QLA_SUCCESS) {
1456 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001459 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1460 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001461
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001462 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001463 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1464 vha->fcoe_fcf_idx = mcp->mb[10];
1465 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1466 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1467 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1468 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1469 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1470 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1471 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001472 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001473 if (IS_FAWWN_CAPABLE(vha->hw)) {
1474 if (mcp->mb[7] & BIT_14) {
1475 vha->port_name[0] = MSB(mcp->mb[16]);
1476 vha->port_name[1] = LSB(mcp->mb[16]);
1477 vha->port_name[2] = MSB(mcp->mb[17]);
1478 vha->port_name[3] = LSB(mcp->mb[17]);
1479 vha->port_name[4] = MSB(mcp->mb[18]);
1480 vha->port_name[5] = LSB(mcp->mb[18]);
1481 vha->port_name[6] = MSB(mcp->mb[19]);
1482 vha->port_name[7] = LSB(mcp->mb[19]);
1483 fc_host_port_name(vha->host) =
1484 wwn_to_u64(vha->port_name);
1485 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1486 "FA-WWN acquired %016llx\n",
1487 wwn_to_u64(vha->port_name));
1488 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001489 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001490
1491 if (IS_QLA27XX(vha->hw))
1492 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 }
1494
1495 return rval;
1496}
1497
1498/*
1499 * qla2x00_get_retry_cnt
1500 * Get current firmware login retry count and delay.
1501 *
1502 * Input:
1503 * ha = adapter block pointer.
1504 * retry_cnt = pointer to login retry count.
1505 * tov = pointer to login timeout value.
1506 *
1507 * Returns:
1508 * qla2x00 local function return status code.
1509 *
1510 * Context:
1511 * Kernel context.
1512 */
1513int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001514qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 uint16_t *r_a_tov)
1516{
1517 int rval;
1518 uint16_t ratov;
1519 mbx_cmd_t mc;
1520 mbx_cmd_t *mcp = &mc;
1521
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001522 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1523 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
1525 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1526 mcp->out_mb = MBX_0;
1527 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001528 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001530 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532 if (rval != QLA_SUCCESS) {
1533 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001534 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1535 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 } else {
1537 /* Convert returned data and check our values. */
1538 *r_a_tov = mcp->mb[3] / 2;
1539 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1540 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1541 /* Update to the larger values */
1542 *retry_cnt = (uint8_t)mcp->mb[1];
1543 *tov = ratov;
1544 }
1545
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001546 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001547 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 }
1549
1550 return rval;
1551}
1552
1553/*
1554 * qla2x00_init_firmware
1555 * Initialize adapter firmware.
1556 *
1557 * Input:
1558 * ha = adapter block pointer.
1559 * dptr = Initialization control block pointer.
1560 * size = size of initialization control block.
1561 * TARGET_QUEUE_LOCK must be released.
1562 * ADAPTER_STATE_LOCK must be released.
1563 *
1564 * Returns:
1565 * qla2x00 local function return status code.
1566 *
1567 * Context:
1568 * Kernel context.
1569 */
1570int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001571qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572{
1573 int rval;
1574 mbx_cmd_t mc;
1575 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001576 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001578 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1579 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001581 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001582 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001583 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1584
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001585 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001586 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1587 else
1588 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1589
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001590 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 mcp->mb[2] = MSW(ha->init_cb_dma);
1592 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1594 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001595 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001596 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001597 mcp->mb[1] = BIT_0;
1598 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1599 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1600 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1601 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1602 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1603 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1604 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001605 /* 1 and 2 should normally be captured. */
1606 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001607 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001608 /* mb3 is additional info about the installed SFP. */
1609 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 mcp->buf_size = size;
1611 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001612 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001613 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
1615 if (rval != QLA_SUCCESS) {
1616 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001617 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001618 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1619 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 } else {
1621 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001622 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1623 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 }
1625
1626 return rval;
1627}
1628
1629/*
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001630 * qla2x00_get_node_name_list
1631 * Issue get node name list mailbox command, kmalloc()
1632 * and return the resulting list. Caller must kfree() it!
1633 *
1634 * Input:
1635 * ha = adapter state pointer.
1636 * out_data = resulting list
1637 * out_len = length of the resulting list
1638 *
1639 * Returns:
1640 * qla2x00 local function return status code.
1641 *
1642 * Context:
1643 * Kernel context.
1644 */
1645int
1646qla2x00_get_node_name_list(scsi_qla_host_t *vha, void **out_data, int *out_len)
1647{
1648 struct qla_hw_data *ha = vha->hw;
1649 struct qla_port_24xx_data *list = NULL;
1650 void *pmap;
1651 mbx_cmd_t mc;
1652 dma_addr_t pmap_dma;
1653 ulong dma_size;
1654 int rval, left;
1655
1656 left = 1;
1657 while (left > 0) {
1658 dma_size = left * sizeof(*list);
1659 pmap = dma_alloc_coherent(&ha->pdev->dev, dma_size,
1660 &pmap_dma, GFP_KERNEL);
1661 if (!pmap) {
1662 ql_log(ql_log_warn, vha, 0x113f,
1663 "%s(%ld): DMA Alloc failed of %ld\n",
1664 __func__, vha->host_no, dma_size);
1665 rval = QLA_MEMORY_ALLOC_FAILED;
1666 goto out;
1667 }
1668
1669 mc.mb[0] = MBC_PORT_NODE_NAME_LIST;
1670 mc.mb[1] = BIT_1 | BIT_3;
1671 mc.mb[2] = MSW(pmap_dma);
1672 mc.mb[3] = LSW(pmap_dma);
1673 mc.mb[6] = MSW(MSD(pmap_dma));
1674 mc.mb[7] = LSW(MSD(pmap_dma));
1675 mc.mb[8] = dma_size;
1676 mc.out_mb = MBX_0|MBX_1|MBX_2|MBX_3|MBX_6|MBX_7|MBX_8;
1677 mc.in_mb = MBX_0|MBX_1;
1678 mc.tov = 30;
1679 mc.flags = MBX_DMA_IN;
1680
1681 rval = qla2x00_mailbox_command(vha, &mc);
1682 if (rval != QLA_SUCCESS) {
1683 if ((mc.mb[0] == MBS_COMMAND_ERROR) &&
1684 (mc.mb[1] == 0xA)) {
1685 left += le16_to_cpu(mc.mb[2]) /
1686 sizeof(struct qla_port_24xx_data);
1687 goto restart;
1688 }
1689 goto out_free;
1690 }
1691
1692 left = 0;
1693
Benoit Tainec1818f12014-05-26 17:21:16 +02001694 list = kmemdup(pmap, dma_size, GFP_KERNEL);
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001695 if (!list) {
1696 ql_log(ql_log_warn, vha, 0x1140,
1697 "%s(%ld): failed to allocate node names list "
1698 "structure.\n", __func__, vha->host_no);
1699 rval = QLA_MEMORY_ALLOC_FAILED;
1700 goto out_free;
1701 }
1702
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001703restart:
1704 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1705 }
1706
1707 *out_data = list;
1708 *out_len = dma_size;
1709
1710out:
1711 return rval;
1712
1713out_free:
1714 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1715 return rval;
1716}
1717
1718/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 * qla2x00_get_port_database
1720 * Issue normal/enhanced get port database mailbox command
1721 * and copy device name as necessary.
1722 *
1723 * Input:
1724 * ha = adapter state pointer.
1725 * dev = structure pointer.
1726 * opt = enhanced cmd option byte.
1727 *
1728 * Returns:
1729 * qla2x00 local function return status code.
1730 *
1731 * Context:
1732 * Kernel context.
1733 */
1734int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001735qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736{
1737 int rval;
1738 mbx_cmd_t mc;
1739 mbx_cmd_t *mcp = &mc;
1740 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001741 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001743 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1746 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001748 pd24 = NULL;
1749 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001751 ql_log(ql_log_warn, vha, 0x1050,
1752 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 return QLA_MEMORY_ALLOC_FAILED;
1754 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001755 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001757 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001758 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 mcp->mb[2] = MSW(pd_dma);
1761 mcp->mb[3] = LSW(pd_dma);
1762 mcp->mb[6] = MSW(MSD(pd_dma));
1763 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001764 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001765 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001767 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001768 mcp->mb[1] = fcport->loop_id;
1769 mcp->mb[10] = opt;
1770 mcp->out_mb |= MBX_10|MBX_1;
1771 mcp->in_mb |= MBX_1;
1772 } else if (HAS_EXTENDED_IDS(ha)) {
1773 mcp->mb[1] = fcport->loop_id;
1774 mcp->mb[10] = opt;
1775 mcp->out_mb |= MBX_10|MBX_1;
1776 } else {
1777 mcp->mb[1] = fcport->loop_id << 8 | opt;
1778 mcp->out_mb |= MBX_1;
1779 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001780 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1781 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 mcp->flags = MBX_DMA_IN;
1783 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001784 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 if (rval != QLA_SUCCESS)
1786 goto gpd_error_out;
1787
Andrew Vasqueze4289242007-07-19 15:05:56 -07001788 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001789 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001790 pd24 = (struct port_database_24xx *) pd;
1791
1792 /* Check for logged in state. */
1793 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1794 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001795 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1796 "Unable to verify login-state (%x/%x) for "
1797 "loop_id %x.\n", pd24->current_login_state,
1798 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001799 rval = QLA_FUNCTION_FAILED;
1800 goto gpd_error_out;
1801 }
1802
Arun Easi0eba25d2012-02-09 11:15:58 -08001803 if (fcport->loop_id == FC_NO_LOOP_ID ||
1804 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1805 memcmp(fcport->port_name, pd24->port_name, 8))) {
1806 /* We lost the device mid way. */
1807 rval = QLA_NOT_LOGGED_IN;
1808 goto gpd_error_out;
1809 }
1810
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001811 /* Names are little-endian. */
1812 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1813 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1814
1815 /* Get port_id of device. */
1816 fcport->d_id.b.domain = pd24->port_id[0];
1817 fcport->d_id.b.area = pd24->port_id[1];
1818 fcport->d_id.b.al_pa = pd24->port_id[2];
1819 fcport->d_id.b.rsvd_1 = 0;
1820
1821 /* If not target must be initiator or unknown type. */
1822 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1823 fcport->port_type = FCT_INITIATOR;
1824 else
1825 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001826
1827 /* Passback COS information. */
1828 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1829 FC_COS_CLASS2 : FC_COS_CLASS3;
1830
1831 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1832 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001833 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001834 uint64_t zero = 0;
1835
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001836 /* Check for logged in state. */
1837 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1838 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001839 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1840 "Unable to verify login-state (%x/%x) - "
1841 "portid=%02x%02x%02x.\n", pd->master_state,
1842 pd->slave_state, fcport->d_id.b.domain,
1843 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001844 rval = QLA_FUNCTION_FAILED;
1845 goto gpd_error_out;
1846 }
1847
Arun Easi0eba25d2012-02-09 11:15:58 -08001848 if (fcport->loop_id == FC_NO_LOOP_ID ||
1849 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1850 memcmp(fcport->port_name, pd->port_name, 8))) {
1851 /* We lost the device mid way. */
1852 rval = QLA_NOT_LOGGED_IN;
1853 goto gpd_error_out;
1854 }
1855
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001856 /* Names are little-endian. */
1857 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1858 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1859
1860 /* Get port_id of device. */
1861 fcport->d_id.b.domain = pd->port_id[0];
1862 fcport->d_id.b.area = pd->port_id[3];
1863 fcport->d_id.b.al_pa = pd->port_id[2];
1864 fcport->d_id.b.rsvd_1 = 0;
1865
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001866 /* If not target must be initiator or unknown type. */
1867 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1868 fcport->port_type = FCT_INITIATOR;
1869 else
1870 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001871
1872 /* Passback COS information. */
1873 fcport->supported_classes = (pd->options & BIT_4) ?
1874 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877gpd_error_out:
1878 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1879
1880 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001881 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1882 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1883 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1886 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 }
1888
1889 return rval;
1890}
1891
1892/*
1893 * qla2x00_get_firmware_state
1894 * Get adapter firmware state.
1895 *
1896 * Input:
1897 * ha = adapter block pointer.
1898 * dptr = pointer for firmware state.
1899 * TARGET_QUEUE_LOCK must be released.
1900 * ADAPTER_STATE_LOCK must be released.
1901 *
1902 * Returns:
1903 * qla2x00 local function return status code.
1904 *
1905 * Context:
1906 * Kernel context.
1907 */
1908int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001909qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910{
1911 int rval;
1912 mbx_cmd_t mc;
1913 mbx_cmd_t *mcp = &mc;
1914
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001915 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1916 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
1918 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1919 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001920 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001921 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001922 else
1923 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001924 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001926 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001928 /* Return firmware states. */
1929 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001930 if (IS_FWI2_CAPABLE(vha->hw)) {
1931 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04001932 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001933 states[3] = mcp->mb[4];
1934 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04001935 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001936 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
1938 if (rval != QLA_SUCCESS) {
1939 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001940 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 } else {
1942 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001943 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1944 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
1946
1947 return rval;
1948}
1949
1950/*
1951 * qla2x00_get_port_name
1952 * Issue get port name mailbox command.
1953 * Returned name is in big endian format.
1954 *
1955 * Input:
1956 * ha = adapter block pointer.
1957 * loop_id = loop ID of device.
1958 * name = pointer for name.
1959 * TARGET_QUEUE_LOCK must be released.
1960 * ADAPTER_STATE_LOCK must be released.
1961 *
1962 * Returns:
1963 * qla2x00 local function return status code.
1964 *
1965 * Context:
1966 * Kernel context.
1967 */
1968int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001969qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 uint8_t opt)
1971{
1972 int rval;
1973 mbx_cmd_t mc;
1974 mbx_cmd_t *mcp = &mc;
1975
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001976 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1977 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978
1979 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001980 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001981 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001982 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 mcp->mb[1] = loop_id;
1984 mcp->mb[10] = opt;
1985 mcp->out_mb |= MBX_10;
1986 } else {
1987 mcp->mb[1] = loop_id << 8 | opt;
1988 }
1989
1990 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001991 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001993 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 if (rval != QLA_SUCCESS) {
1996 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001997 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 } else {
1999 if (name != NULL) {
2000 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002001 name[0] = MSB(mcp->mb[2]);
2002 name[1] = LSB(mcp->mb[2]);
2003 name[2] = MSB(mcp->mb[3]);
2004 name[3] = LSB(mcp->mb[3]);
2005 name[4] = MSB(mcp->mb[6]);
2006 name[5] = LSB(mcp->mb[6]);
2007 name[6] = MSB(mcp->mb[7]);
2008 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002011 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2012 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 }
2014
2015 return rval;
2016}
2017
2018/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002019 * qla24xx_link_initialization
2020 * Issue link initialization mailbox command.
2021 *
2022 * Input:
2023 * ha = adapter block pointer.
2024 * TARGET_QUEUE_LOCK must be released.
2025 * ADAPTER_STATE_LOCK must be released.
2026 *
2027 * Returns:
2028 * qla2x00 local function return status code.
2029 *
2030 * Context:
2031 * Kernel context.
2032 */
2033int
2034qla24xx_link_initialize(scsi_qla_host_t *vha)
2035{
2036 int rval;
2037 mbx_cmd_t mc;
2038 mbx_cmd_t *mcp = &mc;
2039
2040 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2041 "Entered %s.\n", __func__);
2042
2043 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2044 return QLA_FUNCTION_FAILED;
2045
2046 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002047 mcp->mb[1] = BIT_4;
2048 if (vha->hw->operating_mode == LOOP)
2049 mcp->mb[1] |= BIT_6;
2050 else
2051 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002052 mcp->mb[2] = 0;
2053 mcp->mb[3] = 0;
2054 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2055 mcp->in_mb = MBX_0;
2056 mcp->tov = MBX_TOV_SECONDS;
2057 mcp->flags = 0;
2058 rval = qla2x00_mailbox_command(vha, mcp);
2059
2060 if (rval != QLA_SUCCESS) {
2061 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2062 } else {
2063 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2064 "Done %s.\n", __func__);
2065 }
2066
2067 return rval;
2068}
2069
2070/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 * qla2x00_lip_reset
2072 * Issue LIP reset mailbox command.
2073 *
2074 * Input:
2075 * ha = adapter block pointer.
2076 * TARGET_QUEUE_LOCK must be released.
2077 * ADAPTER_STATE_LOCK must be released.
2078 *
2079 * Returns:
2080 * qla2x00 local function return status code.
2081 *
2082 * Context:
2083 * Kernel context.
2084 */
2085int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002086qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
2088 int rval;
2089 mbx_cmd_t mc;
2090 mbx_cmd_t *mcp = &mc;
2091
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002092 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2093 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002095 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002096 /* Logout across all FCFs. */
2097 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2098 mcp->mb[1] = BIT_1;
2099 mcp->mb[2] = 0;
2100 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2101 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002102 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002103 mcp->mb[1] = BIT_6;
2104 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002105 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002106 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002108 mcp->mb[0] = MBC_LIP_RESET;
2109 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002110 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002111 mcp->mb[1] = 0x00ff;
2112 mcp->mb[10] = 0;
2113 mcp->out_mb |= MBX_10;
2114 } else {
2115 mcp->mb[1] = 0xff00;
2116 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002117 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002118 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002121 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002123 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 if (rval != QLA_SUCCESS) {
2126 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002127 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 } else {
2129 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002130 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2131 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 }
2133
2134 return rval;
2135}
2136
2137/*
2138 * qla2x00_send_sns
2139 * Send SNS command.
2140 *
2141 * Input:
2142 * ha = adapter block pointer.
2143 * sns = pointer for command.
2144 * cmd_size = command size.
2145 * buf_size = response/command size.
2146 * TARGET_QUEUE_LOCK must be released.
2147 * ADAPTER_STATE_LOCK must be released.
2148 *
2149 * Returns:
2150 * qla2x00 local function return status code.
2151 *
2152 * Context:
2153 * Kernel context.
2154 */
2155int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002156qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 uint16_t cmd_size, size_t buf_size)
2158{
2159 int rval;
2160 mbx_cmd_t mc;
2161 mbx_cmd_t *mcp = &mc;
2162
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002163 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2164 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002166 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002167 "Retry cnt=%d ratov=%d total tov=%d.\n",
2168 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2171 mcp->mb[1] = cmd_size;
2172 mcp->mb[2] = MSW(sns_phys_address);
2173 mcp->mb[3] = LSW(sns_phys_address);
2174 mcp->mb[6] = MSW(MSD(sns_phys_address));
2175 mcp->mb[7] = LSW(MSD(sns_phys_address));
2176 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2177 mcp->in_mb = MBX_0|MBX_1;
2178 mcp->buf_size = buf_size;
2179 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002180 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2181 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182
2183 if (rval != QLA_SUCCESS) {
2184 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002185 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2186 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2187 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 } else {
2189 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002190 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2191 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 }
2193
2194 return rval;
2195}
2196
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002197int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002198qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002199 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2200{
2201 int rval;
2202
2203 struct logio_entry_24xx *lg;
2204 dma_addr_t lg_dma;
2205 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002206 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002207 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002208
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002209 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2210 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002211
Michael Hernandezd7459522016-12-12 14:40:07 -08002212 if (vha->vp_idx && vha->qpair)
2213 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002214 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002215 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002216
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002217 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2218 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002219 ql_log(ql_log_warn, vha, 0x1062,
2220 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002221 return QLA_MEMORY_ALLOC_FAILED;
2222 }
2223 memset(lg, 0, sizeof(struct logio_entry_24xx));
2224
2225 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2226 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002227 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002228 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002229 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002230 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002231 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002232 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002233 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002234 lg->port_id[0] = al_pa;
2235 lg->port_id[1] = area;
2236 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002237 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002238 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2239 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002240 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002241 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2242 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002243 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002244 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2245 "Failed to complete IOCB -- error status (%x).\n",
2246 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002247 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002248 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002249 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2250 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2251
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002252 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2253 "Failed to complete IOCB -- completion status (%x) "
2254 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2255 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002256
2257 switch (iop[0]) {
2258 case LSC_SCODE_PORTID_USED:
2259 mb[0] = MBS_PORT_ID_USED;
2260 mb[1] = LSW(iop[1]);
2261 break;
2262 case LSC_SCODE_NPORT_USED:
2263 mb[0] = MBS_LOOP_ID_USED;
2264 break;
2265 case LSC_SCODE_NOLINK:
2266 case LSC_SCODE_NOIOCB:
2267 case LSC_SCODE_NOXCB:
2268 case LSC_SCODE_CMD_FAILED:
2269 case LSC_SCODE_NOFABRIC:
2270 case LSC_SCODE_FW_NOT_READY:
2271 case LSC_SCODE_NOT_LOGGED_IN:
2272 case LSC_SCODE_NOPCB:
2273 case LSC_SCODE_ELS_REJECT:
2274 case LSC_SCODE_CMD_PARAM_ERR:
2275 case LSC_SCODE_NONPORT:
2276 case LSC_SCODE_LOGGED_IN:
2277 case LSC_SCODE_NOFLOGI_ACC:
2278 default:
2279 mb[0] = MBS_COMMAND_ERROR;
2280 break;
2281 }
2282 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002283 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2284 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002285
2286 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2287
2288 mb[0] = MBS_COMMAND_COMPLETE;
2289 mb[1] = 0;
2290 if (iop[0] & BIT_4) {
2291 if (iop[0] & BIT_8)
2292 mb[1] |= BIT_1;
2293 } else
2294 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002295
2296 /* Passback COS information. */
2297 mb[10] = 0;
2298 if (lg->io_parameter[7] || lg->io_parameter[8])
2299 mb[10] |= BIT_0; /* Class 2. */
2300 if (lg->io_parameter[9] || lg->io_parameter[10])
2301 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002302 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002303 mb[10] |= BIT_7; /* Confirmed Completion
2304 * Allowed
2305 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002306 }
2307
2308 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2309
2310 return rval;
2311}
2312
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313/*
2314 * qla2x00_login_fabric
2315 * Issue login fabric port mailbox command.
2316 *
2317 * Input:
2318 * ha = adapter block pointer.
2319 * loop_id = device loop ID.
2320 * domain = device domain.
2321 * area = device area.
2322 * al_pa = device AL_PA.
2323 * status = pointer for return status.
2324 * opt = command options.
2325 * TARGET_QUEUE_LOCK must be released.
2326 * ADAPTER_STATE_LOCK must be released.
2327 *
2328 * Returns:
2329 * qla2x00 local function return status code.
2330 *
2331 * Context:
2332 * Kernel context.
2333 */
2334int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002335qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2337{
2338 int rval;
2339 mbx_cmd_t mc;
2340 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002341 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002343 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2344 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
2346 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2347 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2348 if (HAS_EXTENDED_IDS(ha)) {
2349 mcp->mb[1] = loop_id;
2350 mcp->mb[10] = opt;
2351 mcp->out_mb |= MBX_10;
2352 } else {
2353 mcp->mb[1] = (loop_id << 8) | opt;
2354 }
2355 mcp->mb[2] = domain;
2356 mcp->mb[3] = area << 8 | al_pa;
2357
2358 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2359 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2360 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002361 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
2363 /* Return mailbox statuses. */
2364 if (mb != NULL) {
2365 mb[0] = mcp->mb[0];
2366 mb[1] = mcp->mb[1];
2367 mb[2] = mcp->mb[2];
2368 mb[6] = mcp->mb[6];
2369 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002370 /* COS retrieved from Get-Port-Database mailbox command. */
2371 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 }
2373
2374 if (rval != QLA_SUCCESS) {
2375 /* RLU tmp code: need to change main mailbox_command function to
2376 * return ok even when the mailbox completion value is not
2377 * SUCCESS. The caller needs to be responsible to interpret
2378 * the return values of this mailbox command if we're not
2379 * to change too much of the existing code.
2380 */
2381 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2382 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2383 mcp->mb[0] == 0x4006)
2384 rval = QLA_SUCCESS;
2385
2386 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002387 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2388 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2389 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 } else {
2391 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002392 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2393 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 }
2395
2396 return rval;
2397}
2398
2399/*
2400 * qla2x00_login_local_device
2401 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002402 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 * Input:
2404 * ha = adapter block pointer.
2405 * loop_id = device loop ID.
2406 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002407 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 * Returns:
2409 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002410 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 * Context:
2412 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002413 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 */
2415int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002416qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 uint16_t *mb_ret, uint8_t opt)
2418{
2419 int rval;
2420 mbx_cmd_t mc;
2421 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002422 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002424 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2425 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002426
Andrew Vasqueze4289242007-07-19 15:05:56 -07002427 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002428 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002429 fcport->d_id.b.domain, fcport->d_id.b.area,
2430 fcport->d_id.b.al_pa, mb_ret, opt);
2431
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2433 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002434 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002436 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 mcp->mb[2] = opt;
2438 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2439 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2440 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2441 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002442 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
2444 /* Return mailbox statuses. */
2445 if (mb_ret != NULL) {
2446 mb_ret[0] = mcp->mb[0];
2447 mb_ret[1] = mcp->mb[1];
2448 mb_ret[6] = mcp->mb[6];
2449 mb_ret[7] = mcp->mb[7];
2450 }
2451
2452 if (rval != QLA_SUCCESS) {
2453 /* AV tmp code: need to change main mailbox_command function to
2454 * return ok even when the mailbox completion value is not
2455 * SUCCESS. The caller needs to be responsible to interpret
2456 * the return values of this mailbox command if we're not
2457 * to change too much of the existing code.
2458 */
2459 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2460 rval = QLA_SUCCESS;
2461
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002462 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2463 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2464 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 } else {
2466 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002467 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2468 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 }
2470
2471 return (rval);
2472}
2473
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002474int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002475qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002476 uint8_t area, uint8_t al_pa)
2477{
2478 int rval;
2479 struct logio_entry_24xx *lg;
2480 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002481 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002482 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002483
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002484 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2485 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002486
2487 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2488 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002489 ql_log(ql_log_warn, vha, 0x106e,
2490 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002491 return QLA_MEMORY_ALLOC_FAILED;
2492 }
2493 memset(lg, 0, sizeof(struct logio_entry_24xx));
2494
Michael Hernandezd7459522016-12-12 14:40:07 -08002495 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002496 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2497 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002498 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002499 lg->nport_handle = cpu_to_le16(loop_id);
2500 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002501 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002502 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002503 lg->port_id[0] = al_pa;
2504 lg->port_id[1] = area;
2505 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002506 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002507 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2508 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002509 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002510 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2511 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002512 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002513 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2514 "Failed to complete IOCB -- error status (%x).\n",
2515 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002516 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002517 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002518 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2519 "Failed to complete IOCB -- completion status (%x) "
2520 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002521 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002522 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002523 } else {
2524 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002525 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2526 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002527 }
2528
2529 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2530
2531 return rval;
2532}
2533
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534/*
2535 * qla2x00_fabric_logout
2536 * Issue logout fabric port mailbox command.
2537 *
2538 * Input:
2539 * ha = adapter block pointer.
2540 * loop_id = device loop ID.
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_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002552 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553{
2554 int rval;
2555 mbx_cmd_t mc;
2556 mbx_cmd_t *mcp = &mc;
2557
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002558 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2559 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560
2561 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2562 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002563 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 mcp->mb[1] = loop_id;
2565 mcp->mb[10] = 0;
2566 mcp->out_mb |= MBX_10;
2567 } else {
2568 mcp->mb[1] = loop_id << 8;
2569 }
2570
2571 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002572 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002574 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
2576 if (rval != QLA_SUCCESS) {
2577 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002578 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2579 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 } else {
2581 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002582 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2583 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 }
2585
2586 return rval;
2587}
2588
2589/*
2590 * qla2x00_full_login_lip
2591 * Issue full login LIP mailbox command.
2592 *
2593 * Input:
2594 * ha = adapter block pointer.
2595 * TARGET_QUEUE_LOCK must be released.
2596 * ADAPTER_STATE_LOCK must be released.
2597 *
2598 * Returns:
2599 * qla2x00 local function return status code.
2600 *
2601 * Context:
2602 * Kernel context.
2603 */
2604int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002605qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606{
2607 int rval;
2608 mbx_cmd_t mc;
2609 mbx_cmd_t *mcp = &mc;
2610
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002611 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2612 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
2614 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002615 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002616 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 mcp->mb[3] = 0;
2618 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2619 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002620 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002622 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
2624 if (rval != QLA_SUCCESS) {
2625 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002626 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 } else {
2628 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002629 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2630 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 }
2632
2633 return rval;
2634}
2635
2636/*
2637 * qla2x00_get_id_list
2638 *
2639 * Input:
2640 * ha = adapter block pointer.
2641 *
2642 * Returns:
2643 * qla2x00 local function return status code.
2644 *
2645 * Context:
2646 * Kernel context.
2647 */
2648int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002649qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 uint16_t *entries)
2651{
2652 int rval;
2653 mbx_cmd_t mc;
2654 mbx_cmd_t *mcp = &mc;
2655
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002656 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2657 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
2659 if (id_list == NULL)
2660 return QLA_FUNCTION_FAILED;
2661
2662 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002663 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002664 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002665 mcp->mb[2] = MSW(id_list_dma);
2666 mcp->mb[3] = LSW(id_list_dma);
2667 mcp->mb[6] = MSW(MSD(id_list_dma));
2668 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002669 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002670 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002671 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002672 } else {
2673 mcp->mb[1] = MSW(id_list_dma);
2674 mcp->mb[2] = LSW(id_list_dma);
2675 mcp->mb[3] = MSW(MSD(id_list_dma));
2676 mcp->mb[6] = LSW(MSD(id_list_dma));
2677 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002680 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002682 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683
2684 if (rval != QLA_SUCCESS) {
2685 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002686 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 } else {
2688 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002689 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2690 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 }
2692
2693 return rval;
2694}
2695
2696/*
2697 * qla2x00_get_resource_cnts
2698 * Get current firmware resource counts.
2699 *
2700 * Input:
2701 * ha = adapter block pointer.
2702 *
2703 * Returns:
2704 * qla2x00 local function return status code.
2705 *
2706 * Context:
2707 * Kernel context.
2708 */
2709int
Quinn Tran03e8c682015-12-17 14:56:59 -05002710qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711{
Quinn Tran03e8c682015-12-17 14:56:59 -05002712 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 int rval;
2714 mbx_cmd_t mc;
2715 mbx_cmd_t *mcp = &mc;
2716
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002717 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2718 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2721 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002722 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 -05002723 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002724 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002725 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002727 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
2729 if (rval != QLA_SUCCESS) {
2730 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002731 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2732 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002734 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002735 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2736 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2737 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2738 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
Quinn Tran03e8c682015-12-17 14:56:59 -05002740 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2741 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2742 ha->cur_fw_xcb_count = mcp->mb[3];
2743 ha->orig_fw_xcb_count = mcp->mb[6];
2744 ha->cur_fw_iocb_count = mcp->mb[7];
2745 ha->orig_fw_iocb_count = mcp->mb[10];
2746 if (ha->flags.npiv_supported)
2747 ha->max_npiv_vports = mcp->mb[11];
2748 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2749 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 }
2751
2752 return (rval);
2753}
2754
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755/*
2756 * qla2x00_get_fcal_position_map
2757 * Get FCAL (LILP) position map using mailbox command
2758 *
2759 * Input:
2760 * ha = adapter state pointer.
2761 * pos_map = buffer pointer (can be NULL).
2762 *
2763 * Returns:
2764 * qla2x00 local function return status code.
2765 *
2766 * Context:
2767 * Kernel context.
2768 */
2769int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002770qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771{
2772 int rval;
2773 mbx_cmd_t mc;
2774 mbx_cmd_t *mcp = &mc;
2775 char *pmap;
2776 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002777 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2780 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002781
Andrew Vasquez4b892582008-09-11 21:22:48 -07002782 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002784 ql_log(ql_log_warn, vha, 0x1080,
2785 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 return QLA_MEMORY_ALLOC_FAILED;
2787 }
2788 memset(pmap, 0, FCAL_MAP_SIZE);
2789
2790 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2791 mcp->mb[2] = MSW(pmap_dma);
2792 mcp->mb[3] = LSW(pmap_dma);
2793 mcp->mb[6] = MSW(MSD(pmap_dma));
2794 mcp->mb[7] = LSW(MSD(pmap_dma));
2795 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2796 mcp->in_mb = MBX_1|MBX_0;
2797 mcp->buf_size = FCAL_MAP_SIZE;
2798 mcp->flags = MBX_DMA_IN;
2799 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002800 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
2802 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002803 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002804 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2805 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2806 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2807 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
2809 if (pos_map)
2810 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2811 }
2812 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2813
2814 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002815 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002817 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2818 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 }
2820
2821 return rval;
2822}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002823
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002824/*
2825 * qla2x00_get_link_status
2826 *
2827 * Input:
2828 * ha = adapter block pointer.
2829 * loop_id = device loop ID.
2830 * ret_buf = pointer to link status return buffer.
2831 *
2832 * Returns:
2833 * 0 = success.
2834 * BIT_0 = mem alloc error.
2835 * BIT_1 = mailbox error.
2836 */
2837int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002838qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002839 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002840{
2841 int rval;
2842 mbx_cmd_t mc;
2843 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002844 uint32_t *iter = (void *)stats;
2845 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002846 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002847
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002848 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2849 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002850
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002851 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002852 mcp->mb[2] = MSW(LSD(stats_dma));
2853 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002854 mcp->mb[6] = MSW(MSD(stats_dma));
2855 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002856 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2857 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002858 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002859 mcp->mb[1] = loop_id;
2860 mcp->mb[4] = 0;
2861 mcp->mb[10] = 0;
2862 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2863 mcp->in_mb |= MBX_1;
2864 } else if (HAS_EXTENDED_IDS(ha)) {
2865 mcp->mb[1] = loop_id;
2866 mcp->mb[10] = 0;
2867 mcp->out_mb |= MBX_10|MBX_1;
2868 } else {
2869 mcp->mb[1] = loop_id << 8;
2870 mcp->out_mb |= MBX_1;
2871 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002872 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002873 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002874 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002875
2876 if (rval == QLA_SUCCESS) {
2877 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002878 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2879 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002880 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002881 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002882 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002883 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2884 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002885 for ( ; dwords--; iter++)
2886 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002887 }
2888 } else {
2889 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002890 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002891 }
2892
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002893 return rval;
2894}
2895
2896int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002897qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002898 dma_addr_t stats_dma, uint options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002899{
2900 int rval;
2901 mbx_cmd_t mc;
2902 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002903 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002904
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002905 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2906 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002907
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002908 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002909 mcp->mb[2] = MSW(stats_dma);
2910 mcp->mb[3] = LSW(stats_dma);
2911 mcp->mb[6] = MSW(MSD(stats_dma));
2912 mcp->mb[7] = LSW(MSD(stats_dma));
2913 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002914 mcp->mb[9] = vha->vp_idx;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002915 mcp->mb[10] = options;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002916 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002917 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002918 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002919 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002920 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002921
2922 if (rval == QLA_SUCCESS) {
2923 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002924 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2925 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002926 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002927 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002928 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2929 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002930 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002931 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05002932 iter = &stats->link_fail_cnt;
2933 for ( ; dwords--; iter++)
2934 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002935 }
2936 } else {
2937 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002938 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002939 }
2940
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002941 return rval;
2942}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002943
2944int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002945qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002946{
2947 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002948 unsigned long flags = 0;
2949
2950 struct abort_entry_24xx *abt;
2951 dma_addr_t abt_dma;
2952 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002953 fc_port_t *fcport = sp->fcport;
2954 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002955 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002956 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002957
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002958 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2959 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002960
Michael Hernandezd7459522016-12-12 14:40:07 -08002961 if (vha->flags.qpairs_available && sp->qpair)
2962 req = sp->qpair->req;
2963
Armen Baloyan4440e462014-02-26 04:15:18 -05002964 if (ql2xasynctmfenable)
2965 return qla24xx_async_abort_command(sp);
2966
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002967 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002968 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002969 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002970 break;
2971 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002972 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002973 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002974 /* Command not found. */
2975 return QLA_FUNCTION_FAILED;
2976 }
2977
2978 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2979 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002980 ql_log(ql_log_warn, vha, 0x108d,
2981 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002982 return QLA_MEMORY_ALLOC_FAILED;
2983 }
2984 memset(abt, 0, sizeof(struct abort_entry_24xx));
2985
2986 abt->entry_type = ABORT_IOCB_TYPE;
2987 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002988 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002989 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002990 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002991 abt->port_id[0] = fcport->d_id.b.al_pa;
2992 abt->port_id[1] = fcport->d_id.b.area;
2993 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002994 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002995
2996 abt->req_que_no = cpu_to_le16(req->id);
2997
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002998 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002999 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003000 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3001 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003002 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003003 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3004 "Failed to complete IOCB -- error status (%x).\n",
3005 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003006 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003007 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003008 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3009 "Failed to complete IOCB -- completion status (%x).\n",
3010 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003011 if (abt->nport_handle == CS_IOCB_ERROR)
3012 rval = QLA_FUNCTION_PARAMETER_ERROR;
3013 else
3014 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003015 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003016 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3017 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003018 }
3019
3020 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3021
3022 return rval;
3023}
3024
3025struct tsk_mgmt_cmd {
3026 union {
3027 struct tsk_mgmt_entry tsk;
3028 struct sts_entry_24xx sts;
3029 } p;
3030};
3031
Andrew Vasquez523ec772008-04-03 13:13:24 -07003032static int
3033__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003034 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003035{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003036 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003037 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003038 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003039 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003040 scsi_qla_host_t *vha;
3041 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003042 struct req_que *req;
3043 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003044 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003045
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003046 vha = fcport->vha;
3047 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003048 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003049
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003050 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3051 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003052
Michael Hernandezd7459522016-12-12 14:40:07 -08003053 if (vha->vp_idx && vha->qpair) {
3054 /* NPIV port */
3055 qpair = vha->qpair;
3056 rsp = qpair->rsp;
3057 req = qpair->req;
3058 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003059 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003060 }
3061
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003062 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003063 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003064 ql_log(ql_log_warn, vha, 0x1093,
3065 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003066 return QLA_MEMORY_ALLOC_FAILED;
3067 }
3068 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
3069
3070 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3071 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003072 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003073 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003074 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003075 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003076 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3077 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3078 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003079 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003080 if (type == TCF_LUN_RESET) {
3081 int_to_scsilun(l, &tsk->p.tsk.lun);
3082 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3083 sizeof(tsk->p.tsk.lun));
3084 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003085
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003086 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003087 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003088 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003089 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3090 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003091 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003092 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3093 "Failed to complete IOCB -- error status (%x).\n",
3094 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003095 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003096 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003097 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3098 "Failed to complete IOCB -- completion status (%x).\n",
3099 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003100 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003101 } else if (le16_to_cpu(sts->scsi_status) &
3102 SS_RESPONSE_INFO_LEN_VALID) {
3103 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003104 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003105 "Ignoring inconsistent data length -- not enough "
3106 "response info (%d).\n",
3107 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003108 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003109 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3110 "Failed to complete IOCB -- response (%x).\n",
3111 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003112 rval = QLA_FUNCTION_FAILED;
3113 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003114 }
3115
3116 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003117 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003118 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3119 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003120 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3121 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003122 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003123 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3124 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003125 }
3126
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003127 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003128
3129 return rval;
3130}
3131
Andrew Vasquez523ec772008-04-03 13:13:24 -07003132int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003133qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003134{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003135 struct qla_hw_data *ha = fcport->vha->hw;
3136
3137 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3138 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3139
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003140 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003141}
3142
3143int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003144qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003145{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003146 struct qla_hw_data *ha = fcport->vha->hw;
3147
3148 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3149 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3150
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003151 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003152}
3153
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003154int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003155qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003156{
3157 int rval;
3158 mbx_cmd_t mc;
3159 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003160 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003161
Andrew Vasquez68af0812008-05-12 22:21:13 -07003162 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003163 return QLA_FUNCTION_FAILED;
3164
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003165 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3166 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003167
3168 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3169 mcp->out_mb = MBX_0;
3170 mcp->in_mb = MBX_0;
3171 mcp->tov = 5;
3172 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003173 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003174
3175 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003176 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003177 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003178 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3179 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003180 }
3181
3182 return rval;
3183}
3184
Joe Carnucciodb64e932013-10-30 03:38:18 -04003185int
3186qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3187{
3188 int rval;
3189 mbx_cmd_t mc;
3190 mbx_cmd_t *mcp = &mc;
3191
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003192 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3193 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003194 return QLA_FUNCTION_FAILED;
3195
3196 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3197 "Entered %s.\n", __func__);
3198
3199 mcp->mb[0] = MBC_WRITE_SERDES;
3200 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003201 if (IS_QLA2031(vha->hw))
3202 mcp->mb[2] = data & 0xff;
3203 else
3204 mcp->mb[2] = data;
3205
Joe Carnucciodb64e932013-10-30 03:38:18 -04003206 mcp->mb[3] = 0;
3207 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3208 mcp->in_mb = MBX_0;
3209 mcp->tov = MBX_TOV_SECONDS;
3210 mcp->flags = 0;
3211 rval = qla2x00_mailbox_command(vha, mcp);
3212
3213 if (rval != QLA_SUCCESS) {
3214 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3215 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3216 } else {
3217 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3218 "Done %s.\n", __func__);
3219 }
3220
3221 return rval;
3222}
3223
3224int
3225qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3226{
3227 int rval;
3228 mbx_cmd_t mc;
3229 mbx_cmd_t *mcp = &mc;
3230
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003231 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3232 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003233 return QLA_FUNCTION_FAILED;
3234
3235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3236 "Entered %s.\n", __func__);
3237
3238 mcp->mb[0] = MBC_READ_SERDES;
3239 mcp->mb[1] = addr;
3240 mcp->mb[3] = 0;
3241 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3242 mcp->in_mb = MBX_1|MBX_0;
3243 mcp->tov = MBX_TOV_SECONDS;
3244 mcp->flags = 0;
3245 rval = qla2x00_mailbox_command(vha, mcp);
3246
Andrew Vasquez064135e2015-04-09 15:00:02 -04003247 if (IS_QLA2031(vha->hw))
3248 *data = mcp->mb[1] & 0xff;
3249 else
3250 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003251
3252 if (rval != QLA_SUCCESS) {
3253 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3254 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3255 } else {
3256 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3257 "Done %s.\n", __func__);
3258 }
3259
3260 return rval;
3261}
3262
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003263int
3264qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3265{
3266 int rval;
3267 mbx_cmd_t mc;
3268 mbx_cmd_t *mcp = &mc;
3269
3270 if (!IS_QLA8044(vha->hw))
3271 return QLA_FUNCTION_FAILED;
3272
3273 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1186,
3274 "Entered %s.\n", __func__);
3275
3276 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3277 mcp->mb[1] = HCS_WRITE_SERDES;
3278 mcp->mb[3] = LSW(addr);
3279 mcp->mb[4] = MSW(addr);
3280 mcp->mb[5] = LSW(data);
3281 mcp->mb[6] = MSW(data);
3282 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3283 mcp->in_mb = MBX_0;
3284 mcp->tov = MBX_TOV_SECONDS;
3285 mcp->flags = 0;
3286 rval = qla2x00_mailbox_command(vha, mcp);
3287
3288 if (rval != QLA_SUCCESS) {
3289 ql_dbg(ql_dbg_mbx, vha, 0x1187,
3290 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3291 } else {
3292 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3293 "Done %s.\n", __func__);
3294 }
3295
3296 return rval;
3297}
3298
3299int
3300qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3301{
3302 int rval;
3303 mbx_cmd_t mc;
3304 mbx_cmd_t *mcp = &mc;
3305
3306 if (!IS_QLA8044(vha->hw))
3307 return QLA_FUNCTION_FAILED;
3308
3309 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3310 "Entered %s.\n", __func__);
3311
3312 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3313 mcp->mb[1] = HCS_READ_SERDES;
3314 mcp->mb[3] = LSW(addr);
3315 mcp->mb[4] = MSW(addr);
3316 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3317 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3318 mcp->tov = MBX_TOV_SECONDS;
3319 mcp->flags = 0;
3320 rval = qla2x00_mailbox_command(vha, mcp);
3321
3322 *data = mcp->mb[2] << 16 | mcp->mb[1];
3323
3324 if (rval != QLA_SUCCESS) {
3325 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3326 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3327 } else {
3328 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3329 "Done %s.\n", __func__);
3330 }
3331
3332 return rval;
3333}
3334
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003335/**
3336 * qla2x00_set_serdes_params() -
3337 * @ha: HA context
3338 *
3339 * Returns
3340 */
3341int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003342qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003343 uint16_t sw_em_2g, uint16_t sw_em_4g)
3344{
3345 int rval;
3346 mbx_cmd_t mc;
3347 mbx_cmd_t *mcp = &mc;
3348
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003349 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3350 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003351
3352 mcp->mb[0] = MBC_SERDES_PARAMS;
3353 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003354 mcp->mb[2] = sw_em_1g | BIT_15;
3355 mcp->mb[3] = sw_em_2g | BIT_15;
3356 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003357 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3358 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003359 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003360 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003361 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003362
3363 if (rval != QLA_SUCCESS) {
3364 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003365 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3366 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003367 } else {
3368 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003369 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3370 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003371 }
3372
3373 return rval;
3374}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003375
3376int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003377qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003378{
3379 int rval;
3380 mbx_cmd_t mc;
3381 mbx_cmd_t *mcp = &mc;
3382
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003383 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003384 return QLA_FUNCTION_FAILED;
3385
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003386 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3387 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003388
3389 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003390 mcp->mb[1] = 0;
3391 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003392 mcp->in_mb = MBX_0;
3393 mcp->tov = 5;
3394 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003395 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003396
3397 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003398 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003399 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3400 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003401 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003402 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3403 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003404 }
3405
3406 return rval;
3407}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003408
3409int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003410qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003411 uint16_t buffers)
3412{
3413 int rval;
3414 mbx_cmd_t mc;
3415 mbx_cmd_t *mcp = &mc;
3416
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003417 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3418 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003419
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003420 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003421 return QLA_FUNCTION_FAILED;
3422
Andrew Vasquez85880802009-12-15 21:29:46 -08003423 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3424 return QLA_FUNCTION_FAILED;
3425
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003426 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003427 mcp->mb[1] = TC_EFT_ENABLE;
3428 mcp->mb[2] = LSW(eft_dma);
3429 mcp->mb[3] = MSW(eft_dma);
3430 mcp->mb[4] = LSW(MSD(eft_dma));
3431 mcp->mb[5] = MSW(MSD(eft_dma));
3432 mcp->mb[6] = buffers;
3433 mcp->mb[7] = TC_AEN_DISABLE;
3434 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 -07003435 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003436 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003437 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003438 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003439 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003440 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3441 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3442 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003443 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003444 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3445 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003446 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003447
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003448 return rval;
3449}
3450
3451int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003452qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003453{
3454 int rval;
3455 mbx_cmd_t mc;
3456 mbx_cmd_t *mcp = &mc;
3457
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003458 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3459 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003460
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003461 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003462 return QLA_FUNCTION_FAILED;
3463
Andrew Vasquez85880802009-12-15 21:29:46 -08003464 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3465 return QLA_FUNCTION_FAILED;
3466
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003467 mcp->mb[0] = MBC_TRACE_CONTROL;
3468 mcp->mb[1] = TC_EFT_DISABLE;
3469 mcp->out_mb = MBX_1|MBX_0;
3470 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003471 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003472 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003473 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003474 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003475 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3476 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3477 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003478 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003479 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3480 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003481 }
3482
3483 return rval;
3484}
3485
Andrew Vasquez88729e52006-06-23 16:10:50 -07003486int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003487qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003488 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3489{
3490 int rval;
3491 mbx_cmd_t mc;
3492 mbx_cmd_t *mcp = &mc;
3493
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003494 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3495 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003496
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003497 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003498 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003499 return QLA_FUNCTION_FAILED;
3500
Andrew Vasquez85880802009-12-15 21:29:46 -08003501 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3502 return QLA_FUNCTION_FAILED;
3503
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003504 mcp->mb[0] = MBC_TRACE_CONTROL;
3505 mcp->mb[1] = TC_FCE_ENABLE;
3506 mcp->mb[2] = LSW(fce_dma);
3507 mcp->mb[3] = MSW(fce_dma);
3508 mcp->mb[4] = LSW(MSD(fce_dma));
3509 mcp->mb[5] = MSW(MSD(fce_dma));
3510 mcp->mb[6] = buffers;
3511 mcp->mb[7] = TC_AEN_DISABLE;
3512 mcp->mb[8] = 0;
3513 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3514 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3515 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3516 MBX_1|MBX_0;
3517 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003518 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003519 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003520 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003521 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003522 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3523 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3524 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003525 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003526 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3527 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003528
3529 if (mb)
3530 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3531 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003532 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003533 }
3534
3535 return rval;
3536}
3537
3538int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003539qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003540{
3541 int rval;
3542 mbx_cmd_t mc;
3543 mbx_cmd_t *mcp = &mc;
3544
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003545 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3546 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003547
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003548 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003549 return QLA_FUNCTION_FAILED;
3550
Andrew Vasquez85880802009-12-15 21:29:46 -08003551 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3552 return QLA_FUNCTION_FAILED;
3553
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003554 mcp->mb[0] = MBC_TRACE_CONTROL;
3555 mcp->mb[1] = TC_FCE_DISABLE;
3556 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3557 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3558 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3559 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003560 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003561 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003562 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003563 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003564 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3565 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3566 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003567 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003568 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3569 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003570
3571 if (wr)
3572 *wr = (uint64_t) mcp->mb[5] << 48 |
3573 (uint64_t) mcp->mb[4] << 32 |
3574 (uint64_t) mcp->mb[3] << 16 |
3575 (uint64_t) mcp->mb[2];
3576 if (rd)
3577 *rd = (uint64_t) mcp->mb[9] << 48 |
3578 (uint64_t) mcp->mb[8] << 32 |
3579 (uint64_t) mcp->mb[7] << 16 |
3580 (uint64_t) mcp->mb[6];
3581 }
3582
3583 return rval;
3584}
3585
3586int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003587qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3588 uint16_t *port_speed, uint16_t *mb)
3589{
3590 int rval;
3591 mbx_cmd_t mc;
3592 mbx_cmd_t *mcp = &mc;
3593
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003594 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3595 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003596
Giridhar Malavali6e980162010-03-19 17:03:58 -07003597 if (!IS_IIDMA_CAPABLE(vha->hw))
3598 return QLA_FUNCTION_FAILED;
3599
Giridhar Malavali6e980162010-03-19 17:03:58 -07003600 mcp->mb[0] = MBC_PORT_PARAMS;
3601 mcp->mb[1] = loop_id;
3602 mcp->mb[2] = mcp->mb[3] = 0;
3603 mcp->mb[9] = vha->vp_idx;
3604 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3605 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3606 mcp->tov = MBX_TOV_SECONDS;
3607 mcp->flags = 0;
3608 rval = qla2x00_mailbox_command(vha, mcp);
3609
3610 /* Return mailbox statuses. */
3611 if (mb != NULL) {
3612 mb[0] = mcp->mb[0];
3613 mb[1] = mcp->mb[1];
3614 mb[3] = mcp->mb[3];
3615 }
3616
3617 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003618 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003619 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003620 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3621 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003622 if (port_speed)
3623 *port_speed = mcp->mb[3];
3624 }
3625
3626 return rval;
3627}
3628
3629int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003630qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003631 uint16_t port_speed, uint16_t *mb)
3632{
3633 int rval;
3634 mbx_cmd_t mc;
3635 mbx_cmd_t *mcp = &mc;
3636
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003637 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3638 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003639
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003640 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003641 return QLA_FUNCTION_FAILED;
3642
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003643 mcp->mb[0] = MBC_PORT_PARAMS;
3644 mcp->mb[1] = loop_id;
3645 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003646 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003647 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3648 else
3649 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3650 mcp->mb[9] = vha->vp_idx;
3651 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3652 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003653 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003654 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003655 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003656
3657 /* Return mailbox statuses. */
3658 if (mb != NULL) {
3659 mb[0] = mcp->mb[0];
3660 mb[1] = mcp->mb[1];
3661 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003662 }
3663
3664 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003665 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3666 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003667 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003668 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3669 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003670 }
3671
3672 return rval;
3673}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003674
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003675void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003676qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003677 struct vp_rpt_id_entry_24xx *rptid_entry)
3678{
3679 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07003680 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003681 struct qla_hw_data *ha = vha->hw;
3682 scsi_qla_host_t *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003683 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003684 int found;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003685
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003686 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3687 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003688
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003689 if (rptid_entry->entry_status != 0)
3690 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003691
3692 if (rptid_entry->format == 0) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003693 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003694 "Format 0 : Number of VPs setup %d, number of "
3695 "VPs acquired %d.\n",
3696 MSB(le16_to_cpu(rptid_entry->vp_count)),
3697 LSB(le16_to_cpu(rptid_entry->vp_count)));
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003698 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003699 "Primary port id %02x%02x%02x.\n",
3700 rptid_entry->port_id[2], rptid_entry->port_id[1],
3701 rptid_entry->port_id[0]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003702 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07003703 vp_idx = LSB(stat);
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003704 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003705 "Format 1: VP[%d] enabled - status %d - with "
3706 "port id %02x%02x%02x.\n", vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003707 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003708 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003709
Sawan Chandak969a6192016-01-27 12:03:32 -05003710 /* buffer to buffer credit flag */
3711 vha->flags.bbcr_enable = (rptid_entry->bbcr & 0xf) != 0;
3712
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003713 /* FA-WWN is only for physical port */
3714 if (!vp_idx) {
3715 void *wwpn = ha->init_cb->port_name;
3716
3717 if (!MSB(stat)) {
3718 if (rptid_entry->vp_idx_map[1] & BIT_6)
3719 wwpn = rptid_entry->reserved_4 + 8;
3720 }
3721 memcpy(vha->port_name, wwpn, WWN_SIZE);
3722 fc_host_port_name(vha->host) =
3723 wwn_to_u64(vha->port_name);
3724 ql_dbg(ql_dbg_mbx, vha, 0x1018,
3725 "FA-WWN portname %016llx (%x)\n",
3726 fc_host_port_name(vha->host), MSB(stat));
3727 }
3728
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003729 vp = vha;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003730 if (vp_idx == 0)
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003731 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003732
Saurav Kashyap681e0142012-11-21 02:40:28 -05003733 if (MSB(stat) != 0 && MSB(stat) != 2) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003734 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3735 "Could not acquire ID for VP[%d].\n", vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003736 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07003737 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003738
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003739 found = 0;
Arun Easifeafb7b2010-09-03 14:57:00 -07003740 spin_lock_irqsave(&ha->vport_slock, flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003741 list_for_each_entry(vp, &ha->vp_list, list) {
3742 if (vp_idx == vp->vp_idx) {
3743 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003744 break;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003745 }
3746 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003747 spin_unlock_irqrestore(&ha->vport_slock, flags);
3748
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003749 if (!found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003750 return;
3751
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003752 vp->d_id.b.domain = rptid_entry->port_id[2];
3753 vp->d_id.b.area = rptid_entry->port_id[1];
3754 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003755
3756 /*
3757 * Cannot configure here as we are still sitting on the
3758 * response queue. Handle it in dpc context.
3759 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003760 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003761
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003762reg_needed:
3763 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3764 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
3765 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003766 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003767 }
3768}
3769
3770/*
3771 * qla24xx_modify_vp_config
3772 * Change VP configuration for vha
3773 *
3774 * Input:
3775 * vha = adapter block pointer.
3776 *
3777 * Returns:
3778 * qla2xxx local function return status code.
3779 *
3780 * Context:
3781 * Kernel context.
3782 */
3783int
3784qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3785{
3786 int rval;
3787 struct vp_config_entry_24xx *vpmod;
3788 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003789 struct qla_hw_data *ha = vha->hw;
3790 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003791
3792 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003793
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003794 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3795 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003796
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003797 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003798 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003799 ql_log(ql_log_warn, vha, 0x10bc,
3800 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003801 return QLA_MEMORY_ALLOC_FAILED;
3802 }
3803
3804 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3805 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3806 vpmod->entry_count = 1;
3807 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3808 vpmod->vp_count = 1;
3809 vpmod->vp_index1 = vha->vp_idx;
3810 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003811
3812 qlt_modify_vp_config(vha, vpmod);
3813
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003814 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3815 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3816 vpmod->entry_count = 1;
3817
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003818 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003819 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003820 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3821 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003822 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003823 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3824 "Failed to complete IOCB -- error status (%x).\n",
3825 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003826 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003827 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003828 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3829 "Failed to complete IOCB -- completion status (%x).\n",
3830 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003831 rval = QLA_FUNCTION_FAILED;
3832 } else {
3833 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003834 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3835 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003836 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3837 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003838 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003839
3840 return rval;
3841}
3842
3843/*
3844 * qla24xx_control_vp
3845 * Enable a virtual port for given host
3846 *
3847 * Input:
3848 * ha = adapter block pointer.
3849 * vhba = virtual adapter (unused)
3850 * index = index number for enabled VP
3851 *
3852 * Returns:
3853 * qla2xxx local function return status code.
3854 *
3855 * Context:
3856 * Kernel context.
3857 */
3858int
3859qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3860{
3861 int rval;
3862 int map, pos;
3863 struct vp_ctrl_entry_24xx *vce;
3864 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003865 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003866 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003867 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003868
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003869 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003870 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003871
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003872 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003873 return QLA_PARAMETER_ERROR;
3874
3875 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3876 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003877 ql_log(ql_log_warn, vha, 0x10c2,
3878 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003879 return QLA_MEMORY_ALLOC_FAILED;
3880 }
3881 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3882
3883 vce->entry_type = VP_CTRL_IOCB_TYPE;
3884 vce->entry_count = 1;
3885 vce->command = cpu_to_le16(cmd);
Bart Van Asschead950362015-07-09 07:24:08 -07003886 vce->vp_count = cpu_to_le16(1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003887
3888 /* index map in firmware starts with 1; decrement index
3889 * this is ok as we never use index 0
3890 */
3891 map = (vp_index - 1) / 8;
3892 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003893 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003894 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003895 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003896
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003897 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003898 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003899 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3900 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003901 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003902 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3903 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003904 vce->entry_status);
3905 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003906 } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003907 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3908 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003909 le16_to_cpu(vce->comp_status));
3910 rval = QLA_FUNCTION_FAILED;
3911 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003912 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3913 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003914 }
3915
3916 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3917
3918 return rval;
3919}
3920
3921/*
3922 * qla2x00_send_change_request
3923 * Receive or disable RSCN request from fabric controller
3924 *
3925 * Input:
3926 * ha = adapter block pointer
3927 * format = registration format:
3928 * 0 - Reserved
3929 * 1 - Fabric detected registration
3930 * 2 - N_port detected registration
3931 * 3 - Full registration
3932 * FF - clear registration
3933 * vp_idx = Virtual port index
3934 *
3935 * Returns:
3936 * qla2x00 local function return status code.
3937 *
3938 * Context:
3939 * Kernel Context
3940 */
3941
3942int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003943qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003944 uint16_t vp_idx)
3945{
3946 int rval;
3947 mbx_cmd_t mc;
3948 mbx_cmd_t *mcp = &mc;
3949
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003950 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3951 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003952
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003953 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3954 mcp->mb[1] = format;
3955 mcp->mb[9] = vp_idx;
3956 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3957 mcp->in_mb = MBX_0|MBX_1;
3958 mcp->tov = MBX_TOV_SECONDS;
3959 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003960 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003961
3962 if (rval == QLA_SUCCESS) {
3963 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3964 rval = BIT_1;
3965 }
3966 } else
3967 rval = BIT_1;
3968
3969 return rval;
3970}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003971
3972int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003973qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003974 uint32_t size)
3975{
3976 int rval;
3977 mbx_cmd_t mc;
3978 mbx_cmd_t *mcp = &mc;
3979
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003980 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3981 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003982
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003983 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003984 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3985 mcp->mb[8] = MSW(addr);
3986 mcp->out_mb = MBX_8|MBX_0;
3987 } else {
3988 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3989 mcp->out_mb = MBX_0;
3990 }
3991 mcp->mb[1] = LSW(addr);
3992 mcp->mb[2] = MSW(req_dma);
3993 mcp->mb[3] = LSW(req_dma);
3994 mcp->mb[6] = MSW(MSD(req_dma));
3995 mcp->mb[7] = LSW(MSD(req_dma));
3996 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003997 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003998 mcp->mb[4] = MSW(size);
3999 mcp->mb[5] = LSW(size);
4000 mcp->out_mb |= MBX_5|MBX_4;
4001 } else {
4002 mcp->mb[4] = LSW(size);
4003 mcp->out_mb |= MBX_4;
4004 }
4005
4006 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004007 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004008 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004009 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004010
4011 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004012 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4013 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004014 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4016 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004017 }
4018
4019 return rval;
4020}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004021/* 84XX Support **************************************************************/
4022
4023struct cs84xx_mgmt_cmd {
4024 union {
4025 struct verify_chip_entry_84xx req;
4026 struct verify_chip_rsp_84xx rsp;
4027 } p;
4028};
4029
4030int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004031qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004032{
4033 int rval, retry;
4034 struct cs84xx_mgmt_cmd *mn;
4035 dma_addr_t mn_dma;
4036 uint16_t options;
4037 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004038 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004039
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004040 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4041 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004042
4043 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4044 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004045 return QLA_MEMORY_ALLOC_FAILED;
4046 }
4047
4048 /* Force Update? */
4049 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4050 /* Diagnostic firmware? */
4051 /* options |= MENLO_DIAG_FW; */
4052 /* We update the firmware with only one data sequence. */
4053 options |= VCO_END_OF_DATA;
4054
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004055 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004056 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004057 memset(mn, 0, sizeof(*mn));
4058 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4059 mn->p.req.entry_count = 1;
4060 mn->p.req.options = cpu_to_le16(options);
4061
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004062 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4063 "Dump of Verify Request.\n");
4064 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4065 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004066
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004067 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004068 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004069 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4070 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004071 goto verify_done;
4072 }
4073
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004074 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4075 "Dump of Verify Response.\n");
4076 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4077 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004078
4079 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4080 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4081 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004083 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004084
4085 if (status[0] != CS_COMPLETE) {
4086 rval = QLA_FUNCTION_FAILED;
4087 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004088 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4089 "Firmware update failed. Retrying "
4090 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004091 options |= VCO_DONT_UPDATE_FW;
4092 options &= ~VCO_FORCE_UPDATE;
4093 retry = 1;
4094 }
4095 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004096 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004097 "Firmware updated to %x.\n",
4098 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004099
4100 /* NOTE: we only update OP firmware. */
4101 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4102 ha->cs84xx->op_fw_version =
4103 le32_to_cpu(mn->p.rsp.fw_ver);
4104 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4105 flags);
4106 }
4107 } while (retry);
4108
4109verify_done:
4110 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4111
4112 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004113 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4114 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004115 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004116 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4117 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004118 }
4119
4120 return rval;
4121}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004122
4123int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004124qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004125{
4126 int rval;
4127 unsigned long flags;
4128 mbx_cmd_t mc;
4129 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004130 struct qla_hw_data *ha = vha->hw;
4131
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004132 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4133 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004134
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004135 if (IS_SHADOW_REG_CAPABLE(ha))
4136 req->options |= BIT_13;
4137
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004138 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004139 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004140 mcp->mb[2] = MSW(LSD(req->dma));
4141 mcp->mb[3] = LSW(LSD(req->dma));
4142 mcp->mb[6] = MSW(MSD(req->dma));
4143 mcp->mb[7] = LSW(MSD(req->dma));
4144 mcp->mb[5] = req->length;
4145 if (req->rsp)
4146 mcp->mb[10] = req->rsp->id;
4147 mcp->mb[12] = req->qos;
4148 mcp->mb[11] = req->vp_idx;
4149 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004150 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004151 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004152
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004153 mcp->mb[4] = req->id;
4154 /* que in ptr index */
4155 mcp->mb[8] = 0;
4156 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004157 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004158 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4159 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4160 mcp->in_mb = MBX_0;
4161 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004162 mcp->tov = MBX_TOV_SECONDS * 2;
4163
Chad Dupuisf73cb692014-02-26 04:15:06 -05004164 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004165 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004166 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004167 mcp->out_mb |= MBX_15;
4168 /* debug q create issue in SR-IOV */
4169 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4170 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004171
4172 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004173 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004174 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004175 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004176 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004177 }
4178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4179
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004180 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004181 if (rval != QLA_SUCCESS) {
4182 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4183 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4184 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004185 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4186 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004187 }
4188
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004189 return rval;
4190}
4191
4192int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004193qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004194{
4195 int rval;
4196 unsigned long flags;
4197 mbx_cmd_t mc;
4198 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004199 struct qla_hw_data *ha = vha->hw;
4200
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004201 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4202 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004203
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004204 if (IS_SHADOW_REG_CAPABLE(ha))
4205 rsp->options |= BIT_13;
4206
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004207 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004208 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004209 mcp->mb[2] = MSW(LSD(rsp->dma));
4210 mcp->mb[3] = LSW(LSD(rsp->dma));
4211 mcp->mb[6] = MSW(MSD(rsp->dma));
4212 mcp->mb[7] = LSW(MSD(rsp->dma));
4213 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004214 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004215 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004216 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004217 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004218
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004219 mcp->mb[4] = rsp->id;
4220 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004221 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004222 /* que out ptr index */
4223 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004224 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004225 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4226 mcp->in_mb = MBX_0;
4227 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004228 mcp->tov = MBX_TOV_SECONDS * 2;
4229
4230 if (IS_QLA81XX(ha)) {
4231 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4232 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004233 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004234 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4235 mcp->in_mb |= MBX_1;
4236 /* debug q create issue in SR-IOV */
4237 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4238 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004239
4240 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004241 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004242 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004243 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004244 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004245 }
4246
4247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4248
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004249 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004250 if (rval != QLA_SUCCESS) {
4251 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4252 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4253 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004254 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4255 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004256 }
4257
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004258 return rval;
4259}
4260
Andrew Vasquez8a659572009-02-08 20:50:12 -08004261int
4262qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4263{
4264 int rval;
4265 mbx_cmd_t mc;
4266 mbx_cmd_t *mcp = &mc;
4267
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004268 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4269 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004270
4271 mcp->mb[0] = MBC_IDC_ACK;
4272 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4273 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4274 mcp->in_mb = 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, 0x10da,
4281 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004282 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004283 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4284 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004285 }
4286
4287 return rval;
4288}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004289
4290int
4291qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4292{
4293 int rval;
4294 mbx_cmd_t mc;
4295 mbx_cmd_t *mcp = &mc;
4296
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004297 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4298 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004299
Chad Dupuisf73cb692014-02-26 04:15:06 -05004300 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4301 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004302 return QLA_FUNCTION_FAILED;
4303
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004304 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4305 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4306 mcp->out_mb = MBX_1|MBX_0;
4307 mcp->in_mb = MBX_1|MBX_0;
4308 mcp->tov = MBX_TOV_SECONDS;
4309 mcp->flags = 0;
4310 rval = qla2x00_mailbox_command(vha, mcp);
4311
4312 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004313 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4314 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4315 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004316 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004317 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4318 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004319 *sector_size = mcp->mb[1];
4320 }
4321
4322 return rval;
4323}
4324
4325int
4326qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4327{
4328 int rval;
4329 mbx_cmd_t mc;
4330 mbx_cmd_t *mcp = &mc;
4331
Chad Dupuisf73cb692014-02-26 04:15:06 -05004332 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4333 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004334 return QLA_FUNCTION_FAILED;
4335
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004336 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4337 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004338
4339 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4340 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4341 FAC_OPT_CMD_WRITE_PROTECT;
4342 mcp->out_mb = MBX_1|MBX_0;
4343 mcp->in_mb = MBX_1|MBX_0;
4344 mcp->tov = MBX_TOV_SECONDS;
4345 mcp->flags = 0;
4346 rval = qla2x00_mailbox_command(vha, mcp);
4347
4348 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004349 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4350 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4351 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004352 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004353 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4354 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004355 }
4356
4357 return rval;
4358}
4359
4360int
4361qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4362{
4363 int rval;
4364 mbx_cmd_t mc;
4365 mbx_cmd_t *mcp = &mc;
4366
Chad Dupuisf73cb692014-02-26 04:15:06 -05004367 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4368 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004369 return QLA_FUNCTION_FAILED;
4370
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4372 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004373
4374 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4375 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4376 mcp->mb[2] = LSW(start);
4377 mcp->mb[3] = MSW(start);
4378 mcp->mb[4] = LSW(finish);
4379 mcp->mb[5] = MSW(finish);
4380 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4381 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4382 mcp->tov = MBX_TOV_SECONDS;
4383 mcp->flags = 0;
4384 rval = qla2x00_mailbox_command(vha, mcp);
4385
4386 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004387 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4388 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4389 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004390 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4392 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004393 }
4394
4395 return rval;
4396}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004397
4398int
4399qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4400{
4401 int rval = 0;
4402 mbx_cmd_t mc;
4403 mbx_cmd_t *mcp = &mc;
4404
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004405 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4406 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004407
4408 mcp->mb[0] = MBC_RESTART_MPI_FW;
4409 mcp->out_mb = MBX_0;
4410 mcp->in_mb = MBX_0|MBX_1;
4411 mcp->tov = MBX_TOV_SECONDS;
4412 mcp->flags = 0;
4413 rval = qla2x00_mailbox_command(vha, mcp);
4414
4415 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004416 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4417 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4418 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004419 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004420 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4421 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004422 }
4423
4424 return rval;
4425}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004426
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004427int
4428qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4429{
4430 int rval;
4431 mbx_cmd_t mc;
4432 mbx_cmd_t *mcp = &mc;
4433 int i;
4434 int len;
4435 uint16_t *str;
4436 struct qla_hw_data *ha = vha->hw;
4437
4438 if (!IS_P3P_TYPE(ha))
4439 return QLA_FUNCTION_FAILED;
4440
4441 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4442 "Entered %s.\n", __func__);
4443
4444 str = (void *)version;
4445 len = strlen(version);
4446
4447 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4448 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4449 mcp->out_mb = MBX_1|MBX_0;
4450 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4451 mcp->mb[i] = cpu_to_le16p(str);
4452 mcp->out_mb |= 1<<i;
4453 }
4454 for (; i < 16; i++) {
4455 mcp->mb[i] = 0;
4456 mcp->out_mb |= 1<<i;
4457 }
4458 mcp->in_mb = MBX_1|MBX_0;
4459 mcp->tov = MBX_TOV_SECONDS;
4460 mcp->flags = 0;
4461 rval = qla2x00_mailbox_command(vha, mcp);
4462
4463 if (rval != QLA_SUCCESS) {
4464 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4465 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4466 } else {
4467 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4468 "Done %s.\n", __func__);
4469 }
4470
4471 return rval;
4472}
4473
4474int
4475qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4476{
4477 int rval;
4478 mbx_cmd_t mc;
4479 mbx_cmd_t *mcp = &mc;
4480 int len;
4481 uint16_t dwlen;
4482 uint8_t *str;
4483 dma_addr_t str_dma;
4484 struct qla_hw_data *ha = vha->hw;
4485
4486 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4487 IS_P3P_TYPE(ha))
4488 return QLA_FUNCTION_FAILED;
4489
4490 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4491 "Entered %s.\n", __func__);
4492
4493 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4494 if (!str) {
4495 ql_log(ql_log_warn, vha, 0x117f,
4496 "Failed to allocate driver version param.\n");
4497 return QLA_MEMORY_ALLOC_FAILED;
4498 }
4499
4500 memcpy(str, "\x7\x3\x11\x0", 4);
4501 dwlen = str[0];
4502 len = dwlen * 4 - 4;
4503 memset(str + 4, 0, len);
4504 if (len > strlen(version))
4505 len = strlen(version);
4506 memcpy(str + 4, version, len);
4507
4508 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4509 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4510 mcp->mb[2] = MSW(LSD(str_dma));
4511 mcp->mb[3] = LSW(LSD(str_dma));
4512 mcp->mb[6] = MSW(MSD(str_dma));
4513 mcp->mb[7] = LSW(MSD(str_dma));
4514 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4515 mcp->in_mb = MBX_1|MBX_0;
4516 mcp->tov = MBX_TOV_SECONDS;
4517 mcp->flags = 0;
4518 rval = qla2x00_mailbox_command(vha, mcp);
4519
4520 if (rval != QLA_SUCCESS) {
4521 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4522 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4523 } else {
4524 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4525 "Done %s.\n", __func__);
4526 }
4527
4528 dma_pool_free(ha->s_dma_pool, str, str_dma);
4529
4530 return rval;
4531}
4532
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004533static int
4534qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4535{
4536 int rval;
4537 mbx_cmd_t mc;
4538 mbx_cmd_t *mcp = &mc;
4539
4540 if (!IS_FWI2_CAPABLE(vha->hw))
4541 return QLA_FUNCTION_FAILED;
4542
4543 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4544 "Entered %s.\n", __func__);
4545
4546 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4547 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4548 mcp->out_mb = MBX_1|MBX_0;
4549 mcp->in_mb = MBX_1|MBX_0;
4550 mcp->tov = MBX_TOV_SECONDS;
4551 mcp->flags = 0;
4552 rval = qla2x00_mailbox_command(vha, mcp);
4553 *temp = mcp->mb[1];
4554
4555 if (rval != QLA_SUCCESS) {
4556 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4557 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4558 } else {
4559 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4560 "Done %s.\n", __func__);
4561 }
4562
4563 return rval;
4564}
4565
Joe Carnuccio3a117112013-02-08 01:58:00 -05004566int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004567qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4568 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004569{
4570 int rval;
4571 mbx_cmd_t mc;
4572 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004573 struct qla_hw_data *ha = vha->hw;
4574
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004575 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4576 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004577
Joe Carnuccio6766df92011-05-10 11:30:15 -07004578 if (!IS_FWI2_CAPABLE(ha))
4579 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004580
Joe Carnuccio6766df92011-05-10 11:30:15 -07004581 if (len == 1)
4582 opt |= BIT_0;
4583
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004584 mcp->mb[0] = MBC_READ_SFP;
4585 mcp->mb[1] = dev;
4586 mcp->mb[2] = MSW(sfp_dma);
4587 mcp->mb[3] = LSW(sfp_dma);
4588 mcp->mb[6] = MSW(MSD(sfp_dma));
4589 mcp->mb[7] = LSW(MSD(sfp_dma));
4590 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004591 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004592 mcp->mb[10] = opt;
4593 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 -07004594 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004595 mcp->tov = MBX_TOV_SECONDS;
4596 mcp->flags = 0;
4597 rval = qla2x00_mailbox_command(vha, mcp);
4598
4599 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004600 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004601
4602 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004603 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4604 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004605 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004606 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4607 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004608 }
4609
4610 return rval;
4611}
4612
4613int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004614qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4615 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004616{
4617 int rval;
4618 mbx_cmd_t mc;
4619 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004620 struct qla_hw_data *ha = vha->hw;
4621
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004622 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4623 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004624
Joe Carnuccio6766df92011-05-10 11:30:15 -07004625 if (!IS_FWI2_CAPABLE(ha))
4626 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004627
Joe Carnuccio6766df92011-05-10 11:30:15 -07004628 if (len == 1)
4629 opt |= BIT_0;
4630
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004631 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004632 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004633
4634 mcp->mb[0] = MBC_WRITE_SFP;
4635 mcp->mb[1] = dev;
4636 mcp->mb[2] = MSW(sfp_dma);
4637 mcp->mb[3] = LSW(sfp_dma);
4638 mcp->mb[6] = MSW(MSD(sfp_dma));
4639 mcp->mb[7] = LSW(MSD(sfp_dma));
4640 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004641 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004642 mcp->mb[10] = opt;
4643 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 -07004644 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004645 mcp->tov = MBX_TOV_SECONDS;
4646 mcp->flags = 0;
4647 rval = qla2x00_mailbox_command(vha, mcp);
4648
4649 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004650 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4651 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004652 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004653 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4654 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004655 }
4656
4657 return rval;
4658}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004659
4660int
4661qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4662 uint16_t size_in_bytes, uint16_t *actual_size)
4663{
4664 int rval;
4665 mbx_cmd_t mc;
4666 mbx_cmd_t *mcp = &mc;
4667
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004668 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4669 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004670
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004671 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004672 return QLA_FUNCTION_FAILED;
4673
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004674 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4675 mcp->mb[2] = MSW(stats_dma);
4676 mcp->mb[3] = LSW(stats_dma);
4677 mcp->mb[6] = MSW(MSD(stats_dma));
4678 mcp->mb[7] = LSW(MSD(stats_dma));
4679 mcp->mb[8] = size_in_bytes >> 2;
4680 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4681 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4682 mcp->tov = MBX_TOV_SECONDS;
4683 mcp->flags = 0;
4684 rval = qla2x00_mailbox_command(vha, mcp);
4685
4686 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004687 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4688 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4689 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004690 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004691 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4692 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004693
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004694
4695 *actual_size = mcp->mb[2] << 2;
4696 }
4697
4698 return rval;
4699}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004700
4701int
4702qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4703 uint16_t size)
4704{
4705 int rval;
4706 mbx_cmd_t mc;
4707 mbx_cmd_t *mcp = &mc;
4708
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004709 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4710 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004711
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004712 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004713 return QLA_FUNCTION_FAILED;
4714
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004715 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4716 mcp->mb[1] = 0;
4717 mcp->mb[2] = MSW(tlv_dma);
4718 mcp->mb[3] = LSW(tlv_dma);
4719 mcp->mb[6] = MSW(MSD(tlv_dma));
4720 mcp->mb[7] = LSW(MSD(tlv_dma));
4721 mcp->mb[8] = size;
4722 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4723 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4724 mcp->tov = MBX_TOV_SECONDS;
4725 mcp->flags = 0;
4726 rval = qla2x00_mailbox_command(vha, mcp);
4727
4728 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004729 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4730 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4731 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004732 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004733 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4734 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004735 }
4736
4737 return rval;
4738}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004739
4740int
4741qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4742{
4743 int rval;
4744 mbx_cmd_t mc;
4745 mbx_cmd_t *mcp = &mc;
4746
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004747 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4748 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004749
Andrew Vasquez18e75552009-06-03 09:55:30 -07004750 if (!IS_FWI2_CAPABLE(vha->hw))
4751 return QLA_FUNCTION_FAILED;
4752
Andrew Vasquez18e75552009-06-03 09:55:30 -07004753 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4754 mcp->mb[1] = LSW(risc_addr);
4755 mcp->mb[8] = MSW(risc_addr);
4756 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4757 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4758 mcp->tov = 30;
4759 mcp->flags = 0;
4760 rval = qla2x00_mailbox_command(vha, mcp);
4761 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004762 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4763 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004764 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004765 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4766 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004767 *data = mcp->mb[3] << 16 | mcp->mb[2];
4768 }
4769
4770 return rval;
4771}
4772
4773int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004774qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4775 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004776{
4777 int rval;
4778 mbx_cmd_t mc;
4779 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004780
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004781 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4782 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004783
4784 memset(mcp->mb, 0 , sizeof(mcp->mb));
4785 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4786 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4787
4788 /* transfer count */
4789 mcp->mb[10] = LSW(mreq->transfer_size);
4790 mcp->mb[11] = MSW(mreq->transfer_size);
4791
4792 /* send data address */
4793 mcp->mb[14] = LSW(mreq->send_dma);
4794 mcp->mb[15] = MSW(mreq->send_dma);
4795 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4796 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4797
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004798 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004799 mcp->mb[16] = LSW(mreq->rcv_dma);
4800 mcp->mb[17] = MSW(mreq->rcv_dma);
4801 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4802 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4803
4804 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04004805 mcp->mb[18] = LSW(mreq->iteration_count);
4806 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004807
4808 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4809 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 -08004810 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004811 mcp->out_mb |= MBX_2;
4812 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4813
4814 mcp->buf_size = mreq->transfer_size;
4815 mcp->tov = MBX_TOV_SECONDS;
4816 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4817
4818 rval = qla2x00_mailbox_command(vha, mcp);
4819
4820 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004821 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4822 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4823 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4824 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004825 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004826 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4827 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004828 }
4829
4830 /* Copy mailbox information */
4831 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004832 return rval;
4833}
4834
4835int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004836qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4837 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004838{
4839 int rval;
4840 mbx_cmd_t mc;
4841 mbx_cmd_t *mcp = &mc;
4842 struct qla_hw_data *ha = vha->hw;
4843
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004844 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4845 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004846
4847 memset(mcp->mb, 0 , sizeof(mcp->mb));
4848 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
4849 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004850 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004851 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004852 mcp->mb[2] = vha->fcoe_fcf_idx;
4853 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004854 mcp->mb[16] = LSW(mreq->rcv_dma);
4855 mcp->mb[17] = MSW(mreq->rcv_dma);
4856 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4857 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4858
4859 mcp->mb[10] = LSW(mreq->transfer_size);
4860
4861 mcp->mb[14] = LSW(mreq->send_dma);
4862 mcp->mb[15] = MSW(mreq->send_dma);
4863 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4864 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4865
4866 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4867 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004868 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004869 mcp->out_mb |= MBX_2;
4870
4871 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004872 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4873 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004874 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004875 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004876 mcp->in_mb |= MBX_3;
4877
4878 mcp->tov = MBX_TOV_SECONDS;
4879 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4880 mcp->buf_size = mreq->transfer_size;
4881
4882 rval = qla2x00_mailbox_command(vha, mcp);
4883
4884 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004885 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4886 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4887 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004888 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004889 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4890 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004891 }
4892
4893 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004894 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004895 return rval;
4896}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004897
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004898int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004899qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004900{
4901 int rval;
4902 mbx_cmd_t mc;
4903 mbx_cmd_t *mcp = &mc;
4904
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004905 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004906 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004907
4908 mcp->mb[0] = MBC_ISP84XX_RESET;
4909 mcp->mb[1] = enable_diagnostic;
4910 mcp->out_mb = MBX_1|MBX_0;
4911 mcp->in_mb = MBX_1|MBX_0;
4912 mcp->tov = MBX_TOV_SECONDS;
4913 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004914 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004915
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004916 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004917 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004918 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004919 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4920 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004921
4922 return rval;
4923}
4924
4925int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004926qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4927{
4928 int rval;
4929 mbx_cmd_t mc;
4930 mbx_cmd_t *mcp = &mc;
4931
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004932 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4933 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004934
Andrew Vasquez18e75552009-06-03 09:55:30 -07004935 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004936 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004937
Andrew Vasquez18e75552009-06-03 09:55:30 -07004938 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4939 mcp->mb[1] = LSW(risc_addr);
4940 mcp->mb[2] = LSW(data);
4941 mcp->mb[3] = MSW(data);
4942 mcp->mb[8] = MSW(risc_addr);
4943 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4944 mcp->in_mb = MBX_0;
4945 mcp->tov = 30;
4946 mcp->flags = 0;
4947 rval = qla2x00_mailbox_command(vha, mcp);
4948 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004949 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4950 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004951 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004952 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4953 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004954 }
4955
4956 return rval;
4957}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004958
4959int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004960qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4961{
4962 int rval;
4963 uint32_t stat, timer;
4964 uint16_t mb0 = 0;
4965 struct qla_hw_data *ha = vha->hw;
4966 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4967
4968 rval = QLA_SUCCESS;
4969
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004970 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4971 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004972
4973 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4974
4975 /* Write the MBC data to the registers */
4976 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4977 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4978 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4979 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4980 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4981
4982 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4983
4984 /* Poll for MBC interrupt */
4985 for (timer = 6000000; timer; timer--) {
4986 /* Check for pending interrupts. */
4987 stat = RD_REG_DWORD(&reg->host_status);
4988 if (stat & HSRX_RISC_INT) {
4989 stat &= 0xff;
4990
4991 if (stat == 0x1 || stat == 0x2 ||
4992 stat == 0x10 || stat == 0x11) {
4993 set_bit(MBX_INTERRUPT,
4994 &ha->mbx_cmd_flags);
4995 mb0 = RD_REG_WORD(&reg->mailbox0);
4996 WRT_REG_DWORD(&reg->hccr,
4997 HCCRX_CLR_RISC_INT);
4998 RD_REG_DWORD(&reg->hccr);
4999 break;
5000 }
5001 }
5002 udelay(5);
5003 }
5004
5005 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5006 rval = mb0 & MBS_MASK;
5007 else
5008 rval = QLA_FUNCTION_FAILED;
5009
5010 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005011 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5012 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005013 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005014 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5015 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005016 }
5017
5018 return rval;
5019}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005020
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005021int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005022qla2x00_get_data_rate(scsi_qla_host_t *vha)
5023{
5024 int rval;
5025 mbx_cmd_t mc;
5026 mbx_cmd_t *mcp = &mc;
5027 struct qla_hw_data *ha = vha->hw;
5028
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005029 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5030 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005031
Michael Hernandez3064ff32009-12-15 21:29:44 -08005032 if (!IS_FWI2_CAPABLE(ha))
5033 return QLA_FUNCTION_FAILED;
5034
Michael Hernandez3064ff32009-12-15 21:29:44 -08005035 mcp->mb[0] = MBC_DATA_RATE;
5036 mcp->mb[1] = 0;
5037 mcp->out_mb = MBX_1|MBX_0;
5038 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005039 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005040 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005041 mcp->tov = MBX_TOV_SECONDS;
5042 mcp->flags = 0;
5043 rval = qla2x00_mailbox_command(vha, mcp);
5044 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005045 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5046 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005047 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005048 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5049 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005050 if (mcp->mb[1] != 0x7)
5051 ha->link_data_rate = mcp->mb[1];
5052 }
5053
5054 return rval;
5055}
Sarang Radke09ff7012010-03-19 17:03:59 -07005056
5057int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005058qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5059{
5060 int rval;
5061 mbx_cmd_t mc;
5062 mbx_cmd_t *mcp = &mc;
5063 struct qla_hw_data *ha = vha->hw;
5064
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005065 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5066 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005067
Chad Dupuisf73cb692014-02-26 04:15:06 -05005068 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5069 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005070 return QLA_FUNCTION_FAILED;
5071 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5072 mcp->out_mb = MBX_0;
5073 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5074 mcp->tov = MBX_TOV_SECONDS;
5075 mcp->flags = 0;
5076
5077 rval = qla2x00_mailbox_command(vha, mcp);
5078
5079 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005080 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5081 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005082 } else {
5083 /* Copy all bits to preserve original value */
5084 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5085
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005086 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5087 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005088 }
5089 return rval;
5090}
5091
5092int
5093qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5094{
5095 int rval;
5096 mbx_cmd_t mc;
5097 mbx_cmd_t *mcp = &mc;
5098
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005099 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5100 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005101
5102 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5103 /* Copy all bits to preserve original setting */
5104 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5105 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5106 mcp->in_mb = MBX_0;
5107 mcp->tov = MBX_TOV_SECONDS;
5108 mcp->flags = 0;
5109 rval = qla2x00_mailbox_command(vha, mcp);
5110
5111 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005112 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5113 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005114 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005115 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5116 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005117
5118 return rval;
5119}
5120
5121
5122int
Sarang Radke09ff7012010-03-19 17:03:59 -07005123qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5124 uint16_t *mb)
5125{
5126 int rval;
5127 mbx_cmd_t mc;
5128 mbx_cmd_t *mcp = &mc;
5129 struct qla_hw_data *ha = vha->hw;
5130
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005131 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5132 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005133
Sarang Radke09ff7012010-03-19 17:03:59 -07005134 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5135 return QLA_FUNCTION_FAILED;
5136
Sarang Radke09ff7012010-03-19 17:03:59 -07005137 mcp->mb[0] = MBC_PORT_PARAMS;
5138 mcp->mb[1] = loop_id;
5139 if (ha->flags.fcp_prio_enabled)
5140 mcp->mb[2] = BIT_1;
5141 else
5142 mcp->mb[2] = BIT_2;
5143 mcp->mb[4] = priority & 0xf;
5144 mcp->mb[9] = vha->vp_idx;
5145 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5146 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5147 mcp->tov = 30;
5148 mcp->flags = 0;
5149 rval = qla2x00_mailbox_command(vha, mcp);
5150 if (mb != NULL) {
5151 mb[0] = mcp->mb[0];
5152 mb[1] = mcp->mb[1];
5153 mb[3] = mcp->mb[3];
5154 mb[4] = mcp->mb[4];
5155 }
5156
5157 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005158 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005159 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5161 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005162 }
5163
5164 return rval;
5165}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005166
5167int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005168qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005169{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005170 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005171 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005172 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005173
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005174 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5175 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5176 "Thermal not supported by this card.\n");
5177 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005178 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005179
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005180 if (IS_QLA25XX(ha)) {
5181 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5182 ha->pdev->subsystem_device == 0x0175) {
5183 rval = qla2x00_read_sfp(vha, 0, &byte,
5184 0x98, 0x1, 1, BIT_13|BIT_0);
5185 *temp = byte;
5186 return rval;
5187 }
5188 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5189 ha->pdev->subsystem_device == 0x338e) {
5190 rval = qla2x00_read_sfp(vha, 0, &byte,
5191 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5192 *temp = byte;
5193 return rval;
5194 }
5195 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5196 "Thermal not supported by this card.\n");
5197 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005198 }
5199
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005200 if (IS_QLA82XX(ha)) {
5201 *temp = qla82xx_read_temperature(vha);
5202 rval = QLA_SUCCESS;
5203 return rval;
5204 } else if (IS_QLA8044(ha)) {
5205 *temp = qla8044_read_temperature(vha);
5206 rval = QLA_SUCCESS;
5207 return rval;
5208 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005209
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005210 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005211 return rval;
5212}
5213
5214int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005215qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5216{
5217 int rval;
5218 struct qla_hw_data *ha = vha->hw;
5219 mbx_cmd_t mc;
5220 mbx_cmd_t *mcp = &mc;
5221
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005222 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5223 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005224
Giridhar Malavalia9083012010-04-12 17:59:55 -07005225 if (!IS_FWI2_CAPABLE(ha))
5226 return QLA_FUNCTION_FAILED;
5227
Giridhar Malavalia9083012010-04-12 17:59:55 -07005228 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005229 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005230 mcp->mb[1] = 1;
5231
5232 mcp->out_mb = MBX_1|MBX_0;
5233 mcp->in_mb = MBX_0;
5234 mcp->tov = 30;
5235 mcp->flags = 0;
5236
5237 rval = qla2x00_mailbox_command(vha, mcp);
5238 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005239 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5240 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005241 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5243 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005244 }
5245
5246 return rval;
5247}
5248
5249int
5250qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5251{
5252 int rval;
5253 struct qla_hw_data *ha = vha->hw;
5254 mbx_cmd_t mc;
5255 mbx_cmd_t *mcp = &mc;
5256
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005257 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5258 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005259
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005260 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005261 return QLA_FUNCTION_FAILED;
5262
Giridhar Malavalia9083012010-04-12 17:59:55 -07005263 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005264 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005265 mcp->mb[1] = 0;
5266
5267 mcp->out_mb = MBX_1|MBX_0;
5268 mcp->in_mb = MBX_0;
5269 mcp->tov = 30;
5270 mcp->flags = 0;
5271
5272 rval = qla2x00_mailbox_command(vha, mcp);
5273 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005274 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5275 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005276 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005277 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5278 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005279 }
5280
5281 return rval;
5282}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005283
5284int
5285qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5286{
5287 struct qla_hw_data *ha = vha->hw;
5288 mbx_cmd_t mc;
5289 mbx_cmd_t *mcp = &mc;
5290 int rval = QLA_FUNCTION_FAILED;
5291
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005292 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5293 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005294
5295 memset(mcp->mb, 0 , sizeof(mcp->mb));
5296 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5297 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5298 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5299 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5300
5301 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5302 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5303 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5304
5305 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5306 mcp->tov = MBX_TOV_SECONDS;
5307 rval = qla2x00_mailbox_command(vha, mcp);
5308
5309 /* Always copy back return mailbox values. */
5310 if (rval != QLA_SUCCESS) {
5311 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5312 "mailbox command FAILED=0x%x, subcode=%x.\n",
5313 (mcp->mb[1] << 16) | mcp->mb[0],
5314 (mcp->mb[3] << 16) | mcp->mb[2]);
5315 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005316 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5317 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005318 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5319 if (!ha->md_template_size) {
5320 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5321 "Null template size obtained.\n");
5322 rval = QLA_FUNCTION_FAILED;
5323 }
5324 }
5325 return rval;
5326}
5327
5328int
5329qla82xx_md_get_template(scsi_qla_host_t *vha)
5330{
5331 struct qla_hw_data *ha = vha->hw;
5332 mbx_cmd_t mc;
5333 mbx_cmd_t *mcp = &mc;
5334 int rval = QLA_FUNCTION_FAILED;
5335
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005336 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5337 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005338
5339 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5340 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5341 if (!ha->md_tmplt_hdr) {
5342 ql_log(ql_log_warn, vha, 0x1124,
5343 "Unable to allocate memory for Minidump template.\n");
5344 return rval;
5345 }
5346
5347 memset(mcp->mb, 0 , sizeof(mcp->mb));
5348 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5349 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5350 mcp->mb[2] = LSW(RQST_TMPLT);
5351 mcp->mb[3] = MSW(RQST_TMPLT);
5352 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5353 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5354 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5355 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5356 mcp->mb[8] = LSW(ha->md_template_size);
5357 mcp->mb[9] = MSW(ha->md_template_size);
5358
5359 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5360 mcp->tov = MBX_TOV_SECONDS;
5361 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5362 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5363 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5364 rval = qla2x00_mailbox_command(vha, mcp);
5365
5366 if (rval != QLA_SUCCESS) {
5367 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5368 "mailbox command FAILED=0x%x, subcode=%x.\n",
5369 ((mcp->mb[1] << 16) | mcp->mb[0]),
5370 ((mcp->mb[3] << 16) | mcp->mb[2]));
5371 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005372 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5373 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005374 return rval;
5375}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005376
5377int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005378qla8044_md_get_template(scsi_qla_host_t *vha)
5379{
5380 struct qla_hw_data *ha = vha->hw;
5381 mbx_cmd_t mc;
5382 mbx_cmd_t *mcp = &mc;
5383 int rval = QLA_FUNCTION_FAILED;
5384 int offset = 0, size = MINIDUMP_SIZE_36K;
5385 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5386 "Entered %s.\n", __func__);
5387
5388 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5389 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5390 if (!ha->md_tmplt_hdr) {
5391 ql_log(ql_log_warn, vha, 0xb11b,
5392 "Unable to allocate memory for Minidump template.\n");
5393 return rval;
5394 }
5395
5396 memset(mcp->mb, 0 , sizeof(mcp->mb));
5397 while (offset < ha->md_template_size) {
5398 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5399 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5400 mcp->mb[2] = LSW(RQST_TMPLT);
5401 mcp->mb[3] = MSW(RQST_TMPLT);
5402 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5403 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5404 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5405 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5406 mcp->mb[8] = LSW(size);
5407 mcp->mb[9] = MSW(size);
5408 mcp->mb[10] = offset & 0x0000FFFF;
5409 mcp->mb[11] = offset & 0xFFFF0000;
5410 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5411 mcp->tov = MBX_TOV_SECONDS;
5412 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5413 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5414 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5415 rval = qla2x00_mailbox_command(vha, mcp);
5416
5417 if (rval != QLA_SUCCESS) {
5418 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5419 "mailbox command FAILED=0x%x, subcode=%x.\n",
5420 ((mcp->mb[1] << 16) | mcp->mb[0]),
5421 ((mcp->mb[3] << 16) | mcp->mb[2]));
5422 return rval;
5423 } else
5424 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5425 "Done %s.\n", __func__);
5426 offset = offset + size;
5427 }
5428 return rval;
5429}
5430
5431int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005432qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5433{
5434 int rval;
5435 struct qla_hw_data *ha = vha->hw;
5436 mbx_cmd_t mc;
5437 mbx_cmd_t *mcp = &mc;
5438
5439 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5440 return QLA_FUNCTION_FAILED;
5441
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005442 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5443 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005444
5445 memset(mcp, 0, sizeof(mbx_cmd_t));
5446 mcp->mb[0] = MBC_SET_LED_CONFIG;
5447 mcp->mb[1] = led_cfg[0];
5448 mcp->mb[2] = led_cfg[1];
5449 if (IS_QLA8031(ha)) {
5450 mcp->mb[3] = led_cfg[2];
5451 mcp->mb[4] = led_cfg[3];
5452 mcp->mb[5] = led_cfg[4];
5453 mcp->mb[6] = led_cfg[5];
5454 }
5455
5456 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5457 if (IS_QLA8031(ha))
5458 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5459 mcp->in_mb = MBX_0;
5460 mcp->tov = 30;
5461 mcp->flags = 0;
5462
5463 rval = qla2x00_mailbox_command(vha, mcp);
5464 if (rval != QLA_SUCCESS) {
5465 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5466 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5467 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005468 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5469 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005470 }
5471
5472 return rval;
5473}
5474
5475int
5476qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5477{
5478 int rval;
5479 struct qla_hw_data *ha = vha->hw;
5480 mbx_cmd_t mc;
5481 mbx_cmd_t *mcp = &mc;
5482
5483 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5484 return QLA_FUNCTION_FAILED;
5485
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005486 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5487 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005488
5489 memset(mcp, 0, sizeof(mbx_cmd_t));
5490 mcp->mb[0] = MBC_GET_LED_CONFIG;
5491
5492 mcp->out_mb = MBX_0;
5493 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5494 if (IS_QLA8031(ha))
5495 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5496 mcp->tov = 30;
5497 mcp->flags = 0;
5498
5499 rval = qla2x00_mailbox_command(vha, mcp);
5500 if (rval != QLA_SUCCESS) {
5501 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5502 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5503 } else {
5504 led_cfg[0] = mcp->mb[1];
5505 led_cfg[1] = mcp->mb[2];
5506 if (IS_QLA8031(ha)) {
5507 led_cfg[2] = mcp->mb[3];
5508 led_cfg[3] = mcp->mb[4];
5509 led_cfg[4] = mcp->mb[5];
5510 led_cfg[5] = mcp->mb[6];
5511 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005512 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5513 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005514 }
5515
5516 return rval;
5517}
5518
5519int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005520qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5521{
5522 int rval;
5523 struct qla_hw_data *ha = vha->hw;
5524 mbx_cmd_t mc;
5525 mbx_cmd_t *mcp = &mc;
5526
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005527 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005528 return QLA_FUNCTION_FAILED;
5529
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005530 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005531 "Entered %s.\n", __func__);
5532
5533 memset(mcp, 0, sizeof(mbx_cmd_t));
5534 mcp->mb[0] = MBC_SET_LED_CONFIG;
5535 if (enable)
5536 mcp->mb[7] = 0xE;
5537 else
5538 mcp->mb[7] = 0xD;
5539
5540 mcp->out_mb = MBX_7|MBX_0;
5541 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005542 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005543 mcp->flags = 0;
5544
5545 rval = qla2x00_mailbox_command(vha, mcp);
5546 if (rval != QLA_SUCCESS) {
5547 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5548 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5549 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005550 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005551 "Done %s.\n", __func__);
5552 }
5553
5554 return rval;
5555}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005556
5557int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005558qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005559{
5560 int rval;
5561 struct qla_hw_data *ha = vha->hw;
5562 mbx_cmd_t mc;
5563 mbx_cmd_t *mcp = &mc;
5564
Chad Dupuisf73cb692014-02-26 04:15:06 -05005565 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005566 return QLA_FUNCTION_FAILED;
5567
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005568 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5569 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005570
5571 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5572 mcp->mb[1] = LSW(reg);
5573 mcp->mb[2] = MSW(reg);
5574 mcp->mb[3] = LSW(data);
5575 mcp->mb[4] = MSW(data);
5576 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5577
5578 mcp->in_mb = MBX_1|MBX_0;
5579 mcp->tov = MBX_TOV_SECONDS;
5580 mcp->flags = 0;
5581 rval = qla2x00_mailbox_command(vha, mcp);
5582
5583 if (rval != QLA_SUCCESS) {
5584 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5585 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5586 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005587 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005588 "Done %s.\n", __func__);
5589 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005590
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005591 return rval;
5592}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005593
5594int
5595qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5596{
5597 int rval;
5598 struct qla_hw_data *ha = vha->hw;
5599 mbx_cmd_t mc;
5600 mbx_cmd_t *mcp = &mc;
5601
5602 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005603 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005604 "Implicit LOGO Unsupported.\n");
5605 return QLA_FUNCTION_FAILED;
5606 }
5607
5608
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005609 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5610 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005611
5612 /* Perform Implicit LOGO. */
5613 mcp->mb[0] = MBC_PORT_LOGOUT;
5614 mcp->mb[1] = fcport->loop_id;
5615 mcp->mb[10] = BIT_15;
5616 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5617 mcp->in_mb = MBX_0;
5618 mcp->tov = MBX_TOV_SECONDS;
5619 mcp->flags = 0;
5620 rval = qla2x00_mailbox_command(vha, mcp);
5621 if (rval != QLA_SUCCESS)
5622 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5623 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5624 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005625 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5626 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005627
5628 return rval;
5629}
5630
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005631int
5632qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5633{
5634 int rval;
5635 mbx_cmd_t mc;
5636 mbx_cmd_t *mcp = &mc;
5637 struct qla_hw_data *ha = vha->hw;
5638 unsigned long retry_max_time = jiffies + (2 * HZ);
5639
Chad Dupuisf73cb692014-02-26 04:15:06 -05005640 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005641 return QLA_FUNCTION_FAILED;
5642
5643 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5644
5645retry_rd_reg:
5646 mcp->mb[0] = MBC_READ_REMOTE_REG;
5647 mcp->mb[1] = LSW(reg);
5648 mcp->mb[2] = MSW(reg);
5649 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5650 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5651 mcp->tov = MBX_TOV_SECONDS;
5652 mcp->flags = 0;
5653 rval = qla2x00_mailbox_command(vha, mcp);
5654
5655 if (rval != QLA_SUCCESS) {
5656 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5657 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5658 rval, mcp->mb[0], mcp->mb[1]);
5659 } else {
5660 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5661 if (*data == QLA8XXX_BAD_VALUE) {
5662 /*
5663 * During soft-reset CAMRAM register reads might
5664 * return 0xbad0bad0. So retry for MAX of 2 sec
5665 * while reading camram registers.
5666 */
5667 if (time_after(jiffies, retry_max_time)) {
5668 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5669 "Failure to read CAMRAM register. "
5670 "data=0x%x.\n", *data);
5671 return QLA_FUNCTION_FAILED;
5672 }
5673 msleep(100);
5674 goto retry_rd_reg;
5675 }
5676 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5677 }
5678
5679 return rval;
5680}
5681
5682int
5683qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5684{
5685 int rval;
5686 mbx_cmd_t mc;
5687 mbx_cmd_t *mcp = &mc;
5688 struct qla_hw_data *ha = vha->hw;
5689
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005690 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005691 return QLA_FUNCTION_FAILED;
5692
5693 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5694
5695 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5696 mcp->out_mb = MBX_0;
5697 mcp->in_mb = MBX_1|MBX_0;
5698 mcp->tov = MBX_TOV_SECONDS;
5699 mcp->flags = 0;
5700 rval = qla2x00_mailbox_command(vha, mcp);
5701
5702 if (rval != QLA_SUCCESS) {
5703 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5704 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5705 rval, mcp->mb[0], mcp->mb[1]);
5706 ha->isp_ops->fw_dump(vha, 0);
5707 } else {
5708 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5709 }
5710
5711 return rval;
5712}
5713
5714int
5715qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5716 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5717{
5718 int rval;
5719 mbx_cmd_t mc;
5720 mbx_cmd_t *mcp = &mc;
5721 uint8_t subcode = (uint8_t)options;
5722 struct qla_hw_data *ha = vha->hw;
5723
5724 if (!IS_QLA8031(ha))
5725 return QLA_FUNCTION_FAILED;
5726
5727 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5728
5729 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5730 mcp->mb[1] = options;
5731 mcp->out_mb = MBX_1|MBX_0;
5732 if (subcode & BIT_2) {
5733 mcp->mb[2] = LSW(start_addr);
5734 mcp->mb[3] = MSW(start_addr);
5735 mcp->mb[4] = LSW(end_addr);
5736 mcp->mb[5] = MSW(end_addr);
5737 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5738 }
5739 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5740 if (!(subcode & (BIT_2 | BIT_5)))
5741 mcp->in_mb |= MBX_4|MBX_3;
5742 mcp->tov = MBX_TOV_SECONDS;
5743 mcp->flags = 0;
5744 rval = qla2x00_mailbox_command(vha, mcp);
5745
5746 if (rval != QLA_SUCCESS) {
5747 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5748 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5749 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5750 mcp->mb[4]);
5751 ha->isp_ops->fw_dump(vha, 0);
5752 } else {
5753 if (subcode & BIT_5)
5754 *sector_size = mcp->mb[1];
5755 else if (subcode & (BIT_6 | BIT_7)) {
5756 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5757 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5758 } else if (subcode & (BIT_3 | BIT_4)) {
5759 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5760 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5761 }
5762 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5763 }
5764
5765 return rval;
5766}
Saurav Kashyap81178772012-08-22 14:21:04 -04005767
5768int
5769qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5770 uint32_t size)
5771{
5772 int rval;
5773 mbx_cmd_t mc;
5774 mbx_cmd_t *mcp = &mc;
5775
5776 if (!IS_MCTP_CAPABLE(vha->hw))
5777 return QLA_FUNCTION_FAILED;
5778
5779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5780 "Entered %s.\n", __func__);
5781
5782 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5783 mcp->mb[1] = LSW(addr);
5784 mcp->mb[2] = MSW(req_dma);
5785 mcp->mb[3] = LSW(req_dma);
5786 mcp->mb[4] = MSW(size);
5787 mcp->mb[5] = LSW(size);
5788 mcp->mb[6] = MSW(MSD(req_dma));
5789 mcp->mb[7] = LSW(MSD(req_dma));
5790 mcp->mb[8] = MSW(addr);
5791 /* Setting RAM ID to valid */
5792 mcp->mb[10] |= BIT_7;
5793 /* For MCTP RAM ID is 0x40 */
5794 mcp->mb[10] |= 0x40;
5795
5796 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5797 MBX_0;
5798
5799 mcp->in_mb = MBX_0;
5800 mcp->tov = MBX_TOV_SECONDS;
5801 mcp->flags = 0;
5802 rval = qla2x00_mailbox_command(vha, mcp);
5803
5804 if (rval != QLA_SUCCESS) {
5805 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5806 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5807 } else {
5808 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5809 "Done %s.\n", __func__);
5810 }
5811
5812 return rval;
5813}
Joe Carnuccioec891462016-07-06 11:14:26 -04005814
5815int
5816qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5817 void *dd_buf, uint size, uint options)
5818{
5819 int rval;
5820 mbx_cmd_t mc;
5821 mbx_cmd_t *mcp = &mc;
5822 dma_addr_t dd_dma;
5823
5824 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5825 return QLA_FUNCTION_FAILED;
5826
5827 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
5828 "Entered %s.\n", __func__);
5829
Joe Carnuccioec891462016-07-06 11:14:26 -04005830 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5831 dd_buf, size, DMA_FROM_DEVICE);
5832 if (!dd_dma) {
5833 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5834 return QLA_MEMORY_ALLOC_FAILED;
5835 }
5836
5837 memset(dd_buf, 0, size);
5838
5839 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5840 mcp->mb[1] = options;
5841 mcp->mb[2] = MSW(LSD(dd_dma));
5842 mcp->mb[3] = LSW(LSD(dd_dma));
5843 mcp->mb[6] = MSW(MSD(dd_dma));
5844 mcp->mb[7] = LSW(MSD(dd_dma));
5845 mcp->mb[8] = size;
5846 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5847 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5848 mcp->buf_size = size;
5849 mcp->flags = MBX_DMA_IN;
5850 mcp->tov = MBX_TOV_SECONDS * 4;
5851 rval = qla2x00_mailbox_command(vha, mcp);
5852
5853 if (rval != QLA_SUCCESS) {
5854 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5855 } else {
5856 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5857 "Done %s.\n", __func__);
5858 }
5859
5860 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5861 size, DMA_FROM_DEVICE);
5862
5863 return rval;
5864}