blob: 1cc6913f76c4745242b72cc7aa71e5edaae54519 [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;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700705 ha->flags.using_lr_setting = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500706 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700707 IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700708 if (ql2xautodetectsfp) {
709 if (ha->flags.detected_lr_sfp) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700710 mcp->mb[4] |=
711 qla25xx_set_sfp_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700712 ha->flags.using_lr_setting = 1;
713 }
714 } else {
715 struct nvram_81xx *nv = ha->nvram;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700716 /* set LR distance if specified in nvram */
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700717 if (nv->enhanced_features &
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700718 NEF_LR_DIST_ENABLE) {
719 mcp->mb[4] |=
720 qla25xx_set_nvr_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700721 ha->flags.using_lr_setting = 1;
722 }
723 }
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700724 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500725
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700726 if (ql2xnvmeenable && (IS_QLA27XX(ha) || IS_QLA28XX(ha)))
Duane Grigsbye84067d2017-06-21 13:48:43 -0700727 mcp->mb[4] |= NVME_ENABLE_FLAG;
728
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700729 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -0700730 struct nvram_81xx *nv = ha->nvram;
731 /* set minimum speed if specified in nvram */
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700732 if (nv->min_supported_speed >= 2 &&
733 nv->min_supported_speed <= 5) {
Sawan Chandak92d44082017-08-23 15:05:16 -0700734 mcp->mb[4] |= BIT_4;
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700735 mcp->mb[11] |= nv->min_supported_speed & 0xF;
Sawan Chandak92d44082017-08-23 15:05:16 -0700736 mcp->out_mb |= MBX_11;
737 mcp->in_mb |= BIT_5;
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700738 vha->min_supported_speed =
739 nv->min_supported_speed;
Sawan Chandak92d44082017-08-23 15:05:16 -0700740 }
741 }
742
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500743 if (ha->flags.exlogins_enabled)
744 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
745
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500746 if (ha->flags.exchoffld_enabled)
747 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
748
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700749 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700750 mcp->in_mb |= MBX_3 | MBX_2 | MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700751 } else {
752 mcp->mb[1] = LSW(risc_addr);
753 mcp->out_mb |= MBX_1;
754 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
755 mcp->mb[2] = 0;
756 mcp->out_mb |= MBX_2;
757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 }
759
Ravi Anandb93480e2008-04-03 13:13:25 -0700760 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800762 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700764 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700765 ql_dbg(ql_dbg_mbx, vha, 0x1026,
766 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700767 return rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700768 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700770 if (!IS_FWI2_CAPABLE(ha))
771 goto done;
772
773 ha->fw_ability_mask = mcp->mb[3] << 16 | mcp->mb[2];
774 ql_dbg(ql_dbg_mbx, vha, 0x119a,
775 "fw_ability_mask=%x.\n", ha->fw_ability_mask);
776 ql_dbg(ql_dbg_mbx, vha, 0x1027, "exchanges=%x.\n", mcp->mb[1]);
777 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
778 ha->max_supported_speed = mcp->mb[2] & (BIT_0|BIT_1);
779 ql_dbg(ql_dbg_mbx, vha, 0x119b, "max_supported_speed=%s.\n",
780 ha->max_supported_speed == 0 ? "16Gps" :
781 ha->max_supported_speed == 1 ? "32Gps" :
782 ha->max_supported_speed == 2 ? "64Gps" : "unknown");
783 if (vha->min_supported_speed) {
784 ha->min_supported_speed = mcp->mb[5] &
785 (BIT_0 | BIT_1 | BIT_2);
786 ql_dbg(ql_dbg_mbx, vha, 0x119c,
787 "min_supported_speed=%s.\n",
788 ha->min_supported_speed == 6 ? "64Gps" :
789 ha->min_supported_speed == 5 ? "32Gps" :
790 ha->min_supported_speed == 4 ? "16Gps" :
791 ha->min_supported_speed == 3 ? "8Gps" :
792 ha->min_supported_speed == 2 ? "4Gps" : "unknown");
793 }
794 }
795
796done:
797 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
798 "Done %s.\n", __func__);
799
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 return rval;
801}
802
803/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500804 * qla_get_exlogin_status
805 * Get extended login status
806 * uses the memory offload control/status Mailbox
807 *
808 * Input:
809 * ha: adapter state pointer.
810 * fwopt: firmware options
811 *
812 * Returns:
813 * qla2x00 local function status
814 *
815 * Context:
816 * Kernel context.
817 */
818#define FETCH_XLOGINS_STAT 0x8
819int
820qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
821 uint16_t *ex_logins_cnt)
822{
823 int rval;
824 mbx_cmd_t mc;
825 mbx_cmd_t *mcp = &mc;
826
827 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
828 "Entered %s\n", __func__);
829
830 memset(mcp->mb, 0 , sizeof(mcp->mb));
831 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
832 mcp->mb[1] = FETCH_XLOGINS_STAT;
833 mcp->out_mb = MBX_1|MBX_0;
834 mcp->in_mb = MBX_10|MBX_4|MBX_0;
835 mcp->tov = MBX_TOV_SECONDS;
836 mcp->flags = 0;
837
838 rval = qla2x00_mailbox_command(vha, mcp);
839 if (rval != QLA_SUCCESS) {
840 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
841 } else {
842 *buf_sz = mcp->mb[4];
843 *ex_logins_cnt = mcp->mb[10];
844
845 ql_log(ql_log_info, vha, 0x1190,
846 "buffer size 0x%x, exchange login count=%d\n",
847 mcp->mb[4], mcp->mb[10]);
848
849 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
850 "Done %s.\n", __func__);
851 }
852
853 return rval;
854}
855
856/*
857 * qla_set_exlogin_mem_cfg
858 * set extended login memory configuration
859 * Mbx needs to be issues before init_cb is set
860 *
861 * Input:
862 * ha: adapter state pointer.
863 * buffer: buffer pointer
864 * phys_addr: physical address of buffer
865 * size: size of buffer
866 * TARGET_QUEUE_LOCK must be released
867 * ADAPTER_STATE_LOCK must be release
868 *
869 * Returns:
870 * qla2x00 local funxtion status code.
871 *
872 * Context:
873 * Kernel context.
874 */
875#define CONFIG_XLOGINS_MEM 0x3
876int
877qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
878{
879 int rval;
880 mbx_cmd_t mc;
881 mbx_cmd_t *mcp = &mc;
882 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500883
884 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
885 "Entered %s.\n", __func__);
886
887 memset(mcp->mb, 0 , sizeof(mcp->mb));
888 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
889 mcp->mb[1] = CONFIG_XLOGINS_MEM;
890 mcp->mb[2] = MSW(phys_addr);
891 mcp->mb[3] = LSW(phys_addr);
892 mcp->mb[6] = MSW(MSD(phys_addr));
893 mcp->mb[7] = LSW(MSD(phys_addr));
894 mcp->mb[8] = MSW(ha->exlogin_size);
895 mcp->mb[9] = LSW(ha->exlogin_size);
896 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
897 mcp->in_mb = MBX_11|MBX_0;
898 mcp->tov = MBX_TOV_SECONDS;
899 mcp->flags = 0;
900 rval = qla2x00_mailbox_command(vha, mcp);
901 if (rval != QLA_SUCCESS) {
902 /*EMPTY*/
903 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
904 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500905 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
906 "Done %s.\n", __func__);
907 }
908
909 return rval;
910}
911
912/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500913 * qla_get_exchoffld_status
914 * Get exchange offload status
915 * uses the memory offload control/status Mailbox
916 *
917 * Input:
918 * ha: adapter state pointer.
919 * fwopt: firmware options
920 *
921 * Returns:
922 * qla2x00 local function status
923 *
924 * Context:
925 * Kernel context.
926 */
927#define FETCH_XCHOFFLD_STAT 0x2
928int
929qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
930 uint16_t *ex_logins_cnt)
931{
932 int rval;
933 mbx_cmd_t mc;
934 mbx_cmd_t *mcp = &mc;
935
936 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
937 "Entered %s\n", __func__);
938
939 memset(mcp->mb, 0 , sizeof(mcp->mb));
940 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
941 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
942 mcp->out_mb = MBX_1|MBX_0;
943 mcp->in_mb = MBX_10|MBX_4|MBX_0;
944 mcp->tov = MBX_TOV_SECONDS;
945 mcp->flags = 0;
946
947 rval = qla2x00_mailbox_command(vha, mcp);
948 if (rval != QLA_SUCCESS) {
949 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
950 } else {
951 *buf_sz = mcp->mb[4];
952 *ex_logins_cnt = mcp->mb[10];
953
954 ql_log(ql_log_info, vha, 0x118e,
955 "buffer size 0x%x, exchange offload count=%d\n",
956 mcp->mb[4], mcp->mb[10]);
957
958 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
959 "Done %s.\n", __func__);
960 }
961
962 return rval;
963}
964
965/*
966 * qla_set_exchoffld_mem_cfg
967 * Set exchange offload memory configuration
968 * Mbx needs to be issues before init_cb is set
969 *
970 * Input:
971 * ha: adapter state pointer.
972 * buffer: buffer pointer
973 * phys_addr: physical address of buffer
974 * size: size of buffer
975 * TARGET_QUEUE_LOCK must be released
976 * ADAPTER_STATE_LOCK must be release
977 *
978 * Returns:
979 * qla2x00 local funxtion status code.
980 *
981 * Context:
982 * Kernel context.
983 */
984#define CONFIG_XCHOFFLD_MEM 0x3
985int
Quinn Tran99e1b682017-06-02 09:12:03 -0700986qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500987{
988 int rval;
989 mbx_cmd_t mc;
990 mbx_cmd_t *mcp = &mc;
991 struct qla_hw_data *ha = vha->hw;
992
993 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
994 "Entered %s.\n", __func__);
995
996 memset(mcp->mb, 0 , sizeof(mcp->mb));
997 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
998 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -0700999 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
1000 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
1001 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
1002 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
1003 mcp->mb[8] = MSW(ha->exchoffld_size);
1004 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001005 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1006 mcp->in_mb = MBX_11|MBX_0;
1007 mcp->tov = MBX_TOV_SECONDS;
1008 mcp->flags = 0;
1009 rval = qla2x00_mailbox_command(vha, mcp);
1010 if (rval != QLA_SUCCESS) {
1011 /*EMPTY*/
1012 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
1013 } else {
1014 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
1015 "Done %s.\n", __func__);
1016 }
1017
1018 return rval;
1019}
1020
1021/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 * qla2x00_get_fw_version
1023 * Get firmware version.
1024 *
1025 * Input:
1026 * ha: adapter state pointer.
1027 * major: pointer for major number.
1028 * minor: pointer for minor number.
1029 * subminor: pointer for subminor number.
1030 *
1031 * Returns:
1032 * qla2x00 local function return status code.
1033 *
1034 * Context:
1035 * Kernel context.
1036 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001037int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001038qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039{
1040 int rval;
1041 mbx_cmd_t mc;
1042 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001043 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001045 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
1046 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
1048 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
1049 mcp->out_mb = MBX_0;
1050 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001051 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001052 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -04001053 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001054 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001055 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001056 mcp->in_mb |=
1057 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07001058 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001059
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001061 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001062 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001063 if (rval != QLA_SUCCESS)
1064 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001067 ha->fw_major_version = mcp->mb[1];
1068 ha->fw_minor_version = mcp->mb[2];
1069 ha->fw_subminor_version = mcp->mb[3];
1070 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001071 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001072 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001074 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -04001075
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001076 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001077 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1078 ha->mpi_version[1] = mcp->mb[11] >> 8;
1079 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1080 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
1081 ha->phy_version[0] = mcp->mb[8] & 0xff;
1082 ha->phy_version[1] = mcp->mb[9] >> 8;
1083 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001084 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001085
Saurav Kashyap81178772012-08-22 14:21:04 -04001086 if (IS_FWI2_CAPABLE(ha)) {
1087 ha->fw_attributes_h = mcp->mb[15];
1088 ha->fw_attributes_ext[0] = mcp->mb[16];
1089 ha->fw_attributes_ext[1] = mcp->mb[17];
1090 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
1091 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
1092 __func__, mcp->mb[15], mcp->mb[6]);
1093 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
1094 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
1095 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001096
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001097 if (ha->fw_attributes_h & 0x4)
1098 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
1099 "%s: Firmware supports Extended Login 0x%x\n",
1100 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001101
1102 if (ha->fw_attributes_h & 0x8)
1103 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
1104 "%s: Firmware supports Exchange Offload 0x%x\n",
1105 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -07001106
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07001107 /*
1108 * FW supports nvme and driver load parameter requested nvme.
1109 * BIT 26 of fw_attributes indicates NVMe support.
1110 */
Giridhar Malavali171e4902019-01-30 09:50:44 -08001111 if ((ha->fw_attributes_h &
1112 (FW_ATTR_H_NVME | FW_ATTR_H_NVME_UPDATED)) &&
1113 ql2xnvmeenable) {
Darren Trapp03aaa892019-02-15 14:37:13 -08001114 if (ha->fw_attributes_h & FW_ATTR_H_NVME_FBURST)
1115 vha->flags.nvme_first_burst = 1;
1116
Duane Grigsbye84067d2017-06-21 13:48:43 -07001117 vha->flags.nvme_enabled = 1;
Darren Trapp1cbc0ef2018-03-20 23:09:37 -07001118 ql_log(ql_log_info, vha, 0xd302,
1119 "%s: FC-NVMe is Enabled (0x%x)\n",
1120 __func__, ha->fw_attributes_h);
1121 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001122 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001123
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001124 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07001125 ha->serdes_version[0] = mcp->mb[7] & 0xff;
1126 ha->serdes_version[1] = mcp->mb[8] >> 8;
1127 ha->serdes_version[2] = mcp->mb[8] & 0xff;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001128 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1129 ha->mpi_version[1] = mcp->mb[11] >> 8;
1130 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1131 ha->pep_version[0] = mcp->mb[13] & 0xff;
1132 ha->pep_version[1] = mcp->mb[14] >> 8;
1133 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001134 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
1135 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001136 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
1137 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Michael Hernandez3f006ac2019-03-12 11:08:22 -07001138 if (IS_QLA28XX(ha)) {
1139 if (mcp->mb[16] & BIT_10) {
1140 ql_log(ql_log_info, vha, 0xffff,
1141 "FW support secure flash updates\n");
1142 ha->flags.secure_fw = 1;
1143 }
1144 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001145 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001146
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001147failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 if (rval != QLA_SUCCESS) {
1149 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001150 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 } else {
1152 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001153 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
1154 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001156 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157}
1158
1159/*
1160 * qla2x00_get_fw_options
1161 * Set firmware options.
1162 *
1163 * Input:
1164 * ha = adapter block pointer.
1165 * fwopt = pointer for firmware options.
1166 *
1167 * Returns:
1168 * qla2x00 local function return status code.
1169 *
1170 * Context:
1171 * Kernel context.
1172 */
1173int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001174qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175{
1176 int rval;
1177 mbx_cmd_t mc;
1178 mbx_cmd_t *mcp = &mc;
1179
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001180 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1181 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182
1183 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1184 mcp->out_mb = MBX_0;
1185 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001186 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001188 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
1190 if (rval != QLA_SUCCESS) {
1191 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001192 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001194 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 fwopts[1] = mcp->mb[1];
1196 fwopts[2] = mcp->mb[2];
1197 fwopts[3] = mcp->mb[3];
1198
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001199 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1200 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 }
1202
1203 return rval;
1204}
1205
1206
1207/*
1208 * qla2x00_set_fw_options
1209 * Set firmware options.
1210 *
1211 * Input:
1212 * ha = adapter block pointer.
1213 * fwopt = pointer for firmware options.
1214 *
1215 * Returns:
1216 * qla2x00 local function return status code.
1217 *
1218 * Context:
1219 * Kernel context.
1220 */
1221int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001222qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223{
1224 int rval;
1225 mbx_cmd_t mc;
1226 mbx_cmd_t *mcp = &mc;
1227
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001228 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1229 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
1231 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1232 mcp->mb[1] = fwopts[1];
1233 mcp->mb[2] = fwopts[2];
1234 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001235 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001237 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001238 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001239 mcp->mb[10] = fwopts[10];
1240 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001241 } else {
1242 mcp->mb[10] = fwopts[10];
1243 mcp->mb[11] = fwopts[11];
1244 mcp->mb[12] = 0; /* Undocumented, but used */
1245 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1246 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001247 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001249 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001251 fwopts[0] = mcp->mb[0];
1252
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 if (rval != QLA_SUCCESS) {
1254 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001255 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1256 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 } else {
1258 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001259 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1260 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 }
1262
1263 return rval;
1264}
1265
1266/*
1267 * qla2x00_mbx_reg_test
1268 * Mailbox register wrap test.
1269 *
1270 * Input:
1271 * ha = adapter block pointer.
1272 * TARGET_QUEUE_LOCK must be released.
1273 * ADAPTER_STATE_LOCK must be released.
1274 *
1275 * Returns:
1276 * qla2x00 local function return status code.
1277 *
1278 * Context:
1279 * Kernel context.
1280 */
1281int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001282qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283{
1284 int rval;
1285 mbx_cmd_t mc;
1286 mbx_cmd_t *mcp = &mc;
1287
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001288 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1289 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1292 mcp->mb[1] = 0xAAAA;
1293 mcp->mb[2] = 0x5555;
1294 mcp->mb[3] = 0xAA55;
1295 mcp->mb[4] = 0x55AA;
1296 mcp->mb[5] = 0xA5A5;
1297 mcp->mb[6] = 0x5A5A;
1298 mcp->mb[7] = 0x2525;
1299 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1300 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 -07001301 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001303 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 if (rval == QLA_SUCCESS) {
1306 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1307 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1308 rval = QLA_FUNCTION_FAILED;
1309 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1310 mcp->mb[7] != 0x2525)
1311 rval = QLA_FUNCTION_FAILED;
1312 }
1313
1314 if (rval != QLA_SUCCESS) {
1315 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001316 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 } else {
1318 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001319 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1320 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 }
1322
1323 return rval;
1324}
1325
1326/*
1327 * qla2x00_verify_checksum
1328 * Verify firmware checksum.
1329 *
1330 * Input:
1331 * ha = adapter block pointer.
1332 * TARGET_QUEUE_LOCK must be released.
1333 * ADAPTER_STATE_LOCK must be released.
1334 *
1335 * Returns:
1336 * qla2x00 local function return status code.
1337 *
1338 * Context:
1339 * Kernel context.
1340 */
1341int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001342qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
1344 int rval;
1345 mbx_cmd_t mc;
1346 mbx_cmd_t *mcp = &mc;
1347
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001348 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1349 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
1351 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001352 mcp->out_mb = MBX_0;
1353 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001354 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001355 mcp->mb[1] = MSW(risc_addr);
1356 mcp->mb[2] = LSW(risc_addr);
1357 mcp->out_mb |= MBX_2|MBX_1;
1358 mcp->in_mb |= MBX_2|MBX_1;
1359 } else {
1360 mcp->mb[1] = LSW(risc_addr);
1361 mcp->out_mb |= MBX_1;
1362 mcp->in_mb |= MBX_1;
1363 }
1364
Ravi Anandb93480e2008-04-03 13:13:25 -07001365 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001367 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001370 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1371 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1372 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001374 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1375 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
1377
1378 return rval;
1379}
1380
1381/*
1382 * qla2x00_issue_iocb
1383 * Issue IOCB using mailbox command
1384 *
1385 * Input:
1386 * ha = adapter state pointer.
1387 * buffer = buffer pointer.
1388 * phys_addr = physical address of buffer.
1389 * size = size of buffer.
1390 * TARGET_QUEUE_LOCK must be released.
1391 * ADAPTER_STATE_LOCK must be released.
1392 *
1393 * Returns:
1394 * qla2x00 local function return status code.
1395 *
1396 * Context:
1397 * Kernel context.
1398 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001399int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001400qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001401 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
1403 int rval;
1404 mbx_cmd_t mc;
1405 mbx_cmd_t *mcp = &mc;
1406
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001407 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1408 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001409
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1411 mcp->mb[1] = 0;
1412 mcp->mb[2] = MSW(phys_addr);
1413 mcp->mb[3] = LSW(phys_addr);
1414 mcp->mb[6] = MSW(MSD(phys_addr));
1415 mcp->mb[7] = LSW(MSD(phys_addr));
1416 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1417 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001418 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001420 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 if (rval != QLA_SUCCESS) {
1423 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001424 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001426 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1427
1428 /* Mask reserved bits. */
1429 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001430 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001431 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1432 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434
1435 return rval;
1436}
1437
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001438int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001439qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001440 size_t size)
1441{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001442 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001443 MBX_TOV_SECONDS);
1444}
1445
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446/*
1447 * qla2x00_abort_command
1448 * Abort command aborts a specified IOCB.
1449 *
1450 * Input:
1451 * ha = adapter block pointer.
1452 * sp = SB structure pointer.
1453 *
1454 * Returns:
1455 * qla2x00 local function return status code.
1456 *
1457 * Context:
1458 * Kernel context.
1459 */
1460int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001461qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
1463 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001465 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 mbx_cmd_t mc;
1467 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001468 fc_port_t *fcport = sp->fcport;
1469 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001470 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001471 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001472 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001474 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1475 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Michael Hernandezd7459522016-12-12 14:40:07 -08001477 if (vha->flags.qpairs_available && sp->qpair)
1478 req = sp->qpair->req;
1479 else
1480 req = vha->req;
1481
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001482 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001483 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001484 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 break;
1486 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001487 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Chad Dupuis8d93f552013-01-30 03:34:37 -05001489 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 /* command not found */
1491 return QLA_FUNCTION_FAILED;
1492 }
1493
1494 mcp->mb[0] = MBC_ABORT_COMMAND;
1495 if (HAS_EXTENDED_IDS(ha))
1496 mcp->mb[1] = fcport->loop_id;
1497 else
1498 mcp->mb[1] = fcport->loop_id << 8;
1499 mcp->mb[2] = (uint16_t)handle;
1500 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001501 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1503 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001504 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001506 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001509 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001511 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1512 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 }
1514
1515 return rval;
1516}
1517
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001519qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001521 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 mbx_cmd_t mc;
1523 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001524 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001526 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001527
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001528 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1529 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001530
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001532 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001533 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 mcp->mb[1] = fcport->loop_id;
1535 mcp->mb[10] = 0;
1536 mcp->out_mb |= MBX_10;
1537 } else {
1538 mcp->mb[1] = fcport->loop_id << 8;
1539 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001540 mcp->mb[2] = vha->hw->loop_reset_delay;
1541 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001544 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001546 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001548 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1549 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001550 }
1551
1552 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08001553 rval2 = qla2x00_marker(vha, vha->hw->base_qpair, fcport->loop_id, 0,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001554 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001555 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001556 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1557 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001559 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1560 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001561 }
1562
1563 return rval;
1564}
1565
1566int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001567qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001568{
1569 int rval, rval2;
1570 mbx_cmd_t mc;
1571 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001572 scsi_qla_host_t *vha;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001573
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001574 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001575
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001576 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1577 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001578
Andrew Vasquez523ec772008-04-03 13:13:24 -07001579 mcp->mb[0] = MBC_LUN_RESET;
1580 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001581 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001582 mcp->mb[1] = fcport->loop_id;
1583 else
1584 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001585 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001586 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001587 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001588
1589 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001590 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001591 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001592 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001593 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001594 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001595 }
1596
1597 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08001598 rval2 = qla2x00_marker(vha, vha->hw->base_qpair, fcport->loop_id, l,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001599 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001600 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001601 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1602 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001603 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001604 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1605 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 }
1607
1608 return rval;
1609}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
1611/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 * qla2x00_get_adapter_id
1613 * Get adapter ID and topology.
1614 *
1615 * Input:
1616 * ha = adapter block pointer.
1617 * id = pointer for loop ID.
1618 * al_pa = pointer for AL_PA.
1619 * area = pointer for area.
1620 * domain = pointer for domain.
1621 * top = pointer for topology.
1622 * TARGET_QUEUE_LOCK must be released.
1623 * ADAPTER_STATE_LOCK must be released.
1624 *
1625 * Returns:
1626 * qla2x00 local function return status code.
1627 *
1628 * Context:
1629 * Kernel context.
1630 */
1631int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001632qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001633 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634{
1635 int rval;
1636 mbx_cmd_t mc;
1637 mbx_cmd_t *mcp = &mc;
1638
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001639 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1640 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
1642 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001643 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001644 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001645 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001646 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001647 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001648 if (IS_FWI2_CAPABLE(vha->hw))
1649 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001650 if (IS_QLA27XX(vha->hw) || IS_QLA28XX(vha->hw))
Sawan Chandak969a6192016-01-27 12:03:32 -05001651 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001652 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001654 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001655 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1656 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001657 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1658 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
1660 /* Return data. */
1661 *id = mcp->mb[1];
1662 *al_pa = LSB(mcp->mb[2]);
1663 *area = MSB(mcp->mb[2]);
1664 *domain = LSB(mcp->mb[3]);
1665 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001666 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 if (rval != QLA_SUCCESS) {
1669 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001670 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001672 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1673 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001674
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001675 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001676 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1677 vha->fcoe_fcf_idx = mcp->mb[10];
1678 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1679 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1680 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1681 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1682 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1683 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1684 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001685 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001686 if (IS_FAWWN_CAPABLE(vha->hw)) {
1687 if (mcp->mb[7] & BIT_14) {
1688 vha->port_name[0] = MSB(mcp->mb[16]);
1689 vha->port_name[1] = LSB(mcp->mb[16]);
1690 vha->port_name[2] = MSB(mcp->mb[17]);
1691 vha->port_name[3] = LSB(mcp->mb[17]);
1692 vha->port_name[4] = MSB(mcp->mb[18]);
1693 vha->port_name[5] = LSB(mcp->mb[18]);
1694 vha->port_name[6] = MSB(mcp->mb[19]);
1695 vha->port_name[7] = LSB(mcp->mb[19]);
1696 fc_host_port_name(vha->host) =
1697 wwn_to_u64(vha->port_name);
1698 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1699 "FA-WWN acquired %016llx\n",
1700 wwn_to_u64(vha->port_name));
1701 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001702 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001703
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001704 if (IS_QLA27XX(vha->hw) || IS_QLA28XX(vha->hw))
Sawan Chandak969a6192016-01-27 12:03:32 -05001705 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 }
1707
1708 return rval;
1709}
1710
1711/*
1712 * qla2x00_get_retry_cnt
1713 * Get current firmware login retry count and delay.
1714 *
1715 * Input:
1716 * ha = adapter block pointer.
1717 * retry_cnt = pointer to login retry count.
1718 * tov = pointer to login timeout value.
1719 *
1720 * Returns:
1721 * qla2x00 local function return status code.
1722 *
1723 * Context:
1724 * Kernel context.
1725 */
1726int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001727qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 uint16_t *r_a_tov)
1729{
1730 int rval;
1731 uint16_t ratov;
1732 mbx_cmd_t mc;
1733 mbx_cmd_t *mcp = &mc;
1734
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001735 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1736 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1739 mcp->out_mb = MBX_0;
1740 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001741 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001743 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
1745 if (rval != QLA_SUCCESS) {
1746 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001747 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1748 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 } else {
1750 /* Convert returned data and check our values. */
1751 *r_a_tov = mcp->mb[3] / 2;
1752 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1753 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1754 /* Update to the larger values */
1755 *retry_cnt = (uint8_t)mcp->mb[1];
1756 *tov = ratov;
1757 }
1758
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001759 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001760 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 }
1762
1763 return rval;
1764}
1765
1766/*
1767 * qla2x00_init_firmware
1768 * Initialize adapter firmware.
1769 *
1770 * Input:
1771 * ha = adapter block pointer.
1772 * dptr = Initialization control block pointer.
1773 * size = size of initialization control block.
1774 * TARGET_QUEUE_LOCK must be released.
1775 * ADAPTER_STATE_LOCK must be released.
1776 *
1777 * Returns:
1778 * qla2x00 local function return status code.
1779 *
1780 * Context:
1781 * Kernel context.
1782 */
1783int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001784qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
1786 int rval;
1787 mbx_cmd_t mc;
1788 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001789 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001791 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1792 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001794 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001795 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001796 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1797
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001798 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001799 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1800 else
1801 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1802
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001803 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 mcp->mb[2] = MSW(ha->init_cb_dma);
1805 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1807 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001808 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001809 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001810 mcp->mb[1] = BIT_0;
1811 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1812 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1813 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1814 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1815 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1816 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1817 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001818 /* 1 and 2 should normally be captured. */
1819 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001820 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001821 /* mb3 is additional info about the installed SFP. */
1822 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 mcp->buf_size = size;
1824 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001825 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001826 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 if (rval != QLA_SUCCESS) {
1829 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001830 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07001831 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x.\n",
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001832 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Joe Carnucciof8f97b02019-03-12 11:08:16 -07001833 if (ha->init_cb) {
1834 ql_dbg(ql_dbg_mbx, vha, 0x104d, "init_cb:\n");
1835 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha,
1836 0x0104d, ha->init_cb, sizeof(*ha->init_cb));
1837 }
1838 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
1839 ql_dbg(ql_dbg_mbx, vha, 0x104d, "ex_init_cb:\n");
1840 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha,
1841 0x0104d, ha->ex_init_cb, sizeof(*ha->ex_init_cb));
1842 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 } else {
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001844 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -07001845 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1846 ql_dbg(ql_dbg_mbx, vha, 0x119d,
1847 "Invalid SFP/Validation Failed\n");
1848 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001849 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1850 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 }
1852
1853 return rval;
1854}
1855
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001856
1857/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 * qla2x00_get_port_database
1859 * Issue normal/enhanced get port database mailbox command
1860 * and copy device name as necessary.
1861 *
1862 * Input:
1863 * ha = adapter state pointer.
1864 * dev = structure pointer.
1865 * opt = enhanced cmd option byte.
1866 *
1867 * Returns:
1868 * qla2x00 local function return status code.
1869 *
1870 * Context:
1871 * Kernel context.
1872 */
1873int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001874qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875{
1876 int rval;
1877 mbx_cmd_t mc;
1878 mbx_cmd_t *mcp = &mc;
1879 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001880 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001882 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001884 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1885 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001887 pd24 = NULL;
Thomas Meyer08eb7f42017-09-21 08:15:26 +02001888 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001890 ql_log(ql_log_warn, vha, 0x1050,
1891 "Failed to allocate port database structure.\n");
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001892 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 return QLA_MEMORY_ALLOC_FAILED;
1894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001896 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001897 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 mcp->mb[2] = MSW(pd_dma);
1900 mcp->mb[3] = LSW(pd_dma);
1901 mcp->mb[6] = MSW(MSD(pd_dma));
1902 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001903 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001904 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001906 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001907 mcp->mb[1] = fcport->loop_id;
1908 mcp->mb[10] = opt;
1909 mcp->out_mb |= MBX_10|MBX_1;
1910 mcp->in_mb |= MBX_1;
1911 } else if (HAS_EXTENDED_IDS(ha)) {
1912 mcp->mb[1] = fcport->loop_id;
1913 mcp->mb[10] = opt;
1914 mcp->out_mb |= MBX_10|MBX_1;
1915 } else {
1916 mcp->mb[1] = fcport->loop_id << 8 | opt;
1917 mcp->out_mb |= MBX_1;
1918 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001919 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1920 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 mcp->flags = MBX_DMA_IN;
1922 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001923 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 if (rval != QLA_SUCCESS)
1925 goto gpd_error_out;
1926
Andrew Vasqueze4289242007-07-19 15:05:56 -07001927 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001928 uint64_t zero = 0;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001929 u8 current_login_state, last_login_state;
1930
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001931 pd24 = (struct port_database_24xx *) pd;
1932
1933 /* Check for logged in state. */
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001934 if (fcport->fc4f_nvme) {
1935 current_login_state = pd24->current_login_state >> 4;
1936 last_login_state = pd24->last_login_state >> 4;
1937 } else {
1938 current_login_state = pd24->current_login_state & 0xf;
1939 last_login_state = pd24->last_login_state & 0xf;
1940 }
1941 fcport->current_login_state = pd24->current_login_state;
1942 fcport->last_login_state = pd24->last_login_state;
1943
1944 /* Check for logged in state. */
1945 if (current_login_state != PDS_PRLI_COMPLETE &&
1946 last_login_state != PDS_PRLI_COMPLETE) {
1947 ql_dbg(ql_dbg_mbx, vha, 0x119a,
1948 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
1949 current_login_state, last_login_state,
1950 fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001951 rval = QLA_FUNCTION_FAILED;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001952
1953 if (!fcport->query)
1954 goto gpd_error_out;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001955 }
1956
Arun Easi0eba25d2012-02-09 11:15:58 -08001957 if (fcport->loop_id == FC_NO_LOOP_ID ||
1958 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1959 memcmp(fcport->port_name, pd24->port_name, 8))) {
1960 /* We lost the device mid way. */
1961 rval = QLA_NOT_LOGGED_IN;
1962 goto gpd_error_out;
1963 }
1964
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001965 /* Names are little-endian. */
1966 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1967 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1968
1969 /* Get port_id of device. */
1970 fcport->d_id.b.domain = pd24->port_id[0];
1971 fcport->d_id.b.area = pd24->port_id[1];
1972 fcport->d_id.b.al_pa = pd24->port_id[2];
1973 fcport->d_id.b.rsvd_1 = 0;
1974
1975 /* If not target must be initiator or unknown type. */
1976 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1977 fcport->port_type = FCT_INITIATOR;
1978 else
1979 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001980
1981 /* Passback COS information. */
1982 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1983 FC_COS_CLASS2 : FC_COS_CLASS3;
1984
1985 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1986 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001987 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001988 uint64_t zero = 0;
1989
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001990 /* Check for logged in state. */
1991 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1992 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001993 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1994 "Unable to verify login-state (%x/%x) - "
1995 "portid=%02x%02x%02x.\n", pd->master_state,
1996 pd->slave_state, fcport->d_id.b.domain,
1997 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001998 rval = QLA_FUNCTION_FAILED;
1999 goto gpd_error_out;
2000 }
2001
Arun Easi0eba25d2012-02-09 11:15:58 -08002002 if (fcport->loop_id == FC_NO_LOOP_ID ||
2003 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
2004 memcmp(fcport->port_name, pd->port_name, 8))) {
2005 /* We lost the device mid way. */
2006 rval = QLA_NOT_LOGGED_IN;
2007 goto gpd_error_out;
2008 }
2009
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002010 /* Names are little-endian. */
2011 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
2012 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
2013
2014 /* Get port_id of device. */
2015 fcport->d_id.b.domain = pd->port_id[0];
2016 fcport->d_id.b.area = pd->port_id[3];
2017 fcport->d_id.b.al_pa = pd->port_id[2];
2018 fcport->d_id.b.rsvd_1 = 0;
2019
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002020 /* If not target must be initiator or unknown type. */
2021 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
2022 fcport->port_type = FCT_INITIATOR;
2023 else
2024 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002025
2026 /* Passback COS information. */
2027 fcport->supported_classes = (pd->options & BIT_4) ?
Bart Van Assche58e27532019-04-11 14:53:19 -07002028 FC_COS_CLASS2 : FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 }
2030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031gpd_error_out:
2032 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07002033 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002036 ql_dbg(ql_dbg_mbx, vha, 0x1052,
2037 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
2038 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002040 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
2041 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 }
2043
2044 return rval;
2045}
2046
2047/*
2048 * qla2x00_get_firmware_state
2049 * Get adapter firmware state.
2050 *
2051 * Input:
2052 * ha = adapter block pointer.
2053 * dptr = pointer for firmware state.
2054 * TARGET_QUEUE_LOCK must be released.
2055 * ADAPTER_STATE_LOCK must be released.
2056 *
2057 * Returns:
2058 * qla2x00 local function return status code.
2059 *
2060 * Context:
2061 * Kernel context.
2062 */
2063int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002064qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
2066 int rval;
2067 mbx_cmd_t mc;
2068 mbx_cmd_t *mcp = &mc;
Sawan Chandak92d44082017-08-23 15:05:16 -07002069 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002071 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
2072 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
2075 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002076 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002077 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002078 else
2079 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002080 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002082 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002084 /* Return firmware states. */
2085 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002086 if (IS_FWI2_CAPABLE(vha->hw)) {
2087 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04002088 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002089 states[3] = mcp->mb[4];
2090 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002091 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
2094 if (rval != QLA_SUCCESS) {
2095 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002096 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 } else {
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002098 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -07002099 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
2100 ql_dbg(ql_dbg_mbx, vha, 0x119e,
2101 "Invalid SFP/Validation Failed\n");
2102 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002103 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
2104 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 }
2106
2107 return rval;
2108}
2109
2110/*
2111 * qla2x00_get_port_name
2112 * Issue get port name mailbox command.
2113 * Returned name is in big endian format.
2114 *
2115 * Input:
2116 * ha = adapter block pointer.
2117 * loop_id = loop ID of device.
2118 * name = pointer for name.
2119 * TARGET_QUEUE_LOCK must be released.
2120 * ADAPTER_STATE_LOCK must be released.
2121 *
2122 * Returns:
2123 * qla2x00 local function return status code.
2124 *
2125 * Context:
2126 * Kernel context.
2127 */
2128int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002129qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 uint8_t opt)
2131{
2132 int rval;
2133 mbx_cmd_t mc;
2134 mbx_cmd_t *mcp = &mc;
2135
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002136 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
2137 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002140 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002141 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002142 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 mcp->mb[1] = loop_id;
2144 mcp->mb[10] = opt;
2145 mcp->out_mb |= MBX_10;
2146 } else {
2147 mcp->mb[1] = loop_id << 8 | opt;
2148 }
2149
2150 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002151 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002153 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154
2155 if (rval != QLA_SUCCESS) {
2156 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002157 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 } else {
2159 if (name != NULL) {
2160 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002161 name[0] = MSB(mcp->mb[2]);
2162 name[1] = LSB(mcp->mb[2]);
2163 name[2] = MSB(mcp->mb[3]);
2164 name[3] = LSB(mcp->mb[3]);
2165 name[4] = MSB(mcp->mb[6]);
2166 name[5] = LSB(mcp->mb[6]);
2167 name[6] = MSB(mcp->mb[7]);
2168 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 }
2170
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002171 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2172 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 }
2174
2175 return rval;
2176}
2177
2178/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002179 * qla24xx_link_initialization
2180 * Issue link initialization mailbox command.
2181 *
2182 * Input:
2183 * ha = adapter block pointer.
2184 * TARGET_QUEUE_LOCK must be released.
2185 * ADAPTER_STATE_LOCK must be released.
2186 *
2187 * Returns:
2188 * qla2x00 local function return status code.
2189 *
2190 * Context:
2191 * Kernel context.
2192 */
2193int
2194qla24xx_link_initialize(scsi_qla_host_t *vha)
2195{
2196 int rval;
2197 mbx_cmd_t mc;
2198 mbx_cmd_t *mcp = &mc;
2199
2200 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2201 "Entered %s.\n", __func__);
2202
2203 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2204 return QLA_FUNCTION_FAILED;
2205
2206 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002207 mcp->mb[1] = BIT_4;
2208 if (vha->hw->operating_mode == LOOP)
2209 mcp->mb[1] |= BIT_6;
2210 else
2211 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002212 mcp->mb[2] = 0;
2213 mcp->mb[3] = 0;
2214 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2215 mcp->in_mb = MBX_0;
2216 mcp->tov = MBX_TOV_SECONDS;
2217 mcp->flags = 0;
2218 rval = qla2x00_mailbox_command(vha, mcp);
2219
2220 if (rval != QLA_SUCCESS) {
2221 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2222 } else {
2223 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2224 "Done %s.\n", __func__);
2225 }
2226
2227 return rval;
2228}
2229
2230/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 * qla2x00_lip_reset
2232 * Issue LIP reset mailbox command.
2233 *
2234 * Input:
2235 * ha = adapter block pointer.
2236 * TARGET_QUEUE_LOCK must be released.
2237 * ADAPTER_STATE_LOCK must be released.
2238 *
2239 * Returns:
2240 * qla2x00 local function return status code.
2241 *
2242 * Context:
2243 * Kernel context.
2244 */
2245int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002246qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247{
2248 int rval;
2249 mbx_cmd_t mc;
2250 mbx_cmd_t *mcp = &mc;
2251
Quinn Tran7f2a3982019-09-12 11:09:09 -07002252 ql_dbg(ql_dbg_disc, vha, 0x105a,
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002253 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002255 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002256 /* Logout across all FCFs. */
2257 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2258 mcp->mb[1] = BIT_1;
2259 mcp->mb[2] = 0;
2260 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2261 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002262 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002263 mcp->mb[1] = BIT_4;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002264 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002265 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002266 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002268 mcp->mb[0] = MBC_LIP_RESET;
2269 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002270 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002271 mcp->mb[1] = 0x00ff;
2272 mcp->mb[10] = 0;
2273 mcp->out_mb |= MBX_10;
2274 } else {
2275 mcp->mb[1] = 0xff00;
2276 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002277 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002278 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002281 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002283 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284
2285 if (rval != QLA_SUCCESS) {
2286 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002287 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 } else {
2289 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002290 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2291 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 }
2293
2294 return rval;
2295}
2296
2297/*
2298 * qla2x00_send_sns
2299 * Send SNS command.
2300 *
2301 * Input:
2302 * ha = adapter block pointer.
2303 * sns = pointer for command.
2304 * cmd_size = command size.
2305 * buf_size = response/command size.
2306 * TARGET_QUEUE_LOCK must be released.
2307 * ADAPTER_STATE_LOCK must be released.
2308 *
2309 * Returns:
2310 * qla2x00 local function return status code.
2311 *
2312 * Context:
2313 * Kernel context.
2314 */
2315int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002316qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 uint16_t cmd_size, size_t buf_size)
2318{
2319 int rval;
2320 mbx_cmd_t mc;
2321 mbx_cmd_t *mcp = &mc;
2322
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002323 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2324 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002326 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002327 "Retry cnt=%d ratov=%d total tov=%d.\n",
2328 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
2330 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2331 mcp->mb[1] = cmd_size;
2332 mcp->mb[2] = MSW(sns_phys_address);
2333 mcp->mb[3] = LSW(sns_phys_address);
2334 mcp->mb[6] = MSW(MSD(sns_phys_address));
2335 mcp->mb[7] = LSW(MSD(sns_phys_address));
2336 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2337 mcp->in_mb = MBX_0|MBX_1;
2338 mcp->buf_size = buf_size;
2339 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002340 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2341 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
2343 if (rval != QLA_SUCCESS) {
2344 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002345 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2346 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2347 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 } else {
2349 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002350 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2351 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353
2354 return rval;
2355}
2356
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002357int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002358qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002359 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2360{
2361 int rval;
2362
2363 struct logio_entry_24xx *lg;
2364 dma_addr_t lg_dma;
2365 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002366 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002367 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002368
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002369 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2370 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002371
Michael Hernandezd7459522016-12-12 14:40:07 -08002372 if (vha->vp_idx && vha->qpair)
2373 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002374 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002375 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002376
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002377 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002378 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002379 ql_log(ql_log_warn, vha, 0x1062,
2380 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002381 return QLA_MEMORY_ALLOC_FAILED;
2382 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002383
2384 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2385 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002386 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002387 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002388 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002389 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002390 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002391 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002392 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002393 lg->port_id[0] = al_pa;
2394 lg->port_id[1] = area;
2395 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002396 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002397 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2398 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002399 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002400 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2401 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002402 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002403 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2404 "Failed to complete IOCB -- error status (%x).\n",
2405 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002406 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002407 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002408 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2409 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2410
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002411 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2412 "Failed to complete IOCB -- completion status (%x) "
2413 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2414 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002415
2416 switch (iop[0]) {
2417 case LSC_SCODE_PORTID_USED:
2418 mb[0] = MBS_PORT_ID_USED;
2419 mb[1] = LSW(iop[1]);
2420 break;
2421 case LSC_SCODE_NPORT_USED:
2422 mb[0] = MBS_LOOP_ID_USED;
2423 break;
2424 case LSC_SCODE_NOLINK:
2425 case LSC_SCODE_NOIOCB:
2426 case LSC_SCODE_NOXCB:
2427 case LSC_SCODE_CMD_FAILED:
2428 case LSC_SCODE_NOFABRIC:
2429 case LSC_SCODE_FW_NOT_READY:
2430 case LSC_SCODE_NOT_LOGGED_IN:
2431 case LSC_SCODE_NOPCB:
2432 case LSC_SCODE_ELS_REJECT:
2433 case LSC_SCODE_CMD_PARAM_ERR:
2434 case LSC_SCODE_NONPORT:
2435 case LSC_SCODE_LOGGED_IN:
2436 case LSC_SCODE_NOFLOGI_ACC:
2437 default:
2438 mb[0] = MBS_COMMAND_ERROR;
2439 break;
2440 }
2441 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002442 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2443 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002444
2445 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2446
2447 mb[0] = MBS_COMMAND_COMPLETE;
2448 mb[1] = 0;
2449 if (iop[0] & BIT_4) {
2450 if (iop[0] & BIT_8)
2451 mb[1] |= BIT_1;
2452 } else
2453 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002454
2455 /* Passback COS information. */
2456 mb[10] = 0;
2457 if (lg->io_parameter[7] || lg->io_parameter[8])
2458 mb[10] |= BIT_0; /* Class 2. */
2459 if (lg->io_parameter[9] || lg->io_parameter[10])
2460 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002461 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002462 mb[10] |= BIT_7; /* Confirmed Completion
2463 * Allowed
2464 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002465 }
2466
2467 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2468
2469 return rval;
2470}
2471
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472/*
2473 * qla2x00_login_fabric
2474 * Issue login fabric port mailbox command.
2475 *
2476 * Input:
2477 * ha = adapter block pointer.
2478 * loop_id = device loop ID.
2479 * domain = device domain.
2480 * area = device area.
2481 * al_pa = device AL_PA.
2482 * status = pointer for return status.
2483 * opt = command options.
2484 * TARGET_QUEUE_LOCK must be released.
2485 * ADAPTER_STATE_LOCK must be released.
2486 *
2487 * Returns:
2488 * qla2x00 local function return status code.
2489 *
2490 * Context:
2491 * Kernel context.
2492 */
2493int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002494qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2496{
2497 int rval;
2498 mbx_cmd_t mc;
2499 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002500 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002502 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2503 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
2505 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2506 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2507 if (HAS_EXTENDED_IDS(ha)) {
2508 mcp->mb[1] = loop_id;
2509 mcp->mb[10] = opt;
2510 mcp->out_mb |= MBX_10;
2511 } else {
2512 mcp->mb[1] = (loop_id << 8) | opt;
2513 }
2514 mcp->mb[2] = domain;
2515 mcp->mb[3] = area << 8 | al_pa;
2516
2517 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2518 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2519 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002520 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
2522 /* Return mailbox statuses. */
2523 if (mb != NULL) {
2524 mb[0] = mcp->mb[0];
2525 mb[1] = mcp->mb[1];
2526 mb[2] = mcp->mb[2];
2527 mb[6] = mcp->mb[6];
2528 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002529 /* COS retrieved from Get-Port-Database mailbox command. */
2530 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
2532
2533 if (rval != QLA_SUCCESS) {
2534 /* RLU tmp code: need to change main mailbox_command function to
2535 * return ok even when the mailbox completion value is not
2536 * SUCCESS. The caller needs to be responsible to interpret
2537 * the return values of this mailbox command if we're not
2538 * to change too much of the existing code.
2539 */
2540 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2541 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2542 mcp->mb[0] == 0x4006)
2543 rval = QLA_SUCCESS;
2544
2545 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002546 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2547 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2548 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 } else {
2550 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002551 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2552 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 }
2554
2555 return rval;
2556}
2557
2558/*
2559 * qla2x00_login_local_device
2560 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002561 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 * Input:
2563 * ha = adapter block pointer.
2564 * loop_id = device loop ID.
2565 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002566 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 * Returns:
2568 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002569 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 * Context:
2571 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002572 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 */
2574int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002575qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 uint16_t *mb_ret, uint8_t opt)
2577{
2578 int rval;
2579 mbx_cmd_t mc;
2580 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002581 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002583 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2584 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002585
Andrew Vasqueze4289242007-07-19 15:05:56 -07002586 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002587 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002588 fcport->d_id.b.domain, fcport->d_id.b.area,
2589 fcport->d_id.b.al_pa, mb_ret, opt);
2590
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2592 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002593 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002595 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 mcp->mb[2] = opt;
2597 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2598 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2599 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2600 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002601 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602
2603 /* Return mailbox statuses. */
2604 if (mb_ret != NULL) {
2605 mb_ret[0] = mcp->mb[0];
2606 mb_ret[1] = mcp->mb[1];
2607 mb_ret[6] = mcp->mb[6];
2608 mb_ret[7] = mcp->mb[7];
2609 }
2610
2611 if (rval != QLA_SUCCESS) {
2612 /* AV tmp code: need to change main mailbox_command function to
2613 * return ok even when the mailbox completion value is not
2614 * SUCCESS. The caller needs to be responsible to interpret
2615 * the return values of this mailbox command if we're not
2616 * to change too much of the existing code.
2617 */
2618 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2619 rval = QLA_SUCCESS;
2620
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002621 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2622 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2623 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 } else {
2625 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002626 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2627 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
2629
2630 return (rval);
2631}
2632
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002633int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002634qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002635 uint8_t area, uint8_t al_pa)
2636{
2637 int rval;
2638 struct logio_entry_24xx *lg;
2639 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002640 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002641 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002642
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002643 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2644 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002645
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002646 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002647 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002648 ql_log(ql_log_warn, vha, 0x106e,
2649 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002650 return QLA_MEMORY_ALLOC_FAILED;
2651 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002652
Michael Hernandezd7459522016-12-12 14:40:07 -08002653 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002654 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2655 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002656 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002657 lg->nport_handle = cpu_to_le16(loop_id);
2658 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002659 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002660 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002661 lg->port_id[0] = al_pa;
2662 lg->port_id[1] = area;
2663 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002664 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002665 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2666 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002667 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002668 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2669 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002670 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002671 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2672 "Failed to complete IOCB -- error status (%x).\n",
2673 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002674 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002675 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002676 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2677 "Failed to complete IOCB -- completion status (%x) "
2678 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002679 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002680 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002681 } else {
2682 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002683 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2684 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002685 }
2686
2687 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2688
2689 return rval;
2690}
2691
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692/*
2693 * qla2x00_fabric_logout
2694 * Issue logout fabric port mailbox command.
2695 *
2696 * Input:
2697 * ha = adapter block pointer.
2698 * loop_id = device loop ID.
2699 * TARGET_QUEUE_LOCK must be released.
2700 * ADAPTER_STATE_LOCK must be released.
2701 *
2702 * Returns:
2703 * qla2x00 local function return status code.
2704 *
2705 * Context:
2706 * Kernel context.
2707 */
2708int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002709qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002710 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711{
2712 int rval;
2713 mbx_cmd_t mc;
2714 mbx_cmd_t *mcp = &mc;
2715
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002716 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2717 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718
2719 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2720 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002721 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 mcp->mb[1] = loop_id;
2723 mcp->mb[10] = 0;
2724 mcp->out_mb |= MBX_10;
2725 } else {
2726 mcp->mb[1] = loop_id << 8;
2727 }
2728
2729 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002730 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002732 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733
2734 if (rval != QLA_SUCCESS) {
2735 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002736 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2737 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 } else {
2739 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002740 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2741 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 }
2743
2744 return rval;
2745}
2746
2747/*
2748 * qla2x00_full_login_lip
2749 * Issue full login LIP mailbox command.
2750 *
2751 * Input:
2752 * ha = adapter block pointer.
2753 * TARGET_QUEUE_LOCK must be released.
2754 * ADAPTER_STATE_LOCK must be released.
2755 *
2756 * Returns:
2757 * qla2x00 local function return status code.
2758 *
2759 * Context:
2760 * Kernel context.
2761 */
2762int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002763qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764{
2765 int rval;
2766 mbx_cmd_t mc;
2767 mbx_cmd_t *mcp = &mc;
2768
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002769 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2770 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
2772 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002773 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_4 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002774 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 mcp->mb[3] = 0;
2776 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2777 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002778 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002780 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781
2782 if (rval != QLA_SUCCESS) {
2783 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002784 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 } else {
2786 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002787 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2788 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 }
2790
2791 return rval;
2792}
2793
2794/*
2795 * qla2x00_get_id_list
2796 *
2797 * Input:
2798 * ha = adapter block pointer.
2799 *
2800 * Returns:
2801 * qla2x00 local function return status code.
2802 *
2803 * Context:
2804 * Kernel context.
2805 */
2806int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002807qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 uint16_t *entries)
2809{
2810 int rval;
2811 mbx_cmd_t mc;
2812 mbx_cmd_t *mcp = &mc;
2813
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002814 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2815 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
2817 if (id_list == NULL)
2818 return QLA_FUNCTION_FAILED;
2819
2820 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002821 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002822 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002823 mcp->mb[2] = MSW(id_list_dma);
2824 mcp->mb[3] = LSW(id_list_dma);
2825 mcp->mb[6] = MSW(MSD(id_list_dma));
2826 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002827 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002828 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002829 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002830 } else {
2831 mcp->mb[1] = MSW(id_list_dma);
2832 mcp->mb[2] = LSW(id_list_dma);
2833 mcp->mb[3] = MSW(MSD(id_list_dma));
2834 mcp->mb[6] = LSW(MSD(id_list_dma));
2835 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002838 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002840 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841
2842 if (rval != QLA_SUCCESS) {
2843 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002844 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 } else {
2846 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002847 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2848 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
2850
2851 return rval;
2852}
2853
2854/*
2855 * qla2x00_get_resource_cnts
2856 * Get current firmware resource counts.
2857 *
2858 * Input:
2859 * ha = adapter block pointer.
2860 *
2861 * Returns:
2862 * qla2x00 local function return status code.
2863 *
2864 * Context:
2865 * Kernel context.
2866 */
2867int
Quinn Tran03e8c682015-12-17 14:56:59 -05002868qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869{
Quinn Tran03e8c682015-12-17 14:56:59 -05002870 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 int rval;
2872 mbx_cmd_t mc;
2873 mbx_cmd_t *mcp = &mc;
2874
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002875 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2876 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877
2878 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2879 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002880 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 -07002881 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
2882 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002883 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002884 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002886 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
2888 if (rval != QLA_SUCCESS) {
2889 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002890 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2891 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002893 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002894 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2895 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2896 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2897 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
Quinn Tran03e8c682015-12-17 14:56:59 -05002899 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2900 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2901 ha->cur_fw_xcb_count = mcp->mb[3];
2902 ha->orig_fw_xcb_count = mcp->mb[6];
2903 ha->cur_fw_iocb_count = mcp->mb[7];
2904 ha->orig_fw_iocb_count = mcp->mb[10];
2905 if (ha->flags.npiv_supported)
2906 ha->max_npiv_vports = mcp->mb[11];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002907 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
2908 IS_QLA28XX(ha))
Quinn Tran03e8c682015-12-17 14:56:59 -05002909 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 }
2911
2912 return (rval);
2913}
2914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915/*
2916 * qla2x00_get_fcal_position_map
2917 * Get FCAL (LILP) position map using mailbox command
2918 *
2919 * Input:
2920 * ha = adapter state pointer.
2921 * pos_map = buffer pointer (can be NULL).
2922 *
2923 * Returns:
2924 * qla2x00 local function return status code.
2925 *
2926 * Context:
2927 * Kernel context.
2928 */
2929int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002930qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931{
2932 int rval;
2933 mbx_cmd_t mc;
2934 mbx_cmd_t *mcp = &mc;
2935 char *pmap;
2936 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002937 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002939 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2940 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002941
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002942 pmap = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002944 ql_log(ql_log_warn, vha, 0x1080,
2945 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 return QLA_MEMORY_ALLOC_FAILED;
2947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
2949 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2950 mcp->mb[2] = MSW(pmap_dma);
2951 mcp->mb[3] = LSW(pmap_dma);
2952 mcp->mb[6] = MSW(MSD(pmap_dma));
2953 mcp->mb[7] = LSW(MSD(pmap_dma));
2954 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2955 mcp->in_mb = MBX_1|MBX_0;
2956 mcp->buf_size = FCAL_MAP_SIZE;
2957 mcp->flags = MBX_DMA_IN;
2958 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002959 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960
2961 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002962 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002963 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2964 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2965 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2966 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
2968 if (pos_map)
2969 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2970 }
2971 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2972
2973 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002974 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002976 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2977 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 }
2979
2980 return rval;
2981}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002982
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002983/*
2984 * qla2x00_get_link_status
2985 *
2986 * Input:
2987 * ha = adapter block pointer.
2988 * loop_id = device loop ID.
2989 * ret_buf = pointer to link status return buffer.
2990 *
2991 * Returns:
2992 * 0 = success.
2993 * BIT_0 = mem alloc error.
2994 * BIT_1 = mailbox error.
2995 */
2996int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002997qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002998 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002999{
3000 int rval;
3001 mbx_cmd_t mc;
3002 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003003 uint32_t *iter = (void *)stats;
3004 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003005 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003006
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
3008 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003009
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003010 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003011 mcp->mb[2] = MSW(LSD(stats_dma));
3012 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003013 mcp->mb[6] = MSW(MSD(stats_dma));
3014 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003015 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3016 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07003017 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003018 mcp->mb[1] = loop_id;
3019 mcp->mb[4] = 0;
3020 mcp->mb[10] = 0;
3021 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
3022 mcp->in_mb |= MBX_1;
3023 } else if (HAS_EXTENDED_IDS(ha)) {
3024 mcp->mb[1] = loop_id;
3025 mcp->mb[10] = 0;
3026 mcp->out_mb |= MBX_10|MBX_1;
3027 } else {
3028 mcp->mb[1] = loop_id << 8;
3029 mcp->out_mb |= MBX_1;
3030 }
Ravi Anandb93480e2008-04-03 13:13:25 -07003031 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003032 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003033 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003034
3035 if (rval == QLA_SUCCESS) {
3036 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003037 ql_dbg(ql_dbg_mbx, vha, 0x1085,
3038 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003039 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003040 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003041 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003042 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
3043 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003044 for ( ; dwords--; iter++)
3045 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003046 }
3047 } else {
3048 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003049 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003050 }
3051
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003052 return rval;
3053}
3054
3055int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003056qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07003057 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003058{
3059 int rval;
3060 mbx_cmd_t mc;
3061 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003062 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003063
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003064 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
3065 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003066
Quinn Tran15f30a52017-03-15 09:48:52 -07003067 memset(&mc, 0, sizeof(mc));
3068 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
3069 mc.mb[2] = MSW(stats_dma);
3070 mc.mb[3] = LSW(stats_dma);
3071 mc.mb[6] = MSW(MSD(stats_dma));
3072 mc.mb[7] = LSW(MSD(stats_dma));
3073 mc.mb[8] = sizeof(struct link_statistics) / 4;
3074 mc.mb[9] = cpu_to_le16(vha->vp_idx);
3075 mc.mb[10] = cpu_to_le16(options);
3076
3077 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003078
3079 if (rval == QLA_SUCCESS) {
3080 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003081 ql_dbg(ql_dbg_mbx, vha, 0x1089,
3082 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003083 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003084 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003085 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
3086 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003087 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003088 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003089 iter = &stats->link_fail_cnt;
3090 for ( ; dwords--; iter++)
3091 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003092 }
3093 } else {
3094 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003095 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003096 }
3097
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003098 return rval;
3099}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003100
3101int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003102qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003103{
3104 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003105 unsigned long flags = 0;
3106
3107 struct abort_entry_24xx *abt;
3108 dma_addr_t abt_dma;
3109 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003110 fc_port_t *fcport = sp->fcport;
3111 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003112 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003113 struct req_que *req = vha->req;
Quinn Tran585def92018-09-04 14:19:20 -07003114 struct qla_qpair *qpair = sp->qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003115
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003116 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
3117 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003118
Michael Hernandezd7459522016-12-12 14:40:07 -08003119 if (vha->flags.qpairs_available && sp->qpair)
3120 req = sp->qpair->req;
Quinn Tran585def92018-09-04 14:19:20 -07003121 else
3122 return QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08003123
Armen Baloyan4440e462014-02-26 04:15:18 -05003124 if (ql2xasynctmfenable)
3125 return qla24xx_async_abort_command(sp);
3126
Quinn Tran585def92018-09-04 14:19:20 -07003127 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003128 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003129 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003130 break;
3131 }
Quinn Tran585def92018-09-04 14:19:20 -07003132 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003133 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003134 /* Command not found. */
3135 return QLA_FUNCTION_FAILED;
3136 }
3137
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003138 abt = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003139 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003140 ql_log(ql_log_warn, vha, 0x108d,
3141 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003142 return QLA_MEMORY_ALLOC_FAILED;
3143 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003144
3145 abt->entry_type = ABORT_IOCB_TYPE;
3146 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003147 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003148 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07003149 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003150 abt->port_id[0] = fcport->d_id.b.al_pa;
3151 abt->port_id[1] = fcport->d_id.b.area;
3152 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003153 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003154
3155 abt->req_que_no = cpu_to_le16(req->id);
3156
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003157 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003158 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003159 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3160 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003161 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003162 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3163 "Failed to complete IOCB -- error status (%x).\n",
3164 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003165 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003166 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003167 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3168 "Failed to complete IOCB -- completion status (%x).\n",
3169 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003170 if (abt->nport_handle == CS_IOCB_ERROR)
3171 rval = QLA_FUNCTION_PARAMETER_ERROR;
3172 else
3173 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003174 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003175 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3176 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003177 }
3178
3179 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3180
3181 return rval;
3182}
3183
3184struct tsk_mgmt_cmd {
3185 union {
3186 struct tsk_mgmt_entry tsk;
3187 struct sts_entry_24xx sts;
3188 } p;
3189};
3190
Andrew Vasquez523ec772008-04-03 13:13:24 -07003191static int
3192__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003193 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003194{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003195 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003196 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003197 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003198 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003199 scsi_qla_host_t *vha;
3200 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003201 struct req_que *req;
Michael Hernandezd7459522016-12-12 14:40:07 -08003202 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003203
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003204 vha = fcport->vha;
3205 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003206 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003207
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003208 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3209 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003210
Michael Hernandezd7459522016-12-12 14:40:07 -08003211 if (vha->vp_idx && vha->qpair) {
3212 /* NPIV port */
3213 qpair = vha->qpair;
Michael Hernandezd7459522016-12-12 14:40:07 -08003214 req = qpair->req;
Michael Hernandezd7459522016-12-12 14:40:07 -08003215 }
3216
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003217 tsk = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003218 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003219 ql_log(ql_log_warn, vha, 0x1093,
3220 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003221 return QLA_MEMORY_ALLOC_FAILED;
3222 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003223
3224 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3225 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003226 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003227 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003228 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003229 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003230 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3231 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3232 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003233 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003234 if (type == TCF_LUN_RESET) {
3235 int_to_scsilun(l, &tsk->p.tsk.lun);
3236 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3237 sizeof(tsk->p.tsk.lun));
3238 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003239
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003240 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003241 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003242 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003243 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3244 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003245 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003246 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3247 "Failed to complete IOCB -- error status (%x).\n",
3248 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003249 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003250 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003251 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3252 "Failed to complete IOCB -- completion status (%x).\n",
3253 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003254 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003255 } else if (le16_to_cpu(sts->scsi_status) &
3256 SS_RESPONSE_INFO_LEN_VALID) {
3257 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003258 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003259 "Ignoring inconsistent data length -- not enough "
3260 "response info (%d).\n",
3261 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003262 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003263 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3264 "Failed to complete IOCB -- response (%x).\n",
3265 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003266 rval = QLA_FUNCTION_FAILED;
3267 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003268 }
3269
3270 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08003271 rval2 = qla2x00_marker(vha, ha->base_qpair, fcport->loop_id, l,
Bart Van Assche58e27532019-04-11 14:53:19 -07003272 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003273 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003274 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3275 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003276 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003277 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3278 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003279 }
3280
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003281 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003282
3283 return rval;
3284}
3285
Andrew Vasquez523ec772008-04-03 13:13:24 -07003286int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003287qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003288{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003289 struct qla_hw_data *ha = fcport->vha->hw;
3290
3291 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3292 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3293
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003294 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003295}
3296
3297int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003298qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003299{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003300 struct qla_hw_data *ha = fcport->vha->hw;
3301
3302 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3303 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3304
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003305 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003306}
3307
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003308int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003309qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003310{
3311 int rval;
3312 mbx_cmd_t mc;
3313 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003314 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003315
Andrew Vasquez68af0812008-05-12 22:21:13 -07003316 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003317 return QLA_FUNCTION_FAILED;
3318
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003319 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3320 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003321
3322 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3323 mcp->out_mb = MBX_0;
3324 mcp->in_mb = MBX_0;
3325 mcp->tov = 5;
3326 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003327 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003328
3329 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003330 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003331 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003332 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3333 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003334 }
3335
3336 return rval;
3337}
3338
Joe Carnucciodb64e932013-10-30 03:38:18 -04003339int
3340qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3341{
3342 int rval;
3343 mbx_cmd_t mc;
3344 mbx_cmd_t *mcp = &mc;
3345
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003346 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003347 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003348 return QLA_FUNCTION_FAILED;
3349
3350 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3351 "Entered %s.\n", __func__);
3352
3353 mcp->mb[0] = MBC_WRITE_SERDES;
3354 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003355 if (IS_QLA2031(vha->hw))
3356 mcp->mb[2] = data & 0xff;
3357 else
3358 mcp->mb[2] = data;
3359
Joe Carnucciodb64e932013-10-30 03:38:18 -04003360 mcp->mb[3] = 0;
3361 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3362 mcp->in_mb = MBX_0;
3363 mcp->tov = MBX_TOV_SECONDS;
3364 mcp->flags = 0;
3365 rval = qla2x00_mailbox_command(vha, mcp);
3366
3367 if (rval != QLA_SUCCESS) {
3368 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3369 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3370 } else {
3371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3372 "Done %s.\n", __func__);
3373 }
3374
3375 return rval;
3376}
3377
3378int
3379qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3380{
3381 int rval;
3382 mbx_cmd_t mc;
3383 mbx_cmd_t *mcp = &mc;
3384
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003385 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003386 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003387 return QLA_FUNCTION_FAILED;
3388
3389 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3390 "Entered %s.\n", __func__);
3391
3392 mcp->mb[0] = MBC_READ_SERDES;
3393 mcp->mb[1] = addr;
3394 mcp->mb[3] = 0;
3395 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3396 mcp->in_mb = MBX_1|MBX_0;
3397 mcp->tov = MBX_TOV_SECONDS;
3398 mcp->flags = 0;
3399 rval = qla2x00_mailbox_command(vha, mcp);
3400
Andrew Vasquez064135e2015-04-09 15:00:02 -04003401 if (IS_QLA2031(vha->hw))
3402 *data = mcp->mb[1] & 0xff;
3403 else
3404 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003405
3406 if (rval != QLA_SUCCESS) {
3407 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3408 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3409 } else {
3410 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3411 "Done %s.\n", __func__);
3412 }
3413
3414 return rval;
3415}
3416
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003417int
3418qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3419{
3420 int rval;
3421 mbx_cmd_t mc;
3422 mbx_cmd_t *mcp = &mc;
3423
3424 if (!IS_QLA8044(vha->hw))
3425 return QLA_FUNCTION_FAILED;
3426
Quinn Tran83548fe2017-06-02 09:12:01 -07003427 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003428 "Entered %s.\n", __func__);
3429
3430 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3431 mcp->mb[1] = HCS_WRITE_SERDES;
3432 mcp->mb[3] = LSW(addr);
3433 mcp->mb[4] = MSW(addr);
3434 mcp->mb[5] = LSW(data);
3435 mcp->mb[6] = MSW(data);
3436 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3437 mcp->in_mb = MBX_0;
3438 mcp->tov = MBX_TOV_SECONDS;
3439 mcp->flags = 0;
3440 rval = qla2x00_mailbox_command(vha, mcp);
3441
3442 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003443 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003444 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3445 } else {
3446 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3447 "Done %s.\n", __func__);
3448 }
3449
3450 return rval;
3451}
3452
3453int
3454qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3455{
3456 int rval;
3457 mbx_cmd_t mc;
3458 mbx_cmd_t *mcp = &mc;
3459
3460 if (!IS_QLA8044(vha->hw))
3461 return QLA_FUNCTION_FAILED;
3462
3463 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3464 "Entered %s.\n", __func__);
3465
3466 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3467 mcp->mb[1] = HCS_READ_SERDES;
3468 mcp->mb[3] = LSW(addr);
3469 mcp->mb[4] = MSW(addr);
3470 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3471 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3472 mcp->tov = MBX_TOV_SECONDS;
3473 mcp->flags = 0;
3474 rval = qla2x00_mailbox_command(vha, mcp);
3475
3476 *data = mcp->mb[2] << 16 | mcp->mb[1];
3477
3478 if (rval != QLA_SUCCESS) {
3479 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3480 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3481 } else {
3482 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3483 "Done %s.\n", __func__);
3484 }
3485
3486 return rval;
3487}
3488
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003489/**
3490 * qla2x00_set_serdes_params() -
Bart Van Assche2db62282018-01-23 16:33:51 -08003491 * @vha: HA context
Bart Van Assche807eb902018-10-18 15:45:41 -07003492 * @sw_em_1g: serial link options
3493 * @sw_em_2g: serial link options
3494 * @sw_em_4g: serial link options
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003495 *
3496 * Returns
3497 */
3498int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003499qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003500 uint16_t sw_em_2g, uint16_t sw_em_4g)
3501{
3502 int rval;
3503 mbx_cmd_t mc;
3504 mbx_cmd_t *mcp = &mc;
3505
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003506 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3507 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003508
3509 mcp->mb[0] = MBC_SERDES_PARAMS;
3510 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003511 mcp->mb[2] = sw_em_1g | BIT_15;
3512 mcp->mb[3] = sw_em_2g | BIT_15;
3513 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003514 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3515 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003516 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003517 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003518 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003519
3520 if (rval != QLA_SUCCESS) {
3521 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003522 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3523 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003524 } else {
3525 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003526 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3527 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003528 }
3529
3530 return rval;
3531}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003532
3533int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003534qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003535{
3536 int rval;
3537 mbx_cmd_t mc;
3538 mbx_cmd_t *mcp = &mc;
3539
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003540 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003541 return QLA_FUNCTION_FAILED;
3542
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003543 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3544 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003545
3546 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003547 mcp->mb[1] = 0;
3548 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003549 mcp->in_mb = MBX_0;
3550 mcp->tov = 5;
3551 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003552 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003553
3554 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003555 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003556 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3557 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003558 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003559 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3560 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003561 }
3562
3563 return rval;
3564}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003565
3566int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003567qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003568 uint16_t buffers)
3569{
3570 int rval;
3571 mbx_cmd_t mc;
3572 mbx_cmd_t *mcp = &mc;
3573
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003574 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3575 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003576
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003577 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003578 return QLA_FUNCTION_FAILED;
3579
Andrew Vasquez85880802009-12-15 21:29:46 -08003580 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3581 return QLA_FUNCTION_FAILED;
3582
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003583 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003584 mcp->mb[1] = TC_EFT_ENABLE;
3585 mcp->mb[2] = LSW(eft_dma);
3586 mcp->mb[3] = MSW(eft_dma);
3587 mcp->mb[4] = LSW(MSD(eft_dma));
3588 mcp->mb[5] = MSW(MSD(eft_dma));
3589 mcp->mb[6] = buffers;
3590 mcp->mb[7] = TC_AEN_DISABLE;
3591 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 -07003592 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003593 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003594 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003595 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003596 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003597 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3598 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3599 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003600 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003601 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3602 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003603 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003604
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003605 return rval;
3606}
3607
3608int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003609qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003610{
3611 int rval;
3612 mbx_cmd_t mc;
3613 mbx_cmd_t *mcp = &mc;
3614
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003615 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3616 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003617
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003618 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003619 return QLA_FUNCTION_FAILED;
3620
Andrew Vasquez85880802009-12-15 21:29:46 -08003621 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3622 return QLA_FUNCTION_FAILED;
3623
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003624 mcp->mb[0] = MBC_TRACE_CONTROL;
3625 mcp->mb[1] = TC_EFT_DISABLE;
3626 mcp->out_mb = MBX_1|MBX_0;
3627 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003628 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003629 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003630 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003631 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003632 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3633 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3634 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003635 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003636 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3637 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003638 }
3639
3640 return rval;
3641}
3642
Andrew Vasquez88729e52006-06-23 16:10:50 -07003643int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003644qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003645 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3646{
3647 int rval;
3648 mbx_cmd_t mc;
3649 mbx_cmd_t *mcp = &mc;
3650
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003651 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3652 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003653
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003654 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003655 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
3656 !IS_QLA28XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003657 return QLA_FUNCTION_FAILED;
3658
Andrew Vasquez85880802009-12-15 21:29:46 -08003659 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3660 return QLA_FUNCTION_FAILED;
3661
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003662 mcp->mb[0] = MBC_TRACE_CONTROL;
3663 mcp->mb[1] = TC_FCE_ENABLE;
3664 mcp->mb[2] = LSW(fce_dma);
3665 mcp->mb[3] = MSW(fce_dma);
3666 mcp->mb[4] = LSW(MSD(fce_dma));
3667 mcp->mb[5] = MSW(MSD(fce_dma));
3668 mcp->mb[6] = buffers;
3669 mcp->mb[7] = TC_AEN_DISABLE;
3670 mcp->mb[8] = 0;
3671 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3672 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3673 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3674 MBX_1|MBX_0;
3675 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003676 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003677 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003678 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003679 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003680 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3681 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3682 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003683 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003684 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3685 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003686
3687 if (mb)
3688 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3689 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003690 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003691 }
3692
3693 return rval;
3694}
3695
3696int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003697qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003698{
3699 int rval;
3700 mbx_cmd_t mc;
3701 mbx_cmd_t *mcp = &mc;
3702
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003703 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3704 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003705
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003706 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003707 return QLA_FUNCTION_FAILED;
3708
Andrew Vasquez85880802009-12-15 21:29:46 -08003709 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3710 return QLA_FUNCTION_FAILED;
3711
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003712 mcp->mb[0] = MBC_TRACE_CONTROL;
3713 mcp->mb[1] = TC_FCE_DISABLE;
3714 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3715 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3716 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3717 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003718 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003719 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003720 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003721 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003722 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3723 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3724 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003725 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003726 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3727 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003728
3729 if (wr)
3730 *wr = (uint64_t) mcp->mb[5] << 48 |
3731 (uint64_t) mcp->mb[4] << 32 |
3732 (uint64_t) mcp->mb[3] << 16 |
3733 (uint64_t) mcp->mb[2];
3734 if (rd)
3735 *rd = (uint64_t) mcp->mb[9] << 48 |
3736 (uint64_t) mcp->mb[8] << 32 |
3737 (uint64_t) mcp->mb[7] << 16 |
3738 (uint64_t) mcp->mb[6];
3739 }
3740
3741 return rval;
3742}
3743
3744int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003745qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3746 uint16_t *port_speed, uint16_t *mb)
3747{
3748 int rval;
3749 mbx_cmd_t mc;
3750 mbx_cmd_t *mcp = &mc;
3751
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003752 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3753 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003754
Giridhar Malavali6e980162010-03-19 17:03:58 -07003755 if (!IS_IIDMA_CAPABLE(vha->hw))
3756 return QLA_FUNCTION_FAILED;
3757
Giridhar Malavali6e980162010-03-19 17:03:58 -07003758 mcp->mb[0] = MBC_PORT_PARAMS;
3759 mcp->mb[1] = loop_id;
3760 mcp->mb[2] = mcp->mb[3] = 0;
3761 mcp->mb[9] = vha->vp_idx;
3762 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3763 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3764 mcp->tov = MBX_TOV_SECONDS;
3765 mcp->flags = 0;
3766 rval = qla2x00_mailbox_command(vha, mcp);
3767
3768 /* Return mailbox statuses. */
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003769 if (mb) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07003770 mb[0] = mcp->mb[0];
3771 mb[1] = mcp->mb[1];
3772 mb[3] = mcp->mb[3];
3773 }
3774
3775 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003776 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003777 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003778 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3779 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003780 if (port_speed)
3781 *port_speed = mcp->mb[3];
3782 }
3783
3784 return rval;
3785}
3786
3787int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003788qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003789 uint16_t port_speed, uint16_t *mb)
3790{
3791 int rval;
3792 mbx_cmd_t mc;
3793 mbx_cmd_t *mcp = &mc;
3794
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003795 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3796 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003797
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003798 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003799 return QLA_FUNCTION_FAILED;
3800
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003801 mcp->mb[0] = MBC_PORT_PARAMS;
3802 mcp->mb[1] = loop_id;
3803 mcp->mb[2] = BIT_0;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003804 mcp->mb[3] = port_speed & 0x3F;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003805 mcp->mb[9] = vha->vp_idx;
3806 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3807 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003808 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003809 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003810 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003811
3812 /* Return mailbox statuses. */
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003813 if (mb) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003814 mb[0] = mcp->mb[0];
3815 mb[1] = mcp->mb[1];
3816 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003817 }
3818
3819 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003820 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3821 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003822 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003823 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3824 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003825 }
3826
3827 return rval;
3828}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003829
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003830void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003831qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003832 struct vp_rpt_id_entry_24xx *rptid_entry)
3833{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003834 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003835 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003836 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003837 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003838 port_id_t id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08003839 struct fc_port *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003840
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003841 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3842 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003843
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003844 if (rptid_entry->entry_status != 0)
3845 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003846
Quinn Tran482c9dc2017-03-15 09:48:54 -07003847 id.b.domain = rptid_entry->port_id[2];
3848 id.b.area = rptid_entry->port_id[1];
3849 id.b.al_pa = rptid_entry->port_id[0];
3850 id.b.rsvd_1 = 0;
Darren Trapp1763c1f2018-03-20 23:09:34 -07003851 ha->flags.n2n_ae = 0;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003852
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003853 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003854 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003855 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003856 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003857 "VPs acquired %d.\n", rptid_entry->vp_setup,
3858 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003859 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003860 "Primary port id %02x%02x%02x.\n",
3861 rptid_entry->port_id[2], rptid_entry->port_id[1],
3862 rptid_entry->port_id[0]);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003863 ha->current_topology = ISP_CFG_NL;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003864 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003865
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003866 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003867 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003868 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003869 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003870 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3871 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003872 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003873 rptid_entry->port_id[0]);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003874 ql_dbg(ql_dbg_async, vha, 0x5075,
3875 "Format 1: Remote WWPN %8phC.\n",
3876 rptid_entry->u.f1.port_name);
3877
3878 ql_dbg(ql_dbg_async, vha, 0x5075,
3879 "Format 1: WWPN %8phC.\n",
3880 vha->port_name);
3881
Quinn Tran8777e432018-08-02 13:16:57 -07003882 switch (rptid_entry->u.f1.flags & TOPO_MASK) {
3883 case TOPO_N2N:
3884 ha->current_topology = ISP_CFG_N;
3885 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
Quinn Tran7f2a3982019-09-12 11:09:09 -07003886 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3887 fcport->scan_state = QLA_FCPORT_SCAN;
3888 fcport->n2n_flag = 0;
3889 }
3890
Quinn Tran8777e432018-08-02 13:16:57 -07003891 fcport = qla2x00_find_fcport_by_wwpn(vha,
3892 rptid_entry->u.f1.port_name, 1);
3893 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3894
3895 if (fcport) {
3896 fcport->plogi_nack_done_deadline = jiffies + HZ;
Quinn Tran7f2a3982019-09-12 11:09:09 -07003897 fcport->dm_login_expire = jiffies + 2*HZ;
Quinn Tran8777e432018-08-02 13:16:57 -07003898 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran7f2a3982019-09-12 11:09:09 -07003899 fcport->n2n_flag = 1;
Quinn Tranf3f19382019-09-12 11:09:10 -07003900 fcport->keep_nport_handle = 1;
Quinn Tran7f2a3982019-09-12 11:09:09 -07003901 if (vha->flags.nvme_enabled)
3902 fcport->fc4f_nvme = 1;
3903
Quinn Tran8777e432018-08-02 13:16:57 -07003904 switch (fcport->disc_state) {
3905 case DSC_DELETED:
3906 set_bit(RELOGIN_NEEDED,
3907 &vha->dpc_flags);
3908 break;
3909 case DSC_DELETE_PEND:
3910 break;
3911 default:
3912 qlt_schedule_sess_for_deletion(fcport);
3913 break;
3914 }
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003915 } else {
Quinn Tran8777e432018-08-02 13:16:57 -07003916 id.b24 = 0;
3917 if (wwn_to_u64(vha->port_name) >
3918 wwn_to_u64(rptid_entry->u.f1.port_name)) {
3919 vha->d_id.b24 = 0;
3920 vha->d_id.b.al_pa = 1;
3921 ha->flags.n2n_bigger = 1;
3922
3923 id.b.al_pa = 2;
3924 ql_dbg(ql_dbg_async, vha, 0x5075,
3925 "Format 1: assign local id %x remote id %x\n",
3926 vha->d_id.b24, id.b24);
3927 } else {
3928 ql_dbg(ql_dbg_async, vha, 0x5075,
3929 "Format 1: Remote login - Waiting for WWPN %8phC.\n",
3930 rptid_entry->u.f1.port_name);
3931 ha->flags.n2n_bigger = 0;
3932 }
3933 qla24xx_post_newsess_work(vha, &id,
3934 rptid_entry->u.f1.port_name,
3935 rptid_entry->u.f1.node_name,
3936 NULL,
Quinn Tran7f2a3982019-09-12 11:09:09 -07003937 FS_FCP_IS_N2N);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003938 }
3939
Quinn Tran8777e432018-08-02 13:16:57 -07003940 /* if our portname is higher then initiate N2N login */
3941
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003942 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
Darren Trapp1763c1f2018-03-20 23:09:34 -07003943 ha->flags.n2n_ae = 1;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003944 return;
Quinn Tran8777e432018-08-02 13:16:57 -07003945 break;
3946 case TOPO_FL:
3947 ha->current_topology = ISP_CFG_FL;
3948 break;
3949 case TOPO_F:
3950 ha->current_topology = ISP_CFG_F;
3951 break;
3952 default:
3953 break;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003954 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003955
Quinn Tran9cd883f2017-12-28 12:33:24 -08003956 ha->flags.gpsc_supported = 1;
3957 ha->current_topology = ISP_CFG_F;
Sawan Chandak969a6192016-01-27 12:03:32 -05003958 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003959 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003960
Quinn Tran41dc5292017-01-19 22:28:03 -08003961 if (rptid_entry->vp_idx == 0) {
3962 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3963 /* FA-WWN is only for physical port */
3964 if (qla_ini_mode_enabled(vha) &&
3965 ha->flags.fawwpn_enabled &&
3966 (rptid_entry->u.f1.flags &
Sawan Chandakfcc5b5c2017-08-23 15:05:02 -07003967 BIT_6)) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003968 memcpy(vha->port_name,
3969 rptid_entry->u.f1.port_name,
3970 WWN_SIZE);
3971 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003972
Quinn Tran482c9dc2017-03-15 09:48:54 -07003973 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003974 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003975
Quinn Tran41dc5292017-01-19 22:28:03 -08003976 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3977 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3978 } else {
3979 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3980 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3981 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3982 "Could not acquire ID for VP[%d].\n",
3983 rptid_entry->vp_idx);
3984 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003985 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003986
3987 found = 0;
3988 spin_lock_irqsave(&ha->vport_slock, flags);
3989 list_for_each_entry(vp, &ha->vp_list, list) {
3990 if (rptid_entry->vp_idx == vp->vp_idx) {
3991 found = 1;
3992 break;
3993 }
3994 }
3995 spin_unlock_irqrestore(&ha->vport_slock, flags);
3996
3997 if (!found)
3998 return;
3999
Quinn Tran482c9dc2017-03-15 09:48:54 -07004000 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08004001
4002 /*
4003 * Cannot configure here as we are still sitting on the
4004 * response queue. Handle it in dpc context.
4005 */
4006 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
4007 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
4008 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05004009 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07004010 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004011 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08004012 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004013 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08004014 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
4015 rptid_entry->port_id[2], rptid_entry->port_id[1],
4016 rptid_entry->port_id[0]);
4017
Quinn Tran83548fe2017-06-02 09:12:01 -07004018 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08004019 "N2N: Remote WWPN %8phC.\n",
4020 rptid_entry->u.f2.port_name);
4021
4022 /* N2N. direct connect */
Quinn Tran9cd883f2017-12-28 12:33:24 -08004023 ha->current_topology = ISP_CFG_N;
4024 ha->flags.rida_fmt2 = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004025 vha->d_id.b.domain = rptid_entry->port_id[2];
4026 vha->d_id.b.area = rptid_entry->port_id[1];
4027 vha->d_id.b.al_pa = rptid_entry->port_id[0];
4028
Darren Trapp1763c1f2018-03-20 23:09:34 -07004029 ha->flags.n2n_ae = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004030 spin_lock_irqsave(&ha->vport_slock, flags);
4031 qlt_update_vp_map(vha, SET_AL_PA);
4032 spin_unlock_irqrestore(&ha->vport_slock, flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004033
4034 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4035 fcport->scan_state = QLA_FCPORT_SCAN;
Quinn Tran7f2a3982019-09-12 11:09:09 -07004036 fcport->n2n_flag = 0;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004037 }
4038
4039 fcport = qla2x00_find_fcport_by_wwpn(vha,
4040 rptid_entry->u.f2.port_name, 1);
4041
4042 if (fcport) {
Quinn Tran23dd98a2018-08-02 13:16:45 -07004043 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004044 fcport->plogi_nack_done_deadline = jiffies + HZ;
4045 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tranf3f19382019-09-12 11:09:10 -07004046 fcport->keep_nport_handle = 1;
Quinn Tran7f2a3982019-09-12 11:09:09 -07004047 fcport->n2n_flag = 1;
4048 fcport->d_id.b.domain =
4049 rptid_entry->u.f2.remote_nport_id[2];
4050 fcport->d_id.b.area =
4051 rptid_entry->u.f2.remote_nport_id[1];
4052 fcport->d_id.b.al_pa =
4053 rptid_entry->u.f2.remote_nport_id[0];
Quinn Tran9cd883f2017-12-28 12:33:24 -08004054 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004055 }
4056}
4057
4058/*
4059 * qla24xx_modify_vp_config
4060 * Change VP configuration for vha
4061 *
4062 * Input:
4063 * vha = adapter block pointer.
4064 *
4065 * Returns:
4066 * qla2xxx local function return status code.
4067 *
4068 * Context:
4069 * Kernel context.
4070 */
4071int
4072qla24xx_modify_vp_config(scsi_qla_host_t *vha)
4073{
4074 int rval;
4075 struct vp_config_entry_24xx *vpmod;
4076 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004077 struct qla_hw_data *ha = vha->hw;
4078 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004079
4080 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004081
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
4083 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004084
Thomas Meyer08eb7f42017-09-21 08:15:26 +02004085 vpmod = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004086 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004087 ql_log(ql_log_warn, vha, 0x10bc,
4088 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004089 return QLA_MEMORY_ALLOC_FAILED;
4090 }
4091
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004092 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
4093 vpmod->entry_count = 1;
4094 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
4095 vpmod->vp_count = 1;
4096 vpmod->vp_index1 = vha->vp_idx;
4097 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004098
4099 qlt_modify_vp_config(vha, vpmod);
4100
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004101 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
4102 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
4103 vpmod->entry_count = 1;
4104
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004105 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004106 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004107 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
4108 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004109 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004110 ql_dbg(ql_dbg_mbx, vha, 0x10be,
4111 "Failed to complete IOCB -- error status (%x).\n",
4112 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004113 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07004114 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004115 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
4116 "Failed to complete IOCB -- completion status (%x).\n",
4117 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004118 rval = QLA_FUNCTION_FAILED;
4119 } else {
4120 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004121 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
4122 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004123 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
4124 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004125 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004126
4127 return rval;
4128}
4129
4130/*
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004131 * qla2x00_send_change_request
4132 * Receive or disable RSCN request from fabric controller
4133 *
4134 * Input:
4135 * ha = adapter block pointer
4136 * format = registration format:
4137 * 0 - Reserved
4138 * 1 - Fabric detected registration
4139 * 2 - N_port detected registration
4140 * 3 - Full registration
4141 * FF - clear registration
4142 * vp_idx = Virtual port index
4143 *
4144 * Returns:
4145 * qla2x00 local function return status code.
4146 *
4147 * Context:
4148 * Kernel Context
4149 */
4150
4151int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004152qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004153 uint16_t vp_idx)
4154{
4155 int rval;
4156 mbx_cmd_t mc;
4157 mbx_cmd_t *mcp = &mc;
4158
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004159 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
4160 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004161
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004162 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
4163 mcp->mb[1] = format;
4164 mcp->mb[9] = vp_idx;
4165 mcp->out_mb = MBX_9|MBX_1|MBX_0;
4166 mcp->in_mb = MBX_0|MBX_1;
4167 mcp->tov = MBX_TOV_SECONDS;
4168 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004169 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004170
4171 if (rval == QLA_SUCCESS) {
4172 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
4173 rval = BIT_1;
4174 }
4175 } else
4176 rval = BIT_1;
4177
4178 return rval;
4179}
Andrew Vasquez338c9162007-09-20 14:07:33 -07004180
4181int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004182qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07004183 uint32_t size)
4184{
4185 int rval;
4186 mbx_cmd_t mc;
4187 mbx_cmd_t *mcp = &mc;
4188
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004189 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
4190 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004191
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004192 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004193 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
4194 mcp->mb[8] = MSW(addr);
4195 mcp->out_mb = MBX_8|MBX_0;
4196 } else {
4197 mcp->mb[0] = MBC_DUMP_RISC_RAM;
4198 mcp->out_mb = MBX_0;
4199 }
4200 mcp->mb[1] = LSW(addr);
4201 mcp->mb[2] = MSW(req_dma);
4202 mcp->mb[3] = LSW(req_dma);
4203 mcp->mb[6] = MSW(MSD(req_dma));
4204 mcp->mb[7] = LSW(MSD(req_dma));
4205 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004206 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004207 mcp->mb[4] = MSW(size);
4208 mcp->mb[5] = LSW(size);
4209 mcp->out_mb |= MBX_5|MBX_4;
4210 } else {
4211 mcp->mb[4] = LSW(size);
4212 mcp->out_mb |= MBX_4;
4213 }
4214
4215 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004216 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004217 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004218 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004219
4220 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004221 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4222 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004223 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004224 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4225 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004226 }
4227
4228 return rval;
4229}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004230/* 84XX Support **************************************************************/
4231
4232struct cs84xx_mgmt_cmd {
4233 union {
4234 struct verify_chip_entry_84xx req;
4235 struct verify_chip_rsp_84xx rsp;
4236 } p;
4237};
4238
4239int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004240qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004241{
4242 int rval, retry;
4243 struct cs84xx_mgmt_cmd *mn;
4244 dma_addr_t mn_dma;
4245 uint16_t options;
4246 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004247 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004248
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4250 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251
4252 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4253 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004254 return QLA_MEMORY_ALLOC_FAILED;
4255 }
4256
4257 /* Force Update? */
4258 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4259 /* Diagnostic firmware? */
4260 /* options |= MENLO_DIAG_FW; */
4261 /* We update the firmware with only one data sequence. */
4262 options |= VCO_END_OF_DATA;
4263
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004264 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004265 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004266 memset(mn, 0, sizeof(*mn));
4267 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4268 mn->p.req.entry_count = 1;
4269 mn->p.req.options = cpu_to_le16(options);
4270
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004271 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4272 "Dump of Verify Request.\n");
4273 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07004274 mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004275
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004276 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004277 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004278 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4279 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004280 goto verify_done;
4281 }
4282
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004283 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4284 "Dump of Verify Response.\n");
4285 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07004286 mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004287
4288 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4289 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4290 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004291 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004292 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004293
4294 if (status[0] != CS_COMPLETE) {
4295 rval = QLA_FUNCTION_FAILED;
4296 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004297 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4298 "Firmware update failed. Retrying "
4299 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004300 options |= VCO_DONT_UPDATE_FW;
4301 options &= ~VCO_FORCE_UPDATE;
4302 retry = 1;
4303 }
4304 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004305 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004306 "Firmware updated to %x.\n",
4307 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004308
4309 /* NOTE: we only update OP firmware. */
4310 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4311 ha->cs84xx->op_fw_version =
4312 le32_to_cpu(mn->p.rsp.fw_ver);
4313 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4314 flags);
4315 }
4316 } while (retry);
4317
4318verify_done:
4319 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4320
4321 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004322 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4323 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004324 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004325 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4326 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004327 }
4328
4329 return rval;
4330}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004331
4332int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004333qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004334{
4335 int rval;
4336 unsigned long flags;
4337 mbx_cmd_t mc;
4338 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004339 struct qla_hw_data *ha = vha->hw;
4340
Quinn Tran45235022018-07-18 14:29:53 -07004341 if (!ha->flags.fw_started)
4342 return QLA_SUCCESS;
4343
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004344 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4345 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004346
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004347 if (IS_SHADOW_REG_CAPABLE(ha))
4348 req->options |= BIT_13;
4349
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004350 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004351 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004352 mcp->mb[2] = MSW(LSD(req->dma));
4353 mcp->mb[3] = LSW(LSD(req->dma));
4354 mcp->mb[6] = MSW(MSD(req->dma));
4355 mcp->mb[7] = LSW(MSD(req->dma));
4356 mcp->mb[5] = req->length;
4357 if (req->rsp)
4358 mcp->mb[10] = req->rsp->id;
4359 mcp->mb[12] = req->qos;
4360 mcp->mb[11] = req->vp_idx;
4361 mcp->mb[13] = req->rid;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004362 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004363 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004364
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004365 mcp->mb[4] = req->id;
4366 /* que in ptr index */
4367 mcp->mb[8] = 0;
4368 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004369 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004370 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4371 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4372 mcp->in_mb = MBX_0;
4373 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004374 mcp->tov = MBX_TOV_SECONDS * 2;
4375
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004376 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4377 IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004378 mcp->in_mb |= MBX_1;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004379 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004380 mcp->out_mb |= MBX_15;
4381 /* debug q create issue in SR-IOV */
4382 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4383 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004384
4385 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004386 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004387 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004388 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004389 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004390 }
4391 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4392
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004393 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004394 if (rval != QLA_SUCCESS) {
4395 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4396 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4397 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004398 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4399 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004400 }
4401
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004402 return rval;
4403}
4404
4405int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004406qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004407{
4408 int rval;
4409 unsigned long flags;
4410 mbx_cmd_t mc;
4411 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004412 struct qla_hw_data *ha = vha->hw;
4413
Quinn Tran45235022018-07-18 14:29:53 -07004414 if (!ha->flags.fw_started)
4415 return QLA_SUCCESS;
4416
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004417 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4418 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004419
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004420 if (IS_SHADOW_REG_CAPABLE(ha))
4421 rsp->options |= BIT_13;
4422
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004423 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004424 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004425 mcp->mb[2] = MSW(LSD(rsp->dma));
4426 mcp->mb[3] = LSW(LSD(rsp->dma));
4427 mcp->mb[6] = MSW(MSD(rsp->dma));
4428 mcp->mb[7] = LSW(MSD(rsp->dma));
4429 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004430 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004431 mcp->mb[13] = rsp->rid;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004432 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004433 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004434
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004435 mcp->mb[4] = rsp->id;
4436 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004437 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004438 /* que out ptr index */
4439 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004440 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004441 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4442 mcp->in_mb = MBX_0;
4443 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004444 mcp->tov = MBX_TOV_SECONDS * 2;
4445
4446 if (IS_QLA81XX(ha)) {
4447 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4448 mcp->in_mb |= MBX_1;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004449 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004450 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4451 mcp->in_mb |= MBX_1;
4452 /* debug q create issue in SR-IOV */
4453 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4454 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004455
4456 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004457 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004458 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004459 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004460 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004461 }
4462
4463 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4464
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004465 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004466 if (rval != QLA_SUCCESS) {
4467 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4468 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4469 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4471 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004472 }
4473
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004474 return rval;
4475}
4476
Andrew Vasquez8a659572009-02-08 20:50:12 -08004477int
4478qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4479{
4480 int rval;
4481 mbx_cmd_t mc;
4482 mbx_cmd_t *mcp = &mc;
4483
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004484 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4485 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004486
4487 mcp->mb[0] = MBC_IDC_ACK;
4488 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4489 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4490 mcp->in_mb = MBX_0;
4491 mcp->tov = MBX_TOV_SECONDS;
4492 mcp->flags = 0;
4493 rval = qla2x00_mailbox_command(vha, mcp);
4494
4495 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004496 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4497 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004498 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004499 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4500 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004501 }
4502
4503 return rval;
4504}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004505
4506int
4507qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4508{
4509 int rval;
4510 mbx_cmd_t mc;
4511 mbx_cmd_t *mcp = &mc;
4512
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004513 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4514 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004515
Chad Dupuisf73cb692014-02-26 04:15:06 -05004516 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004517 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004518 return QLA_FUNCTION_FAILED;
4519
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004520 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4521 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4522 mcp->out_mb = MBX_1|MBX_0;
4523 mcp->in_mb = MBX_1|MBX_0;
4524 mcp->tov = MBX_TOV_SECONDS;
4525 mcp->flags = 0;
4526 rval = qla2x00_mailbox_command(vha, mcp);
4527
4528 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004529 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4530 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4531 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004532 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4534 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004535 *sector_size = mcp->mb[1];
4536 }
4537
4538 return rval;
4539}
4540
4541int
4542qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4543{
4544 int rval;
4545 mbx_cmd_t mc;
4546 mbx_cmd_t *mcp = &mc;
4547
Chad Dupuisf73cb692014-02-26 04:15:06 -05004548 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004549 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004550 return QLA_FUNCTION_FAILED;
4551
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004552 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4553 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004554
4555 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4556 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4557 FAC_OPT_CMD_WRITE_PROTECT;
4558 mcp->out_mb = MBX_1|MBX_0;
4559 mcp->in_mb = MBX_1|MBX_0;
4560 mcp->tov = MBX_TOV_SECONDS;
4561 mcp->flags = 0;
4562 rval = qla2x00_mailbox_command(vha, mcp);
4563
4564 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004565 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4566 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4567 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004568 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4570 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004571 }
4572
4573 return rval;
4574}
4575
4576int
4577qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4578{
4579 int rval;
4580 mbx_cmd_t mc;
4581 mbx_cmd_t *mcp = &mc;
4582
Chad Dupuisf73cb692014-02-26 04:15:06 -05004583 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004584 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004585 return QLA_FUNCTION_FAILED;
4586
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004587 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4588 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004589
4590 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4591 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4592 mcp->mb[2] = LSW(start);
4593 mcp->mb[3] = MSW(start);
4594 mcp->mb[4] = LSW(finish);
4595 mcp->mb[5] = MSW(finish);
4596 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4597 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4598 mcp->tov = MBX_TOV_SECONDS;
4599 mcp->flags = 0;
4600 rval = qla2x00_mailbox_command(vha, mcp);
4601
4602 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004603 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4604 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4605 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004606 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004607 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4608 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004609 }
4610
4611 return rval;
4612}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004613
4614int
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004615qla81xx_fac_semaphore_access(scsi_qla_host_t *vha, int lock)
4616{
4617 int rval = QLA_SUCCESS;
4618 mbx_cmd_t mc;
4619 mbx_cmd_t *mcp = &mc;
4620 struct qla_hw_data *ha = vha->hw;
4621
4622 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
4623 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
4624 return rval;
4625
4626 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4627 "Entered %s.\n", __func__);
4628
4629 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4630 mcp->mb[1] = (lock ? FAC_OPT_CMD_LOCK_SEMAPHORE :
4631 FAC_OPT_CMD_UNLOCK_SEMAPHORE);
4632 mcp->out_mb = MBX_1|MBX_0;
4633 mcp->in_mb = MBX_1|MBX_0;
4634 mcp->tov = MBX_TOV_SECONDS;
4635 mcp->flags = 0;
4636 rval = qla2x00_mailbox_command(vha, mcp);
4637
4638 if (rval != QLA_SUCCESS) {
4639 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4640 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4641 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
4642 } else {
4643 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4644 "Done %s.\n", __func__);
4645 }
4646
4647 return rval;
4648}
4649
4650int
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004651qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4652{
4653 int rval = 0;
4654 mbx_cmd_t mc;
4655 mbx_cmd_t *mcp = &mc;
4656
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4658 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004659
4660 mcp->mb[0] = MBC_RESTART_MPI_FW;
4661 mcp->out_mb = MBX_0;
4662 mcp->in_mb = MBX_0|MBX_1;
4663 mcp->tov = MBX_TOV_SECONDS;
4664 mcp->flags = 0;
4665 rval = qla2x00_mailbox_command(vha, mcp);
4666
4667 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004668 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4669 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4670 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004671 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004672 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4673 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004674 }
4675
4676 return rval;
4677}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004678
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004679int
4680qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4681{
4682 int rval;
4683 mbx_cmd_t mc;
4684 mbx_cmd_t *mcp = &mc;
4685 int i;
4686 int len;
4687 uint16_t *str;
4688 struct qla_hw_data *ha = vha->hw;
4689
4690 if (!IS_P3P_TYPE(ha))
4691 return QLA_FUNCTION_FAILED;
4692
4693 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4694 "Entered %s.\n", __func__);
4695
4696 str = (void *)version;
4697 len = strlen(version);
4698
4699 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4700 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4701 mcp->out_mb = MBX_1|MBX_0;
4702 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4703 mcp->mb[i] = cpu_to_le16p(str);
4704 mcp->out_mb |= 1<<i;
4705 }
4706 for (; i < 16; i++) {
4707 mcp->mb[i] = 0;
4708 mcp->out_mb |= 1<<i;
4709 }
4710 mcp->in_mb = MBX_1|MBX_0;
4711 mcp->tov = MBX_TOV_SECONDS;
4712 mcp->flags = 0;
4713 rval = qla2x00_mailbox_command(vha, mcp);
4714
4715 if (rval != QLA_SUCCESS) {
4716 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4717 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4718 } else {
4719 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4720 "Done %s.\n", __func__);
4721 }
4722
4723 return rval;
4724}
4725
4726int
4727qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4728{
4729 int rval;
4730 mbx_cmd_t mc;
4731 mbx_cmd_t *mcp = &mc;
4732 int len;
4733 uint16_t dwlen;
4734 uint8_t *str;
4735 dma_addr_t str_dma;
4736 struct qla_hw_data *ha = vha->hw;
4737
4738 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4739 IS_P3P_TYPE(ha))
4740 return QLA_FUNCTION_FAILED;
4741
4742 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4743 "Entered %s.\n", __func__);
4744
4745 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4746 if (!str) {
4747 ql_log(ql_log_warn, vha, 0x117f,
4748 "Failed to allocate driver version param.\n");
4749 return QLA_MEMORY_ALLOC_FAILED;
4750 }
4751
4752 memcpy(str, "\x7\x3\x11\x0", 4);
4753 dwlen = str[0];
4754 len = dwlen * 4 - 4;
4755 memset(str + 4, 0, len);
4756 if (len > strlen(version))
4757 len = strlen(version);
4758 memcpy(str + 4, version, len);
4759
4760 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4761 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4762 mcp->mb[2] = MSW(LSD(str_dma));
4763 mcp->mb[3] = LSW(LSD(str_dma));
4764 mcp->mb[6] = MSW(MSD(str_dma));
4765 mcp->mb[7] = LSW(MSD(str_dma));
4766 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4767 mcp->in_mb = MBX_1|MBX_0;
4768 mcp->tov = MBX_TOV_SECONDS;
4769 mcp->flags = 0;
4770 rval = qla2x00_mailbox_command(vha, mcp);
4771
4772 if (rval != QLA_SUCCESS) {
4773 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4774 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4775 } else {
4776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4777 "Done %s.\n", __func__);
4778 }
4779
4780 dma_pool_free(ha->s_dma_pool, str, str_dma);
4781
4782 return rval;
4783}
4784
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004785int
4786qla24xx_get_port_login_templ(scsi_qla_host_t *vha, dma_addr_t buf_dma,
4787 void *buf, uint16_t bufsiz)
4788{
4789 int rval, i;
4790 mbx_cmd_t mc;
4791 mbx_cmd_t *mcp = &mc;
4792 uint32_t *bp;
4793
4794 if (!IS_FWI2_CAPABLE(vha->hw))
4795 return QLA_FUNCTION_FAILED;
4796
4797 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4798 "Entered %s.\n", __func__);
4799
4800 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4801 mcp->mb[1] = RNID_TYPE_PORT_LOGIN << 8;
4802 mcp->mb[2] = MSW(buf_dma);
4803 mcp->mb[3] = LSW(buf_dma);
4804 mcp->mb[6] = MSW(MSD(buf_dma));
4805 mcp->mb[7] = LSW(MSD(buf_dma));
4806 mcp->mb[8] = bufsiz/4;
4807 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4808 mcp->in_mb = MBX_1|MBX_0;
4809 mcp->tov = MBX_TOV_SECONDS;
4810 mcp->flags = 0;
4811 rval = qla2x00_mailbox_command(vha, mcp);
4812
4813 if (rval != QLA_SUCCESS) {
4814 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4815 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4816 } else {
4817 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4818 "Done %s.\n", __func__);
4819 bp = (uint32_t *) buf;
4820 for (i = 0; i < (bufsiz-4)/4; i++, bp++)
Quinn Tran8777e432018-08-02 13:16:57 -07004821 *bp = le32_to_cpu(*bp);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004822 }
4823
4824 return rval;
4825}
4826
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004827static int
4828qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4829{
4830 int rval;
4831 mbx_cmd_t mc;
4832 mbx_cmd_t *mcp = &mc;
4833
4834 if (!IS_FWI2_CAPABLE(vha->hw))
4835 return QLA_FUNCTION_FAILED;
4836
4837 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4838 "Entered %s.\n", __func__);
4839
4840 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4841 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4842 mcp->out_mb = MBX_1|MBX_0;
4843 mcp->in_mb = MBX_1|MBX_0;
4844 mcp->tov = MBX_TOV_SECONDS;
4845 mcp->flags = 0;
4846 rval = qla2x00_mailbox_command(vha, mcp);
4847 *temp = mcp->mb[1];
4848
4849 if (rval != QLA_SUCCESS) {
4850 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4851 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4852 } else {
4853 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4854 "Done %s.\n", __func__);
4855 }
4856
4857 return rval;
4858}
4859
Joe Carnuccio3a117112013-02-08 01:58:00 -05004860int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004861qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4862 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004863{
4864 int rval;
4865 mbx_cmd_t mc;
4866 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004867 struct qla_hw_data *ha = vha->hw;
4868
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004869 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4870 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004871
Joe Carnuccio6766df92011-05-10 11:30:15 -07004872 if (!IS_FWI2_CAPABLE(ha))
4873 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004874
Joe Carnuccio6766df92011-05-10 11:30:15 -07004875 if (len == 1)
4876 opt |= BIT_0;
4877
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004878 mcp->mb[0] = MBC_READ_SFP;
4879 mcp->mb[1] = dev;
4880 mcp->mb[2] = MSW(sfp_dma);
4881 mcp->mb[3] = LSW(sfp_dma);
4882 mcp->mb[6] = MSW(MSD(sfp_dma));
4883 mcp->mb[7] = LSW(MSD(sfp_dma));
4884 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004885 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004886 mcp->mb[10] = opt;
4887 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 -07004888 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004889 mcp->tov = MBX_TOV_SECONDS;
4890 mcp->flags = 0;
4891 rval = qla2x00_mailbox_command(vha, mcp);
4892
4893 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004894 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004895
4896 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004897 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4898 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07004899 if (mcp->mb[0] == MBS_COMMAND_ERROR && mcp->mb[1] == 0x22) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004900 /* sfp is not there */
4901 rval = QLA_INTERFACE_ERROR;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07004902 }
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004903 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4905 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004906 }
4907
4908 return rval;
4909}
4910
4911int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004912qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4913 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004914{
4915 int rval;
4916 mbx_cmd_t mc;
4917 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004918 struct qla_hw_data *ha = vha->hw;
4919
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004920 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4921 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004922
Joe Carnuccio6766df92011-05-10 11:30:15 -07004923 if (!IS_FWI2_CAPABLE(ha))
4924 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004925
Joe Carnuccio6766df92011-05-10 11:30:15 -07004926 if (len == 1)
4927 opt |= BIT_0;
4928
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004929 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004930 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004931
4932 mcp->mb[0] = MBC_WRITE_SFP;
4933 mcp->mb[1] = dev;
4934 mcp->mb[2] = MSW(sfp_dma);
4935 mcp->mb[3] = LSW(sfp_dma);
4936 mcp->mb[6] = MSW(MSD(sfp_dma));
4937 mcp->mb[7] = LSW(MSD(sfp_dma));
4938 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004939 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004940 mcp->mb[10] = opt;
4941 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 -07004942 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004943 mcp->tov = MBX_TOV_SECONDS;
4944 mcp->flags = 0;
4945 rval = qla2x00_mailbox_command(vha, mcp);
4946
4947 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004948 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4949 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004950 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004951 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4952 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004953 }
4954
4955 return rval;
4956}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004957
4958int
4959qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4960 uint16_t size_in_bytes, uint16_t *actual_size)
4961{
4962 int rval;
4963 mbx_cmd_t mc;
4964 mbx_cmd_t *mcp = &mc;
4965
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004966 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4967 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004968
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004969 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004970 return QLA_FUNCTION_FAILED;
4971
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004972 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4973 mcp->mb[2] = MSW(stats_dma);
4974 mcp->mb[3] = LSW(stats_dma);
4975 mcp->mb[6] = MSW(MSD(stats_dma));
4976 mcp->mb[7] = LSW(MSD(stats_dma));
4977 mcp->mb[8] = size_in_bytes >> 2;
4978 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4979 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4980 mcp->tov = MBX_TOV_SECONDS;
4981 mcp->flags = 0;
4982 rval = qla2x00_mailbox_command(vha, mcp);
4983
4984 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004985 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4986 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4987 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004988 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004989 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4990 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004991
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004992
4993 *actual_size = mcp->mb[2] << 2;
4994 }
4995
4996 return rval;
4997}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004998
4999int
5000qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
5001 uint16_t size)
5002{
5003 int rval;
5004 mbx_cmd_t mc;
5005 mbx_cmd_t *mcp = &mc;
5006
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
5008 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005009
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005010 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005011 return QLA_FUNCTION_FAILED;
5012
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005013 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
5014 mcp->mb[1] = 0;
5015 mcp->mb[2] = MSW(tlv_dma);
5016 mcp->mb[3] = LSW(tlv_dma);
5017 mcp->mb[6] = MSW(MSD(tlv_dma));
5018 mcp->mb[7] = LSW(MSD(tlv_dma));
5019 mcp->mb[8] = size;
5020 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5021 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5022 mcp->tov = MBX_TOV_SECONDS;
5023 mcp->flags = 0;
5024 rval = qla2x00_mailbox_command(vha, mcp);
5025
5026 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005027 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
5028 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
5029 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005030 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005031 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
5032 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005033 }
5034
5035 return rval;
5036}
Andrew Vasquez18e75552009-06-03 09:55:30 -07005037
5038int
5039qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
5040{
5041 int rval;
5042 mbx_cmd_t mc;
5043 mbx_cmd_t *mcp = &mc;
5044
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005045 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
5046 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005047
Andrew Vasquez18e75552009-06-03 09:55:30 -07005048 if (!IS_FWI2_CAPABLE(vha->hw))
5049 return QLA_FUNCTION_FAILED;
5050
Andrew Vasquez18e75552009-06-03 09:55:30 -07005051 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
5052 mcp->mb[1] = LSW(risc_addr);
5053 mcp->mb[8] = MSW(risc_addr);
5054 mcp->out_mb = MBX_8|MBX_1|MBX_0;
5055 mcp->in_mb = MBX_3|MBX_2|MBX_0;
5056 mcp->tov = 30;
5057 mcp->flags = 0;
5058 rval = qla2x00_mailbox_command(vha, mcp);
5059 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005060 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
5061 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005062 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005063 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
5064 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005065 *data = mcp->mb[3] << 16 | mcp->mb[2];
5066 }
5067
5068 return rval;
5069}
5070
5071int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005072qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5073 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005074{
5075 int rval;
5076 mbx_cmd_t mc;
5077 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005078
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005079 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
5080 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005081
5082 memset(mcp->mb, 0 , sizeof(mcp->mb));
5083 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
5084 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
5085
5086 /* transfer count */
5087 mcp->mb[10] = LSW(mreq->transfer_size);
5088 mcp->mb[11] = MSW(mreq->transfer_size);
5089
5090 /* send data address */
5091 mcp->mb[14] = LSW(mreq->send_dma);
5092 mcp->mb[15] = MSW(mreq->send_dma);
5093 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5094 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5095
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005096 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005097 mcp->mb[16] = LSW(mreq->rcv_dma);
5098 mcp->mb[17] = MSW(mreq->rcv_dma);
5099 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5100 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5101
5102 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04005103 mcp->mb[18] = LSW(mreq->iteration_count);
5104 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005105
5106 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
5107 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 -08005108 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005109 mcp->out_mb |= MBX_2;
5110 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
5111
5112 mcp->buf_size = mreq->transfer_size;
5113 mcp->tov = MBX_TOV_SECONDS;
5114 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5115
5116 rval = qla2x00_mailbox_command(vha, mcp);
5117
5118 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005119 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
5120 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
5121 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
5122 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005123 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005124 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
5125 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005126 }
5127
5128 /* Copy mailbox information */
5129 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005130 return rval;
5131}
5132
5133int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005134qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5135 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005136{
5137 int rval;
5138 mbx_cmd_t mc;
5139 mbx_cmd_t *mcp = &mc;
5140 struct qla_hw_data *ha = vha->hw;
5141
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005142 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
5143 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005144
5145 memset(mcp->mb, 0 , sizeof(mcp->mb));
5146 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07005147 /* BIT_6 specifies 64bit address */
5148 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005149 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005150 mcp->mb[2] = vha->fcoe_fcf_idx;
5151 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005152 mcp->mb[16] = LSW(mreq->rcv_dma);
5153 mcp->mb[17] = MSW(mreq->rcv_dma);
5154 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5155 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5156
5157 mcp->mb[10] = LSW(mreq->transfer_size);
5158
5159 mcp->mb[14] = LSW(mreq->send_dma);
5160 mcp->mb[15] = MSW(mreq->send_dma);
5161 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5162 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5163
5164 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
5165 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005166 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005167 mcp->out_mb |= MBX_2;
5168
5169 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005170 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
5171 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005172 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005173 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005174 mcp->in_mb |= MBX_3;
5175
5176 mcp->tov = MBX_TOV_SECONDS;
5177 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5178 mcp->buf_size = mreq->transfer_size;
5179
5180 rval = qla2x00_mailbox_command(vha, mcp);
5181
5182 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005183 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
5184 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5185 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005186 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005187 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
5188 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005189 }
5190
5191 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005192 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005193 return rval;
5194}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005195
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005196int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005197qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005198{
5199 int rval;
5200 mbx_cmd_t mc;
5201 mbx_cmd_t *mcp = &mc;
5202
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005203 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005204 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005205
5206 mcp->mb[0] = MBC_ISP84XX_RESET;
5207 mcp->mb[1] = enable_diagnostic;
5208 mcp->out_mb = MBX_1|MBX_0;
5209 mcp->in_mb = MBX_1|MBX_0;
5210 mcp->tov = MBX_TOV_SECONDS;
5211 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005212 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005213
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005214 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005215 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005216 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005217 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
5218 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005219
5220 return rval;
5221}
5222
5223int
Andrew Vasquez18e75552009-06-03 09:55:30 -07005224qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
5225{
5226 int rval;
5227 mbx_cmd_t mc;
5228 mbx_cmd_t *mcp = &mc;
5229
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005230 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
5231 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005232
Andrew Vasquez18e75552009-06-03 09:55:30 -07005233 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005234 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005235
Andrew Vasquez18e75552009-06-03 09:55:30 -07005236 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
5237 mcp->mb[1] = LSW(risc_addr);
5238 mcp->mb[2] = LSW(data);
5239 mcp->mb[3] = MSW(data);
5240 mcp->mb[8] = MSW(risc_addr);
5241 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07005242 mcp->in_mb = MBX_1|MBX_0;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005243 mcp->tov = 30;
5244 mcp->flags = 0;
5245 rval = qla2x00_mailbox_command(vha, mcp);
5246 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005247 ql_dbg(ql_dbg_mbx, vha, 0x1101,
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07005248 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5249 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005250 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005251 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
5252 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005253 }
5254
5255 return rval;
5256}
Michael Hernandez3064ff32009-12-15 21:29:44 -08005257
5258int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005259qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
5260{
5261 int rval;
5262 uint32_t stat, timer;
5263 uint16_t mb0 = 0;
5264 struct qla_hw_data *ha = vha->hw;
5265 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5266
5267 rval = QLA_SUCCESS;
5268
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005269 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
5270 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005271
5272 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
5273
5274 /* Write the MBC data to the registers */
5275 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
5276 WRT_REG_WORD(&reg->mailbox1, mb[0]);
5277 WRT_REG_WORD(&reg->mailbox2, mb[1]);
5278 WRT_REG_WORD(&reg->mailbox3, mb[2]);
5279 WRT_REG_WORD(&reg->mailbox4, mb[3]);
5280
5281 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
5282
5283 /* Poll for MBC interrupt */
5284 for (timer = 6000000; timer; timer--) {
5285 /* Check for pending interrupts. */
5286 stat = RD_REG_DWORD(&reg->host_status);
5287 if (stat & HSRX_RISC_INT) {
5288 stat &= 0xff;
5289
5290 if (stat == 0x1 || stat == 0x2 ||
5291 stat == 0x10 || stat == 0x11) {
5292 set_bit(MBX_INTERRUPT,
5293 &ha->mbx_cmd_flags);
5294 mb0 = RD_REG_WORD(&reg->mailbox0);
5295 WRT_REG_DWORD(&reg->hccr,
5296 HCCRX_CLR_RISC_INT);
5297 RD_REG_DWORD(&reg->hccr);
5298 break;
5299 }
5300 }
5301 udelay(5);
5302 }
5303
5304 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5305 rval = mb0 & MBS_MASK;
5306 else
5307 rval = QLA_FUNCTION_FAILED;
5308
5309 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005310 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5311 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005312 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005313 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5314 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005315 }
5316
5317 return rval;
5318}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005319
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005320/* Set the specified data rate */
5321int
5322qla2x00_set_data_rate(scsi_qla_host_t *vha, uint16_t mode)
5323{
5324 int rval;
5325 mbx_cmd_t mc;
5326 mbx_cmd_t *mcp = &mc;
5327 struct qla_hw_data *ha = vha->hw;
5328 uint16_t val;
5329
5330 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5331 "Entered %s speed:0x%x mode:0x%x.\n", __func__, ha->set_data_rate,
5332 mode);
5333
5334 if (!IS_FWI2_CAPABLE(ha))
5335 return QLA_FUNCTION_FAILED;
5336
5337 memset(mcp, 0, sizeof(*mcp));
5338 switch (ha->set_data_rate) {
5339 case PORT_SPEED_AUTO:
5340 case PORT_SPEED_4GB:
5341 case PORT_SPEED_8GB:
5342 case PORT_SPEED_16GB:
5343 case PORT_SPEED_32GB:
5344 val = ha->set_data_rate;
5345 break;
5346 default:
5347 ql_log(ql_log_warn, vha, 0x1199,
5348 "Unrecognized speed setting:%d. Setting Autoneg\n",
5349 ha->set_data_rate);
5350 val = ha->set_data_rate = PORT_SPEED_AUTO;
5351 break;
5352 }
5353
5354 mcp->mb[0] = MBC_DATA_RATE;
5355 mcp->mb[1] = mode;
5356 mcp->mb[2] = val;
5357
5358 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5359 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005360 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005361 mcp->in_mb |= MBX_4|MBX_3;
5362 mcp->tov = MBX_TOV_SECONDS;
5363 mcp->flags = 0;
5364 rval = qla2x00_mailbox_command(vha, mcp);
5365 if (rval != QLA_SUCCESS) {
5366 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5367 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5368 } else {
5369 if (mcp->mb[1] != 0x7)
5370 ql_dbg(ql_dbg_mbx, vha, 0x1179,
5371 "Speed set:0x%x\n", mcp->mb[1]);
5372
5373 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5374 "Done %s.\n", __func__);
5375 }
5376
5377 return rval;
5378}
5379
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005380int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005381qla2x00_get_data_rate(scsi_qla_host_t *vha)
5382{
5383 int rval;
5384 mbx_cmd_t mc;
5385 mbx_cmd_t *mcp = &mc;
5386 struct qla_hw_data *ha = vha->hw;
5387
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005388 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5389 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005390
Michael Hernandez3064ff32009-12-15 21:29:44 -08005391 if (!IS_FWI2_CAPABLE(ha))
5392 return QLA_FUNCTION_FAILED;
5393
Michael Hernandez3064ff32009-12-15 21:29:44 -08005394 mcp->mb[0] = MBC_DATA_RATE;
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005395 mcp->mb[1] = QLA_GET_DATA_RATE;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005396 mcp->out_mb = MBX_1|MBX_0;
5397 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005398 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005399 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005400 mcp->tov = MBX_TOV_SECONDS;
5401 mcp->flags = 0;
5402 rval = qla2x00_mailbox_command(vha, mcp);
5403 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005404 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5405 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005406 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005407 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5408 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005409 if (mcp->mb[1] != 0x7)
5410 ha->link_data_rate = mcp->mb[1];
5411 }
5412
5413 return rval;
5414}
Sarang Radke09ff7012010-03-19 17:03:59 -07005415
5416int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005417qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5418{
5419 int rval;
5420 mbx_cmd_t mc;
5421 mbx_cmd_t *mcp = &mc;
5422 struct qla_hw_data *ha = vha->hw;
5423
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005424 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5425 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005426
Chad Dupuisf73cb692014-02-26 04:15:06 -05005427 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005428 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005429 return QLA_FUNCTION_FAILED;
5430 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5431 mcp->out_mb = MBX_0;
5432 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5433 mcp->tov = MBX_TOV_SECONDS;
5434 mcp->flags = 0;
5435
5436 rval = qla2x00_mailbox_command(vha, mcp);
5437
5438 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005439 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5440 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005441 } else {
5442 /* Copy all bits to preserve original value */
5443 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5444
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005445 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5446 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005447 }
5448 return rval;
5449}
5450
5451int
5452qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5453{
5454 int rval;
5455 mbx_cmd_t mc;
5456 mbx_cmd_t *mcp = &mc;
5457
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005458 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5459 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005460
5461 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5462 /* Copy all bits to preserve original setting */
5463 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5464 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5465 mcp->in_mb = MBX_0;
5466 mcp->tov = MBX_TOV_SECONDS;
5467 mcp->flags = 0;
5468 rval = qla2x00_mailbox_command(vha, mcp);
5469
5470 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005471 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5472 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005473 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005474 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5475 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005476
5477 return rval;
5478}
5479
5480
5481int
Sarang Radke09ff7012010-03-19 17:03:59 -07005482qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5483 uint16_t *mb)
5484{
5485 int rval;
5486 mbx_cmd_t mc;
5487 mbx_cmd_t *mcp = &mc;
5488 struct qla_hw_data *ha = vha->hw;
5489
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005490 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5491 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005492
Sarang Radke09ff7012010-03-19 17:03:59 -07005493 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5494 return QLA_FUNCTION_FAILED;
5495
Sarang Radke09ff7012010-03-19 17:03:59 -07005496 mcp->mb[0] = MBC_PORT_PARAMS;
5497 mcp->mb[1] = loop_id;
5498 if (ha->flags.fcp_prio_enabled)
5499 mcp->mb[2] = BIT_1;
5500 else
5501 mcp->mb[2] = BIT_2;
5502 mcp->mb[4] = priority & 0xf;
5503 mcp->mb[9] = vha->vp_idx;
5504 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5505 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5506 mcp->tov = 30;
5507 mcp->flags = 0;
5508 rval = qla2x00_mailbox_command(vha, mcp);
5509 if (mb != NULL) {
5510 mb[0] = mcp->mb[0];
5511 mb[1] = mcp->mb[1];
5512 mb[3] = mcp->mb[3];
5513 mb[4] = mcp->mb[4];
5514 }
5515
5516 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005517 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005518 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005519 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5520 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005521 }
5522
5523 return rval;
5524}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005525
5526int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005527qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005528{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005529 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005530 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005531 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005532
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005533 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5534 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5535 "Thermal not supported by this card.\n");
5536 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005537 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005538
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005539 if (IS_QLA25XX(ha)) {
5540 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5541 ha->pdev->subsystem_device == 0x0175) {
5542 rval = qla2x00_read_sfp(vha, 0, &byte,
5543 0x98, 0x1, 1, BIT_13|BIT_0);
5544 *temp = byte;
5545 return rval;
5546 }
5547 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5548 ha->pdev->subsystem_device == 0x338e) {
5549 rval = qla2x00_read_sfp(vha, 0, &byte,
5550 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5551 *temp = byte;
5552 return rval;
5553 }
5554 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5555 "Thermal not supported by this card.\n");
5556 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005557 }
5558
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005559 if (IS_QLA82XX(ha)) {
5560 *temp = qla82xx_read_temperature(vha);
5561 rval = QLA_SUCCESS;
5562 return rval;
5563 } else if (IS_QLA8044(ha)) {
5564 *temp = qla8044_read_temperature(vha);
5565 rval = QLA_SUCCESS;
5566 return rval;
5567 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005568
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005569 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005570 return rval;
5571}
5572
5573int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005574qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5575{
5576 int rval;
5577 struct qla_hw_data *ha = vha->hw;
5578 mbx_cmd_t mc;
5579 mbx_cmd_t *mcp = &mc;
5580
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005581 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5582 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005583
Giridhar Malavalia9083012010-04-12 17:59:55 -07005584 if (!IS_FWI2_CAPABLE(ha))
5585 return QLA_FUNCTION_FAILED;
5586
Giridhar Malavalia9083012010-04-12 17:59:55 -07005587 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005588 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005589 mcp->mb[1] = 1;
5590
5591 mcp->out_mb = MBX_1|MBX_0;
5592 mcp->in_mb = MBX_0;
5593 mcp->tov = 30;
5594 mcp->flags = 0;
5595
5596 rval = qla2x00_mailbox_command(vha, mcp);
5597 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005598 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5599 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005600 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005601 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5602 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005603 }
5604
5605 return rval;
5606}
5607
5608int
5609qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5610{
5611 int rval;
5612 struct qla_hw_data *ha = vha->hw;
5613 mbx_cmd_t mc;
5614 mbx_cmd_t *mcp = &mc;
5615
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005616 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5617 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005618
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005619 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005620 return QLA_FUNCTION_FAILED;
5621
Giridhar Malavalia9083012010-04-12 17:59:55 -07005622 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005623 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005624 mcp->mb[1] = 0;
5625
5626 mcp->out_mb = MBX_1|MBX_0;
5627 mcp->in_mb = MBX_0;
5628 mcp->tov = 30;
5629 mcp->flags = 0;
5630
5631 rval = qla2x00_mailbox_command(vha, mcp);
5632 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005633 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5634 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005635 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005636 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5637 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005638 }
5639
5640 return rval;
5641}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005642
5643int
5644qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5645{
5646 struct qla_hw_data *ha = vha->hw;
5647 mbx_cmd_t mc;
5648 mbx_cmd_t *mcp = &mc;
5649 int rval = QLA_FUNCTION_FAILED;
5650
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005651 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5652 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005653
5654 memset(mcp->mb, 0 , sizeof(mcp->mb));
5655 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5656 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5657 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5658 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5659
5660 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5661 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5662 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5663
5664 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5665 mcp->tov = MBX_TOV_SECONDS;
5666 rval = qla2x00_mailbox_command(vha, mcp);
5667
5668 /* Always copy back return mailbox values. */
5669 if (rval != QLA_SUCCESS) {
5670 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5671 "mailbox command FAILED=0x%x, subcode=%x.\n",
5672 (mcp->mb[1] << 16) | mcp->mb[0],
5673 (mcp->mb[3] << 16) | mcp->mb[2]);
5674 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005675 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5676 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005677 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5678 if (!ha->md_template_size) {
5679 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5680 "Null template size obtained.\n");
5681 rval = QLA_FUNCTION_FAILED;
5682 }
5683 }
5684 return rval;
5685}
5686
5687int
5688qla82xx_md_get_template(scsi_qla_host_t *vha)
5689{
5690 struct qla_hw_data *ha = vha->hw;
5691 mbx_cmd_t mc;
5692 mbx_cmd_t *mcp = &mc;
5693 int rval = QLA_FUNCTION_FAILED;
5694
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005695 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5696 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005697
5698 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5699 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5700 if (!ha->md_tmplt_hdr) {
5701 ql_log(ql_log_warn, vha, 0x1124,
5702 "Unable to allocate memory for Minidump template.\n");
5703 return rval;
5704 }
5705
5706 memset(mcp->mb, 0 , sizeof(mcp->mb));
5707 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5708 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5709 mcp->mb[2] = LSW(RQST_TMPLT);
5710 mcp->mb[3] = MSW(RQST_TMPLT);
5711 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5712 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5713 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5714 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5715 mcp->mb[8] = LSW(ha->md_template_size);
5716 mcp->mb[9] = MSW(ha->md_template_size);
5717
5718 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5719 mcp->tov = MBX_TOV_SECONDS;
5720 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5721 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5722 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5723 rval = qla2x00_mailbox_command(vha, mcp);
5724
5725 if (rval != QLA_SUCCESS) {
5726 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5727 "mailbox command FAILED=0x%x, subcode=%x.\n",
5728 ((mcp->mb[1] << 16) | mcp->mb[0]),
5729 ((mcp->mb[3] << 16) | mcp->mb[2]));
5730 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005731 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5732 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005733 return rval;
5734}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005735
5736int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005737qla8044_md_get_template(scsi_qla_host_t *vha)
5738{
5739 struct qla_hw_data *ha = vha->hw;
5740 mbx_cmd_t mc;
5741 mbx_cmd_t *mcp = &mc;
5742 int rval = QLA_FUNCTION_FAILED;
5743 int offset = 0, size = MINIDUMP_SIZE_36K;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07005744
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5746 "Entered %s.\n", __func__);
5747
5748 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5749 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5750 if (!ha->md_tmplt_hdr) {
5751 ql_log(ql_log_warn, vha, 0xb11b,
5752 "Unable to allocate memory for Minidump template.\n");
5753 return rval;
5754 }
5755
5756 memset(mcp->mb, 0 , sizeof(mcp->mb));
5757 while (offset < ha->md_template_size) {
5758 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5759 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5760 mcp->mb[2] = LSW(RQST_TMPLT);
5761 mcp->mb[3] = MSW(RQST_TMPLT);
5762 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5763 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5764 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5765 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5766 mcp->mb[8] = LSW(size);
5767 mcp->mb[9] = MSW(size);
5768 mcp->mb[10] = offset & 0x0000FFFF;
5769 mcp->mb[11] = offset & 0xFFFF0000;
5770 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5771 mcp->tov = MBX_TOV_SECONDS;
5772 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5773 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5774 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5775 rval = qla2x00_mailbox_command(vha, mcp);
5776
5777 if (rval != QLA_SUCCESS) {
5778 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5779 "mailbox command FAILED=0x%x, subcode=%x.\n",
5780 ((mcp->mb[1] << 16) | mcp->mb[0]),
5781 ((mcp->mb[3] << 16) | mcp->mb[2]));
5782 return rval;
5783 } else
5784 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5785 "Done %s.\n", __func__);
5786 offset = offset + size;
5787 }
5788 return rval;
5789}
5790
5791int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005792qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5793{
5794 int rval;
5795 struct qla_hw_data *ha = vha->hw;
5796 mbx_cmd_t mc;
5797 mbx_cmd_t *mcp = &mc;
5798
5799 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5800 return QLA_FUNCTION_FAILED;
5801
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005802 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5803 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005804
5805 memset(mcp, 0, sizeof(mbx_cmd_t));
5806 mcp->mb[0] = MBC_SET_LED_CONFIG;
5807 mcp->mb[1] = led_cfg[0];
5808 mcp->mb[2] = led_cfg[1];
5809 if (IS_QLA8031(ha)) {
5810 mcp->mb[3] = led_cfg[2];
5811 mcp->mb[4] = led_cfg[3];
5812 mcp->mb[5] = led_cfg[4];
5813 mcp->mb[6] = led_cfg[5];
5814 }
5815
5816 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5817 if (IS_QLA8031(ha))
5818 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5819 mcp->in_mb = MBX_0;
5820 mcp->tov = 30;
5821 mcp->flags = 0;
5822
5823 rval = qla2x00_mailbox_command(vha, mcp);
5824 if (rval != QLA_SUCCESS) {
5825 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5826 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5827 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005828 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5829 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005830 }
5831
5832 return rval;
5833}
5834
5835int
5836qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5837{
5838 int rval;
5839 struct qla_hw_data *ha = vha->hw;
5840 mbx_cmd_t mc;
5841 mbx_cmd_t *mcp = &mc;
5842
5843 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5844 return QLA_FUNCTION_FAILED;
5845
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005846 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5847 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005848
5849 memset(mcp, 0, sizeof(mbx_cmd_t));
5850 mcp->mb[0] = MBC_GET_LED_CONFIG;
5851
5852 mcp->out_mb = MBX_0;
5853 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5854 if (IS_QLA8031(ha))
5855 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5856 mcp->tov = 30;
5857 mcp->flags = 0;
5858
5859 rval = qla2x00_mailbox_command(vha, mcp);
5860 if (rval != QLA_SUCCESS) {
5861 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5862 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5863 } else {
5864 led_cfg[0] = mcp->mb[1];
5865 led_cfg[1] = mcp->mb[2];
5866 if (IS_QLA8031(ha)) {
5867 led_cfg[2] = mcp->mb[3];
5868 led_cfg[3] = mcp->mb[4];
5869 led_cfg[4] = mcp->mb[5];
5870 led_cfg[5] = mcp->mb[6];
5871 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005872 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5873 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005874 }
5875
5876 return rval;
5877}
5878
5879int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005880qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5881{
5882 int rval;
5883 struct qla_hw_data *ha = vha->hw;
5884 mbx_cmd_t mc;
5885 mbx_cmd_t *mcp = &mc;
5886
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005887 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005888 return QLA_FUNCTION_FAILED;
5889
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005890 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005891 "Entered %s.\n", __func__);
5892
5893 memset(mcp, 0, sizeof(mbx_cmd_t));
5894 mcp->mb[0] = MBC_SET_LED_CONFIG;
5895 if (enable)
5896 mcp->mb[7] = 0xE;
5897 else
5898 mcp->mb[7] = 0xD;
5899
5900 mcp->out_mb = MBX_7|MBX_0;
5901 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005902 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005903 mcp->flags = 0;
5904
5905 rval = qla2x00_mailbox_command(vha, mcp);
5906 if (rval != QLA_SUCCESS) {
5907 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5908 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5909 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005910 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005911 "Done %s.\n", __func__);
5912 }
5913
5914 return rval;
5915}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005916
5917int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005918qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005919{
5920 int rval;
5921 struct qla_hw_data *ha = vha->hw;
5922 mbx_cmd_t mc;
5923 mbx_cmd_t *mcp = &mc;
5924
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005925 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005926 return QLA_FUNCTION_FAILED;
5927
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005928 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5929 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005930
5931 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5932 mcp->mb[1] = LSW(reg);
5933 mcp->mb[2] = MSW(reg);
5934 mcp->mb[3] = LSW(data);
5935 mcp->mb[4] = MSW(data);
5936 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5937
5938 mcp->in_mb = MBX_1|MBX_0;
5939 mcp->tov = MBX_TOV_SECONDS;
5940 mcp->flags = 0;
5941 rval = qla2x00_mailbox_command(vha, mcp);
5942
5943 if (rval != QLA_SUCCESS) {
5944 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5945 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5946 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005947 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005948 "Done %s.\n", __func__);
5949 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005950
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005951 return rval;
5952}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005953
5954int
5955qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5956{
5957 int rval;
5958 struct qla_hw_data *ha = vha->hw;
5959 mbx_cmd_t mc;
5960 mbx_cmd_t *mcp = &mc;
5961
5962 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005963 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005964 "Implicit LOGO Unsupported.\n");
5965 return QLA_FUNCTION_FAILED;
5966 }
5967
5968
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005969 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5970 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005971
5972 /* Perform Implicit LOGO. */
5973 mcp->mb[0] = MBC_PORT_LOGOUT;
5974 mcp->mb[1] = fcport->loop_id;
5975 mcp->mb[10] = BIT_15;
5976 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5977 mcp->in_mb = MBX_0;
5978 mcp->tov = MBX_TOV_SECONDS;
5979 mcp->flags = 0;
5980 rval = qla2x00_mailbox_command(vha, mcp);
5981 if (rval != QLA_SUCCESS)
5982 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5983 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5984 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005985 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5986 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005987
5988 return rval;
5989}
5990
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005991int
5992qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5993{
5994 int rval;
5995 mbx_cmd_t mc;
5996 mbx_cmd_t *mcp = &mc;
5997 struct qla_hw_data *ha = vha->hw;
5998 unsigned long retry_max_time = jiffies + (2 * HZ);
5999
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006000 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006001 return QLA_FUNCTION_FAILED;
6002
6003 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
6004
6005retry_rd_reg:
6006 mcp->mb[0] = MBC_READ_REMOTE_REG;
6007 mcp->mb[1] = LSW(reg);
6008 mcp->mb[2] = MSW(reg);
6009 mcp->out_mb = MBX_2|MBX_1|MBX_0;
6010 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
6011 mcp->tov = MBX_TOV_SECONDS;
6012 mcp->flags = 0;
6013 rval = qla2x00_mailbox_command(vha, mcp);
6014
6015 if (rval != QLA_SUCCESS) {
6016 ql_dbg(ql_dbg_mbx, vha, 0x114c,
6017 "Failed=%x mb[0]=%x mb[1]=%x.\n",
6018 rval, mcp->mb[0], mcp->mb[1]);
6019 } else {
6020 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
6021 if (*data == QLA8XXX_BAD_VALUE) {
6022 /*
6023 * During soft-reset CAMRAM register reads might
6024 * return 0xbad0bad0. So retry for MAX of 2 sec
6025 * while reading camram registers.
6026 */
6027 if (time_after(jiffies, retry_max_time)) {
6028 ql_dbg(ql_dbg_mbx, vha, 0x1141,
6029 "Failure to read CAMRAM register. "
6030 "data=0x%x.\n", *data);
6031 return QLA_FUNCTION_FAILED;
6032 }
6033 msleep(100);
6034 goto retry_rd_reg;
6035 }
6036 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
6037 }
6038
6039 return rval;
6040}
6041
6042int
6043qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
6044{
6045 int rval;
6046 mbx_cmd_t mc;
6047 mbx_cmd_t *mcp = &mc;
6048 struct qla_hw_data *ha = vha->hw;
6049
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006050 if (!IS_QLA83XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006051 return QLA_FUNCTION_FAILED;
6052
6053 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
6054
6055 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
6056 mcp->out_mb = MBX_0;
6057 mcp->in_mb = MBX_1|MBX_0;
6058 mcp->tov = MBX_TOV_SECONDS;
6059 mcp->flags = 0;
6060 rval = qla2x00_mailbox_command(vha, mcp);
6061
6062 if (rval != QLA_SUCCESS) {
6063 ql_dbg(ql_dbg_mbx, vha, 0x1144,
6064 "Failed=%x mb[0]=%x mb[1]=%x.\n",
6065 rval, mcp->mb[0], mcp->mb[1]);
6066 ha->isp_ops->fw_dump(vha, 0);
6067 } else {
6068 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
6069 }
6070
6071 return rval;
6072}
6073
6074int
6075qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
6076 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
6077{
6078 int rval;
6079 mbx_cmd_t mc;
6080 mbx_cmd_t *mcp = &mc;
6081 uint8_t subcode = (uint8_t)options;
6082 struct qla_hw_data *ha = vha->hw;
6083
6084 if (!IS_QLA8031(ha))
6085 return QLA_FUNCTION_FAILED;
6086
6087 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
6088
6089 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
6090 mcp->mb[1] = options;
6091 mcp->out_mb = MBX_1|MBX_0;
6092 if (subcode & BIT_2) {
6093 mcp->mb[2] = LSW(start_addr);
6094 mcp->mb[3] = MSW(start_addr);
6095 mcp->mb[4] = LSW(end_addr);
6096 mcp->mb[5] = MSW(end_addr);
6097 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
6098 }
6099 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6100 if (!(subcode & (BIT_2 | BIT_5)))
6101 mcp->in_mb |= MBX_4|MBX_3;
6102 mcp->tov = MBX_TOV_SECONDS;
6103 mcp->flags = 0;
6104 rval = qla2x00_mailbox_command(vha, mcp);
6105
6106 if (rval != QLA_SUCCESS) {
6107 ql_dbg(ql_dbg_mbx, vha, 0x1147,
6108 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
6109 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
6110 mcp->mb[4]);
6111 ha->isp_ops->fw_dump(vha, 0);
6112 } else {
6113 if (subcode & BIT_5)
6114 *sector_size = mcp->mb[1];
6115 else if (subcode & (BIT_6 | BIT_7)) {
6116 ql_dbg(ql_dbg_mbx, vha, 0x1148,
6117 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6118 } else if (subcode & (BIT_3 | BIT_4)) {
6119 ql_dbg(ql_dbg_mbx, vha, 0x1149,
6120 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6121 }
6122 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
6123 }
6124
6125 return rval;
6126}
Saurav Kashyap81178772012-08-22 14:21:04 -04006127
6128int
6129qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
6130 uint32_t size)
6131{
6132 int rval;
6133 mbx_cmd_t mc;
6134 mbx_cmd_t *mcp = &mc;
6135
6136 if (!IS_MCTP_CAPABLE(vha->hw))
6137 return QLA_FUNCTION_FAILED;
6138
6139 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
6140 "Entered %s.\n", __func__);
6141
6142 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
6143 mcp->mb[1] = LSW(addr);
6144 mcp->mb[2] = MSW(req_dma);
6145 mcp->mb[3] = LSW(req_dma);
6146 mcp->mb[4] = MSW(size);
6147 mcp->mb[5] = LSW(size);
6148 mcp->mb[6] = MSW(MSD(req_dma));
6149 mcp->mb[7] = LSW(MSD(req_dma));
6150 mcp->mb[8] = MSW(addr);
6151 /* Setting RAM ID to valid */
6152 mcp->mb[10] |= BIT_7;
6153 /* For MCTP RAM ID is 0x40 */
6154 mcp->mb[10] |= 0x40;
6155
6156 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
6157 MBX_0;
6158
6159 mcp->in_mb = MBX_0;
6160 mcp->tov = MBX_TOV_SECONDS;
6161 mcp->flags = 0;
6162 rval = qla2x00_mailbox_command(vha, mcp);
6163
6164 if (rval != QLA_SUCCESS) {
6165 ql_dbg(ql_dbg_mbx, vha, 0x114e,
6166 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6167 } else {
6168 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
6169 "Done %s.\n", __func__);
6170 }
6171
6172 return rval;
6173}
Joe Carnuccioec891462016-07-06 11:14:26 -04006174
6175int
6176qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
6177 void *dd_buf, uint size, uint options)
6178{
6179 int rval;
6180 mbx_cmd_t mc;
6181 mbx_cmd_t *mcp = &mc;
6182 dma_addr_t dd_dma;
6183
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006184 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
6185 !IS_QLA28XX(vha->hw))
Joe Carnuccioec891462016-07-06 11:14:26 -04006186 return QLA_FUNCTION_FAILED;
6187
Quinn Tran83548fe2017-06-02 09:12:01 -07006188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04006189 "Entered %s.\n", __func__);
6190
Joe Carnuccioec891462016-07-06 11:14:26 -04006191 dd_dma = dma_map_single(&vha->hw->pdev->dev,
6192 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08006193 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04006194 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
6195 return QLA_MEMORY_ALLOC_FAILED;
6196 }
6197
6198 memset(dd_buf, 0, size);
6199
6200 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
6201 mcp->mb[1] = options;
6202 mcp->mb[2] = MSW(LSD(dd_dma));
6203 mcp->mb[3] = LSW(LSD(dd_dma));
6204 mcp->mb[6] = MSW(MSD(dd_dma));
6205 mcp->mb[7] = LSW(MSD(dd_dma));
6206 mcp->mb[8] = size;
6207 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
6208 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
6209 mcp->buf_size = size;
6210 mcp->flags = MBX_DMA_IN;
6211 mcp->tov = MBX_TOV_SECONDS * 4;
6212 rval = qla2x00_mailbox_command(vha, mcp);
6213
6214 if (rval != QLA_SUCCESS) {
6215 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
6216 } else {
6217 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
6218 "Done %s.\n", __func__);
6219 }
6220
6221 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
6222 size, DMA_FROM_DEVICE);
6223
6224 return rval;
6225}
Quinn Tran15f30a52017-03-15 09:48:52 -07006226
Bart Van Assche6c18a432019-08-08 20:02:04 -07006227static void qla2x00_async_mb_sp_done(srb_t *sp, int res)
Quinn Tran15f30a52017-03-15 09:48:52 -07006228{
Quinn Tran15f30a52017-03-15 09:48:52 -07006229 sp->u.iocb_cmd.u.mbx.rc = res;
6230
6231 complete(&sp->u.iocb_cmd.u.mbx.comp);
6232 /* don't free sp here. Let the caller do the free */
6233}
6234
6235/*
6236 * This mailbox uses the iocb interface to send MB command.
6237 * This allows non-critial (non chip setup) command to go
6238 * out in parrallel.
6239 */
6240int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
6241{
6242 int rval = QLA_FUNCTION_FAILED;
6243 srb_t *sp;
6244 struct srb_iocb *c;
6245
6246 if (!vha->hw->flags.fw_started)
6247 goto done;
6248
6249 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
6250 if (!sp)
6251 goto done;
6252
6253 sp->type = SRB_MB_IOCB;
6254 sp->name = mb_to_str(mcp->mb[0]);
6255
Quinn Tran15f30a52017-03-15 09:48:52 -07006256 c = &sp->u.iocb_cmd;
6257 c->timeout = qla2x00_async_iocb_timeout;
6258 init_completion(&c->u.mbx.comp);
6259
Ben Hutchingse74e7d92018-03-20 21:36:14 +00006260 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
6261
6262 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
6263
Quinn Tran15f30a52017-03-15 09:48:52 -07006264 sp->done = qla2x00_async_mb_sp_done;
6265
6266 rval = qla2x00_start_sp(sp);
6267 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006268 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07006269 "%s: %s Failed submission. %x.\n",
6270 __func__, sp->name, rval);
6271 goto done_free_sp;
6272 }
6273
Quinn Tran83548fe2017-06-02 09:12:01 -07006274 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006275 sp->name, sp->handle);
6276
6277 wait_for_completion(&c->u.mbx.comp);
6278 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
6279
6280 rval = c->u.mbx.rc;
6281 switch (rval) {
6282 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07006283 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006284 __func__, sp->name, rval);
6285 break;
6286 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07006287 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006288 __func__, sp->name);
6289 sp->free(sp);
6290 break;
6291 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07006292 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006293 __func__, sp->name, rval);
6294 sp->free(sp);
6295 break;
6296 }
6297
6298 return rval;
6299
6300done_free_sp:
6301 sp->free(sp);
6302done:
6303 return rval;
6304}
6305
6306/*
6307 * qla24xx_gpdb_wait
6308 * NOTE: Do not call this routine from DPC thread
6309 */
6310int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
6311{
6312 int rval = QLA_FUNCTION_FAILED;
6313 dma_addr_t pd_dma;
6314 struct port_database_24xx *pd;
6315 struct qla_hw_data *ha = vha->hw;
6316 mbx_cmd_t mc;
6317
6318 if (!vha->hw->flags.fw_started)
6319 goto done;
6320
Thomas Meyer08eb7f42017-09-21 08:15:26 +02006321 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran15f30a52017-03-15 09:48:52 -07006322 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006323 ql_log(ql_log_warn, vha, 0xd047,
6324 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07006325 goto done_free_sp;
6326 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006327
6328 memset(&mc, 0, sizeof(mc));
6329 mc.mb[0] = MBC_GET_PORT_DATABASE;
6330 mc.mb[1] = cpu_to_le16(fcport->loop_id);
6331 mc.mb[2] = MSW(pd_dma);
6332 mc.mb[3] = LSW(pd_dma);
6333 mc.mb[6] = MSW(MSD(pd_dma));
6334 mc.mb[7] = LSW(MSD(pd_dma));
6335 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6336 mc.mb[10] = cpu_to_le16((uint16_t)opt);
6337
6338 rval = qla24xx_send_mb_cmd(vha, &mc);
6339 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006340 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07006341 "%s: %8phC fail\n", __func__, fcport->port_name);
6342 goto done_free_sp;
6343 }
6344
6345 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
6346
Quinn Tran83548fe2017-06-02 09:12:01 -07006347 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006348 __func__, fcport->port_name);
6349
6350done_free_sp:
6351 if (pd)
6352 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
6353done:
6354 return rval;
6355}
6356
6357int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
6358 struct port_database_24xx *pd)
6359{
6360 int rval = QLA_SUCCESS;
6361 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006362 u8 current_login_state, last_login_state;
6363
6364 if (fcport->fc4f_nvme) {
6365 current_login_state = pd->current_login_state >> 4;
6366 last_login_state = pd->last_login_state >> 4;
6367 } else {
6368 current_login_state = pd->current_login_state & 0xf;
6369 last_login_state = pd->last_login_state & 0xf;
6370 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006371
6372 /* Check for logged in state. */
Quinn Tran23c64552017-12-04 14:45:08 -08006373 if (current_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006374 ql_dbg(ql_dbg_mbx, vha, 0x119a,
6375 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006376 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006377 rval = QLA_FUNCTION_FAILED;
6378 goto gpd_error_out;
6379 }
6380
6381 if (fcport->loop_id == FC_NO_LOOP_ID ||
6382 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6383 memcmp(fcport->port_name, pd->port_name, 8))) {
6384 /* We lost the device mid way. */
6385 rval = QLA_NOT_LOGGED_IN;
6386 goto gpd_error_out;
6387 }
6388
6389 /* Names are little-endian. */
6390 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6391 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6392
6393 /* Get port_id of device. */
6394 fcport->d_id.b.domain = pd->port_id[0];
6395 fcport->d_id.b.area = pd->port_id[1];
6396 fcport->d_id.b.al_pa = pd->port_id[2];
6397 fcport->d_id.b.rsvd_1 = 0;
6398
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006399 if (fcport->fc4f_nvme) {
Hannes Reineckea6a6d052019-04-10 16:16:19 +02006400 fcport->port_type = 0;
6401 if ((pd->prli_svc_param_word_3[0] & BIT_5) == 0)
6402 fcport->port_type |= FCT_NVME_INITIATOR;
6403 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6404 fcport->port_type |= FCT_NVME_TARGET;
6405 if ((pd->prli_svc_param_word_3[0] & BIT_3) == 0)
6406 fcport->port_type |= FCT_NVME_DISCOVERY;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006407 } else {
6408 /* If not target must be initiator or unknown type. */
6409 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6410 fcport->port_type = FCT_INITIATOR;
6411 else
6412 fcport->port_type = FCT_TARGET;
6413 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006414 /* Passback COS information. */
6415 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6416 FC_COS_CLASS2 : FC_COS_CLASS3;
6417
6418 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6419 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6420 fcport->conf_compl_supported = 1;
6421 }
6422
6423gpd_error_out:
6424 return rval;
6425}
6426
6427/*
6428 * qla24xx_gidlist__wait
6429 * NOTE: don't call this routine from DPC thread.
6430 */
6431int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6432 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6433{
6434 int rval = QLA_FUNCTION_FAILED;
6435 mbx_cmd_t mc;
6436
6437 if (!vha->hw->flags.fw_started)
6438 goto done;
6439
6440 memset(&mc, 0, sizeof(mc));
6441 mc.mb[0] = MBC_GET_ID_LIST;
6442 mc.mb[2] = MSW(id_list_dma);
6443 mc.mb[3] = LSW(id_list_dma);
6444 mc.mb[6] = MSW(MSD(id_list_dma));
6445 mc.mb[7] = LSW(MSD(id_list_dma));
6446 mc.mb[8] = 0;
6447 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6448
6449 rval = qla24xx_send_mb_cmd(vha, &mc);
6450 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006451 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6452 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006453 } else {
6454 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006455 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6456 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006457 }
6458done:
6459 return rval;
6460}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006461
6462int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6463{
6464 int rval;
6465 mbx_cmd_t mc;
6466 mbx_cmd_t *mcp = &mc;
6467
6468 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6469 "Entered %s\n", __func__);
6470
6471 memset(mcp->mb, 0 , sizeof(mcp->mb));
6472 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6473 mcp->mb[1] = cpu_to_le16(1);
6474 mcp->mb[2] = cpu_to_le16(value);
6475 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6476 mcp->in_mb = MBX_2 | MBX_0;
6477 mcp->tov = MBX_TOV_SECONDS;
6478 mcp->flags = 0;
6479
6480 rval = qla2x00_mailbox_command(vha, mcp);
6481
6482 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6483 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6484
6485 return rval;
6486}
6487
6488int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6489{
6490 int rval;
6491 mbx_cmd_t mc;
6492 mbx_cmd_t *mcp = &mc;
6493
6494 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6495 "Entered %s\n", __func__);
6496
6497 memset(mcp->mb, 0, sizeof(mcp->mb));
6498 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6499 mcp->mb[1] = cpu_to_le16(0);
6500 mcp->out_mb = MBX_1 | MBX_0;
6501 mcp->in_mb = MBX_2 | MBX_0;
6502 mcp->tov = MBX_TOV_SECONDS;
6503 mcp->flags = 0;
6504
6505 rval = qla2x00_mailbox_command(vha, mcp);
6506 if (rval == QLA_SUCCESS)
6507 *value = mc.mb[2];
6508
6509 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6510 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6511
6512 return rval;
6513}
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006514
6515int
6516qla2x00_read_sfp_dev(struct scsi_qla_host *vha, char *buf, int count)
6517{
6518 struct qla_hw_data *ha = vha->hw;
6519 uint16_t iter, addr, offset;
6520 dma_addr_t phys_addr;
6521 int rval, c;
6522 u8 *sfp_data;
6523
6524 memset(ha->sfp_data, 0, SFP_DEV_SIZE);
6525 addr = 0xa0;
6526 phys_addr = ha->sfp_data_dma;
6527 sfp_data = ha->sfp_data;
6528 offset = c = 0;
6529
6530 for (iter = 0; iter < SFP_DEV_SIZE / SFP_BLOCK_SIZE; iter++) {
6531 if (iter == 4) {
6532 /* Skip to next device address. */
6533 addr = 0xa2;
6534 offset = 0;
6535 }
6536
6537 rval = qla2x00_read_sfp(vha, phys_addr, sfp_data,
6538 addr, offset, SFP_BLOCK_SIZE, BIT_1);
6539 if (rval != QLA_SUCCESS) {
6540 ql_log(ql_log_warn, vha, 0x706d,
6541 "Unable to read SFP data (%x/%x/%x).\n", rval,
6542 addr, offset);
6543
6544 return rval;
6545 }
6546
6547 if (buf && (c < count)) {
6548 u16 sz;
6549
6550 if ((count - c) >= SFP_BLOCK_SIZE)
6551 sz = SFP_BLOCK_SIZE;
6552 else
6553 sz = count - c;
6554
6555 memcpy(buf, sfp_data, sz);
6556 buf += SFP_BLOCK_SIZE;
6557 c += sz;
6558 }
6559 phys_addr += SFP_BLOCK_SIZE;
6560 sfp_data += SFP_BLOCK_SIZE;
6561 offset += SFP_BLOCK_SIZE;
6562 }
6563
6564 return rval;
6565}
Quinn Tran94d83e32017-12-28 12:33:23 -08006566
6567int qla24xx_res_count_wait(struct scsi_qla_host *vha,
6568 uint16_t *out_mb, int out_mb_sz)
6569{
6570 int rval = QLA_FUNCTION_FAILED;
6571 mbx_cmd_t mc;
6572
6573 if (!vha->hw->flags.fw_started)
6574 goto done;
6575
6576 memset(&mc, 0, sizeof(mc));
6577 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
6578
6579 rval = qla24xx_send_mb_cmd(vha, &mc);
6580 if (rval != QLA_SUCCESS) {
6581 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6582 "%s: fail\n", __func__);
6583 } else {
6584 if (out_mb_sz <= SIZEOF_IOCB_MB_REG)
6585 memcpy(out_mb, mc.mb, out_mb_sz);
6586 else
6587 memcpy(out_mb, mc.mb, SIZEOF_IOCB_MB_REG);
6588
6589 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6590 "%s: done\n", __func__);
6591 }
6592done:
6593 return rval;
6594}
Michael Hernandez3f006ac2019-03-12 11:08:22 -07006595
6596int qla28xx_secure_flash_update(scsi_qla_host_t *vha, uint16_t opts,
6597 uint16_t region, uint32_t len, dma_addr_t sfub_dma_addr,
6598 uint32_t sfub_len)
6599{
6600 int rval;
6601 mbx_cmd_t mc;
6602 mbx_cmd_t *mcp = &mc;
6603
6604 mcp->mb[0] = MBC_SECURE_FLASH_UPDATE;
6605 mcp->mb[1] = opts;
6606 mcp->mb[2] = region;
6607 mcp->mb[3] = MSW(len);
6608 mcp->mb[4] = LSW(len);
6609 mcp->mb[5] = MSW(sfub_dma_addr);
6610 mcp->mb[6] = LSW(sfub_dma_addr);
6611 mcp->mb[7] = MSW(MSD(sfub_dma_addr));
6612 mcp->mb[8] = LSW(MSD(sfub_dma_addr));
6613 mcp->mb[9] = sfub_len;
6614 mcp->out_mb =
6615 MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6616 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6617 mcp->tov = MBX_TOV_SECONDS;
6618 mcp->flags = 0;
6619 rval = qla2x00_mailbox_command(vha, mcp);
6620
6621 if (rval != QLA_SUCCESS) {
6622 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s(%ld): failed rval 0x%x, %x %x %x",
6623 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1],
6624 mcp->mb[2]);
6625 }
6626
6627 return rval;
6628}
6629
6630int qla2xxx_write_remote_register(scsi_qla_host_t *vha, uint32_t addr,
6631 uint32_t data)
6632{
6633 int rval;
6634 mbx_cmd_t mc;
6635 mbx_cmd_t *mcp = &mc;
6636
6637 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
6638 "Entered %s.\n", __func__);
6639
6640 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
6641 mcp->mb[1] = LSW(addr);
6642 mcp->mb[2] = MSW(addr);
6643 mcp->mb[3] = LSW(data);
6644 mcp->mb[4] = MSW(data);
6645 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6646 mcp->in_mb = MBX_1|MBX_0;
6647 mcp->tov = MBX_TOV_SECONDS;
6648 mcp->flags = 0;
6649 rval = qla2x00_mailbox_command(vha, mcp);
6650
6651 if (rval != QLA_SUCCESS) {
6652 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
6653 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6654 } else {
6655 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
6656 "Done %s.\n", __func__);
6657 }
6658
6659 return rval;
6660}
6661
6662int qla2xxx_read_remote_register(scsi_qla_host_t *vha, uint32_t addr,
6663 uint32_t *data)
6664{
6665 int rval;
6666 mbx_cmd_t mc;
6667 mbx_cmd_t *mcp = &mc;
6668
6669 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
6670 "Entered %s.\n", __func__);
6671
6672 mcp->mb[0] = MBC_READ_REMOTE_REG;
6673 mcp->mb[1] = LSW(addr);
6674 mcp->mb[2] = MSW(addr);
6675 mcp->out_mb = MBX_2|MBX_1|MBX_0;
6676 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6677 mcp->tov = MBX_TOV_SECONDS;
6678 mcp->flags = 0;
6679 rval = qla2x00_mailbox_command(vha, mcp);
6680
6681 *data = (uint32_t)((((uint32_t)mcp->mb[4]) << 16) | mcp->mb[3]);
6682
6683 if (rval != QLA_SUCCESS) {
6684 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
6685 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6686 } else {
6687 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
6688 "Done %s.\n", __func__);
6689 }
6690
6691 return rval;
6692}