blob: a82b6db2fa9dc537ca23804e4a80e187afad77cf [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
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400256 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700257 if (RD_REG_DWORD(&reg->isp82.hint) &
258 HINT_MBX_INT_PENDING) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700259 ha->flags.mbox_busy = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700260 spin_unlock_irqrestore(&ha->hardware_lock,
261 flags);
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700262
Quinn Tranb2000802018-08-02 13:16:52 -0700263 atomic_dec(&ha->num_pend_mbx_stage2);
Arun Easi5e19ed92012-02-09 11:15:51 -0800264 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700265 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700266 rval = QLA_FUNCTION_TIMEOUT;
267 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700268 }
269 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
270 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700271 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
272 else
273 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 spin_unlock_irqrestore(&ha->hardware_lock, flags);
275
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800276 wait_time = jiffies;
Quinn Tranb2000802018-08-02 13:16:52 -0700277 atomic_inc(&ha->num_pend_mbx_stage3);
Giridhar Malavali754d1242013-06-25 11:27:16 -0400278 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
279 mcp->tov * HZ)) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700280 if (chip_reset != ha->chip_reset) {
281 spin_lock_irqsave(&ha->hardware_lock, flags);
282 ha->flags.mbox_busy = 0;
283 spin_unlock_irqrestore(&ha->hardware_lock,
284 flags);
285 atomic_dec(&ha->num_pend_mbx_stage2);
286 atomic_dec(&ha->num_pend_mbx_stage3);
287 rval = QLA_ABORTED;
288 goto premature_exit;
289 }
Giridhar Malavali754d1242013-06-25 11:27:16 -0400290 ql_dbg(ql_dbg_mbx, vha, 0x117a,
291 "cmd=%x Timeout.\n", command);
292 spin_lock_irqsave(&ha->hardware_lock, flags);
293 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
294 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700295
296 } else if (ha->flags.purge_mbox ||
297 chip_reset != ha->chip_reset) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700298 spin_lock_irqsave(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700299 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700300 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700301 atomic_dec(&ha->num_pend_mbx_stage2);
302 atomic_dec(&ha->num_pend_mbx_stage3);
303 rval = QLA_ABORTED;
304 goto premature_exit;
Giridhar Malavali754d1242013-06-25 11:27:16 -0400305 }
Quinn Tranb2000802018-08-02 13:16:52 -0700306 atomic_dec(&ha->num_pend_mbx_stage3);
307
himanshu.madhani@cavium.com77ddb942016-12-12 14:40:05 -0800308 if (time_after(jiffies, wait_time + 5 * HZ))
309 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
310 command, jiffies_to_msecs(jiffies - wait_time));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800312 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700313 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400315 if (IS_P3P_TYPE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -0700316 if (RD_REG_DWORD(&reg->isp82.hint) &
317 HINT_MBX_INT_PENDING) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700318 ha->flags.mbox_busy = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700319 spin_unlock_irqrestore(&ha->hardware_lock,
320 flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700321 atomic_dec(&ha->num_pend_mbx_stage2);
Arun Easi5e19ed92012-02-09 11:15:51 -0800322 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700323 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700324 rval = QLA_FUNCTION_TIMEOUT;
325 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700326 }
327 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
328 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700329 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
330 else
331 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
335 while (!ha->flags.mbox_int) {
Quinn Tranb2000802018-08-02 13:16:52 -0700336 if (ha->flags.purge_mbox ||
337 chip_reset != ha->chip_reset) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700338 spin_lock_irqsave(&ha->hardware_lock, flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700339 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700340 spin_unlock_irqrestore(&ha->hardware_lock,
341 flags);
Quinn Tranb2000802018-08-02 13:16:52 -0700342 atomic_dec(&ha->num_pend_mbx_stage2);
343 rval = QLA_ABORTED;
344 goto premature_exit;
345 }
346
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 if (time_after(jiffies, wait_time))
348 break;
349
Rodrigo R. Galvao3cb182b2018-05-28 14:58:44 -0300350 /*
351 * Check if it's UNLOADING, cause we cannot poll in
352 * this case, or else a NULL pointer dereference
353 * is triggered.
354 */
355 if (unlikely(test_bit(UNLOADING, &base_vha->dpc_flags)))
356 return QLA_FUNCTION_TIMEOUT;
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800359 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Andrew Vasquez85880802009-12-15 21:29:46 -0800361 if (!ha->flags.mbox_int &&
362 !(IS_QLA2200(ha) &&
363 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800364 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800366 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700367 "Waited %d sec.\n",
368 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 }
Quinn Tranb2000802018-08-02 13:16:52 -0700370 atomic_dec(&ha->num_pend_mbx_stage2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 /* Check whether we timed out */
373 if (ha->flags.mbox_int) {
374 uint16_t *iptr2;
375
Arun Easi5e19ed92012-02-09 11:15:51 -0800376 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700377 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379 /* Got interrupt. Clear the flag. */
380 ha->flags.mbox_int = 0;
381 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
382
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -0400383 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700384 spin_lock_irqsave(&ha->hardware_lock, flags);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700385 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700386 spin_unlock_irqrestore(&ha->hardware_lock, flags);
387
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700388 /* Setting Link-Down error */
389 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
390 ha->mcp = NULL;
391 rval = QLA_FUNCTION_FAILED;
Quinn Tran83548fe2017-06-02 09:12:01 -0700392 ql_log(ql_log_warn, vha, 0xd048,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700393 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700394 goto premature_exit;
395 }
396
Bart Van Asscheb3e97722019-08-08 20:01:41 -0700397 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) {
398 ql_dbg(ql_dbg_mbx, vha, 0x11ff,
399 "mb_out[0] = %#x <> %#x\n", ha->mailbox_out[0],
400 MBS_COMMAND_COMPLETE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 rval = QLA_FUNCTION_FAILED;
Bart Van Asscheb3e97722019-08-08 20:01:41 -0700402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404 /* Load return mailbox registers. */
405 iptr2 = mcp->mb;
406 iptr = (uint16_t *)&ha->mailbox_out[0];
407 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700408
409 ql_dbg(ql_dbg_mbx, vha, 0x1113,
410 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700412 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700414 ql_dbg(ql_dbg_mbx, vha, 0x1114,
415 "mbox[%d]->0x%04x\n", cnt, *iptr2);
416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 mboxes >>= 1;
419 iptr2++;
420 iptr++;
421 }
422 } else {
423
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800424 uint16_t mb[8];
425 uint32_t ictrl, host_status, hccr;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400426 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700427
Andrew Vasqueze4289242007-07-19 15:05:56 -0700428 if (IS_FWI2_CAPABLE(ha)) {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800429 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
430 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
431 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
432 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
433 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700434 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800435 host_status = RD_REG_DWORD(&reg->isp24.host_status);
436 hccr = RD_REG_DWORD(&reg->isp24.hccr);
437
Quinn Tran83548fe2017-06-02 09:12:01 -0700438 ql_log(ql_log_warn, vha, 0xd04c,
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800439 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
440 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
441 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
442 mb[7], host_status, hccr);
443
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700444 } else {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800445 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700446 ictrl = RD_REG_WORD(&reg->isp.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800447 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
448 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
449 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700450 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800451 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400453 /* Capture FW dump only, if PCI device active */
454 if (!pci_channel_offline(vha->hw->pdev)) {
455 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Quinn Tranb2000802018-08-02 13:16:52 -0700456 if (w == 0xffff || ictrl == 0xffffffff ||
457 (chip_reset != ha->chip_reset)) {
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400458 /* This is special case if there is unload
459 * of driver happening and if PCI device go
460 * into bad state due to PCI error condition
461 * then only PCI ERR flag would be set.
462 * we will do premature exit for above case.
463 */
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700464 spin_lock_irqsave(&ha->hardware_lock, flags);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400465 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700466 spin_unlock_irqrestore(&ha->hardware_lock,
467 flags);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400468 rval = QLA_FUNCTION_TIMEOUT;
469 goto premature_exit;
470 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800471
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400472 /* Attempt to capture firmware dump for further
473 * anallysis of the current formware state. we do not
474 * need to do this if we are intentionally generating
475 * a dump
476 */
477 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
478 ha->isp_ops->fw_dump(vha, 0);
479 rval = QLA_FUNCTION_TIMEOUT;
480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700482 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700484 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 /* Clean up */
487 ha->mcp = NULL;
488
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800489 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800490 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700491 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800494 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 }
496
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700497 if (rval == QLA_FUNCTION_TIMEOUT &&
498 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800499 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
500 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800502 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700503 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700504
505 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
506 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
507 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800508 if (IS_QLA82XX(ha)) {
509 ql_dbg(ql_dbg_mbx, vha, 0x112a,
510 "disabling pause transmit on port "
511 "0 & 1.\n");
512 qla82xx_wr_32(ha,
513 QLA82XX_CRB_NIU + 0x98,
514 CRB_NIU_XG_PAUSE_CTL_P0|
515 CRB_NIU_XG_PAUSE_CTL_P1);
516 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700517 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400518 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800519 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
520 "abort.\n", command, mcp->mb[0],
521 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700522 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
523 qla2xxx_wake_dpc(vha);
524 }
Quinn Tran710bc782018-09-26 22:05:16 -0700525 } else if (current == ha->dpc_thread) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800527 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700528 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700530 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
531 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
532 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800533 if (IS_QLA82XX(ha)) {
534 ql_dbg(ql_dbg_mbx, vha, 0x112b,
535 "disabling pause transmit on port "
536 "0 & 1.\n");
537 qla82xx_wr_32(ha,
538 QLA82XX_CRB_NIU + 0x98,
539 CRB_NIU_XG_PAUSE_CTL_P0|
540 CRB_NIU_XG_PAUSE_CTL_P1);
541 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700542 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400543 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800544 "mb[0]=0x%x. Scheduling ISP abort ",
545 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700546 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
547 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800548 /* Allow next mbx cmd to come in. */
549 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700550 if (ha->isp_ops->abort_isp(vha)) {
551 /* Failed. retry later. */
552 set_bit(ISP_ABORT_NEEDED,
553 &vha->dpc_flags);
554 }
555 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800556 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700557 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800558 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561 }
562
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700563premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800565 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Giridhar Malavalid3360962012-02-09 11:14:10 -0800567mbx_done:
Quinn Tranb2000802018-08-02 13:16:52 -0700568 if (rval == QLA_ABORTED) {
569 ql_log(ql_log_info, vha, 0xd035,
570 "Chip Reset in progress. Purging Mbox cmd=0x%x.\n",
571 mcp->mb[0]);
572 } else if (rval) {
Joe Carnuccio050dc762017-08-23 15:05:14 -0700573 if (ql2xextended_error_logging & (ql_dbg_disc|ql_dbg_mbx)) {
Bart Van Assche3f918ff2019-04-17 14:44:20 -0700574 pr_warn("%s [%s]-%04x:%ld: **** Failed=%x", QL_MSGHDR,
Joe Carnuccio050dc762017-08-23 15:05:14 -0700575 dev_name(&ha->pdev->dev), 0x1020+0x800,
Bart Van Assche3f918ff2019-04-17 14:44:20 -0700576 vha->host_no, rval);
Joe Carnuccio050dc762017-08-23 15:05:14 -0700577 mboxes = mcp->in_mb;
578 cnt = 4;
579 for (i = 0; i < ha->mbx_count && cnt; i++, mboxes >>= 1)
580 if (mboxes & BIT_0) {
581 printk(" mb[%u]=%x", i, mcp->mb[i]);
582 cnt--;
583 }
584 pr_warn(" cmd=%x ****\n", command);
585 }
Meelis Roosf7e59e92018-03-08 15:44:07 +0200586 if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha))) {
587 ql_dbg(ql_dbg_mbx, vha, 0x1198,
588 "host_status=%#x intr_ctrl=%#x intr_status=%#x\n",
589 RD_REG_DWORD(&reg->isp24.host_status),
590 RD_REG_DWORD(&reg->isp24.ictrl),
591 RD_REG_DWORD(&reg->isp24.istatus));
592 } else {
593 ql_dbg(ql_dbg_mbx, vha, 0x1206,
594 "ctrl_status=%#x ictrl=%#x istatus=%#x\n",
595 RD_REG_WORD(&reg->isp.ctrl_status),
596 RD_REG_WORD(&reg->isp.ictrl),
597 RD_REG_WORD(&reg->isp.istatus));
598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700600 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 }
602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 return rval;
604}
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800607qla2x00_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 -0800608 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609{
610 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800611 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 mbx_cmd_t mc;
613 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400615 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
616 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
Andrew Vasqueze4289242007-07-19 15:05:56 -0700618 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800619 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
620 mcp->mb[8] = MSW(risc_addr);
621 mcp->out_mb = MBX_8|MBX_0;
622 } else {
623 mcp->mb[0] = MBC_LOAD_RISC_RAM;
624 mcp->out_mb = MBX_0;
625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 mcp->mb[1] = LSW(risc_addr);
627 mcp->mb[2] = MSW(req_dma);
628 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 mcp->mb[6] = MSW(MSD(req_dma));
630 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800631 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700632 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700633 mcp->mb[4] = MSW(risc_code_size);
634 mcp->mb[5] = LSW(risc_code_size);
635 mcp->out_mb |= MBX_5|MBX_4;
636 } else {
637 mcp->mb[4] = LSW(risc_code_size);
638 mcp->out_mb |= MBX_4;
639 }
640
Joe Carnuccio2a3192a2019-03-12 11:08:14 -0700641 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700642 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800644 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700647 ql_dbg(ql_dbg_mbx, vha, 0x1023,
Joe Carnuccio2a3192a2019-03-12 11:08:14 -0700648 "Failed=%x mb[0]=%x mb[1]=%x.\n",
649 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400651 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
652 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 }
654
655 return rval;
656}
657
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700658#define EXTENDED_BB_CREDITS BIT_0
Duane Grigsbye84067d2017-06-21 13:48:43 -0700659#define NVME_ENABLE_FLAG BIT_3
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700660static inline uint16_t qla25xx_set_sfp_lr_dist(struct qla_hw_data *ha)
661{
662 uint16_t mb4 = BIT_0;
663
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700664 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700665 mb4 |= ha->long_range_distance << LR_DIST_FW_POS;
666
667 return mb4;
668}
669
670static inline uint16_t qla25xx_set_nvr_lr_dist(struct qla_hw_data *ha)
671{
672 uint16_t mb4 = BIT_0;
673
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700674 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700675 struct nvram_81xx *nv = ha->nvram;
676
677 mb4 |= LR_DIST_FW_FIELD(nv->enhanced_features);
678 }
679
680 return mb4;
681}
Duane Grigsbye84067d2017-06-21 13:48:43 -0700682
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683/*
684 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700685 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 *
687 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700688 * ha = adapter block pointer.
689 * TARGET_QUEUE_LOCK must be released.
690 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 *
692 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700693 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 *
695 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700696 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 */
698int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800699qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700{
701 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800702 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 mbx_cmd_t mc;
704 mbx_cmd_t *mcp = &mc;
705
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400706 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
707 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700710 mcp->out_mb = MBX_0;
711 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700712 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700713 mcp->mb[1] = MSW(risc_addr);
714 mcp->mb[2] = LSW(risc_addr);
715 mcp->mb[3] = 0;
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700716 mcp->mb[4] = 0;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700717 ha->flags.using_lr_setting = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500718 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700719 IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700720 if (ql2xautodetectsfp) {
721 if (ha->flags.detected_lr_sfp) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700722 mcp->mb[4] |=
723 qla25xx_set_sfp_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700724 ha->flags.using_lr_setting = 1;
725 }
726 } else {
727 struct nvram_81xx *nv = ha->nvram;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700728 /* set LR distance if specified in nvram */
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700729 if (nv->enhanced_features &
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700730 NEF_LR_DIST_ENABLE) {
731 mcp->mb[4] |=
732 qla25xx_set_nvr_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700733 ha->flags.using_lr_setting = 1;
734 }
735 }
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700736 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500737
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700738 if (ql2xnvmeenable && (IS_QLA27XX(ha) || IS_QLA28XX(ha)))
Duane Grigsbye84067d2017-06-21 13:48:43 -0700739 mcp->mb[4] |= NVME_ENABLE_FLAG;
740
Joe Carnuccioecc89f22019-03-12 11:08:13 -0700741 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -0700742 struct nvram_81xx *nv = ha->nvram;
743 /* set minimum speed if specified in nvram */
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700744 if (nv->min_supported_speed >= 2 &&
745 nv->min_supported_speed <= 5) {
Sawan Chandak92d44082017-08-23 15:05:16 -0700746 mcp->mb[4] |= BIT_4;
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700747 mcp->mb[11] |= nv->min_supported_speed & 0xF;
Sawan Chandak92d44082017-08-23 15:05:16 -0700748 mcp->out_mb |= MBX_11;
749 mcp->in_mb |= BIT_5;
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700750 vha->min_supported_speed =
751 nv->min_supported_speed;
Sawan Chandak92d44082017-08-23 15:05:16 -0700752 }
753 }
754
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500755 if (ha->flags.exlogins_enabled)
756 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
757
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500758 if (ha->flags.exchoffld_enabled)
759 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
760
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700761 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700762 mcp->in_mb |= MBX_3 | MBX_2 | MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700763 } else {
764 mcp->mb[1] = LSW(risc_addr);
765 mcp->out_mb |= MBX_1;
766 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
767 mcp->mb[2] = 0;
768 mcp->out_mb |= MBX_2;
769 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 }
771
Ravi Anandb93480e2008-04-03 13:13:25 -0700772 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800774 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700776 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700777 ql_dbg(ql_dbg_mbx, vha, 0x1026,
778 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700779 return rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
Joe Carnuccio72a92df2019-03-12 11:08:15 -0700782 if (!IS_FWI2_CAPABLE(ha))
783 goto done;
784
785 ha->fw_ability_mask = mcp->mb[3] << 16 | mcp->mb[2];
786 ql_dbg(ql_dbg_mbx, vha, 0x119a,
787 "fw_ability_mask=%x.\n", ha->fw_ability_mask);
788 ql_dbg(ql_dbg_mbx, vha, 0x1027, "exchanges=%x.\n", mcp->mb[1]);
789 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
790 ha->max_supported_speed = mcp->mb[2] & (BIT_0|BIT_1);
791 ql_dbg(ql_dbg_mbx, vha, 0x119b, "max_supported_speed=%s.\n",
792 ha->max_supported_speed == 0 ? "16Gps" :
793 ha->max_supported_speed == 1 ? "32Gps" :
794 ha->max_supported_speed == 2 ? "64Gps" : "unknown");
795 if (vha->min_supported_speed) {
796 ha->min_supported_speed = mcp->mb[5] &
797 (BIT_0 | BIT_1 | BIT_2);
798 ql_dbg(ql_dbg_mbx, vha, 0x119c,
799 "min_supported_speed=%s.\n",
800 ha->min_supported_speed == 6 ? "64Gps" :
801 ha->min_supported_speed == 5 ? "32Gps" :
802 ha->min_supported_speed == 4 ? "16Gps" :
803 ha->min_supported_speed == 3 ? "8Gps" :
804 ha->min_supported_speed == 2 ? "4Gps" : "unknown");
805 }
806 }
807
808done:
809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
810 "Done %s.\n", __func__);
811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 return rval;
813}
814
815/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500816 * qla_get_exlogin_status
817 * Get extended login status
818 * uses the memory offload control/status Mailbox
819 *
820 * Input:
821 * ha: adapter state pointer.
822 * fwopt: firmware options
823 *
824 * Returns:
825 * qla2x00 local function status
826 *
827 * Context:
828 * Kernel context.
829 */
830#define FETCH_XLOGINS_STAT 0x8
831int
832qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
833 uint16_t *ex_logins_cnt)
834{
835 int rval;
836 mbx_cmd_t mc;
837 mbx_cmd_t *mcp = &mc;
838
839 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
840 "Entered %s\n", __func__);
841
842 memset(mcp->mb, 0 , sizeof(mcp->mb));
843 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
844 mcp->mb[1] = FETCH_XLOGINS_STAT;
845 mcp->out_mb = MBX_1|MBX_0;
846 mcp->in_mb = MBX_10|MBX_4|MBX_0;
847 mcp->tov = MBX_TOV_SECONDS;
848 mcp->flags = 0;
849
850 rval = qla2x00_mailbox_command(vha, mcp);
851 if (rval != QLA_SUCCESS) {
852 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
853 } else {
854 *buf_sz = mcp->mb[4];
855 *ex_logins_cnt = mcp->mb[10];
856
857 ql_log(ql_log_info, vha, 0x1190,
858 "buffer size 0x%x, exchange login count=%d\n",
859 mcp->mb[4], mcp->mb[10]);
860
861 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
862 "Done %s.\n", __func__);
863 }
864
865 return rval;
866}
867
868/*
869 * qla_set_exlogin_mem_cfg
870 * set extended login memory configuration
871 * Mbx needs to be issues before init_cb is set
872 *
873 * Input:
874 * ha: adapter state pointer.
875 * buffer: buffer pointer
876 * phys_addr: physical address of buffer
877 * size: size of buffer
878 * TARGET_QUEUE_LOCK must be released
879 * ADAPTER_STATE_LOCK must be release
880 *
881 * Returns:
882 * qla2x00 local funxtion status code.
883 *
884 * Context:
885 * Kernel context.
886 */
887#define CONFIG_XLOGINS_MEM 0x3
888int
889qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
890{
891 int rval;
892 mbx_cmd_t mc;
893 mbx_cmd_t *mcp = &mc;
894 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500895
896 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
897 "Entered %s.\n", __func__);
898
899 memset(mcp->mb, 0 , sizeof(mcp->mb));
900 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
901 mcp->mb[1] = CONFIG_XLOGINS_MEM;
902 mcp->mb[2] = MSW(phys_addr);
903 mcp->mb[3] = LSW(phys_addr);
904 mcp->mb[6] = MSW(MSD(phys_addr));
905 mcp->mb[7] = LSW(MSD(phys_addr));
906 mcp->mb[8] = MSW(ha->exlogin_size);
907 mcp->mb[9] = LSW(ha->exlogin_size);
908 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
909 mcp->in_mb = MBX_11|MBX_0;
910 mcp->tov = MBX_TOV_SECONDS;
911 mcp->flags = 0;
912 rval = qla2x00_mailbox_command(vha, mcp);
913 if (rval != QLA_SUCCESS) {
914 /*EMPTY*/
915 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
916 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500917 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
918 "Done %s.\n", __func__);
919 }
920
921 return rval;
922}
923
924/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500925 * qla_get_exchoffld_status
926 * Get exchange offload status
927 * uses the memory offload control/status Mailbox
928 *
929 * Input:
930 * ha: adapter state pointer.
931 * fwopt: firmware options
932 *
933 * Returns:
934 * qla2x00 local function status
935 *
936 * Context:
937 * Kernel context.
938 */
939#define FETCH_XCHOFFLD_STAT 0x2
940int
941qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
942 uint16_t *ex_logins_cnt)
943{
944 int rval;
945 mbx_cmd_t mc;
946 mbx_cmd_t *mcp = &mc;
947
948 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
949 "Entered %s\n", __func__);
950
951 memset(mcp->mb, 0 , sizeof(mcp->mb));
952 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
953 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
954 mcp->out_mb = MBX_1|MBX_0;
955 mcp->in_mb = MBX_10|MBX_4|MBX_0;
956 mcp->tov = MBX_TOV_SECONDS;
957 mcp->flags = 0;
958
959 rval = qla2x00_mailbox_command(vha, mcp);
960 if (rval != QLA_SUCCESS) {
961 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
962 } else {
963 *buf_sz = mcp->mb[4];
964 *ex_logins_cnt = mcp->mb[10];
965
966 ql_log(ql_log_info, vha, 0x118e,
967 "buffer size 0x%x, exchange offload count=%d\n",
968 mcp->mb[4], mcp->mb[10]);
969
970 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
971 "Done %s.\n", __func__);
972 }
973
974 return rval;
975}
976
977/*
978 * qla_set_exchoffld_mem_cfg
979 * Set exchange offload memory configuration
980 * Mbx needs to be issues before init_cb is set
981 *
982 * Input:
983 * ha: adapter state pointer.
984 * buffer: buffer pointer
985 * phys_addr: physical address of buffer
986 * size: size of buffer
987 * TARGET_QUEUE_LOCK must be released
988 * ADAPTER_STATE_LOCK must be release
989 *
990 * Returns:
991 * qla2x00 local funxtion status code.
992 *
993 * Context:
994 * Kernel context.
995 */
996#define CONFIG_XCHOFFLD_MEM 0x3
997int
Quinn Tran99e1b682017-06-02 09:12:03 -0700998qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500999{
1000 int rval;
1001 mbx_cmd_t mc;
1002 mbx_cmd_t *mcp = &mc;
1003 struct qla_hw_data *ha = vha->hw;
1004
1005 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
1006 "Entered %s.\n", __func__);
1007
1008 memset(mcp->mb, 0 , sizeof(mcp->mb));
1009 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
1010 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -07001011 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
1012 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
1013 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
1014 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
1015 mcp->mb[8] = MSW(ha->exchoffld_size);
1016 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001017 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1018 mcp->in_mb = MBX_11|MBX_0;
1019 mcp->tov = MBX_TOV_SECONDS;
1020 mcp->flags = 0;
1021 rval = qla2x00_mailbox_command(vha, mcp);
1022 if (rval != QLA_SUCCESS) {
1023 /*EMPTY*/
1024 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
1025 } else {
1026 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
1027 "Done %s.\n", __func__);
1028 }
1029
1030 return rval;
1031}
1032
1033/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 * qla2x00_get_fw_version
1035 * Get firmware version.
1036 *
1037 * Input:
1038 * ha: adapter state pointer.
1039 * major: pointer for major number.
1040 * minor: pointer for minor number.
1041 * subminor: pointer for subminor number.
1042 *
1043 * Returns:
1044 * qla2x00 local function return status code.
1045 *
1046 * Context:
1047 * Kernel context.
1048 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001049int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001050qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051{
1052 int rval;
1053 mbx_cmd_t mc;
1054 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001055 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001057 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
1058 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
1061 mcp->out_mb = MBX_0;
1062 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001063 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001064 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -04001065 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001066 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001067 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001068 mcp->in_mb |=
1069 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07001070 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001071
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001073 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001074 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001075 if (rval != QLA_SUCCESS)
1076 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001079 ha->fw_major_version = mcp->mb[1];
1080 ha->fw_minor_version = mcp->mb[2];
1081 ha->fw_subminor_version = mcp->mb[3];
1082 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001083 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001084 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001086 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -04001087
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001088 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001089 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1090 ha->mpi_version[1] = mcp->mb[11] >> 8;
1091 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1092 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
1093 ha->phy_version[0] = mcp->mb[8] & 0xff;
1094 ha->phy_version[1] = mcp->mb[9] >> 8;
1095 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001096 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001097
Saurav Kashyap81178772012-08-22 14:21:04 -04001098 if (IS_FWI2_CAPABLE(ha)) {
1099 ha->fw_attributes_h = mcp->mb[15];
1100 ha->fw_attributes_ext[0] = mcp->mb[16];
1101 ha->fw_attributes_ext[1] = mcp->mb[17];
1102 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
1103 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
1104 __func__, mcp->mb[15], mcp->mb[6]);
1105 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
1106 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
1107 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001108
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001109 if (ha->fw_attributes_h & 0x4)
1110 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
1111 "%s: Firmware supports Extended Login 0x%x\n",
1112 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001113
1114 if (ha->fw_attributes_h & 0x8)
1115 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
1116 "%s: Firmware supports Exchange Offload 0x%x\n",
1117 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -07001118
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07001119 /*
1120 * FW supports nvme and driver load parameter requested nvme.
1121 * BIT 26 of fw_attributes indicates NVMe support.
1122 */
Giridhar Malavali171e4902019-01-30 09:50:44 -08001123 if ((ha->fw_attributes_h &
1124 (FW_ATTR_H_NVME | FW_ATTR_H_NVME_UPDATED)) &&
1125 ql2xnvmeenable) {
Darren Trapp03aaa892019-02-15 14:37:13 -08001126 if (ha->fw_attributes_h & FW_ATTR_H_NVME_FBURST)
1127 vha->flags.nvme_first_burst = 1;
1128
Duane Grigsbye84067d2017-06-21 13:48:43 -07001129 vha->flags.nvme_enabled = 1;
Darren Trapp1cbc0ef2018-03-20 23:09:37 -07001130 ql_log(ql_log_info, vha, 0xd302,
1131 "%s: FC-NVMe is Enabled (0x%x)\n",
1132 __func__, ha->fw_attributes_h);
1133 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001134 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001135
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001136 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07001137 ha->serdes_version[0] = mcp->mb[7] & 0xff;
1138 ha->serdes_version[1] = mcp->mb[8] >> 8;
1139 ha->serdes_version[2] = mcp->mb[8] & 0xff;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001140 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1141 ha->mpi_version[1] = mcp->mb[11] >> 8;
1142 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1143 ha->pep_version[0] = mcp->mb[13] & 0xff;
1144 ha->pep_version[1] = mcp->mb[14] >> 8;
1145 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001146 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
1147 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001148 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
1149 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Michael Hernandez3f006ac2019-03-12 11:08:22 -07001150 if (IS_QLA28XX(ha)) {
1151 if (mcp->mb[16] & BIT_10) {
1152 ql_log(ql_log_info, vha, 0xffff,
1153 "FW support secure flash updates\n");
1154 ha->flags.secure_fw = 1;
1155 }
1156 }
Chad Dupuisf73cb692014-02-26 04:15:06 -05001157 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001158
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001159failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (rval != QLA_SUCCESS) {
1161 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001162 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 } else {
1164 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001165 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
1166 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001168 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169}
1170
1171/*
1172 * qla2x00_get_fw_options
1173 * Set firmware options.
1174 *
1175 * Input:
1176 * ha = adapter block pointer.
1177 * fwopt = pointer for firmware options.
1178 *
1179 * Returns:
1180 * qla2x00 local function return status code.
1181 *
1182 * Context:
1183 * Kernel context.
1184 */
1185int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001186qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
1188 int rval;
1189 mbx_cmd_t mc;
1190 mbx_cmd_t *mcp = &mc;
1191
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001192 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1193 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1196 mcp->out_mb = MBX_0;
1197 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001198 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001200 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201
1202 if (rval != QLA_SUCCESS) {
1203 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001204 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001206 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 fwopts[1] = mcp->mb[1];
1208 fwopts[2] = mcp->mb[2];
1209 fwopts[3] = mcp->mb[3];
1210
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001211 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1212 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
1214
1215 return rval;
1216}
1217
1218
1219/*
1220 * qla2x00_set_fw_options
1221 * Set firmware options.
1222 *
1223 * Input:
1224 * ha = adapter block pointer.
1225 * fwopt = pointer for firmware options.
1226 *
1227 * Returns:
1228 * qla2x00 local function return status code.
1229 *
1230 * Context:
1231 * Kernel context.
1232 */
1233int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001234qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235{
1236 int rval;
1237 mbx_cmd_t mc;
1238 mbx_cmd_t *mcp = &mc;
1239
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001240 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1241 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242
1243 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1244 mcp->mb[1] = fwopts[1];
1245 mcp->mb[2] = fwopts[2];
1246 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001247 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001249 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001250 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001251 mcp->mb[10] = fwopts[10];
1252 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001253 } else {
1254 mcp->mb[10] = fwopts[10];
1255 mcp->mb[11] = fwopts[11];
1256 mcp->mb[12] = 0; /* Undocumented, but used */
1257 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1258 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001259 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001261 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001263 fwopts[0] = mcp->mb[0];
1264
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if (rval != QLA_SUCCESS) {
1266 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001267 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1268 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 } else {
1270 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001271 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1272 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
1274
1275 return rval;
1276}
1277
1278/*
1279 * qla2x00_mbx_reg_test
1280 * Mailbox register wrap test.
1281 *
1282 * Input:
1283 * ha = adapter block pointer.
1284 * TARGET_QUEUE_LOCK must be released.
1285 * ADAPTER_STATE_LOCK must be released.
1286 *
1287 * Returns:
1288 * qla2x00 local function return status code.
1289 *
1290 * Context:
1291 * Kernel context.
1292 */
1293int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001294qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295{
1296 int rval;
1297 mbx_cmd_t mc;
1298 mbx_cmd_t *mcp = &mc;
1299
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001300 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1301 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302
1303 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1304 mcp->mb[1] = 0xAAAA;
1305 mcp->mb[2] = 0x5555;
1306 mcp->mb[3] = 0xAA55;
1307 mcp->mb[4] = 0x55AA;
1308 mcp->mb[5] = 0xA5A5;
1309 mcp->mb[6] = 0x5A5A;
1310 mcp->mb[7] = 0x2525;
1311 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1312 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 -07001313 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001315 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317 if (rval == QLA_SUCCESS) {
1318 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1319 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1320 rval = QLA_FUNCTION_FAILED;
1321 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1322 mcp->mb[7] != 0x2525)
1323 rval = QLA_FUNCTION_FAILED;
1324 }
1325
1326 if (rval != QLA_SUCCESS) {
1327 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001328 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 } else {
1330 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001331 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1332 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 }
1334
1335 return rval;
1336}
1337
1338/*
1339 * qla2x00_verify_checksum
1340 * Verify firmware checksum.
1341 *
1342 * Input:
1343 * ha = adapter block pointer.
1344 * TARGET_QUEUE_LOCK must be released.
1345 * ADAPTER_STATE_LOCK must be released.
1346 *
1347 * Returns:
1348 * qla2x00 local function return status code.
1349 *
1350 * Context:
1351 * Kernel context.
1352 */
1353int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001354qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355{
1356 int rval;
1357 mbx_cmd_t mc;
1358 mbx_cmd_t *mcp = &mc;
1359
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001360 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1361 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
1363 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001364 mcp->out_mb = MBX_0;
1365 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001366 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001367 mcp->mb[1] = MSW(risc_addr);
1368 mcp->mb[2] = LSW(risc_addr);
1369 mcp->out_mb |= MBX_2|MBX_1;
1370 mcp->in_mb |= MBX_2|MBX_1;
1371 } else {
1372 mcp->mb[1] = LSW(risc_addr);
1373 mcp->out_mb |= MBX_1;
1374 mcp->in_mb |= MBX_1;
1375 }
1376
Ravi Anandb93480e2008-04-03 13:13:25 -07001377 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001379 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
1381 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001382 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1383 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1384 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001386 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1387 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389
1390 return rval;
1391}
1392
1393/*
1394 * qla2x00_issue_iocb
1395 * Issue IOCB using mailbox command
1396 *
1397 * Input:
1398 * ha = adapter state pointer.
1399 * buffer = buffer pointer.
1400 * phys_addr = physical address of buffer.
1401 * size = size of buffer.
1402 * TARGET_QUEUE_LOCK must be released.
1403 * ADAPTER_STATE_LOCK must be released.
1404 *
1405 * Returns:
1406 * qla2x00 local function return status code.
1407 *
1408 * Context:
1409 * Kernel context.
1410 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001411int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001412qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001413 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414{
1415 int rval;
1416 mbx_cmd_t mc;
1417 mbx_cmd_t *mcp = &mc;
1418
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001419 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1420 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001421
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1423 mcp->mb[1] = 0;
1424 mcp->mb[2] = MSW(phys_addr);
1425 mcp->mb[3] = LSW(phys_addr);
1426 mcp->mb[6] = MSW(MSD(phys_addr));
1427 mcp->mb[7] = LSW(MSD(phys_addr));
1428 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1429 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001430 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001432 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 if (rval != QLA_SUCCESS) {
1435 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001436 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001438 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1439
1440 /* Mask reserved bits. */
1441 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001442 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001443 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1444 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 }
1446
1447 return rval;
1448}
1449
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001450int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001451qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001452 size_t size)
1453{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001454 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001455 MBX_TOV_SECONDS);
1456}
1457
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458/*
1459 * qla2x00_abort_command
1460 * Abort command aborts a specified IOCB.
1461 *
1462 * Input:
1463 * ha = adapter block pointer.
1464 * sp = SB structure pointer.
1465 *
1466 * Returns:
1467 * qla2x00 local function return status code.
1468 *
1469 * Context:
1470 * Kernel context.
1471 */
1472int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001473qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001477 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 mbx_cmd_t mc;
1479 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001480 fc_port_t *fcport = sp->fcport;
1481 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001482 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001483 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001484 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001486 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1487 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
Michael Hernandezd7459522016-12-12 14:40:07 -08001489 if (vha->flags.qpairs_available && sp->qpair)
1490 req = sp->qpair->req;
1491 else
1492 req = vha->req;
1493
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001494 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001495 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001496 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 break;
1498 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001499 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
Chad Dupuis8d93f552013-01-30 03:34:37 -05001501 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 /* command not found */
1503 return QLA_FUNCTION_FAILED;
1504 }
1505
1506 mcp->mb[0] = MBC_ABORT_COMMAND;
1507 if (HAS_EXTENDED_IDS(ha))
1508 mcp->mb[1] = fcport->loop_id;
1509 else
1510 mcp->mb[1] = fcport->loop_id << 8;
1511 mcp->mb[2] = (uint16_t)handle;
1512 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001513 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1515 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001516 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001518 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
1520 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001521 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001523 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1524 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
1526
1527 return rval;
1528}
1529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001531qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001533 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 mbx_cmd_t mc;
1535 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001536 scsi_qla_host_t *vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001538 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001539
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001540 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1541 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001542
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001544 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001545 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 mcp->mb[1] = fcport->loop_id;
1547 mcp->mb[10] = 0;
1548 mcp->out_mb |= MBX_10;
1549 } else {
1550 mcp->mb[1] = fcport->loop_id << 8;
1551 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001552 mcp->mb[2] = vha->hw->loop_reset_delay;
1553 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001556 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001558 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1561 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001562 }
1563
1564 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08001565 rval2 = qla2x00_marker(vha, vha->hw->base_qpair, fcport->loop_id, 0,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001566 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001567 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001568 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1569 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001571 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1572 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001573 }
1574
1575 return rval;
1576}
1577
1578int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001579qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001580{
1581 int rval, rval2;
1582 mbx_cmd_t mc;
1583 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001584 scsi_qla_host_t *vha;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001585
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001586 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001587
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1589 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001590
Andrew Vasquez523ec772008-04-03 13:13:24 -07001591 mcp->mb[0] = MBC_LUN_RESET;
1592 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001593 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001594 mcp->mb[1] = fcport->loop_id;
1595 else
1596 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001597 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001598 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001599 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001600
1601 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001602 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001603 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001604 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001605 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001606 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001607 }
1608
1609 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08001610 rval2 = qla2x00_marker(vha, vha->hw->base_qpair, fcport->loop_id, l,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001611 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001612 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001613 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1614 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001615 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001616 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1617 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 }
1619
1620 return rval;
1621}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 * qla2x00_get_adapter_id
1625 * Get adapter ID and topology.
1626 *
1627 * Input:
1628 * ha = adapter block pointer.
1629 * id = pointer for loop ID.
1630 * al_pa = pointer for AL_PA.
1631 * area = pointer for area.
1632 * domain = pointer for domain.
1633 * top = pointer for topology.
1634 * TARGET_QUEUE_LOCK must be released.
1635 * ADAPTER_STATE_LOCK must be released.
1636 *
1637 * Returns:
1638 * qla2x00 local function return status code.
1639 *
1640 * Context:
1641 * Kernel context.
1642 */
1643int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001644qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001645 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646{
1647 int rval;
1648 mbx_cmd_t mc;
1649 mbx_cmd_t *mcp = &mc;
1650
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001651 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1652 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001655 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001656 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001657 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001658 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001659 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001660 if (IS_FWI2_CAPABLE(vha->hw))
1661 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001662 if (IS_QLA27XX(vha->hw) || IS_QLA28XX(vha->hw))
Sawan Chandak969a6192016-01-27 12:03:32 -05001663 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001664 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001666 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001667 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1668 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001669 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1670 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
1672 /* Return data. */
1673 *id = mcp->mb[1];
1674 *al_pa = LSB(mcp->mb[2]);
1675 *area = MSB(mcp->mb[2]);
1676 *domain = LSB(mcp->mb[3]);
1677 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001678 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679
1680 if (rval != QLA_SUCCESS) {
1681 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001682 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001684 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1685 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001686
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001687 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001688 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1689 vha->fcoe_fcf_idx = mcp->mb[10];
1690 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1691 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1692 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1693 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1694 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1695 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1696 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001697 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001698 if (IS_FAWWN_CAPABLE(vha->hw)) {
1699 if (mcp->mb[7] & BIT_14) {
1700 vha->port_name[0] = MSB(mcp->mb[16]);
1701 vha->port_name[1] = LSB(mcp->mb[16]);
1702 vha->port_name[2] = MSB(mcp->mb[17]);
1703 vha->port_name[3] = LSB(mcp->mb[17]);
1704 vha->port_name[4] = MSB(mcp->mb[18]);
1705 vha->port_name[5] = LSB(mcp->mb[18]);
1706 vha->port_name[6] = MSB(mcp->mb[19]);
1707 vha->port_name[7] = LSB(mcp->mb[19]);
1708 fc_host_port_name(vha->host) =
1709 wwn_to_u64(vha->port_name);
1710 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1711 "FA-WWN acquired %016llx\n",
1712 wwn_to_u64(vha->port_name));
1713 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001714 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001715
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001716 if (IS_QLA27XX(vha->hw) || IS_QLA28XX(vha->hw))
Sawan Chandak969a6192016-01-27 12:03:32 -05001717 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 }
1719
1720 return rval;
1721}
1722
1723/*
1724 * qla2x00_get_retry_cnt
1725 * Get current firmware login retry count and delay.
1726 *
1727 * Input:
1728 * ha = adapter block pointer.
1729 * retry_cnt = pointer to login retry count.
1730 * tov = pointer to login timeout value.
1731 *
1732 * Returns:
1733 * qla2x00 local function return status code.
1734 *
1735 * Context:
1736 * Kernel context.
1737 */
1738int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001739qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 uint16_t *r_a_tov)
1741{
1742 int rval;
1743 uint16_t ratov;
1744 mbx_cmd_t mc;
1745 mbx_cmd_t *mcp = &mc;
1746
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001747 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1748 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749
1750 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1751 mcp->out_mb = MBX_0;
1752 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001753 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001755 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756
1757 if (rval != QLA_SUCCESS) {
1758 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001759 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1760 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 } else {
1762 /* Convert returned data and check our values. */
1763 *r_a_tov = mcp->mb[3] / 2;
1764 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1765 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1766 /* Update to the larger values */
1767 *retry_cnt = (uint8_t)mcp->mb[1];
1768 *tov = ratov;
1769 }
1770
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001771 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001772 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
1774
1775 return rval;
1776}
1777
1778/*
1779 * qla2x00_init_firmware
1780 * Initialize adapter firmware.
1781 *
1782 * Input:
1783 * ha = adapter block pointer.
1784 * dptr = Initialization control block pointer.
1785 * size = size of initialization control block.
1786 * TARGET_QUEUE_LOCK must be released.
1787 * ADAPTER_STATE_LOCK must be released.
1788 *
1789 * Returns:
1790 * qla2x00 local function return status code.
1791 *
1792 * Context:
1793 * Kernel context.
1794 */
1795int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001796qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797{
1798 int rval;
1799 mbx_cmd_t mc;
1800 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001801 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001803 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1804 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001806 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001807 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001808 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1809
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001810 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001811 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1812 else
1813 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1814
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001815 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 mcp->mb[2] = MSW(ha->init_cb_dma);
1817 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1819 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001820 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001821 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001822 mcp->mb[1] = BIT_0;
1823 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1824 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1825 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1826 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1827 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1828 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1829 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001830 /* 1 and 2 should normally be captured. */
1831 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001832 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001833 /* mb3 is additional info about the installed SFP. */
1834 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 mcp->buf_size = size;
1836 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001837 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001838 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
1840 if (rval != QLA_SUCCESS) {
1841 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001842 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07001843 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x.\n",
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001844 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Joe Carnucciof8f97b02019-03-12 11:08:16 -07001845 if (ha->init_cb) {
1846 ql_dbg(ql_dbg_mbx, vha, 0x104d, "init_cb:\n");
1847 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha,
1848 0x0104d, ha->init_cb, sizeof(*ha->init_cb));
1849 }
1850 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
1851 ql_dbg(ql_dbg_mbx, vha, 0x104d, "ex_init_cb:\n");
1852 ql_dump_buffer(ql_dbg_init + ql_dbg_verbose, vha,
1853 0x0104d, ha->ex_init_cb, sizeof(*ha->ex_init_cb));
1854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 } else {
Joe Carnuccioecc89f22019-03-12 11:08:13 -07001856 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -07001857 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1858 ql_dbg(ql_dbg_mbx, vha, 0x119d,
1859 "Invalid SFP/Validation Failed\n");
1860 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001861 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1862 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 }
1864
1865 return rval;
1866}
1867
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001868
1869/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 * qla2x00_get_port_database
1871 * Issue normal/enhanced get port database mailbox command
1872 * and copy device name as necessary.
1873 *
1874 * Input:
1875 * ha = adapter state pointer.
1876 * dev = structure pointer.
1877 * opt = enhanced cmd option byte.
1878 *
1879 * Returns:
1880 * qla2x00 local function return status code.
1881 *
1882 * Context:
1883 * Kernel context.
1884 */
1885int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001886qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
1888 int rval;
1889 mbx_cmd_t mc;
1890 mbx_cmd_t *mcp = &mc;
1891 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001892 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001894 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001896 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1897 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001899 pd24 = NULL;
Thomas Meyer08eb7f42017-09-21 08:15:26 +02001900 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001902 ql_log(ql_log_warn, vha, 0x1050,
1903 "Failed to allocate port database structure.\n");
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001904 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 return QLA_MEMORY_ALLOC_FAILED;
1906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001908 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001909 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 mcp->mb[2] = MSW(pd_dma);
1912 mcp->mb[3] = LSW(pd_dma);
1913 mcp->mb[6] = MSW(MSD(pd_dma));
1914 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001915 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001916 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001918 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001919 mcp->mb[1] = fcport->loop_id;
1920 mcp->mb[10] = opt;
1921 mcp->out_mb |= MBX_10|MBX_1;
1922 mcp->in_mb |= MBX_1;
1923 } else if (HAS_EXTENDED_IDS(ha)) {
1924 mcp->mb[1] = fcport->loop_id;
1925 mcp->mb[10] = opt;
1926 mcp->out_mb |= MBX_10|MBX_1;
1927 } else {
1928 mcp->mb[1] = fcport->loop_id << 8 | opt;
1929 mcp->out_mb |= MBX_1;
1930 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001931 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1932 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 mcp->flags = MBX_DMA_IN;
1934 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001935 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 if (rval != QLA_SUCCESS)
1937 goto gpd_error_out;
1938
Andrew Vasqueze4289242007-07-19 15:05:56 -07001939 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001940 uint64_t zero = 0;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001941 u8 current_login_state, last_login_state;
1942
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001943 pd24 = (struct port_database_24xx *) pd;
1944
1945 /* Check for logged in state. */
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001946 if (fcport->fc4f_nvme) {
1947 current_login_state = pd24->current_login_state >> 4;
1948 last_login_state = pd24->last_login_state >> 4;
1949 } else {
1950 current_login_state = pd24->current_login_state & 0xf;
1951 last_login_state = pd24->last_login_state & 0xf;
1952 }
1953 fcport->current_login_state = pd24->current_login_state;
1954 fcport->last_login_state = pd24->last_login_state;
1955
1956 /* Check for logged in state. */
1957 if (current_login_state != PDS_PRLI_COMPLETE &&
1958 last_login_state != PDS_PRLI_COMPLETE) {
1959 ql_dbg(ql_dbg_mbx, vha, 0x119a,
1960 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
1961 current_login_state, last_login_state,
1962 fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001963 rval = QLA_FUNCTION_FAILED;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001964
1965 if (!fcport->query)
1966 goto gpd_error_out;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001967 }
1968
Arun Easi0eba25d2012-02-09 11:15:58 -08001969 if (fcport->loop_id == FC_NO_LOOP_ID ||
1970 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1971 memcmp(fcport->port_name, pd24->port_name, 8))) {
1972 /* We lost the device mid way. */
1973 rval = QLA_NOT_LOGGED_IN;
1974 goto gpd_error_out;
1975 }
1976
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001977 /* Names are little-endian. */
1978 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1979 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1980
1981 /* Get port_id of device. */
1982 fcport->d_id.b.domain = pd24->port_id[0];
1983 fcport->d_id.b.area = pd24->port_id[1];
1984 fcport->d_id.b.al_pa = pd24->port_id[2];
1985 fcport->d_id.b.rsvd_1 = 0;
1986
1987 /* If not target must be initiator or unknown type. */
1988 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1989 fcport->port_type = FCT_INITIATOR;
1990 else
1991 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001992
1993 /* Passback COS information. */
1994 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1995 FC_COS_CLASS2 : FC_COS_CLASS3;
1996
1997 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1998 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001999 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08002000 uint64_t zero = 0;
2001
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002002 /* Check for logged in state. */
2003 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
2004 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002005 ql_dbg(ql_dbg_mbx, vha, 0x100a,
2006 "Unable to verify login-state (%x/%x) - "
2007 "portid=%02x%02x%02x.\n", pd->master_state,
2008 pd->slave_state, fcport->d_id.b.domain,
2009 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002010 rval = QLA_FUNCTION_FAILED;
2011 goto gpd_error_out;
2012 }
2013
Arun Easi0eba25d2012-02-09 11:15:58 -08002014 if (fcport->loop_id == FC_NO_LOOP_ID ||
2015 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
2016 memcmp(fcport->port_name, pd->port_name, 8))) {
2017 /* We lost the device mid way. */
2018 rval = QLA_NOT_LOGGED_IN;
2019 goto gpd_error_out;
2020 }
2021
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002022 /* Names are little-endian. */
2023 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
2024 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
2025
2026 /* Get port_id of device. */
2027 fcport->d_id.b.domain = pd->port_id[0];
2028 fcport->d_id.b.area = pd->port_id[3];
2029 fcport->d_id.b.al_pa = pd->port_id[2];
2030 fcport->d_id.b.rsvd_1 = 0;
2031
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002032 /* If not target must be initiator or unknown type. */
2033 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
2034 fcport->port_type = FCT_INITIATOR;
2035 else
2036 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002037
2038 /* Passback COS information. */
2039 fcport->supported_classes = (pd->options & BIT_4) ?
Bart Van Assche58e27532019-04-11 14:53:19 -07002040 FC_COS_CLASS2 : FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 }
2042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043gpd_error_out:
2044 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07002045 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
2047 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002048 ql_dbg(ql_dbg_mbx, vha, 0x1052,
2049 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
2050 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002052 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
2053 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 }
2055
2056 return rval;
2057}
2058
2059/*
2060 * qla2x00_get_firmware_state
2061 * Get adapter firmware state.
2062 *
2063 * Input:
2064 * ha = adapter block pointer.
2065 * dptr = pointer for firmware state.
2066 * TARGET_QUEUE_LOCK must be released.
2067 * ADAPTER_STATE_LOCK must be released.
2068 *
2069 * Returns:
2070 * qla2x00 local function return status code.
2071 *
2072 * Context:
2073 * Kernel context.
2074 */
2075int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002076qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 int rval;
2079 mbx_cmd_t mc;
2080 mbx_cmd_t *mcp = &mc;
Sawan Chandak92d44082017-08-23 15:05:16 -07002081 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002083 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
2084 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085
2086 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
2087 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002088 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002089 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002090 else
2091 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002092 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002094 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002096 /* Return firmware states. */
2097 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002098 if (IS_FWI2_CAPABLE(vha->hw)) {
2099 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04002100 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002101 states[3] = mcp->mb[4];
2102 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002103 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002104 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105
2106 if (rval != QLA_SUCCESS) {
2107 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002108 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 } else {
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002110 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Sawan Chandak92d44082017-08-23 15:05:16 -07002111 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
2112 ql_dbg(ql_dbg_mbx, vha, 0x119e,
2113 "Invalid SFP/Validation Failed\n");
2114 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002115 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
2116 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
2118
2119 return rval;
2120}
2121
2122/*
2123 * qla2x00_get_port_name
2124 * Issue get port name mailbox command.
2125 * Returned name is in big endian format.
2126 *
2127 * Input:
2128 * ha = adapter block pointer.
2129 * loop_id = loop ID of device.
2130 * name = pointer for name.
2131 * TARGET_QUEUE_LOCK must be released.
2132 * ADAPTER_STATE_LOCK must be released.
2133 *
2134 * Returns:
2135 * qla2x00 local function return status code.
2136 *
2137 * Context:
2138 * Kernel context.
2139 */
2140int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002141qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 uint8_t opt)
2143{
2144 int rval;
2145 mbx_cmd_t mc;
2146 mbx_cmd_t *mcp = &mc;
2147
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002148 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
2149 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
2151 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002152 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002153 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002154 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 mcp->mb[1] = loop_id;
2156 mcp->mb[10] = opt;
2157 mcp->out_mb |= MBX_10;
2158 } else {
2159 mcp->mb[1] = loop_id << 8 | opt;
2160 }
2161
2162 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002163 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002165 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 if (rval != QLA_SUCCESS) {
2168 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002169 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 } else {
2171 if (name != NULL) {
2172 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002173 name[0] = MSB(mcp->mb[2]);
2174 name[1] = LSB(mcp->mb[2]);
2175 name[2] = MSB(mcp->mb[3]);
2176 name[3] = LSB(mcp->mb[3]);
2177 name[4] = MSB(mcp->mb[6]);
2178 name[5] = LSB(mcp->mb[6]);
2179 name[6] = MSB(mcp->mb[7]);
2180 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 }
2182
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002183 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2184 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 }
2186
2187 return rval;
2188}
2189
2190/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002191 * qla24xx_link_initialization
2192 * Issue link initialization mailbox command.
2193 *
2194 * Input:
2195 * ha = adapter block pointer.
2196 * TARGET_QUEUE_LOCK must be released.
2197 * ADAPTER_STATE_LOCK must be released.
2198 *
2199 * Returns:
2200 * qla2x00 local function return status code.
2201 *
2202 * Context:
2203 * Kernel context.
2204 */
2205int
2206qla24xx_link_initialize(scsi_qla_host_t *vha)
2207{
2208 int rval;
2209 mbx_cmd_t mc;
2210 mbx_cmd_t *mcp = &mc;
2211
2212 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2213 "Entered %s.\n", __func__);
2214
2215 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2216 return QLA_FUNCTION_FAILED;
2217
2218 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002219 mcp->mb[1] = BIT_4;
2220 if (vha->hw->operating_mode == LOOP)
2221 mcp->mb[1] |= BIT_6;
2222 else
2223 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002224 mcp->mb[2] = 0;
2225 mcp->mb[3] = 0;
2226 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2227 mcp->in_mb = MBX_0;
2228 mcp->tov = MBX_TOV_SECONDS;
2229 mcp->flags = 0;
2230 rval = qla2x00_mailbox_command(vha, mcp);
2231
2232 if (rval != QLA_SUCCESS) {
2233 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2234 } else {
2235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2236 "Done %s.\n", __func__);
2237 }
2238
2239 return rval;
2240}
2241
2242/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 * qla2x00_lip_reset
2244 * Issue LIP reset mailbox command.
2245 *
2246 * Input:
2247 * ha = adapter block pointer.
2248 * TARGET_QUEUE_LOCK must be released.
2249 * ADAPTER_STATE_LOCK must be released.
2250 *
2251 * Returns:
2252 * qla2x00 local function return status code.
2253 *
2254 * Context:
2255 * Kernel context.
2256 */
2257int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002258qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
2260 int rval;
2261 mbx_cmd_t mc;
2262 mbx_cmd_t *mcp = &mc;
2263
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002264 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2265 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002267 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002268 /* Logout across all FCFs. */
2269 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2270 mcp->mb[1] = BIT_1;
2271 mcp->mb[2] = 0;
2272 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2273 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002274 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002275 mcp->mb[1] = BIT_4;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002276 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002277 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002278 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002280 mcp->mb[0] = MBC_LIP_RESET;
2281 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002282 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283 mcp->mb[1] = 0x00ff;
2284 mcp->mb[10] = 0;
2285 mcp->out_mb |= MBX_10;
2286 } else {
2287 mcp->mb[1] = 0xff00;
2288 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002289 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002290 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002293 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002295 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296
2297 if (rval != QLA_SUCCESS) {
2298 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002299 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 } else {
2301 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2303 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 }
2305
2306 return rval;
2307}
2308
2309/*
2310 * qla2x00_send_sns
2311 * Send SNS command.
2312 *
2313 * Input:
2314 * ha = adapter block pointer.
2315 * sns = pointer for command.
2316 * cmd_size = command size.
2317 * buf_size = response/command size.
2318 * TARGET_QUEUE_LOCK must be released.
2319 * ADAPTER_STATE_LOCK must be released.
2320 *
2321 * Returns:
2322 * qla2x00 local function return status code.
2323 *
2324 * Context:
2325 * Kernel context.
2326 */
2327int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002328qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 uint16_t cmd_size, size_t buf_size)
2330{
2331 int rval;
2332 mbx_cmd_t mc;
2333 mbx_cmd_t *mcp = &mc;
2334
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002335 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2336 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002339 "Retry cnt=%d ratov=%d total tov=%d.\n",
2340 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
2342 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2343 mcp->mb[1] = cmd_size;
2344 mcp->mb[2] = MSW(sns_phys_address);
2345 mcp->mb[3] = LSW(sns_phys_address);
2346 mcp->mb[6] = MSW(MSD(sns_phys_address));
2347 mcp->mb[7] = LSW(MSD(sns_phys_address));
2348 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2349 mcp->in_mb = MBX_0|MBX_1;
2350 mcp->buf_size = buf_size;
2351 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002352 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2353 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355 if (rval != QLA_SUCCESS) {
2356 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002357 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2358 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2359 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 } else {
2361 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002362 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2363 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 }
2365
2366 return rval;
2367}
2368
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002369int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002370qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002371 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2372{
2373 int rval;
2374
2375 struct logio_entry_24xx *lg;
2376 dma_addr_t lg_dma;
2377 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002378 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002379 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002380
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002381 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2382 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002383
Michael Hernandezd7459522016-12-12 14:40:07 -08002384 if (vha->vp_idx && vha->qpair)
2385 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002386 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002387 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002388
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002389 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002390 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002391 ql_log(ql_log_warn, vha, 0x1062,
2392 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002393 return QLA_MEMORY_ALLOC_FAILED;
2394 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002395
2396 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2397 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002398 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002399 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002400 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002401 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002402 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002403 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002404 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002405 lg->port_id[0] = al_pa;
2406 lg->port_id[1] = area;
2407 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002408 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002409 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2410 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002411 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002412 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2413 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002414 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002415 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2416 "Failed to complete IOCB -- error status (%x).\n",
2417 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002418 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002419 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002420 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2421 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2422
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002423 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2424 "Failed to complete IOCB -- completion status (%x) "
2425 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2426 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002427
2428 switch (iop[0]) {
2429 case LSC_SCODE_PORTID_USED:
2430 mb[0] = MBS_PORT_ID_USED;
2431 mb[1] = LSW(iop[1]);
2432 break;
2433 case LSC_SCODE_NPORT_USED:
2434 mb[0] = MBS_LOOP_ID_USED;
2435 break;
2436 case LSC_SCODE_NOLINK:
2437 case LSC_SCODE_NOIOCB:
2438 case LSC_SCODE_NOXCB:
2439 case LSC_SCODE_CMD_FAILED:
2440 case LSC_SCODE_NOFABRIC:
2441 case LSC_SCODE_FW_NOT_READY:
2442 case LSC_SCODE_NOT_LOGGED_IN:
2443 case LSC_SCODE_NOPCB:
2444 case LSC_SCODE_ELS_REJECT:
2445 case LSC_SCODE_CMD_PARAM_ERR:
2446 case LSC_SCODE_NONPORT:
2447 case LSC_SCODE_LOGGED_IN:
2448 case LSC_SCODE_NOFLOGI_ACC:
2449 default:
2450 mb[0] = MBS_COMMAND_ERROR;
2451 break;
2452 }
2453 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002454 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2455 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002456
2457 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2458
2459 mb[0] = MBS_COMMAND_COMPLETE;
2460 mb[1] = 0;
2461 if (iop[0] & BIT_4) {
2462 if (iop[0] & BIT_8)
2463 mb[1] |= BIT_1;
2464 } else
2465 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002466
2467 /* Passback COS information. */
2468 mb[10] = 0;
2469 if (lg->io_parameter[7] || lg->io_parameter[8])
2470 mb[10] |= BIT_0; /* Class 2. */
2471 if (lg->io_parameter[9] || lg->io_parameter[10])
2472 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002473 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002474 mb[10] |= BIT_7; /* Confirmed Completion
2475 * Allowed
2476 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002477 }
2478
2479 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2480
2481 return rval;
2482}
2483
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484/*
2485 * qla2x00_login_fabric
2486 * Issue login fabric port mailbox command.
2487 *
2488 * Input:
2489 * ha = adapter block pointer.
2490 * loop_id = device loop ID.
2491 * domain = device domain.
2492 * area = device area.
2493 * al_pa = device AL_PA.
2494 * status = pointer for return status.
2495 * opt = command options.
2496 * TARGET_QUEUE_LOCK must be released.
2497 * ADAPTER_STATE_LOCK must be released.
2498 *
2499 * Returns:
2500 * qla2x00 local function return status code.
2501 *
2502 * Context:
2503 * Kernel context.
2504 */
2505int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002506qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2508{
2509 int rval;
2510 mbx_cmd_t mc;
2511 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002512 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002514 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2515 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516
2517 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2518 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2519 if (HAS_EXTENDED_IDS(ha)) {
2520 mcp->mb[1] = loop_id;
2521 mcp->mb[10] = opt;
2522 mcp->out_mb |= MBX_10;
2523 } else {
2524 mcp->mb[1] = (loop_id << 8) | opt;
2525 }
2526 mcp->mb[2] = domain;
2527 mcp->mb[3] = area << 8 | al_pa;
2528
2529 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2530 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2531 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002532 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533
2534 /* Return mailbox statuses. */
2535 if (mb != NULL) {
2536 mb[0] = mcp->mb[0];
2537 mb[1] = mcp->mb[1];
2538 mb[2] = mcp->mb[2];
2539 mb[6] = mcp->mb[6];
2540 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002541 /* COS retrieved from Get-Port-Database mailbox command. */
2542 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 }
2544
2545 if (rval != QLA_SUCCESS) {
2546 /* RLU tmp code: need to change main mailbox_command function to
2547 * return ok even when the mailbox completion value is not
2548 * SUCCESS. The caller needs to be responsible to interpret
2549 * the return values of this mailbox command if we're not
2550 * to change too much of the existing code.
2551 */
2552 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2553 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2554 mcp->mb[0] == 0x4006)
2555 rval = QLA_SUCCESS;
2556
2557 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002558 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2559 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2560 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 } else {
2562 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002563 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2564 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 }
2566
2567 return rval;
2568}
2569
2570/*
2571 * qla2x00_login_local_device
2572 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002573 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 * Input:
2575 * ha = adapter block pointer.
2576 * loop_id = device loop ID.
2577 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002578 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 * Returns:
2580 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002581 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 * Context:
2583 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002584 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 */
2586int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002587qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 uint16_t *mb_ret, uint8_t opt)
2589{
2590 int rval;
2591 mbx_cmd_t mc;
2592 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002593 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002595 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2596 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002597
Andrew Vasqueze4289242007-07-19 15:05:56 -07002598 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002599 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002600 fcport->d_id.b.domain, fcport->d_id.b.area,
2601 fcport->d_id.b.al_pa, mb_ret, opt);
2602
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2604 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002605 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002607 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 mcp->mb[2] = opt;
2609 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2610 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2611 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2612 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002613 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614
2615 /* Return mailbox statuses. */
2616 if (mb_ret != NULL) {
2617 mb_ret[0] = mcp->mb[0];
2618 mb_ret[1] = mcp->mb[1];
2619 mb_ret[6] = mcp->mb[6];
2620 mb_ret[7] = mcp->mb[7];
2621 }
2622
2623 if (rval != QLA_SUCCESS) {
2624 /* AV tmp code: need to change main mailbox_command function to
2625 * return ok even when the mailbox completion value is not
2626 * SUCCESS. The caller needs to be responsible to interpret
2627 * the return values of this mailbox command if we're not
2628 * to change too much of the existing code.
2629 */
2630 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2631 rval = QLA_SUCCESS;
2632
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002633 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2634 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2635 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 } else {
2637 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002638 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2639 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 }
2641
2642 return (rval);
2643}
2644
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002645int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002646qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002647 uint8_t area, uint8_t al_pa)
2648{
2649 int rval;
2650 struct logio_entry_24xx *lg;
2651 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002652 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002653 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002654
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002655 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2656 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002657
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002658 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002659 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002660 ql_log(ql_log_warn, vha, 0x106e,
2661 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002662 return QLA_MEMORY_ALLOC_FAILED;
2663 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002664
Michael Hernandezd7459522016-12-12 14:40:07 -08002665 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002666 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2667 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002668 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002669 lg->nport_handle = cpu_to_le16(loop_id);
2670 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002671 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002672 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002673 lg->port_id[0] = al_pa;
2674 lg->port_id[1] = area;
2675 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002676 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002677 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2678 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002679 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002680 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2681 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002682 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002683 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2684 "Failed to complete IOCB -- error status (%x).\n",
2685 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002686 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002687 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002688 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2689 "Failed to complete IOCB -- completion status (%x) "
2690 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002691 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002692 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002693 } else {
2694 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002695 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2696 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002697 }
2698
2699 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2700
2701 return rval;
2702}
2703
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704/*
2705 * qla2x00_fabric_logout
2706 * Issue logout fabric port mailbox command.
2707 *
2708 * Input:
2709 * ha = adapter block pointer.
2710 * loop_id = device loop ID.
2711 * TARGET_QUEUE_LOCK must be released.
2712 * ADAPTER_STATE_LOCK must be released.
2713 *
2714 * Returns:
2715 * qla2x00 local function return status code.
2716 *
2717 * Context:
2718 * Kernel context.
2719 */
2720int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002721qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002722 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723{
2724 int rval;
2725 mbx_cmd_t mc;
2726 mbx_cmd_t *mcp = &mc;
2727
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002728 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2729 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
2731 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2732 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002733 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 mcp->mb[1] = loop_id;
2735 mcp->mb[10] = 0;
2736 mcp->out_mb |= MBX_10;
2737 } else {
2738 mcp->mb[1] = loop_id << 8;
2739 }
2740
2741 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002742 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002744 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
2746 if (rval != QLA_SUCCESS) {
2747 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002748 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2749 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 } else {
2751 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002752 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2753 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 }
2755
2756 return rval;
2757}
2758
2759/*
2760 * qla2x00_full_login_lip
2761 * Issue full login LIP mailbox command.
2762 *
2763 * Input:
2764 * ha = adapter block pointer.
2765 * TARGET_QUEUE_LOCK must be released.
2766 * ADAPTER_STATE_LOCK must be released.
2767 *
2768 * Returns:
2769 * qla2x00 local function return status code.
2770 *
2771 * Context:
2772 * Kernel context.
2773 */
2774int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002775qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776{
2777 int rval;
2778 mbx_cmd_t mc;
2779 mbx_cmd_t *mcp = &mc;
2780
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002781 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2782 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002785 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_4 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002786 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 mcp->mb[3] = 0;
2788 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2789 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002790 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002792 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
2794 if (rval != QLA_SUCCESS) {
2795 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002796 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 } else {
2798 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002799 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2800 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 }
2802
2803 return rval;
2804}
2805
2806/*
2807 * qla2x00_get_id_list
2808 *
2809 * Input:
2810 * ha = adapter block pointer.
2811 *
2812 * Returns:
2813 * qla2x00 local function return status code.
2814 *
2815 * Context:
2816 * Kernel context.
2817 */
2818int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002819qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 uint16_t *entries)
2821{
2822 int rval;
2823 mbx_cmd_t mc;
2824 mbx_cmd_t *mcp = &mc;
2825
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002826 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2827 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
2829 if (id_list == NULL)
2830 return QLA_FUNCTION_FAILED;
2831
2832 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002833 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002834 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002835 mcp->mb[2] = MSW(id_list_dma);
2836 mcp->mb[3] = LSW(id_list_dma);
2837 mcp->mb[6] = MSW(MSD(id_list_dma));
2838 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002839 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002840 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002841 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002842 } else {
2843 mcp->mb[1] = MSW(id_list_dma);
2844 mcp->mb[2] = LSW(id_list_dma);
2845 mcp->mb[3] = MSW(MSD(id_list_dma));
2846 mcp->mb[6] = LSW(MSD(id_list_dma));
2847 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002850 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002852 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853
2854 if (rval != QLA_SUCCESS) {
2855 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002856 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 } else {
2858 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002859 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2860 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 }
2862
2863 return rval;
2864}
2865
2866/*
2867 * qla2x00_get_resource_cnts
2868 * Get current firmware resource counts.
2869 *
2870 * Input:
2871 * ha = adapter block pointer.
2872 *
2873 * Returns:
2874 * qla2x00 local function return status code.
2875 *
2876 * Context:
2877 * Kernel context.
2878 */
2879int
Quinn Tran03e8c682015-12-17 14:56:59 -05002880qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881{
Quinn Tran03e8c682015-12-17 14:56:59 -05002882 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 int rval;
2884 mbx_cmd_t mc;
2885 mbx_cmd_t *mcp = &mc;
2886
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002887 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2888 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889
2890 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2891 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002892 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 -07002893 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
2894 IS_QLA27XX(ha) || IS_QLA28XX(ha))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002895 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002896 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002898 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
2900 if (rval != QLA_SUCCESS) {
2901 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002902 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2903 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002905 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002906 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2907 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2908 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2909 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
Quinn Tran03e8c682015-12-17 14:56:59 -05002911 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2912 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2913 ha->cur_fw_xcb_count = mcp->mb[3];
2914 ha->orig_fw_xcb_count = mcp->mb[6];
2915 ha->cur_fw_iocb_count = mcp->mb[7];
2916 ha->orig_fw_iocb_count = mcp->mb[10];
2917 if (ha->flags.npiv_supported)
2918 ha->max_npiv_vports = mcp->mb[11];
Joe Carnuccioecc89f22019-03-12 11:08:13 -07002919 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
2920 IS_QLA28XX(ha))
Quinn Tran03e8c682015-12-17 14:56:59 -05002921 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 }
2923
2924 return (rval);
2925}
2926
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927/*
2928 * qla2x00_get_fcal_position_map
2929 * Get FCAL (LILP) position map using mailbox command
2930 *
2931 * Input:
2932 * ha = adapter state pointer.
2933 * pos_map = buffer pointer (can be NULL).
2934 *
2935 * Returns:
2936 * qla2x00 local function return status code.
2937 *
2938 * Context:
2939 * Kernel context.
2940 */
2941int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002942qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943{
2944 int rval;
2945 mbx_cmd_t mc;
2946 mbx_cmd_t *mcp = &mc;
2947 char *pmap;
2948 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002949 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002951 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2952 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002953
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002954 pmap = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002956 ql_log(ql_log_warn, vha, 0x1080,
2957 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 return QLA_MEMORY_ALLOC_FAILED;
2959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960
2961 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2962 mcp->mb[2] = MSW(pmap_dma);
2963 mcp->mb[3] = LSW(pmap_dma);
2964 mcp->mb[6] = MSW(MSD(pmap_dma));
2965 mcp->mb[7] = LSW(MSD(pmap_dma));
2966 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2967 mcp->in_mb = MBX_1|MBX_0;
2968 mcp->buf_size = FCAL_MAP_SIZE;
2969 mcp->flags = MBX_DMA_IN;
2970 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002971 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
2973 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002974 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002975 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2976 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2977 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2978 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979
2980 if (pos_map)
2981 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2982 }
2983 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2984
2985 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002986 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002988 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2989 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 }
2991
2992 return rval;
2993}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002994
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002995/*
2996 * qla2x00_get_link_status
2997 *
2998 * Input:
2999 * ha = adapter block pointer.
3000 * loop_id = device loop ID.
3001 * ret_buf = pointer to link status return buffer.
3002 *
3003 * Returns:
3004 * 0 = success.
3005 * BIT_0 = mem alloc error.
3006 * BIT_1 = mailbox error.
3007 */
3008int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003009qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003010 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003011{
3012 int rval;
3013 mbx_cmd_t mc;
3014 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003015 uint32_t *iter = (void *)stats;
3016 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003017 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003018
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003019 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
3020 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003021
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003022 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003023 mcp->mb[2] = MSW(LSD(stats_dma));
3024 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003025 mcp->mb[6] = MSW(MSD(stats_dma));
3026 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003027 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3028 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07003029 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003030 mcp->mb[1] = loop_id;
3031 mcp->mb[4] = 0;
3032 mcp->mb[10] = 0;
3033 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
3034 mcp->in_mb |= MBX_1;
3035 } else if (HAS_EXTENDED_IDS(ha)) {
3036 mcp->mb[1] = loop_id;
3037 mcp->mb[10] = 0;
3038 mcp->out_mb |= MBX_10|MBX_1;
3039 } else {
3040 mcp->mb[1] = loop_id << 8;
3041 mcp->out_mb |= MBX_1;
3042 }
Ravi Anandb93480e2008-04-03 13:13:25 -07003043 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003044 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003045 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003046
3047 if (rval == QLA_SUCCESS) {
3048 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003049 ql_dbg(ql_dbg_mbx, vha, 0x1085,
3050 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003051 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003052 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003053 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003054 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
3055 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003056 for ( ; dwords--; iter++)
3057 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003058 }
3059 } else {
3060 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003061 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003062 }
3063
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003064 return rval;
3065}
3066
3067int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003068qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07003069 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003070{
3071 int rval;
3072 mbx_cmd_t mc;
3073 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003074 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003075
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003076 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
3077 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003078
Quinn Tran15f30a52017-03-15 09:48:52 -07003079 memset(&mc, 0, sizeof(mc));
3080 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
3081 mc.mb[2] = MSW(stats_dma);
3082 mc.mb[3] = LSW(stats_dma);
3083 mc.mb[6] = MSW(MSD(stats_dma));
3084 mc.mb[7] = LSW(MSD(stats_dma));
3085 mc.mb[8] = sizeof(struct link_statistics) / 4;
3086 mc.mb[9] = cpu_to_le16(vha->vp_idx);
3087 mc.mb[10] = cpu_to_le16(options);
3088
3089 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003090
3091 if (rval == QLA_SUCCESS) {
3092 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003093 ql_dbg(ql_dbg_mbx, vha, 0x1089,
3094 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003095 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003096 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
3098 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003099 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003100 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003101 iter = &stats->link_fail_cnt;
3102 for ( ; dwords--; iter++)
3103 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003104 }
3105 } else {
3106 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003107 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003108 }
3109
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003110 return rval;
3111}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003112
3113int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003114qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003115{
3116 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003117 unsigned long flags = 0;
3118
3119 struct abort_entry_24xx *abt;
3120 dma_addr_t abt_dma;
3121 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003122 fc_port_t *fcport = sp->fcport;
3123 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003124 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003125 struct req_que *req = vha->req;
Quinn Tran585def92018-09-04 14:19:20 -07003126 struct qla_qpair *qpair = sp->qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003127
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003128 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
3129 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003130
Michael Hernandezd7459522016-12-12 14:40:07 -08003131 if (vha->flags.qpairs_available && sp->qpair)
3132 req = sp->qpair->req;
Quinn Tran585def92018-09-04 14:19:20 -07003133 else
3134 return QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08003135
Armen Baloyan4440e462014-02-26 04:15:18 -05003136 if (ql2xasynctmfenable)
3137 return qla24xx_async_abort_command(sp);
3138
Quinn Tran585def92018-09-04 14:19:20 -07003139 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003140 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003141 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003142 break;
3143 }
Quinn Tran585def92018-09-04 14:19:20 -07003144 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003145 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003146 /* Command not found. */
3147 return QLA_FUNCTION_FAILED;
3148 }
3149
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003150 abt = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003151 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003152 ql_log(ql_log_warn, vha, 0x108d,
3153 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003154 return QLA_MEMORY_ALLOC_FAILED;
3155 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003156
3157 abt->entry_type = ABORT_IOCB_TYPE;
3158 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003159 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003160 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07003161 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003162 abt->port_id[0] = fcport->d_id.b.al_pa;
3163 abt->port_id[1] = fcport->d_id.b.area;
3164 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003165 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003166
3167 abt->req_que_no = cpu_to_le16(req->id);
3168
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003169 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003170 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003171 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3172 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003173 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003174 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3175 "Failed to complete IOCB -- error status (%x).\n",
3176 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003177 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003178 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003179 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3180 "Failed to complete IOCB -- completion status (%x).\n",
3181 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003182 if (abt->nport_handle == CS_IOCB_ERROR)
3183 rval = QLA_FUNCTION_PARAMETER_ERROR;
3184 else
3185 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003186 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003187 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3188 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003189 }
3190
3191 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3192
3193 return rval;
3194}
3195
3196struct tsk_mgmt_cmd {
3197 union {
3198 struct tsk_mgmt_entry tsk;
3199 struct sts_entry_24xx sts;
3200 } p;
3201};
3202
Andrew Vasquez523ec772008-04-03 13:13:24 -07003203static int
3204__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003205 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003206{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003207 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003208 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003209 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003210 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003211 scsi_qla_host_t *vha;
3212 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003213 struct req_que *req;
Michael Hernandezd7459522016-12-12 14:40:07 -08003214 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003215
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003216 vha = fcport->vha;
3217 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003218 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003219
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003220 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3221 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003222
Michael Hernandezd7459522016-12-12 14:40:07 -08003223 if (vha->vp_idx && vha->qpair) {
3224 /* NPIV port */
3225 qpair = vha->qpair;
Michael Hernandezd7459522016-12-12 14:40:07 -08003226 req = qpair->req;
Michael Hernandezd7459522016-12-12 14:40:07 -08003227 }
3228
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003229 tsk = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003230 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003231 ql_log(ql_log_warn, vha, 0x1093,
3232 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003233 return QLA_MEMORY_ALLOC_FAILED;
3234 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003235
3236 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3237 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003238 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003239 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003240 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003241 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003242 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3243 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3244 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003245 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003246 if (type == TCF_LUN_RESET) {
3247 int_to_scsilun(l, &tsk->p.tsk.lun);
3248 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3249 sizeof(tsk->p.tsk.lun));
3250 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003251
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003252 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003253 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003254 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003255 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3256 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003257 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003258 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3259 "Failed to complete IOCB -- error status (%x).\n",
3260 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003261 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003262 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003263 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3264 "Failed to complete IOCB -- completion status (%x).\n",
3265 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003266 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003267 } else if (le16_to_cpu(sts->scsi_status) &
3268 SS_RESPONSE_INFO_LEN_VALID) {
3269 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003270 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003271 "Ignoring inconsistent data length -- not enough "
3272 "response info (%d).\n",
3273 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003274 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003275 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3276 "Failed to complete IOCB -- response (%x).\n",
3277 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003278 rval = QLA_FUNCTION_FAILED;
3279 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003280 }
3281
3282 /* Issue marker IOCB. */
Quinn Tran9eb9c6d2019-02-15 14:37:19 -08003283 rval2 = qla2x00_marker(vha, ha->base_qpair, fcport->loop_id, l,
Bart Van Assche58e27532019-04-11 14:53:19 -07003284 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003285 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003286 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3287 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003288 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003289 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3290 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003291 }
3292
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003293 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003294
3295 return rval;
3296}
3297
Andrew Vasquez523ec772008-04-03 13:13:24 -07003298int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003299qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003300{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003301 struct qla_hw_data *ha = fcport->vha->hw;
3302
3303 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3304 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3305
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003306 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003307}
3308
3309int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003310qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003311{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003312 struct qla_hw_data *ha = fcport->vha->hw;
3313
3314 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3315 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3316
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003317 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003318}
3319
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003320int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003321qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003322{
3323 int rval;
3324 mbx_cmd_t mc;
3325 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003326 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003327
Andrew Vasquez68af0812008-05-12 22:21:13 -07003328 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003329 return QLA_FUNCTION_FAILED;
3330
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003331 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3332 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003333
3334 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3335 mcp->out_mb = MBX_0;
3336 mcp->in_mb = MBX_0;
3337 mcp->tov = 5;
3338 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003339 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003340
3341 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003342 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003343 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003344 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3345 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003346 }
3347
3348 return rval;
3349}
3350
Joe Carnucciodb64e932013-10-30 03:38:18 -04003351int
3352qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3353{
3354 int rval;
3355 mbx_cmd_t mc;
3356 mbx_cmd_t *mcp = &mc;
3357
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003358 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003359 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003360 return QLA_FUNCTION_FAILED;
3361
3362 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3363 "Entered %s.\n", __func__);
3364
3365 mcp->mb[0] = MBC_WRITE_SERDES;
3366 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003367 if (IS_QLA2031(vha->hw))
3368 mcp->mb[2] = data & 0xff;
3369 else
3370 mcp->mb[2] = data;
3371
Joe Carnucciodb64e932013-10-30 03:38:18 -04003372 mcp->mb[3] = 0;
3373 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3374 mcp->in_mb = MBX_0;
3375 mcp->tov = MBX_TOV_SECONDS;
3376 mcp->flags = 0;
3377 rval = qla2x00_mailbox_command(vha, mcp);
3378
3379 if (rval != QLA_SUCCESS) {
3380 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3381 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3382 } else {
3383 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3384 "Done %s.\n", __func__);
3385 }
3386
3387 return rval;
3388}
3389
3390int
3391qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3392{
3393 int rval;
3394 mbx_cmd_t mc;
3395 mbx_cmd_t *mcp = &mc;
3396
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003397 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003398 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003399 return QLA_FUNCTION_FAILED;
3400
3401 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3402 "Entered %s.\n", __func__);
3403
3404 mcp->mb[0] = MBC_READ_SERDES;
3405 mcp->mb[1] = addr;
3406 mcp->mb[3] = 0;
3407 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3408 mcp->in_mb = MBX_1|MBX_0;
3409 mcp->tov = MBX_TOV_SECONDS;
3410 mcp->flags = 0;
3411 rval = qla2x00_mailbox_command(vha, mcp);
3412
Andrew Vasquez064135e2015-04-09 15:00:02 -04003413 if (IS_QLA2031(vha->hw))
3414 *data = mcp->mb[1] & 0xff;
3415 else
3416 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003417
3418 if (rval != QLA_SUCCESS) {
3419 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3420 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3421 } else {
3422 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3423 "Done %s.\n", __func__);
3424 }
3425
3426 return rval;
3427}
3428
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003429int
3430qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3431{
3432 int rval;
3433 mbx_cmd_t mc;
3434 mbx_cmd_t *mcp = &mc;
3435
3436 if (!IS_QLA8044(vha->hw))
3437 return QLA_FUNCTION_FAILED;
3438
Quinn Tran83548fe2017-06-02 09:12:01 -07003439 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003440 "Entered %s.\n", __func__);
3441
3442 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3443 mcp->mb[1] = HCS_WRITE_SERDES;
3444 mcp->mb[3] = LSW(addr);
3445 mcp->mb[4] = MSW(addr);
3446 mcp->mb[5] = LSW(data);
3447 mcp->mb[6] = MSW(data);
3448 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3449 mcp->in_mb = MBX_0;
3450 mcp->tov = MBX_TOV_SECONDS;
3451 mcp->flags = 0;
3452 rval = qla2x00_mailbox_command(vha, mcp);
3453
3454 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003455 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003456 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3457 } else {
3458 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3459 "Done %s.\n", __func__);
3460 }
3461
3462 return rval;
3463}
3464
3465int
3466qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3467{
3468 int rval;
3469 mbx_cmd_t mc;
3470 mbx_cmd_t *mcp = &mc;
3471
3472 if (!IS_QLA8044(vha->hw))
3473 return QLA_FUNCTION_FAILED;
3474
3475 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3476 "Entered %s.\n", __func__);
3477
3478 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3479 mcp->mb[1] = HCS_READ_SERDES;
3480 mcp->mb[3] = LSW(addr);
3481 mcp->mb[4] = MSW(addr);
3482 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3483 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3484 mcp->tov = MBX_TOV_SECONDS;
3485 mcp->flags = 0;
3486 rval = qla2x00_mailbox_command(vha, mcp);
3487
3488 *data = mcp->mb[2] << 16 | mcp->mb[1];
3489
3490 if (rval != QLA_SUCCESS) {
3491 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3492 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3493 } else {
3494 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3495 "Done %s.\n", __func__);
3496 }
3497
3498 return rval;
3499}
3500
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003501/**
3502 * qla2x00_set_serdes_params() -
Bart Van Assche2db62282018-01-23 16:33:51 -08003503 * @vha: HA context
Bart Van Assche807eb902018-10-18 15:45:41 -07003504 * @sw_em_1g: serial link options
3505 * @sw_em_2g: serial link options
3506 * @sw_em_4g: serial link options
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003507 *
3508 * Returns
3509 */
3510int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003511qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003512 uint16_t sw_em_2g, uint16_t sw_em_4g)
3513{
3514 int rval;
3515 mbx_cmd_t mc;
3516 mbx_cmd_t *mcp = &mc;
3517
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003518 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3519 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003520
3521 mcp->mb[0] = MBC_SERDES_PARAMS;
3522 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003523 mcp->mb[2] = sw_em_1g | BIT_15;
3524 mcp->mb[3] = sw_em_2g | BIT_15;
3525 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003526 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3527 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003528 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003529 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003530 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003531
3532 if (rval != QLA_SUCCESS) {
3533 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003534 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3535 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003536 } else {
3537 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003538 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3539 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003540 }
3541
3542 return rval;
3543}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003544
3545int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003546qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003547{
3548 int rval;
3549 mbx_cmd_t mc;
3550 mbx_cmd_t *mcp = &mc;
3551
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003552 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003553 return QLA_FUNCTION_FAILED;
3554
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003555 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3556 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003557
3558 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003559 mcp->mb[1] = 0;
3560 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003561 mcp->in_mb = MBX_0;
3562 mcp->tov = 5;
3563 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003564 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003565
3566 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003567 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003568 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3569 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003570 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003571 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3572 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003573 }
3574
3575 return rval;
3576}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003577
3578int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003579qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003580 uint16_t buffers)
3581{
3582 int rval;
3583 mbx_cmd_t mc;
3584 mbx_cmd_t *mcp = &mc;
3585
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003586 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3587 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003588
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003589 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003590 return QLA_FUNCTION_FAILED;
3591
Andrew Vasquez85880802009-12-15 21:29:46 -08003592 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3593 return QLA_FUNCTION_FAILED;
3594
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003595 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003596 mcp->mb[1] = TC_EFT_ENABLE;
3597 mcp->mb[2] = LSW(eft_dma);
3598 mcp->mb[3] = MSW(eft_dma);
3599 mcp->mb[4] = LSW(MSD(eft_dma));
3600 mcp->mb[5] = MSW(MSD(eft_dma));
3601 mcp->mb[6] = buffers;
3602 mcp->mb[7] = TC_AEN_DISABLE;
3603 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 -07003604 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003605 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003606 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003607 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003608 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003609 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3610 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3611 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003612 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003613 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3614 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003615 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003616
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003617 return rval;
3618}
3619
3620int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003621qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003622{
3623 int rval;
3624 mbx_cmd_t mc;
3625 mbx_cmd_t *mcp = &mc;
3626
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3628 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003629
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003630 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003631 return QLA_FUNCTION_FAILED;
3632
Andrew Vasquez85880802009-12-15 21:29:46 -08003633 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3634 return QLA_FUNCTION_FAILED;
3635
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003636 mcp->mb[0] = MBC_TRACE_CONTROL;
3637 mcp->mb[1] = TC_EFT_DISABLE;
3638 mcp->out_mb = MBX_1|MBX_0;
3639 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003640 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003641 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003642 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003643 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003644 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3645 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3646 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003647 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003648 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3649 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003650 }
3651
3652 return rval;
3653}
3654
Andrew Vasquez88729e52006-06-23 16:10:50 -07003655int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003656qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003657 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3658{
3659 int rval;
3660 mbx_cmd_t mc;
3661 mbx_cmd_t *mcp = &mc;
3662
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003663 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3664 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003665
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003666 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07003667 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
3668 !IS_QLA28XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003669 return QLA_FUNCTION_FAILED;
3670
Andrew Vasquez85880802009-12-15 21:29:46 -08003671 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3672 return QLA_FUNCTION_FAILED;
3673
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003674 mcp->mb[0] = MBC_TRACE_CONTROL;
3675 mcp->mb[1] = TC_FCE_ENABLE;
3676 mcp->mb[2] = LSW(fce_dma);
3677 mcp->mb[3] = MSW(fce_dma);
3678 mcp->mb[4] = LSW(MSD(fce_dma));
3679 mcp->mb[5] = MSW(MSD(fce_dma));
3680 mcp->mb[6] = buffers;
3681 mcp->mb[7] = TC_AEN_DISABLE;
3682 mcp->mb[8] = 0;
3683 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3684 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3685 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3686 MBX_1|MBX_0;
3687 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003688 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003689 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003690 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003691 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003692 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3693 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3694 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003695 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003696 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3697 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003698
3699 if (mb)
3700 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3701 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003702 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003703 }
3704
3705 return rval;
3706}
3707
3708int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003709qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003710{
3711 int rval;
3712 mbx_cmd_t mc;
3713 mbx_cmd_t *mcp = &mc;
3714
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003715 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3716 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003717
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003718 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003719 return QLA_FUNCTION_FAILED;
3720
Andrew Vasquez85880802009-12-15 21:29:46 -08003721 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3722 return QLA_FUNCTION_FAILED;
3723
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003724 mcp->mb[0] = MBC_TRACE_CONTROL;
3725 mcp->mb[1] = TC_FCE_DISABLE;
3726 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3727 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3728 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3729 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003730 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003731 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003732 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003733 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003734 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3735 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3736 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003737 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003738 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3739 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003740
3741 if (wr)
3742 *wr = (uint64_t) mcp->mb[5] << 48 |
3743 (uint64_t) mcp->mb[4] << 32 |
3744 (uint64_t) mcp->mb[3] << 16 |
3745 (uint64_t) mcp->mb[2];
3746 if (rd)
3747 *rd = (uint64_t) mcp->mb[9] << 48 |
3748 (uint64_t) mcp->mb[8] << 32 |
3749 (uint64_t) mcp->mb[7] << 16 |
3750 (uint64_t) mcp->mb[6];
3751 }
3752
3753 return rval;
3754}
3755
3756int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003757qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3758 uint16_t *port_speed, uint16_t *mb)
3759{
3760 int rval;
3761 mbx_cmd_t mc;
3762 mbx_cmd_t *mcp = &mc;
3763
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003764 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3765 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003766
Giridhar Malavali6e980162010-03-19 17:03:58 -07003767 if (!IS_IIDMA_CAPABLE(vha->hw))
3768 return QLA_FUNCTION_FAILED;
3769
Giridhar Malavali6e980162010-03-19 17:03:58 -07003770 mcp->mb[0] = MBC_PORT_PARAMS;
3771 mcp->mb[1] = loop_id;
3772 mcp->mb[2] = mcp->mb[3] = 0;
3773 mcp->mb[9] = vha->vp_idx;
3774 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3775 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3776 mcp->tov = MBX_TOV_SECONDS;
3777 mcp->flags = 0;
3778 rval = qla2x00_mailbox_command(vha, mcp);
3779
3780 /* Return mailbox statuses. */
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003781 if (mb) {
Giridhar Malavali6e980162010-03-19 17:03:58 -07003782 mb[0] = mcp->mb[0];
3783 mb[1] = mcp->mb[1];
3784 mb[3] = mcp->mb[3];
3785 }
3786
3787 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003788 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003789 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003790 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3791 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003792 if (port_speed)
3793 *port_speed = mcp->mb[3];
3794 }
3795
3796 return rval;
3797}
3798
3799int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003800qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003801 uint16_t port_speed, uint16_t *mb)
3802{
3803 int rval;
3804 mbx_cmd_t mc;
3805 mbx_cmd_t *mcp = &mc;
3806
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003807 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3808 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003809
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003810 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003811 return QLA_FUNCTION_FAILED;
3812
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003813 mcp->mb[0] = MBC_PORT_PARAMS;
3814 mcp->mb[1] = loop_id;
3815 mcp->mb[2] = BIT_0;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003816 mcp->mb[3] = port_speed & 0x3F;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003817 mcp->mb[9] = vha->vp_idx;
3818 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3819 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003820 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003821 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003822 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003823
3824 /* Return mailbox statuses. */
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07003825 if (mb) {
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003826 mb[0] = mcp->mb[0];
3827 mb[1] = mcp->mb[1];
3828 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003829 }
3830
3831 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003832 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3833 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003834 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003835 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3836 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003837 }
3838
3839 return rval;
3840}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003841
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003842void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003843qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003844 struct vp_rpt_id_entry_24xx *rptid_entry)
3845{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003846 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003847 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003848 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003849 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003850 port_id_t id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08003851 struct fc_port *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003852
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003853 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3854 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003855
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003856 if (rptid_entry->entry_status != 0)
3857 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003858
Quinn Tran482c9dc2017-03-15 09:48:54 -07003859 id.b.domain = rptid_entry->port_id[2];
3860 id.b.area = rptid_entry->port_id[1];
3861 id.b.al_pa = rptid_entry->port_id[0];
3862 id.b.rsvd_1 = 0;
Darren Trapp1763c1f2018-03-20 23:09:34 -07003863 ha->flags.n2n_ae = 0;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003864
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003865 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003866 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003867 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003868 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003869 "VPs acquired %d.\n", rptid_entry->vp_setup,
3870 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003871 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003872 "Primary port id %02x%02x%02x.\n",
3873 rptid_entry->port_id[2], rptid_entry->port_id[1],
3874 rptid_entry->port_id[0]);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003875 ha->current_topology = ISP_CFG_NL;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003876 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003877
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003878 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003879 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003880 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003881 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003882 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3883 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003884 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003885 rptid_entry->port_id[0]);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003886 ql_dbg(ql_dbg_async, vha, 0x5075,
3887 "Format 1: Remote WWPN %8phC.\n",
3888 rptid_entry->u.f1.port_name);
3889
3890 ql_dbg(ql_dbg_async, vha, 0x5075,
3891 "Format 1: WWPN %8phC.\n",
3892 vha->port_name);
3893
Quinn Tran8777e432018-08-02 13:16:57 -07003894 switch (rptid_entry->u.f1.flags & TOPO_MASK) {
3895 case TOPO_N2N:
3896 ha->current_topology = ISP_CFG_N;
3897 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3898 fcport = qla2x00_find_fcport_by_wwpn(vha,
3899 rptid_entry->u.f1.port_name, 1);
3900 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3901
3902 if (fcport) {
3903 fcport->plogi_nack_done_deadline = jiffies + HZ;
3904 fcport->dm_login_expire = jiffies + 3*HZ;
3905 fcport->scan_state = QLA_FCPORT_FOUND;
3906 switch (fcport->disc_state) {
3907 case DSC_DELETED:
3908 set_bit(RELOGIN_NEEDED,
3909 &vha->dpc_flags);
3910 break;
3911 case DSC_DELETE_PEND:
3912 break;
3913 default:
3914 qlt_schedule_sess_for_deletion(fcport);
3915 break;
3916 }
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003917 } else {
Quinn Tran8777e432018-08-02 13:16:57 -07003918 id.b24 = 0;
3919 if (wwn_to_u64(vha->port_name) >
3920 wwn_to_u64(rptid_entry->u.f1.port_name)) {
3921 vha->d_id.b24 = 0;
3922 vha->d_id.b.al_pa = 1;
3923 ha->flags.n2n_bigger = 1;
3924
3925 id.b.al_pa = 2;
3926 ql_dbg(ql_dbg_async, vha, 0x5075,
3927 "Format 1: assign local id %x remote id %x\n",
3928 vha->d_id.b24, id.b24);
3929 } else {
3930 ql_dbg(ql_dbg_async, vha, 0x5075,
3931 "Format 1: Remote login - Waiting for WWPN %8phC.\n",
3932 rptid_entry->u.f1.port_name);
3933 ha->flags.n2n_bigger = 0;
3934 }
3935 qla24xx_post_newsess_work(vha, &id,
3936 rptid_entry->u.f1.port_name,
3937 rptid_entry->u.f1.node_name,
3938 NULL,
3939 FC4_TYPE_UNKNOWN);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003940 }
3941
Quinn Tran8777e432018-08-02 13:16:57 -07003942 /* if our portname is higher then initiate N2N login */
3943
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003944 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
Darren Trapp1763c1f2018-03-20 23:09:34 -07003945 ha->flags.n2n_ae = 1;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003946 return;
Quinn Tran8777e432018-08-02 13:16:57 -07003947 break;
3948 case TOPO_FL:
3949 ha->current_topology = ISP_CFG_FL;
3950 break;
3951 case TOPO_F:
3952 ha->current_topology = ISP_CFG_F;
3953 break;
3954 default:
3955 break;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003956 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003957
Quinn Tran9cd883f2017-12-28 12:33:24 -08003958 ha->flags.gpsc_supported = 1;
3959 ha->current_topology = ISP_CFG_F;
Sawan Chandak969a6192016-01-27 12:03:32 -05003960 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003961 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003962
Quinn Tran41dc5292017-01-19 22:28:03 -08003963 if (rptid_entry->vp_idx == 0) {
3964 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3965 /* FA-WWN is only for physical port */
3966 if (qla_ini_mode_enabled(vha) &&
3967 ha->flags.fawwpn_enabled &&
3968 (rptid_entry->u.f1.flags &
Sawan Chandakfcc5b5c2017-08-23 15:05:02 -07003969 BIT_6)) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003970 memcpy(vha->port_name,
3971 rptid_entry->u.f1.port_name,
3972 WWN_SIZE);
3973 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003974
Quinn Tran482c9dc2017-03-15 09:48:54 -07003975 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003976 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003977
Quinn Tran41dc5292017-01-19 22:28:03 -08003978 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3979 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3980 } else {
3981 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3982 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3983 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3984 "Could not acquire ID for VP[%d].\n",
3985 rptid_entry->vp_idx);
3986 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003987 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003988
3989 found = 0;
3990 spin_lock_irqsave(&ha->vport_slock, flags);
3991 list_for_each_entry(vp, &ha->vp_list, list) {
3992 if (rptid_entry->vp_idx == vp->vp_idx) {
3993 found = 1;
3994 break;
3995 }
3996 }
3997 spin_unlock_irqrestore(&ha->vport_slock, flags);
3998
3999 if (!found)
4000 return;
4001
Quinn Tran482c9dc2017-03-15 09:48:54 -07004002 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08004003
4004 /*
4005 * Cannot configure here as we are still sitting on the
4006 * response queue. Handle it in dpc context.
4007 */
4008 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
4009 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
4010 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05004011 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07004012 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004013 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08004014 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07004015 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08004016 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
4017 rptid_entry->port_id[2], rptid_entry->port_id[1],
4018 rptid_entry->port_id[0]);
4019
Quinn Tran83548fe2017-06-02 09:12:01 -07004020 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08004021 "N2N: Remote WWPN %8phC.\n",
4022 rptid_entry->u.f2.port_name);
4023
4024 /* N2N. direct connect */
Quinn Tran9cd883f2017-12-28 12:33:24 -08004025 ha->current_topology = ISP_CFG_N;
4026 ha->flags.rida_fmt2 = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004027 vha->d_id.b.domain = rptid_entry->port_id[2];
4028 vha->d_id.b.area = rptid_entry->port_id[1];
4029 vha->d_id.b.al_pa = rptid_entry->port_id[0];
4030
Darren Trapp1763c1f2018-03-20 23:09:34 -07004031 ha->flags.n2n_ae = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004032 spin_lock_irqsave(&ha->vport_slock, flags);
4033 qlt_update_vp_map(vha, SET_AL_PA);
4034 spin_unlock_irqrestore(&ha->vport_slock, flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004035
4036 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4037 fcport->scan_state = QLA_FCPORT_SCAN;
4038 }
4039
4040 fcport = qla2x00_find_fcport_by_wwpn(vha,
4041 rptid_entry->u.f2.port_name, 1);
4042
4043 if (fcport) {
Quinn Tran23dd98a2018-08-02 13:16:45 -07004044 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004045 fcport->plogi_nack_done_deadline = jiffies + HZ;
4046 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004047 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004048 }
4049}
4050
4051/*
4052 * qla24xx_modify_vp_config
4053 * Change VP configuration for vha
4054 *
4055 * Input:
4056 * vha = adapter block pointer.
4057 *
4058 * Returns:
4059 * qla2xxx local function return status code.
4060 *
4061 * Context:
4062 * Kernel context.
4063 */
4064int
4065qla24xx_modify_vp_config(scsi_qla_host_t *vha)
4066{
4067 int rval;
4068 struct vp_config_entry_24xx *vpmod;
4069 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004070 struct qla_hw_data *ha = vha->hw;
4071 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004072
4073 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004074
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004075 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
4076 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004077
Thomas Meyer08eb7f42017-09-21 08:15:26 +02004078 vpmod = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004079 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004080 ql_log(ql_log_warn, vha, 0x10bc,
4081 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004082 return QLA_MEMORY_ALLOC_FAILED;
4083 }
4084
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004085 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
4086 vpmod->entry_count = 1;
4087 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
4088 vpmod->vp_count = 1;
4089 vpmod->vp_index1 = vha->vp_idx;
4090 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004091
4092 qlt_modify_vp_config(vha, vpmod);
4093
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004094 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
4095 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
4096 vpmod->entry_count = 1;
4097
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004098 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004099 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004100 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
4101 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004102 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004103 ql_dbg(ql_dbg_mbx, vha, 0x10be,
4104 "Failed to complete IOCB -- error status (%x).\n",
4105 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004106 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07004107 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004108 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
4109 "Failed to complete IOCB -- completion status (%x).\n",
4110 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004111 rval = QLA_FUNCTION_FAILED;
4112 } else {
4113 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004114 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
4115 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004116 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
4117 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004118 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004119
4120 return rval;
4121}
4122
4123/*
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004124 * qla2x00_send_change_request
4125 * Receive or disable RSCN request from fabric controller
4126 *
4127 * Input:
4128 * ha = adapter block pointer
4129 * format = registration format:
4130 * 0 - Reserved
4131 * 1 - Fabric detected registration
4132 * 2 - N_port detected registration
4133 * 3 - Full registration
4134 * FF - clear registration
4135 * vp_idx = Virtual port index
4136 *
4137 * Returns:
4138 * qla2x00 local function return status code.
4139 *
4140 * Context:
4141 * Kernel Context
4142 */
4143
4144int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004145qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004146 uint16_t vp_idx)
4147{
4148 int rval;
4149 mbx_cmd_t mc;
4150 mbx_cmd_t *mcp = &mc;
4151
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004152 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
4153 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004154
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004155 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
4156 mcp->mb[1] = format;
4157 mcp->mb[9] = vp_idx;
4158 mcp->out_mb = MBX_9|MBX_1|MBX_0;
4159 mcp->in_mb = MBX_0|MBX_1;
4160 mcp->tov = MBX_TOV_SECONDS;
4161 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004162 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004163
4164 if (rval == QLA_SUCCESS) {
4165 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
4166 rval = BIT_1;
4167 }
4168 } else
4169 rval = BIT_1;
4170
4171 return rval;
4172}
Andrew Vasquez338c9162007-09-20 14:07:33 -07004173
4174int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004175qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07004176 uint32_t size)
4177{
4178 int rval;
4179 mbx_cmd_t mc;
4180 mbx_cmd_t *mcp = &mc;
4181
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004182 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
4183 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004184
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004185 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004186 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
4187 mcp->mb[8] = MSW(addr);
4188 mcp->out_mb = MBX_8|MBX_0;
4189 } else {
4190 mcp->mb[0] = MBC_DUMP_RISC_RAM;
4191 mcp->out_mb = MBX_0;
4192 }
4193 mcp->mb[1] = LSW(addr);
4194 mcp->mb[2] = MSW(req_dma);
4195 mcp->mb[3] = LSW(req_dma);
4196 mcp->mb[6] = MSW(MSD(req_dma));
4197 mcp->mb[7] = LSW(MSD(req_dma));
4198 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004199 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004200 mcp->mb[4] = MSW(size);
4201 mcp->mb[5] = LSW(size);
4202 mcp->out_mb |= MBX_5|MBX_4;
4203 } else {
4204 mcp->mb[4] = LSW(size);
4205 mcp->out_mb |= MBX_4;
4206 }
4207
4208 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004209 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004210 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004211 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004212
4213 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004214 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4215 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004216 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004217 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4218 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004219 }
4220
4221 return rval;
4222}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004223/* 84XX Support **************************************************************/
4224
4225struct cs84xx_mgmt_cmd {
4226 union {
4227 struct verify_chip_entry_84xx req;
4228 struct verify_chip_rsp_84xx rsp;
4229 } p;
4230};
4231
4232int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004233qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004234{
4235 int rval, retry;
4236 struct cs84xx_mgmt_cmd *mn;
4237 dma_addr_t mn_dma;
4238 uint16_t options;
4239 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004240 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004241
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4243 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004244
4245 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4246 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004247 return QLA_MEMORY_ALLOC_FAILED;
4248 }
4249
4250 /* Force Update? */
4251 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4252 /* Diagnostic firmware? */
4253 /* options |= MENLO_DIAG_FW; */
4254 /* We update the firmware with only one data sequence. */
4255 options |= VCO_END_OF_DATA;
4256
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004257 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004258 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004259 memset(mn, 0, sizeof(*mn));
4260 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4261 mn->p.req.entry_count = 1;
4262 mn->p.req.options = cpu_to_le16(options);
4263
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004264 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4265 "Dump of Verify Request.\n");
4266 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07004267 mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004268
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004269 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004270 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004271 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4272 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004273 goto verify_done;
4274 }
4275
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004276 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4277 "Dump of Verify Response.\n");
4278 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
Joe Carnucciof8f97b02019-03-12 11:08:16 -07004279 mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004280
4281 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4282 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4283 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004284 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004285 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004286
4287 if (status[0] != CS_COMPLETE) {
4288 rval = QLA_FUNCTION_FAILED;
4289 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004290 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4291 "Firmware update failed. Retrying "
4292 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004293 options |= VCO_DONT_UPDATE_FW;
4294 options &= ~VCO_FORCE_UPDATE;
4295 retry = 1;
4296 }
4297 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004298 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004299 "Firmware updated to %x.\n",
4300 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004301
4302 /* NOTE: we only update OP firmware. */
4303 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4304 ha->cs84xx->op_fw_version =
4305 le32_to_cpu(mn->p.rsp.fw_ver);
4306 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4307 flags);
4308 }
4309 } while (retry);
4310
4311verify_done:
4312 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4313
4314 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004315 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4316 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004317 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004318 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4319 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004320 }
4321
4322 return rval;
4323}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004324
4325int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004326qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004327{
4328 int rval;
4329 unsigned long flags;
4330 mbx_cmd_t mc;
4331 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004332 struct qla_hw_data *ha = vha->hw;
4333
Quinn Tran45235022018-07-18 14:29:53 -07004334 if (!ha->flags.fw_started)
4335 return QLA_SUCCESS;
4336
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004337 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4338 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004339
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004340 if (IS_SHADOW_REG_CAPABLE(ha))
4341 req->options |= BIT_13;
4342
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004343 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004344 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004345 mcp->mb[2] = MSW(LSD(req->dma));
4346 mcp->mb[3] = LSW(LSD(req->dma));
4347 mcp->mb[6] = MSW(MSD(req->dma));
4348 mcp->mb[7] = LSW(MSD(req->dma));
4349 mcp->mb[5] = req->length;
4350 if (req->rsp)
4351 mcp->mb[10] = req->rsp->id;
4352 mcp->mb[12] = req->qos;
4353 mcp->mb[11] = req->vp_idx;
4354 mcp->mb[13] = req->rid;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004355 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004356 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004357
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004358 mcp->mb[4] = req->id;
4359 /* que in ptr index */
4360 mcp->mb[8] = 0;
4361 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004362 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004363 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4364 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4365 mcp->in_mb = MBX_0;
4366 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004367 mcp->tov = MBX_TOV_SECONDS * 2;
4368
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004369 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4370 IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004371 mcp->in_mb |= MBX_1;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004372 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004373 mcp->out_mb |= MBX_15;
4374 /* debug q create issue in SR-IOV */
4375 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4376 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004377
4378 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004379 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004380 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004381 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004382 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004383 }
4384 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4385
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004386 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004387 if (rval != QLA_SUCCESS) {
4388 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4389 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4390 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4392 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004393 }
4394
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004395 return rval;
4396}
4397
4398int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004399qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004400{
4401 int rval;
4402 unsigned long flags;
4403 mbx_cmd_t mc;
4404 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004405 struct qla_hw_data *ha = vha->hw;
4406
Quinn Tran45235022018-07-18 14:29:53 -07004407 if (!ha->flags.fw_started)
4408 return QLA_SUCCESS;
4409
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004410 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4411 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004412
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004413 if (IS_SHADOW_REG_CAPABLE(ha))
4414 rsp->options |= BIT_13;
4415
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004416 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004417 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004418 mcp->mb[2] = MSW(LSD(rsp->dma));
4419 mcp->mb[3] = LSW(LSD(rsp->dma));
4420 mcp->mb[6] = MSW(MSD(rsp->dma));
4421 mcp->mb[7] = LSW(MSD(rsp->dma));
4422 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004423 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004424 mcp->mb[13] = rsp->rid;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004425 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004426 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004427
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004428 mcp->mb[4] = rsp->id;
4429 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004430 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004431 /* que out ptr index */
4432 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004433 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004434 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4435 mcp->in_mb = MBX_0;
4436 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004437 mcp->tov = MBX_TOV_SECONDS * 2;
4438
4439 if (IS_QLA81XX(ha)) {
4440 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4441 mcp->in_mb |= MBX_1;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004442 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004443 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4444 mcp->in_mb |= MBX_1;
4445 /* debug q create issue in SR-IOV */
4446 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4447 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004448
4449 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004450 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004451 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004452 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004453 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004454 }
4455
4456 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4457
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004458 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004459 if (rval != QLA_SUCCESS) {
4460 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4461 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4462 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004463 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4464 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004465 }
4466
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004467 return rval;
4468}
4469
Andrew Vasquez8a659572009-02-08 20:50:12 -08004470int
4471qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4472{
4473 int rval;
4474 mbx_cmd_t mc;
4475 mbx_cmd_t *mcp = &mc;
4476
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004477 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4478 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004479
4480 mcp->mb[0] = MBC_IDC_ACK;
4481 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4482 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4483 mcp->in_mb = MBX_0;
4484 mcp->tov = MBX_TOV_SECONDS;
4485 mcp->flags = 0;
4486 rval = qla2x00_mailbox_command(vha, mcp);
4487
4488 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004489 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4490 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004491 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004492 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4493 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004494 }
4495
4496 return rval;
4497}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004498
4499int
4500qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4501{
4502 int rval;
4503 mbx_cmd_t mc;
4504 mbx_cmd_t *mcp = &mc;
4505
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004506 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4507 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004508
Chad Dupuisf73cb692014-02-26 04:15:06 -05004509 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004510 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004511 return QLA_FUNCTION_FAILED;
4512
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004513 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4514 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4515 mcp->out_mb = MBX_1|MBX_0;
4516 mcp->in_mb = MBX_1|MBX_0;
4517 mcp->tov = MBX_TOV_SECONDS;
4518 mcp->flags = 0;
4519 rval = qla2x00_mailbox_command(vha, mcp);
4520
4521 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004522 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4523 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4524 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004525 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004526 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4527 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004528 *sector_size = mcp->mb[1];
4529 }
4530
4531 return rval;
4532}
4533
4534int
4535qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4536{
4537 int rval;
4538 mbx_cmd_t mc;
4539 mbx_cmd_t *mcp = &mc;
4540
Chad Dupuisf73cb692014-02-26 04:15:06 -05004541 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004542 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004543 return QLA_FUNCTION_FAILED;
4544
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004545 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4546 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004547
4548 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4549 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4550 FAC_OPT_CMD_WRITE_PROTECT;
4551 mcp->out_mb = MBX_1|MBX_0;
4552 mcp->in_mb = MBX_1|MBX_0;
4553 mcp->tov = MBX_TOV_SECONDS;
4554 mcp->flags = 0;
4555 rval = qla2x00_mailbox_command(vha, mcp);
4556
4557 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004558 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4559 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4560 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004561 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004562 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4563 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004564 }
4565
4566 return rval;
4567}
4568
4569int
4570qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4571{
4572 int rval;
4573 mbx_cmd_t mc;
4574 mbx_cmd_t *mcp = &mc;
4575
Chad Dupuisf73cb692014-02-26 04:15:06 -05004576 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07004577 !IS_QLA27XX(vha->hw) && !IS_QLA28XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004578 return QLA_FUNCTION_FAILED;
4579
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4581 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004582
4583 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4584 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4585 mcp->mb[2] = LSW(start);
4586 mcp->mb[3] = MSW(start);
4587 mcp->mb[4] = LSW(finish);
4588 mcp->mb[5] = MSW(finish);
4589 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4590 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4591 mcp->tov = MBX_TOV_SECONDS;
4592 mcp->flags = 0;
4593 rval = qla2x00_mailbox_command(vha, mcp);
4594
4595 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004596 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4597 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4598 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004599 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004600 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4601 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004602 }
4603
4604 return rval;
4605}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004606
4607int
Michael Hernandez3f006ac2019-03-12 11:08:22 -07004608qla81xx_fac_semaphore_access(scsi_qla_host_t *vha, int lock)
4609{
4610 int rval = QLA_SUCCESS;
4611 mbx_cmd_t mc;
4612 mbx_cmd_t *mcp = &mc;
4613 struct qla_hw_data *ha = vha->hw;
4614
4615 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
4616 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
4617 return rval;
4618
4619 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4620 "Entered %s.\n", __func__);
4621
4622 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4623 mcp->mb[1] = (lock ? FAC_OPT_CMD_LOCK_SEMAPHORE :
4624 FAC_OPT_CMD_UNLOCK_SEMAPHORE);
4625 mcp->out_mb = MBX_1|MBX_0;
4626 mcp->in_mb = MBX_1|MBX_0;
4627 mcp->tov = MBX_TOV_SECONDS;
4628 mcp->flags = 0;
4629 rval = qla2x00_mailbox_command(vha, mcp);
4630
4631 if (rval != QLA_SUCCESS) {
4632 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4633 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4634 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
4635 } else {
4636 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4637 "Done %s.\n", __func__);
4638 }
4639
4640 return rval;
4641}
4642
4643int
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004644qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4645{
4646 int rval = 0;
4647 mbx_cmd_t mc;
4648 mbx_cmd_t *mcp = &mc;
4649
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004650 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4651 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004652
4653 mcp->mb[0] = MBC_RESTART_MPI_FW;
4654 mcp->out_mb = MBX_0;
4655 mcp->in_mb = MBX_0|MBX_1;
4656 mcp->tov = MBX_TOV_SECONDS;
4657 mcp->flags = 0;
4658 rval = qla2x00_mailbox_command(vha, mcp);
4659
4660 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004661 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4662 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4663 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004664 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004665 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4666 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004667 }
4668
4669 return rval;
4670}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004671
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004672int
4673qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4674{
4675 int rval;
4676 mbx_cmd_t mc;
4677 mbx_cmd_t *mcp = &mc;
4678 int i;
4679 int len;
4680 uint16_t *str;
4681 struct qla_hw_data *ha = vha->hw;
4682
4683 if (!IS_P3P_TYPE(ha))
4684 return QLA_FUNCTION_FAILED;
4685
4686 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4687 "Entered %s.\n", __func__);
4688
4689 str = (void *)version;
4690 len = strlen(version);
4691
4692 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4693 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4694 mcp->out_mb = MBX_1|MBX_0;
4695 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4696 mcp->mb[i] = cpu_to_le16p(str);
4697 mcp->out_mb |= 1<<i;
4698 }
4699 for (; i < 16; i++) {
4700 mcp->mb[i] = 0;
4701 mcp->out_mb |= 1<<i;
4702 }
4703 mcp->in_mb = MBX_1|MBX_0;
4704 mcp->tov = MBX_TOV_SECONDS;
4705 mcp->flags = 0;
4706 rval = qla2x00_mailbox_command(vha, mcp);
4707
4708 if (rval != QLA_SUCCESS) {
4709 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4710 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4711 } else {
4712 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4713 "Done %s.\n", __func__);
4714 }
4715
4716 return rval;
4717}
4718
4719int
4720qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4721{
4722 int rval;
4723 mbx_cmd_t mc;
4724 mbx_cmd_t *mcp = &mc;
4725 int len;
4726 uint16_t dwlen;
4727 uint8_t *str;
4728 dma_addr_t str_dma;
4729 struct qla_hw_data *ha = vha->hw;
4730
4731 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4732 IS_P3P_TYPE(ha))
4733 return QLA_FUNCTION_FAILED;
4734
4735 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4736 "Entered %s.\n", __func__);
4737
4738 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4739 if (!str) {
4740 ql_log(ql_log_warn, vha, 0x117f,
4741 "Failed to allocate driver version param.\n");
4742 return QLA_MEMORY_ALLOC_FAILED;
4743 }
4744
4745 memcpy(str, "\x7\x3\x11\x0", 4);
4746 dwlen = str[0];
4747 len = dwlen * 4 - 4;
4748 memset(str + 4, 0, len);
4749 if (len > strlen(version))
4750 len = strlen(version);
4751 memcpy(str + 4, version, len);
4752
4753 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4754 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4755 mcp->mb[2] = MSW(LSD(str_dma));
4756 mcp->mb[3] = LSW(LSD(str_dma));
4757 mcp->mb[6] = MSW(MSD(str_dma));
4758 mcp->mb[7] = LSW(MSD(str_dma));
4759 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4760 mcp->in_mb = MBX_1|MBX_0;
4761 mcp->tov = MBX_TOV_SECONDS;
4762 mcp->flags = 0;
4763 rval = qla2x00_mailbox_command(vha, mcp);
4764
4765 if (rval != QLA_SUCCESS) {
4766 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4767 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4768 } else {
4769 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4770 "Done %s.\n", __func__);
4771 }
4772
4773 dma_pool_free(ha->s_dma_pool, str, str_dma);
4774
4775 return rval;
4776}
4777
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004778int
4779qla24xx_get_port_login_templ(scsi_qla_host_t *vha, dma_addr_t buf_dma,
4780 void *buf, uint16_t bufsiz)
4781{
4782 int rval, i;
4783 mbx_cmd_t mc;
4784 mbx_cmd_t *mcp = &mc;
4785 uint32_t *bp;
4786
4787 if (!IS_FWI2_CAPABLE(vha->hw))
4788 return QLA_FUNCTION_FAILED;
4789
4790 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4791 "Entered %s.\n", __func__);
4792
4793 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4794 mcp->mb[1] = RNID_TYPE_PORT_LOGIN << 8;
4795 mcp->mb[2] = MSW(buf_dma);
4796 mcp->mb[3] = LSW(buf_dma);
4797 mcp->mb[6] = MSW(MSD(buf_dma));
4798 mcp->mb[7] = LSW(MSD(buf_dma));
4799 mcp->mb[8] = bufsiz/4;
4800 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4801 mcp->in_mb = MBX_1|MBX_0;
4802 mcp->tov = MBX_TOV_SECONDS;
4803 mcp->flags = 0;
4804 rval = qla2x00_mailbox_command(vha, mcp);
4805
4806 if (rval != QLA_SUCCESS) {
4807 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4808 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4809 } else {
4810 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4811 "Done %s.\n", __func__);
4812 bp = (uint32_t *) buf;
4813 for (i = 0; i < (bufsiz-4)/4; i++, bp++)
Quinn Tran8777e432018-08-02 13:16:57 -07004814 *bp = le32_to_cpu(*bp);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004815 }
4816
4817 return rval;
4818}
4819
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004820static int
4821qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4822{
4823 int rval;
4824 mbx_cmd_t mc;
4825 mbx_cmd_t *mcp = &mc;
4826
4827 if (!IS_FWI2_CAPABLE(vha->hw))
4828 return QLA_FUNCTION_FAILED;
4829
4830 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4831 "Entered %s.\n", __func__);
4832
4833 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4834 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4835 mcp->out_mb = MBX_1|MBX_0;
4836 mcp->in_mb = MBX_1|MBX_0;
4837 mcp->tov = MBX_TOV_SECONDS;
4838 mcp->flags = 0;
4839 rval = qla2x00_mailbox_command(vha, mcp);
4840 *temp = mcp->mb[1];
4841
4842 if (rval != QLA_SUCCESS) {
4843 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4844 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4845 } else {
4846 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4847 "Done %s.\n", __func__);
4848 }
4849
4850 return rval;
4851}
4852
Joe Carnuccio3a117112013-02-08 01:58:00 -05004853int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004854qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4855 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004856{
4857 int rval;
4858 mbx_cmd_t mc;
4859 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004860 struct qla_hw_data *ha = vha->hw;
4861
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004862 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4863 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004864
Joe Carnuccio6766df92011-05-10 11:30:15 -07004865 if (!IS_FWI2_CAPABLE(ha))
4866 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004867
Joe Carnuccio6766df92011-05-10 11:30:15 -07004868 if (len == 1)
4869 opt |= BIT_0;
4870
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004871 mcp->mb[0] = MBC_READ_SFP;
4872 mcp->mb[1] = dev;
4873 mcp->mb[2] = MSW(sfp_dma);
4874 mcp->mb[3] = LSW(sfp_dma);
4875 mcp->mb[6] = MSW(MSD(sfp_dma));
4876 mcp->mb[7] = LSW(MSD(sfp_dma));
4877 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004878 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004879 mcp->mb[10] = opt;
4880 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 -07004881 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004882 mcp->tov = MBX_TOV_SECONDS;
4883 mcp->flags = 0;
4884 rval = qla2x00_mailbox_command(vha, mcp);
4885
4886 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004887 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004888
4889 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004890 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4891 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07004892 if (mcp->mb[0] == MBS_COMMAND_ERROR && mcp->mb[1] == 0x22) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004893 /* sfp is not there */
4894 rval = QLA_INTERFACE_ERROR;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07004895 }
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004896 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004897 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4898 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004899 }
4900
4901 return rval;
4902}
4903
4904int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004905qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4906 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004907{
4908 int rval;
4909 mbx_cmd_t mc;
4910 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004911 struct qla_hw_data *ha = vha->hw;
4912
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004913 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4914 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004915
Joe Carnuccio6766df92011-05-10 11:30:15 -07004916 if (!IS_FWI2_CAPABLE(ha))
4917 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004918
Joe Carnuccio6766df92011-05-10 11:30:15 -07004919 if (len == 1)
4920 opt |= BIT_0;
4921
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004922 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004923 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004924
4925 mcp->mb[0] = MBC_WRITE_SFP;
4926 mcp->mb[1] = dev;
4927 mcp->mb[2] = MSW(sfp_dma);
4928 mcp->mb[3] = LSW(sfp_dma);
4929 mcp->mb[6] = MSW(MSD(sfp_dma));
4930 mcp->mb[7] = LSW(MSD(sfp_dma));
4931 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004932 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004933 mcp->mb[10] = opt;
4934 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 -07004935 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004936 mcp->tov = MBX_TOV_SECONDS;
4937 mcp->flags = 0;
4938 rval = qla2x00_mailbox_command(vha, mcp);
4939
4940 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004941 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4942 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004943 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004944 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4945 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004946 }
4947
4948 return rval;
4949}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004950
4951int
4952qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4953 uint16_t size_in_bytes, uint16_t *actual_size)
4954{
4955 int rval;
4956 mbx_cmd_t mc;
4957 mbx_cmd_t *mcp = &mc;
4958
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004959 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4960 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004961
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004962 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004963 return QLA_FUNCTION_FAILED;
4964
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004965 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4966 mcp->mb[2] = MSW(stats_dma);
4967 mcp->mb[3] = LSW(stats_dma);
4968 mcp->mb[6] = MSW(MSD(stats_dma));
4969 mcp->mb[7] = LSW(MSD(stats_dma));
4970 mcp->mb[8] = size_in_bytes >> 2;
4971 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4972 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4973 mcp->tov = MBX_TOV_SECONDS;
4974 mcp->flags = 0;
4975 rval = qla2x00_mailbox_command(vha, mcp);
4976
4977 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004978 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4979 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4980 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004981 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004982 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4983 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004984
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004985
4986 *actual_size = mcp->mb[2] << 2;
4987 }
4988
4989 return rval;
4990}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004991
4992int
4993qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4994 uint16_t size)
4995{
4996 int rval;
4997 mbx_cmd_t mc;
4998 mbx_cmd_t *mcp = &mc;
4999
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005000 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
5001 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005002
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005003 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005004 return QLA_FUNCTION_FAILED;
5005
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005006 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
5007 mcp->mb[1] = 0;
5008 mcp->mb[2] = MSW(tlv_dma);
5009 mcp->mb[3] = LSW(tlv_dma);
5010 mcp->mb[6] = MSW(MSD(tlv_dma));
5011 mcp->mb[7] = LSW(MSD(tlv_dma));
5012 mcp->mb[8] = size;
5013 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5014 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5015 mcp->tov = MBX_TOV_SECONDS;
5016 mcp->flags = 0;
5017 rval = qla2x00_mailbox_command(vha, mcp);
5018
5019 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005020 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
5021 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
5022 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005023 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005024 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
5025 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07005026 }
5027
5028 return rval;
5029}
Andrew Vasquez18e75552009-06-03 09:55:30 -07005030
5031int
5032qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
5033{
5034 int rval;
5035 mbx_cmd_t mc;
5036 mbx_cmd_t *mcp = &mc;
5037
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005038 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
5039 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005040
Andrew Vasquez18e75552009-06-03 09:55:30 -07005041 if (!IS_FWI2_CAPABLE(vha->hw))
5042 return QLA_FUNCTION_FAILED;
5043
Andrew Vasquez18e75552009-06-03 09:55:30 -07005044 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
5045 mcp->mb[1] = LSW(risc_addr);
5046 mcp->mb[8] = MSW(risc_addr);
5047 mcp->out_mb = MBX_8|MBX_1|MBX_0;
5048 mcp->in_mb = MBX_3|MBX_2|MBX_0;
5049 mcp->tov = 30;
5050 mcp->flags = 0;
5051 rval = qla2x00_mailbox_command(vha, mcp);
5052 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005053 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
5054 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005055 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005056 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
5057 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005058 *data = mcp->mb[3] << 16 | mcp->mb[2];
5059 }
5060
5061 return rval;
5062}
5063
5064int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005065qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5066 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005067{
5068 int rval;
5069 mbx_cmd_t mc;
5070 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005071
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005072 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
5073 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005074
5075 memset(mcp->mb, 0 , sizeof(mcp->mb));
5076 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
5077 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
5078
5079 /* transfer count */
5080 mcp->mb[10] = LSW(mreq->transfer_size);
5081 mcp->mb[11] = MSW(mreq->transfer_size);
5082
5083 /* send data address */
5084 mcp->mb[14] = LSW(mreq->send_dma);
5085 mcp->mb[15] = MSW(mreq->send_dma);
5086 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5087 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5088
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005089 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005090 mcp->mb[16] = LSW(mreq->rcv_dma);
5091 mcp->mb[17] = MSW(mreq->rcv_dma);
5092 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5093 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5094
5095 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04005096 mcp->mb[18] = LSW(mreq->iteration_count);
5097 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005098
5099 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
5100 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 -08005101 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005102 mcp->out_mb |= MBX_2;
5103 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
5104
5105 mcp->buf_size = mreq->transfer_size;
5106 mcp->tov = MBX_TOV_SECONDS;
5107 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5108
5109 rval = qla2x00_mailbox_command(vha, mcp);
5110
5111 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005112 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
5113 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
5114 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
5115 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005116 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005117 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
5118 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005119 }
5120
5121 /* Copy mailbox information */
5122 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005123 return rval;
5124}
5125
5126int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005127qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5128 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005129{
5130 int rval;
5131 mbx_cmd_t mc;
5132 mbx_cmd_t *mcp = &mc;
5133 struct qla_hw_data *ha = vha->hw;
5134
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005135 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
5136 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005137
5138 memset(mcp->mb, 0 , sizeof(mcp->mb));
5139 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07005140 /* BIT_6 specifies 64bit address */
5141 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005142 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005143 mcp->mb[2] = vha->fcoe_fcf_idx;
5144 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005145 mcp->mb[16] = LSW(mreq->rcv_dma);
5146 mcp->mb[17] = MSW(mreq->rcv_dma);
5147 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5148 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5149
5150 mcp->mb[10] = LSW(mreq->transfer_size);
5151
5152 mcp->mb[14] = LSW(mreq->send_dma);
5153 mcp->mb[15] = MSW(mreq->send_dma);
5154 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5155 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5156
5157 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
5158 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005159 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005160 mcp->out_mb |= MBX_2;
5161
5162 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005163 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
5164 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005165 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005166 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005167 mcp->in_mb |= MBX_3;
5168
5169 mcp->tov = MBX_TOV_SECONDS;
5170 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5171 mcp->buf_size = mreq->transfer_size;
5172
5173 rval = qla2x00_mailbox_command(vha, mcp);
5174
5175 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005176 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
5177 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5178 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005179 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005180 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
5181 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005182 }
5183
5184 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005185 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005186 return rval;
5187}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005188
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005189int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005190qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005191{
5192 int rval;
5193 mbx_cmd_t mc;
5194 mbx_cmd_t *mcp = &mc;
5195
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005196 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005197 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005198
5199 mcp->mb[0] = MBC_ISP84XX_RESET;
5200 mcp->mb[1] = enable_diagnostic;
5201 mcp->out_mb = MBX_1|MBX_0;
5202 mcp->in_mb = MBX_1|MBX_0;
5203 mcp->tov = MBX_TOV_SECONDS;
5204 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005205 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005206
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005207 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005208 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005209 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005210 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
5211 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005212
5213 return rval;
5214}
5215
5216int
Andrew Vasquez18e75552009-06-03 09:55:30 -07005217qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
5218{
5219 int rval;
5220 mbx_cmd_t mc;
5221 mbx_cmd_t *mcp = &mc;
5222
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005223 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
5224 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005225
Andrew Vasquez18e75552009-06-03 09:55:30 -07005226 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005227 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005228
Andrew Vasquez18e75552009-06-03 09:55:30 -07005229 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
5230 mcp->mb[1] = LSW(risc_addr);
5231 mcp->mb[2] = LSW(data);
5232 mcp->mb[3] = MSW(data);
5233 mcp->mb[8] = MSW(risc_addr);
5234 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07005235 mcp->in_mb = MBX_1|MBX_0;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005236 mcp->tov = 30;
5237 mcp->flags = 0;
5238 rval = qla2x00_mailbox_command(vha, mcp);
5239 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005240 ql_dbg(ql_dbg_mbx, vha, 0x1101,
Joe Carnuccio2a3192a2019-03-12 11:08:14 -07005241 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5242 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005243 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005244 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
5245 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005246 }
5247
5248 return rval;
5249}
Michael Hernandez3064ff32009-12-15 21:29:44 -08005250
5251int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005252qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
5253{
5254 int rval;
5255 uint32_t stat, timer;
5256 uint16_t mb0 = 0;
5257 struct qla_hw_data *ha = vha->hw;
5258 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5259
5260 rval = QLA_SUCCESS;
5261
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005262 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
5263 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005264
5265 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
5266
5267 /* Write the MBC data to the registers */
5268 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
5269 WRT_REG_WORD(&reg->mailbox1, mb[0]);
5270 WRT_REG_WORD(&reg->mailbox2, mb[1]);
5271 WRT_REG_WORD(&reg->mailbox3, mb[2]);
5272 WRT_REG_WORD(&reg->mailbox4, mb[3]);
5273
5274 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
5275
5276 /* Poll for MBC interrupt */
5277 for (timer = 6000000; timer; timer--) {
5278 /* Check for pending interrupts. */
5279 stat = RD_REG_DWORD(&reg->host_status);
5280 if (stat & HSRX_RISC_INT) {
5281 stat &= 0xff;
5282
5283 if (stat == 0x1 || stat == 0x2 ||
5284 stat == 0x10 || stat == 0x11) {
5285 set_bit(MBX_INTERRUPT,
5286 &ha->mbx_cmd_flags);
5287 mb0 = RD_REG_WORD(&reg->mailbox0);
5288 WRT_REG_DWORD(&reg->hccr,
5289 HCCRX_CLR_RISC_INT);
5290 RD_REG_DWORD(&reg->hccr);
5291 break;
5292 }
5293 }
5294 udelay(5);
5295 }
5296
5297 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5298 rval = mb0 & MBS_MASK;
5299 else
5300 rval = QLA_FUNCTION_FAILED;
5301
5302 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005303 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5304 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005305 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005306 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5307 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005308 }
5309
5310 return rval;
5311}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005312
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005313/* Set the specified data rate */
5314int
5315qla2x00_set_data_rate(scsi_qla_host_t *vha, uint16_t mode)
5316{
5317 int rval;
5318 mbx_cmd_t mc;
5319 mbx_cmd_t *mcp = &mc;
5320 struct qla_hw_data *ha = vha->hw;
5321 uint16_t val;
5322
5323 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5324 "Entered %s speed:0x%x mode:0x%x.\n", __func__, ha->set_data_rate,
5325 mode);
5326
5327 if (!IS_FWI2_CAPABLE(ha))
5328 return QLA_FUNCTION_FAILED;
5329
5330 memset(mcp, 0, sizeof(*mcp));
5331 switch (ha->set_data_rate) {
5332 case PORT_SPEED_AUTO:
5333 case PORT_SPEED_4GB:
5334 case PORT_SPEED_8GB:
5335 case PORT_SPEED_16GB:
5336 case PORT_SPEED_32GB:
5337 val = ha->set_data_rate;
5338 break;
5339 default:
5340 ql_log(ql_log_warn, vha, 0x1199,
5341 "Unrecognized speed setting:%d. Setting Autoneg\n",
5342 ha->set_data_rate);
5343 val = ha->set_data_rate = PORT_SPEED_AUTO;
5344 break;
5345 }
5346
5347 mcp->mb[0] = MBC_DATA_RATE;
5348 mcp->mb[1] = mode;
5349 mcp->mb[2] = val;
5350
5351 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5352 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005353 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005354 mcp->in_mb |= MBX_4|MBX_3;
5355 mcp->tov = MBX_TOV_SECONDS;
5356 mcp->flags = 0;
5357 rval = qla2x00_mailbox_command(vha, mcp);
5358 if (rval != QLA_SUCCESS) {
5359 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5360 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5361 } else {
5362 if (mcp->mb[1] != 0x7)
5363 ql_dbg(ql_dbg_mbx, vha, 0x1179,
5364 "Speed set:0x%x\n", mcp->mb[1]);
5365
5366 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5367 "Done %s.\n", __func__);
5368 }
5369
5370 return rval;
5371}
5372
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005373int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005374qla2x00_get_data_rate(scsi_qla_host_t *vha)
5375{
5376 int rval;
5377 mbx_cmd_t mc;
5378 mbx_cmd_t *mcp = &mc;
5379 struct qla_hw_data *ha = vha->hw;
5380
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005381 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5382 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005383
Michael Hernandez3064ff32009-12-15 21:29:44 -08005384 if (!IS_FWI2_CAPABLE(ha))
5385 return QLA_FUNCTION_FAILED;
5386
Michael Hernandez3064ff32009-12-15 21:29:44 -08005387 mcp->mb[0] = MBC_DATA_RATE;
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005388 mcp->mb[1] = QLA_GET_DATA_RATE;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005389 mcp->out_mb = MBX_1|MBX_0;
5390 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005391 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005392 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005393 mcp->tov = MBX_TOV_SECONDS;
5394 mcp->flags = 0;
5395 rval = qla2x00_mailbox_command(vha, mcp);
5396 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005397 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5398 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005399 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005400 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5401 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005402 if (mcp->mb[1] != 0x7)
5403 ha->link_data_rate = mcp->mb[1];
5404 }
5405
5406 return rval;
5407}
Sarang Radke09ff7012010-03-19 17:03:59 -07005408
5409int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005410qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5411{
5412 int rval;
5413 mbx_cmd_t mc;
5414 mbx_cmd_t *mcp = &mc;
5415 struct qla_hw_data *ha = vha->hw;
5416
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005417 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5418 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005419
Chad Dupuisf73cb692014-02-26 04:15:06 -05005420 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005421 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005422 return QLA_FUNCTION_FAILED;
5423 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5424 mcp->out_mb = MBX_0;
5425 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5426 mcp->tov = MBX_TOV_SECONDS;
5427 mcp->flags = 0;
5428
5429 rval = qla2x00_mailbox_command(vha, mcp);
5430
5431 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005432 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5433 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005434 } else {
5435 /* Copy all bits to preserve original value */
5436 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5437
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005438 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5439 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005440 }
5441 return rval;
5442}
5443
5444int
5445qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5446{
5447 int rval;
5448 mbx_cmd_t mc;
5449 mbx_cmd_t *mcp = &mc;
5450
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005451 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5452 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005453
5454 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5455 /* Copy all bits to preserve original setting */
5456 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5457 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5458 mcp->in_mb = MBX_0;
5459 mcp->tov = MBX_TOV_SECONDS;
5460 mcp->flags = 0;
5461 rval = qla2x00_mailbox_command(vha, mcp);
5462
5463 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005464 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5465 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005466 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005467 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5468 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005469
5470 return rval;
5471}
5472
5473
5474int
Sarang Radke09ff7012010-03-19 17:03:59 -07005475qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5476 uint16_t *mb)
5477{
5478 int rval;
5479 mbx_cmd_t mc;
5480 mbx_cmd_t *mcp = &mc;
5481 struct qla_hw_data *ha = vha->hw;
5482
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005483 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5484 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005485
Sarang Radke09ff7012010-03-19 17:03:59 -07005486 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5487 return QLA_FUNCTION_FAILED;
5488
Sarang Radke09ff7012010-03-19 17:03:59 -07005489 mcp->mb[0] = MBC_PORT_PARAMS;
5490 mcp->mb[1] = loop_id;
5491 if (ha->flags.fcp_prio_enabled)
5492 mcp->mb[2] = BIT_1;
5493 else
5494 mcp->mb[2] = BIT_2;
5495 mcp->mb[4] = priority & 0xf;
5496 mcp->mb[9] = vha->vp_idx;
5497 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5498 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5499 mcp->tov = 30;
5500 mcp->flags = 0;
5501 rval = qla2x00_mailbox_command(vha, mcp);
5502 if (mb != NULL) {
5503 mb[0] = mcp->mb[0];
5504 mb[1] = mcp->mb[1];
5505 mb[3] = mcp->mb[3];
5506 mb[4] = mcp->mb[4];
5507 }
5508
5509 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005510 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005511 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005512 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5513 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005514 }
5515
5516 return rval;
5517}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005518
5519int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005520qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005521{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005522 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005523 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005524 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005525
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005526 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5527 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5528 "Thermal not supported by this card.\n");
5529 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005530 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005531
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005532 if (IS_QLA25XX(ha)) {
5533 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5534 ha->pdev->subsystem_device == 0x0175) {
5535 rval = qla2x00_read_sfp(vha, 0, &byte,
5536 0x98, 0x1, 1, BIT_13|BIT_0);
5537 *temp = byte;
5538 return rval;
5539 }
5540 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5541 ha->pdev->subsystem_device == 0x338e) {
5542 rval = qla2x00_read_sfp(vha, 0, &byte,
5543 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5544 *temp = byte;
5545 return rval;
5546 }
5547 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5548 "Thermal not supported by this card.\n");
5549 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005550 }
5551
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005552 if (IS_QLA82XX(ha)) {
5553 *temp = qla82xx_read_temperature(vha);
5554 rval = QLA_SUCCESS;
5555 return rval;
5556 } else if (IS_QLA8044(ha)) {
5557 *temp = qla8044_read_temperature(vha);
5558 rval = QLA_SUCCESS;
5559 return rval;
5560 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005561
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005562 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005563 return rval;
5564}
5565
5566int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005567qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5568{
5569 int rval;
5570 struct qla_hw_data *ha = vha->hw;
5571 mbx_cmd_t mc;
5572 mbx_cmd_t *mcp = &mc;
5573
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005574 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5575 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005576
Giridhar Malavalia9083012010-04-12 17:59:55 -07005577 if (!IS_FWI2_CAPABLE(ha))
5578 return QLA_FUNCTION_FAILED;
5579
Giridhar Malavalia9083012010-04-12 17:59:55 -07005580 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005581 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005582 mcp->mb[1] = 1;
5583
5584 mcp->out_mb = MBX_1|MBX_0;
5585 mcp->in_mb = MBX_0;
5586 mcp->tov = 30;
5587 mcp->flags = 0;
5588
5589 rval = qla2x00_mailbox_command(vha, mcp);
5590 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005591 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5592 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005593 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005594 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5595 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005596 }
5597
5598 return rval;
5599}
5600
5601int
5602qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5603{
5604 int rval;
5605 struct qla_hw_data *ha = vha->hw;
5606 mbx_cmd_t mc;
5607 mbx_cmd_t *mcp = &mc;
5608
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005609 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5610 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005611
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005612 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005613 return QLA_FUNCTION_FAILED;
5614
Giridhar Malavalia9083012010-04-12 17:59:55 -07005615 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005616 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005617 mcp->mb[1] = 0;
5618
5619 mcp->out_mb = MBX_1|MBX_0;
5620 mcp->in_mb = MBX_0;
5621 mcp->tov = 30;
5622 mcp->flags = 0;
5623
5624 rval = qla2x00_mailbox_command(vha, mcp);
5625 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005626 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5627 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005628 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005629 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5630 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005631 }
5632
5633 return rval;
5634}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005635
5636int
5637qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5638{
5639 struct qla_hw_data *ha = vha->hw;
5640 mbx_cmd_t mc;
5641 mbx_cmd_t *mcp = &mc;
5642 int rval = QLA_FUNCTION_FAILED;
5643
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005644 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5645 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005646
5647 memset(mcp->mb, 0 , sizeof(mcp->mb));
5648 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5649 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5650 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5651 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5652
5653 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5654 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5655 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5656
5657 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5658 mcp->tov = MBX_TOV_SECONDS;
5659 rval = qla2x00_mailbox_command(vha, mcp);
5660
5661 /* Always copy back return mailbox values. */
5662 if (rval != QLA_SUCCESS) {
5663 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5664 "mailbox command FAILED=0x%x, subcode=%x.\n",
5665 (mcp->mb[1] << 16) | mcp->mb[0],
5666 (mcp->mb[3] << 16) | mcp->mb[2]);
5667 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005668 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5669 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005670 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5671 if (!ha->md_template_size) {
5672 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5673 "Null template size obtained.\n");
5674 rval = QLA_FUNCTION_FAILED;
5675 }
5676 }
5677 return rval;
5678}
5679
5680int
5681qla82xx_md_get_template(scsi_qla_host_t *vha)
5682{
5683 struct qla_hw_data *ha = vha->hw;
5684 mbx_cmd_t mc;
5685 mbx_cmd_t *mcp = &mc;
5686 int rval = QLA_FUNCTION_FAILED;
5687
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005688 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5689 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005690
5691 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5692 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5693 if (!ha->md_tmplt_hdr) {
5694 ql_log(ql_log_warn, vha, 0x1124,
5695 "Unable to allocate memory for Minidump template.\n");
5696 return rval;
5697 }
5698
5699 memset(mcp->mb, 0 , sizeof(mcp->mb));
5700 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5701 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5702 mcp->mb[2] = LSW(RQST_TMPLT);
5703 mcp->mb[3] = MSW(RQST_TMPLT);
5704 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5705 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5706 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5707 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5708 mcp->mb[8] = LSW(ha->md_template_size);
5709 mcp->mb[9] = MSW(ha->md_template_size);
5710
5711 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5712 mcp->tov = MBX_TOV_SECONDS;
5713 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5714 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5715 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5716 rval = qla2x00_mailbox_command(vha, mcp);
5717
5718 if (rval != QLA_SUCCESS) {
5719 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5720 "mailbox command FAILED=0x%x, subcode=%x.\n",
5721 ((mcp->mb[1] << 16) | mcp->mb[0]),
5722 ((mcp->mb[3] << 16) | mcp->mb[2]));
5723 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005724 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5725 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005726 return rval;
5727}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005728
5729int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005730qla8044_md_get_template(scsi_qla_host_t *vha)
5731{
5732 struct qla_hw_data *ha = vha->hw;
5733 mbx_cmd_t mc;
5734 mbx_cmd_t *mcp = &mc;
5735 int rval = QLA_FUNCTION_FAILED;
5736 int offset = 0, size = MINIDUMP_SIZE_36K;
Bart Van Asschebd432bb2019-04-11 14:53:17 -07005737
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005738 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5739 "Entered %s.\n", __func__);
5740
5741 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5742 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5743 if (!ha->md_tmplt_hdr) {
5744 ql_log(ql_log_warn, vha, 0xb11b,
5745 "Unable to allocate memory for Minidump template.\n");
5746 return rval;
5747 }
5748
5749 memset(mcp->mb, 0 , sizeof(mcp->mb));
5750 while (offset < ha->md_template_size) {
5751 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5752 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5753 mcp->mb[2] = LSW(RQST_TMPLT);
5754 mcp->mb[3] = MSW(RQST_TMPLT);
5755 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5756 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5757 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5758 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5759 mcp->mb[8] = LSW(size);
5760 mcp->mb[9] = MSW(size);
5761 mcp->mb[10] = offset & 0x0000FFFF;
5762 mcp->mb[11] = offset & 0xFFFF0000;
5763 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5764 mcp->tov = MBX_TOV_SECONDS;
5765 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5766 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5767 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5768 rval = qla2x00_mailbox_command(vha, mcp);
5769
5770 if (rval != QLA_SUCCESS) {
5771 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5772 "mailbox command FAILED=0x%x, subcode=%x.\n",
5773 ((mcp->mb[1] << 16) | mcp->mb[0]),
5774 ((mcp->mb[3] << 16) | mcp->mb[2]));
5775 return rval;
5776 } else
5777 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5778 "Done %s.\n", __func__);
5779 offset = offset + size;
5780 }
5781 return rval;
5782}
5783
5784int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005785qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5786{
5787 int rval;
5788 struct qla_hw_data *ha = vha->hw;
5789 mbx_cmd_t mc;
5790 mbx_cmd_t *mcp = &mc;
5791
5792 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5793 return QLA_FUNCTION_FAILED;
5794
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005795 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5796 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005797
5798 memset(mcp, 0, sizeof(mbx_cmd_t));
5799 mcp->mb[0] = MBC_SET_LED_CONFIG;
5800 mcp->mb[1] = led_cfg[0];
5801 mcp->mb[2] = led_cfg[1];
5802 if (IS_QLA8031(ha)) {
5803 mcp->mb[3] = led_cfg[2];
5804 mcp->mb[4] = led_cfg[3];
5805 mcp->mb[5] = led_cfg[4];
5806 mcp->mb[6] = led_cfg[5];
5807 }
5808
5809 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5810 if (IS_QLA8031(ha))
5811 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5812 mcp->in_mb = MBX_0;
5813 mcp->tov = 30;
5814 mcp->flags = 0;
5815
5816 rval = qla2x00_mailbox_command(vha, mcp);
5817 if (rval != QLA_SUCCESS) {
5818 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5819 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5820 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005821 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5822 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005823 }
5824
5825 return rval;
5826}
5827
5828int
5829qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5830{
5831 int rval;
5832 struct qla_hw_data *ha = vha->hw;
5833 mbx_cmd_t mc;
5834 mbx_cmd_t *mcp = &mc;
5835
5836 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5837 return QLA_FUNCTION_FAILED;
5838
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005839 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5840 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005841
5842 memset(mcp, 0, sizeof(mbx_cmd_t));
5843 mcp->mb[0] = MBC_GET_LED_CONFIG;
5844
5845 mcp->out_mb = MBX_0;
5846 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5847 if (IS_QLA8031(ha))
5848 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5849 mcp->tov = 30;
5850 mcp->flags = 0;
5851
5852 rval = qla2x00_mailbox_command(vha, mcp);
5853 if (rval != QLA_SUCCESS) {
5854 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5855 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5856 } else {
5857 led_cfg[0] = mcp->mb[1];
5858 led_cfg[1] = mcp->mb[2];
5859 if (IS_QLA8031(ha)) {
5860 led_cfg[2] = mcp->mb[3];
5861 led_cfg[3] = mcp->mb[4];
5862 led_cfg[4] = mcp->mb[5];
5863 led_cfg[5] = mcp->mb[6];
5864 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005865 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5866 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005867 }
5868
5869 return rval;
5870}
5871
5872int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005873qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5874{
5875 int rval;
5876 struct qla_hw_data *ha = vha->hw;
5877 mbx_cmd_t mc;
5878 mbx_cmd_t *mcp = &mc;
5879
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005880 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005881 return QLA_FUNCTION_FAILED;
5882
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005883 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005884 "Entered %s.\n", __func__);
5885
5886 memset(mcp, 0, sizeof(mbx_cmd_t));
5887 mcp->mb[0] = MBC_SET_LED_CONFIG;
5888 if (enable)
5889 mcp->mb[7] = 0xE;
5890 else
5891 mcp->mb[7] = 0xD;
5892
5893 mcp->out_mb = MBX_7|MBX_0;
5894 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005895 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005896 mcp->flags = 0;
5897
5898 rval = qla2x00_mailbox_command(vha, mcp);
5899 if (rval != QLA_SUCCESS) {
5900 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5901 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5902 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005903 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005904 "Done %s.\n", __func__);
5905 }
5906
5907 return rval;
5908}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005909
5910int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005911qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005912{
5913 int rval;
5914 struct qla_hw_data *ha = vha->hw;
5915 mbx_cmd_t mc;
5916 mbx_cmd_t *mcp = &mc;
5917
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005918 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005919 return QLA_FUNCTION_FAILED;
5920
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005921 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5922 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005923
5924 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5925 mcp->mb[1] = LSW(reg);
5926 mcp->mb[2] = MSW(reg);
5927 mcp->mb[3] = LSW(data);
5928 mcp->mb[4] = MSW(data);
5929 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5930
5931 mcp->in_mb = MBX_1|MBX_0;
5932 mcp->tov = MBX_TOV_SECONDS;
5933 mcp->flags = 0;
5934 rval = qla2x00_mailbox_command(vha, mcp);
5935
5936 if (rval != QLA_SUCCESS) {
5937 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5938 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5939 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005940 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005941 "Done %s.\n", __func__);
5942 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005943
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005944 return rval;
5945}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005946
5947int
5948qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5949{
5950 int rval;
5951 struct qla_hw_data *ha = vha->hw;
5952 mbx_cmd_t mc;
5953 mbx_cmd_t *mcp = &mc;
5954
5955 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005956 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005957 "Implicit LOGO Unsupported.\n");
5958 return QLA_FUNCTION_FAILED;
5959 }
5960
5961
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005962 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5963 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005964
5965 /* Perform Implicit LOGO. */
5966 mcp->mb[0] = MBC_PORT_LOGOUT;
5967 mcp->mb[1] = fcport->loop_id;
5968 mcp->mb[10] = BIT_15;
5969 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5970 mcp->in_mb = MBX_0;
5971 mcp->tov = MBX_TOV_SECONDS;
5972 mcp->flags = 0;
5973 rval = qla2x00_mailbox_command(vha, mcp);
5974 if (rval != QLA_SUCCESS)
5975 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5976 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5977 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005978 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5979 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005980
5981 return rval;
5982}
5983
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005984int
5985qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5986{
5987 int rval;
5988 mbx_cmd_t mc;
5989 mbx_cmd_t *mcp = &mc;
5990 struct qla_hw_data *ha = vha->hw;
5991 unsigned long retry_max_time = jiffies + (2 * HZ);
5992
Joe Carnuccioecc89f22019-03-12 11:08:13 -07005993 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005994 return QLA_FUNCTION_FAILED;
5995
5996 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5997
5998retry_rd_reg:
5999 mcp->mb[0] = MBC_READ_REMOTE_REG;
6000 mcp->mb[1] = LSW(reg);
6001 mcp->mb[2] = MSW(reg);
6002 mcp->out_mb = MBX_2|MBX_1|MBX_0;
6003 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
6004 mcp->tov = MBX_TOV_SECONDS;
6005 mcp->flags = 0;
6006 rval = qla2x00_mailbox_command(vha, mcp);
6007
6008 if (rval != QLA_SUCCESS) {
6009 ql_dbg(ql_dbg_mbx, vha, 0x114c,
6010 "Failed=%x mb[0]=%x mb[1]=%x.\n",
6011 rval, mcp->mb[0], mcp->mb[1]);
6012 } else {
6013 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
6014 if (*data == QLA8XXX_BAD_VALUE) {
6015 /*
6016 * During soft-reset CAMRAM register reads might
6017 * return 0xbad0bad0. So retry for MAX of 2 sec
6018 * while reading camram registers.
6019 */
6020 if (time_after(jiffies, retry_max_time)) {
6021 ql_dbg(ql_dbg_mbx, vha, 0x1141,
6022 "Failure to read CAMRAM register. "
6023 "data=0x%x.\n", *data);
6024 return QLA_FUNCTION_FAILED;
6025 }
6026 msleep(100);
6027 goto retry_rd_reg;
6028 }
6029 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
6030 }
6031
6032 return rval;
6033}
6034
6035int
6036qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
6037{
6038 int rval;
6039 mbx_cmd_t mc;
6040 mbx_cmd_t *mcp = &mc;
6041 struct qla_hw_data *ha = vha->hw;
6042
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006043 if (!IS_QLA83XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04006044 return QLA_FUNCTION_FAILED;
6045
6046 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
6047
6048 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
6049 mcp->out_mb = MBX_0;
6050 mcp->in_mb = MBX_1|MBX_0;
6051 mcp->tov = MBX_TOV_SECONDS;
6052 mcp->flags = 0;
6053 rval = qla2x00_mailbox_command(vha, mcp);
6054
6055 if (rval != QLA_SUCCESS) {
6056 ql_dbg(ql_dbg_mbx, vha, 0x1144,
6057 "Failed=%x mb[0]=%x mb[1]=%x.\n",
6058 rval, mcp->mb[0], mcp->mb[1]);
6059 ha->isp_ops->fw_dump(vha, 0);
6060 } else {
6061 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
6062 }
6063
6064 return rval;
6065}
6066
6067int
6068qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
6069 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
6070{
6071 int rval;
6072 mbx_cmd_t mc;
6073 mbx_cmd_t *mcp = &mc;
6074 uint8_t subcode = (uint8_t)options;
6075 struct qla_hw_data *ha = vha->hw;
6076
6077 if (!IS_QLA8031(ha))
6078 return QLA_FUNCTION_FAILED;
6079
6080 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
6081
6082 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
6083 mcp->mb[1] = options;
6084 mcp->out_mb = MBX_1|MBX_0;
6085 if (subcode & BIT_2) {
6086 mcp->mb[2] = LSW(start_addr);
6087 mcp->mb[3] = MSW(start_addr);
6088 mcp->mb[4] = LSW(end_addr);
6089 mcp->mb[5] = MSW(end_addr);
6090 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
6091 }
6092 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6093 if (!(subcode & (BIT_2 | BIT_5)))
6094 mcp->in_mb |= MBX_4|MBX_3;
6095 mcp->tov = MBX_TOV_SECONDS;
6096 mcp->flags = 0;
6097 rval = qla2x00_mailbox_command(vha, mcp);
6098
6099 if (rval != QLA_SUCCESS) {
6100 ql_dbg(ql_dbg_mbx, vha, 0x1147,
6101 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
6102 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
6103 mcp->mb[4]);
6104 ha->isp_ops->fw_dump(vha, 0);
6105 } else {
6106 if (subcode & BIT_5)
6107 *sector_size = mcp->mb[1];
6108 else if (subcode & (BIT_6 | BIT_7)) {
6109 ql_dbg(ql_dbg_mbx, vha, 0x1148,
6110 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6111 } else if (subcode & (BIT_3 | BIT_4)) {
6112 ql_dbg(ql_dbg_mbx, vha, 0x1149,
6113 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6114 }
6115 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
6116 }
6117
6118 return rval;
6119}
Saurav Kashyap81178772012-08-22 14:21:04 -04006120
6121int
6122qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
6123 uint32_t size)
6124{
6125 int rval;
6126 mbx_cmd_t mc;
6127 mbx_cmd_t *mcp = &mc;
6128
6129 if (!IS_MCTP_CAPABLE(vha->hw))
6130 return QLA_FUNCTION_FAILED;
6131
6132 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
6133 "Entered %s.\n", __func__);
6134
6135 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
6136 mcp->mb[1] = LSW(addr);
6137 mcp->mb[2] = MSW(req_dma);
6138 mcp->mb[3] = LSW(req_dma);
6139 mcp->mb[4] = MSW(size);
6140 mcp->mb[5] = LSW(size);
6141 mcp->mb[6] = MSW(MSD(req_dma));
6142 mcp->mb[7] = LSW(MSD(req_dma));
6143 mcp->mb[8] = MSW(addr);
6144 /* Setting RAM ID to valid */
6145 mcp->mb[10] |= BIT_7;
6146 /* For MCTP RAM ID is 0x40 */
6147 mcp->mb[10] |= 0x40;
6148
6149 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
6150 MBX_0;
6151
6152 mcp->in_mb = MBX_0;
6153 mcp->tov = MBX_TOV_SECONDS;
6154 mcp->flags = 0;
6155 rval = qla2x00_mailbox_command(vha, mcp);
6156
6157 if (rval != QLA_SUCCESS) {
6158 ql_dbg(ql_dbg_mbx, vha, 0x114e,
6159 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6160 } else {
6161 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
6162 "Done %s.\n", __func__);
6163 }
6164
6165 return rval;
6166}
Joe Carnuccioec891462016-07-06 11:14:26 -04006167
6168int
6169qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
6170 void *dd_buf, uint size, uint options)
6171{
6172 int rval;
6173 mbx_cmd_t mc;
6174 mbx_cmd_t *mcp = &mc;
6175 dma_addr_t dd_dma;
6176
Joe Carnuccioecc89f22019-03-12 11:08:13 -07006177 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
6178 !IS_QLA28XX(vha->hw))
Joe Carnuccioec891462016-07-06 11:14:26 -04006179 return QLA_FUNCTION_FAILED;
6180
Quinn Tran83548fe2017-06-02 09:12:01 -07006181 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04006182 "Entered %s.\n", __func__);
6183
Joe Carnuccioec891462016-07-06 11:14:26 -04006184 dd_dma = dma_map_single(&vha->hw->pdev->dev,
6185 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08006186 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04006187 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
6188 return QLA_MEMORY_ALLOC_FAILED;
6189 }
6190
6191 memset(dd_buf, 0, size);
6192
6193 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
6194 mcp->mb[1] = options;
6195 mcp->mb[2] = MSW(LSD(dd_dma));
6196 mcp->mb[3] = LSW(LSD(dd_dma));
6197 mcp->mb[6] = MSW(MSD(dd_dma));
6198 mcp->mb[7] = LSW(MSD(dd_dma));
6199 mcp->mb[8] = size;
6200 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
6201 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
6202 mcp->buf_size = size;
6203 mcp->flags = MBX_DMA_IN;
6204 mcp->tov = MBX_TOV_SECONDS * 4;
6205 rval = qla2x00_mailbox_command(vha, mcp);
6206
6207 if (rval != QLA_SUCCESS) {
6208 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
6209 } else {
6210 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
6211 "Done %s.\n", __func__);
6212 }
6213
6214 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
6215 size, DMA_FROM_DEVICE);
6216
6217 return rval;
6218}
Quinn Tran15f30a52017-03-15 09:48:52 -07006219
Bart Van Assche6c18a432019-08-08 20:02:04 -07006220static void qla2x00_async_mb_sp_done(srb_t *sp, int res)
Quinn Tran15f30a52017-03-15 09:48:52 -07006221{
Quinn Tran15f30a52017-03-15 09:48:52 -07006222 sp->u.iocb_cmd.u.mbx.rc = res;
6223
6224 complete(&sp->u.iocb_cmd.u.mbx.comp);
6225 /* don't free sp here. Let the caller do the free */
6226}
6227
6228/*
6229 * This mailbox uses the iocb interface to send MB command.
6230 * This allows non-critial (non chip setup) command to go
6231 * out in parrallel.
6232 */
6233int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
6234{
6235 int rval = QLA_FUNCTION_FAILED;
6236 srb_t *sp;
6237 struct srb_iocb *c;
6238
6239 if (!vha->hw->flags.fw_started)
6240 goto done;
6241
6242 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
6243 if (!sp)
6244 goto done;
6245
6246 sp->type = SRB_MB_IOCB;
6247 sp->name = mb_to_str(mcp->mb[0]);
6248
Quinn Tran15f30a52017-03-15 09:48:52 -07006249 c = &sp->u.iocb_cmd;
6250 c->timeout = qla2x00_async_iocb_timeout;
6251 init_completion(&c->u.mbx.comp);
6252
Ben Hutchingse74e7d92018-03-20 21:36:14 +00006253 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
6254
6255 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
6256
Quinn Tran15f30a52017-03-15 09:48:52 -07006257 sp->done = qla2x00_async_mb_sp_done;
6258
6259 rval = qla2x00_start_sp(sp);
6260 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006261 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07006262 "%s: %s Failed submission. %x.\n",
6263 __func__, sp->name, rval);
6264 goto done_free_sp;
6265 }
6266
Quinn Tran83548fe2017-06-02 09:12:01 -07006267 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006268 sp->name, sp->handle);
6269
6270 wait_for_completion(&c->u.mbx.comp);
6271 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
6272
6273 rval = c->u.mbx.rc;
6274 switch (rval) {
6275 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07006276 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006277 __func__, sp->name, rval);
6278 break;
6279 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07006280 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006281 __func__, sp->name);
6282 sp->free(sp);
6283 break;
6284 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07006285 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006286 __func__, sp->name, rval);
6287 sp->free(sp);
6288 break;
6289 }
6290
6291 return rval;
6292
6293done_free_sp:
6294 sp->free(sp);
6295done:
6296 return rval;
6297}
6298
6299/*
6300 * qla24xx_gpdb_wait
6301 * NOTE: Do not call this routine from DPC thread
6302 */
6303int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
6304{
6305 int rval = QLA_FUNCTION_FAILED;
6306 dma_addr_t pd_dma;
6307 struct port_database_24xx *pd;
6308 struct qla_hw_data *ha = vha->hw;
6309 mbx_cmd_t mc;
6310
6311 if (!vha->hw->flags.fw_started)
6312 goto done;
6313
Thomas Meyer08eb7f42017-09-21 08:15:26 +02006314 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran15f30a52017-03-15 09:48:52 -07006315 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006316 ql_log(ql_log_warn, vha, 0xd047,
6317 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07006318 goto done_free_sp;
6319 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006320
6321 memset(&mc, 0, sizeof(mc));
6322 mc.mb[0] = MBC_GET_PORT_DATABASE;
6323 mc.mb[1] = cpu_to_le16(fcport->loop_id);
6324 mc.mb[2] = MSW(pd_dma);
6325 mc.mb[3] = LSW(pd_dma);
6326 mc.mb[6] = MSW(MSD(pd_dma));
6327 mc.mb[7] = LSW(MSD(pd_dma));
6328 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6329 mc.mb[10] = cpu_to_le16((uint16_t)opt);
6330
6331 rval = qla24xx_send_mb_cmd(vha, &mc);
6332 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006333 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07006334 "%s: %8phC fail\n", __func__, fcport->port_name);
6335 goto done_free_sp;
6336 }
6337
6338 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
6339
Quinn Tran83548fe2017-06-02 09:12:01 -07006340 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006341 __func__, fcport->port_name);
6342
6343done_free_sp:
6344 if (pd)
6345 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
6346done:
6347 return rval;
6348}
6349
6350int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
6351 struct port_database_24xx *pd)
6352{
6353 int rval = QLA_SUCCESS;
6354 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006355 u8 current_login_state, last_login_state;
6356
6357 if (fcport->fc4f_nvme) {
6358 current_login_state = pd->current_login_state >> 4;
6359 last_login_state = pd->last_login_state >> 4;
6360 } else {
6361 current_login_state = pd->current_login_state & 0xf;
6362 last_login_state = pd->last_login_state & 0xf;
6363 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006364
6365 /* Check for logged in state. */
Quinn Tran23c64552017-12-04 14:45:08 -08006366 if (current_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006367 ql_dbg(ql_dbg_mbx, vha, 0x119a,
6368 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006369 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006370 rval = QLA_FUNCTION_FAILED;
6371 goto gpd_error_out;
6372 }
6373
6374 if (fcport->loop_id == FC_NO_LOOP_ID ||
6375 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6376 memcmp(fcport->port_name, pd->port_name, 8))) {
6377 /* We lost the device mid way. */
6378 rval = QLA_NOT_LOGGED_IN;
6379 goto gpd_error_out;
6380 }
6381
6382 /* Names are little-endian. */
6383 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6384 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6385
6386 /* Get port_id of device. */
6387 fcport->d_id.b.domain = pd->port_id[0];
6388 fcport->d_id.b.area = pd->port_id[1];
6389 fcport->d_id.b.al_pa = pd->port_id[2];
6390 fcport->d_id.b.rsvd_1 = 0;
6391
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006392 if (fcport->fc4f_nvme) {
Hannes Reineckea6a6d052019-04-10 16:16:19 +02006393 fcport->port_type = 0;
6394 if ((pd->prli_svc_param_word_3[0] & BIT_5) == 0)
6395 fcport->port_type |= FCT_NVME_INITIATOR;
6396 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6397 fcport->port_type |= FCT_NVME_TARGET;
6398 if ((pd->prli_svc_param_word_3[0] & BIT_3) == 0)
6399 fcport->port_type |= FCT_NVME_DISCOVERY;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006400 } else {
6401 /* If not target must be initiator or unknown type. */
6402 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6403 fcport->port_type = FCT_INITIATOR;
6404 else
6405 fcport->port_type = FCT_TARGET;
6406 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006407 /* Passback COS information. */
6408 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6409 FC_COS_CLASS2 : FC_COS_CLASS3;
6410
6411 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6412 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6413 fcport->conf_compl_supported = 1;
6414 }
6415
6416gpd_error_out:
6417 return rval;
6418}
6419
6420/*
6421 * qla24xx_gidlist__wait
6422 * NOTE: don't call this routine from DPC thread.
6423 */
6424int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6425 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6426{
6427 int rval = QLA_FUNCTION_FAILED;
6428 mbx_cmd_t mc;
6429
6430 if (!vha->hw->flags.fw_started)
6431 goto done;
6432
6433 memset(&mc, 0, sizeof(mc));
6434 mc.mb[0] = MBC_GET_ID_LIST;
6435 mc.mb[2] = MSW(id_list_dma);
6436 mc.mb[3] = LSW(id_list_dma);
6437 mc.mb[6] = MSW(MSD(id_list_dma));
6438 mc.mb[7] = LSW(MSD(id_list_dma));
6439 mc.mb[8] = 0;
6440 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6441
6442 rval = qla24xx_send_mb_cmd(vha, &mc);
6443 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006444 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6445 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006446 } else {
6447 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006448 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6449 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006450 }
6451done:
6452 return rval;
6453}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006454
6455int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6456{
6457 int rval;
6458 mbx_cmd_t mc;
6459 mbx_cmd_t *mcp = &mc;
6460
6461 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6462 "Entered %s\n", __func__);
6463
6464 memset(mcp->mb, 0 , sizeof(mcp->mb));
6465 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6466 mcp->mb[1] = cpu_to_le16(1);
6467 mcp->mb[2] = cpu_to_le16(value);
6468 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6469 mcp->in_mb = MBX_2 | MBX_0;
6470 mcp->tov = MBX_TOV_SECONDS;
6471 mcp->flags = 0;
6472
6473 rval = qla2x00_mailbox_command(vha, mcp);
6474
6475 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6476 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6477
6478 return rval;
6479}
6480
6481int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6482{
6483 int rval;
6484 mbx_cmd_t mc;
6485 mbx_cmd_t *mcp = &mc;
6486
6487 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6488 "Entered %s\n", __func__);
6489
6490 memset(mcp->mb, 0, sizeof(mcp->mb));
6491 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6492 mcp->mb[1] = cpu_to_le16(0);
6493 mcp->out_mb = MBX_1 | MBX_0;
6494 mcp->in_mb = MBX_2 | MBX_0;
6495 mcp->tov = MBX_TOV_SECONDS;
6496 mcp->flags = 0;
6497
6498 rval = qla2x00_mailbox_command(vha, mcp);
6499 if (rval == QLA_SUCCESS)
6500 *value = mc.mb[2];
6501
6502 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6503 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6504
6505 return rval;
6506}
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006507
6508int
6509qla2x00_read_sfp_dev(struct scsi_qla_host *vha, char *buf, int count)
6510{
6511 struct qla_hw_data *ha = vha->hw;
6512 uint16_t iter, addr, offset;
6513 dma_addr_t phys_addr;
6514 int rval, c;
6515 u8 *sfp_data;
6516
6517 memset(ha->sfp_data, 0, SFP_DEV_SIZE);
6518 addr = 0xa0;
6519 phys_addr = ha->sfp_data_dma;
6520 sfp_data = ha->sfp_data;
6521 offset = c = 0;
6522
6523 for (iter = 0; iter < SFP_DEV_SIZE / SFP_BLOCK_SIZE; iter++) {
6524 if (iter == 4) {
6525 /* Skip to next device address. */
6526 addr = 0xa2;
6527 offset = 0;
6528 }
6529
6530 rval = qla2x00_read_sfp(vha, phys_addr, sfp_data,
6531 addr, offset, SFP_BLOCK_SIZE, BIT_1);
6532 if (rval != QLA_SUCCESS) {
6533 ql_log(ql_log_warn, vha, 0x706d,
6534 "Unable to read SFP data (%x/%x/%x).\n", rval,
6535 addr, offset);
6536
6537 return rval;
6538 }
6539
6540 if (buf && (c < count)) {
6541 u16 sz;
6542
6543 if ((count - c) >= SFP_BLOCK_SIZE)
6544 sz = SFP_BLOCK_SIZE;
6545 else
6546 sz = count - c;
6547
6548 memcpy(buf, sfp_data, sz);
6549 buf += SFP_BLOCK_SIZE;
6550 c += sz;
6551 }
6552 phys_addr += SFP_BLOCK_SIZE;
6553 sfp_data += SFP_BLOCK_SIZE;
6554 offset += SFP_BLOCK_SIZE;
6555 }
6556
6557 return rval;
6558}
Quinn Tran94d83e32017-12-28 12:33:23 -08006559
6560int qla24xx_res_count_wait(struct scsi_qla_host *vha,
6561 uint16_t *out_mb, int out_mb_sz)
6562{
6563 int rval = QLA_FUNCTION_FAILED;
6564 mbx_cmd_t mc;
6565
6566 if (!vha->hw->flags.fw_started)
6567 goto done;
6568
6569 memset(&mc, 0, sizeof(mc));
6570 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
6571
6572 rval = qla24xx_send_mb_cmd(vha, &mc);
6573 if (rval != QLA_SUCCESS) {
6574 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6575 "%s: fail\n", __func__);
6576 } else {
6577 if (out_mb_sz <= SIZEOF_IOCB_MB_REG)
6578 memcpy(out_mb, mc.mb, out_mb_sz);
6579 else
6580 memcpy(out_mb, mc.mb, SIZEOF_IOCB_MB_REG);
6581
6582 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6583 "%s: done\n", __func__);
6584 }
6585done:
6586 return rval;
6587}
Michael Hernandez3f006ac2019-03-12 11:08:22 -07006588
6589int qla28xx_secure_flash_update(scsi_qla_host_t *vha, uint16_t opts,
6590 uint16_t region, uint32_t len, dma_addr_t sfub_dma_addr,
6591 uint32_t sfub_len)
6592{
6593 int rval;
6594 mbx_cmd_t mc;
6595 mbx_cmd_t *mcp = &mc;
6596
6597 mcp->mb[0] = MBC_SECURE_FLASH_UPDATE;
6598 mcp->mb[1] = opts;
6599 mcp->mb[2] = region;
6600 mcp->mb[3] = MSW(len);
6601 mcp->mb[4] = LSW(len);
6602 mcp->mb[5] = MSW(sfub_dma_addr);
6603 mcp->mb[6] = LSW(sfub_dma_addr);
6604 mcp->mb[7] = MSW(MSD(sfub_dma_addr));
6605 mcp->mb[8] = LSW(MSD(sfub_dma_addr));
6606 mcp->mb[9] = sfub_len;
6607 mcp->out_mb =
6608 MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6609 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6610 mcp->tov = MBX_TOV_SECONDS;
6611 mcp->flags = 0;
6612 rval = qla2x00_mailbox_command(vha, mcp);
6613
6614 if (rval != QLA_SUCCESS) {
6615 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s(%ld): failed rval 0x%x, %x %x %x",
6616 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1],
6617 mcp->mb[2]);
6618 }
6619
6620 return rval;
6621}
6622
6623int qla2xxx_write_remote_register(scsi_qla_host_t *vha, uint32_t addr,
6624 uint32_t data)
6625{
6626 int rval;
6627 mbx_cmd_t mc;
6628 mbx_cmd_t *mcp = &mc;
6629
6630 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
6631 "Entered %s.\n", __func__);
6632
6633 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
6634 mcp->mb[1] = LSW(addr);
6635 mcp->mb[2] = MSW(addr);
6636 mcp->mb[3] = LSW(data);
6637 mcp->mb[4] = MSW(data);
6638 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6639 mcp->in_mb = MBX_1|MBX_0;
6640 mcp->tov = MBX_TOV_SECONDS;
6641 mcp->flags = 0;
6642 rval = qla2x00_mailbox_command(vha, mcp);
6643
6644 if (rval != QLA_SUCCESS) {
6645 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
6646 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6647 } else {
6648 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
6649 "Done %s.\n", __func__);
6650 }
6651
6652 return rval;
6653}
6654
6655int qla2xxx_read_remote_register(scsi_qla_host_t *vha, uint32_t addr,
6656 uint32_t *data)
6657{
6658 int rval;
6659 mbx_cmd_t mc;
6660 mbx_cmd_t *mcp = &mc;
6661
6662 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
6663 "Entered %s.\n", __func__);
6664
6665 mcp->mb[0] = MBC_READ_REMOTE_REG;
6666 mcp->mb[1] = LSW(addr);
6667 mcp->mb[2] = MSW(addr);
6668 mcp->out_mb = MBX_2|MBX_1|MBX_0;
6669 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
6670 mcp->tov = MBX_TOV_SECONDS;
6671 mcp->flags = 0;
6672 rval = qla2x00_mailbox_command(vha, mcp);
6673
6674 *data = (uint32_t)((((uint32_t)mcp->mb[4]) << 16) | mcp->mb[3]);
6675
6676 if (rval != QLA_SUCCESS) {
6677 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
6678 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6679 } else {
6680 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
6681 "Done %s.\n", __func__);
6682 }
6683
6684 return rval;
6685}