blob: 4a1f21c11758ea5b8ee0e2222bfb4f05fc49dc84 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Armen Baloyanbd21eaf2014-04-11 16:54:24 -04003 * Copyright (c) 2003-2014 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04008#include "qla_target.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Quinn Tran15f30a52017-03-15 09:48:52 -070013static struct mb_cmd_name {
14 uint16_t cmd;
15 const char *str;
16} mb_str[] = {
17 {MBC_GET_PORT_DATABASE, "GPDB"},
18 {MBC_GET_ID_LIST, "GIDList"},
19 {MBC_GET_LINK_PRIV_STATS, "Stats"},
Quinn Tran94d83e32017-12-28 12:33:23 -080020 {MBC_GET_RESOURCE_COUNTS, "ResCnt"},
Quinn Tran15f30a52017-03-15 09:48:52 -070021};
22
23static const char *mb_to_str(uint16_t cmd)
24{
25 int i;
26 struct mb_cmd_name *e;
27
28 for (i = 0; i < ARRAY_SIZE(mb_str); i++) {
29 e = mb_str + i;
30 if (cmd == e->cmd)
31 return e->str;
32 }
33 return "unknown";
34}
35
Bart Van Asscheca825822017-01-17 09:34:14 -080036static struct rom_cmd {
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080037 uint16_t cmd;
38} rom_cmds[] = {
39 { MBC_LOAD_RAM },
40 { MBC_EXECUTE_FIRMWARE },
41 { MBC_READ_RAM_WORD },
42 { MBC_MAILBOX_REGISTER_TEST },
43 { MBC_VERIFY_CHECKSUM },
44 { MBC_GET_FIRMWARE_VERSION },
45 { MBC_LOAD_RISC_RAM },
46 { MBC_DUMP_RISC_RAM },
47 { MBC_LOAD_RISC_RAM_EXTENDED },
48 { MBC_DUMP_RISC_RAM_EXTENDED },
49 { MBC_WRITE_RAM_WORD_EXTENDED },
50 { MBC_READ_RAM_EXTENDED },
51 { MBC_GET_RESOURCE_COUNTS },
52 { MBC_SET_FIRMWARE_OPTION },
53 { MBC_MID_INITIALIZE_FIRMWARE },
54 { MBC_GET_FIRMWARE_STATE },
55 { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
56 { MBC_GET_RETRY_COUNT },
57 { MBC_TRACE_CONTROL },
Michael Hernandezb7edfa22017-08-23 15:04:56 -070058 { MBC_INITIALIZE_MULTIQ },
Quinn Tran1608cc42017-08-23 15:05:03 -070059 { MBC_IOCB_COMMAND_A64 },
60 { MBC_GET_ADAPTER_LOOP_ID },
Quinn Trane4e3a2c2017-08-23 15:05:07 -070061 { MBC_READ_SFP },
Quinn Tran8777e432018-08-02 13:16:57 -070062 { MBC_GET_RNID_PARAMS },
Quinn Tran8b4673b2018-09-04 14:19:14 -070063 { MBC_GET_SET_ZIO_THRESHOLD },
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -080064};
65
66static int is_rom_cmd(uint16_t cmd)
67{
68 int i;
69 struct rom_cmd *wc;
70
71 for (i = 0; i < ARRAY_SIZE(rom_cmds); i++) {
72 wc = rom_cmds + i;
73 if (wc->cmd == cmd)
74 return 1;
75 }
76
77 return 0;
78}
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80/*
81 * qla2x00_mailbox_command
82 * Issue mailbox command and waits for completion.
83 *
84 * Input:
85 * ha = adapter block pointer.
86 * mcp = driver internal mbx struct pointer.
87 *
88 * Output:
89 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
90 *
91 * Returns:
92 * 0 : QLA_SUCCESS = cmd performed success
93 * 1 : QLA_FUNCTION_FAILED (error encountered)
94 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
95 *
96 * Context:
97 * Kernel context.
98 */
99static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800100qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400102 int rval, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 unsigned long flags = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500104 device_reg_t *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700105 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700106 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700107 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 uint16_t *iptr;
109 uint16_t __iomem *optr;
110 uint32_t cnt;
111 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800113 struct qla_hw_data *ha = vha->hw;
114 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Quinn Tranb2000802018-08-02 13:16:52 -0700115 u32 chip_reset;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700116
Himanshu Madhanid14e72f2015-04-09 15:00:03 -0400117
Arun Easi5e19ed92012-02-09 11:15:51 -0800118 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700119
120 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800121 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700122 "error_state is greater than pci_channel_io_frozen, "
123 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -0700124 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700125 }
Seokmann Jub9b12f72009-03-24 09:08:18 -0700126
Giridhar Malavalia9083012010-04-12 17:59:55 -0700127 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800128 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700129 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -0700130 return QLA_FUNCTION_TIMEOUT;
131 }
132
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800133 /* if PCI error, then avoid mbx processing.*/
Sawan Chandakba175892017-06-02 09:11:58 -0700134 if (test_bit(PFLG_DISCONNECTED, &base_vha->dpc_flags) &&
135 test_bit(UNLOADING, &base_vha->dpc_flags)) {
Quinn Tran83548fe2017-06-02 09:12:01 -0700136 ql_log(ql_log_warn, vha, 0xd04e,
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400137 "PCI error, exiting.\n");
138 return QLA_FUNCTION_TIMEOUT;
Bart Van Asschec2a5d942017-01-11 15:58:58 -0800139 }
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400140
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700141 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800142 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800145 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700146 chip_reset = ha->chip_reset;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700147
Andrew Vasquez85880802009-12-15 21:29:46 -0800148 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800149 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700150 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -0800151 return QLA_FUNCTION_TIMEOUT;
152 }
153
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400154 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -0800155 /* Setting Link-Down error */
156 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -0800157 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700158 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -0800159 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -0800160 }
161
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800162 /* check if ISP abort is active and return cmd with timeout */
163 if ((test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
164 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
165 test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) &&
166 !is_rom_cmd(mcp->mb[0])) {
167 ql_log(ql_log_info, vha, 0x1005,
168 "Cmd 0x%x aborted with timeout since ISP Abort is pending\n",
169 mcp->mb[0]);
170 return QLA_FUNCTION_TIMEOUT;
171 }
172
Quinn Tranb2000802018-08-02 13:16:52 -0700173 atomic_inc(&ha->num_pend_mbx_stage1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700175 * Wait for active mailbox commands to finish by waiting at most tov
176 * seconds. This is to serialize actual issuing of mailbox cmds during
177 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800179 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
180 /* Timeout occurred. Return error. */
Quinn Tran83548fe2017-06-02 09:12:01 -0700181 ql_log(ql_log_warn, vha, 0xd035,
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800182 "Cmd access timeout, cmd=0x%x, Exiting.\n",
183 mcp->mb[0]);
Quinn Tranb2000802018-08-02 13:16:52 -0700184 atomic_dec(&ha->num_pend_mbx_stage1);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800185 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
Quinn Tranb2000802018-08-02 13:16:52 -0700187 atomic_dec(&ha->num_pend_mbx_stage1);
188 if (ha->flags.purge_mbox || chip_reset != ha->chip_reset) {
189 rval = QLA_ABORTED;
190 goto premature_exit;
191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /* Save mailbox command for debug */
195 ha->mcp = mcp;
196
Arun Easi5e19ed92012-02-09 11:15:51 -0800197 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700198 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200 spin_lock_irqsave(&ha->hardware_lock, flags);
201
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700202 if (ha->flags.purge_mbox || chip_reset != ha->chip_reset ||
203 ha->flags.mbox_busy) {
Quinn Tranb2000802018-08-02 13:16:52 -0700204 rval = QLA_ABORTED;
Quinn Tranb2000802018-08-02 13:16:52 -0700205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
206 goto premature_exit;
207 }
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700208 ha->flags.mbox_busy = 1;
Quinn Tranb2000802018-08-02 13:16:52 -0700209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 /* Load mailbox registers. */
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400211 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700212 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400213 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha)))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700214 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
215 else
216 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218 iptr = mcp->mb;
219 command = mcp->mb[0];
220 mboxes = mcp->out_mb;
221
Joe Carnuccio7b711622014-09-25 05:16:43 -0400222 ql_dbg(ql_dbg_mbx, vha, 0x1111,
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700223 "Mailbox registers (OUT):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
225 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700226 optr =
227 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700228 if (mboxes & BIT_0) {
229 ql_dbg(ql_dbg_mbx, vha, 0x1112,
230 "mbox[%d]<-0x%04x\n", cnt, *iptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 WRT_REG_WORD(optr, *iptr);
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233
234 mboxes >>= 1;
235 optr++;
236 iptr++;
237 }
238
Arun Easi5e19ed92012-02-09 11:15:51 -0800239 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700240 "I/O Address = %p.\n", optr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242 /* Issue set host interrupt command to send cmd out. */
243 ha->flags.mbox_int = 0;
244 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
245
246 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800247 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700248 "Going to unlock irq & waiting for interrupts. "
249 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 /* Wait for mbx cmd completion until timeout */
Quinn Tranb2000802018-08-02 13:16:52 -0700252 atomic_inc(&ha->num_pend_mbx_stage2);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800253 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
255
Himanshu Madhani32a13df2019-08-30 15:23:59 -0700256 if (IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -0700257 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
Himanshu Madhani32a13df2019-08-30 15:23:59 -0700258 else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700259 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
260 else
261 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 spin_unlock_irqrestore(&ha->hardware_lock, flags);
263
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800264 wait_time = jiffies;
Quinn Tranb2000802018-08-02 13:16:52 -0700265 atomic_inc(&ha->num_pend_mbx_stage3);
Giridhar Malavali754d1242013-06-25 11:27:16 -0400266 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
267 mcp->tov * HZ)) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700268 if (chip_reset != ha->chip_reset) {
269 spin_lock_irqsave(&ha->hardware_lock, flags);
270 ha->flags.mbox_busy = 0;
271 spin_unlock_irqrestore(&ha->hardware_lock,
272 flags);
273 atomic_dec(&ha->num_pend_mbx_stage2);
274 atomic_dec(&ha->num_pend_mbx_stage3);
275 rval = QLA_ABORTED;
276 goto premature_exit;
277 }
Giridhar Malavali754d1242013-06-25 11:27:16 -0400278 ql_dbg(ql_dbg_mbx, vha, 0x117a,
279 "cmd=%x Timeout.\n", command);
280 spin_lock_irqsave(&ha->hardware_lock, flags);
281 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
282 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700283
284 } else if (ha->flags.purge_mbox ||
285 chip_reset != ha->chip_reset) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700286 spin_lock_irqsave(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700287 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700289 atomic_dec(&ha->num_pend_mbx_stage2);
290 atomic_dec(&ha->num_pend_mbx_stage3);
291 rval = QLA_ABORTED;
292 goto premature_exit;
Giridhar Malavali754d1242013-06-25 11:27:16 -0400293 }
Quinn Tranb2000802018-08-02 13:16:52 -0700294 atomic_dec(&ha->num_pend_mbx_stage3);
295
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800296 if (time_after(jiffies, wait_time + 5 * HZ))
297 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
298 command, jiffies_to_msecs(jiffies - wait_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800300 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700301 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400303 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700304 if (RD_REG_DWORD(&reg->isp82.hint) &
305 HINT_MBX_INT_PENDING) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700306 ha->flags.mbox_busy = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700307 spin_unlock_irqrestore(&ha->hardware_lock,
308 flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700309 atomic_dec(&ha->num_pend_mbx_stage2);
Arun Easi5e19ed92012-02-09 11:15:51 -0800310 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700311 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700312 rval = QLA_FUNCTION_TIMEOUT;
313 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700314 }
315 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
316 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700317 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
318 else
319 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
322 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
323 while (!ha->flags.mbox_int) {
Quinn Tranb2000802018-08-02 13:16:52 -0700324 if (ha->flags.purge_mbox ||
325 chip_reset != ha->chip_reset) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700326 spin_lock_irqsave(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700327 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700328 spin_unlock_irqrestore(&ha->hardware_lock,
329 flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700330 atomic_dec(&ha->num_pend_mbx_stage2);
331 rval = QLA_ABORTED;
332 goto premature_exit;
333 }
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 if (time_after(jiffies, wait_time))
336 break;
337
Rodrigo R. Galvao3cb182b2018-05-28 14:58:44 -0300338 /*
339 * Check if it's UNLOADING, cause we cannot poll in
340 * this case, or else a NULL pointer dereference
341 * is triggered.
342 */
343 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)))
344 return QLA_FUNCTION_TIMEOUT;
345
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800347 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Andrew Vasquez85880802009-12-15 21:29:46 -0800349 if (!ha->flags.mbox_int &&
350 !(IS_QLA2200(ha) &&
351 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800352 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800354 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700355 "Waited %d sec.\n",
356 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
Quinn Tranb2000802018-08-02 13:16:52 -0700358 atomic_dec(&ha->num_pend_mbx_stage2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 /* Check whether we timed out */
361 if (ha->flags.mbox_int) {
362 uint16_t *iptr2;
363
Arun Easi5e19ed92012-02-09 11:15:51 -0800364 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700365 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
367 /* Got interrupt. Clear the flag. */
368 ha->flags.mbox_int = 0;
369 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
370
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400371 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700372 spin_lock_irqsave(&ha->hardware_lock, flags);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700373 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700374 spin_unlock_irqrestore(&ha->hardware_lock, flags);
375
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700376 /* Setting Link-Down error */
377 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
378 ha->mcp = NULL;
379 rval = QLA_FUNCTION_FAILED;
Quinn Tran83548fe2017-06-02 09:12:01 -0700380 ql_log(ql_log_warn, vha, 0xd048,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700381 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700382 goto premature_exit;
383 }
384
Bart Van Asscheb3e97722019-08-08 20:01:41 -0700385 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) {
386 ql_dbg(ql_dbg_mbx, vha, 0x11ff,
387 "mb_out[0] = %#x <> %#x\n", ha->mailbox_out[0],
388 MBS_COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 rval = QLA_FUNCTION_FAILED;
Bart Van Asscheb3e97722019-08-08 20:01:41 -0700390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 /* Load return mailbox registers. */
393 iptr2 = mcp->mb;
394 iptr = (uint16_t *)&ha->mailbox_out[0];
395 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700396
397 ql_dbg(ql_dbg_mbx, vha, 0x1113,
398 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700400 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700402 ql_dbg(ql_dbg_mbx, vha, 0x1114,
403 "mbox[%d]->0x%04x\n", cnt, *iptr2);
404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 mboxes >>= 1;
407 iptr2++;
408 iptr++;
409 }
410 } else {
411
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800412 uint16_t mb[8];
413 uint32_t ictrl, host_status, hccr;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400414 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700415
Andrew Vasqueze4289242007-07-19 15:05:56 -0700416 if (IS_FWI2_CAPABLE(ha)) {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800417 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
418 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
419 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
420 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
421 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700422 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800423 host_status = RD_REG_DWORD(&reg->isp24.host_status);
424 hccr = RD_REG_DWORD(&reg->isp24.hccr);
425
Quinn Tran83548fe2017-06-02 09:12:01 -0700426 ql_log(ql_log_warn, vha, 0xd04c,
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800427 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
428 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
429 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
430 mb[7], host_status, hccr);
431
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700432 } else {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800433 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700434 ictrl = RD_REG_WORD(&reg->isp.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800435 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
436 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
437 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700438 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800439 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400441 /* Capture FW dump only, if PCI device active */
442 if (!pci_channel_offline(vha->hw->pdev)) {
443 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Quinn Tranb2000802018-08-02 13:16:52 -0700444 if (w == 0xffff || ictrl == 0xffffffff ||
445 (chip_reset != ha->chip_reset)) {
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400446 /* This is special case if there is unload
447 * of driver happening and if PCI device go
448 * into bad state due to PCI error condition
449 * then only PCI ERR flag would be set.
450 * we will do premature exit for above case.
451 */
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700452 spin_lock_irqsave(&ha->hardware_lock, flags);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400453 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700454 spin_unlock_irqrestore(&ha->hardware_lock,
455 flags);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400456 rval = QLA_FUNCTION_TIMEOUT;
457 goto premature_exit;
458 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800459
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400460 /* Attempt to capture firmware dump for further
461 * anallysis of the current formware state. we do not
462 * need to do this if we are intentionally generating
463 * a dump
464 */
465 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
466 ha->isp_ops->fw_dump(vha, 0);
467 rval = QLA_FUNCTION_TIMEOUT;
468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700470 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700472 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 /* Clean up */
475 ha->mcp = NULL;
476
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800477 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800478 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700479 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800482 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 }
484
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700485 if (rval == QLA_FUNCTION_TIMEOUT &&
486 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800487 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
488 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800490 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700491 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700492
493 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
494 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
495 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800496 if (IS_QLA82XX(ha)) {
497 ql_dbg(ql_dbg_mbx, vha, 0x112a,
498 "disabling pause transmit on port "
499 "0 & 1.\n");
500 qla82xx_wr_32(ha,
501 QLA82XX_CRB_NIU + 0x98,
502 CRB_NIU_XG_PAUSE_CTL_P0|
503 CRB_NIU_XG_PAUSE_CTL_P1);
504 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700505 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400506 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800507 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
508 "abort.\n", command, mcp->mb[0],
509 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700510 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
511 qla2xxx_wake_dpc(vha);
512 }
Quinn Tran710bc782018-09-26 22:05:16 -0700513 } else if (current == ha->dpc_thread) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800515 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700516 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700518 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
519 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
520 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800521 if (IS_QLA82XX(ha)) {
522 ql_dbg(ql_dbg_mbx, vha, 0x112b,
523 "disabling pause transmit on port "
524 "0 & 1.\n");
525 qla82xx_wr_32(ha,
526 QLA82XX_CRB_NIU + 0x98,
527 CRB_NIU_XG_PAUSE_CTL_P0|
528 CRB_NIU_XG_PAUSE_CTL_P1);
529 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700530 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400531 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800532 "mb[0]=0x%x. Scheduling ISP abort ",
533 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700534 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
535 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800536 /* Allow next mbx cmd to come in. */
537 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700538 if (ha->isp_ops->abort_isp(vha)) {
539 /* Failed. retry later. */
540 set_bit(ISP_ABORT_NEEDED,
541 &vha->dpc_flags);
542 }
543 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800544 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700545 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800546 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 }
549 }
550
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700551premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800553 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Giridhar Malavalid3360962012-02-09 11:14:10 -0800555mbx_done:
Quinn Tranb2000802018-08-02 13:16:52 -0700556 if (rval == QLA_ABORTED) {
557 ql_log(ql_log_info, vha, 0xd035,
558 "Chip Reset in progress. Purging Mbox cmd=0x%x.\n",
559 mcp->mb[0]);
560 } else if (rval) {
Joe Carnuccio050dc762017-08-23 15:05:14 -0700561 if (ql2xextended_error_logging & (ql_dbg_disc|ql_dbg_mbx)) {
Bart Van Assche3f918ff2019-04-17 14:44:20 -0700562 pr_warn("%s [%s]-%04x:%ld: **** Failed=%x", QL_MSGHDR,
Joe Carnuccio050dc762017-08-23 15:05:14 -0700563 dev_name(&ha->pdev->dev), 0x1020+0x800,
Bart Van Assche3f918ff2019-04-17 14:44:20 -0700564 vha->host_no, rval);
Joe Carnuccio050dc762017-08-23 15:05:14 -0700565 mboxes = mcp->in_mb;
566 cnt = 4;
567 for (i = 0; i < ha->mbx_count && cnt; i++, mboxes >>= 1)
568 if (mboxes & BIT_0) {
569 printk(" mb[%u]=%x", i, mcp->mb[i]);
570 cnt--;
571 }
572 pr_warn(" cmd=%x ****\n", command);
573 }
Meelis Roosf7e59e92018-03-08 15:44:07 +0200574 if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha))) {
575 ql_dbg(ql_dbg_mbx, vha, 0x1198,
576 "host_status=%#x intr_ctrl=%#x intr_status=%#x\n",
577 RD_REG_DWORD(&reg->isp24.host_status),
578 RD_REG_DWORD(&reg->isp24.ictrl),
579 RD_REG_DWORD(&reg->isp24.istatus));
580 } else {
581 ql_dbg(ql_dbg_mbx, vha, 0x1206,
582 "ctrl_status=%#x ictrl=%#x istatus=%#x\n",
583 RD_REG_WORD(&reg->isp.ctrl_status),
584 RD_REG_WORD(&reg->isp.ictrl),
585 RD_REG_WORD(&reg->isp.istatus));
586 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700588 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 }
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return rval;
592}
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800595qla2x00_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 -0800596 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
598 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800599 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 mbx_cmd_t mc;
601 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400603 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
604 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Andrew Vasqueze4289242007-07-19 15:05:56 -0700606 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800607 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
608 mcp->mb[8] = MSW(risc_addr);
609 mcp->out_mb = MBX_8|MBX_0;
610 } else {
611 mcp->mb[0] = MBC_LOAD_RISC_RAM;
612 mcp->out_mb = MBX_0;
613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 mcp->mb[1] = LSW(risc_addr);
615 mcp->mb[2] = MSW(req_dma);
616 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 mcp->mb[6] = MSW(MSD(req_dma));
618 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800619 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700620 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700621 mcp->mb[4] = MSW(risc_code_size);
622 mcp->mb[5] = LSW(risc_code_size);
623 mcp->out_mb |= MBX_5|MBX_4;
624 } else {
625 mcp->mb[4] = LSW(risc_code_size);
626 mcp->out_mb |= MBX_4;
627 }
628
Joe Carnuccio2a3192a2019-03-12 11:08:14 -0700629 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700630 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800632 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700635 ql_dbg(ql_dbg_mbx, vha, 0x1023,
Joe Carnuccio2a3192a2019-03-12 11:08:14 -0700636 "Failed=%x mb[0]=%x mb[1]=%x.\n",
637 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400639 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
640 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642
643 return rval;
644}
645
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700646#define EXTENDED_BB_CREDITS BIT_0
Duane Grigsbye84067d2017-06-21 13:48:43 -0700647#define NVME_ENABLE_FLAG BIT_3
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700648static inline uint16_t qla25xx_set_sfp_lr_dist(struct qla_hw_data *ha)
649{
650 uint16_t mb4 = BIT_0;
651
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700652 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700653 mb4 |= ha->long_range_distance << LR_DIST_FW_POS;
654
655 return mb4;
656}
657
658static inline uint16_t qla25xx_set_nvr_lr_dist(struct qla_hw_data *ha)
659{
660 uint16_t mb4 = BIT_0;
661
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700662 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700663 struct nvram_81xx *nv = ha->nvram;
664
665 mb4 |= LR_DIST_FW_FIELD(nv->enhanced_features);
666 }
667
668 return mb4;
669}
Duane Grigsbye84067d2017-06-21 13:48:43 -0700670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671/*
672 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700673 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 *
675 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700676 * ha = adapter block pointer.
677 * TARGET_QUEUE_LOCK must be released.
678 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 *
680 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700681 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 *
683 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700684 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 */
686int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800687qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688{
689 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800690 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 mbx_cmd_t mc;
692 mbx_cmd_t *mcp = &mc;
693
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400694 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
695 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
697 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700698 mcp->out_mb = MBX_0;
699 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700700 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700701 mcp->mb[1] = MSW(risc_addr);
702 mcp->mb[2] = LSW(risc_addr);
703 mcp->mb[3] = 0;
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700704 mcp->mb[4] = 0;
Himanshu Madhanic2ff2a32019-10-22 12:36:42 -0700705 mcp->mb[11] = 0;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700706 ha->flags.using_lr_setting = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500707 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700708 IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700709 if (ql2xautodetectsfp) {
710 if (ha->flags.detected_lr_sfp) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700711 mcp->mb[4] |=
712 qla25xx_set_sfp_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700713 ha->flags.using_lr_setting = 1;
714 }
715 } else {
716 struct nvram_81xx *nv = ha->nvram;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700717 /* set LR distance if specified in nvram */
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700718 if (nv->enhanced_features &
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700719 NEF_LR_DIST_ENABLE) {
720 mcp->mb[4] |=
721 qla25xx_set_nvr_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700722 ha->flags.using_lr_setting = 1;
723 }
724 }
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700725 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500726
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700727 if (ql2xnvmeenable && (IS_QLA27XX(ha) || IS_QLA28XX(ha)))
Duane Grigsbye84067d2017-06-21 13:48:43 -0700728 mcp->mb[4] |= NVME_ENABLE_FLAG;
729
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700730 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -0700731 struct nvram_81xx *nv = ha->nvram;
732 /* set minimum speed if specified in nvram */
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700733 if (nv->min_supported_speed >= 2 &&
734 nv->min_supported_speed <= 5) {
Sawan Chandak92d44082017-08-23 15:05:16 -0700735 mcp->mb[4] |= BIT_4;
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700736 mcp->mb[11] |= nv->min_supported_speed & 0xF;
Sawan Chandak92d44082017-08-23 15:05:16 -0700737 mcp->out_mb |= MBX_11;
738 mcp->in_mb |= BIT_5;
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700739 vha->min_supported_speed =
740 nv->min_supported_speed;
Sawan Chandak92d44082017-08-23 15:05:16 -0700741 }
742 }
743
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500744 if (ha->flags.exlogins_enabled)
745 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
746
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500747 if (ha->flags.exchoffld_enabled)
748 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
749
Himanshu Madhanic2ff2a32019-10-22 12:36:42 -0700750 mcp->out_mb |= MBX_4 | MBX_3 | MBX_2 | MBX_1 | MBX_11;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700751 mcp->in_mb |= MBX_3 | MBX_2 | MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700752 } else {
753 mcp->mb[1] = LSW(risc_addr);
754 mcp->out_mb |= MBX_1;
755 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
756 mcp->mb[2] = 0;
757 mcp->out_mb |= MBX_2;
758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 }
760
Ravi Anandb93480e2008-04-03 13:13:25 -0700761 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800763 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700765 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700766 ql_dbg(ql_dbg_mbx, vha, 0x1026,
767 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700768 return rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700771 if (!IS_FWI2_CAPABLE(ha))
772 goto done;
773
774 ha->fw_ability_mask = mcp->mb[3] << 16 | mcp->mb[2];
775 ql_dbg(ql_dbg_mbx, vha, 0x119a,
776 "fw_ability_mask=%x.\n", ha->fw_ability_mask);
777 ql_dbg(ql_dbg_mbx, vha, 0x1027, "exchanges=%x.\n", mcp->mb[1]);
778 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
779 ha->max_supported_speed = mcp->mb[2] & (BIT_0|BIT_1);
780 ql_dbg(ql_dbg_mbx, vha, 0x119b, "max_supported_speed=%s.\n",
781 ha->max_supported_speed == 0 ? "16Gps" :
782 ha->max_supported_speed == 1 ? "32Gps" :
783 ha->max_supported_speed == 2 ? "64Gps" : "unknown");
784 if (vha->min_supported_speed) {
785 ha->min_supported_speed = mcp->mb[5] &
786 (BIT_0 | BIT_1 | BIT_2);
787 ql_dbg(ql_dbg_mbx, vha, 0x119c,
788 "min_supported_speed=%s.\n",
789 ha->min_supported_speed == 6 ? "64Gps" :
790 ha->min_supported_speed == 5 ? "32Gps" :
791 ha->min_supported_speed == 4 ? "16Gps" :
792 ha->min_supported_speed == 3 ? "8Gps" :
793 ha->min_supported_speed == 2 ? "4Gps" : "unknown");
794 }
795 }
796
797done:
798 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
799 "Done %s.\n", __func__);
800
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 return rval;
802}
803
804/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500805 * qla_get_exlogin_status
806 * Get extended login status
807 * uses the memory offload control/status Mailbox
808 *
809 * Input:
810 * ha: adapter state pointer.
811 * fwopt: firmware options
812 *
813 * Returns:
814 * qla2x00 local function status
815 *
816 * Context:
817 * Kernel context.
818 */
819#define FETCH_XLOGINS_STAT 0x8
820int
821qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
822 uint16_t *ex_logins_cnt)
823{
824 int rval;
825 mbx_cmd_t mc;
826 mbx_cmd_t *mcp = &mc;
827
828 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
829 "Entered %s\n", __func__);
830
831 memset(mcp->mb, 0 , sizeof(mcp->mb));
832 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
833 mcp->mb[1] = FETCH_XLOGINS_STAT;
834 mcp->out_mb = MBX_1|MBX_0;
835 mcp->in_mb = MBX_10|MBX_4|MBX_0;
836 mcp->tov = MBX_TOV_SECONDS;
837 mcp->flags = 0;
838
839 rval = qla2x00_mailbox_command(vha, mcp);
840 if (rval != QLA_SUCCESS) {
841 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
842 } else {
843 *buf_sz = mcp->mb[4];
844 *ex_logins_cnt = mcp->mb[10];
845
846 ql_log(ql_log_info, vha, 0x1190,
847 "buffer size 0x%x, exchange login count=%d\n",
848 mcp->mb[4], mcp->mb[10]);
849
850 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
851 "Done %s.\n", __func__);
852 }
853
854 return rval;
855}
856
857/*
858 * qla_set_exlogin_mem_cfg
859 * set extended login memory configuration
860 * Mbx needs to be issues before init_cb is set
861 *
862 * Input:
863 * ha: adapter state pointer.
864 * buffer: buffer pointer
865 * phys_addr: physical address of buffer
866 * size: size of buffer
867 * TARGET_QUEUE_LOCK must be released
868 * ADAPTER_STATE_LOCK must be release
869 *
870 * Returns:
871 * qla2x00 local funxtion status code.
872 *
873 * Context:
874 * Kernel context.
875 */
876#define CONFIG_XLOGINS_MEM 0x3
877int
878qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
879{
880 int rval;
881 mbx_cmd_t mc;
882 mbx_cmd_t *mcp = &mc;
883 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500884
885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
886 "Entered %s.\n", __func__);
887
888 memset(mcp->mb, 0 , sizeof(mcp->mb));
889 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
890 mcp->mb[1] = CONFIG_XLOGINS_MEM;
891 mcp->mb[2] = MSW(phys_addr);
892 mcp->mb[3] = LSW(phys_addr);
893 mcp->mb[6] = MSW(MSD(phys_addr));
894 mcp->mb[7] = LSW(MSD(phys_addr));
895 mcp->mb[8] = MSW(ha->exlogin_size);
896 mcp->mb[9] = LSW(ha->exlogin_size);
897 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
898 mcp->in_mb = MBX_11|MBX_0;
899 mcp->tov = MBX_TOV_SECONDS;
900 mcp->flags = 0;
901 rval = qla2x00_mailbox_command(vha, mcp);
902 if (rval != QLA_SUCCESS) {
903 /*EMPTY*/
904 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
905 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500906 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
907 "Done %s.\n", __func__);
908 }
909
910 return rval;
911}
912
913/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500914 * qla_get_exchoffld_status
915 * Get exchange offload status
916 * uses the memory offload control/status Mailbox
917 *
918 * Input:
919 * ha: adapter state pointer.
920 * fwopt: firmware options
921 *
922 * Returns:
923 * qla2x00 local function status
924 *
925 * Context:
926 * Kernel context.
927 */
928#define FETCH_XCHOFFLD_STAT 0x2
929int
930qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
931 uint16_t *ex_logins_cnt)
932{
933 int rval;
934 mbx_cmd_t mc;
935 mbx_cmd_t *mcp = &mc;
936
937 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
938 "Entered %s\n", __func__);
939
940 memset(mcp->mb, 0 , sizeof(mcp->mb));
941 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
942 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
943 mcp->out_mb = MBX_1|MBX_0;
944 mcp->in_mb = MBX_10|MBX_4|MBX_0;
945 mcp->tov = MBX_TOV_SECONDS;
946 mcp->flags = 0;
947
948 rval = qla2x00_mailbox_command(vha, mcp);
949 if (rval != QLA_SUCCESS) {
950 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
951 } else {
952 *buf_sz = mcp->mb[4];
953 *ex_logins_cnt = mcp->mb[10];
954
955 ql_log(ql_log_info, vha, 0x118e,
956 "buffer size 0x%x, exchange offload count=%d\n",
957 mcp->mb[4], mcp->mb[10]);
958
959 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
960 "Done %s.\n", __func__);
961 }
962
963 return rval;
964}
965
966/*
967 * qla_set_exchoffld_mem_cfg
968 * Set exchange offload memory configuration
969 * Mbx needs to be issues before init_cb is set
970 *
971 * Input:
972 * ha: adapter state pointer.
973 * buffer: buffer pointer
974 * phys_addr: physical address of buffer
975 * size: size of buffer
976 * TARGET_QUEUE_LOCK must be released
977 * ADAPTER_STATE_LOCK must be release
978 *
979 * Returns:
980 * qla2x00 local funxtion status code.
981 *
982 * Context:
983 * Kernel context.
984 */
985#define CONFIG_XCHOFFLD_MEM 0x3
986int
Quinn Tran99e1b682017-06-02 09:12:03 -0700987qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500988{
989 int rval;
990 mbx_cmd_t mc;
991 mbx_cmd_t *mcp = &mc;
992 struct qla_hw_data *ha = vha->hw;
993
994 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
995 "Entered %s.\n", __func__);
996
997 memset(mcp->mb, 0 , sizeof(mcp->mb));
998 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
999 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -07001000 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
1001 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
1002 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
1003 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
1004 mcp->mb[8] = MSW(ha->exchoffld_size);
1005 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001006 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1007 mcp->in_mb = MBX_11|MBX_0;
1008 mcp->tov = MBX_TOV_SECONDS;
1009 mcp->flags = 0;
1010 rval = qla2x00_mailbox_command(vha, mcp);
1011 if (rval != QLA_SUCCESS) {
1012 /*EMPTY*/
1013 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
1014 } else {
1015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
1016 "Done %s.\n", __func__);
1017 }
1018
1019 return rval;
1020}
1021
1022/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 * qla2x00_get_fw_version
1024 * Get firmware version.
1025 *
1026 * Input:
1027 * ha: adapter state pointer.
1028 * major: pointer for major number.
1029 * minor: pointer for minor number.
1030 * subminor: pointer for subminor number.
1031 *
1032 * Returns:
1033 * qla2x00 local function return status code.
1034 *
1035 * Context:
1036 * Kernel context.
1037 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001038int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001039qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
1041 int rval;
1042 mbx_cmd_t mc;
1043 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001044 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001046 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
1047 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
1050 mcp->out_mb = MBX_0;
1051 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001052 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001053 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -04001054 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001055 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001056 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001057 mcp->in_mb |=
1058 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07001059 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001062 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001063 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001064 if (rval != QLA_SUCCESS)
1065 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
1067 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001068 ha->fw_major_version = mcp->mb[1];
1069 ha->fw_minor_version = mcp->mb[2];
1070 ha->fw_subminor_version = mcp->mb[3];
1071 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001073 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001075 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -04001076
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001077 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001078 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1079 ha->mpi_version[1] = mcp->mb[11] >> 8;
1080 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1081 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
1082 ha->phy_version[0] = mcp->mb[8] & 0xff;
1083 ha->phy_version[1] = mcp->mb[9] >> 8;
1084 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001085 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001086
Saurav Kashyap81178772012-08-22 14:21:04 -04001087 if (IS_FWI2_CAPABLE(ha)) {
1088 ha->fw_attributes_h = mcp->mb[15];
1089 ha->fw_attributes_ext[0] = mcp->mb[16];
1090 ha->fw_attributes_ext[1] = mcp->mb[17];
1091 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
1092 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
1093 __func__, mcp->mb[15], mcp->mb[6]);
1094 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
1095 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
1096 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001097
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001098 if (ha->fw_attributes_h & 0x4)
1099 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
1100 "%s: Firmware supports Extended Login 0x%x\n",
1101 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001102
1103 if (ha->fw_attributes_h & 0x8)
1104 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
1105 "%s: Firmware supports Exchange Offload 0x%x\n",
1106 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -07001107
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07001108 /*
1109 * FW supports nvme and driver load parameter requested nvme.
1110 * BIT 26 of fw_attributes indicates NVMe support.
1111 */
Giridhar Malavali171e4902019-01-30 09:50:44 -08001112 if ((ha->fw_attributes_h &
1113 (FW_ATTR_H_NVME | FW_ATTR_H_NVME_UPDATED)) &&
1114 ql2xnvmeenable) {
Darren Trapp03aaa892019-02-15 14:37:13 -08001115 if (ha->fw_attributes_h & FW_ATTR_H_NVME_FBURST)
1116 vha->flags.nvme_first_burst = 1;
1117
Duane Grigsbye84067d2017-06-21 13:48:43 -07001118 vha->flags.nvme_enabled = 1;
Darren Trapp1cbc0ef2018-03-20 23:09:37 -07001119 ql_log(ql_log_info, vha, 0xd302,
1120 "%s: FC-NVMe is Enabled (0x%x)\n",
1121 __func__, ha->fw_attributes_h);
1122 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001123 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001124
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001125 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07001126 ha->serdes_version[0] = mcp->mb[7] & 0xff;
1127 ha->serdes_version[1] = mcp->mb[8] >> 8;
1128 ha->serdes_version[2] = mcp->mb[8] & 0xff;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001129 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1130 ha->mpi_version[1] = mcp->mb[11] >> 8;
1131 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1132 ha->pep_version[0] = mcp->mb[13] & 0xff;
1133 ha->pep_version[1] = mcp->mb[14] >> 8;
1134 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001135 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
1136 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001137 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
1138 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Michael Hernandez3f006ac2019-03-12 11:08:22 -07001139 if (IS_QLA28XX(ha)) {
1140 if (mcp->mb[16] & BIT_10) {
1141 ql_log(ql_log_info, vha, 0xffff,
1142 "FW support secure flash updates\n");
1143 ha->flags.secure_fw = 1;
1144 }
1145 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001146 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001147
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001148failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 if (rval != QLA_SUCCESS) {
1150 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001151 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 } else {
1153 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001154 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
1155 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001157 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158}
1159
1160/*
1161 * qla2x00_get_fw_options
1162 * Set firmware options.
1163 *
1164 * Input:
1165 * ha = adapter block pointer.
1166 * fwopt = pointer for firmware options.
1167 *
1168 * Returns:
1169 * qla2x00 local function return status code.
1170 *
1171 * Context:
1172 * Kernel context.
1173 */
1174int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001175qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176{
1177 int rval;
1178 mbx_cmd_t mc;
1179 mbx_cmd_t *mcp = &mc;
1180
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001181 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1182 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1185 mcp->out_mb = MBX_0;
1186 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001187 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001189 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
1191 if (rval != QLA_SUCCESS) {
1192 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001193 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001195 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 fwopts[1] = mcp->mb[1];
1197 fwopts[2] = mcp->mb[2];
1198 fwopts[3] = mcp->mb[3];
1199
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001200 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1201 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
1203
1204 return rval;
1205}
1206
1207
1208/*
1209 * qla2x00_set_fw_options
1210 * Set firmware options.
1211 *
1212 * Input:
1213 * ha = adapter block pointer.
1214 * fwopt = pointer for firmware options.
1215 *
1216 * Returns:
1217 * qla2x00 local function return status code.
1218 *
1219 * Context:
1220 * Kernel context.
1221 */
1222int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001223qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224{
1225 int rval;
1226 mbx_cmd_t mc;
1227 mbx_cmd_t *mcp = &mc;
1228
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001229 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1230 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1233 mcp->mb[1] = fwopts[1];
1234 mcp->mb[2] = fwopts[2];
1235 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001236 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001238 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001239 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001240 mcp->mb[10] = fwopts[10];
1241 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001242 } else {
1243 mcp->mb[10] = fwopts[10];
1244 mcp->mb[11] = fwopts[11];
1245 mcp->mb[12] = 0; /* Undocumented, but used */
1246 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1247 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001248 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001250 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001252 fwopts[0] = mcp->mb[0];
1253
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 if (rval != QLA_SUCCESS) {
1255 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001256 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1257 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 } else {
1259 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001260 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1261 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 }
1263
1264 return rval;
1265}
1266
1267/*
1268 * qla2x00_mbx_reg_test
1269 * Mailbox register wrap test.
1270 *
1271 * Input:
1272 * ha = adapter block pointer.
1273 * TARGET_QUEUE_LOCK must be released.
1274 * ADAPTER_STATE_LOCK must be released.
1275 *
1276 * Returns:
1277 * qla2x00 local function return status code.
1278 *
1279 * Context:
1280 * Kernel context.
1281 */
1282int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001283qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284{
1285 int rval;
1286 mbx_cmd_t mc;
1287 mbx_cmd_t *mcp = &mc;
1288
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001289 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1290 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291
1292 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1293 mcp->mb[1] = 0xAAAA;
1294 mcp->mb[2] = 0x5555;
1295 mcp->mb[3] = 0xAA55;
1296 mcp->mb[4] = 0x55AA;
1297 mcp->mb[5] = 0xA5A5;
1298 mcp->mb[6] = 0x5A5A;
1299 mcp->mb[7] = 0x2525;
1300 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1301 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 -07001302 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001304 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
1306 if (rval == QLA_SUCCESS) {
1307 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1308 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1309 rval = QLA_FUNCTION_FAILED;
1310 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1311 mcp->mb[7] != 0x2525)
1312 rval = QLA_FUNCTION_FAILED;
1313 }
1314
1315 if (rval != QLA_SUCCESS) {
1316 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001317 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 } else {
1319 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001320 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1321 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
1323
1324 return rval;
1325}
1326
1327/*
1328 * qla2x00_verify_checksum
1329 * Verify firmware checksum.
1330 *
1331 * Input:
1332 * ha = adapter block pointer.
1333 * TARGET_QUEUE_LOCK must be released.
1334 * ADAPTER_STATE_LOCK must be released.
1335 *
1336 * Returns:
1337 * qla2x00 local function return status code.
1338 *
1339 * Context:
1340 * Kernel context.
1341 */
1342int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001343qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344{
1345 int rval;
1346 mbx_cmd_t mc;
1347 mbx_cmd_t *mcp = &mc;
1348
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001349 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1350 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351
1352 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001353 mcp->out_mb = MBX_0;
1354 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001355 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001356 mcp->mb[1] = MSW(risc_addr);
1357 mcp->mb[2] = LSW(risc_addr);
1358 mcp->out_mb |= MBX_2|MBX_1;
1359 mcp->in_mb |= MBX_2|MBX_1;
1360 } else {
1361 mcp->mb[1] = LSW(risc_addr);
1362 mcp->out_mb |= MBX_1;
1363 mcp->in_mb |= MBX_1;
1364 }
1365
Ravi Anandb93480e2008-04-03 13:13:25 -07001366 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001368 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001371 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1372 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1373 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001375 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1376 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 }
1378
1379 return rval;
1380}
1381
1382/*
1383 * qla2x00_issue_iocb
1384 * Issue IOCB using mailbox command
1385 *
1386 * Input:
1387 * ha = adapter state pointer.
1388 * buffer = buffer pointer.
1389 * phys_addr = physical address of buffer.
1390 * size = size of buffer.
1391 * TARGET_QUEUE_LOCK must be released.
1392 * ADAPTER_STATE_LOCK must be released.
1393 *
1394 * Returns:
1395 * qla2x00 local function return status code.
1396 *
1397 * Context:
1398 * Kernel context.
1399 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001400int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001401qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001402 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403{
1404 int rval;
1405 mbx_cmd_t mc;
1406 mbx_cmd_t *mcp = &mc;
1407
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1409 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001410
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1412 mcp->mb[1] = 0;
1413 mcp->mb[2] = MSW(phys_addr);
1414 mcp->mb[3] = LSW(phys_addr);
1415 mcp->mb[6] = MSW(MSD(phys_addr));
1416 mcp->mb[7] = LSW(MSD(phys_addr));
1417 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1418 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001419 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001421 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
1423 if (rval != QLA_SUCCESS) {
1424 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001425 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001427 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1428
1429 /* Mask reserved bits. */
1430 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001431 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001432 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1433 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 }
1435
1436 return rval;
1437}
1438
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001439int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001440qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001441 size_t size)
1442{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001443 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001444 MBX_TOV_SECONDS);
1445}
1446
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447/*
1448 * qla2x00_abort_command
1449 * Abort command aborts a specified IOCB.
1450 *
1451 * Input:
1452 * ha = adapter block pointer.
1453 * sp = SB structure pointer.
1454 *
1455 * Returns:
1456 * qla2x00 local function return status code.
1457 *
1458 * Context:
1459 * Kernel context.
1460 */
1461int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001462qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463{
1464 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001466 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 mbx_cmd_t mc;
1468 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001469 fc_port_t *fcport = sp->fcport;
1470 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001471 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001472 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001473 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001475 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1476 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
Michael Hernandezd7459522016-12-12 14:40:07 -08001478 if (vha->flags.qpairs_available && sp->qpair)
1479 req = sp->qpair->req;
1480 else
1481 req = vha->req;
1482
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001483 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001484 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001485 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 break;
1487 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001488 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
Chad Dupuis8d93f552013-01-30 03:34:37 -05001490 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 /* command not found */
1492 return QLA_FUNCTION_FAILED;
1493 }
1494
1495 mcp->mb[0] = MBC_ABORT_COMMAND;
1496 if (HAS_EXTENDED_IDS(ha))
1497 mcp->mb[1] = fcport->loop_id;
1498 else
1499 mcp->mb[1] = fcport->loop_id << 8;
1500 mcp->mb[2] = (uint16_t)handle;
1501 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001502 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1504 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001505 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001507 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001510 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001512 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1513 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 }
1515
1516 return rval;
1517}
1518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001520qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001522 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 mbx_cmd_t mc;
1524 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001525 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001527 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001528
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001529 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1530 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001531
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001533 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001534 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 mcp->mb[1] = fcport->loop_id;
1536 mcp->mb[10] = 0;
1537 mcp->out_mb |= MBX_10;
1538 } else {
1539 mcp->mb[1] = fcport->loop_id << 8;
1540 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001541 mcp->mb[2] = vha->hw->loop_reset_delay;
1542 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543
1544 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001545 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001547 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001549 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1550 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001551 }
1552
1553 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08001554 rval2 = qla2x00_marker(vha, vha->hw->base_qpair, fcport->loop_id, 0,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001555 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001556 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1558 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1561 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001562 }
1563
1564 return rval;
1565}
1566
1567int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001568qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001569{
1570 int rval, rval2;
1571 mbx_cmd_t mc;
1572 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001573 scsi_qla_host_t *vha;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001574
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001575 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001576
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001577 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1578 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001579
Andrew Vasquez523ec772008-04-03 13:13:24 -07001580 mcp->mb[0] = MBC_LUN_RESET;
1581 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001582 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001583 mcp->mb[1] = fcport->loop_id;
1584 else
1585 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001586 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001587 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001588 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001589
1590 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001591 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001592 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001593 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001594 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001595 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001596 }
1597
1598 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08001599 rval2 = qla2x00_marker(vha, vha->hw->base_qpair, fcport->loop_id, l,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001600 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001601 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001602 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1603 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001604 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001605 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1606 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 }
1608
1609 return rval;
1610}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 * qla2x00_get_adapter_id
1614 * Get adapter ID and topology.
1615 *
1616 * Input:
1617 * ha = adapter block pointer.
1618 * id = pointer for loop ID.
1619 * al_pa = pointer for AL_PA.
1620 * area = pointer for area.
1621 * domain = pointer for domain.
1622 * top = pointer for topology.
1623 * TARGET_QUEUE_LOCK must be released.
1624 * ADAPTER_STATE_LOCK must be released.
1625 *
1626 * Returns:
1627 * qla2x00 local function return status code.
1628 *
1629 * Context:
1630 * Kernel context.
1631 */
1632int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001633qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001634 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635{
1636 int rval;
1637 mbx_cmd_t mc;
1638 mbx_cmd_t *mcp = &mc;
1639
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001640 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1641 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642
1643 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001644 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001645 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001646 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001647 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001648 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001649 if (IS_FWI2_CAPABLE(vha->hw))
1650 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001651 if (IS_QLA27XX(vha->hw) || IS_QLA28XX(vha->hw))
Sawan Chandak969a6192016-01-27 12:03:32 -05001652 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001653 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001655 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001656 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1657 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001658 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1659 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660
1661 /* Return data. */
1662 *id = mcp->mb[1];
1663 *al_pa = LSB(mcp->mb[2]);
1664 *area = MSB(mcp->mb[2]);
1665 *domain = LSB(mcp->mb[3]);
1666 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001667 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668
1669 if (rval != QLA_SUCCESS) {
1670 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001671 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001673 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1674 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001675
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001676 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001677 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1678 vha->fcoe_fcf_idx = mcp->mb[10];
1679 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1680 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1681 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1682 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1683 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1684 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1685 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001686 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001687 if (IS_FAWWN_CAPABLE(vha->hw)) {
1688 if (mcp->mb[7] & BIT_14) {
1689 vha->port_name[0] = MSB(mcp->mb[16]);
1690 vha->port_name[1] = LSB(mcp->mb[16]);
1691 vha->port_name[2] = MSB(mcp->mb[17]);
1692 vha->port_name[3] = LSB(mcp->mb[17]);
1693 vha->port_name[4] = MSB(mcp->mb[18]);
1694 vha->port_name[5] = LSB(mcp->mb[18]);
1695 vha->port_name[6] = MSB(mcp->mb[19]);
1696 vha->port_name[7] = LSB(mcp->mb[19]);
1697 fc_host_port_name(vha->host) =
1698 wwn_to_u64(vha->port_name);
1699 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1700 "FA-WWN acquired %016llx\n",
1701 wwn_to_u64(vha->port_name));
1702 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001703 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001704
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001705 if (IS_QLA27XX(vha->hw) || IS_QLA28XX(vha->hw))
Sawan Chandak969a6192016-01-27 12:03:32 -05001706 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 }
1708
1709 return rval;
1710}
1711
1712/*
1713 * qla2x00_get_retry_cnt
1714 * Get current firmware login retry count and delay.
1715 *
1716 * Input:
1717 * ha = adapter block pointer.
1718 * retry_cnt = pointer to login retry count.
1719 * tov = pointer to login timeout value.
1720 *
1721 * Returns:
1722 * qla2x00 local function return status code.
1723 *
1724 * Context:
1725 * Kernel context.
1726 */
1727int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001728qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 uint16_t *r_a_tov)
1730{
1731 int rval;
1732 uint16_t ratov;
1733 mbx_cmd_t mc;
1734 mbx_cmd_t *mcp = &mc;
1735
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001736 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1737 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738
1739 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1740 mcp->out_mb = MBX_0;
1741 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001742 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001744 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 if (rval != QLA_SUCCESS) {
1747 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001748 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1749 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 } else {
1751 /* Convert returned data and check our values. */
1752 *r_a_tov = mcp->mb[3] / 2;
1753 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1754 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1755 /* Update to the larger values */
1756 *retry_cnt = (uint8_t)mcp->mb[1];
1757 *tov = ratov;
1758 }
1759
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001760 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001761 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763
1764 return rval;
1765}
1766
1767/*
1768 * qla2x00_init_firmware
1769 * Initialize adapter firmware.
1770 *
1771 * Input:
1772 * ha = adapter block pointer.
1773 * dptr = Initialization control block pointer.
1774 * size = size of initialization control block.
1775 * TARGET_QUEUE_LOCK must be released.
1776 * ADAPTER_STATE_LOCK must be released.
1777 *
1778 * Returns:
1779 * qla2x00 local function return status code.
1780 *
1781 * Context:
1782 * Kernel context.
1783 */
1784int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001785qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786{
1787 int rval;
1788 mbx_cmd_t mc;
1789 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001790 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001792 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1793 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001795 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001796 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001797 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1798
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001799 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001800 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1801 else
1802 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1803
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001804 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 mcp->mb[2] = MSW(ha->init_cb_dma);
1806 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1808 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001809 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001810 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001811 mcp->mb[1] = BIT_0;
1812 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1813 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1814 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1815 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1816 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1817 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1818 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001819 /* 1 and 2 should normally be captured. */
1820 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001821 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001822 /* mb3 is additional info about the installed SFP. */
1823 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 mcp->buf_size = size;
1825 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001826 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001827 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 if (rval != QLA_SUCCESS) {
1830 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001831 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07001832 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x.\n",
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001833 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Joe Carnucciof8f97b02019-03-12 11:08:16 -07001834 if (ha->init_cb) {
1835 ql_dbg(ql_dbg_mbx, vha, 0x104d, "init_cb:\n");
1836 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha,
1837 0x0104d, ha->init_cb, sizeof(*ha->init_cb));
1838 }
1839 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
1840 ql_dbg(ql_dbg_mbx, vha, 0x104d, "ex_init_cb:\n");
1841 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha,
1842 0x0104d, ha->ex_init_cb, sizeof(*ha->ex_init_cb));
1843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 } else {
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001845 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -07001846 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1847 ql_dbg(ql_dbg_mbx, vha, 0x119d,
1848 "Invalid SFP/Validation Failed\n");
1849 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001850 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1851 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 }
1853
1854 return rval;
1855}
1856
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001857
1858/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 * qla2x00_get_port_database
1860 * Issue normal/enhanced get port database mailbox command
1861 * and copy device name as necessary.
1862 *
1863 * Input:
1864 * ha = adapter state pointer.
1865 * dev = structure pointer.
1866 * opt = enhanced cmd option byte.
1867 *
1868 * Returns:
1869 * qla2x00 local function return status code.
1870 *
1871 * Context:
1872 * Kernel context.
1873 */
1874int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001875qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
1877 int rval;
1878 mbx_cmd_t mc;
1879 mbx_cmd_t *mcp = &mc;
1880 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001881 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001883 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1886 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001888 pd24 = NULL;
Thomas Meyer08eb7f42017-09-21 08:15:26 +02001889 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001891 ql_log(ql_log_warn, vha, 0x1050,
1892 "Failed to allocate port database structure.\n");
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001893 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 return QLA_MEMORY_ALLOC_FAILED;
1895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001897 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001898 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 mcp->mb[2] = MSW(pd_dma);
1901 mcp->mb[3] = LSW(pd_dma);
1902 mcp->mb[6] = MSW(MSD(pd_dma));
1903 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001904 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001905 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001907 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001908 mcp->mb[1] = fcport->loop_id;
1909 mcp->mb[10] = opt;
1910 mcp->out_mb |= MBX_10|MBX_1;
1911 mcp->in_mb |= MBX_1;
1912 } else if (HAS_EXTENDED_IDS(ha)) {
1913 mcp->mb[1] = fcport->loop_id;
1914 mcp->mb[10] = opt;
1915 mcp->out_mb |= MBX_10|MBX_1;
1916 } else {
1917 mcp->mb[1] = fcport->loop_id << 8 | opt;
1918 mcp->out_mb |= MBX_1;
1919 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001920 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1921 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 mcp->flags = MBX_DMA_IN;
1923 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001924 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 if (rval != QLA_SUCCESS)
1926 goto gpd_error_out;
1927
Andrew Vasqueze4289242007-07-19 15:05:56 -07001928 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001929 uint64_t zero = 0;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001930 u8 current_login_state, last_login_state;
1931
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001932 pd24 = (struct port_database_24xx *) pd;
1933
1934 /* Check for logged in state. */
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001935 if (fcport->fc4f_nvme) {
1936 current_login_state = pd24->current_login_state >> 4;
1937 last_login_state = pd24->last_login_state >> 4;
1938 } else {
1939 current_login_state = pd24->current_login_state & 0xf;
1940 last_login_state = pd24->last_login_state & 0xf;
1941 }
1942 fcport->current_login_state = pd24->current_login_state;
1943 fcport->last_login_state = pd24->last_login_state;
1944
1945 /* Check for logged in state. */
1946 if (current_login_state != PDS_PRLI_COMPLETE &&
1947 last_login_state != PDS_PRLI_COMPLETE) {
1948 ql_dbg(ql_dbg_mbx, vha, 0x119a,
1949 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
1950 current_login_state, last_login_state,
1951 fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001952 rval = QLA_FUNCTION_FAILED;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001953
1954 if (!fcport->query)
1955 goto gpd_error_out;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001956 }
1957
Arun Easi0eba25d2012-02-09 11:15:58 -08001958 if (fcport->loop_id == FC_NO_LOOP_ID ||
1959 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1960 memcmp(fcport->port_name, pd24->port_name, 8))) {
1961 /* We lost the device mid way. */
1962 rval = QLA_NOT_LOGGED_IN;
1963 goto gpd_error_out;
1964 }
1965
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001966 /* Names are little-endian. */
1967 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1968 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1969
1970 /* Get port_id of device. */
1971 fcport->d_id.b.domain = pd24->port_id[0];
1972 fcport->d_id.b.area = pd24->port_id[1];
1973 fcport->d_id.b.al_pa = pd24->port_id[2];
1974 fcport->d_id.b.rsvd_1 = 0;
1975
1976 /* If not target must be initiator or unknown type. */
1977 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1978 fcport->port_type = FCT_INITIATOR;
1979 else
1980 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001981
1982 /* Passback COS information. */
1983 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1984 FC_COS_CLASS2 : FC_COS_CLASS3;
1985
1986 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1987 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001988 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001989 uint64_t zero = 0;
1990
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001991 /* Check for logged in state. */
1992 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1993 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001994 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1995 "Unable to verify login-state (%x/%x) - "
1996 "portid=%02x%02x%02x.\n", pd->master_state,
1997 pd->slave_state, fcport->d_id.b.domain,
1998 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001999 rval = QLA_FUNCTION_FAILED;
2000 goto gpd_error_out;
2001 }
2002
Arun Easi0eba25d2012-02-09 11:15:58 -08002003 if (fcport->loop_id == FC_NO_LOOP_ID ||
2004 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
2005 memcmp(fcport->port_name, pd->port_name, 8))) {
2006 /* We lost the device mid way. */
2007 rval = QLA_NOT_LOGGED_IN;
2008 goto gpd_error_out;
2009 }
2010
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002011 /* Names are little-endian. */
2012 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
2013 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
2014
2015 /* Get port_id of device. */
2016 fcport->d_id.b.domain = pd->port_id[0];
2017 fcport->d_id.b.area = pd->port_id[3];
2018 fcport->d_id.b.al_pa = pd->port_id[2];
2019 fcport->d_id.b.rsvd_1 = 0;
2020
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002021 /* If not target must be initiator or unknown type. */
2022 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
2023 fcport->port_type = FCT_INITIATOR;
2024 else
2025 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002026
2027 /* Passback COS information. */
2028 fcport->supported_classes = (pd->options & BIT_4) ?
Bart Van Assche58e27532019-04-11 14:53:19 -07002029 FC_COS_CLASS2 : FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032gpd_error_out:
2033 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07002034 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
2036 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002037 ql_dbg(ql_dbg_mbx, vha, 0x1052,
2038 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
2039 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002041 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
2042 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 }
2044
2045 return rval;
2046}
2047
2048/*
2049 * qla2x00_get_firmware_state
2050 * Get adapter firmware state.
2051 *
2052 * Input:
2053 * ha = adapter block pointer.
2054 * dptr = pointer for firmware state.
2055 * TARGET_QUEUE_LOCK must be released.
2056 * ADAPTER_STATE_LOCK must be released.
2057 *
2058 * Returns:
2059 * qla2x00 local function return status code.
2060 *
2061 * Context:
2062 * Kernel context.
2063 */
2064int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002065qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066{
2067 int rval;
2068 mbx_cmd_t mc;
2069 mbx_cmd_t *mcp = &mc;
Sawan Chandak92d44082017-08-23 15:05:16 -07002070 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002072 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
2073 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
2075 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
2076 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002077 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002078 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002079 else
2080 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002081 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002083 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002085 /* Return firmware states. */
2086 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002087 if (IS_FWI2_CAPABLE(vha->hw)) {
2088 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04002089 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002090 states[3] = mcp->mb[4];
2091 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002092 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002093 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 if (rval != QLA_SUCCESS) {
2096 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002097 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 } else {
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002099 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -07002100 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
2101 ql_dbg(ql_dbg_mbx, vha, 0x119e,
2102 "Invalid SFP/Validation Failed\n");
2103 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002104 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
2105 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
2107
2108 return rval;
2109}
2110
2111/*
2112 * qla2x00_get_port_name
2113 * Issue get port name mailbox command.
2114 * Returned name is in big endian format.
2115 *
2116 * Input:
2117 * ha = adapter block pointer.
2118 * loop_id = loop ID of device.
2119 * name = pointer for name.
2120 * TARGET_QUEUE_LOCK must be released.
2121 * ADAPTER_STATE_LOCK must be released.
2122 *
2123 * Returns:
2124 * qla2x00 local function return status code.
2125 *
2126 * Context:
2127 * Kernel context.
2128 */
2129int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002130qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 uint8_t opt)
2132{
2133 int rval;
2134 mbx_cmd_t mc;
2135 mbx_cmd_t *mcp = &mc;
2136
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002137 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
2138 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002141 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002142 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002143 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 mcp->mb[1] = loop_id;
2145 mcp->mb[10] = opt;
2146 mcp->out_mb |= MBX_10;
2147 } else {
2148 mcp->mb[1] = loop_id << 8 | opt;
2149 }
2150
2151 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002152 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002154 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
2156 if (rval != QLA_SUCCESS) {
2157 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002158 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 } else {
2160 if (name != NULL) {
2161 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002162 name[0] = MSB(mcp->mb[2]);
2163 name[1] = LSB(mcp->mb[2]);
2164 name[2] = MSB(mcp->mb[3]);
2165 name[3] = LSB(mcp->mb[3]);
2166 name[4] = MSB(mcp->mb[6]);
2167 name[5] = LSB(mcp->mb[6]);
2168 name[6] = MSB(mcp->mb[7]);
2169 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 }
2171
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002172 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2173 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 }
2175
2176 return rval;
2177}
2178
2179/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002180 * qla24xx_link_initialization
2181 * Issue link initialization mailbox command.
2182 *
2183 * Input:
2184 * ha = adapter block pointer.
2185 * TARGET_QUEUE_LOCK must be released.
2186 * ADAPTER_STATE_LOCK must be released.
2187 *
2188 * Returns:
2189 * qla2x00 local function return status code.
2190 *
2191 * Context:
2192 * Kernel context.
2193 */
2194int
2195qla24xx_link_initialize(scsi_qla_host_t *vha)
2196{
2197 int rval;
2198 mbx_cmd_t mc;
2199 mbx_cmd_t *mcp = &mc;
2200
2201 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2202 "Entered %s.\n", __func__);
2203
2204 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2205 return QLA_FUNCTION_FAILED;
2206
2207 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002208 mcp->mb[1] = BIT_4;
2209 if (vha->hw->operating_mode == LOOP)
2210 mcp->mb[1] |= BIT_6;
2211 else
2212 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002213 mcp->mb[2] = 0;
2214 mcp->mb[3] = 0;
2215 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2216 mcp->in_mb = MBX_0;
2217 mcp->tov = MBX_TOV_SECONDS;
2218 mcp->flags = 0;
2219 rval = qla2x00_mailbox_command(vha, mcp);
2220
2221 if (rval != QLA_SUCCESS) {
2222 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2223 } else {
2224 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2225 "Done %s.\n", __func__);
2226 }
2227
2228 return rval;
2229}
2230
2231/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 * qla2x00_lip_reset
2233 * Issue LIP reset mailbox command.
2234 *
2235 * Input:
2236 * ha = adapter block pointer.
2237 * TARGET_QUEUE_LOCK must be released.
2238 * ADAPTER_STATE_LOCK must be released.
2239 *
2240 * Returns:
2241 * qla2x00 local function return status code.
2242 *
2243 * Context:
2244 * Kernel context.
2245 */
2246int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002247qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248{
2249 int rval;
2250 mbx_cmd_t mc;
2251 mbx_cmd_t *mcp = &mc;
2252
Quinn Tran7f2a3982019-09-12 11:09:09 -07002253 ql_dbg(ql_dbg_disc, vha, 0x105a,
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002254 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002256 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002257 /* Logout across all FCFs. */
2258 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2259 mcp->mb[1] = BIT_1;
2260 mcp->mb[2] = 0;
2261 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2262 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002263 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002264 mcp->mb[1] = BIT_4;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002265 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002266 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002267 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002269 mcp->mb[0] = MBC_LIP_RESET;
2270 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002271 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002272 mcp->mb[1] = 0x00ff;
2273 mcp->mb[10] = 0;
2274 mcp->out_mb |= MBX_10;
2275 } else {
2276 mcp->mb[1] = 0xff00;
2277 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002278 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002279 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002282 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002284 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286 if (rval != QLA_SUCCESS) {
2287 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002288 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 } else {
2290 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002291 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2292 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 }
2294
2295 return rval;
2296}
2297
2298/*
2299 * qla2x00_send_sns
2300 * Send SNS command.
2301 *
2302 * Input:
2303 * ha = adapter block pointer.
2304 * sns = pointer for command.
2305 * cmd_size = command size.
2306 * buf_size = response/command size.
2307 * TARGET_QUEUE_LOCK must be released.
2308 * ADAPTER_STATE_LOCK must be released.
2309 *
2310 * Returns:
2311 * qla2x00 local function return status code.
2312 *
2313 * Context:
2314 * Kernel context.
2315 */
2316int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002317qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 uint16_t cmd_size, size_t buf_size)
2319{
2320 int rval;
2321 mbx_cmd_t mc;
2322 mbx_cmd_t *mcp = &mc;
2323
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002324 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2325 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002327 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002328 "Retry cnt=%d ratov=%d total tov=%d.\n",
2329 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2332 mcp->mb[1] = cmd_size;
2333 mcp->mb[2] = MSW(sns_phys_address);
2334 mcp->mb[3] = LSW(sns_phys_address);
2335 mcp->mb[6] = MSW(MSD(sns_phys_address));
2336 mcp->mb[7] = LSW(MSD(sns_phys_address));
2337 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2338 mcp->in_mb = MBX_0|MBX_1;
2339 mcp->buf_size = buf_size;
2340 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002341 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2342 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
2344 if (rval != QLA_SUCCESS) {
2345 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002346 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2347 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2348 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 } else {
2350 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2352 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 }
2354
2355 return rval;
2356}
2357
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002358int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002359qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002360 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2361{
2362 int rval;
2363
2364 struct logio_entry_24xx *lg;
2365 dma_addr_t lg_dma;
2366 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002367 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002368 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002369
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002370 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2371 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002372
Michael Hernandezd7459522016-12-12 14:40:07 -08002373 if (vha->vp_idx && vha->qpair)
2374 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002375 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002376 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002377
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002378 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002379 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002380 ql_log(ql_log_warn, vha, 0x1062,
2381 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002382 return QLA_MEMORY_ALLOC_FAILED;
2383 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002384
2385 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2386 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002387 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002388 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002389 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002390 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002391 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002392 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002393 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002394 lg->port_id[0] = al_pa;
2395 lg->port_id[1] = area;
2396 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002397 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002398 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2399 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002400 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002401 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2402 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002403 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002404 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2405 "Failed to complete IOCB -- error status (%x).\n",
2406 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002407 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002408 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002409 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2410 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2411
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002412 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2413 "Failed to complete IOCB -- completion status (%x) "
2414 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2415 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002416
2417 switch (iop[0]) {
2418 case LSC_SCODE_PORTID_USED:
2419 mb[0] = MBS_PORT_ID_USED;
2420 mb[1] = LSW(iop[1]);
2421 break;
2422 case LSC_SCODE_NPORT_USED:
2423 mb[0] = MBS_LOOP_ID_USED;
2424 break;
2425 case LSC_SCODE_NOLINK:
2426 case LSC_SCODE_NOIOCB:
2427 case LSC_SCODE_NOXCB:
2428 case LSC_SCODE_CMD_FAILED:
2429 case LSC_SCODE_NOFABRIC:
2430 case LSC_SCODE_FW_NOT_READY:
2431 case LSC_SCODE_NOT_LOGGED_IN:
2432 case LSC_SCODE_NOPCB:
2433 case LSC_SCODE_ELS_REJECT:
2434 case LSC_SCODE_CMD_PARAM_ERR:
2435 case LSC_SCODE_NONPORT:
2436 case LSC_SCODE_LOGGED_IN:
2437 case LSC_SCODE_NOFLOGI_ACC:
2438 default:
2439 mb[0] = MBS_COMMAND_ERROR;
2440 break;
2441 }
2442 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002443 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2444 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002445
2446 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2447
2448 mb[0] = MBS_COMMAND_COMPLETE;
2449 mb[1] = 0;
2450 if (iop[0] & BIT_4) {
2451 if (iop[0] & BIT_8)
2452 mb[1] |= BIT_1;
2453 } else
2454 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002455
2456 /* Passback COS information. */
2457 mb[10] = 0;
2458 if (lg->io_parameter[7] || lg->io_parameter[8])
2459 mb[10] |= BIT_0; /* Class 2. */
2460 if (lg->io_parameter[9] || lg->io_parameter[10])
2461 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002462 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002463 mb[10] |= BIT_7; /* Confirmed Completion
2464 * Allowed
2465 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002466 }
2467
2468 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2469
2470 return rval;
2471}
2472
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473/*
2474 * qla2x00_login_fabric
2475 * Issue login fabric port mailbox command.
2476 *
2477 * Input:
2478 * ha = adapter block pointer.
2479 * loop_id = device loop ID.
2480 * domain = device domain.
2481 * area = device area.
2482 * al_pa = device AL_PA.
2483 * status = pointer for return status.
2484 * opt = command options.
2485 * TARGET_QUEUE_LOCK must be released.
2486 * ADAPTER_STATE_LOCK must be released.
2487 *
2488 * Returns:
2489 * qla2x00 local function return status code.
2490 *
2491 * Context:
2492 * Kernel context.
2493 */
2494int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002495qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2497{
2498 int rval;
2499 mbx_cmd_t mc;
2500 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002501 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2504 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
2506 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2507 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2508 if (HAS_EXTENDED_IDS(ha)) {
2509 mcp->mb[1] = loop_id;
2510 mcp->mb[10] = opt;
2511 mcp->out_mb |= MBX_10;
2512 } else {
2513 mcp->mb[1] = (loop_id << 8) | opt;
2514 }
2515 mcp->mb[2] = domain;
2516 mcp->mb[3] = area << 8 | al_pa;
2517
2518 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2519 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2520 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002521 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522
2523 /* Return mailbox statuses. */
2524 if (mb != NULL) {
2525 mb[0] = mcp->mb[0];
2526 mb[1] = mcp->mb[1];
2527 mb[2] = mcp->mb[2];
2528 mb[6] = mcp->mb[6];
2529 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002530 /* COS retrieved from Get-Port-Database mailbox command. */
2531 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 }
2533
2534 if (rval != QLA_SUCCESS) {
2535 /* RLU tmp code: need to change main mailbox_command function to
2536 * return ok even when the mailbox completion value is not
2537 * SUCCESS. The caller needs to be responsible to interpret
2538 * the return values of this mailbox command if we're not
2539 * to change too much of the existing code.
2540 */
2541 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2542 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2543 mcp->mb[0] == 0x4006)
2544 rval = QLA_SUCCESS;
2545
2546 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002547 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2548 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2549 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 } else {
2551 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002552 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2553 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 }
2555
2556 return rval;
2557}
2558
2559/*
2560 * qla2x00_login_local_device
2561 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002562 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 * Input:
2564 * ha = adapter block pointer.
2565 * loop_id = device loop ID.
2566 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002567 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 * Returns:
2569 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002570 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 * Context:
2572 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002573 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 */
2575int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002576qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 uint16_t *mb_ret, uint8_t opt)
2578{
2579 int rval;
2580 mbx_cmd_t mc;
2581 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002582 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002584 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2585 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002586
Andrew Vasqueze4289242007-07-19 15:05:56 -07002587 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002588 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002589 fcport->d_id.b.domain, fcport->d_id.b.area,
2590 fcport->d_id.b.al_pa, mb_ret, opt);
2591
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2593 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002594 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002596 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 mcp->mb[2] = opt;
2598 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2599 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2600 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2601 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002602 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
2604 /* Return mailbox statuses. */
2605 if (mb_ret != NULL) {
2606 mb_ret[0] = mcp->mb[0];
2607 mb_ret[1] = mcp->mb[1];
2608 mb_ret[6] = mcp->mb[6];
2609 mb_ret[7] = mcp->mb[7];
2610 }
2611
2612 if (rval != QLA_SUCCESS) {
2613 /* AV tmp code: need to change main mailbox_command function to
2614 * return ok even when the mailbox completion value is not
2615 * SUCCESS. The caller needs to be responsible to interpret
2616 * the return values of this mailbox command if we're not
2617 * to change too much of the existing code.
2618 */
2619 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2620 rval = QLA_SUCCESS;
2621
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002622 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2623 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2624 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 } else {
2626 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2628 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 }
2630
2631 return (rval);
2632}
2633
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002634int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002635qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002636 uint8_t area, uint8_t al_pa)
2637{
2638 int rval;
2639 struct logio_entry_24xx *lg;
2640 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002641 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002642 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002643
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002644 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2645 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002646
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002647 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002648 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002649 ql_log(ql_log_warn, vha, 0x106e,
2650 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002651 return QLA_MEMORY_ALLOC_FAILED;
2652 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002653
Michael Hernandezd7459522016-12-12 14:40:07 -08002654 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002655 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2656 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002657 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002658 lg->nport_handle = cpu_to_le16(loop_id);
2659 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002660 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002661 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002662 lg->port_id[0] = al_pa;
2663 lg->port_id[1] = area;
2664 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002665 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002666 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2667 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002668 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002669 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2670 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002671 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002672 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2673 "Failed to complete IOCB -- error status (%x).\n",
2674 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002675 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002676 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002677 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2678 "Failed to complete IOCB -- completion status (%x) "
2679 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002680 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002681 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002682 } else {
2683 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002684 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2685 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002686 }
2687
2688 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2689
2690 return rval;
2691}
2692
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693/*
2694 * qla2x00_fabric_logout
2695 * Issue logout fabric port mailbox command.
2696 *
2697 * Input:
2698 * ha = adapter block pointer.
2699 * loop_id = device loop ID.
2700 * TARGET_QUEUE_LOCK must be released.
2701 * ADAPTER_STATE_LOCK must be released.
2702 *
2703 * Returns:
2704 * qla2x00 local function return status code.
2705 *
2706 * Context:
2707 * Kernel context.
2708 */
2709int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002710qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002711 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712{
2713 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, 0x1073,
2718 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719
2720 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2721 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002722 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 mcp->mb[1] = loop_id;
2724 mcp->mb[10] = 0;
2725 mcp->out_mb |= MBX_10;
2726 } else {
2727 mcp->mb[1] = loop_id << 8;
2728 }
2729
2730 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002731 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002733 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
2735 if (rval != QLA_SUCCESS) {
2736 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002737 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2738 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 } else {
2740 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002741 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2742 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 }
2744
2745 return rval;
2746}
2747
2748/*
2749 * qla2x00_full_login_lip
2750 * Issue full login LIP mailbox command.
2751 *
2752 * Input:
2753 * ha = adapter block pointer.
2754 * TARGET_QUEUE_LOCK must be released.
2755 * ADAPTER_STATE_LOCK must be released.
2756 *
2757 * Returns:
2758 * qla2x00 local function return status code.
2759 *
2760 * Context:
2761 * Kernel context.
2762 */
2763int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002764qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765{
2766 int rval;
2767 mbx_cmd_t mc;
2768 mbx_cmd_t *mcp = &mc;
2769
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002770 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2771 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772
2773 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002774 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_4 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002775 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 mcp->mb[3] = 0;
2777 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2778 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002779 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002781 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782
2783 if (rval != QLA_SUCCESS) {
2784 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002785 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 } else {
2787 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002788 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2789 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 }
2791
2792 return rval;
2793}
2794
2795/*
2796 * qla2x00_get_id_list
2797 *
2798 * Input:
2799 * ha = adapter block pointer.
2800 *
2801 * Returns:
2802 * qla2x00 local function return status code.
2803 *
2804 * Context:
2805 * Kernel context.
2806 */
2807int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002808qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 uint16_t *entries)
2810{
2811 int rval;
2812 mbx_cmd_t mc;
2813 mbx_cmd_t *mcp = &mc;
2814
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002815 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2816 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
2818 if (id_list == NULL)
2819 return QLA_FUNCTION_FAILED;
2820
2821 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002822 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002823 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002824 mcp->mb[2] = MSW(id_list_dma);
2825 mcp->mb[3] = LSW(id_list_dma);
2826 mcp->mb[6] = MSW(MSD(id_list_dma));
2827 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002828 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002829 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002830 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002831 } else {
2832 mcp->mb[1] = MSW(id_list_dma);
2833 mcp->mb[2] = LSW(id_list_dma);
2834 mcp->mb[3] = MSW(MSD(id_list_dma));
2835 mcp->mb[6] = LSW(MSD(id_list_dma));
2836 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002839 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002841 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842
2843 if (rval != QLA_SUCCESS) {
2844 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002845 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 } else {
2847 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002848 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2849 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 }
2851
2852 return rval;
2853}
2854
2855/*
2856 * qla2x00_get_resource_cnts
2857 * Get current firmware resource counts.
2858 *
2859 * Input:
2860 * ha = adapter block pointer.
2861 *
2862 * Returns:
2863 * qla2x00 local function return status code.
2864 *
2865 * Context:
2866 * Kernel context.
2867 */
2868int
Quinn Tran03e8c682015-12-17 14:56:59 -05002869qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870{
Quinn Tran03e8c682015-12-17 14:56:59 -05002871 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 int rval;
2873 mbx_cmd_t mc;
2874 mbx_cmd_t *mcp = &mc;
2875
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002876 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2877 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878
2879 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2880 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002881 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002882 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
2883 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002884 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002885 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002887 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888
2889 if (rval != QLA_SUCCESS) {
2890 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002891 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2892 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002894 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002895 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2896 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2897 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2898 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
Quinn Tran03e8c682015-12-17 14:56:59 -05002900 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2901 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2902 ha->cur_fw_xcb_count = mcp->mb[3];
2903 ha->orig_fw_xcb_count = mcp->mb[6];
2904 ha->cur_fw_iocb_count = mcp->mb[7];
2905 ha->orig_fw_iocb_count = mcp->mb[10];
2906 if (ha->flags.npiv_supported)
2907 ha->max_npiv_vports = mcp->mb[11];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002908 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
2909 IS_QLA28XX(ha))
Quinn Tran03e8c682015-12-17 14:56:59 -05002910 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 }
2912
2913 return (rval);
2914}
2915
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916/*
2917 * qla2x00_get_fcal_position_map
2918 * Get FCAL (LILP) position map using mailbox command
2919 *
2920 * Input:
2921 * ha = adapter state pointer.
2922 * pos_map = buffer pointer (can be NULL).
2923 *
2924 * Returns:
2925 * qla2x00 local function return status code.
2926 *
2927 * Context:
2928 * Kernel context.
2929 */
2930int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002931qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932{
2933 int rval;
2934 mbx_cmd_t mc;
2935 mbx_cmd_t *mcp = &mc;
2936 char *pmap;
2937 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002938 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002940 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2941 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002942
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002943 pmap = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002945 ql_log(ql_log_warn, vha, 0x1080,
2946 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 return QLA_MEMORY_ALLOC_FAILED;
2948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949
2950 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2951 mcp->mb[2] = MSW(pmap_dma);
2952 mcp->mb[3] = LSW(pmap_dma);
2953 mcp->mb[6] = MSW(MSD(pmap_dma));
2954 mcp->mb[7] = LSW(MSD(pmap_dma));
2955 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2956 mcp->in_mb = MBX_1|MBX_0;
2957 mcp->buf_size = FCAL_MAP_SIZE;
2958 mcp->flags = MBX_DMA_IN;
2959 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002960 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961
2962 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002963 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002964 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2965 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2966 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2967 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
2969 if (pos_map)
2970 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2971 }
2972 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2973
2974 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002975 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002977 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2978 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 }
2980
2981 return rval;
2982}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002983
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002984/*
2985 * qla2x00_get_link_status
2986 *
2987 * Input:
2988 * ha = adapter block pointer.
2989 * loop_id = device loop ID.
2990 * ret_buf = pointer to link status return buffer.
2991 *
2992 * Returns:
2993 * 0 = success.
2994 * BIT_0 = mem alloc error.
2995 * BIT_1 = mailbox error.
2996 */
2997int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002998qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002999 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003000{
3001 int rval;
3002 mbx_cmd_t mc;
3003 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003004 uint32_t *iter = (void *)stats;
3005 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003006 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003007
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003008 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
3009 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003010
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003011 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003012 mcp->mb[2] = MSW(LSD(stats_dma));
3013 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003014 mcp->mb[6] = MSW(MSD(stats_dma));
3015 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003016 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3017 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07003018 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003019 mcp->mb[1] = loop_id;
3020 mcp->mb[4] = 0;
3021 mcp->mb[10] = 0;
3022 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
3023 mcp->in_mb |= MBX_1;
3024 } else if (HAS_EXTENDED_IDS(ha)) {
3025 mcp->mb[1] = loop_id;
3026 mcp->mb[10] = 0;
3027 mcp->out_mb |= MBX_10|MBX_1;
3028 } else {
3029 mcp->mb[1] = loop_id << 8;
3030 mcp->out_mb |= MBX_1;
3031 }
Ravi Anandb93480e2008-04-03 13:13:25 -07003032 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003033 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003034 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003035
3036 if (rval == QLA_SUCCESS) {
3037 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003038 ql_dbg(ql_dbg_mbx, vha, 0x1085,
3039 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003040 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003041 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003042 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003043 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
3044 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003045 for ( ; dwords--; iter++)
3046 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003047 }
3048 } else {
3049 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003050 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003051 }
3052
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003053 return rval;
3054}
3055
3056int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003057qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07003058 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003059{
3060 int rval;
3061 mbx_cmd_t mc;
3062 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003063 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003064
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003065 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
3066 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003067
Quinn Tran15f30a52017-03-15 09:48:52 -07003068 memset(&mc, 0, sizeof(mc));
3069 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
3070 mc.mb[2] = MSW(stats_dma);
3071 mc.mb[3] = LSW(stats_dma);
3072 mc.mb[6] = MSW(MSD(stats_dma));
3073 mc.mb[7] = LSW(MSD(stats_dma));
3074 mc.mb[8] = sizeof(struct link_statistics) / 4;
3075 mc.mb[9] = cpu_to_le16(vha->vp_idx);
3076 mc.mb[10] = cpu_to_le16(options);
3077
3078 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003079
3080 if (rval == QLA_SUCCESS) {
3081 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003082 ql_dbg(ql_dbg_mbx, vha, 0x1089,
3083 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003084 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003085 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003086 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
3087 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003088 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003089 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003090 iter = &stats->link_fail_cnt;
3091 for ( ; dwords--; iter++)
3092 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003093 }
3094 } else {
3095 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003096 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003097 }
3098
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003099 return rval;
3100}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003101
3102int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003103qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003104{
3105 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003106 unsigned long flags = 0;
3107
3108 struct abort_entry_24xx *abt;
3109 dma_addr_t abt_dma;
3110 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003111 fc_port_t *fcport = sp->fcport;
3112 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003113 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003114 struct req_que *req = vha->req;
Quinn Tran585def92018-09-04 14:19:20 -07003115 struct qla_qpair *qpair = sp->qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003116
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003117 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
3118 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003119
Michael Hernandezd7459522016-12-12 14:40:07 -08003120 if (vha->flags.qpairs_available && sp->qpair)
3121 req = sp->qpair->req;
Quinn Tran585def92018-09-04 14:19:20 -07003122 else
3123 return QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08003124
Armen Baloyan4440e462014-02-26 04:15:18 -05003125 if (ql2xasynctmfenable)
3126 return qla24xx_async_abort_command(sp);
3127
Quinn Tran585def92018-09-04 14:19:20 -07003128 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003129 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003130 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003131 break;
3132 }
Quinn Tran585def92018-09-04 14:19:20 -07003133 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003134 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003135 /* Command not found. */
3136 return QLA_FUNCTION_FAILED;
3137 }
3138
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003139 abt = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003140 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003141 ql_log(ql_log_warn, vha, 0x108d,
3142 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003143 return QLA_MEMORY_ALLOC_FAILED;
3144 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003145
3146 abt->entry_type = ABORT_IOCB_TYPE;
3147 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003148 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003149 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07003150 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003151 abt->port_id[0] = fcport->d_id.b.al_pa;
3152 abt->port_id[1] = fcport->d_id.b.area;
3153 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003154 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003155
3156 abt->req_que_no = cpu_to_le16(req->id);
3157
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003158 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003159 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003160 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3161 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003162 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003163 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3164 "Failed to complete IOCB -- error status (%x).\n",
3165 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003166 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003167 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003168 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3169 "Failed to complete IOCB -- completion status (%x).\n",
3170 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003171 if (abt->nport_handle == CS_IOCB_ERROR)
3172 rval = QLA_FUNCTION_PARAMETER_ERROR;
3173 else
3174 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003175 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003176 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3177 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003178 }
3179
3180 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3181
3182 return rval;
3183}
3184
3185struct tsk_mgmt_cmd {
3186 union {
3187 struct tsk_mgmt_entry tsk;
3188 struct sts_entry_24xx sts;
3189 } p;
3190};
3191
Andrew Vasquez523ec772008-04-03 13:13:24 -07003192static int
3193__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003194 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003195{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003196 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003197 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003198 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003199 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003200 scsi_qla_host_t *vha;
3201 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003202 struct req_que *req;
Michael Hernandezd7459522016-12-12 14:40:07 -08003203 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003204
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003205 vha = fcport->vha;
3206 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003207 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003208
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003209 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3210 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003211
Michael Hernandezd7459522016-12-12 14:40:07 -08003212 if (vha->vp_idx && vha->qpair) {
3213 /* NPIV port */
3214 qpair = vha->qpair;
Michael Hernandezd7459522016-12-12 14:40:07 -08003215 req = qpair->req;
Michael Hernandezd7459522016-12-12 14:40:07 -08003216 }
3217
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003218 tsk = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003219 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003220 ql_log(ql_log_warn, vha, 0x1093,
3221 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003222 return QLA_MEMORY_ALLOC_FAILED;
3223 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003224
3225 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3226 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003227 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003228 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003229 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003230 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003231 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3232 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3233 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003234 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003235 if (type == TCF_LUN_RESET) {
3236 int_to_scsilun(l, &tsk->p.tsk.lun);
3237 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3238 sizeof(tsk->p.tsk.lun));
3239 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003240
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003241 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003242 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003243 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003244 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3245 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003246 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003247 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3248 "Failed to complete IOCB -- error status (%x).\n",
3249 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003250 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003251 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003252 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3253 "Failed to complete IOCB -- completion status (%x).\n",
3254 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003255 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003256 } else if (le16_to_cpu(sts->scsi_status) &
3257 SS_RESPONSE_INFO_LEN_VALID) {
3258 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003259 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003260 "Ignoring inconsistent data length -- not enough "
3261 "response info (%d).\n",
3262 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003263 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003264 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3265 "Failed to complete IOCB -- response (%x).\n",
3266 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003267 rval = QLA_FUNCTION_FAILED;
3268 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003269 }
3270
3271 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08003272 rval2 = qla2x00_marker(vha, ha->base_qpair, fcport->loop_id, l,
Bart Van Assche58e27532019-04-11 14:53:19 -07003273 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003274 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003275 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3276 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003277 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003278 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3279 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003280 }
3281
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003282 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003283
3284 return rval;
3285}
3286
Andrew Vasquez523ec772008-04-03 13:13:24 -07003287int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003288qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003289{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003290 struct qla_hw_data *ha = fcport->vha->hw;
3291
3292 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3293 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3294
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003295 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003296}
3297
3298int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003299qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003300{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003301 struct qla_hw_data *ha = fcport->vha->hw;
3302
3303 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3304 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3305
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003306 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003307}
3308
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003309int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003310qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003311{
3312 int rval;
3313 mbx_cmd_t mc;
3314 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003315 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003316
Andrew Vasquez68af0812008-05-12 22:21:13 -07003317 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003318 return QLA_FUNCTION_FAILED;
3319
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003320 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3321 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003322
3323 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3324 mcp->out_mb = MBX_0;
3325 mcp->in_mb = MBX_0;
3326 mcp->tov = 5;
3327 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003328 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003329
3330 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003331 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003332 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003333 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3334 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003335 }
3336
3337 return rval;
3338}
3339
Joe Carnucciodb64e932013-10-30 03:38:18 -04003340int
3341qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3342{
3343 int rval;
3344 mbx_cmd_t mc;
3345 mbx_cmd_t *mcp = &mc;
3346
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003347 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003348 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003349 return QLA_FUNCTION_FAILED;
3350
3351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3352 "Entered %s.\n", __func__);
3353
3354 mcp->mb[0] = MBC_WRITE_SERDES;
3355 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003356 if (IS_QLA2031(vha->hw))
3357 mcp->mb[2] = data & 0xff;
3358 else
3359 mcp->mb[2] = data;
3360
Joe Carnucciodb64e932013-10-30 03:38:18 -04003361 mcp->mb[3] = 0;
3362 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3363 mcp->in_mb = MBX_0;
3364 mcp->tov = MBX_TOV_SECONDS;
3365 mcp->flags = 0;
3366 rval = qla2x00_mailbox_command(vha, mcp);
3367
3368 if (rval != QLA_SUCCESS) {
3369 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3370 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3371 } else {
3372 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3373 "Done %s.\n", __func__);
3374 }
3375
3376 return rval;
3377}
3378
3379int
3380qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3381{
3382 int rval;
3383 mbx_cmd_t mc;
3384 mbx_cmd_t *mcp = &mc;
3385
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003386 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003387 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003388 return QLA_FUNCTION_FAILED;
3389
3390 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3391 "Entered %s.\n", __func__);
3392
3393 mcp->mb[0] = MBC_READ_SERDES;
3394 mcp->mb[1] = addr;
3395 mcp->mb[3] = 0;
3396 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3397 mcp->in_mb = MBX_1|MBX_0;
3398 mcp->tov = MBX_TOV_SECONDS;
3399 mcp->flags = 0;
3400 rval = qla2x00_mailbox_command(vha, mcp);
3401
Andrew Vasquez064135e2015-04-09 15:00:02 -04003402 if (IS_QLA2031(vha->hw))
3403 *data = mcp->mb[1] & 0xff;
3404 else
3405 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003406
3407 if (rval != QLA_SUCCESS) {
3408 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3409 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3410 } else {
3411 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3412 "Done %s.\n", __func__);
3413 }
3414
3415 return rval;
3416}
3417
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003418int
3419qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3420{
3421 int rval;
3422 mbx_cmd_t mc;
3423 mbx_cmd_t *mcp = &mc;
3424
3425 if (!IS_QLA8044(vha->hw))
3426 return QLA_FUNCTION_FAILED;
3427
Quinn Tran83548fe2017-06-02 09:12:01 -07003428 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003429 "Entered %s.\n", __func__);
3430
3431 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3432 mcp->mb[1] = HCS_WRITE_SERDES;
3433 mcp->mb[3] = LSW(addr);
3434 mcp->mb[4] = MSW(addr);
3435 mcp->mb[5] = LSW(data);
3436 mcp->mb[6] = MSW(data);
3437 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3438 mcp->in_mb = MBX_0;
3439 mcp->tov = MBX_TOV_SECONDS;
3440 mcp->flags = 0;
3441 rval = qla2x00_mailbox_command(vha, mcp);
3442
3443 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003444 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003445 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3446 } else {
3447 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3448 "Done %s.\n", __func__);
3449 }
3450
3451 return rval;
3452}
3453
3454int
3455qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3456{
3457 int rval;
3458 mbx_cmd_t mc;
3459 mbx_cmd_t *mcp = &mc;
3460
3461 if (!IS_QLA8044(vha->hw))
3462 return QLA_FUNCTION_FAILED;
3463
3464 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3465 "Entered %s.\n", __func__);
3466
3467 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3468 mcp->mb[1] = HCS_READ_SERDES;
3469 mcp->mb[3] = LSW(addr);
3470 mcp->mb[4] = MSW(addr);
3471 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3472 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3473 mcp->tov = MBX_TOV_SECONDS;
3474 mcp->flags = 0;
3475 rval = qla2x00_mailbox_command(vha, mcp);
3476
3477 *data = mcp->mb[2] << 16 | mcp->mb[1];
3478
3479 if (rval != QLA_SUCCESS) {
3480 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3481 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3482 } else {
3483 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3484 "Done %s.\n", __func__);
3485 }
3486
3487 return rval;
3488}
3489
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003490/**
3491 * qla2x00_set_serdes_params() -
Bart Van Assche2db62282018-01-23 16:33:51 -08003492 * @vha: HA context
Bart Van Assche807eb902018-10-18 15:45:41 -07003493 * @sw_em_1g: serial link options
3494 * @sw_em_2g: serial link options
3495 * @sw_em_4g: serial link options
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003496 *
3497 * Returns
3498 */
3499int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003500qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003501 uint16_t sw_em_2g, uint16_t sw_em_4g)
3502{
3503 int rval;
3504 mbx_cmd_t mc;
3505 mbx_cmd_t *mcp = &mc;
3506
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003507 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3508 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003509
3510 mcp->mb[0] = MBC_SERDES_PARAMS;
3511 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003512 mcp->mb[2] = sw_em_1g | BIT_15;
3513 mcp->mb[3] = sw_em_2g | BIT_15;
3514 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003515 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3516 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003517 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003518 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003519 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003520
3521 if (rval != QLA_SUCCESS) {
3522 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003523 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3524 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003525 } else {
3526 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003527 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3528 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003529 }
3530
3531 return rval;
3532}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003533
3534int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003535qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003536{
3537 int rval;
3538 mbx_cmd_t mc;
3539 mbx_cmd_t *mcp = &mc;
3540
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003541 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003542 return QLA_FUNCTION_FAILED;
3543
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003544 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3545 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003546
3547 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003548 mcp->mb[1] = 0;
3549 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003550 mcp->in_mb = MBX_0;
3551 mcp->tov = 5;
3552 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003553 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003554
3555 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003556 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003557 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3558 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003559 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3561 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003562 }
3563
3564 return rval;
3565}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003566
3567int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003568qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003569 uint16_t buffers)
3570{
3571 int rval;
3572 mbx_cmd_t mc;
3573 mbx_cmd_t *mcp = &mc;
3574
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003575 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3576 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003577
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003578 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003579 return QLA_FUNCTION_FAILED;
3580
Andrew Vasquez85880802009-12-15 21:29:46 -08003581 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3582 return QLA_FUNCTION_FAILED;
3583
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003584 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003585 mcp->mb[1] = TC_EFT_ENABLE;
3586 mcp->mb[2] = LSW(eft_dma);
3587 mcp->mb[3] = MSW(eft_dma);
3588 mcp->mb[4] = LSW(MSD(eft_dma));
3589 mcp->mb[5] = MSW(MSD(eft_dma));
3590 mcp->mb[6] = buffers;
3591 mcp->mb[7] = TC_AEN_DISABLE;
3592 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 -07003593 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003594 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003595 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003596 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003597 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003598 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3599 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3600 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003601 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003602 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3603 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003604 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003605
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003606 return rval;
3607}
3608
3609int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003610qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003611{
3612 int rval;
3613 mbx_cmd_t mc;
3614 mbx_cmd_t *mcp = &mc;
3615
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003616 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3617 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003618
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003619 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003620 return QLA_FUNCTION_FAILED;
3621
Andrew Vasquez85880802009-12-15 21:29:46 -08003622 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3623 return QLA_FUNCTION_FAILED;
3624
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003625 mcp->mb[0] = MBC_TRACE_CONTROL;
3626 mcp->mb[1] = TC_EFT_DISABLE;
3627 mcp->out_mb = MBX_1|MBX_0;
3628 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003629 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003630 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003631 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003632 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003633 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3634 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3635 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003636 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003637 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3638 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003639 }
3640
3641 return rval;
3642}
3643
Andrew Vasquez88729e52006-06-23 16:10:50 -07003644int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003645qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003646 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3647{
3648 int rval;
3649 mbx_cmd_t mc;
3650 mbx_cmd_t *mcp = &mc;
3651
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003652 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3653 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003654
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003655 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003656 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
3657 !IS_QLA28XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003658 return QLA_FUNCTION_FAILED;
3659
Andrew Vasquez85880802009-12-15 21:29:46 -08003660 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3661 return QLA_FUNCTION_FAILED;
3662
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003663 mcp->mb[0] = MBC_TRACE_CONTROL;
3664 mcp->mb[1] = TC_FCE_ENABLE;
3665 mcp->mb[2] = LSW(fce_dma);
3666 mcp->mb[3] = MSW(fce_dma);
3667 mcp->mb[4] = LSW(MSD(fce_dma));
3668 mcp->mb[5] = MSW(MSD(fce_dma));
3669 mcp->mb[6] = buffers;
3670 mcp->mb[7] = TC_AEN_DISABLE;
3671 mcp->mb[8] = 0;
3672 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3673 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3674 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3675 MBX_1|MBX_0;
3676 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003677 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003678 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003679 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003680 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003681 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3682 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3683 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003684 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003685 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3686 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003687
3688 if (mb)
3689 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3690 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003691 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003692 }
3693
3694 return rval;
3695}
3696
3697int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003698qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003699{
3700 int rval;
3701 mbx_cmd_t mc;
3702 mbx_cmd_t *mcp = &mc;
3703
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003704 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3705 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003706
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003707 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003708 return QLA_FUNCTION_FAILED;
3709
Andrew Vasquez85880802009-12-15 21:29:46 -08003710 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3711 return QLA_FUNCTION_FAILED;
3712
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003713 mcp->mb[0] = MBC_TRACE_CONTROL;
3714 mcp->mb[1] = TC_FCE_DISABLE;
3715 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3716 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3717 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3718 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003719 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003720 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003721 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003722 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003723 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3724 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3725 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003726 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003727 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3728 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003729
3730 if (wr)
3731 *wr = (uint64_t) mcp->mb[5] << 48 |
3732 (uint64_t) mcp->mb[4] << 32 |
3733 (uint64_t) mcp->mb[3] << 16 |
3734 (uint64_t) mcp->mb[2];
3735 if (rd)
3736 *rd = (uint64_t) mcp->mb[9] << 48 |
3737 (uint64_t) mcp->mb[8] << 32 |
3738 (uint64_t) mcp->mb[7] << 16 |
3739 (uint64_t) mcp->mb[6];
3740 }
3741
3742 return rval;
3743}
3744
3745int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003746qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3747 uint16_t *port_speed, uint16_t *mb)
3748{
3749 int rval;
3750 mbx_cmd_t mc;
3751 mbx_cmd_t *mcp = &mc;
3752
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003753 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3754 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003755
Giridhar Malavali6e980162010-03-19 17:03:58 -07003756 if (!IS_IIDMA_CAPABLE(vha->hw))
3757 return QLA_FUNCTION_FAILED;
3758
Giridhar Malavali6e980162010-03-19 17:03:58 -07003759 mcp->mb[0] = MBC_PORT_PARAMS;
3760 mcp->mb[1] = loop_id;
3761 mcp->mb[2] = mcp->mb[3] = 0;
3762 mcp->mb[9] = vha->vp_idx;
3763 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3764 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3765 mcp->tov = MBX_TOV_SECONDS;
3766 mcp->flags = 0;
3767 rval = qla2x00_mailbox_command(vha, mcp);
3768
3769 /* Return mailbox statuses. */
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003770 if (mb) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07003771 mb[0] = mcp->mb[0];
3772 mb[1] = mcp->mb[1];
3773 mb[3] = mcp->mb[3];
3774 }
3775
3776 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003777 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003778 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3780 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003781 if (port_speed)
3782 *port_speed = mcp->mb[3];
3783 }
3784
3785 return rval;
3786}
3787
3788int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003789qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003790 uint16_t port_speed, uint16_t *mb)
3791{
3792 int rval;
3793 mbx_cmd_t mc;
3794 mbx_cmd_t *mcp = &mc;
3795
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003796 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3797 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003798
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003799 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003800 return QLA_FUNCTION_FAILED;
3801
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003802 mcp->mb[0] = MBC_PORT_PARAMS;
3803 mcp->mb[1] = loop_id;
3804 mcp->mb[2] = BIT_0;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003805 mcp->mb[3] = port_speed & 0x3F;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003806 mcp->mb[9] = vha->vp_idx;
3807 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3808 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003809 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003810 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003811 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003812
3813 /* Return mailbox statuses. */
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003814 if (mb) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003815 mb[0] = mcp->mb[0];
3816 mb[1] = mcp->mb[1];
3817 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003818 }
3819
3820 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003821 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3822 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003823 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003824 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3825 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003826 }
3827
3828 return rval;
3829}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003830
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003831void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003832qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003833 struct vp_rpt_id_entry_24xx *rptid_entry)
3834{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003835 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003836 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003837 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003838 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003839 port_id_t id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08003840 struct fc_port *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003841
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003842 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3843 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003844
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003845 if (rptid_entry->entry_status != 0)
3846 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003847
Quinn Tran482c9dc2017-03-15 09:48:54 -07003848 id.b.domain = rptid_entry->port_id[2];
3849 id.b.area = rptid_entry->port_id[1];
3850 id.b.al_pa = rptid_entry->port_id[0];
3851 id.b.rsvd_1 = 0;
Darren Trapp1763c1f2018-03-20 23:09:34 -07003852 ha->flags.n2n_ae = 0;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003853
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003854 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003855 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003856 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003857 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003858 "VPs acquired %d.\n", rptid_entry->vp_setup,
3859 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003860 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003861 "Primary port id %02x%02x%02x.\n",
3862 rptid_entry->port_id[2], rptid_entry->port_id[1],
3863 rptid_entry->port_id[0]);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003864 ha->current_topology = ISP_CFG_NL;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003865 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003866
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003867 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003868 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003869 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003870 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003871 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3872 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003873 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003874 rptid_entry->port_id[0]);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003875 ql_dbg(ql_dbg_async, vha, 0x5075,
3876 "Format 1: Remote WWPN %8phC.\n",
3877 rptid_entry->u.f1.port_name);
3878
3879 ql_dbg(ql_dbg_async, vha, 0x5075,
3880 "Format 1: WWPN %8phC.\n",
3881 vha->port_name);
3882
Quinn Tran8777e432018-08-02 13:16:57 -07003883 switch (rptid_entry->u.f1.flags & TOPO_MASK) {
3884 case TOPO_N2N:
3885 ha->current_topology = ISP_CFG_N;
3886 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Tran7f2a3982019-09-12 11:09:09 -07003887 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3888 fcport->scan_state = QLA_FCPORT_SCAN;
3889 fcport->n2n_flag = 0;
3890 }
3891
Quinn Tran8777e432018-08-02 13:16:57 -07003892 fcport = qla2x00_find_fcport_by_wwpn(vha,
3893 rptid_entry->u.f1.port_name, 1);
3894 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3895
3896 if (fcport) {
3897 fcport->plogi_nack_done_deadline = jiffies + HZ;
Quinn Tran7f2a3982019-09-12 11:09:09 -07003898 fcport->dm_login_expire = jiffies + 2*HZ;
Quinn Tran8777e432018-08-02 13:16:57 -07003899 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran7f2a3982019-09-12 11:09:09 -07003900 fcport->n2n_flag = 1;
Quinn Tranf3f19382019-09-12 11:09:10 -07003901 fcport->keep_nport_handle = 1;
Quinn Tran7f2a3982019-09-12 11:09:09 -07003902 if (vha->flags.nvme_enabled)
3903 fcport->fc4f_nvme = 1;
3904
Quinn Tran8777e432018-08-02 13:16:57 -07003905 switch (fcport->disc_state) {
3906 case DSC_DELETED:
3907 set_bit(RELOGIN_NEEDED,
3908 &vha->dpc_flags);
3909 break;
3910 case DSC_DELETE_PEND:
3911 break;
3912 default:
3913 qlt_schedule_sess_for_deletion(fcport);
3914 break;
3915 }
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003916 } else {
Quinn Tran8777e432018-08-02 13:16:57 -07003917 id.b24 = 0;
3918 if (wwn_to_u64(vha->port_name) >
3919 wwn_to_u64(rptid_entry->u.f1.port_name)) {
3920 vha->d_id.b24 = 0;
3921 vha->d_id.b.al_pa = 1;
3922 ha->flags.n2n_bigger = 1;
3923
3924 id.b.al_pa = 2;
3925 ql_dbg(ql_dbg_async, vha, 0x5075,
3926 "Format 1: assign local id %x remote id %x\n",
3927 vha->d_id.b24, id.b24);
3928 } else {
3929 ql_dbg(ql_dbg_async, vha, 0x5075,
3930 "Format 1: Remote login - Waiting for WWPN %8phC.\n",
3931 rptid_entry->u.f1.port_name);
3932 ha->flags.n2n_bigger = 0;
3933 }
3934 qla24xx_post_newsess_work(vha, &id,
3935 rptid_entry->u.f1.port_name,
3936 rptid_entry->u.f1.node_name,
3937 NULL,
Quinn Tran7f2a3982019-09-12 11:09:09 -07003938 FS_FCP_IS_N2N);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003939 }
3940
Quinn Tran8777e432018-08-02 13:16:57 -07003941 /* if our portname is higher then initiate N2N login */
3942
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003943 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
Darren Trapp1763c1f2018-03-20 23:09:34 -07003944 ha->flags.n2n_ae = 1;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003945 return;
Quinn Tran8777e432018-08-02 13:16:57 -07003946 break;
3947 case TOPO_FL:
3948 ha->current_topology = ISP_CFG_FL;
3949 break;
3950 case TOPO_F:
3951 ha->current_topology = ISP_CFG_F;
3952 break;
3953 default:
3954 break;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003955 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003956
Quinn Tran9cd883f2017-12-28 12:33:24 -08003957 ha->flags.gpsc_supported = 1;
3958 ha->current_topology = ISP_CFG_F;
Sawan Chandak969a6192016-01-27 12:03:32 -05003959 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003960 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003961
Quinn Tran41dc5292017-01-19 22:28:03 -08003962 if (rptid_entry->vp_idx == 0) {
3963 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3964 /* FA-WWN is only for physical port */
3965 if (qla_ini_mode_enabled(vha) &&
3966 ha->flags.fawwpn_enabled &&
3967 (rptid_entry->u.f1.flags &
Sawan Chandakfcc5b5c2017-08-23 15:05:02 -07003968 BIT_6)) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003969 memcpy(vha->port_name,
3970 rptid_entry->u.f1.port_name,
3971 WWN_SIZE);
3972 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003973
Quinn Tran482c9dc2017-03-15 09:48:54 -07003974 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003975 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003976
Quinn Tran41dc5292017-01-19 22:28:03 -08003977 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3978 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3979 } else {
3980 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3981 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3982 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3983 "Could not acquire ID for VP[%d].\n",
3984 rptid_entry->vp_idx);
3985 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003986 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003987
3988 found = 0;
3989 spin_lock_irqsave(&ha->vport_slock, flags);
3990 list_for_each_entry(vp, &ha->vp_list, list) {
3991 if (rptid_entry->vp_idx == vp->vp_idx) {
3992 found = 1;
3993 break;
3994 }
3995 }
3996 spin_unlock_irqrestore(&ha->vport_slock, flags);
3997
3998 if (!found)
3999 return;
4000
Quinn Tran482c9dc2017-03-15 09:48:54 -07004001 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08004002
4003 /*
4004 * Cannot configure here as we are still sitting on the
4005 * response queue. Handle it in dpc context.
4006 */
4007 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
4008 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
4009 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05004010 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07004011 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004012 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08004013 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004014 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08004015 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
4016 rptid_entry->port_id[2], rptid_entry->port_id[1],
4017 rptid_entry->port_id[0]);
4018
Quinn Tran83548fe2017-06-02 09:12:01 -07004019 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08004020 "N2N: Remote WWPN %8phC.\n",
4021 rptid_entry->u.f2.port_name);
4022
4023 /* N2N. direct connect */
Quinn Tran9cd883f2017-12-28 12:33:24 -08004024 ha->current_topology = ISP_CFG_N;
4025 ha->flags.rida_fmt2 = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004026 vha->d_id.b.domain = rptid_entry->port_id[2];
4027 vha->d_id.b.area = rptid_entry->port_id[1];
4028 vha->d_id.b.al_pa = rptid_entry->port_id[0];
4029
Darren Trapp1763c1f2018-03-20 23:09:34 -07004030 ha->flags.n2n_ae = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004031 spin_lock_irqsave(&ha->vport_slock, flags);
4032 qlt_update_vp_map(vha, SET_AL_PA);
4033 spin_unlock_irqrestore(&ha->vport_slock, flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004034
4035 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4036 fcport->scan_state = QLA_FCPORT_SCAN;
Quinn Tran7f2a3982019-09-12 11:09:09 -07004037 fcport->n2n_flag = 0;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004038 }
4039
4040 fcport = qla2x00_find_fcport_by_wwpn(vha,
4041 rptid_entry->u.f2.port_name, 1);
4042
4043 if (fcport) {
Quinn Tran23dd98a2018-08-02 13:16:45 -07004044 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004045 fcport->plogi_nack_done_deadline = jiffies + HZ;
4046 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tranf3f19382019-09-12 11:09:10 -07004047 fcport->keep_nport_handle = 1;
Quinn Tran7f2a3982019-09-12 11:09:09 -07004048 fcport->n2n_flag = 1;
4049 fcport->d_id.b.domain =
4050 rptid_entry->u.f2.remote_nport_id[2];
4051 fcport->d_id.b.area =
4052 rptid_entry->u.f2.remote_nport_id[1];
4053 fcport->d_id.b.al_pa =
4054 rptid_entry->u.f2.remote_nport_id[0];
Quinn Tran9cd883f2017-12-28 12:33:24 -08004055 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004056 }
4057}
4058
4059/*
4060 * qla24xx_modify_vp_config
4061 * Change VP configuration for vha
4062 *
4063 * Input:
4064 * vha = adapter block pointer.
4065 *
4066 * Returns:
4067 * qla2xxx local function return status code.
4068 *
4069 * Context:
4070 * Kernel context.
4071 */
4072int
4073qla24xx_modify_vp_config(scsi_qla_host_t *vha)
4074{
4075 int rval;
4076 struct vp_config_entry_24xx *vpmod;
4077 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004078 struct qla_hw_data *ha = vha->hw;
4079 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004080
4081 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004082
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004083 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
4084 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004085
Thomas Meyer08eb7f42017-09-21 08:15:26 +02004086 vpmod = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004087 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004088 ql_log(ql_log_warn, vha, 0x10bc,
4089 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004090 return QLA_MEMORY_ALLOC_FAILED;
4091 }
4092
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004093 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
4094 vpmod->entry_count = 1;
4095 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
4096 vpmod->vp_count = 1;
4097 vpmod->vp_index1 = vha->vp_idx;
4098 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004099
4100 qlt_modify_vp_config(vha, vpmod);
4101
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004102 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
4103 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
4104 vpmod->entry_count = 1;
4105
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004106 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004107 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004108 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
4109 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004110 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004111 ql_dbg(ql_dbg_mbx, vha, 0x10be,
4112 "Failed to complete IOCB -- error status (%x).\n",
4113 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004114 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07004115 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004116 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
4117 "Failed to complete IOCB -- completion status (%x).\n",
4118 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004119 rval = QLA_FUNCTION_FAILED;
4120 } else {
4121 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004122 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
4123 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004124 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
4125 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004126 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004127
4128 return rval;
4129}
4130
4131/*
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004132 * qla2x00_send_change_request
4133 * Receive or disable RSCN request from fabric controller
4134 *
4135 * Input:
4136 * ha = adapter block pointer
4137 * format = registration format:
4138 * 0 - Reserved
4139 * 1 - Fabric detected registration
4140 * 2 - N_port detected registration
4141 * 3 - Full registration
4142 * FF - clear registration
4143 * vp_idx = Virtual port index
4144 *
4145 * Returns:
4146 * qla2x00 local function return status code.
4147 *
4148 * Context:
4149 * Kernel Context
4150 */
4151
4152int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004153qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004154 uint16_t vp_idx)
4155{
4156 int rval;
4157 mbx_cmd_t mc;
4158 mbx_cmd_t *mcp = &mc;
4159
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
4161 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004162
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004163 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
4164 mcp->mb[1] = format;
4165 mcp->mb[9] = vp_idx;
4166 mcp->out_mb = MBX_9|MBX_1|MBX_0;
4167 mcp->in_mb = MBX_0|MBX_1;
4168 mcp->tov = MBX_TOV_SECONDS;
4169 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004170 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004171
4172 if (rval == QLA_SUCCESS) {
4173 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
4174 rval = BIT_1;
4175 }
4176 } else
4177 rval = BIT_1;
4178
4179 return rval;
4180}
Andrew Vasquez338c9162007-09-20 14:07:33 -07004181
4182int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004183qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07004184 uint32_t size)
4185{
4186 int rval;
4187 mbx_cmd_t mc;
4188 mbx_cmd_t *mcp = &mc;
4189
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004190 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
4191 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004192
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004193 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004194 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
4195 mcp->mb[8] = MSW(addr);
4196 mcp->out_mb = MBX_8|MBX_0;
4197 } else {
4198 mcp->mb[0] = MBC_DUMP_RISC_RAM;
4199 mcp->out_mb = MBX_0;
4200 }
4201 mcp->mb[1] = LSW(addr);
4202 mcp->mb[2] = MSW(req_dma);
4203 mcp->mb[3] = LSW(req_dma);
4204 mcp->mb[6] = MSW(MSD(req_dma));
4205 mcp->mb[7] = LSW(MSD(req_dma));
4206 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004207 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004208 mcp->mb[4] = MSW(size);
4209 mcp->mb[5] = LSW(size);
4210 mcp->out_mb |= MBX_5|MBX_4;
4211 } else {
4212 mcp->mb[4] = LSW(size);
4213 mcp->out_mb |= MBX_4;
4214 }
4215
4216 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004217 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004218 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004219 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004220
4221 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004222 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4223 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004224 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004225 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4226 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004227 }
4228
4229 return rval;
4230}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004231/* 84XX Support **************************************************************/
4232
4233struct cs84xx_mgmt_cmd {
4234 union {
4235 struct verify_chip_entry_84xx req;
4236 struct verify_chip_rsp_84xx rsp;
4237 } p;
4238};
4239
4240int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004241qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004242{
4243 int rval, retry;
4244 struct cs84xx_mgmt_cmd *mn;
4245 dma_addr_t mn_dma;
4246 uint16_t options;
4247 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004248 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004249
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004250 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4251 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004252
4253 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4254 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004255 return QLA_MEMORY_ALLOC_FAILED;
4256 }
4257
4258 /* Force Update? */
4259 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4260 /* Diagnostic firmware? */
4261 /* options |= MENLO_DIAG_FW; */
4262 /* We update the firmware with only one data sequence. */
4263 options |= VCO_END_OF_DATA;
4264
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004265 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004266 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004267 memset(mn, 0, sizeof(*mn));
4268 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4269 mn->p.req.entry_count = 1;
4270 mn->p.req.options = cpu_to_le16(options);
4271
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004272 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4273 "Dump of Verify Request.\n");
4274 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07004275 mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004276
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004277 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004278 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004279 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4280 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004281 goto verify_done;
4282 }
4283
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004284 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4285 "Dump of Verify Response.\n");
4286 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07004287 mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004288
4289 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4290 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4291 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004292 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004293 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004294
4295 if (status[0] != CS_COMPLETE) {
4296 rval = QLA_FUNCTION_FAILED;
4297 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004298 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4299 "Firmware update failed. Retrying "
4300 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004301 options |= VCO_DONT_UPDATE_FW;
4302 options &= ~VCO_FORCE_UPDATE;
4303 retry = 1;
4304 }
4305 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004306 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004307 "Firmware updated to %x.\n",
4308 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004309
4310 /* NOTE: we only update OP firmware. */
4311 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4312 ha->cs84xx->op_fw_version =
4313 le32_to_cpu(mn->p.rsp.fw_ver);
4314 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4315 flags);
4316 }
4317 } while (retry);
4318
4319verify_done:
4320 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4321
4322 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004323 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4324 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004325 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004326 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4327 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004328 }
4329
4330 return rval;
4331}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004332
4333int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004334qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004335{
4336 int rval;
4337 unsigned long flags;
4338 mbx_cmd_t mc;
4339 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004340 struct qla_hw_data *ha = vha->hw;
4341
Quinn Tran45235022018-07-18 14:29:53 -07004342 if (!ha->flags.fw_started)
4343 return QLA_SUCCESS;
4344
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004345 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4346 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004347
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004348 if (IS_SHADOW_REG_CAPABLE(ha))
4349 req->options |= BIT_13;
4350
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004351 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004352 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004353 mcp->mb[2] = MSW(LSD(req->dma));
4354 mcp->mb[3] = LSW(LSD(req->dma));
4355 mcp->mb[6] = MSW(MSD(req->dma));
4356 mcp->mb[7] = LSW(MSD(req->dma));
4357 mcp->mb[5] = req->length;
4358 if (req->rsp)
4359 mcp->mb[10] = req->rsp->id;
4360 mcp->mb[12] = req->qos;
4361 mcp->mb[11] = req->vp_idx;
4362 mcp->mb[13] = req->rid;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004363 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004364 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004365
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004366 mcp->mb[4] = req->id;
4367 /* que in ptr index */
4368 mcp->mb[8] = 0;
4369 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004370 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004371 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4372 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4373 mcp->in_mb = MBX_0;
4374 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004375 mcp->tov = MBX_TOV_SECONDS * 2;
4376
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004377 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4378 IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004379 mcp->in_mb |= MBX_1;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004380 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004381 mcp->out_mb |= MBX_15;
4382 /* debug q create issue in SR-IOV */
4383 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4384 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004385
4386 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004387 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004388 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004389 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004390 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004391 }
4392 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4393
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004394 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004395 if (rval != QLA_SUCCESS) {
4396 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4397 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4398 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004399 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4400 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004401 }
4402
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004403 return rval;
4404}
4405
4406int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004407qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004408{
4409 int rval;
4410 unsigned long flags;
4411 mbx_cmd_t mc;
4412 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004413 struct qla_hw_data *ha = vha->hw;
4414
Quinn Tran45235022018-07-18 14:29:53 -07004415 if (!ha->flags.fw_started)
4416 return QLA_SUCCESS;
4417
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004418 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4419 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004420
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004421 if (IS_SHADOW_REG_CAPABLE(ha))
4422 rsp->options |= BIT_13;
4423
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004424 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004425 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004426 mcp->mb[2] = MSW(LSD(rsp->dma));
4427 mcp->mb[3] = LSW(LSD(rsp->dma));
4428 mcp->mb[6] = MSW(MSD(rsp->dma));
4429 mcp->mb[7] = LSW(MSD(rsp->dma));
4430 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004431 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004432 mcp->mb[13] = rsp->rid;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004433 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004434 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004435
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004436 mcp->mb[4] = rsp->id;
4437 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004438 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004439 /* que out ptr index */
4440 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004441 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004442 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4443 mcp->in_mb = MBX_0;
4444 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004445 mcp->tov = MBX_TOV_SECONDS * 2;
4446
4447 if (IS_QLA81XX(ha)) {
4448 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4449 mcp->in_mb |= MBX_1;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004450 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004451 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4452 mcp->in_mb |= MBX_1;
4453 /* debug q create issue in SR-IOV */
4454 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4455 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004456
4457 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004458 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004459 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004460 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004461 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004462 }
4463
4464 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4465
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004466 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004467 if (rval != QLA_SUCCESS) {
4468 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4469 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4470 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004471 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4472 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004473 }
4474
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004475 return rval;
4476}
4477
Andrew Vasquez8a659572009-02-08 20:50:12 -08004478int
4479qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4480{
4481 int rval;
4482 mbx_cmd_t mc;
4483 mbx_cmd_t *mcp = &mc;
4484
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004485 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4486 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004487
4488 mcp->mb[0] = MBC_IDC_ACK;
4489 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4490 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4491 mcp->in_mb = MBX_0;
4492 mcp->tov = MBX_TOV_SECONDS;
4493 mcp->flags = 0;
4494 rval = qla2x00_mailbox_command(vha, mcp);
4495
4496 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004497 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4498 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004499 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004500 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4501 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004502 }
4503
4504 return rval;
4505}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004506
4507int
4508qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4509{
4510 int rval;
4511 mbx_cmd_t mc;
4512 mbx_cmd_t *mcp = &mc;
4513
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004514 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4515 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004516
Chad Dupuisf73cb692014-02-26 04:15:06 -05004517 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004518 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004519 return QLA_FUNCTION_FAILED;
4520
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004521 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4522 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4523 mcp->out_mb = MBX_1|MBX_0;
4524 mcp->in_mb = MBX_1|MBX_0;
4525 mcp->tov = MBX_TOV_SECONDS;
4526 mcp->flags = 0;
4527 rval = qla2x00_mailbox_command(vha, mcp);
4528
4529 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004530 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4531 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4532 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004533 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004534 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4535 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004536 *sector_size = mcp->mb[1];
4537 }
4538
4539 return rval;
4540}
4541
4542int
4543qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4544{
4545 int rval;
4546 mbx_cmd_t mc;
4547 mbx_cmd_t *mcp = &mc;
4548
Chad Dupuisf73cb692014-02-26 04:15:06 -05004549 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004550 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004551 return QLA_FUNCTION_FAILED;
4552
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004553 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4554 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004555
4556 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4557 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4558 FAC_OPT_CMD_WRITE_PROTECT;
4559 mcp->out_mb = MBX_1|MBX_0;
4560 mcp->in_mb = MBX_1|MBX_0;
4561 mcp->tov = MBX_TOV_SECONDS;
4562 mcp->flags = 0;
4563 rval = qla2x00_mailbox_command(vha, mcp);
4564
4565 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004566 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4567 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4568 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004569 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004570 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4571 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004572 }
4573
4574 return rval;
4575}
4576
4577int
4578qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4579{
4580 int rval;
4581 mbx_cmd_t mc;
4582 mbx_cmd_t *mcp = &mc;
4583
Chad Dupuisf73cb692014-02-26 04:15:06 -05004584 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004585 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004586 return QLA_FUNCTION_FAILED;
4587
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4589 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004590
4591 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4592 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4593 mcp->mb[2] = LSW(start);
4594 mcp->mb[3] = MSW(start);
4595 mcp->mb[4] = LSW(finish);
4596 mcp->mb[5] = MSW(finish);
4597 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4598 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4599 mcp->tov = MBX_TOV_SECONDS;
4600 mcp->flags = 0;
4601 rval = qla2x00_mailbox_command(vha, mcp);
4602
4603 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004604 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4605 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4606 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004607 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004608 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4609 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004610 }
4611
4612 return rval;
4613}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004614
4615int
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004616qla81xx_fac_semaphore_access(scsi_qla_host_t *vha, int lock)
4617{
4618 int rval = QLA_SUCCESS;
4619 mbx_cmd_t mc;
4620 mbx_cmd_t *mcp = &mc;
4621 struct qla_hw_data *ha = vha->hw;
4622
4623 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
4624 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
4625 return rval;
4626
4627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4628 "Entered %s.\n", __func__);
4629
4630 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4631 mcp->mb[1] = (lock ? FAC_OPT_CMD_LOCK_SEMAPHORE :
4632 FAC_OPT_CMD_UNLOCK_SEMAPHORE);
4633 mcp->out_mb = MBX_1|MBX_0;
4634 mcp->in_mb = MBX_1|MBX_0;
4635 mcp->tov = MBX_TOV_SECONDS;
4636 mcp->flags = 0;
4637 rval = qla2x00_mailbox_command(vha, mcp);
4638
4639 if (rval != QLA_SUCCESS) {
4640 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4641 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4642 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
4643 } else {
4644 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4645 "Done %s.\n", __func__);
4646 }
4647
4648 return rval;
4649}
4650
4651int
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004652qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4653{
4654 int rval = 0;
4655 mbx_cmd_t mc;
4656 mbx_cmd_t *mcp = &mc;
4657
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004658 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4659 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004660
4661 mcp->mb[0] = MBC_RESTART_MPI_FW;
4662 mcp->out_mb = MBX_0;
4663 mcp->in_mb = MBX_0|MBX_1;
4664 mcp->tov = MBX_TOV_SECONDS;
4665 mcp->flags = 0;
4666 rval = qla2x00_mailbox_command(vha, mcp);
4667
4668 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004669 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4670 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4671 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004672 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004673 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4674 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004675 }
4676
4677 return rval;
4678}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004679
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004680int
4681qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4682{
4683 int rval;
4684 mbx_cmd_t mc;
4685 mbx_cmd_t *mcp = &mc;
4686 int i;
4687 int len;
4688 uint16_t *str;
4689 struct qla_hw_data *ha = vha->hw;
4690
4691 if (!IS_P3P_TYPE(ha))
4692 return QLA_FUNCTION_FAILED;
4693
4694 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4695 "Entered %s.\n", __func__);
4696
4697 str = (void *)version;
4698 len = strlen(version);
4699
4700 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4701 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4702 mcp->out_mb = MBX_1|MBX_0;
4703 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4704 mcp->mb[i] = cpu_to_le16p(str);
4705 mcp->out_mb |= 1<<i;
4706 }
4707 for (; i < 16; i++) {
4708 mcp->mb[i] = 0;
4709 mcp->out_mb |= 1<<i;
4710 }
4711 mcp->in_mb = MBX_1|MBX_0;
4712 mcp->tov = MBX_TOV_SECONDS;
4713 mcp->flags = 0;
4714 rval = qla2x00_mailbox_command(vha, mcp);
4715
4716 if (rval != QLA_SUCCESS) {
4717 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4718 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4719 } else {
4720 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4721 "Done %s.\n", __func__);
4722 }
4723
4724 return rval;
4725}
4726
4727int
4728qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4729{
4730 int rval;
4731 mbx_cmd_t mc;
4732 mbx_cmd_t *mcp = &mc;
4733 int len;
4734 uint16_t dwlen;
4735 uint8_t *str;
4736 dma_addr_t str_dma;
4737 struct qla_hw_data *ha = vha->hw;
4738
4739 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4740 IS_P3P_TYPE(ha))
4741 return QLA_FUNCTION_FAILED;
4742
4743 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4744 "Entered %s.\n", __func__);
4745
4746 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4747 if (!str) {
4748 ql_log(ql_log_warn, vha, 0x117f,
4749 "Failed to allocate driver version param.\n");
4750 return QLA_MEMORY_ALLOC_FAILED;
4751 }
4752
4753 memcpy(str, "\x7\x3\x11\x0", 4);
4754 dwlen = str[0];
4755 len = dwlen * 4 - 4;
4756 memset(str + 4, 0, len);
4757 if (len > strlen(version))
4758 len = strlen(version);
4759 memcpy(str + 4, version, len);
4760
4761 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4762 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4763 mcp->mb[2] = MSW(LSD(str_dma));
4764 mcp->mb[3] = LSW(LSD(str_dma));
4765 mcp->mb[6] = MSW(MSD(str_dma));
4766 mcp->mb[7] = LSW(MSD(str_dma));
4767 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4768 mcp->in_mb = MBX_1|MBX_0;
4769 mcp->tov = MBX_TOV_SECONDS;
4770 mcp->flags = 0;
4771 rval = qla2x00_mailbox_command(vha, mcp);
4772
4773 if (rval != QLA_SUCCESS) {
4774 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4775 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4776 } else {
4777 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4778 "Done %s.\n", __func__);
4779 }
4780
4781 dma_pool_free(ha->s_dma_pool, str, str_dma);
4782
4783 return rval;
4784}
4785
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004786int
4787qla24xx_get_port_login_templ(scsi_qla_host_t *vha, dma_addr_t buf_dma,
4788 void *buf, uint16_t bufsiz)
4789{
4790 int rval, i;
4791 mbx_cmd_t mc;
4792 mbx_cmd_t *mcp = &mc;
4793 uint32_t *bp;
4794
4795 if (!IS_FWI2_CAPABLE(vha->hw))
4796 return QLA_FUNCTION_FAILED;
4797
4798 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4799 "Entered %s.\n", __func__);
4800
4801 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4802 mcp->mb[1] = RNID_TYPE_PORT_LOGIN << 8;
4803 mcp->mb[2] = MSW(buf_dma);
4804 mcp->mb[3] = LSW(buf_dma);
4805 mcp->mb[6] = MSW(MSD(buf_dma));
4806 mcp->mb[7] = LSW(MSD(buf_dma));
4807 mcp->mb[8] = bufsiz/4;
4808 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4809 mcp->in_mb = MBX_1|MBX_0;
4810 mcp->tov = MBX_TOV_SECONDS;
4811 mcp->flags = 0;
4812 rval = qla2x00_mailbox_command(vha, mcp);
4813
4814 if (rval != QLA_SUCCESS) {
4815 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4816 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4817 } else {
4818 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4819 "Done %s.\n", __func__);
4820 bp = (uint32_t *) buf;
4821 for (i = 0; i < (bufsiz-4)/4; i++, bp++)
Quinn Tran8777e432018-08-02 13:16:57 -07004822 *bp = le32_to_cpu(*bp);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004823 }
4824
4825 return rval;
4826}
4827
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004828static int
4829qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4830{
4831 int rval;
4832 mbx_cmd_t mc;
4833 mbx_cmd_t *mcp = &mc;
4834
4835 if (!IS_FWI2_CAPABLE(vha->hw))
4836 return QLA_FUNCTION_FAILED;
4837
4838 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4839 "Entered %s.\n", __func__);
4840
4841 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4842 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4843 mcp->out_mb = MBX_1|MBX_0;
4844 mcp->in_mb = MBX_1|MBX_0;
4845 mcp->tov = MBX_TOV_SECONDS;
4846 mcp->flags = 0;
4847 rval = qla2x00_mailbox_command(vha, mcp);
4848 *temp = mcp->mb[1];
4849
4850 if (rval != QLA_SUCCESS) {
4851 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4852 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4853 } else {
4854 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4855 "Done %s.\n", __func__);
4856 }
4857
4858 return rval;
4859}
4860
Joe Carnuccio3a117112013-02-08 01:58:00 -05004861int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004862qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4863 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004864{
4865 int rval;
4866 mbx_cmd_t mc;
4867 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004868 struct qla_hw_data *ha = vha->hw;
4869
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004870 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4871 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004872
Joe Carnuccio6766df92011-05-10 11:30:15 -07004873 if (!IS_FWI2_CAPABLE(ha))
4874 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004875
Joe Carnuccio6766df92011-05-10 11:30:15 -07004876 if (len == 1)
4877 opt |= BIT_0;
4878
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004879 mcp->mb[0] = MBC_READ_SFP;
4880 mcp->mb[1] = dev;
4881 mcp->mb[2] = MSW(sfp_dma);
4882 mcp->mb[3] = LSW(sfp_dma);
4883 mcp->mb[6] = MSW(MSD(sfp_dma));
4884 mcp->mb[7] = LSW(MSD(sfp_dma));
4885 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004886 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004887 mcp->mb[10] = opt;
4888 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 -07004889 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004890 mcp->tov = MBX_TOV_SECONDS;
4891 mcp->flags = 0;
4892 rval = qla2x00_mailbox_command(vha, mcp);
4893
4894 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004895 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004896
4897 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004898 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4899 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07004900 if (mcp->mb[0] == MBS_COMMAND_ERROR && mcp->mb[1] == 0x22) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004901 /* sfp is not there */
4902 rval = QLA_INTERFACE_ERROR;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07004903 }
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004904 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004905 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4906 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004907 }
4908
4909 return rval;
4910}
4911
4912int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004913qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4914 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004915{
4916 int rval;
4917 mbx_cmd_t mc;
4918 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004919 struct qla_hw_data *ha = vha->hw;
4920
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004921 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4922 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004923
Joe Carnuccio6766df92011-05-10 11:30:15 -07004924 if (!IS_FWI2_CAPABLE(ha))
4925 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004926
Joe Carnuccio6766df92011-05-10 11:30:15 -07004927 if (len == 1)
4928 opt |= BIT_0;
4929
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004930 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004931 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004932
4933 mcp->mb[0] = MBC_WRITE_SFP;
4934 mcp->mb[1] = dev;
4935 mcp->mb[2] = MSW(sfp_dma);
4936 mcp->mb[3] = LSW(sfp_dma);
4937 mcp->mb[6] = MSW(MSD(sfp_dma));
4938 mcp->mb[7] = LSW(MSD(sfp_dma));
4939 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004940 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004941 mcp->mb[10] = opt;
4942 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 -07004943 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004944 mcp->tov = MBX_TOV_SECONDS;
4945 mcp->flags = 0;
4946 rval = qla2x00_mailbox_command(vha, mcp);
4947
4948 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004949 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4950 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004951 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004952 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4953 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004954 }
4955
4956 return rval;
4957}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004958
4959int
4960qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4961 uint16_t size_in_bytes, uint16_t *actual_size)
4962{
4963 int rval;
4964 mbx_cmd_t mc;
4965 mbx_cmd_t *mcp = &mc;
4966
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004967 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4968 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004969
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004970 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004971 return QLA_FUNCTION_FAILED;
4972
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004973 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4974 mcp->mb[2] = MSW(stats_dma);
4975 mcp->mb[3] = LSW(stats_dma);
4976 mcp->mb[6] = MSW(MSD(stats_dma));
4977 mcp->mb[7] = LSW(MSD(stats_dma));
4978 mcp->mb[8] = size_in_bytes >> 2;
4979 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4980 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4981 mcp->tov = MBX_TOV_SECONDS;
4982 mcp->flags = 0;
4983 rval = qla2x00_mailbox_command(vha, mcp);
4984
4985 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004986 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4987 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4988 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004989 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004990 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4991 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004992
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004993
4994 *actual_size = mcp->mb[2] << 2;
4995 }
4996
4997 return rval;
4998}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004999
5000int
5001qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
5002 uint16_t size)
5003{
5004 int rval;
5005 mbx_cmd_t mc;
5006 mbx_cmd_t *mcp = &mc;
5007
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005008 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
5009 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005010
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005011 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005012 return QLA_FUNCTION_FAILED;
5013
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005014 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
5015 mcp->mb[1] = 0;
5016 mcp->mb[2] = MSW(tlv_dma);
5017 mcp->mb[3] = LSW(tlv_dma);
5018 mcp->mb[6] = MSW(MSD(tlv_dma));
5019 mcp->mb[7] = LSW(MSD(tlv_dma));
5020 mcp->mb[8] = size;
5021 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5022 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5023 mcp->tov = MBX_TOV_SECONDS;
5024 mcp->flags = 0;
5025 rval = qla2x00_mailbox_command(vha, mcp);
5026
5027 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005028 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
5029 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
5030 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005031 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005032 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
5033 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005034 }
5035
5036 return rval;
5037}
Andrew Vasquez18e75552009-06-03 09:55:30 -07005038
5039int
5040qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
5041{
5042 int rval;
5043 mbx_cmd_t mc;
5044 mbx_cmd_t *mcp = &mc;
5045
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005046 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
5047 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005048
Andrew Vasquez18e75552009-06-03 09:55:30 -07005049 if (!IS_FWI2_CAPABLE(vha->hw))
5050 return QLA_FUNCTION_FAILED;
5051
Andrew Vasquez18e75552009-06-03 09:55:30 -07005052 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
5053 mcp->mb[1] = LSW(risc_addr);
5054 mcp->mb[8] = MSW(risc_addr);
5055 mcp->out_mb = MBX_8|MBX_1|MBX_0;
5056 mcp->in_mb = MBX_3|MBX_2|MBX_0;
5057 mcp->tov = 30;
5058 mcp->flags = 0;
5059 rval = qla2x00_mailbox_command(vha, mcp);
5060 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005061 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
5062 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005063 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005064 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
5065 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005066 *data = mcp->mb[3] << 16 | mcp->mb[2];
5067 }
5068
5069 return rval;
5070}
5071
5072int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005073qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5074 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005075{
5076 int rval;
5077 mbx_cmd_t mc;
5078 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005079
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005080 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
5081 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005082
5083 memset(mcp->mb, 0 , sizeof(mcp->mb));
5084 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
5085 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
5086
5087 /* transfer count */
5088 mcp->mb[10] = LSW(mreq->transfer_size);
5089 mcp->mb[11] = MSW(mreq->transfer_size);
5090
5091 /* send data address */
5092 mcp->mb[14] = LSW(mreq->send_dma);
5093 mcp->mb[15] = MSW(mreq->send_dma);
5094 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5095 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5096
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005097 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005098 mcp->mb[16] = LSW(mreq->rcv_dma);
5099 mcp->mb[17] = MSW(mreq->rcv_dma);
5100 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5101 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5102
5103 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04005104 mcp->mb[18] = LSW(mreq->iteration_count);
5105 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005106
5107 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
5108 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 -08005109 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005110 mcp->out_mb |= MBX_2;
5111 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
5112
5113 mcp->buf_size = mreq->transfer_size;
5114 mcp->tov = MBX_TOV_SECONDS;
5115 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5116
5117 rval = qla2x00_mailbox_command(vha, mcp);
5118
5119 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005120 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
5121 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
5122 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
5123 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005124 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005125 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
5126 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005127 }
5128
5129 /* Copy mailbox information */
5130 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005131 return rval;
5132}
5133
5134int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005135qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5136 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005137{
5138 int rval;
5139 mbx_cmd_t mc;
5140 mbx_cmd_t *mcp = &mc;
5141 struct qla_hw_data *ha = vha->hw;
5142
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005143 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
5144 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005145
5146 memset(mcp->mb, 0 , sizeof(mcp->mb));
5147 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07005148 /* BIT_6 specifies 64bit address */
5149 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005150 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005151 mcp->mb[2] = vha->fcoe_fcf_idx;
5152 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005153 mcp->mb[16] = LSW(mreq->rcv_dma);
5154 mcp->mb[17] = MSW(mreq->rcv_dma);
5155 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5156 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5157
5158 mcp->mb[10] = LSW(mreq->transfer_size);
5159
5160 mcp->mb[14] = LSW(mreq->send_dma);
5161 mcp->mb[15] = MSW(mreq->send_dma);
5162 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5163 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5164
5165 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
5166 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005167 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005168 mcp->out_mb |= MBX_2;
5169
5170 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005171 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
5172 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005173 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005174 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005175 mcp->in_mb |= MBX_3;
5176
5177 mcp->tov = MBX_TOV_SECONDS;
5178 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5179 mcp->buf_size = mreq->transfer_size;
5180
5181 rval = qla2x00_mailbox_command(vha, mcp);
5182
5183 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005184 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
5185 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5186 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005187 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
5189 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005190 }
5191
5192 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005193 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005194 return rval;
5195}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005196
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005197int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005198qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005199{
5200 int rval;
5201 mbx_cmd_t mc;
5202 mbx_cmd_t *mcp = &mc;
5203
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005204 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005205 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005206
5207 mcp->mb[0] = MBC_ISP84XX_RESET;
5208 mcp->mb[1] = enable_diagnostic;
5209 mcp->out_mb = MBX_1|MBX_0;
5210 mcp->in_mb = MBX_1|MBX_0;
5211 mcp->tov = MBX_TOV_SECONDS;
5212 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005213 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005214
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005215 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005216 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005217 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005218 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
5219 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005220
5221 return rval;
5222}
5223
5224int
Andrew Vasquez18e75552009-06-03 09:55:30 -07005225qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
5226{
5227 int rval;
5228 mbx_cmd_t mc;
5229 mbx_cmd_t *mcp = &mc;
5230
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005231 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
5232 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005233
Andrew Vasquez18e75552009-06-03 09:55:30 -07005234 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005235 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005236
Andrew Vasquez18e75552009-06-03 09:55:30 -07005237 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
5238 mcp->mb[1] = LSW(risc_addr);
5239 mcp->mb[2] = LSW(data);
5240 mcp->mb[3] = MSW(data);
5241 mcp->mb[8] = MSW(risc_addr);
5242 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07005243 mcp->in_mb = MBX_1|MBX_0;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005244 mcp->tov = 30;
5245 mcp->flags = 0;
5246 rval = qla2x00_mailbox_command(vha, mcp);
5247 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005248 ql_dbg(ql_dbg_mbx, vha, 0x1101,
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07005249 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5250 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005251 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005252 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
5253 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005254 }
5255
5256 return rval;
5257}
Michael Hernandez3064ff32009-12-15 21:29:44 -08005258
5259int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005260qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
5261{
5262 int rval;
5263 uint32_t stat, timer;
5264 uint16_t mb0 = 0;
5265 struct qla_hw_data *ha = vha->hw;
5266 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5267
5268 rval = QLA_SUCCESS;
5269
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005270 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
5271 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005272
5273 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
5274
5275 /* Write the MBC data to the registers */
5276 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
5277 WRT_REG_WORD(&reg->mailbox1, mb[0]);
5278 WRT_REG_WORD(&reg->mailbox2, mb[1]);
5279 WRT_REG_WORD(&reg->mailbox3, mb[2]);
5280 WRT_REG_WORD(&reg->mailbox4, mb[3]);
5281
5282 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
5283
5284 /* Poll for MBC interrupt */
5285 for (timer = 6000000; timer; timer--) {
5286 /* Check for pending interrupts. */
5287 stat = RD_REG_DWORD(&reg->host_status);
5288 if (stat & HSRX_RISC_INT) {
5289 stat &= 0xff;
5290
5291 if (stat == 0x1 || stat == 0x2 ||
5292 stat == 0x10 || stat == 0x11) {
5293 set_bit(MBX_INTERRUPT,
5294 &ha->mbx_cmd_flags);
5295 mb0 = RD_REG_WORD(&reg->mailbox0);
5296 WRT_REG_DWORD(&reg->hccr,
5297 HCCRX_CLR_RISC_INT);
5298 RD_REG_DWORD(&reg->hccr);
5299 break;
5300 }
5301 }
5302 udelay(5);
5303 }
5304
5305 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5306 rval = mb0 & MBS_MASK;
5307 else
5308 rval = QLA_FUNCTION_FAILED;
5309
5310 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005311 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5312 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005313 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005314 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5315 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005316 }
5317
5318 return rval;
5319}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005320
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005321/* Set the specified data rate */
5322int
5323qla2x00_set_data_rate(scsi_qla_host_t *vha, uint16_t mode)
5324{
5325 int rval;
5326 mbx_cmd_t mc;
5327 mbx_cmd_t *mcp = &mc;
5328 struct qla_hw_data *ha = vha->hw;
5329 uint16_t val;
5330
5331 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5332 "Entered %s speed:0x%x mode:0x%x.\n", __func__, ha->set_data_rate,
5333 mode);
5334
5335 if (!IS_FWI2_CAPABLE(ha))
5336 return QLA_FUNCTION_FAILED;
5337
5338 memset(mcp, 0, sizeof(*mcp));
5339 switch (ha->set_data_rate) {
5340 case PORT_SPEED_AUTO:
5341 case PORT_SPEED_4GB:
5342 case PORT_SPEED_8GB:
5343 case PORT_SPEED_16GB:
5344 case PORT_SPEED_32GB:
5345 val = ha->set_data_rate;
5346 break;
5347 default:
5348 ql_log(ql_log_warn, vha, 0x1199,
5349 "Unrecognized speed setting:%d. Setting Autoneg\n",
5350 ha->set_data_rate);
5351 val = ha->set_data_rate = PORT_SPEED_AUTO;
5352 break;
5353 }
5354
5355 mcp->mb[0] = MBC_DATA_RATE;
5356 mcp->mb[1] = mode;
5357 mcp->mb[2] = val;
5358
5359 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5360 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005361 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005362 mcp->in_mb |= MBX_4|MBX_3;
5363 mcp->tov = MBX_TOV_SECONDS;
5364 mcp->flags = 0;
5365 rval = qla2x00_mailbox_command(vha, mcp);
5366 if (rval != QLA_SUCCESS) {
5367 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5368 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5369 } else {
5370 if (mcp->mb[1] != 0x7)
5371 ql_dbg(ql_dbg_mbx, vha, 0x1179,
5372 "Speed set:0x%x\n", mcp->mb[1]);
5373
5374 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5375 "Done %s.\n", __func__);
5376 }
5377
5378 return rval;
5379}
5380
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005381int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005382qla2x00_get_data_rate(scsi_qla_host_t *vha)
5383{
5384 int rval;
5385 mbx_cmd_t mc;
5386 mbx_cmd_t *mcp = &mc;
5387 struct qla_hw_data *ha = vha->hw;
5388
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005389 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5390 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005391
Michael Hernandez3064ff32009-12-15 21:29:44 -08005392 if (!IS_FWI2_CAPABLE(ha))
5393 return QLA_FUNCTION_FAILED;
5394
Michael Hernandez3064ff32009-12-15 21:29:44 -08005395 mcp->mb[0] = MBC_DATA_RATE;
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005396 mcp->mb[1] = QLA_GET_DATA_RATE;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005397 mcp->out_mb = MBX_1|MBX_0;
5398 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005399 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005400 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005401 mcp->tov = MBX_TOV_SECONDS;
5402 mcp->flags = 0;
5403 rval = qla2x00_mailbox_command(vha, mcp);
5404 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005405 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5406 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005407 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5409 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005410 if (mcp->mb[1] != 0x7)
5411 ha->link_data_rate = mcp->mb[1];
5412 }
5413
5414 return rval;
5415}
Sarang Radke09ff7012010-03-19 17:03:59 -07005416
5417int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005418qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5419{
5420 int rval;
5421 mbx_cmd_t mc;
5422 mbx_cmd_t *mcp = &mc;
5423 struct qla_hw_data *ha = vha->hw;
5424
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005425 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5426 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005427
Chad Dupuisf73cb692014-02-26 04:15:06 -05005428 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005429 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005430 return QLA_FUNCTION_FAILED;
5431 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5432 mcp->out_mb = MBX_0;
5433 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5434 mcp->tov = MBX_TOV_SECONDS;
5435 mcp->flags = 0;
5436
5437 rval = qla2x00_mailbox_command(vha, mcp);
5438
5439 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005440 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5441 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005442 } else {
5443 /* Copy all bits to preserve original value */
5444 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5445
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005446 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5447 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005448 }
5449 return rval;
5450}
5451
5452int
5453qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5454{
5455 int rval;
5456 mbx_cmd_t mc;
5457 mbx_cmd_t *mcp = &mc;
5458
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005459 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5460 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005461
5462 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5463 /* Copy all bits to preserve original setting */
5464 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5465 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5466 mcp->in_mb = MBX_0;
5467 mcp->tov = MBX_TOV_SECONDS;
5468 mcp->flags = 0;
5469 rval = qla2x00_mailbox_command(vha, mcp);
5470
5471 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005472 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5473 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005474 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005475 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5476 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005477
5478 return rval;
5479}
5480
5481
5482int
Sarang Radke09ff7012010-03-19 17:03:59 -07005483qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5484 uint16_t *mb)
5485{
5486 int rval;
5487 mbx_cmd_t mc;
5488 mbx_cmd_t *mcp = &mc;
5489 struct qla_hw_data *ha = vha->hw;
5490
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005491 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5492 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005493
Sarang Radke09ff7012010-03-19 17:03:59 -07005494 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5495 return QLA_FUNCTION_FAILED;
5496
Sarang Radke09ff7012010-03-19 17:03:59 -07005497 mcp->mb[0] = MBC_PORT_PARAMS;
5498 mcp->mb[1] = loop_id;
5499 if (ha->flags.fcp_prio_enabled)
5500 mcp->mb[2] = BIT_1;
5501 else
5502 mcp->mb[2] = BIT_2;
5503 mcp->mb[4] = priority & 0xf;
5504 mcp->mb[9] = vha->vp_idx;
5505 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5506 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5507 mcp->tov = 30;
5508 mcp->flags = 0;
5509 rval = qla2x00_mailbox_command(vha, mcp);
5510 if (mb != NULL) {
5511 mb[0] = mcp->mb[0];
5512 mb[1] = mcp->mb[1];
5513 mb[3] = mcp->mb[3];
5514 mb[4] = mcp->mb[4];
5515 }
5516
5517 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005518 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005519 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005520 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5521 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005522 }
5523
5524 return rval;
5525}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005526
5527int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005528qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005529{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005530 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005531 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005532 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005533
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005534 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5535 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5536 "Thermal not supported by this card.\n");
5537 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005538 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005539
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005540 if (IS_QLA25XX(ha)) {
5541 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5542 ha->pdev->subsystem_device == 0x0175) {
5543 rval = qla2x00_read_sfp(vha, 0, &byte,
5544 0x98, 0x1, 1, BIT_13|BIT_0);
5545 *temp = byte;
5546 return rval;
5547 }
5548 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5549 ha->pdev->subsystem_device == 0x338e) {
5550 rval = qla2x00_read_sfp(vha, 0, &byte,
5551 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5552 *temp = byte;
5553 return rval;
5554 }
5555 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5556 "Thermal not supported by this card.\n");
5557 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005558 }
5559
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005560 if (IS_QLA82XX(ha)) {
5561 *temp = qla82xx_read_temperature(vha);
5562 rval = QLA_SUCCESS;
5563 return rval;
5564 } else if (IS_QLA8044(ha)) {
5565 *temp = qla8044_read_temperature(vha);
5566 rval = QLA_SUCCESS;
5567 return rval;
5568 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005569
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005570 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005571 return rval;
5572}
5573
5574int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005575qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5576{
5577 int rval;
5578 struct qla_hw_data *ha = vha->hw;
5579 mbx_cmd_t mc;
5580 mbx_cmd_t *mcp = &mc;
5581
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005582 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5583 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005584
Giridhar Malavalia9083012010-04-12 17:59:55 -07005585 if (!IS_FWI2_CAPABLE(ha))
5586 return QLA_FUNCTION_FAILED;
5587
Giridhar Malavalia9083012010-04-12 17:59:55 -07005588 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005589 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005590 mcp->mb[1] = 1;
5591
5592 mcp->out_mb = MBX_1|MBX_0;
5593 mcp->in_mb = MBX_0;
5594 mcp->tov = 30;
5595 mcp->flags = 0;
5596
5597 rval = qla2x00_mailbox_command(vha, mcp);
5598 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005599 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5600 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005601 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005602 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5603 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005604 }
5605
5606 return rval;
5607}
5608
5609int
5610qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5611{
5612 int rval;
5613 struct qla_hw_data *ha = vha->hw;
5614 mbx_cmd_t mc;
5615 mbx_cmd_t *mcp = &mc;
5616
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005617 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5618 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005619
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005620 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005621 return QLA_FUNCTION_FAILED;
5622
Giridhar Malavalia9083012010-04-12 17:59:55 -07005623 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005624 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005625 mcp->mb[1] = 0;
5626
5627 mcp->out_mb = MBX_1|MBX_0;
5628 mcp->in_mb = MBX_0;
5629 mcp->tov = 30;
5630 mcp->flags = 0;
5631
5632 rval = qla2x00_mailbox_command(vha, mcp);
5633 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005634 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5635 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005636 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005637 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5638 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005639 }
5640
5641 return rval;
5642}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005643
5644int
5645qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5646{
5647 struct qla_hw_data *ha = vha->hw;
5648 mbx_cmd_t mc;
5649 mbx_cmd_t *mcp = &mc;
5650 int rval = QLA_FUNCTION_FAILED;
5651
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005652 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5653 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005654
5655 memset(mcp->mb, 0 , sizeof(mcp->mb));
5656 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5657 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5658 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5659 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5660
5661 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5662 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5663 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5664
5665 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5666 mcp->tov = MBX_TOV_SECONDS;
5667 rval = qla2x00_mailbox_command(vha, mcp);
5668
5669 /* Always copy back return mailbox values. */
5670 if (rval != QLA_SUCCESS) {
5671 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5672 "mailbox command FAILED=0x%x, subcode=%x.\n",
5673 (mcp->mb[1] << 16) | mcp->mb[0],
5674 (mcp->mb[3] << 16) | mcp->mb[2]);
5675 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5677 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005678 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5679 if (!ha->md_template_size) {
5680 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5681 "Null template size obtained.\n");
5682 rval = QLA_FUNCTION_FAILED;
5683 }
5684 }
5685 return rval;
5686}
5687
5688int
5689qla82xx_md_get_template(scsi_qla_host_t *vha)
5690{
5691 struct qla_hw_data *ha = vha->hw;
5692 mbx_cmd_t mc;
5693 mbx_cmd_t *mcp = &mc;
5694 int rval = QLA_FUNCTION_FAILED;
5695
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005696 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5697 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005698
5699 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5700 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5701 if (!ha->md_tmplt_hdr) {
5702 ql_log(ql_log_warn, vha, 0x1124,
5703 "Unable to allocate memory for Minidump template.\n");
5704 return rval;
5705 }
5706
5707 memset(mcp->mb, 0 , sizeof(mcp->mb));
5708 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5709 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5710 mcp->mb[2] = LSW(RQST_TMPLT);
5711 mcp->mb[3] = MSW(RQST_TMPLT);
5712 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5713 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5714 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5715 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5716 mcp->mb[8] = LSW(ha->md_template_size);
5717 mcp->mb[9] = MSW(ha->md_template_size);
5718
5719 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5720 mcp->tov = MBX_TOV_SECONDS;
5721 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5722 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5723 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5724 rval = qla2x00_mailbox_command(vha, mcp);
5725
5726 if (rval != QLA_SUCCESS) {
5727 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5728 "mailbox command FAILED=0x%x, subcode=%x.\n",
5729 ((mcp->mb[1] << 16) | mcp->mb[0]),
5730 ((mcp->mb[3] << 16) | mcp->mb[2]));
5731 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005732 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5733 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005734 return rval;
5735}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005736
5737int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005738qla8044_md_get_template(scsi_qla_host_t *vha)
5739{
5740 struct qla_hw_data *ha = vha->hw;
5741 mbx_cmd_t mc;
5742 mbx_cmd_t *mcp = &mc;
5743 int rval = QLA_FUNCTION_FAILED;
5744 int offset = 0, size = MINIDUMP_SIZE_36K;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07005745
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005746 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5747 "Entered %s.\n", __func__);
5748
5749 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5750 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5751 if (!ha->md_tmplt_hdr) {
5752 ql_log(ql_log_warn, vha, 0xb11b,
5753 "Unable to allocate memory for Minidump template.\n");
5754 return rval;
5755 }
5756
5757 memset(mcp->mb, 0 , sizeof(mcp->mb));
5758 while (offset < ha->md_template_size) {
5759 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5760 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5761 mcp->mb[2] = LSW(RQST_TMPLT);
5762 mcp->mb[3] = MSW(RQST_TMPLT);
5763 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5764 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5765 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5766 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5767 mcp->mb[8] = LSW(size);
5768 mcp->mb[9] = MSW(size);
5769 mcp->mb[10] = offset & 0x0000FFFF;
5770 mcp->mb[11] = offset & 0xFFFF0000;
5771 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5772 mcp->tov = MBX_TOV_SECONDS;
5773 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5774 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5775 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5776 rval = qla2x00_mailbox_command(vha, mcp);
5777
5778 if (rval != QLA_SUCCESS) {
5779 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5780 "mailbox command FAILED=0x%x, subcode=%x.\n",
5781 ((mcp->mb[1] << 16) | mcp->mb[0]),
5782 ((mcp->mb[3] << 16) | mcp->mb[2]));
5783 return rval;
5784 } else
5785 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5786 "Done %s.\n", __func__);
5787 offset = offset + size;
5788 }
5789 return rval;
5790}
5791
5792int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005793qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5794{
5795 int rval;
5796 struct qla_hw_data *ha = vha->hw;
5797 mbx_cmd_t mc;
5798 mbx_cmd_t *mcp = &mc;
5799
5800 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5801 return QLA_FUNCTION_FAILED;
5802
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005803 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5804 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005805
5806 memset(mcp, 0, sizeof(mbx_cmd_t));
5807 mcp->mb[0] = MBC_SET_LED_CONFIG;
5808 mcp->mb[1] = led_cfg[0];
5809 mcp->mb[2] = led_cfg[1];
5810 if (IS_QLA8031(ha)) {
5811 mcp->mb[3] = led_cfg[2];
5812 mcp->mb[4] = led_cfg[3];
5813 mcp->mb[5] = led_cfg[4];
5814 mcp->mb[6] = led_cfg[5];
5815 }
5816
5817 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5818 if (IS_QLA8031(ha))
5819 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5820 mcp->in_mb = MBX_0;
5821 mcp->tov = 30;
5822 mcp->flags = 0;
5823
5824 rval = qla2x00_mailbox_command(vha, mcp);
5825 if (rval != QLA_SUCCESS) {
5826 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5827 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5828 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5830 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005831 }
5832
5833 return rval;
5834}
5835
5836int
5837qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5838{
5839 int rval;
5840 struct qla_hw_data *ha = vha->hw;
5841 mbx_cmd_t mc;
5842 mbx_cmd_t *mcp = &mc;
5843
5844 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5845 return QLA_FUNCTION_FAILED;
5846
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005847 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5848 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005849
5850 memset(mcp, 0, sizeof(mbx_cmd_t));
5851 mcp->mb[0] = MBC_GET_LED_CONFIG;
5852
5853 mcp->out_mb = MBX_0;
5854 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5855 if (IS_QLA8031(ha))
5856 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5857 mcp->tov = 30;
5858 mcp->flags = 0;
5859
5860 rval = qla2x00_mailbox_command(vha, mcp);
5861 if (rval != QLA_SUCCESS) {
5862 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5863 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5864 } else {
5865 led_cfg[0] = mcp->mb[1];
5866 led_cfg[1] = mcp->mb[2];
5867 if (IS_QLA8031(ha)) {
5868 led_cfg[2] = mcp->mb[3];
5869 led_cfg[3] = mcp->mb[4];
5870 led_cfg[4] = mcp->mb[5];
5871 led_cfg[5] = mcp->mb[6];
5872 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005873 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5874 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005875 }
5876
5877 return rval;
5878}
5879
5880int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005881qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5882{
5883 int rval;
5884 struct qla_hw_data *ha = vha->hw;
5885 mbx_cmd_t mc;
5886 mbx_cmd_t *mcp = &mc;
5887
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005888 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005889 return QLA_FUNCTION_FAILED;
5890
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005891 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005892 "Entered %s.\n", __func__);
5893
5894 memset(mcp, 0, sizeof(mbx_cmd_t));
5895 mcp->mb[0] = MBC_SET_LED_CONFIG;
5896 if (enable)
5897 mcp->mb[7] = 0xE;
5898 else
5899 mcp->mb[7] = 0xD;
5900
5901 mcp->out_mb = MBX_7|MBX_0;
5902 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005903 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005904 mcp->flags = 0;
5905
5906 rval = qla2x00_mailbox_command(vha, mcp);
5907 if (rval != QLA_SUCCESS) {
5908 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5909 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5910 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005911 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005912 "Done %s.\n", __func__);
5913 }
5914
5915 return rval;
5916}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005917
5918int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005919qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005920{
5921 int rval;
5922 struct qla_hw_data *ha = vha->hw;
5923 mbx_cmd_t mc;
5924 mbx_cmd_t *mcp = &mc;
5925
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005926 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005927 return QLA_FUNCTION_FAILED;
5928
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005929 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5930 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005931
5932 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5933 mcp->mb[1] = LSW(reg);
5934 mcp->mb[2] = MSW(reg);
5935 mcp->mb[3] = LSW(data);
5936 mcp->mb[4] = MSW(data);
5937 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5938
5939 mcp->in_mb = MBX_1|MBX_0;
5940 mcp->tov = MBX_TOV_SECONDS;
5941 mcp->flags = 0;
5942 rval = qla2x00_mailbox_command(vha, mcp);
5943
5944 if (rval != QLA_SUCCESS) {
5945 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5946 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5947 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005948 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005949 "Done %s.\n", __func__);
5950 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005951
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005952 return rval;
5953}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005954
5955int
5956qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5957{
5958 int rval;
5959 struct qla_hw_data *ha = vha->hw;
5960 mbx_cmd_t mc;
5961 mbx_cmd_t *mcp = &mc;
5962
5963 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005964 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005965 "Implicit LOGO Unsupported.\n");
5966 return QLA_FUNCTION_FAILED;
5967 }
5968
5969
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005970 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5971 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005972
5973 /* Perform Implicit LOGO. */
5974 mcp->mb[0] = MBC_PORT_LOGOUT;
5975 mcp->mb[1] = fcport->loop_id;
5976 mcp->mb[10] = BIT_15;
5977 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5978 mcp->in_mb = MBX_0;
5979 mcp->tov = MBX_TOV_SECONDS;
5980 mcp->flags = 0;
5981 rval = qla2x00_mailbox_command(vha, mcp);
5982 if (rval != QLA_SUCCESS)
5983 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5984 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5985 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005986 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5987 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005988
5989 return rval;
5990}
5991
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005992int
5993qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5994{
5995 int rval;
5996 mbx_cmd_t mc;
5997 mbx_cmd_t *mcp = &mc;
5998 struct qla_hw_data *ha = vha->hw;
5999 unsigned long retry_max_time = jiffies + (2 * HZ);
6000
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006001 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006002 return QLA_FUNCTION_FAILED;
6003
6004 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
6005
6006retry_rd_reg:
6007 mcp->mb[0] = MBC_READ_REMOTE_REG;
6008 mcp->mb[1] = LSW(reg);
6009 mcp->mb[2] = MSW(reg);
6010 mcp->out_mb = MBX_2|MBX_1|MBX_0;
6011 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
6012 mcp->tov = MBX_TOV_SECONDS;
6013 mcp->flags = 0;
6014 rval = qla2x00_mailbox_command(vha, mcp);
6015
6016 if (rval != QLA_SUCCESS) {
6017 ql_dbg(ql_dbg_mbx, vha, 0x114c,
6018 "Failed=%x mb[0]=%x mb[1]=%x.\n",
6019 rval, mcp->mb[0], mcp->mb[1]);
6020 } else {
6021 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
6022 if (*data == QLA8XXX_BAD_VALUE) {
6023 /*
6024 * During soft-reset CAMRAM register reads might
6025 * return 0xbad0bad0. So retry for MAX of 2 sec
6026 * while reading camram registers.
6027 */
6028 if (time_after(jiffies, retry_max_time)) {
6029 ql_dbg(ql_dbg_mbx, vha, 0x1141,
6030 "Failure to read CAMRAM register. "
6031 "data=0x%x.\n", *data);
6032 return QLA_FUNCTION_FAILED;
6033 }
6034 msleep(100);
6035 goto retry_rd_reg;
6036 }
6037 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
6038 }
6039
6040 return rval;
6041}
6042
6043int
6044qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
6045{
6046 int rval;
6047 mbx_cmd_t mc;
6048 mbx_cmd_t *mcp = &mc;
6049 struct qla_hw_data *ha = vha->hw;
6050
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006051 if (!IS_QLA83XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006052 return QLA_FUNCTION_FAILED;
6053
6054 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
6055
6056 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
6057 mcp->out_mb = MBX_0;
6058 mcp->in_mb = MBX_1|MBX_0;
6059 mcp->tov = MBX_TOV_SECONDS;
6060 mcp->flags = 0;
6061 rval = qla2x00_mailbox_command(vha, mcp);
6062
6063 if (rval != QLA_SUCCESS) {
6064 ql_dbg(ql_dbg_mbx, vha, 0x1144,
6065 "Failed=%x mb[0]=%x mb[1]=%x.\n",
6066 rval, mcp->mb[0], mcp->mb[1]);
6067 ha->isp_ops->fw_dump(vha, 0);
6068 } else {
6069 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
6070 }
6071
6072 return rval;
6073}
6074
6075int
6076qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
6077 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
6078{
6079 int rval;
6080 mbx_cmd_t mc;
6081 mbx_cmd_t *mcp = &mc;
6082 uint8_t subcode = (uint8_t)options;
6083 struct qla_hw_data *ha = vha->hw;
6084
6085 if (!IS_QLA8031(ha))
6086 return QLA_FUNCTION_FAILED;
6087
6088 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
6089
6090 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
6091 mcp->mb[1] = options;
6092 mcp->out_mb = MBX_1|MBX_0;
6093 if (subcode & BIT_2) {
6094 mcp->mb[2] = LSW(start_addr);
6095 mcp->mb[3] = MSW(start_addr);
6096 mcp->mb[4] = LSW(end_addr);
6097 mcp->mb[5] = MSW(end_addr);
6098 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
6099 }
6100 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6101 if (!(subcode & (BIT_2 | BIT_5)))
6102 mcp->in_mb |= MBX_4|MBX_3;
6103 mcp->tov = MBX_TOV_SECONDS;
6104 mcp->flags = 0;
6105 rval = qla2x00_mailbox_command(vha, mcp);
6106
6107 if (rval != QLA_SUCCESS) {
6108 ql_dbg(ql_dbg_mbx, vha, 0x1147,
6109 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
6110 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
6111 mcp->mb[4]);
6112 ha->isp_ops->fw_dump(vha, 0);
6113 } else {
6114 if (subcode & BIT_5)
6115 *sector_size = mcp->mb[1];
6116 else if (subcode & (BIT_6 | BIT_7)) {
6117 ql_dbg(ql_dbg_mbx, vha, 0x1148,
6118 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6119 } else if (subcode & (BIT_3 | BIT_4)) {
6120 ql_dbg(ql_dbg_mbx, vha, 0x1149,
6121 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6122 }
6123 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
6124 }
6125
6126 return rval;
6127}
Saurav Kashyap81178772012-08-22 14:21:04 -04006128
6129int
6130qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
6131 uint32_t size)
6132{
6133 int rval;
6134 mbx_cmd_t mc;
6135 mbx_cmd_t *mcp = &mc;
6136
6137 if (!IS_MCTP_CAPABLE(vha->hw))
6138 return QLA_FUNCTION_FAILED;
6139
6140 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
6141 "Entered %s.\n", __func__);
6142
6143 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
6144 mcp->mb[1] = LSW(addr);
6145 mcp->mb[2] = MSW(req_dma);
6146 mcp->mb[3] = LSW(req_dma);
6147 mcp->mb[4] = MSW(size);
6148 mcp->mb[5] = LSW(size);
6149 mcp->mb[6] = MSW(MSD(req_dma));
6150 mcp->mb[7] = LSW(MSD(req_dma));
6151 mcp->mb[8] = MSW(addr);
6152 /* Setting RAM ID to valid */
6153 mcp->mb[10] |= BIT_7;
6154 /* For MCTP RAM ID is 0x40 */
6155 mcp->mb[10] |= 0x40;
6156
6157 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
6158 MBX_0;
6159
6160 mcp->in_mb = MBX_0;
6161 mcp->tov = MBX_TOV_SECONDS;
6162 mcp->flags = 0;
6163 rval = qla2x00_mailbox_command(vha, mcp);
6164
6165 if (rval != QLA_SUCCESS) {
6166 ql_dbg(ql_dbg_mbx, vha, 0x114e,
6167 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6168 } else {
6169 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
6170 "Done %s.\n", __func__);
6171 }
6172
6173 return rval;
6174}
Joe Carnuccioec891462016-07-06 11:14:26 -04006175
6176int
6177qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
6178 void *dd_buf, uint size, uint options)
6179{
6180 int rval;
6181 mbx_cmd_t mc;
6182 mbx_cmd_t *mcp = &mc;
6183 dma_addr_t dd_dma;
6184
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006185 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
6186 !IS_QLA28XX(vha->hw))
Joe Carnuccioec891462016-07-06 11:14:26 -04006187 return QLA_FUNCTION_FAILED;
6188
Quinn Tran83548fe2017-06-02 09:12:01 -07006189 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04006190 "Entered %s.\n", __func__);
6191
Joe Carnuccioec891462016-07-06 11:14:26 -04006192 dd_dma = dma_map_single(&vha->hw->pdev->dev,
6193 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08006194 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04006195 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
6196 return QLA_MEMORY_ALLOC_FAILED;
6197 }
6198
6199 memset(dd_buf, 0, size);
6200
6201 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
6202 mcp->mb[1] = options;
6203 mcp->mb[2] = MSW(LSD(dd_dma));
6204 mcp->mb[3] = LSW(LSD(dd_dma));
6205 mcp->mb[6] = MSW(MSD(dd_dma));
6206 mcp->mb[7] = LSW(MSD(dd_dma));
6207 mcp->mb[8] = size;
6208 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
6209 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
6210 mcp->buf_size = size;
6211 mcp->flags = MBX_DMA_IN;
6212 mcp->tov = MBX_TOV_SECONDS * 4;
6213 rval = qla2x00_mailbox_command(vha, mcp);
6214
6215 if (rval != QLA_SUCCESS) {
6216 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
6217 } else {
6218 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
6219 "Done %s.\n", __func__);
6220 }
6221
6222 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
6223 size, DMA_FROM_DEVICE);
6224
6225 return rval;
6226}
Quinn Tran15f30a52017-03-15 09:48:52 -07006227
Bart Van Assche6c18a432019-08-08 20:02:04 -07006228static void qla2x00_async_mb_sp_done(srb_t *sp, int res)
Quinn Tran15f30a52017-03-15 09:48:52 -07006229{
Quinn Tran15f30a52017-03-15 09:48:52 -07006230 sp->u.iocb_cmd.u.mbx.rc = res;
6231
6232 complete(&sp->u.iocb_cmd.u.mbx.comp);
6233 /* don't free sp here. Let the caller do the free */
6234}
6235
6236/*
6237 * This mailbox uses the iocb interface to send MB command.
6238 * This allows non-critial (non chip setup) command to go
6239 * out in parrallel.
6240 */
6241int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
6242{
6243 int rval = QLA_FUNCTION_FAILED;
6244 srb_t *sp;
6245 struct srb_iocb *c;
6246
6247 if (!vha->hw->flags.fw_started)
6248 goto done;
6249
6250 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
6251 if (!sp)
6252 goto done;
6253
6254 sp->type = SRB_MB_IOCB;
6255 sp->name = mb_to_str(mcp->mb[0]);
6256
Quinn Tran15f30a52017-03-15 09:48:52 -07006257 c = &sp->u.iocb_cmd;
6258 c->timeout = qla2x00_async_iocb_timeout;
6259 init_completion(&c->u.mbx.comp);
6260
Ben Hutchingse74e7d92018-03-20 21:36:14 +00006261 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
6262
6263 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
6264
Quinn Tran15f30a52017-03-15 09:48:52 -07006265 sp->done = qla2x00_async_mb_sp_done;
6266
6267 rval = qla2x00_start_sp(sp);
6268 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006269 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07006270 "%s: %s Failed submission. %x.\n",
6271 __func__, sp->name, rval);
6272 goto done_free_sp;
6273 }
6274
Quinn Tran83548fe2017-06-02 09:12:01 -07006275 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006276 sp->name, sp->handle);
6277
6278 wait_for_completion(&c->u.mbx.comp);
6279 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
6280
6281 rval = c->u.mbx.rc;
6282 switch (rval) {
6283 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07006284 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006285 __func__, sp->name, rval);
6286 break;
6287 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07006288 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006289 __func__, sp->name);
6290 sp->free(sp);
6291 break;
6292 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07006293 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006294 __func__, sp->name, rval);
6295 sp->free(sp);
6296 break;
6297 }
6298
6299 return rval;
6300
6301done_free_sp:
6302 sp->free(sp);
6303done:
6304 return rval;
6305}
6306
6307/*
6308 * qla24xx_gpdb_wait
6309 * NOTE: Do not call this routine from DPC thread
6310 */
6311int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
6312{
6313 int rval = QLA_FUNCTION_FAILED;
6314 dma_addr_t pd_dma;
6315 struct port_database_24xx *pd;
6316 struct qla_hw_data *ha = vha->hw;
6317 mbx_cmd_t mc;
6318
6319 if (!vha->hw->flags.fw_started)
6320 goto done;
6321
Thomas Meyer08eb7f42017-09-21 08:15:26 +02006322 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran15f30a52017-03-15 09:48:52 -07006323 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006324 ql_log(ql_log_warn, vha, 0xd047,
6325 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07006326 goto done_free_sp;
6327 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006328
6329 memset(&mc, 0, sizeof(mc));
6330 mc.mb[0] = MBC_GET_PORT_DATABASE;
6331 mc.mb[1] = cpu_to_le16(fcport->loop_id);
6332 mc.mb[2] = MSW(pd_dma);
6333 mc.mb[3] = LSW(pd_dma);
6334 mc.mb[6] = MSW(MSD(pd_dma));
6335 mc.mb[7] = LSW(MSD(pd_dma));
6336 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6337 mc.mb[10] = cpu_to_le16((uint16_t)opt);
6338
6339 rval = qla24xx_send_mb_cmd(vha, &mc);
6340 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006341 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07006342 "%s: %8phC fail\n", __func__, fcport->port_name);
6343 goto done_free_sp;
6344 }
6345
6346 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
6347
Quinn Tran83548fe2017-06-02 09:12:01 -07006348 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006349 __func__, fcport->port_name);
6350
6351done_free_sp:
6352 if (pd)
6353 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
6354done:
6355 return rval;
6356}
6357
6358int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
6359 struct port_database_24xx *pd)
6360{
6361 int rval = QLA_SUCCESS;
6362 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006363 u8 current_login_state, last_login_state;
6364
6365 if (fcport->fc4f_nvme) {
6366 current_login_state = pd->current_login_state >> 4;
6367 last_login_state = pd->last_login_state >> 4;
6368 } else {
6369 current_login_state = pd->current_login_state & 0xf;
6370 last_login_state = pd->last_login_state & 0xf;
6371 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006372
6373 /* Check for logged in state. */
Quinn Tran23c64552017-12-04 14:45:08 -08006374 if (current_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006375 ql_dbg(ql_dbg_mbx, vha, 0x119a,
6376 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006377 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006378 rval = QLA_FUNCTION_FAILED;
6379 goto gpd_error_out;
6380 }
6381
6382 if (fcport->loop_id == FC_NO_LOOP_ID ||
6383 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6384 memcmp(fcport->port_name, pd->port_name, 8))) {
6385 /* We lost the device mid way. */
6386 rval = QLA_NOT_LOGGED_IN;
6387 goto gpd_error_out;
6388 }
6389
6390 /* Names are little-endian. */
6391 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6392 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6393
6394 /* Get port_id of device. */
6395 fcport->d_id.b.domain = pd->port_id[0];
6396 fcport->d_id.b.area = pd->port_id[1];
6397 fcport->d_id.b.al_pa = pd->port_id[2];
6398 fcport->d_id.b.rsvd_1 = 0;
6399
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006400 if (fcport->fc4f_nvme) {
Hannes Reineckea6a6d052019-04-10 16:16:19 +02006401 fcport->port_type = 0;
6402 if ((pd->prli_svc_param_word_3[0] & BIT_5) == 0)
6403 fcport->port_type |= FCT_NVME_INITIATOR;
6404 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6405 fcport->port_type |= FCT_NVME_TARGET;
6406 if ((pd->prli_svc_param_word_3[0] & BIT_3) == 0)
6407 fcport->port_type |= FCT_NVME_DISCOVERY;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006408 } else {
6409 /* If not target must be initiator or unknown type. */
6410 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6411 fcport->port_type = FCT_INITIATOR;
6412 else
6413 fcport->port_type = FCT_TARGET;
6414 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006415 /* Passback COS information. */
6416 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6417 FC_COS_CLASS2 : FC_COS_CLASS3;
6418
6419 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6420 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6421 fcport->conf_compl_supported = 1;
6422 }
6423
6424gpd_error_out:
6425 return rval;
6426}
6427
6428/*
6429 * qla24xx_gidlist__wait
6430 * NOTE: don't call this routine from DPC thread.
6431 */
6432int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6433 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6434{
6435 int rval = QLA_FUNCTION_FAILED;
6436 mbx_cmd_t mc;
6437
6438 if (!vha->hw->flags.fw_started)
6439 goto done;
6440
6441 memset(&mc, 0, sizeof(mc));
6442 mc.mb[0] = MBC_GET_ID_LIST;
6443 mc.mb[2] = MSW(id_list_dma);
6444 mc.mb[3] = LSW(id_list_dma);
6445 mc.mb[6] = MSW(MSD(id_list_dma));
6446 mc.mb[7] = LSW(MSD(id_list_dma));
6447 mc.mb[8] = 0;
6448 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6449
6450 rval = qla24xx_send_mb_cmd(vha, &mc);
6451 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006452 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6453 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006454 } else {
6455 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006456 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6457 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006458 }
6459done:
6460 return rval;
6461}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006462
6463int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6464{
6465 int rval;
6466 mbx_cmd_t mc;
6467 mbx_cmd_t *mcp = &mc;
6468
6469 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6470 "Entered %s\n", __func__);
6471
6472 memset(mcp->mb, 0 , sizeof(mcp->mb));
6473 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6474 mcp->mb[1] = cpu_to_le16(1);
6475 mcp->mb[2] = cpu_to_le16(value);
6476 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6477 mcp->in_mb = MBX_2 | MBX_0;
6478 mcp->tov = MBX_TOV_SECONDS;
6479 mcp->flags = 0;
6480
6481 rval = qla2x00_mailbox_command(vha, mcp);
6482
6483 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6484 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6485
6486 return rval;
6487}
6488
6489int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6490{
6491 int rval;
6492 mbx_cmd_t mc;
6493 mbx_cmd_t *mcp = &mc;
6494
6495 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6496 "Entered %s\n", __func__);
6497
6498 memset(mcp->mb, 0, sizeof(mcp->mb));
6499 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6500 mcp->mb[1] = cpu_to_le16(0);
6501 mcp->out_mb = MBX_1 | MBX_0;
6502 mcp->in_mb = MBX_2 | MBX_0;
6503 mcp->tov = MBX_TOV_SECONDS;
6504 mcp->flags = 0;
6505
6506 rval = qla2x00_mailbox_command(vha, mcp);
6507 if (rval == QLA_SUCCESS)
6508 *value = mc.mb[2];
6509
6510 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6511 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6512
6513 return rval;
6514}
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006515
6516int
6517qla2x00_read_sfp_dev(struct scsi_qla_host *vha, char *buf, int count)
6518{
6519 struct qla_hw_data *ha = vha->hw;
6520 uint16_t iter, addr, offset;
6521 dma_addr_t phys_addr;
6522 int rval, c;
6523 u8 *sfp_data;
6524
6525 memset(ha->sfp_data, 0, SFP_DEV_SIZE);
6526 addr = 0xa0;
6527 phys_addr = ha->sfp_data_dma;
6528 sfp_data = ha->sfp_data;
6529 offset = c = 0;
6530
6531 for (iter = 0; iter < SFP_DEV_SIZE / SFP_BLOCK_SIZE; iter++) {
6532 if (iter == 4) {
6533 /* Skip to next device address. */
6534 addr = 0xa2;
6535 offset = 0;
6536 }
6537
6538 rval = qla2x00_read_sfp(vha, phys_addr, sfp_data,
6539 addr, offset, SFP_BLOCK_SIZE, BIT_1);
6540 if (rval != QLA_SUCCESS) {
6541 ql_log(ql_log_warn, vha, 0x706d,
6542 "Unable to read SFP data (%x/%x/%x).\n", rval,
6543 addr, offset);
6544
6545 return rval;
6546 }
6547
6548 if (buf && (c < count)) {
6549 u16 sz;
6550
6551 if ((count - c) >= SFP_BLOCK_SIZE)
6552 sz = SFP_BLOCK_SIZE;
6553 else
6554 sz = count - c;
6555
6556 memcpy(buf, sfp_data, sz);
6557 buf += SFP_BLOCK_SIZE;
6558 c += sz;
6559 }
6560 phys_addr += SFP_BLOCK_SIZE;
6561 sfp_data += SFP_BLOCK_SIZE;
6562 offset += SFP_BLOCK_SIZE;
6563 }
6564
6565 return rval;
6566}
Quinn Tran94d83e32017-12-28 12:33:23 -08006567
6568int qla24xx_res_count_wait(struct scsi_qla_host *vha,
6569 uint16_t *out_mb, int out_mb_sz)
6570{
6571 int rval = QLA_FUNCTION_FAILED;
6572 mbx_cmd_t mc;
6573
6574 if (!vha->hw->flags.fw_started)
6575 goto done;
6576
6577 memset(&mc, 0, sizeof(mc));
6578 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
6579
6580 rval = qla24xx_send_mb_cmd(vha, &mc);
6581 if (rval != QLA_SUCCESS) {
6582 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6583 "%s: fail\n", __func__);
6584 } else {
6585 if (out_mb_sz <= SIZEOF_IOCB_MB_REG)
6586 memcpy(out_mb, mc.mb, out_mb_sz);
6587 else
6588 memcpy(out_mb, mc.mb, SIZEOF_IOCB_MB_REG);
6589
6590 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6591 "%s: done\n", __func__);
6592 }
6593done:
6594 return rval;
6595}
Michael Hernandez3f006ac2019-03-12 11:08:22 -07006596
6597int qla28xx_secure_flash_update(scsi_qla_host_t *vha, uint16_t opts,
6598 uint16_t region, uint32_t len, dma_addr_t sfub_dma_addr,
6599 uint32_t sfub_len)
6600{
6601 int rval;
6602 mbx_cmd_t mc;
6603 mbx_cmd_t *mcp = &mc;
6604
6605 mcp->mb[0] = MBC_SECURE_FLASH_UPDATE;
6606 mcp->mb[1] = opts;
6607 mcp->mb[2] = region;
6608 mcp->mb[3] = MSW(len);
6609 mcp->mb[4] = LSW(len);
6610 mcp->mb[5] = MSW(sfub_dma_addr);
6611 mcp->mb[6] = LSW(sfub_dma_addr);
6612 mcp->mb[7] = MSW(MSD(sfub_dma_addr));
6613 mcp->mb[8] = LSW(MSD(sfub_dma_addr));
6614 mcp->mb[9] = sfub_len;
6615 mcp->out_mb =
6616 MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6617 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6618 mcp->tov = MBX_TOV_SECONDS;
6619 mcp->flags = 0;
6620 rval = qla2x00_mailbox_command(vha, mcp);
6621
6622 if (rval != QLA_SUCCESS) {
6623 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s(%ld): failed rval 0x%x, %x %x %x",
6624 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1],
6625 mcp->mb[2]);
6626 }
6627
6628 return rval;
6629}
6630
6631int qla2xxx_write_remote_register(scsi_qla_host_t *vha, uint32_t addr,
6632 uint32_t data)
6633{
6634 int rval;
6635 mbx_cmd_t mc;
6636 mbx_cmd_t *mcp = &mc;
6637
6638 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
6639 "Entered %s.\n", __func__);
6640
6641 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
6642 mcp->mb[1] = LSW(addr);
6643 mcp->mb[2] = MSW(addr);
6644 mcp->mb[3] = LSW(data);
6645 mcp->mb[4] = MSW(data);
6646 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6647 mcp->in_mb = MBX_1|MBX_0;
6648 mcp->tov = MBX_TOV_SECONDS;
6649 mcp->flags = 0;
6650 rval = qla2x00_mailbox_command(vha, mcp);
6651
6652 if (rval != QLA_SUCCESS) {
6653 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
6654 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6655 } else {
6656 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
6657 "Done %s.\n", __func__);
6658 }
6659
6660 return rval;
6661}
6662
6663int qla2xxx_read_remote_register(scsi_qla_host_t *vha, uint32_t addr,
6664 uint32_t *data)
6665{
6666 int rval;
6667 mbx_cmd_t mc;
6668 mbx_cmd_t *mcp = &mc;
6669
6670 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
6671 "Entered %s.\n", __func__);
6672
6673 mcp->mb[0] = MBC_READ_REMOTE_REG;
6674 mcp->mb[1] = LSW(addr);
6675 mcp->mb[2] = MSW(addr);
6676 mcp->out_mb = MBX_2|MBX_1|MBX_0;
6677 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6678 mcp->tov = MBX_TOV_SECONDS;
6679 mcp->flags = 0;
6680 rval = qla2x00_mailbox_command(vha, mcp);
6681
6682 *data = (uint32_t)((((uint32_t)mcp->mb[4]) << 16) | mcp->mb[3]);
6683
6684 if (rval != QLA_SUCCESS) {
6685 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
6686 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6687 } else {
6688 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
6689 "Done %s.\n", __func__);
6690 }
6691
6692 return rval;
6693}