blob: 7ca3b762b2e4bbba352ca2f9d216c502514008c4 [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
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400397 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Load return mailbox registers. */
401 iptr2 = mcp->mb;
402 iptr = (uint16_t *)&ha->mailbox_out[0];
403 mboxes = mcp->in_mb;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700404
405 ql_dbg(ql_dbg_mbx, vha, 0x1113,
406 "Mailbox registers (IN):\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700408 if (mboxes & BIT_0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 *iptr2 = *iptr;
Joe Carnuccio0e31a2c2013-08-23 07:25:37 -0700410 ql_dbg(ql_dbg_mbx, vha, 0x1114,
411 "mbox[%d]->0x%04x\n", cnt, *iptr2);
412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414 mboxes >>= 1;
415 iptr2++;
416 iptr++;
417 }
418 } else {
419
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800420 uint16_t mb[8];
421 uint32_t ictrl, host_status, hccr;
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400422 uint16_t w;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700423
Andrew Vasqueze4289242007-07-19 15:05:56 -0700424 if (IS_FWI2_CAPABLE(ha)) {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800425 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
426 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
427 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
428 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
429 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700430 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800431 host_status = RD_REG_DWORD(&reg->isp24.host_status);
432 hccr = RD_REG_DWORD(&reg->isp24.hccr);
433
Quinn Tran83548fe2017-06-02 09:12:01 -0700434 ql_log(ql_log_warn, vha, 0xd04c,
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800435 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
436 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
437 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
438 mb[7], host_status, hccr);
439
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700440 } else {
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800441 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700442 ictrl = RD_REG_WORD(&reg->isp.ictrl);
Quinn Tran8d3c9c22016-12-23 18:06:09 -0800443 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
444 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
445 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700446 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800447 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400449 /* Capture FW dump only, if PCI device active */
450 if (!pci_channel_offline(vha->hw->pdev)) {
451 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
Quinn Tranb2000802018-08-02 13:16:52 -0700452 if (w == 0xffff || ictrl == 0xffffffff ||
453 (chip_reset != ha->chip_reset)) {
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400454 /* This is special case if there is unload
455 * of driver happening and if PCI device go
456 * into bad state due to PCI error condition
457 * then only PCI ERR flag would be set.
458 * we will do premature exit for above case.
459 */
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700460 spin_lock_irqsave(&ha->hardware_lock, flags);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400461 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700462 spin_unlock_irqrestore(&ha->hardware_lock,
463 flags);
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400464 rval = QLA_FUNCTION_TIMEOUT;
465 goto premature_exit;
466 }
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800467
Sawan Chandak783e0dc2016-07-06 11:14:25 -0400468 /* Attempt to capture firmware dump for further
469 * anallysis of the current formware state. we do not
470 * need to do this if we are intentionally generating
471 * a dump
472 */
473 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
474 ha->isp_ops->fw_dump(vha, 0);
475 rval = QLA_FUNCTION_TIMEOUT;
476 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700478 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 ha->flags.mbox_busy = 0;
Quinn Tranb6faaaf2018-09-04 14:19:09 -0700480 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 /* Clean up */
483 ha->mcp = NULL;
484
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800485 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800486 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700487 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800490 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700493 if (rval == QLA_FUNCTION_TIMEOUT &&
494 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800495 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
496 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800498 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700499 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700500
501 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
502 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
503 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800504 if (IS_QLA82XX(ha)) {
505 ql_dbg(ql_dbg_mbx, vha, 0x112a,
506 "disabling pause transmit on port "
507 "0 & 1.\n");
508 qla82xx_wr_32(ha,
509 QLA82XX_CRB_NIU + 0x98,
510 CRB_NIU_XG_PAUSE_CTL_P0|
511 CRB_NIU_XG_PAUSE_CTL_P1);
512 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700513 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400514 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800515 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
516 "abort.\n", command, mcp->mb[0],
517 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700518 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
519 qla2xxx_wake_dpc(vha);
520 }
Quinn Tran710bc782018-09-26 22:05:16 -0700521 } else if (current == ha->dpc_thread) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800523 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700524 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700526 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
527 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
528 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800529 if (IS_QLA82XX(ha)) {
530 ql_dbg(ql_dbg_mbx, vha, 0x112b,
531 "disabling pause transmit on port "
532 "0 & 1.\n");
533 qla82xx_wr_32(ha,
534 QLA82XX_CRB_NIU + 0x98,
535 CRB_NIU_XG_PAUSE_CTL_P0|
536 CRB_NIU_XG_PAUSE_CTL_P1);
537 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700538 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400539 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800540 "mb[0]=0x%x. Scheduling ISP abort ",
541 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700542 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
543 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800544 /* Allow next mbx cmd to come in. */
545 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700546 if (ha->isp_ops->abort_isp(vha)) {
547 /* Failed. retry later. */
548 set_bit(ISP_ABORT_NEEDED,
549 &vha->dpc_flags);
550 }
551 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800552 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700553 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800554 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557 }
558
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700559premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800561 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Giridhar Malavalid3360962012-02-09 11:14:10 -0800563mbx_done:
Quinn Tranb2000802018-08-02 13:16:52 -0700564 if (rval == QLA_ABORTED) {
565 ql_log(ql_log_info, vha, 0xd035,
566 "Chip Reset in progress. Purging Mbox cmd=0x%x.\n",
567 mcp->mb[0]);
568 } else if (rval) {
Joe Carnuccio050dc762017-08-23 15:05:14 -0700569 if (ql2xextended_error_logging & (ql_dbg_disc|ql_dbg_mbx)) {
570 pr_warn("%s [%s]-%04x:%ld: **** Failed", QL_MSGHDR,
571 dev_name(&ha->pdev->dev), 0x1020+0x800,
572 vha->host_no);
573 mboxes = mcp->in_mb;
574 cnt = 4;
575 for (i = 0; i < ha->mbx_count && cnt; i++, mboxes >>= 1)
576 if (mboxes & BIT_0) {
577 printk(" mb[%u]=%x", i, mcp->mb[i]);
578 cnt--;
579 }
580 pr_warn(" cmd=%x ****\n", command);
581 }
Meelis Roosf7e59e92018-03-08 15:44:07 +0200582 if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha))) {
583 ql_dbg(ql_dbg_mbx, vha, 0x1198,
584 "host_status=%#x intr_ctrl=%#x intr_status=%#x\n",
585 RD_REG_DWORD(&reg->isp24.host_status),
586 RD_REG_DWORD(&reg->isp24.ictrl),
587 RD_REG_DWORD(&reg->isp24.istatus));
588 } else {
589 ql_dbg(ql_dbg_mbx, vha, 0x1206,
590 "ctrl_status=%#x ictrl=%#x istatus=%#x\n",
591 RD_REG_WORD(&reg->isp.ctrl_status),
592 RD_REG_WORD(&reg->isp.ictrl),
593 RD_REG_WORD(&reg->isp.istatus));
594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700596 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
598
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return rval;
600}
601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800603qla2x00_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 -0800604 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
606 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800607 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 mbx_cmd_t mc;
609 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400611 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
612 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Andrew Vasqueze4289242007-07-19 15:05:56 -0700614 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800615 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
616 mcp->mb[8] = MSW(risc_addr);
617 mcp->out_mb = MBX_8|MBX_0;
618 } else {
619 mcp->mb[0] = MBC_LOAD_RISC_RAM;
620 mcp->out_mb = MBX_0;
621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 mcp->mb[1] = LSW(risc_addr);
623 mcp->mb[2] = MSW(req_dma);
624 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 mcp->mb[6] = MSW(MSD(req_dma));
626 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800627 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700628 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700629 mcp->mb[4] = MSW(risc_code_size);
630 mcp->mb[5] = LSW(risc_code_size);
631 mcp->out_mb |= MBX_5|MBX_4;
632 } else {
633 mcp->mb[4] = LSW(risc_code_size);
634 mcp->out_mb |= MBX_4;
635 }
636
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700638 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800640 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700643 ql_dbg(ql_dbg_mbx, vha, 0x1023,
644 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400646 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
647 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649
650 return rval;
651}
652
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700653#define EXTENDED_BB_CREDITS BIT_0
Duane Grigsbye84067d2017-06-21 13:48:43 -0700654#define NVME_ENABLE_FLAG BIT_3
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700655static inline uint16_t qla25xx_set_sfp_lr_dist(struct qla_hw_data *ha)
656{
657 uint16_t mb4 = BIT_0;
658
659 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
660 mb4 |= ha->long_range_distance << LR_DIST_FW_POS;
661
662 return mb4;
663}
664
665static inline uint16_t qla25xx_set_nvr_lr_dist(struct qla_hw_data *ha)
666{
667 uint16_t mb4 = BIT_0;
668
669 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
670 struct nvram_81xx *nv = ha->nvram;
671
672 mb4 |= LR_DIST_FW_FIELD(nv->enhanced_features);
673 }
674
675 return mb4;
676}
Duane Grigsbye84067d2017-06-21 13:48:43 -0700677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678/*
679 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700680 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 *
682 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700683 * ha = adapter block pointer.
684 * TARGET_QUEUE_LOCK must be released.
685 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 *
687 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700688 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 *
690 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700691 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 */
693int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800694qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695{
696 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800697 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 mbx_cmd_t mc;
699 mbx_cmd_t *mcp = &mc;
700
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400701 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
702 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
704 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700705 mcp->out_mb = MBX_0;
706 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700707 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700708 mcp->mb[1] = MSW(risc_addr);
709 mcp->mb[2] = LSW(risc_addr);
710 mcp->mb[3] = 0;
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700711 mcp->mb[4] = 0;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700712 ha->flags.using_lr_setting = 0;
Chad Dupuisf73cb692014-02-26 04:15:06 -0500713 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
714 IS_QLA27XX(ha)) {
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700715 if (ql2xautodetectsfp) {
716 if (ha->flags.detected_lr_sfp) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700717 mcp->mb[4] |=
718 qla25xx_set_sfp_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700719 ha->flags.using_lr_setting = 1;
720 }
721 } else {
722 struct nvram_81xx *nv = ha->nvram;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700723 /* set LR distance if specified in nvram */
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700724 if (nv->enhanced_features &
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700725 NEF_LR_DIST_ENABLE) {
726 mcp->mb[4] |=
727 qla25xx_set_nvr_lr_dist(ha);
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700728 ha->flags.using_lr_setting = 1;
729 }
730 }
Quinn Trane4e3a2c2017-08-23 15:05:07 -0700731 }
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500732
Duane Grigsbye84067d2017-06-21 13:48:43 -0700733 if (ql2xnvmeenable && IS_QLA27XX(ha))
734 mcp->mb[4] |= NVME_ENABLE_FLAG;
735
Sawan Chandak92d44082017-08-23 15:05:16 -0700736 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
737 struct nvram_81xx *nv = ha->nvram;
738 /* set minimum speed if specified in nvram */
739 if (nv->min_link_speed >= 2 &&
740 nv->min_link_speed <= 5) {
741 mcp->mb[4] |= BIT_4;
742 mcp->mb[11] = nv->min_link_speed;
743 mcp->out_mb |= MBX_11;
744 mcp->in_mb |= BIT_5;
745 vha->min_link_speed_feat = nv->min_link_speed;
746 }
747 }
748
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500749 if (ha->flags.exlogins_enabled)
750 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
751
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500752 if (ha->flags.exchoffld_enabled)
753 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
754
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700755 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700756 mcp->in_mb |= MBX_3 | MBX_2 | MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700757 } else {
758 mcp->mb[1] = LSW(risc_addr);
759 mcp->out_mb |= MBX_1;
760 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
761 mcp->mb[2] = 0;
762 mcp->out_mb |= MBX_2;
763 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765
Ravi Anandb93480e2008-04-03 13:13:25 -0700766 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800768 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700770 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700771 ql_dbg(ql_dbg_mbx, vha, 0x1026,
772 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700773 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700774 if (IS_FWI2_CAPABLE(ha)) {
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700775 ha->fw_ability_mask = mcp->mb[3] << 16 | mcp->mb[2];
776 ql_dbg(ql_dbg_mbx, vha, 0x119a,
777 "fw_ability_mask=%x.\n", ha->fw_ability_mask);
Sawan Chandak92d44082017-08-23 15:05:16 -0700778 ql_dbg(ql_dbg_mbx, vha, 0x1027,
779 "exchanges=%x.\n", mcp->mb[1]);
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700780 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
781 ha->max_speed_sup = mcp->mb[2] & BIT_0;
Sawan Chandak92d44082017-08-23 15:05:16 -0700782 ql_dbg(ql_dbg_mbx, vha, 0x119b,
783 "Maximum speed supported=%s.\n",
784 ha->max_speed_sup ? "32Gps" : "16Gps");
785 if (vha->min_link_speed_feat) {
786 ha->min_link_speed = mcp->mb[5];
787 ql_dbg(ql_dbg_mbx, vha, 0x119c,
788 "Minimum speed set=%s.\n",
789 mcp->mb[5] == 5 ? "32Gps" :
790 mcp->mb[5] == 4 ? "16Gps" :
791 mcp->mb[5] == 3 ? "8Gps" :
792 mcp->mb[5] == 2 ? "4Gps" :
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700793 "unknown");
Sawan Chandak92d44082017-08-23 15:05:16 -0700794 }
795 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700796 }
Joe Carnuccio1f4c7c32017-08-23 15:05:17 -0700797 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
798 "Done.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 return rval;
802}
803
804/*
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500805 * qla_get_exlogin_status
806 * Get extended login status
807 * uses the memory offload control/status Mailbox
808 *
809 * Input:
810 * ha: adapter state pointer.
811 * fwopt: firmware options
812 *
813 * Returns:
814 * qla2x00 local function status
815 *
816 * Context:
817 * Kernel context.
818 */
819#define FETCH_XLOGINS_STAT 0x8
820int
821qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
822 uint16_t *ex_logins_cnt)
823{
824 int rval;
825 mbx_cmd_t mc;
826 mbx_cmd_t *mcp = &mc;
827
828 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
829 "Entered %s\n", __func__);
830
831 memset(mcp->mb, 0 , sizeof(mcp->mb));
832 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
833 mcp->mb[1] = FETCH_XLOGINS_STAT;
834 mcp->out_mb = MBX_1|MBX_0;
835 mcp->in_mb = MBX_10|MBX_4|MBX_0;
836 mcp->tov = MBX_TOV_SECONDS;
837 mcp->flags = 0;
838
839 rval = qla2x00_mailbox_command(vha, mcp);
840 if (rval != QLA_SUCCESS) {
841 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
842 } else {
843 *buf_sz = mcp->mb[4];
844 *ex_logins_cnt = mcp->mb[10];
845
846 ql_log(ql_log_info, vha, 0x1190,
847 "buffer size 0x%x, exchange login count=%d\n",
848 mcp->mb[4], mcp->mb[10]);
849
850 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
851 "Done %s.\n", __func__);
852 }
853
854 return rval;
855}
856
857/*
858 * qla_set_exlogin_mem_cfg
859 * set extended login memory configuration
860 * Mbx needs to be issues before init_cb is set
861 *
862 * Input:
863 * ha: adapter state pointer.
864 * buffer: buffer pointer
865 * phys_addr: physical address of buffer
866 * size: size of buffer
867 * TARGET_QUEUE_LOCK must be released
868 * ADAPTER_STATE_LOCK must be release
869 *
870 * Returns:
871 * qla2x00 local funxtion status code.
872 *
873 * Context:
874 * Kernel context.
875 */
876#define CONFIG_XLOGINS_MEM 0x3
877int
878qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
879{
880 int rval;
881 mbx_cmd_t mc;
882 mbx_cmd_t *mcp = &mc;
883 struct qla_hw_data *ha = vha->hw;
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500884
885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
886 "Entered %s.\n", __func__);
887
888 memset(mcp->mb, 0 , sizeof(mcp->mb));
889 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
890 mcp->mb[1] = CONFIG_XLOGINS_MEM;
891 mcp->mb[2] = MSW(phys_addr);
892 mcp->mb[3] = LSW(phys_addr);
893 mcp->mb[6] = MSW(MSD(phys_addr));
894 mcp->mb[7] = LSW(MSD(phys_addr));
895 mcp->mb[8] = MSW(ha->exlogin_size);
896 mcp->mb[9] = LSW(ha->exlogin_size);
897 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
898 mcp->in_mb = MBX_11|MBX_0;
899 mcp->tov = MBX_TOV_SECONDS;
900 mcp->flags = 0;
901 rval = qla2x00_mailbox_command(vha, mcp);
902 if (rval != QLA_SUCCESS) {
903 /*EMPTY*/
904 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
905 } else {
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -0500906 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
907 "Done %s.\n", __func__);
908 }
909
910 return rval;
911}
912
913/*
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500914 * qla_get_exchoffld_status
915 * Get exchange offload status
916 * uses the memory offload control/status Mailbox
917 *
918 * Input:
919 * ha: adapter state pointer.
920 * fwopt: firmware options
921 *
922 * Returns:
923 * qla2x00 local function status
924 *
925 * Context:
926 * Kernel context.
927 */
928#define FETCH_XCHOFFLD_STAT 0x2
929int
930qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
931 uint16_t *ex_logins_cnt)
932{
933 int rval;
934 mbx_cmd_t mc;
935 mbx_cmd_t *mcp = &mc;
936
937 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
938 "Entered %s\n", __func__);
939
940 memset(mcp->mb, 0 , sizeof(mcp->mb));
941 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
942 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
943 mcp->out_mb = MBX_1|MBX_0;
944 mcp->in_mb = MBX_10|MBX_4|MBX_0;
945 mcp->tov = MBX_TOV_SECONDS;
946 mcp->flags = 0;
947
948 rval = qla2x00_mailbox_command(vha, mcp);
949 if (rval != QLA_SUCCESS) {
950 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
951 } else {
952 *buf_sz = mcp->mb[4];
953 *ex_logins_cnt = mcp->mb[10];
954
955 ql_log(ql_log_info, vha, 0x118e,
956 "buffer size 0x%x, exchange offload count=%d\n",
957 mcp->mb[4], mcp->mb[10]);
958
959 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
960 "Done %s.\n", __func__);
961 }
962
963 return rval;
964}
965
966/*
967 * qla_set_exchoffld_mem_cfg
968 * Set exchange offload memory configuration
969 * Mbx needs to be issues before init_cb is set
970 *
971 * Input:
972 * ha: adapter state pointer.
973 * buffer: buffer pointer
974 * phys_addr: physical address of buffer
975 * size: size of buffer
976 * TARGET_QUEUE_LOCK must be released
977 * ADAPTER_STATE_LOCK must be release
978 *
979 * Returns:
980 * qla2x00 local funxtion status code.
981 *
982 * Context:
983 * Kernel context.
984 */
985#define CONFIG_XCHOFFLD_MEM 0x3
986int
Quinn Tran99e1b682017-06-02 09:12:03 -0700987qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha)
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -0500988{
989 int rval;
990 mbx_cmd_t mc;
991 mbx_cmd_t *mcp = &mc;
992 struct qla_hw_data *ha = vha->hw;
993
994 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
995 "Entered %s.\n", __func__);
996
997 memset(mcp->mb, 0 , sizeof(mcp->mb));
998 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
999 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
Quinn Tran99e1b682017-06-02 09:12:03 -07001000 mcp->mb[2] = MSW(ha->exchoffld_buf_dma);
1001 mcp->mb[3] = LSW(ha->exchoffld_buf_dma);
1002 mcp->mb[6] = MSW(MSD(ha->exchoffld_buf_dma));
1003 mcp->mb[7] = LSW(MSD(ha->exchoffld_buf_dma));
1004 mcp->mb[8] = MSW(ha->exchoffld_size);
1005 mcp->mb[9] = LSW(ha->exchoffld_size);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001006 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1007 mcp->in_mb = MBX_11|MBX_0;
1008 mcp->tov = MBX_TOV_SECONDS;
1009 mcp->flags = 0;
1010 rval = qla2x00_mailbox_command(vha, mcp);
1011 if (rval != QLA_SUCCESS) {
1012 /*EMPTY*/
1013 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
1014 } else {
1015 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
1016 "Done %s.\n", __func__);
1017 }
1018
1019 return rval;
1020}
1021
1022/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 * qla2x00_get_fw_version
1024 * Get firmware version.
1025 *
1026 * Input:
1027 * ha: adapter state pointer.
1028 * major: pointer for major number.
1029 * minor: pointer for minor number.
1030 * subminor: pointer for subminor number.
1031 *
1032 * Returns:
1033 * qla2x00 local function return status code.
1034 *
1035 * Context:
1036 * Kernel context.
1037 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001038int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001039qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040{
1041 int rval;
1042 mbx_cmd_t mc;
1043 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001044 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001046 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
1047 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
1049 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
1050 mcp->out_mb = MBX_0;
1051 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001052 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -07001053 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -04001054 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001055 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001056 if (IS_QLA27XX(ha))
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001057 mcp->in_mb |=
1058 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
1059 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
Sawan Chandak03aa8682015-08-04 13:37:59 -04001060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001062 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001063 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001064 if (rval != QLA_SUCCESS)
1065 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
1067 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001068 ha->fw_major_version = mcp->mb[1];
1069 ha->fw_minor_version = mcp->mb[2];
1070 ha->fw_subminor_version = mcp->mb[3];
1071 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001073 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001075 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
Sawan Chandak03aa8682015-08-04 13:37:59 -04001076
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001077 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001078 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1079 ha->mpi_version[1] = mcp->mb[11] >> 8;
1080 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1081 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
1082 ha->phy_version[0] = mcp->mb[8] & 0xff;
1083 ha->phy_version[1] = mcp->mb[9] >> 8;
1084 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001085 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001086
Saurav Kashyap81178772012-08-22 14:21:04 -04001087 if (IS_FWI2_CAPABLE(ha)) {
1088 ha->fw_attributes_h = mcp->mb[15];
1089 ha->fw_attributes_ext[0] = mcp->mb[16];
1090 ha->fw_attributes_ext[1] = mcp->mb[17];
1091 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
1092 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
1093 __func__, mcp->mb[15], mcp->mb[6]);
1094 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
1095 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
1096 __func__, mcp->mb[17], mcp->mb[16]);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001097
Himanshu Madhanib0d6cab2015-12-17 14:56:56 -05001098 if (ha->fw_attributes_h & 0x4)
1099 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
1100 "%s: Firmware supports Extended Login 0x%x\n",
1101 __func__, ha->fw_attributes_h);
Himanshu Madhani2f56a7f2015-12-17 14:56:57 -05001102
1103 if (ha->fw_attributes_h & 0x8)
1104 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
1105 "%s: Firmware supports Exchange Offload 0x%x\n",
1106 __func__, ha->fw_attributes_h);
Duane Grigsbye84067d2017-06-21 13:48:43 -07001107
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07001108 /*
1109 * FW supports nvme and driver load parameter requested nvme.
1110 * BIT 26 of fw_attributes indicates NVMe support.
1111 */
Giridhar Malavali171e4902019-01-30 09:50:44 -08001112 if ((ha->fw_attributes_h &
1113 (FW_ATTR_H_NVME | FW_ATTR_H_NVME_UPDATED)) &&
1114 ql2xnvmeenable) {
Darren Trapp03aaa892019-02-15 14:37:13 -08001115 if (ha->fw_attributes_h & FW_ATTR_H_NVME_FBURST)
1116 vha->flags.nvme_first_burst = 1;
1117
Duane Grigsbye84067d2017-06-21 13:48:43 -07001118 vha->flags.nvme_enabled = 1;
Darren Trapp1cbc0ef2018-03-20 23:09:37 -07001119 ql_log(ql_log_info, vha, 0xd302,
1120 "%s: FC-NVMe is Enabled (0x%x)\n",
1121 __func__, ha->fw_attributes_h);
1122 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001123 }
Sawan Chandak03aa8682015-08-04 13:37:59 -04001124
Chad Dupuisf73cb692014-02-26 04:15:06 -05001125 if (IS_QLA27XX(ha)) {
Sawan Chandak03aa8682015-08-04 13:37:59 -04001126 ha->mpi_version[0] = mcp->mb[10] & 0xff;
1127 ha->mpi_version[1] = mcp->mb[11] >> 8;
1128 ha->mpi_version[2] = mcp->mb[11] & 0xff;
1129 ha->pep_version[0] = mcp->mb[13] & 0xff;
1130 ha->pep_version[1] = mcp->mb[14] >> 8;
1131 ha->pep_version[2] = mcp->mb[14] & 0xff;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001132 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
1133 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
Joe Carnuccioad1ef172016-07-06 11:14:18 -04001134 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
1135 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
Chad Dupuisf73cb692014-02-26 04:15:06 -05001136 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001137
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001138failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 if (rval != QLA_SUCCESS) {
1140 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001141 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 } else {
1143 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001144 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
1145 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001147 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148}
1149
1150/*
1151 * qla2x00_get_fw_options
1152 * Set firmware options.
1153 *
1154 * Input:
1155 * ha = adapter block pointer.
1156 * fwopt = pointer for firmware options.
1157 *
1158 * Returns:
1159 * qla2x00 local function return status code.
1160 *
1161 * Context:
1162 * Kernel context.
1163 */
1164int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001165qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166{
1167 int rval;
1168 mbx_cmd_t mc;
1169 mbx_cmd_t *mcp = &mc;
1170
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001171 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
1172 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
1174 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
1175 mcp->out_mb = MBX_0;
1176 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001177 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001179 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
1181 if (rval != QLA_SUCCESS) {
1182 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001183 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001185 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 fwopts[1] = mcp->mb[1];
1187 fwopts[2] = mcp->mb[2];
1188 fwopts[3] = mcp->mb[3];
1189
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001190 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1191 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193
1194 return rval;
1195}
1196
1197
1198/*
1199 * qla2x00_set_fw_options
1200 * Set firmware options.
1201 *
1202 * Input:
1203 * ha = adapter block pointer.
1204 * fwopt = pointer for firmware options.
1205 *
1206 * Returns:
1207 * qla2x00 local function return status code.
1208 *
1209 * Context:
1210 * Kernel context.
1211 */
1212int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001213qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214{
1215 int rval;
1216 mbx_cmd_t mc;
1217 mbx_cmd_t *mcp = &mc;
1218
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001219 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1220 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1223 mcp->mb[1] = fwopts[1];
1224 mcp->mb[2] = fwopts[2];
1225 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001226 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001228 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001229 mcp->in_mb |= MBX_1;
Quinn Tran2da52732017-06-02 09:12:05 -07001230 mcp->mb[10] = fwopts[10];
1231 mcp->out_mb |= MBX_10;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001232 } else {
1233 mcp->mb[10] = fwopts[10];
1234 mcp->mb[11] = fwopts[11];
1235 mcp->mb[12] = 0; /* Undocumented, but used */
1236 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1237 }
Ravi Anandb93480e2008-04-03 13:13:25 -07001238 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001240 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001242 fwopts[0] = mcp->mb[0];
1243
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 if (rval != QLA_SUCCESS) {
1245 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001246 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1247 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 } else {
1249 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001250 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1251 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 }
1253
1254 return rval;
1255}
1256
1257/*
1258 * qla2x00_mbx_reg_test
1259 * Mailbox register wrap test.
1260 *
1261 * Input:
1262 * ha = adapter block pointer.
1263 * TARGET_QUEUE_LOCK must be released.
1264 * ADAPTER_STATE_LOCK must be released.
1265 *
1266 * Returns:
1267 * qla2x00 local function return status code.
1268 *
1269 * Context:
1270 * Kernel context.
1271 */
1272int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001273qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274{
1275 int rval;
1276 mbx_cmd_t mc;
1277 mbx_cmd_t *mcp = &mc;
1278
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001279 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1280 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1283 mcp->mb[1] = 0xAAAA;
1284 mcp->mb[2] = 0x5555;
1285 mcp->mb[3] = 0xAA55;
1286 mcp->mb[4] = 0x55AA;
1287 mcp->mb[5] = 0xA5A5;
1288 mcp->mb[6] = 0x5A5A;
1289 mcp->mb[7] = 0x2525;
1290 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1291 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 -07001292 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001294 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 if (rval == QLA_SUCCESS) {
1297 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1298 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1299 rval = QLA_FUNCTION_FAILED;
1300 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1301 mcp->mb[7] != 0x2525)
1302 rval = QLA_FUNCTION_FAILED;
1303 }
1304
1305 if (rval != QLA_SUCCESS) {
1306 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001307 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 } else {
1309 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001310 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1311 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313
1314 return rval;
1315}
1316
1317/*
1318 * qla2x00_verify_checksum
1319 * Verify firmware checksum.
1320 *
1321 * Input:
1322 * ha = adapter block pointer.
1323 * TARGET_QUEUE_LOCK must be released.
1324 * ADAPTER_STATE_LOCK must be released.
1325 *
1326 * Returns:
1327 * qla2x00 local function return status code.
1328 *
1329 * Context:
1330 * Kernel context.
1331 */
1332int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001333qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334{
1335 int rval;
1336 mbx_cmd_t mc;
1337 mbx_cmd_t *mcp = &mc;
1338
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001339 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1340 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341
1342 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001343 mcp->out_mb = MBX_0;
1344 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001345 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001346 mcp->mb[1] = MSW(risc_addr);
1347 mcp->mb[2] = LSW(risc_addr);
1348 mcp->out_mb |= MBX_2|MBX_1;
1349 mcp->in_mb |= MBX_2|MBX_1;
1350 } else {
1351 mcp->mb[1] = LSW(risc_addr);
1352 mcp->out_mb |= MBX_1;
1353 mcp->in_mb |= MBX_1;
1354 }
1355
Ravi Anandb93480e2008-04-03 13:13:25 -07001356 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001358 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001361 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1362 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1363 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001365 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1366 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 }
1368
1369 return rval;
1370}
1371
1372/*
1373 * qla2x00_issue_iocb
1374 * Issue IOCB using mailbox command
1375 *
1376 * Input:
1377 * ha = adapter state pointer.
1378 * buffer = buffer pointer.
1379 * phys_addr = physical address of buffer.
1380 * size = size of buffer.
1381 * TARGET_QUEUE_LOCK must be released.
1382 * ADAPTER_STATE_LOCK must be released.
1383 *
1384 * Returns:
1385 * qla2x00 local function return status code.
1386 *
1387 * Context:
1388 * Kernel context.
1389 */
Giridhar Malavali6e980162010-03-19 17:03:58 -07001390int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001391qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001392 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 int rval;
1395 mbx_cmd_t mc;
1396 mbx_cmd_t *mcp = &mc;
1397
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001398 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1399 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001400
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1402 mcp->mb[1] = 0;
1403 mcp->mb[2] = MSW(phys_addr);
1404 mcp->mb[3] = LSW(phys_addr);
1405 mcp->mb[6] = MSW(MSD(phys_addr));
1406 mcp->mb[7] = LSW(MSD(phys_addr));
1407 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1408 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001409 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001411 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413 if (rval != QLA_SUCCESS) {
1414 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001415 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -07001417 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1418
1419 /* Mask reserved bits. */
1420 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001421 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001422 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1423 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 }
1425
1426 return rval;
1427}
1428
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001429int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001430qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001431 size_t size)
1432{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001433 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001434 MBX_TOV_SECONDS);
1435}
1436
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437/*
1438 * qla2x00_abort_command
1439 * Abort command aborts a specified IOCB.
1440 *
1441 * Input:
1442 * ha = adapter block pointer.
1443 * sp = SB structure pointer.
1444 *
1445 * Returns:
1446 * qla2x00 local function return status code.
1447 *
1448 * Context:
1449 * Kernel context.
1450 */
1451int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001452qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453{
1454 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001456 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 mbx_cmd_t mc;
1458 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001459 fc_port_t *fcport = sp->fcport;
1460 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001461 struct qla_hw_data *ha = vha->hw;
Michael Hernandezd7459522016-12-12 14:40:07 -08001462 struct req_que *req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001463 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001465 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1466 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
Michael Hernandezd7459522016-12-12 14:40:07 -08001468 if (vha->flags.qpairs_available && sp->qpair)
1469 req = sp->qpair->req;
1470 else
1471 req = vha->req;
1472
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001473 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05001474 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001475 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 break;
1477 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07001478 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Chad Dupuis8d93f552013-01-30 03:34:37 -05001480 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 /* command not found */
1482 return QLA_FUNCTION_FAILED;
1483 }
1484
1485 mcp->mb[0] = MBC_ABORT_COMMAND;
1486 if (HAS_EXTENDED_IDS(ha))
1487 mcp->mb[1] = fcport->loop_id;
1488 else
1489 mcp->mb[1] = fcport->loop_id << 8;
1490 mcp->mb[2] = (uint16_t)handle;
1491 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -08001492 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1494 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001495 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001497 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498
1499 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001500 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001502 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1503 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 }
1505
1506 return rval;
1507}
1508
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001510qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511{
Andrew Vasquez523ec772008-04-03 13:13:24 -07001512 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 mbx_cmd_t mc;
1514 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001515 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001516 struct req_que *req;
1517 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001519 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001520
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001521 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1522 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001523
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001524 req = vha->hw->req_q_map[0];
1525 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001527 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001528 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 mcp->mb[1] = fcport->loop_id;
1530 mcp->mb[10] = 0;
1531 mcp->out_mb |= MBX_10;
1532 } else {
1533 mcp->mb[1] = fcport->loop_id << 8;
1534 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001535 mcp->mb[2] = vha->hw->loop_reset_delay;
1536 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001539 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001541 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001543 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1544 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001545 }
1546
1547 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001548 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1549 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001550 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001551 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1552 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001554 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1555 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001556 }
1557
1558 return rval;
1559}
1560
1561int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001562qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07001563{
1564 int rval, rval2;
1565 mbx_cmd_t mc;
1566 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001567 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001568 struct req_que *req;
1569 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001570
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001571 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001572
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001573 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1574 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001575
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001576 req = vha->hw->req_q_map[0];
1577 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001578 mcp->mb[0] = MBC_LUN_RESET;
1579 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001580 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001581 mcp->mb[1] = fcport->loop_id;
1582 else
1583 mcp->mb[1] = fcport->loop_id << 8;
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02001584 mcp->mb[2] = (u32)l;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001585 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001586 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001587
1588 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001589 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001590 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001591 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001592 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001593 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001594 }
1595
1596 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001597 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1598 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001599 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001600 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1601 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001602 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001603 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1604 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 }
1606
1607 return rval;
1608}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 * qla2x00_get_adapter_id
1612 * Get adapter ID and topology.
1613 *
1614 * Input:
1615 * ha = adapter block pointer.
1616 * id = pointer for loop ID.
1617 * al_pa = pointer for AL_PA.
1618 * area = pointer for area.
1619 * domain = pointer for domain.
1620 * top = pointer for topology.
1621 * TARGET_QUEUE_LOCK must be released.
1622 * ADAPTER_STATE_LOCK must be released.
1623 *
1624 * Returns:
1625 * qla2x00 local function return status code.
1626 *
1627 * Context:
1628 * Kernel context.
1629 */
1630int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001631qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001632 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
1634 int rval;
1635 mbx_cmd_t mc;
1636 mbx_cmd_t *mcp = &mc;
1637
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001638 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1639 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001642 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001643 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001644 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001645 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001646 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001647 if (IS_FWI2_CAPABLE(vha->hw))
1648 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
Sawan Chandak969a6192016-01-27 12:03:32 -05001649 if (IS_QLA27XX(vha->hw))
1650 mcp->in_mb |= MBX_15;
Ravi Anandb93480e2008-04-03 13:13:25 -07001651 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001653 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001654 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1655 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001656 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1657 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 /* Return data. */
1660 *id = mcp->mb[1];
1661 *al_pa = LSB(mcp->mb[2]);
1662 *area = MSB(mcp->mb[2]);
1663 *domain = LSB(mcp->mb[3]);
1664 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001665 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 if (rval != QLA_SUCCESS) {
1668 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001669 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001671 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1672 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001673
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001674 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001675 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1676 vha->fcoe_fcf_idx = mcp->mb[10];
1677 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1678 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1679 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1680 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1681 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1682 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1683 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001684 /* If FA-WWN supported */
Saurav Kashyapd6b9b422015-08-04 13:37:55 -04001685 if (IS_FAWWN_CAPABLE(vha->hw)) {
1686 if (mcp->mb[7] & BIT_14) {
1687 vha->port_name[0] = MSB(mcp->mb[16]);
1688 vha->port_name[1] = LSB(mcp->mb[16]);
1689 vha->port_name[2] = MSB(mcp->mb[17]);
1690 vha->port_name[3] = LSB(mcp->mb[17]);
1691 vha->port_name[4] = MSB(mcp->mb[18]);
1692 vha->port_name[5] = LSB(mcp->mb[18]);
1693 vha->port_name[6] = MSB(mcp->mb[19]);
1694 vha->port_name[7] = LSB(mcp->mb[19]);
1695 fc_host_port_name(vha->host) =
1696 wwn_to_u64(vha->port_name);
1697 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1698 "FA-WWN acquired %016llx\n",
1699 wwn_to_u64(vha->port_name));
1700 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04001701 }
Sawan Chandak969a6192016-01-27 12:03:32 -05001702
1703 if (IS_QLA27XX(vha->hw))
1704 vha->bbcr = mcp->mb[15];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 }
1706
1707 return rval;
1708}
1709
1710/*
1711 * qla2x00_get_retry_cnt
1712 * Get current firmware login retry count and delay.
1713 *
1714 * Input:
1715 * ha = adapter block pointer.
1716 * retry_cnt = pointer to login retry count.
1717 * tov = pointer to login timeout value.
1718 *
1719 * Returns:
1720 * qla2x00 local function return status code.
1721 *
1722 * Context:
1723 * Kernel context.
1724 */
1725int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001726qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 uint16_t *r_a_tov)
1728{
1729 int rval;
1730 uint16_t ratov;
1731 mbx_cmd_t mc;
1732 mbx_cmd_t *mcp = &mc;
1733
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001734 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1735 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736
1737 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1738 mcp->out_mb = MBX_0;
1739 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001740 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001742 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 if (rval != QLA_SUCCESS) {
1745 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001746 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1747 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 } else {
1749 /* Convert returned data and check our values. */
1750 *r_a_tov = mcp->mb[3] / 2;
1751 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1752 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1753 /* Update to the larger values */
1754 *retry_cnt = (uint8_t)mcp->mb[1];
1755 *tov = ratov;
1756 }
1757
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001758 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001759 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 }
1761
1762 return rval;
1763}
1764
1765/*
1766 * qla2x00_init_firmware
1767 * Initialize adapter firmware.
1768 *
1769 * Input:
1770 * ha = adapter block pointer.
1771 * dptr = Initialization control block pointer.
1772 * size = size of initialization control block.
1773 * TARGET_QUEUE_LOCK must be released.
1774 * ADAPTER_STATE_LOCK must be released.
1775 *
1776 * Returns:
1777 * qla2x00 local function return status code.
1778 *
1779 * Context:
1780 * Kernel context.
1781 */
1782int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001783qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784{
1785 int rval;
1786 mbx_cmd_t mc;
1787 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001788 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001790 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1791 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04001793 if (IS_P3P_TYPE(ha) && ql2xdbwr)
Bart Van Assche8dfa4b5a2015-07-09 07:24:50 -07001794 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
Giridhar Malavalia9083012010-04-12 17:59:55 -07001795 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1796
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001797 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001798 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1799 else
1800 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1801
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001802 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 mcp->mb[2] = MSW(ha->init_cb_dma);
1804 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1806 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001807 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Joe Carnuccio4ef21bd2013-10-30 03:38:11 -04001808 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001809 mcp->mb[1] = BIT_0;
1810 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1811 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1812 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1813 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1814 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1815 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1816 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001817 /* 1 and 2 should normally be captured. */
1818 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05001819 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001820 /* mb3 is additional info about the installed SFP. */
1821 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 mcp->buf_size = size;
1823 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001824 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001825 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 if (rval != QLA_SUCCESS) {
1828 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001829 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001830 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1831 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 } else {
Sawan Chandak92d44082017-08-23 15:05:16 -07001833 if (IS_QLA27XX(ha)) {
1834 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
1835 ql_dbg(ql_dbg_mbx, vha, 0x119d,
1836 "Invalid SFP/Validation Failed\n");
1837 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001838 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1839 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 }
1841
1842 return rval;
1843}
1844
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001845
1846/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 * qla2x00_get_port_database
1848 * Issue normal/enhanced get port database mailbox command
1849 * and copy device name as necessary.
1850 *
1851 * Input:
1852 * ha = adapter state pointer.
1853 * dev = structure pointer.
1854 * opt = enhanced cmd option byte.
1855 *
1856 * Returns:
1857 * qla2x00 local function return status code.
1858 *
1859 * Context:
1860 * Kernel context.
1861 */
1862int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001863qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864{
1865 int rval;
1866 mbx_cmd_t mc;
1867 mbx_cmd_t *mcp = &mc;
1868 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001869 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001871 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001873 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1874 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001876 pd24 = NULL;
Thomas Meyer08eb7f42017-09-21 08:15:26 +02001877 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001879 ql_log(ql_log_warn, vha, 0x1050,
1880 "Failed to allocate port database structure.\n");
Duane Grigsbyedd05de2017-10-13 09:34:06 -07001881 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 return QLA_MEMORY_ALLOC_FAILED;
1883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001885 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001886 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 mcp->mb[2] = MSW(pd_dma);
1889 mcp->mb[3] = LSW(pd_dma);
1890 mcp->mb[6] = MSW(MSD(pd_dma));
1891 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001892 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001893 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001895 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001896 mcp->mb[1] = fcport->loop_id;
1897 mcp->mb[10] = opt;
1898 mcp->out_mb |= MBX_10|MBX_1;
1899 mcp->in_mb |= MBX_1;
1900 } else if (HAS_EXTENDED_IDS(ha)) {
1901 mcp->mb[1] = fcport->loop_id;
1902 mcp->mb[10] = opt;
1903 mcp->out_mb |= MBX_10|MBX_1;
1904 } else {
1905 mcp->mb[1] = fcport->loop_id << 8 | opt;
1906 mcp->out_mb |= MBX_1;
1907 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001908 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1909 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 mcp->flags = MBX_DMA_IN;
1911 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001912 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 if (rval != QLA_SUCCESS)
1914 goto gpd_error_out;
1915
Andrew Vasqueze4289242007-07-19 15:05:56 -07001916 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001917 uint64_t zero = 0;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001918 u8 current_login_state, last_login_state;
1919
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001920 pd24 = (struct port_database_24xx *) pd;
1921
1922 /* Check for logged in state. */
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001923 if (fcport->fc4f_nvme) {
1924 current_login_state = pd24->current_login_state >> 4;
1925 last_login_state = pd24->last_login_state >> 4;
1926 } else {
1927 current_login_state = pd24->current_login_state & 0xf;
1928 last_login_state = pd24->last_login_state & 0xf;
1929 }
1930 fcport->current_login_state = pd24->current_login_state;
1931 fcport->last_login_state = pd24->last_login_state;
1932
1933 /* Check for logged in state. */
1934 if (current_login_state != PDS_PRLI_COMPLETE &&
1935 last_login_state != PDS_PRLI_COMPLETE) {
1936 ql_dbg(ql_dbg_mbx, vha, 0x119a,
1937 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
1938 current_login_state, last_login_state,
1939 fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001940 rval = QLA_FUNCTION_FAILED;
Duane Grigsbyc0c462c2017-10-13 09:34:05 -07001941
1942 if (!fcport->query)
1943 goto gpd_error_out;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001944 }
1945
Arun Easi0eba25d2012-02-09 11:15:58 -08001946 if (fcport->loop_id == FC_NO_LOOP_ID ||
1947 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1948 memcmp(fcport->port_name, pd24->port_name, 8))) {
1949 /* We lost the device mid way. */
1950 rval = QLA_NOT_LOGGED_IN;
1951 goto gpd_error_out;
1952 }
1953
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001954 /* Names are little-endian. */
1955 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1956 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1957
1958 /* Get port_id of device. */
1959 fcport->d_id.b.domain = pd24->port_id[0];
1960 fcport->d_id.b.area = pd24->port_id[1];
1961 fcport->d_id.b.al_pa = pd24->port_id[2];
1962 fcport->d_id.b.rsvd_1 = 0;
1963
1964 /* If not target must be initiator or unknown type. */
1965 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1966 fcport->port_type = FCT_INITIATOR;
1967 else
1968 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001969
1970 /* Passback COS information. */
1971 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1972 FC_COS_CLASS2 : FC_COS_CLASS3;
1973
1974 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1975 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001976 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001977 uint64_t zero = 0;
1978
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001979 /* Check for logged in state. */
1980 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1981 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001982 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1983 "Unable to verify login-state (%x/%x) - "
1984 "portid=%02x%02x%02x.\n", pd->master_state,
1985 pd->slave_state, fcport->d_id.b.domain,
1986 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001987 rval = QLA_FUNCTION_FAILED;
1988 goto gpd_error_out;
1989 }
1990
Arun Easi0eba25d2012-02-09 11:15:58 -08001991 if (fcport->loop_id == FC_NO_LOOP_ID ||
1992 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1993 memcmp(fcport->port_name, pd->port_name, 8))) {
1994 /* We lost the device mid way. */
1995 rval = QLA_NOT_LOGGED_IN;
1996 goto gpd_error_out;
1997 }
1998
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001999 /* Names are little-endian. */
2000 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
2001 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
2002
2003 /* Get port_id of device. */
2004 fcport->d_id.b.domain = pd->port_id[0];
2005 fcport->d_id.b.area = pd->port_id[3];
2006 fcport->d_id.b.al_pa = pd->port_id[2];
2007 fcport->d_id.b.rsvd_1 = 0;
2008
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002009 /* If not target must be initiator or unknown type. */
2010 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
2011 fcport->port_type = FCT_INITIATOR;
2012 else
2013 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002014
2015 /* Passback COS information. */
2016 fcport->supported_classes = (pd->options & BIT_4) ?
2017 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 }
2019
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020gpd_error_out:
2021 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07002022 fcport->query = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002025 ql_dbg(ql_dbg_mbx, vha, 0x1052,
2026 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
2027 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002029 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
2030 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 }
2032
2033 return rval;
2034}
2035
2036/*
2037 * qla2x00_get_firmware_state
2038 * Get adapter firmware state.
2039 *
2040 * Input:
2041 * ha = adapter block pointer.
2042 * dptr = pointer for firmware state.
2043 * TARGET_QUEUE_LOCK must be released.
2044 * ADAPTER_STATE_LOCK must be released.
2045 *
2046 * Returns:
2047 * qla2x00 local function return status code.
2048 *
2049 * Context:
2050 * Kernel context.
2051 */
2052int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002053qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054{
2055 int rval;
2056 mbx_cmd_t mc;
2057 mbx_cmd_t *mcp = &mc;
Sawan Chandak92d44082017-08-23 15:05:16 -07002058 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002060 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
2061 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
2064 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002065 if (IS_FWI2_CAPABLE(vha->hw))
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002066 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002067 else
2068 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002069 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002071 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002073 /* Return firmware states. */
2074 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002075 if (IS_FWI2_CAPABLE(vha->hw)) {
2076 states[1] = mcp->mb[2];
Joe Carnuccioec891462016-07-06 11:14:26 -04002077 states[2] = mcp->mb[3]; /* SFP info */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002078 states[3] = mcp->mb[4];
2079 states[4] = mcp->mb[5];
Joe Carnucciob5a340d2014-09-25 05:16:48 -04002080 states[5] = mcp->mb[6]; /* DPORT status */
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07002081 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 if (rval != QLA_SUCCESS) {
2084 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002085 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 } else {
Sawan Chandak92d44082017-08-23 15:05:16 -07002087 if (IS_QLA27XX(ha)) {
2088 if (mcp->mb[2] == 6 || mcp->mb[3] == 2)
2089 ql_dbg(ql_dbg_mbx, vha, 0x119e,
2090 "Invalid SFP/Validation Failed\n");
2091 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002092 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
2093 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 }
2095
2096 return rval;
2097}
2098
2099/*
2100 * qla2x00_get_port_name
2101 * Issue get port name mailbox command.
2102 * Returned name is in big endian format.
2103 *
2104 * Input:
2105 * ha = adapter block pointer.
2106 * loop_id = loop ID of device.
2107 * name = pointer for name.
2108 * TARGET_QUEUE_LOCK must be released.
2109 * ADAPTER_STATE_LOCK must be released.
2110 *
2111 * Returns:
2112 * qla2x00 local function return status code.
2113 *
2114 * Context:
2115 * Kernel context.
2116 */
2117int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002118qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 uint8_t opt)
2120{
2121 int rval;
2122 mbx_cmd_t mc;
2123 mbx_cmd_t *mcp = &mc;
2124
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002125 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
2126 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
2128 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002129 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002130 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002131 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 mcp->mb[1] = loop_id;
2133 mcp->mb[10] = opt;
2134 mcp->out_mb |= MBX_10;
2135 } else {
2136 mcp->mb[1] = loop_id << 8 | opt;
2137 }
2138
2139 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002140 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002142 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144 if (rval != QLA_SUCCESS) {
2145 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002146 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 } else {
2148 if (name != NULL) {
2149 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05002150 name[0] = MSB(mcp->mb[2]);
2151 name[1] = LSB(mcp->mb[2]);
2152 name[2] = MSB(mcp->mb[3]);
2153 name[3] = LSB(mcp->mb[3]);
2154 name[4] = MSB(mcp->mb[6]);
2155 name[5] = LSB(mcp->mb[6]);
2156 name[6] = MSB(mcp->mb[7]);
2157 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 }
2159
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
2161 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 }
2163
2164 return rval;
2165}
2166
2167/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002168 * qla24xx_link_initialization
2169 * Issue link initialization mailbox command.
2170 *
2171 * Input:
2172 * ha = adapter block pointer.
2173 * TARGET_QUEUE_LOCK must be released.
2174 * ADAPTER_STATE_LOCK must be released.
2175 *
2176 * Returns:
2177 * qla2x00 local function return status code.
2178 *
2179 * Context:
2180 * Kernel context.
2181 */
2182int
2183qla24xx_link_initialize(scsi_qla_host_t *vha)
2184{
2185 int rval;
2186 mbx_cmd_t mc;
2187 mbx_cmd_t *mcp = &mc;
2188
2189 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
2190 "Entered %s.\n", __func__);
2191
2192 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
2193 return QLA_FUNCTION_FAILED;
2194
2195 mcp->mb[0] = MBC_LINK_INITIALIZATION;
Joe Carnuccio5a5c27b2013-08-27 01:37:49 -04002196 mcp->mb[1] = BIT_4;
2197 if (vha->hw->operating_mode == LOOP)
2198 mcp->mb[1] |= BIT_6;
2199 else
2200 mcp->mb[1] |= BIT_5;
Joe Carnuccio61e1b262013-02-08 01:57:48 -05002201 mcp->mb[2] = 0;
2202 mcp->mb[3] = 0;
2203 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2204 mcp->in_mb = MBX_0;
2205 mcp->tov = MBX_TOV_SECONDS;
2206 mcp->flags = 0;
2207 rval = qla2x00_mailbox_command(vha, mcp);
2208
2209 if (rval != QLA_SUCCESS) {
2210 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2211 } else {
2212 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2213 "Done %s.\n", __func__);
2214 }
2215
2216 return rval;
2217}
2218
2219/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 * qla2x00_lip_reset
2221 * Issue LIP reset mailbox command.
2222 *
2223 * Input:
2224 * ha = adapter block pointer.
2225 * TARGET_QUEUE_LOCK must be released.
2226 * ADAPTER_STATE_LOCK must be released.
2227 *
2228 * Returns:
2229 * qla2x00 local function return status code.
2230 *
2231 * Context:
2232 * Kernel context.
2233 */
2234int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002235qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236{
2237 int rval;
2238 mbx_cmd_t mc;
2239 mbx_cmd_t *mcp = &mc;
2240
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002241 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2242 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002244 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002245 /* Logout across all FCFs. */
2246 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2247 mcp->mb[1] = BIT_1;
2248 mcp->mb[2] = 0;
2249 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2250 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002251 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002252 mcp->mb[1] = BIT_4;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002253 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002254 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002255 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002257 mcp->mb[0] = MBC_LIP_RESET;
2258 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002259 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002260 mcp->mb[1] = 0x00ff;
2261 mcp->mb[10] = 0;
2262 mcp->out_mb |= MBX_10;
2263 } else {
2264 mcp->mb[1] = 0xff00;
2265 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002266 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002267 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002270 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002272 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
2274 if (rval != QLA_SUCCESS) {
2275 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002276 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 } else {
2278 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002279 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2280 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 }
2282
2283 return rval;
2284}
2285
2286/*
2287 * qla2x00_send_sns
2288 * Send SNS command.
2289 *
2290 * Input:
2291 * ha = adapter block pointer.
2292 * sns = pointer for command.
2293 * cmd_size = command size.
2294 * buf_size = response/command size.
2295 * TARGET_QUEUE_LOCK must be released.
2296 * ADAPTER_STATE_LOCK must be released.
2297 *
2298 * Returns:
2299 * qla2x00 local function return status code.
2300 *
2301 * Context:
2302 * Kernel context.
2303 */
2304int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002305qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 uint16_t cmd_size, size_t buf_size)
2307{
2308 int rval;
2309 mbx_cmd_t mc;
2310 mbx_cmd_t *mcp = &mc;
2311
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002312 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2313 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002315 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002316 "Retry cnt=%d ratov=%d total tov=%d.\n",
2317 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318
2319 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2320 mcp->mb[1] = cmd_size;
2321 mcp->mb[2] = MSW(sns_phys_address);
2322 mcp->mb[3] = LSW(sns_phys_address);
2323 mcp->mb[6] = MSW(MSD(sns_phys_address));
2324 mcp->mb[7] = LSW(MSD(sns_phys_address));
2325 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2326 mcp->in_mb = MBX_0|MBX_1;
2327 mcp->buf_size = buf_size;
2328 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002329 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2330 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
2332 if (rval != QLA_SUCCESS) {
2333 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002334 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2335 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2336 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 } else {
2338 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002339 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2340 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 }
2342
2343 return rval;
2344}
2345
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002346int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002347qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002348 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2349{
2350 int rval;
2351
2352 struct logio_entry_24xx *lg;
2353 dma_addr_t lg_dma;
2354 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002355 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002356 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002357
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002358 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2359 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002360
Michael Hernandezd7459522016-12-12 14:40:07 -08002361 if (vha->vp_idx && vha->qpair)
2362 req = vha->qpair->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002363 else
Michael Hernandezd7459522016-12-12 14:40:07 -08002364 req = ha->req_q_map[0];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002365
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002366 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002367 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002368 ql_log(ql_log_warn, vha, 0x1062,
2369 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002370 return QLA_MEMORY_ALLOC_FAILED;
2371 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002372
2373 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2374 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002375 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002376 lg->nport_handle = cpu_to_le16(loop_id);
Bart Van Asschead950362015-07-09 07:24:08 -07002377 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002378 if (opt & BIT_0)
Bart Van Asschead950362015-07-09 07:24:08 -07002379 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07002380 if (opt & BIT_1)
Bart Van Asschead950362015-07-09 07:24:08 -07002381 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002382 lg->port_id[0] = al_pa;
2383 lg->port_id[1] = area;
2384 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002385 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002386 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2387 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002388 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002389 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2390 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002391 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002392 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2393 "Failed to complete IOCB -- error status (%x).\n",
2394 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002395 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002396 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002397 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2398 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2399
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002400 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2401 "Failed to complete IOCB -- completion status (%x) "
2402 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2403 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002404
2405 switch (iop[0]) {
2406 case LSC_SCODE_PORTID_USED:
2407 mb[0] = MBS_PORT_ID_USED;
2408 mb[1] = LSW(iop[1]);
2409 break;
2410 case LSC_SCODE_NPORT_USED:
2411 mb[0] = MBS_LOOP_ID_USED;
2412 break;
2413 case LSC_SCODE_NOLINK:
2414 case LSC_SCODE_NOIOCB:
2415 case LSC_SCODE_NOXCB:
2416 case LSC_SCODE_CMD_FAILED:
2417 case LSC_SCODE_NOFABRIC:
2418 case LSC_SCODE_FW_NOT_READY:
2419 case LSC_SCODE_NOT_LOGGED_IN:
2420 case LSC_SCODE_NOPCB:
2421 case LSC_SCODE_ELS_REJECT:
2422 case LSC_SCODE_CMD_PARAM_ERR:
2423 case LSC_SCODE_NONPORT:
2424 case LSC_SCODE_LOGGED_IN:
2425 case LSC_SCODE_NOFLOGI_ACC:
2426 default:
2427 mb[0] = MBS_COMMAND_ERROR;
2428 break;
2429 }
2430 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002431 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2432 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002433
2434 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2435
2436 mb[0] = MBS_COMMAND_COMPLETE;
2437 mb[1] = 0;
2438 if (iop[0] & BIT_4) {
2439 if (iop[0] & BIT_8)
2440 mb[1] |= BIT_1;
2441 } else
2442 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002443
2444 /* Passback COS information. */
2445 mb[10] = 0;
2446 if (lg->io_parameter[7] || lg->io_parameter[8])
2447 mb[10] |= BIT_0; /* Class 2. */
2448 if (lg->io_parameter[9] || lg->io_parameter[10])
2449 mb[10] |= BIT_1; /* Class 3. */
Bart Van Asschead950362015-07-09 07:24:08 -07002450 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04002451 mb[10] |= BIT_7; /* Confirmed Completion
2452 * Allowed
2453 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002454 }
2455
2456 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2457
2458 return rval;
2459}
2460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461/*
2462 * qla2x00_login_fabric
2463 * Issue login fabric port mailbox command.
2464 *
2465 * Input:
2466 * ha = adapter block pointer.
2467 * loop_id = device loop ID.
2468 * domain = device domain.
2469 * area = device area.
2470 * al_pa = device AL_PA.
2471 * status = pointer for return status.
2472 * opt = command options.
2473 * TARGET_QUEUE_LOCK must be released.
2474 * ADAPTER_STATE_LOCK must be released.
2475 *
2476 * Returns:
2477 * qla2x00 local function return status code.
2478 *
2479 * Context:
2480 * Kernel context.
2481 */
2482int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002483qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2485{
2486 int rval;
2487 mbx_cmd_t mc;
2488 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002489 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002491 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2492 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
2494 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2495 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2496 if (HAS_EXTENDED_IDS(ha)) {
2497 mcp->mb[1] = loop_id;
2498 mcp->mb[10] = opt;
2499 mcp->out_mb |= MBX_10;
2500 } else {
2501 mcp->mb[1] = (loop_id << 8) | opt;
2502 }
2503 mcp->mb[2] = domain;
2504 mcp->mb[3] = area << 8 | al_pa;
2505
2506 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2507 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2508 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002509 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510
2511 /* Return mailbox statuses. */
2512 if (mb != NULL) {
2513 mb[0] = mcp->mb[0];
2514 mb[1] = mcp->mb[1];
2515 mb[2] = mcp->mb[2];
2516 mb[6] = mcp->mb[6];
2517 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002518 /* COS retrieved from Get-Port-Database mailbox command. */
2519 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
2521
2522 if (rval != QLA_SUCCESS) {
2523 /* RLU tmp code: need to change main mailbox_command function to
2524 * return ok even when the mailbox completion value is not
2525 * SUCCESS. The caller needs to be responsible to interpret
2526 * the return values of this mailbox command if we're not
2527 * to change too much of the existing code.
2528 */
2529 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2530 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2531 mcp->mb[0] == 0x4006)
2532 rval = QLA_SUCCESS;
2533
2534 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002535 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2536 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2537 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 } else {
2539 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002540 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2541 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 }
2543
2544 return rval;
2545}
2546
2547/*
2548 * qla2x00_login_local_device
2549 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002550 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 * Input:
2552 * ha = adapter block pointer.
2553 * loop_id = device loop ID.
2554 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002555 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 * Returns:
2557 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002558 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 * Context:
2560 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002561 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 */
2563int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002564qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 uint16_t *mb_ret, uint8_t opt)
2566{
2567 int rval;
2568 mbx_cmd_t mc;
2569 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002570 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002572 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2573 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002574
Andrew Vasqueze4289242007-07-19 15:05:56 -07002575 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002576 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002577 fcport->d_id.b.domain, fcport->d_id.b.area,
2578 fcport->d_id.b.al_pa, mb_ret, opt);
2579
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2581 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002582 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 else
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08002584 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 mcp->mb[2] = opt;
2586 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2587 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2588 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2589 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002590 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
2592 /* Return mailbox statuses. */
2593 if (mb_ret != NULL) {
2594 mb_ret[0] = mcp->mb[0];
2595 mb_ret[1] = mcp->mb[1];
2596 mb_ret[6] = mcp->mb[6];
2597 mb_ret[7] = mcp->mb[7];
2598 }
2599
2600 if (rval != QLA_SUCCESS) {
2601 /* AV tmp code: need to change main mailbox_command function to
2602 * return ok even when the mailbox completion value is not
2603 * SUCCESS. The caller needs to be responsible to interpret
2604 * the return values of this mailbox command if we're not
2605 * to change too much of the existing code.
2606 */
2607 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2608 rval = QLA_SUCCESS;
2609
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002610 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2611 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2612 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 } else {
2614 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002615 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2616 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 }
2618
2619 return (rval);
2620}
2621
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002622int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002623qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002624 uint8_t area, uint8_t al_pa)
2625{
2626 int rval;
2627 struct logio_entry_24xx *lg;
2628 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002629 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002630 struct req_que *req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002631
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002632 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2633 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002634
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002635 lg = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002636 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002637 ql_log(ql_log_warn, vha, 0x106e,
2638 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002639 return QLA_MEMORY_ALLOC_FAILED;
2640 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002641
Michael Hernandezd7459522016-12-12 14:40:07 -08002642 req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002643 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2644 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002645 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002646 lg->nport_handle = cpu_to_le16(loop_id);
2647 lg->control_flags =
Bart Van Asschead950362015-07-09 07:24:08 -07002648 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002649 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002650 lg->port_id[0] = al_pa;
2651 lg->port_id[1] = area;
2652 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002653 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002654 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2655 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002656 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002657 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2658 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002659 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002660 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2661 "Failed to complete IOCB -- error status (%x).\n",
2662 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002663 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07002664 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002665 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2666 "Failed to complete IOCB -- completion status (%x) "
2667 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002668 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002669 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002670 } else {
2671 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002672 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2673 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002674 }
2675
2676 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2677
2678 return rval;
2679}
2680
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681/*
2682 * qla2x00_fabric_logout
2683 * Issue logout fabric port mailbox command.
2684 *
2685 * Input:
2686 * ha = adapter block pointer.
2687 * loop_id = device loop ID.
2688 * TARGET_QUEUE_LOCK must be released.
2689 * ADAPTER_STATE_LOCK must be released.
2690 *
2691 * Returns:
2692 * qla2x00 local function return status code.
2693 *
2694 * Context:
2695 * Kernel context.
2696 */
2697int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002698qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002699 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700{
2701 int rval;
2702 mbx_cmd_t mc;
2703 mbx_cmd_t *mcp = &mc;
2704
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002705 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2706 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
2708 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2709 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002710 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 mcp->mb[1] = loop_id;
2712 mcp->mb[10] = 0;
2713 mcp->out_mb |= MBX_10;
2714 } else {
2715 mcp->mb[1] = loop_id << 8;
2716 }
2717
2718 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002719 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002721 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722
2723 if (rval != QLA_SUCCESS) {
2724 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002725 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2726 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 } else {
2728 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002729 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2730 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 }
2732
2733 return rval;
2734}
2735
2736/*
2737 * qla2x00_full_login_lip
2738 * Issue full login LIP mailbox command.
2739 *
2740 * Input:
2741 * ha = adapter block pointer.
2742 * TARGET_QUEUE_LOCK must be released.
2743 * ADAPTER_STATE_LOCK must be released.
2744 *
2745 * Returns:
2746 * qla2x00 local function return status code.
2747 *
2748 * Context:
2749 * Kernel context.
2750 */
2751int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002752qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753{
2754 int rval;
2755 mbx_cmd_t mc;
2756 mbx_cmd_t *mcp = &mc;
2757
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002758 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2759 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
2761 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Quinn Tran87d6814a2019-01-24 23:23:49 -08002762 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_4 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002763 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 mcp->mb[3] = 0;
2765 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2766 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002767 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002769 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
2771 if (rval != QLA_SUCCESS) {
2772 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002773 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 } else {
2775 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2777 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 }
2779
2780 return rval;
2781}
2782
2783/*
2784 * qla2x00_get_id_list
2785 *
2786 * Input:
2787 * ha = adapter block pointer.
2788 *
2789 * Returns:
2790 * qla2x00 local function return status code.
2791 *
2792 * Context:
2793 * Kernel context.
2794 */
2795int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002796qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 uint16_t *entries)
2798{
2799 int rval;
2800 mbx_cmd_t mc;
2801 mbx_cmd_t *mcp = &mc;
2802
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002803 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2804 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 if (id_list == NULL)
2807 return QLA_FUNCTION_FAILED;
2808
2809 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002810 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002811 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002812 mcp->mb[2] = MSW(id_list_dma);
2813 mcp->mb[3] = LSW(id_list_dma);
2814 mcp->mb[6] = MSW(MSD(id_list_dma));
2815 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002816 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002817 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002819 } else {
2820 mcp->mb[1] = MSW(id_list_dma);
2821 mcp->mb[2] = LSW(id_list_dma);
2822 mcp->mb[3] = MSW(MSD(id_list_dma));
2823 mcp->mb[6] = LSW(MSD(id_list_dma));
2824 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002827 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002829 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830
2831 if (rval != QLA_SUCCESS) {
2832 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002833 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 } else {
2835 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002836 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2837 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 }
2839
2840 return rval;
2841}
2842
2843/*
2844 * qla2x00_get_resource_cnts
2845 * Get current firmware resource counts.
2846 *
2847 * Input:
2848 * ha = adapter block pointer.
2849 *
2850 * Returns:
2851 * qla2x00 local function return status code.
2852 *
2853 * Context:
2854 * Kernel context.
2855 */
2856int
Quinn Tran03e8c682015-12-17 14:56:59 -05002857qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858{
Quinn Tran03e8c682015-12-17 14:56:59 -05002859 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 int rval;
2861 mbx_cmd_t mc;
2862 mbx_cmd_t *mcp = &mc;
2863
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002864 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2865 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866
2867 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2868 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002869 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05002870 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002871 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002872 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002874 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875
2876 if (rval != QLA_SUCCESS) {
2877 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002878 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2879 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002881 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002882 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2883 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2884 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2885 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
Quinn Tran03e8c682015-12-17 14:56:59 -05002887 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2888 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2889 ha->cur_fw_xcb_count = mcp->mb[3];
2890 ha->orig_fw_xcb_count = mcp->mb[6];
2891 ha->cur_fw_iocb_count = mcp->mb[7];
2892 ha->orig_fw_iocb_count = mcp->mb[10];
2893 if (ha->flags.npiv_supported)
2894 ha->max_npiv_vports = mcp->mb[11];
2895 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2896 ha->fw_max_fcf_count = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 }
2898
2899 return (rval);
2900}
2901
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902/*
2903 * qla2x00_get_fcal_position_map
2904 * Get FCAL (LILP) position map using mailbox command
2905 *
2906 * Input:
2907 * ha = adapter state pointer.
2908 * pos_map = buffer pointer (can be NULL).
2909 *
2910 * Returns:
2911 * qla2x00 local function return status code.
2912 *
2913 * Context:
2914 * Kernel context.
2915 */
2916int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002917qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918{
2919 int rval;
2920 mbx_cmd_t mc;
2921 mbx_cmd_t *mcp = &mc;
2922 char *pmap;
2923 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002924 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002926 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2927 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002928
Thomas Meyer08eb7f42017-09-21 08:15:26 +02002929 pmap = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002931 ql_log(ql_log_warn, vha, 0x1080,
2932 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 return QLA_MEMORY_ALLOC_FAILED;
2934 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935
2936 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2937 mcp->mb[2] = MSW(pmap_dma);
2938 mcp->mb[3] = LSW(pmap_dma);
2939 mcp->mb[6] = MSW(MSD(pmap_dma));
2940 mcp->mb[7] = LSW(MSD(pmap_dma));
2941 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2942 mcp->in_mb = MBX_1|MBX_0;
2943 mcp->buf_size = FCAL_MAP_SIZE;
2944 mcp->flags = MBX_DMA_IN;
2945 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002946 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947
2948 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002949 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002950 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2951 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2952 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2953 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954
2955 if (pos_map)
2956 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2957 }
2958 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2959
2960 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002961 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002963 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2964 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966
2967 return rval;
2968}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002969
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002970/*
2971 * qla2x00_get_link_status
2972 *
2973 * Input:
2974 * ha = adapter block pointer.
2975 * loop_id = device loop ID.
2976 * ret_buf = pointer to link status return buffer.
2977 *
2978 * Returns:
2979 * 0 = success.
2980 * BIT_0 = mem alloc error.
2981 * BIT_1 = mailbox error.
2982 */
2983int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002984qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002985 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002986{
2987 int rval;
2988 mbx_cmd_t mc;
2989 mbx_cmd_t *mcp = &mc;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002990 uint32_t *iter = (void *)stats;
2991 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002992 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002993
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002994 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2995 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002996
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002997 mcp->mb[0] = MBC_GET_LINK_STATUS;
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04002998 mcp->mb[2] = MSW(LSD(stats_dma));
2999 mcp->mb[3] = LSW(LSD(stats_dma));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003000 mcp->mb[6] = MSW(MSD(stats_dma));
3001 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003002 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3003 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07003004 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003005 mcp->mb[1] = loop_id;
3006 mcp->mb[4] = 0;
3007 mcp->mb[10] = 0;
3008 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
3009 mcp->in_mb |= MBX_1;
3010 } else if (HAS_EXTENDED_IDS(ha)) {
3011 mcp->mb[1] = loop_id;
3012 mcp->mb[10] = 0;
3013 mcp->out_mb |= MBX_10|MBX_1;
3014 } else {
3015 mcp->mb[1] = loop_id << 8;
3016 mcp->out_mb |= MBX_1;
3017 }
Ravi Anandb93480e2008-04-03 13:13:25 -07003018 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003019 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003020 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003021
3022 if (rval == QLA_SUCCESS) {
3023 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003024 ql_dbg(ql_dbg_mbx, vha, 0x1085,
3025 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003026 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003027 } else {
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003028 /* Re-endianize - firmware data is le32. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003029 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
3030 "Done %s.\n", __func__);
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003031 for ( ; dwords--; iter++)
3032 le32_to_cpus(iter);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003033 }
3034 } else {
3035 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003036 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003037 }
3038
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08003039 return rval;
3040}
3041
3042int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003043qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Quinn Tran15f30a52017-03-15 09:48:52 -07003044 dma_addr_t stats_dma, uint16_t options)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003045{
3046 int rval;
3047 mbx_cmd_t mc;
3048 mbx_cmd_t *mcp = &mc;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003049 uint32_t *iter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003050
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003051 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
3052 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003053
Quinn Tran15f30a52017-03-15 09:48:52 -07003054 memset(&mc, 0, sizeof(mc));
3055 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
3056 mc.mb[2] = MSW(stats_dma);
3057 mc.mb[3] = LSW(stats_dma);
3058 mc.mb[6] = MSW(MSD(stats_dma));
3059 mc.mb[7] = LSW(MSD(stats_dma));
3060 mc.mb[8] = sizeof(struct link_statistics) / 4;
3061 mc.mb[9] = cpu_to_le16(vha->vp_idx);
3062 mc.mb[10] = cpu_to_le16(options);
3063
3064 rval = qla24xx_send_mb_cmd(vha, &mc);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003065
3066 if (rval == QLA_SUCCESS) {
3067 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003068 ql_dbg(ql_dbg_mbx, vha, 0x1089,
3069 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003070 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003071 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003072 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
3073 "Done %s.\n", __func__);
Joe Carnuccioc6dc9902016-07-06 11:14:24 -04003074 /* Re-endianize - firmware data is le32. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08003075 dwords = sizeof(struct link_statistics) / 4;
Joe Carnuccioda08ef52016-01-27 12:03:34 -05003076 iter = &stats->link_fail_cnt;
3077 for ( ; dwords--; iter++)
3078 le32_to_cpus(iter);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003079 }
3080 } else {
3081 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003082 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003083 }
3084
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003085 return rval;
3086}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003087
3088int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003089qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003090{
3091 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003092 unsigned long flags = 0;
3093
3094 struct abort_entry_24xx *abt;
3095 dma_addr_t abt_dma;
3096 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003097 fc_port_t *fcport = sp->fcport;
3098 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003099 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003100 struct req_que *req = vha->req;
Quinn Tran585def92018-09-04 14:19:20 -07003101 struct qla_qpair *qpair = sp->qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003102
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003103 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
3104 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003105
Michael Hernandezd7459522016-12-12 14:40:07 -08003106 if (vha->flags.qpairs_available && sp->qpair)
3107 req = sp->qpair->req;
Quinn Tran585def92018-09-04 14:19:20 -07003108 else
3109 return QLA_FUNCTION_FAILED;
Michael Hernandezd7459522016-12-12 14:40:07 -08003110
Armen Baloyan4440e462014-02-26 04:15:18 -05003111 if (ql2xasynctmfenable)
3112 return qla24xx_async_abort_command(sp);
3113
Quinn Tran585def92018-09-04 14:19:20 -07003114 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003115 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003116 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003117 break;
3118 }
Quinn Tran585def92018-09-04 14:19:20 -07003119 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05003120 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003121 /* Command not found. */
3122 return QLA_FUNCTION_FAILED;
3123 }
3124
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003125 abt = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003126 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003127 ql_log(ql_log_warn, vha, 0x108d,
3128 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003129 return QLA_MEMORY_ALLOC_FAILED;
3130 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003131
3132 abt->entry_type = ABORT_IOCB_TYPE;
3133 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003134 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003135 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07003136 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003137 abt->port_id[0] = fcport->d_id.b.al_pa;
3138 abt->port_id[1] = fcport->d_id.b.area;
3139 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003140 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003141
3142 abt->req_que_no = cpu_to_le16(req->id);
3143
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003144 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003145 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003146 ql_dbg(ql_dbg_mbx, vha, 0x108e,
3147 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003148 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003149 ql_dbg(ql_dbg_mbx, vha, 0x108f,
3150 "Failed to complete IOCB -- error status (%x).\n",
3151 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003152 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003153 } else if (abt->nport_handle != cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003154 ql_dbg(ql_dbg_mbx, vha, 0x1090,
3155 "Failed to complete IOCB -- completion status (%x).\n",
3156 le16_to_cpu(abt->nport_handle));
Chad Dupuisf934c9d2014-04-11 16:54:31 -04003157 if (abt->nport_handle == CS_IOCB_ERROR)
3158 rval = QLA_FUNCTION_PARAMETER_ERROR;
3159 else
3160 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003161 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003162 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
3163 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003164 }
3165
3166 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
3167
3168 return rval;
3169}
3170
3171struct tsk_mgmt_cmd {
3172 union {
3173 struct tsk_mgmt_entry tsk;
3174 struct sts_entry_24xx sts;
3175 } p;
3176};
3177
Andrew Vasquez523ec772008-04-03 13:13:24 -07003178static int
3179__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003180 uint64_t l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003181{
Andrew Vasquez523ec772008-04-03 13:13:24 -07003182 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003183 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003184 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003185 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003186 scsi_qla_host_t *vha;
3187 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003188 struct req_que *req;
3189 struct rsp_que *rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003190 struct qla_qpair *qpair;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003191
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003192 vha = fcport->vha;
3193 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003194 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003195
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003196 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
3197 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003198
Michael Hernandezd7459522016-12-12 14:40:07 -08003199 if (vha->vp_idx && vha->qpair) {
3200 /* NPIV port */
3201 qpair = vha->qpair;
3202 rsp = qpair->rsp;
3203 req = qpair->req;
3204 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07003205 rsp = req->rsp;
Michael Hernandezd7459522016-12-12 14:40:07 -08003206 }
3207
Thomas Meyer08eb7f42017-09-21 08:15:26 +02003208 tsk = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003209 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003210 ql_log(ql_log_warn, vha, 0x1093,
3211 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003212 return QLA_MEMORY_ALLOC_FAILED;
3213 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003214
3215 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3216 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003217 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003218 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003219 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003220 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003221 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3222 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3223 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04003224 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07003225 if (type == TCF_LUN_RESET) {
3226 int_to_scsilun(l, &tsk->p.tsk.lun);
3227 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3228 sizeof(tsk->p.tsk.lun));
3229 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003230
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003231 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003232 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003233 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003234 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3235 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003236 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003237 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3238 "Failed to complete IOCB -- error status (%x).\n",
3239 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003240 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07003241 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003242 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3243 "Failed to complete IOCB -- completion status (%x).\n",
3244 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07003245 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08003246 } else if (le16_to_cpu(sts->scsi_status) &
3247 SS_RESPONSE_INFO_LEN_VALID) {
3248 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003250 "Ignoring inconsistent data length -- not enough "
3251 "response info (%d).\n",
3252 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08003253 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003254 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3255 "Failed to complete IOCB -- response (%x).\n",
3256 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08003257 rval = QLA_FUNCTION_FAILED;
3258 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003259 }
3260
3261 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003262 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07003263 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3264 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003265 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3266 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003267 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003268 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3269 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003270 }
3271
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003272 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003273
3274 return rval;
3275}
3276
Andrew Vasquez523ec772008-04-03 13:13:24 -07003277int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003278qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003279{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003280 struct qla_hw_data *ha = fcport->vha->hw;
3281
3282 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3283 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3284
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003285 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003286}
3287
3288int
Hannes Reinecke9cb78c12014-06-25 15:27:36 +02003289qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07003290{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07003291 struct qla_hw_data *ha = fcport->vha->hw;
3292
3293 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3294 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3295
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003296 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07003297}
3298
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003299int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003300qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003301{
3302 int rval;
3303 mbx_cmd_t mc;
3304 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003305 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003306
Andrew Vasquez68af0812008-05-12 22:21:13 -07003307 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003308 return QLA_FUNCTION_FAILED;
3309
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003310 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3311 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003312
3313 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3314 mcp->out_mb = MBX_0;
3315 mcp->in_mb = MBX_0;
3316 mcp->tov = 5;
3317 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003318 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003319
3320 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003321 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003322 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003323 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3324 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003325 }
3326
3327 return rval;
3328}
3329
Joe Carnucciodb64e932013-10-30 03:38:18 -04003330int
3331qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3332{
3333 int rval;
3334 mbx_cmd_t mc;
3335 mbx_cmd_t *mcp = &mc;
3336
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003337 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3338 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003339 return QLA_FUNCTION_FAILED;
3340
3341 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3342 "Entered %s.\n", __func__);
3343
3344 mcp->mb[0] = MBC_WRITE_SERDES;
3345 mcp->mb[1] = addr;
Andrew Vasquez064135e2015-04-09 15:00:02 -04003346 if (IS_QLA2031(vha->hw))
3347 mcp->mb[2] = data & 0xff;
3348 else
3349 mcp->mb[2] = data;
3350
Joe Carnucciodb64e932013-10-30 03:38:18 -04003351 mcp->mb[3] = 0;
3352 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3353 mcp->in_mb = MBX_0;
3354 mcp->tov = MBX_TOV_SECONDS;
3355 mcp->flags = 0;
3356 rval = qla2x00_mailbox_command(vha, mcp);
3357
3358 if (rval != QLA_SUCCESS) {
3359 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3360 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3361 } else {
3362 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3363 "Done %s.\n", __func__);
3364 }
3365
3366 return rval;
3367}
3368
3369int
3370qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3371{
3372 int rval;
3373 mbx_cmd_t mc;
3374 mbx_cmd_t *mcp = &mc;
3375
Joe Carnucciof299c7c2015-08-04 13:37:51 -04003376 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3377 !IS_QLA27XX(vha->hw))
Joe Carnucciodb64e932013-10-30 03:38:18 -04003378 return QLA_FUNCTION_FAILED;
3379
3380 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3381 "Entered %s.\n", __func__);
3382
3383 mcp->mb[0] = MBC_READ_SERDES;
3384 mcp->mb[1] = addr;
3385 mcp->mb[3] = 0;
3386 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3387 mcp->in_mb = MBX_1|MBX_0;
3388 mcp->tov = MBX_TOV_SECONDS;
3389 mcp->flags = 0;
3390 rval = qla2x00_mailbox_command(vha, mcp);
3391
Andrew Vasquez064135e2015-04-09 15:00:02 -04003392 if (IS_QLA2031(vha->hw))
3393 *data = mcp->mb[1] & 0xff;
3394 else
3395 *data = mcp->mb[1];
Joe Carnucciodb64e932013-10-30 03:38:18 -04003396
3397 if (rval != QLA_SUCCESS) {
3398 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3399 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3400 } else {
3401 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3402 "Done %s.\n", __func__);
3403 }
3404
3405 return rval;
3406}
3407
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003408int
3409qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3410{
3411 int rval;
3412 mbx_cmd_t mc;
3413 mbx_cmd_t *mcp = &mc;
3414
3415 if (!IS_QLA8044(vha->hw))
3416 return QLA_FUNCTION_FAILED;
3417
Quinn Tran83548fe2017-06-02 09:12:01 -07003418 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x11a0,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003419 "Entered %s.\n", __func__);
3420
3421 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3422 mcp->mb[1] = HCS_WRITE_SERDES;
3423 mcp->mb[3] = LSW(addr);
3424 mcp->mb[4] = MSW(addr);
3425 mcp->mb[5] = LSW(data);
3426 mcp->mb[6] = MSW(data);
3427 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3428 mcp->in_mb = MBX_0;
3429 mcp->tov = MBX_TOV_SECONDS;
3430 mcp->flags = 0;
3431 rval = qla2x00_mailbox_command(vha, mcp);
3432
3433 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003434 ql_dbg(ql_dbg_mbx, vha, 0x11a1,
Joe Carnuccioe8887c52014-04-11 16:54:17 -04003435 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3436 } else {
3437 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3438 "Done %s.\n", __func__);
3439 }
3440
3441 return rval;
3442}
3443
3444int
3445qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3446{
3447 int rval;
3448 mbx_cmd_t mc;
3449 mbx_cmd_t *mcp = &mc;
3450
3451 if (!IS_QLA8044(vha->hw))
3452 return QLA_FUNCTION_FAILED;
3453
3454 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3455 "Entered %s.\n", __func__);
3456
3457 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3458 mcp->mb[1] = HCS_READ_SERDES;
3459 mcp->mb[3] = LSW(addr);
3460 mcp->mb[4] = MSW(addr);
3461 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3462 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3463 mcp->tov = MBX_TOV_SECONDS;
3464 mcp->flags = 0;
3465 rval = qla2x00_mailbox_command(vha, mcp);
3466
3467 *data = mcp->mb[2] << 16 | mcp->mb[1];
3468
3469 if (rval != QLA_SUCCESS) {
3470 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3471 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3472 } else {
3473 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3474 "Done %s.\n", __func__);
3475 }
3476
3477 return rval;
3478}
3479
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003480/**
3481 * qla2x00_set_serdes_params() -
Bart Van Assche2db62282018-01-23 16:33:51 -08003482 * @vha: HA context
Bart Van Assche807eb902018-10-18 15:45:41 -07003483 * @sw_em_1g: serial link options
3484 * @sw_em_2g: serial link options
3485 * @sw_em_4g: serial link options
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003486 *
3487 * Returns
3488 */
3489int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003490qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003491 uint16_t sw_em_2g, uint16_t sw_em_4g)
3492{
3493 int rval;
3494 mbx_cmd_t mc;
3495 mbx_cmd_t *mcp = &mc;
3496
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003497 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3498 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003499
3500 mcp->mb[0] = MBC_SERDES_PARAMS;
3501 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08003502 mcp->mb[2] = sw_em_1g | BIT_15;
3503 mcp->mb[3] = sw_em_2g | BIT_15;
3504 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003505 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3506 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003507 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003508 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003509 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003510
3511 if (rval != QLA_SUCCESS) {
3512 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003513 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3514 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003515 } else {
3516 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003517 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3518 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003519 }
3520
3521 return rval;
3522}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003523
3524int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003525qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003526{
3527 int rval;
3528 mbx_cmd_t mc;
3529 mbx_cmd_t *mcp = &mc;
3530
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003531 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003532 return QLA_FUNCTION_FAILED;
3533
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003534 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3535 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003536
3537 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08003538 mcp->mb[1] = 0;
3539 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003540 mcp->in_mb = MBX_0;
3541 mcp->tov = 5;
3542 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003543 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003544
3545 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003546 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07003547 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3548 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003549 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003550 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3551 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07003552 }
3553
3554 return rval;
3555}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003556
3557int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003558qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003559 uint16_t buffers)
3560{
3561 int rval;
3562 mbx_cmd_t mc;
3563 mbx_cmd_t *mcp = &mc;
3564
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003565 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3566 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003567
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003568 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003569 return QLA_FUNCTION_FAILED;
3570
Andrew Vasquez85880802009-12-15 21:29:46 -08003571 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3572 return QLA_FUNCTION_FAILED;
3573
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003574 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003575 mcp->mb[1] = TC_EFT_ENABLE;
3576 mcp->mb[2] = LSW(eft_dma);
3577 mcp->mb[3] = MSW(eft_dma);
3578 mcp->mb[4] = LSW(MSD(eft_dma));
3579 mcp->mb[5] = MSW(MSD(eft_dma));
3580 mcp->mb[6] = buffers;
3581 mcp->mb[7] = TC_AEN_DISABLE;
3582 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 -07003583 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003584 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003585 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003586 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003587 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003588 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3589 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3590 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003591 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003592 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3593 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003594 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003595
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003596 return rval;
3597}
3598
3599int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003600qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003601{
3602 int rval;
3603 mbx_cmd_t mc;
3604 mbx_cmd_t *mcp = &mc;
3605
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003606 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3607 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003608
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003609 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003610 return QLA_FUNCTION_FAILED;
3611
Andrew Vasquez85880802009-12-15 21:29:46 -08003612 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3613 return QLA_FUNCTION_FAILED;
3614
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003615 mcp->mb[0] = MBC_TRACE_CONTROL;
3616 mcp->mb[1] = TC_EFT_DISABLE;
3617 mcp->out_mb = MBX_1|MBX_0;
3618 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003619 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003620 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003621 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003622 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003623 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3624 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3625 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003626 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3628 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07003629 }
3630
3631 return rval;
3632}
3633
Andrew Vasquez88729e52006-06-23 16:10:50 -07003634int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003635qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003636 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3637{
3638 int rval;
3639 mbx_cmd_t mc;
3640 mbx_cmd_t *mcp = &mc;
3641
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003642 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3643 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003644
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003645 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
Chad Dupuisf73cb692014-02-26 04:15:06 -05003646 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003647 return QLA_FUNCTION_FAILED;
3648
Andrew Vasquez85880802009-12-15 21:29:46 -08003649 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3650 return QLA_FUNCTION_FAILED;
3651
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003652 mcp->mb[0] = MBC_TRACE_CONTROL;
3653 mcp->mb[1] = TC_FCE_ENABLE;
3654 mcp->mb[2] = LSW(fce_dma);
3655 mcp->mb[3] = MSW(fce_dma);
3656 mcp->mb[4] = LSW(MSD(fce_dma));
3657 mcp->mb[5] = MSW(MSD(fce_dma));
3658 mcp->mb[6] = buffers;
3659 mcp->mb[7] = TC_AEN_DISABLE;
3660 mcp->mb[8] = 0;
3661 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3662 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3663 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3664 MBX_1|MBX_0;
3665 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003666 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003667 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003668 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003669 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003670 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3671 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3672 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003673 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003674 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3675 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003676
3677 if (mb)
3678 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3679 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07003680 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003681 }
3682
3683 return rval;
3684}
3685
3686int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003687qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003688{
3689 int rval;
3690 mbx_cmd_t mc;
3691 mbx_cmd_t *mcp = &mc;
3692
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003693 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3694 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003695
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003696 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003697 return QLA_FUNCTION_FAILED;
3698
Andrew Vasquez85880802009-12-15 21:29:46 -08003699 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3700 return QLA_FUNCTION_FAILED;
3701
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003702 mcp->mb[0] = MBC_TRACE_CONTROL;
3703 mcp->mb[1] = TC_FCE_DISABLE;
3704 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3705 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3706 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3707 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003708 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003709 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003710 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003711 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003712 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3713 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3714 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003715 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003716 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3717 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003718
3719 if (wr)
3720 *wr = (uint64_t) mcp->mb[5] << 48 |
3721 (uint64_t) mcp->mb[4] << 32 |
3722 (uint64_t) mcp->mb[3] << 16 |
3723 (uint64_t) mcp->mb[2];
3724 if (rd)
3725 *rd = (uint64_t) mcp->mb[9] << 48 |
3726 (uint64_t) mcp->mb[8] << 32 |
3727 (uint64_t) mcp->mb[7] << 16 |
3728 (uint64_t) mcp->mb[6];
3729 }
3730
3731 return rval;
3732}
3733
3734int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003735qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3736 uint16_t *port_speed, uint16_t *mb)
3737{
3738 int rval;
3739 mbx_cmd_t mc;
3740 mbx_cmd_t *mcp = &mc;
3741
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003742 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3743 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003744
Giridhar Malavali6e980162010-03-19 17:03:58 -07003745 if (!IS_IIDMA_CAPABLE(vha->hw))
3746 return QLA_FUNCTION_FAILED;
3747
Giridhar Malavali6e980162010-03-19 17:03:58 -07003748 mcp->mb[0] = MBC_PORT_PARAMS;
3749 mcp->mb[1] = loop_id;
3750 mcp->mb[2] = mcp->mb[3] = 0;
3751 mcp->mb[9] = vha->vp_idx;
3752 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3753 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3754 mcp->tov = MBX_TOV_SECONDS;
3755 mcp->flags = 0;
3756 rval = qla2x00_mailbox_command(vha, mcp);
3757
3758 /* Return mailbox statuses. */
3759 if (mb != NULL) {
3760 mb[0] = mcp->mb[0];
3761 mb[1] = mcp->mb[1];
3762 mb[3] = mcp->mb[3];
3763 }
3764
3765 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003766 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003767 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003768 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3769 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003770 if (port_speed)
3771 *port_speed = mcp->mb[3];
3772 }
3773
3774 return rval;
3775}
3776
3777int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003778qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003779 uint16_t port_speed, uint16_t *mb)
3780{
3781 int rval;
3782 mbx_cmd_t mc;
3783 mbx_cmd_t *mcp = &mc;
3784
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003785 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3786 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003787
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003788 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003789 return QLA_FUNCTION_FAILED;
3790
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003791 mcp->mb[0] = MBC_PORT_PARAMS;
3792 mcp->mb[1] = loop_id;
3793 mcp->mb[2] = BIT_0;
Himanshu Madhani4c1458d2018-08-31 11:24:27 -07003794 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003795 mcp->mb[9] = vha->vp_idx;
3796 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3797 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003798 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003799 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003800 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003801
3802 /* Return mailbox statuses. */
3803 if (mb != NULL) {
3804 mb[0] = mcp->mb[0];
3805 mb[1] = mcp->mb[1];
3806 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003807 }
3808
3809 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003810 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3811 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003812 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003813 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3814 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003815 }
3816
3817 return rval;
3818}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003819
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003820void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003821qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003822 struct vp_rpt_id_entry_24xx *rptid_entry)
3823{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003824 struct qla_hw_data *ha = vha->hw;
Quinn Tran41dc5292017-01-19 22:28:03 -08003825 scsi_qla_host_t *vp = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003826 unsigned long flags;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003827 int found;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003828 port_id_t id;
Quinn Tran9cd883f2017-12-28 12:33:24 -08003829 struct fc_port *fcport;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003830
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003831 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3832 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003833
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003834 if (rptid_entry->entry_status != 0)
3835 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003836
Quinn Tran482c9dc2017-03-15 09:48:54 -07003837 id.b.domain = rptid_entry->port_id[2];
3838 id.b.area = rptid_entry->port_id[1];
3839 id.b.al_pa = rptid_entry->port_id[0];
3840 id.b.rsvd_1 = 0;
Darren Trapp1763c1f2018-03-20 23:09:34 -07003841 ha->flags.n2n_ae = 0;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003842
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003843 if (rptid_entry->format == 0) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003844 /* loop */
Quinn Tranec7193e2017-03-15 09:48:55 -07003845 ql_dbg(ql_dbg_async, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003846 "Format 0 : Number of VPs setup %d, number of "
Quinn Tran41dc5292017-01-19 22:28:03 -08003847 "VPs acquired %d.\n", rptid_entry->vp_setup,
3848 rptid_entry->vp_acquired);
Quinn Tranec7193e2017-03-15 09:48:55 -07003849 ql_dbg(ql_dbg_async, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003850 "Primary port id %02x%02x%02x.\n",
3851 rptid_entry->port_id[2], rptid_entry->port_id[1],
3852 rptid_entry->port_id[0]);
Quinn Tran9cd883f2017-12-28 12:33:24 -08003853 ha->current_topology = ISP_CFG_NL;
Quinn Tran482c9dc2017-03-15 09:48:54 -07003854 qlt_update_host_map(vha, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003855
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003856 } else if (rptid_entry->format == 1) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003857 /* fabric */
Quinn Tranec7193e2017-03-15 09:48:55 -07003858 ql_dbg(ql_dbg_async, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003859 "Format 1: VP[%d] enabled - status %d - with "
Quinn Tran41dc5292017-01-19 22:28:03 -08003860 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3861 rptid_entry->vp_status,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003862 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003863 rptid_entry->port_id[0]);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003864 ql_dbg(ql_dbg_async, vha, 0x5075,
3865 "Format 1: Remote WWPN %8phC.\n",
3866 rptid_entry->u.f1.port_name);
3867
3868 ql_dbg(ql_dbg_async, vha, 0x5075,
3869 "Format 1: WWPN %8phC.\n",
3870 vha->port_name);
3871
Quinn Tran8777e432018-08-02 13:16:57 -07003872 switch (rptid_entry->u.f1.flags & TOPO_MASK) {
3873 case TOPO_N2N:
3874 ha->current_topology = ISP_CFG_N;
3875 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
3876 fcport = qla2x00_find_fcport_by_wwpn(vha,
3877 rptid_entry->u.f1.port_name, 1);
3878 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
3879
3880 if (fcport) {
3881 fcport->plogi_nack_done_deadline = jiffies + HZ;
3882 fcport->dm_login_expire = jiffies + 3*HZ;
3883 fcport->scan_state = QLA_FCPORT_FOUND;
3884 switch (fcport->disc_state) {
3885 case DSC_DELETED:
3886 set_bit(RELOGIN_NEEDED,
3887 &vha->dpc_flags);
3888 break;
3889 case DSC_DELETE_PEND:
3890 break;
3891 default:
3892 qlt_schedule_sess_for_deletion(fcport);
3893 break;
3894 }
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003895 } else {
Quinn Tran8777e432018-08-02 13:16:57 -07003896 id.b24 = 0;
3897 if (wwn_to_u64(vha->port_name) >
3898 wwn_to_u64(rptid_entry->u.f1.port_name)) {
3899 vha->d_id.b24 = 0;
3900 vha->d_id.b.al_pa = 1;
3901 ha->flags.n2n_bigger = 1;
3902
3903 id.b.al_pa = 2;
3904 ql_dbg(ql_dbg_async, vha, 0x5075,
3905 "Format 1: assign local id %x remote id %x\n",
3906 vha->d_id.b24, id.b24);
3907 } else {
3908 ql_dbg(ql_dbg_async, vha, 0x5075,
3909 "Format 1: Remote login - Waiting for WWPN %8phC.\n",
3910 rptid_entry->u.f1.port_name);
3911 ha->flags.n2n_bigger = 0;
3912 }
3913 qla24xx_post_newsess_work(vha, &id,
3914 rptid_entry->u.f1.port_name,
3915 rptid_entry->u.f1.node_name,
3916 NULL,
3917 FC4_TYPE_UNKNOWN);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003918 }
3919
Quinn Tran8777e432018-08-02 13:16:57 -07003920 /* if our portname is higher then initiate N2N login */
3921
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003922 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
Darren Trapp1763c1f2018-03-20 23:09:34 -07003923 ha->flags.n2n_ae = 1;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003924 return;
Quinn Tran8777e432018-08-02 13:16:57 -07003925 break;
3926 case TOPO_FL:
3927 ha->current_topology = ISP_CFG_FL;
3928 break;
3929 case TOPO_F:
3930 ha->current_topology = ISP_CFG_F;
3931 break;
3932 default:
3933 break;
Duane Grigsbyedd05de2017-10-13 09:34:06 -07003934 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003935
Quinn Tran9cd883f2017-12-28 12:33:24 -08003936 ha->flags.gpsc_supported = 1;
3937 ha->current_topology = ISP_CFG_F;
Sawan Chandak969a6192016-01-27 12:03:32 -05003938 /* buffer to buffer credit flag */
Quinn Tran41dc5292017-01-19 22:28:03 -08003939 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
Sawan Chandak969a6192016-01-27 12:03:32 -05003940
Quinn Tran41dc5292017-01-19 22:28:03 -08003941 if (rptid_entry->vp_idx == 0) {
3942 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3943 /* FA-WWN is only for physical port */
3944 if (qla_ini_mode_enabled(vha) &&
3945 ha->flags.fawwpn_enabled &&
3946 (rptid_entry->u.f1.flags &
Sawan Chandakfcc5b5c2017-08-23 15:05:02 -07003947 BIT_6)) {
Quinn Tran41dc5292017-01-19 22:28:03 -08003948 memcpy(vha->port_name,
3949 rptid_entry->u.f1.port_name,
3950 WWN_SIZE);
3951 }
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003952
Quinn Tran482c9dc2017-03-15 09:48:54 -07003953 qlt_update_host_map(vha, id);
Joe Carnuccio7c9c4762014-09-25 05:16:47 -04003954 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003955
Quinn Tran41dc5292017-01-19 22:28:03 -08003956 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3957 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3958 } else {
3959 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3960 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3961 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3962 "Could not acquire ID for VP[%d].\n",
3963 rptid_entry->vp_idx);
3964 return;
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003965 }
Quinn Tran41dc5292017-01-19 22:28:03 -08003966
3967 found = 0;
3968 spin_lock_irqsave(&ha->vport_slock, flags);
3969 list_for_each_entry(vp, &ha->vp_list, list) {
3970 if (rptid_entry->vp_idx == vp->vp_idx) {
3971 found = 1;
3972 break;
3973 }
3974 }
3975 spin_unlock_irqrestore(&ha->vport_slock, flags);
3976
3977 if (!found)
3978 return;
3979
Quinn Tran482c9dc2017-03-15 09:48:54 -07003980 qlt_update_host_map(vp, id);
Quinn Tran41dc5292017-01-19 22:28:03 -08003981
3982 /*
3983 * Cannot configure here as we are still sitting on the
3984 * response queue. Handle it in dpc context.
3985 */
3986 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3987 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3988 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
Andrew Vasquez4ac8d4ca2013-02-08 01:57:58 -05003989 }
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003990 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003991 qla2xxx_wake_dpc(vha);
Quinn Tran41dc5292017-01-19 22:28:03 -08003992 } else if (rptid_entry->format == 2) {
Quinn Tran83548fe2017-06-02 09:12:01 -07003993 ql_dbg(ql_dbg_async, vha, 0x505f,
Quinn Tran41dc5292017-01-19 22:28:03 -08003994 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3995 rptid_entry->port_id[2], rptid_entry->port_id[1],
3996 rptid_entry->port_id[0]);
3997
Quinn Tran83548fe2017-06-02 09:12:01 -07003998 ql_dbg(ql_dbg_async, vha, 0x5075,
Quinn Tran41dc5292017-01-19 22:28:03 -08003999 "N2N: Remote WWPN %8phC.\n",
4000 rptid_entry->u.f2.port_name);
4001
4002 /* N2N. direct connect */
Quinn Tran9cd883f2017-12-28 12:33:24 -08004003 ha->current_topology = ISP_CFG_N;
4004 ha->flags.rida_fmt2 = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004005 vha->d_id.b.domain = rptid_entry->port_id[2];
4006 vha->d_id.b.area = rptid_entry->port_id[1];
4007 vha->d_id.b.al_pa = rptid_entry->port_id[0];
4008
Darren Trapp1763c1f2018-03-20 23:09:34 -07004009 ha->flags.n2n_ae = 1;
Quinn Tran41dc5292017-01-19 22:28:03 -08004010 spin_lock_irqsave(&ha->vport_slock, flags);
4011 qlt_update_vp_map(vha, SET_AL_PA);
4012 spin_unlock_irqrestore(&ha->vport_slock, flags);
Quinn Tran9cd883f2017-12-28 12:33:24 -08004013
4014 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4015 fcport->scan_state = QLA_FCPORT_SCAN;
4016 }
4017
4018 fcport = qla2x00_find_fcport_by_wwpn(vha,
4019 rptid_entry->u.f2.port_name, 1);
4020
4021 if (fcport) {
Quinn Tran23dd98a2018-08-02 13:16:45 -07004022 fcport->login_retry = vha->hw->login_retry_count;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004023 fcport->plogi_nack_done_deadline = jiffies + HZ;
4024 fcport->scan_state = QLA_FCPORT_FOUND;
Quinn Tran9cd883f2017-12-28 12:33:24 -08004025 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004026 }
4027}
4028
4029/*
4030 * qla24xx_modify_vp_config
4031 * Change VP configuration for vha
4032 *
4033 * Input:
4034 * vha = adapter block pointer.
4035 *
4036 * Returns:
4037 * qla2xxx local function return status code.
4038 *
4039 * Context:
4040 * Kernel context.
4041 */
4042int
4043qla24xx_modify_vp_config(scsi_qla_host_t *vha)
4044{
4045 int rval;
4046 struct vp_config_entry_24xx *vpmod;
4047 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004048 struct qla_hw_data *ha = vha->hw;
4049 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004050
4051 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004052
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004053 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
4054 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004055
Thomas Meyer08eb7f42017-09-21 08:15:26 +02004056 vpmod = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004057 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004058 ql_log(ql_log_warn, vha, 0x10bc,
4059 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004060 return QLA_MEMORY_ALLOC_FAILED;
4061 }
4062
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004063 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
4064 vpmod->entry_count = 1;
4065 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
4066 vpmod->vp_count = 1;
4067 vpmod->vp_index1 = vha->vp_idx;
4068 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04004069
4070 qlt_modify_vp_config(vha, vpmod);
4071
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004072 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
4073 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
4074 vpmod->entry_count = 1;
4075
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004076 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004077 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004078 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
4079 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004080 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004081 ql_dbg(ql_dbg_mbx, vha, 0x10be,
4082 "Failed to complete IOCB -- error status (%x).\n",
4083 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004084 rval = QLA_FUNCTION_FAILED;
Bart Van Asschead950362015-07-09 07:24:08 -07004085 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004086 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
4087 "Failed to complete IOCB -- completion status (%x).\n",
4088 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004089 rval = QLA_FUNCTION_FAILED;
4090 } else {
4091 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004092 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
4093 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004094 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
4095 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004096 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004097
4098 return rval;
4099}
4100
4101/*
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004102 * qla2x00_send_change_request
4103 * Receive or disable RSCN request from fabric controller
4104 *
4105 * Input:
4106 * ha = adapter block pointer
4107 * format = registration format:
4108 * 0 - Reserved
4109 * 1 - Fabric detected registration
4110 * 2 - N_port detected registration
4111 * 3 - Full registration
4112 * FF - clear registration
4113 * vp_idx = Virtual port index
4114 *
4115 * Returns:
4116 * qla2x00 local function return status code.
4117 *
4118 * Context:
4119 * Kernel Context
4120 */
4121
4122int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004123qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004124 uint16_t vp_idx)
4125{
4126 int rval;
4127 mbx_cmd_t mc;
4128 mbx_cmd_t *mcp = &mc;
4129
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004130 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
4131 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004132
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004133 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
4134 mcp->mb[1] = format;
4135 mcp->mb[9] = vp_idx;
4136 mcp->out_mb = MBX_9|MBX_1|MBX_0;
4137 mcp->in_mb = MBX_0|MBX_1;
4138 mcp->tov = MBX_TOV_SECONDS;
4139 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004140 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004141
4142 if (rval == QLA_SUCCESS) {
4143 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
4144 rval = BIT_1;
4145 }
4146 } else
4147 rval = BIT_1;
4148
4149 return rval;
4150}
Andrew Vasquez338c9162007-09-20 14:07:33 -07004151
4152int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004153qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07004154 uint32_t size)
4155{
4156 int rval;
4157 mbx_cmd_t mc;
4158 mbx_cmd_t *mcp = &mc;
4159
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
4161 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004162
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004163 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004164 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
4165 mcp->mb[8] = MSW(addr);
4166 mcp->out_mb = MBX_8|MBX_0;
4167 } else {
4168 mcp->mb[0] = MBC_DUMP_RISC_RAM;
4169 mcp->out_mb = MBX_0;
4170 }
4171 mcp->mb[1] = LSW(addr);
4172 mcp->mb[2] = MSW(req_dma);
4173 mcp->mb[3] = LSW(req_dma);
4174 mcp->mb[6] = MSW(MSD(req_dma));
4175 mcp->mb[7] = LSW(MSD(req_dma));
4176 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004177 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07004178 mcp->mb[4] = MSW(size);
4179 mcp->mb[5] = LSW(size);
4180 mcp->out_mb |= MBX_5|MBX_4;
4181 } else {
4182 mcp->mb[4] = LSW(size);
4183 mcp->out_mb |= MBX_4;
4184 }
4185
4186 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07004187 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07004188 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004189 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004190
4191 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004192 ql_dbg(ql_dbg_mbx, vha, 0x1008,
4193 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004194 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004195 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
4196 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07004197 }
4198
4199 return rval;
4200}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004201/* 84XX Support **************************************************************/
4202
4203struct cs84xx_mgmt_cmd {
4204 union {
4205 struct verify_chip_entry_84xx req;
4206 struct verify_chip_rsp_84xx rsp;
4207 } p;
4208};
4209
4210int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004211qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004212{
4213 int rval, retry;
4214 struct cs84xx_mgmt_cmd *mn;
4215 dma_addr_t mn_dma;
4216 uint16_t options;
4217 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004218 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004219
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004220 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4221 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004222
4223 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4224 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004225 return QLA_MEMORY_ALLOC_FAILED;
4226 }
4227
4228 /* Force Update? */
4229 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4230 /* Diagnostic firmware? */
4231 /* options |= MENLO_DIAG_FW; */
4232 /* We update the firmware with only one data sequence. */
4233 options |= VCO_END_OF_DATA;
4234
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004235 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07004236 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004237 memset(mn, 0, sizeof(*mn));
4238 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4239 mn->p.req.entry_count = 1;
4240 mn->p.req.options = cpu_to_le16(options);
4241
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004242 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4243 "Dump of Verify Request.\n");
4244 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4245 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004246
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08004247 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004248 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004249 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4250 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251 goto verify_done;
4252 }
4253
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004254 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4255 "Dump of Verify Response.\n");
4256 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4257 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004258
4259 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4260 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4261 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004262 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004263 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004264
4265 if (status[0] != CS_COMPLETE) {
4266 rval = QLA_FUNCTION_FAILED;
4267 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004268 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4269 "Firmware update failed. Retrying "
4270 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004271 options |= VCO_DONT_UPDATE_FW;
4272 options &= ~VCO_FORCE_UPDATE;
4273 retry = 1;
4274 }
4275 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004276 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004277 "Firmware updated to %x.\n",
4278 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004279
4280 /* NOTE: we only update OP firmware. */
4281 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4282 ha->cs84xx->op_fw_version =
4283 le32_to_cpu(mn->p.rsp.fw_ver);
4284 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4285 flags);
4286 }
4287 } while (retry);
4288
4289verify_done:
4290 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4291
4292 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004293 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4294 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004295 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004296 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4297 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004298 }
4299
4300 return rval;
4301}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004302
4303int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004304qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004305{
4306 int rval;
4307 unsigned long flags;
4308 mbx_cmd_t mc;
4309 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004310 struct qla_hw_data *ha = vha->hw;
4311
Quinn Tran45235022018-07-18 14:29:53 -07004312 if (!ha->flags.fw_started)
4313 return QLA_SUCCESS;
4314
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004315 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4316 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004317
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004318 if (IS_SHADOW_REG_CAPABLE(ha))
4319 req->options |= BIT_13;
4320
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004321 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004322 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004323 mcp->mb[2] = MSW(LSD(req->dma));
4324 mcp->mb[3] = LSW(LSD(req->dma));
4325 mcp->mb[6] = MSW(MSD(req->dma));
4326 mcp->mb[7] = LSW(MSD(req->dma));
4327 mcp->mb[5] = req->length;
4328 if (req->rsp)
4329 mcp->mb[10] = req->rsp->id;
4330 mcp->mb[12] = req->qos;
4331 mcp->mb[11] = req->vp_idx;
4332 mcp->mb[13] = req->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004333 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004334 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004335
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004336 mcp->mb[4] = req->id;
4337 /* que in ptr index */
4338 mcp->mb[8] = 0;
4339 /* que out ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004340 mcp->mb[9] = *req->out_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004341 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4342 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4343 mcp->in_mb = MBX_0;
4344 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004345 mcp->tov = MBX_TOV_SECONDS * 2;
4346
Chad Dupuisf73cb692014-02-26 04:15:06 -05004347 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004348 mcp->in_mb |= MBX_1;
Joe Carnuccioba4828b2014-04-11 16:54:10 -04004349 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004350 mcp->out_mb |= MBX_15;
4351 /* debug q create issue in SR-IOV */
4352 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4353 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004354
4355 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004356 if (!(req->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004357 WRT_REG_DWORD(req->req_q_in, 0);
Joe Carnuccio29db41c2014-04-11 16:54:09 -04004358 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004359 WRT_REG_DWORD(req->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004360 }
4361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4362
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004363 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004364 if (rval != QLA_SUCCESS) {
4365 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4366 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4367 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004368 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4369 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004370 }
4371
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004372 return rval;
4373}
4374
4375int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004376qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004377{
4378 int rval;
4379 unsigned long flags;
4380 mbx_cmd_t mc;
4381 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004382 struct qla_hw_data *ha = vha->hw;
4383
Quinn Tran45235022018-07-18 14:29:53 -07004384 if (!ha->flags.fw_started)
4385 return QLA_SUCCESS;
4386
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004387 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4388 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004389
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004390 if (IS_SHADOW_REG_CAPABLE(ha))
4391 rsp->options |= BIT_13;
4392
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004393 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004394 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004395 mcp->mb[2] = MSW(LSD(rsp->dma));
4396 mcp->mb[3] = LSW(LSD(rsp->dma));
4397 mcp->mb[6] = MSW(MSD(rsp->dma));
4398 mcp->mb[7] = LSW(MSD(rsp->dma));
4399 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08004400 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004401 mcp->mb[13] = rsp->rid;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004402 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004403 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004404
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004405 mcp->mb[4] = rsp->id;
4406 /* que in ptr index */
Joe Carnuccio7c6300e2014-04-11 16:54:37 -04004407 mcp->mb[8] = *rsp->in_ptr = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004408 /* que out ptr index */
4409 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004410 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004411 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4412 mcp->in_mb = MBX_0;
4413 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004414 mcp->tov = MBX_TOV_SECONDS * 2;
4415
4416 if (IS_QLA81XX(ha)) {
4417 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4418 mcp->in_mb |= MBX_1;
Chad Dupuisf73cb692014-02-26 04:15:06 -05004419 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004420 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4421 mcp->in_mb |= MBX_1;
4422 /* debug q create issue in SR-IOV */
4423 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4424 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004425
4426 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004427 if (!(rsp->options & BIT_0)) {
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004428 WRT_REG_DWORD(rsp->rsp_q_out, 0);
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04004429 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Andrew Vasquezda9b1d52013-08-27 01:37:30 -04004430 WRT_REG_DWORD(rsp->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004431 }
4432
4433 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4434
Anirban Chakraborty17d98632008-12-18 10:06:15 -08004435 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004436 if (rval != QLA_SUCCESS) {
4437 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4438 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4439 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004440 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4441 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004442 }
4443
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004444 return rval;
4445}
4446
Andrew Vasquez8a659572009-02-08 20:50:12 -08004447int
4448qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4449{
4450 int rval;
4451 mbx_cmd_t mc;
4452 mbx_cmd_t *mcp = &mc;
4453
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004454 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4455 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004456
4457 mcp->mb[0] = MBC_IDC_ACK;
4458 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4459 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4460 mcp->in_mb = MBX_0;
4461 mcp->tov = MBX_TOV_SECONDS;
4462 mcp->flags = 0;
4463 rval = qla2x00_mailbox_command(vha, mcp);
4464
4465 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004466 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4467 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004468 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004469 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4470 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08004471 }
4472
4473 return rval;
4474}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004475
4476int
4477qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4478{
4479 int rval;
4480 mbx_cmd_t mc;
4481 mbx_cmd_t *mcp = &mc;
4482
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004483 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4484 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004485
Chad Dupuisf73cb692014-02-26 04:15:06 -05004486 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4487 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004488 return QLA_FUNCTION_FAILED;
4489
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004490 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4491 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4492 mcp->out_mb = MBX_1|MBX_0;
4493 mcp->in_mb = MBX_1|MBX_0;
4494 mcp->tov = MBX_TOV_SECONDS;
4495 mcp->flags = 0;
4496 rval = qla2x00_mailbox_command(vha, mcp);
4497
4498 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004499 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4500 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4501 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004502 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4504 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004505 *sector_size = mcp->mb[1];
4506 }
4507
4508 return rval;
4509}
4510
4511int
4512qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4513{
4514 int rval;
4515 mbx_cmd_t mc;
4516 mbx_cmd_t *mcp = &mc;
4517
Chad Dupuisf73cb692014-02-26 04:15:06 -05004518 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4519 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004520 return QLA_FUNCTION_FAILED;
4521
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004522 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4523 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004524
4525 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4526 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4527 FAC_OPT_CMD_WRITE_PROTECT;
4528 mcp->out_mb = MBX_1|MBX_0;
4529 mcp->in_mb = MBX_1|MBX_0;
4530 mcp->tov = MBX_TOV_SECONDS;
4531 mcp->flags = 0;
4532 rval = qla2x00_mailbox_command(vha, mcp);
4533
4534 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004535 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4536 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4537 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004538 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004539 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4540 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004541 }
4542
4543 return rval;
4544}
4545
4546int
4547qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4548{
4549 int rval;
4550 mbx_cmd_t mc;
4551 mbx_cmd_t *mcp = &mc;
4552
Chad Dupuisf73cb692014-02-26 04:15:06 -05004553 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4554 !IS_QLA27XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004555 return QLA_FUNCTION_FAILED;
4556
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004557 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4558 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004559
4560 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4561 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4562 mcp->mb[2] = LSW(start);
4563 mcp->mb[3] = MSW(start);
4564 mcp->mb[4] = LSW(finish);
4565 mcp->mb[5] = MSW(finish);
4566 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4567 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4568 mcp->tov = MBX_TOV_SECONDS;
4569 mcp->flags = 0;
4570 rval = qla2x00_mailbox_command(vha, mcp);
4571
4572 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004573 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4574 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4575 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004576 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004577 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4578 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07004579 }
4580
4581 return rval;
4582}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004583
4584int
4585qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4586{
4587 int rval = 0;
4588 mbx_cmd_t mc;
4589 mbx_cmd_t *mcp = &mc;
4590
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004591 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4592 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004593
4594 mcp->mb[0] = MBC_RESTART_MPI_FW;
4595 mcp->out_mb = MBX_0;
4596 mcp->in_mb = MBX_0|MBX_1;
4597 mcp->tov = MBX_TOV_SECONDS;
4598 mcp->flags = 0;
4599 rval = qla2x00_mailbox_command(vha, mcp);
4600
4601 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004602 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4603 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4604 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004605 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004606 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4607 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07004608 }
4609
4610 return rval;
4611}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004612
Joe Carnuccioc46e65c2013-08-27 01:37:35 -04004613int
4614qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4615{
4616 int rval;
4617 mbx_cmd_t mc;
4618 mbx_cmd_t *mcp = &mc;
4619 int i;
4620 int len;
4621 uint16_t *str;
4622 struct qla_hw_data *ha = vha->hw;
4623
4624 if (!IS_P3P_TYPE(ha))
4625 return QLA_FUNCTION_FAILED;
4626
4627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4628 "Entered %s.\n", __func__);
4629
4630 str = (void *)version;
4631 len = strlen(version);
4632
4633 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4634 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4635 mcp->out_mb = MBX_1|MBX_0;
4636 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4637 mcp->mb[i] = cpu_to_le16p(str);
4638 mcp->out_mb |= 1<<i;
4639 }
4640 for (; i < 16; i++) {
4641 mcp->mb[i] = 0;
4642 mcp->out_mb |= 1<<i;
4643 }
4644 mcp->in_mb = MBX_1|MBX_0;
4645 mcp->tov = MBX_TOV_SECONDS;
4646 mcp->flags = 0;
4647 rval = qla2x00_mailbox_command(vha, mcp);
4648
4649 if (rval != QLA_SUCCESS) {
4650 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4651 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4652 } else {
4653 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4654 "Done %s.\n", __func__);
4655 }
4656
4657 return rval;
4658}
4659
4660int
4661qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4662{
4663 int rval;
4664 mbx_cmd_t mc;
4665 mbx_cmd_t *mcp = &mc;
4666 int len;
4667 uint16_t dwlen;
4668 uint8_t *str;
4669 dma_addr_t str_dma;
4670 struct qla_hw_data *ha = vha->hw;
4671
4672 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4673 IS_P3P_TYPE(ha))
4674 return QLA_FUNCTION_FAILED;
4675
4676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4677 "Entered %s.\n", __func__);
4678
4679 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4680 if (!str) {
4681 ql_log(ql_log_warn, vha, 0x117f,
4682 "Failed to allocate driver version param.\n");
4683 return QLA_MEMORY_ALLOC_FAILED;
4684 }
4685
4686 memcpy(str, "\x7\x3\x11\x0", 4);
4687 dwlen = str[0];
4688 len = dwlen * 4 - 4;
4689 memset(str + 4, 0, len);
4690 if (len > strlen(version))
4691 len = strlen(version);
4692 memcpy(str + 4, version, len);
4693
4694 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4695 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4696 mcp->mb[2] = MSW(LSD(str_dma));
4697 mcp->mb[3] = LSW(LSD(str_dma));
4698 mcp->mb[6] = MSW(MSD(str_dma));
4699 mcp->mb[7] = LSW(MSD(str_dma));
4700 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4701 mcp->in_mb = MBX_1|MBX_0;
4702 mcp->tov = MBX_TOV_SECONDS;
4703 mcp->flags = 0;
4704 rval = qla2x00_mailbox_command(vha, mcp);
4705
4706 if (rval != QLA_SUCCESS) {
4707 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4708 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4709 } else {
4710 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4711 "Done %s.\n", __func__);
4712 }
4713
4714 dma_pool_free(ha->s_dma_pool, str, str_dma);
4715
4716 return rval;
4717}
4718
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004719int
4720qla24xx_get_port_login_templ(scsi_qla_host_t *vha, dma_addr_t buf_dma,
4721 void *buf, uint16_t bufsiz)
4722{
4723 int rval, i;
4724 mbx_cmd_t mc;
4725 mbx_cmd_t *mcp = &mc;
4726 uint32_t *bp;
4727
4728 if (!IS_FWI2_CAPABLE(vha->hw))
4729 return QLA_FUNCTION_FAILED;
4730
4731 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4732 "Entered %s.\n", __func__);
4733
4734 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4735 mcp->mb[1] = RNID_TYPE_PORT_LOGIN << 8;
4736 mcp->mb[2] = MSW(buf_dma);
4737 mcp->mb[3] = LSW(buf_dma);
4738 mcp->mb[6] = MSW(MSD(buf_dma));
4739 mcp->mb[7] = LSW(MSD(buf_dma));
4740 mcp->mb[8] = bufsiz/4;
4741 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4742 mcp->in_mb = MBX_1|MBX_0;
4743 mcp->tov = MBX_TOV_SECONDS;
4744 mcp->flags = 0;
4745 rval = qla2x00_mailbox_command(vha, mcp);
4746
4747 if (rval != QLA_SUCCESS) {
4748 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4749 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4750 } else {
4751 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4752 "Done %s.\n", __func__);
4753 bp = (uint32_t *) buf;
4754 for (i = 0; i < (bufsiz-4)/4; i++, bp++)
Quinn Tran8777e432018-08-02 13:16:57 -07004755 *bp = le32_to_cpu(*bp);
Duane Grigsbyedd05de2017-10-13 09:34:06 -07004756 }
4757
4758 return rval;
4759}
4760
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05004761static int
4762qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4763{
4764 int rval;
4765 mbx_cmd_t mc;
4766 mbx_cmd_t *mcp = &mc;
4767
4768 if (!IS_FWI2_CAPABLE(vha->hw))
4769 return QLA_FUNCTION_FAILED;
4770
4771 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4772 "Entered %s.\n", __func__);
4773
4774 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4775 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4776 mcp->out_mb = MBX_1|MBX_0;
4777 mcp->in_mb = MBX_1|MBX_0;
4778 mcp->tov = MBX_TOV_SECONDS;
4779 mcp->flags = 0;
4780 rval = qla2x00_mailbox_command(vha, mcp);
4781 *temp = mcp->mb[1];
4782
4783 if (rval != QLA_SUCCESS) {
4784 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4785 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4786 } else {
4787 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4788 "Done %s.\n", __func__);
4789 }
4790
4791 return rval;
4792}
4793
Joe Carnuccio3a117112013-02-08 01:58:00 -05004794int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004795qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4796 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004797{
4798 int rval;
4799 mbx_cmd_t mc;
4800 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004801 struct qla_hw_data *ha = vha->hw;
4802
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004803 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4804 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004805
Joe Carnuccio6766df92011-05-10 11:30:15 -07004806 if (!IS_FWI2_CAPABLE(ha))
4807 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004808
Joe Carnuccio6766df92011-05-10 11:30:15 -07004809 if (len == 1)
4810 opt |= BIT_0;
4811
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004812 mcp->mb[0] = MBC_READ_SFP;
4813 mcp->mb[1] = dev;
4814 mcp->mb[2] = MSW(sfp_dma);
4815 mcp->mb[3] = LSW(sfp_dma);
4816 mcp->mb[6] = MSW(MSD(sfp_dma));
4817 mcp->mb[7] = LSW(MSD(sfp_dma));
4818 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004819 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004820 mcp->mb[10] = opt;
4821 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 -07004822 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004823 mcp->tov = MBX_TOV_SECONDS;
4824 mcp->flags = 0;
4825 rval = qla2x00_mailbox_command(vha, mcp);
4826
4827 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004828 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004829
4830 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004831 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4832 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Quinn Trane4e3a2c2017-08-23 15:05:07 -07004833 if (mcp->mb[0] == MBS_COMMAND_ERROR &&
4834 mcp->mb[1] == 0x22)
4835 /* sfp is not there */
4836 rval = QLA_INTERFACE_ERROR;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004837 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004838 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4839 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004840 }
4841
4842 return rval;
4843}
4844
4845int
Joe Carnuccio6766df92011-05-10 11:30:15 -07004846qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4847 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004848{
4849 int rval;
4850 mbx_cmd_t mc;
4851 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004852 struct qla_hw_data *ha = vha->hw;
4853
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004854 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4855 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004856
Joe Carnuccio6766df92011-05-10 11:30:15 -07004857 if (!IS_FWI2_CAPABLE(ha))
4858 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004859
Joe Carnuccio6766df92011-05-10 11:30:15 -07004860 if (len == 1)
4861 opt |= BIT_0;
4862
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004863 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07004864 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004865
4866 mcp->mb[0] = MBC_WRITE_SFP;
4867 mcp->mb[1] = dev;
4868 mcp->mb[2] = MSW(sfp_dma);
4869 mcp->mb[3] = LSW(sfp_dma);
4870 mcp->mb[6] = MSW(MSD(sfp_dma));
4871 mcp->mb[7] = LSW(MSD(sfp_dma));
4872 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07004873 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004874 mcp->mb[10] = opt;
4875 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 -07004876 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004877 mcp->tov = MBX_TOV_SECONDS;
4878 mcp->flags = 0;
4879 rval = qla2x00_mailbox_command(vha, mcp);
4880
4881 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004882 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4883 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004884 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4886 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07004887 }
4888
4889 return rval;
4890}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004891
4892int
4893qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4894 uint16_t size_in_bytes, uint16_t *actual_size)
4895{
4896 int rval;
4897 mbx_cmd_t mc;
4898 mbx_cmd_t *mcp = &mc;
4899
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004900 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4901 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004902
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004903 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004904 return QLA_FUNCTION_FAILED;
4905
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004906 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4907 mcp->mb[2] = MSW(stats_dma);
4908 mcp->mb[3] = LSW(stats_dma);
4909 mcp->mb[6] = MSW(MSD(stats_dma));
4910 mcp->mb[7] = LSW(MSD(stats_dma));
4911 mcp->mb[8] = size_in_bytes >> 2;
4912 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4913 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4914 mcp->tov = MBX_TOV_SECONDS;
4915 mcp->flags = 0;
4916 rval = qla2x00_mailbox_command(vha, mcp);
4917
4918 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004919 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4920 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4921 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004922 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004923 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4924 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004925
Andrew Vasquezce0423f2009-06-03 09:55:13 -07004926
4927 *actual_size = mcp->mb[2] << 2;
4928 }
4929
4930 return rval;
4931}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004932
4933int
4934qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4935 uint16_t size)
4936{
4937 int rval;
4938 mbx_cmd_t mc;
4939 mbx_cmd_t *mcp = &mc;
4940
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004941 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4942 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004943
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004944 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004945 return QLA_FUNCTION_FAILED;
4946
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004947 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4948 mcp->mb[1] = 0;
4949 mcp->mb[2] = MSW(tlv_dma);
4950 mcp->mb[3] = LSW(tlv_dma);
4951 mcp->mb[6] = MSW(MSD(tlv_dma));
4952 mcp->mb[7] = LSW(MSD(tlv_dma));
4953 mcp->mb[8] = size;
4954 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4955 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4956 mcp->tov = MBX_TOV_SECONDS;
4957 mcp->flags = 0;
4958 rval = qla2x00_mailbox_command(vha, mcp);
4959
4960 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004961 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4962 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4963 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004964 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004965 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4966 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004967 }
4968
4969 return rval;
4970}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004971
4972int
4973qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4974{
4975 int rval;
4976 mbx_cmd_t mc;
4977 mbx_cmd_t *mcp = &mc;
4978
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004979 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4980 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004981
Andrew Vasquez18e75552009-06-03 09:55:30 -07004982 if (!IS_FWI2_CAPABLE(vha->hw))
4983 return QLA_FUNCTION_FAILED;
4984
Andrew Vasquez18e75552009-06-03 09:55:30 -07004985 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4986 mcp->mb[1] = LSW(risc_addr);
4987 mcp->mb[8] = MSW(risc_addr);
4988 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4989 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4990 mcp->tov = 30;
4991 mcp->flags = 0;
4992 rval = qla2x00_mailbox_command(vha, mcp);
4993 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004994 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4995 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004996 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004997 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4998 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004999 *data = mcp->mb[3] << 16 | mcp->mb[2];
5000 }
5001
5002 return rval;
5003}
5004
5005int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005006qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5007 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005008{
5009 int rval;
5010 mbx_cmd_t mc;
5011 mbx_cmd_t *mcp = &mc;
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005012
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005013 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
5014 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005015
5016 memset(mcp->mb, 0 , sizeof(mcp->mb));
5017 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
5018 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
5019
5020 /* transfer count */
5021 mcp->mb[10] = LSW(mreq->transfer_size);
5022 mcp->mb[11] = MSW(mreq->transfer_size);
5023
5024 /* send data address */
5025 mcp->mb[14] = LSW(mreq->send_dma);
5026 mcp->mb[15] = MSW(mreq->send_dma);
5027 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5028 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5029
Lucas De Marchi25985ed2011-03-30 22:57:33 -03005030 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005031 mcp->mb[16] = LSW(mreq->rcv_dma);
5032 mcp->mb[17] = MSW(mreq->rcv_dma);
5033 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5034 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5035
5036 /* Iteration count */
Joe Carnuccio1b98b422013-03-28 08:21:26 -04005037 mcp->mb[18] = LSW(mreq->iteration_count);
5038 mcp->mb[19] = MSW(mreq->iteration_count);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005039
5040 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
5041 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 -08005042 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005043 mcp->out_mb |= MBX_2;
5044 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
5045
5046 mcp->buf_size = mreq->transfer_size;
5047 mcp->tov = MBX_TOV_SECONDS;
5048 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5049
5050 rval = qla2x00_mailbox_command(vha, mcp);
5051
5052 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005053 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
5054 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
5055 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
5056 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005057 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005058 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
5059 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005060 }
5061
5062 /* Copy mailbox information */
5063 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005064 return rval;
5065}
5066
5067int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005068qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
5069 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005070{
5071 int rval;
5072 mbx_cmd_t mc;
5073 mbx_cmd_t *mcp = &mc;
5074 struct qla_hw_data *ha = vha->hw;
5075
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005076 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
5077 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005078
5079 memset(mcp->mb, 0 , sizeof(mcp->mb));
5080 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
Joe Carnuccio1d634962017-05-24 18:06:22 -07005081 /* BIT_6 specifies 64bit address */
5082 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005083 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07005084 mcp->mb[2] = vha->fcoe_fcf_idx;
5085 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005086 mcp->mb[16] = LSW(mreq->rcv_dma);
5087 mcp->mb[17] = MSW(mreq->rcv_dma);
5088 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
5089 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
5090
5091 mcp->mb[10] = LSW(mreq->transfer_size);
5092
5093 mcp->mb[14] = LSW(mreq->send_dma);
5094 mcp->mb[15] = MSW(mreq->send_dma);
5095 mcp->mb[20] = LSW(MSD(mreq->send_dma));
5096 mcp->mb[21] = MSW(MSD(mreq->send_dma));
5097
5098 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
5099 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005100 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005101 mcp->out_mb |= MBX_2;
5102
5103 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005104 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
5105 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005106 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005107 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005108 mcp->in_mb |= MBX_3;
5109
5110 mcp->tov = MBX_TOV_SECONDS;
5111 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5112 mcp->buf_size = mreq->transfer_size;
5113
5114 rval = qla2x00_mailbox_command(vha, mcp);
5115
5116 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005117 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
5118 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5119 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005120 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005121 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
5122 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005123 }
5124
5125 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005126 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005127 return rval;
5128}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07005129
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005130int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005131qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005132{
5133 int rval;
5134 mbx_cmd_t mc;
5135 mbx_cmd_t *mcp = &mc;
5136
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005137 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005138 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005139
5140 mcp->mb[0] = MBC_ISP84XX_RESET;
5141 mcp->mb[1] = enable_diagnostic;
5142 mcp->out_mb = MBX_1|MBX_0;
5143 mcp->in_mb = MBX_1|MBX_0;
5144 mcp->tov = MBX_TOV_SECONDS;
5145 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005146 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005147
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005148 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005149 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005150 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005151 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
5152 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08005153
5154 return rval;
5155}
5156
5157int
Andrew Vasquez18e75552009-06-03 09:55:30 -07005158qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
5159{
5160 int rval;
5161 mbx_cmd_t mc;
5162 mbx_cmd_t *mcp = &mc;
5163
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005164 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
5165 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005166
Andrew Vasquez18e75552009-06-03 09:55:30 -07005167 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005168 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07005169
Andrew Vasquez18e75552009-06-03 09:55:30 -07005170 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
5171 mcp->mb[1] = LSW(risc_addr);
5172 mcp->mb[2] = LSW(data);
5173 mcp->mb[3] = MSW(data);
5174 mcp->mb[8] = MSW(risc_addr);
5175 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
5176 mcp->in_mb = MBX_0;
5177 mcp->tov = 30;
5178 mcp->flags = 0;
5179 rval = qla2x00_mailbox_command(vha, mcp);
5180 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005181 ql_dbg(ql_dbg_mbx, vha, 0x1101,
5182 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005183 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005184 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
5185 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07005186 }
5187
5188 return rval;
5189}
Michael Hernandez3064ff32009-12-15 21:29:44 -08005190
5191int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005192qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
5193{
5194 int rval;
5195 uint32_t stat, timer;
5196 uint16_t mb0 = 0;
5197 struct qla_hw_data *ha = vha->hw;
5198 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
5199
5200 rval = QLA_SUCCESS;
5201
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005202 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
5203 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005204
5205 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
5206
5207 /* Write the MBC data to the registers */
5208 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
5209 WRT_REG_WORD(&reg->mailbox1, mb[0]);
5210 WRT_REG_WORD(&reg->mailbox2, mb[1]);
5211 WRT_REG_WORD(&reg->mailbox3, mb[2]);
5212 WRT_REG_WORD(&reg->mailbox4, mb[3]);
5213
5214 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
5215
5216 /* Poll for MBC interrupt */
5217 for (timer = 6000000; timer; timer--) {
5218 /* Check for pending interrupts. */
5219 stat = RD_REG_DWORD(&reg->host_status);
5220 if (stat & HSRX_RISC_INT) {
5221 stat &= 0xff;
5222
5223 if (stat == 0x1 || stat == 0x2 ||
5224 stat == 0x10 || stat == 0x11) {
5225 set_bit(MBX_INTERRUPT,
5226 &ha->mbx_cmd_flags);
5227 mb0 = RD_REG_WORD(&reg->mailbox0);
5228 WRT_REG_DWORD(&reg->hccr,
5229 HCCRX_CLR_RISC_INT);
5230 RD_REG_DWORD(&reg->hccr);
5231 break;
5232 }
5233 }
5234 udelay(5);
5235 }
5236
5237 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
5238 rval = mb0 & MBS_MASK;
5239 else
5240 rval = QLA_FUNCTION_FAILED;
5241
5242 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005243 ql_dbg(ql_dbg_mbx, vha, 0x1104,
5244 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005245 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005246 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
5247 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005248 }
5249
5250 return rval;
5251}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005252
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005253/* Set the specified data rate */
5254int
5255qla2x00_set_data_rate(scsi_qla_host_t *vha, uint16_t mode)
5256{
5257 int rval;
5258 mbx_cmd_t mc;
5259 mbx_cmd_t *mcp = &mc;
5260 struct qla_hw_data *ha = vha->hw;
5261 uint16_t val;
5262
5263 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5264 "Entered %s speed:0x%x mode:0x%x.\n", __func__, ha->set_data_rate,
5265 mode);
5266
5267 if (!IS_FWI2_CAPABLE(ha))
5268 return QLA_FUNCTION_FAILED;
5269
5270 memset(mcp, 0, sizeof(*mcp));
5271 switch (ha->set_data_rate) {
5272 case PORT_SPEED_AUTO:
5273 case PORT_SPEED_4GB:
5274 case PORT_SPEED_8GB:
5275 case PORT_SPEED_16GB:
5276 case PORT_SPEED_32GB:
5277 val = ha->set_data_rate;
5278 break;
5279 default:
5280 ql_log(ql_log_warn, vha, 0x1199,
5281 "Unrecognized speed setting:%d. Setting Autoneg\n",
5282 ha->set_data_rate);
5283 val = ha->set_data_rate = PORT_SPEED_AUTO;
5284 break;
5285 }
5286
5287 mcp->mb[0] = MBC_DATA_RATE;
5288 mcp->mb[1] = mode;
5289 mcp->mb[2] = val;
5290
5291 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5292 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5293 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
5294 mcp->in_mb |= MBX_4|MBX_3;
5295 mcp->tov = MBX_TOV_SECONDS;
5296 mcp->flags = 0;
5297 rval = qla2x00_mailbox_command(vha, mcp);
5298 if (rval != QLA_SUCCESS) {
5299 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5300 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5301 } else {
5302 if (mcp->mb[1] != 0x7)
5303 ql_dbg(ql_dbg_mbx, vha, 0x1179,
5304 "Speed set:0x%x\n", mcp->mb[1]);
5305
5306 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5307 "Done %s.\n", __func__);
5308 }
5309
5310 return rval;
5311}
5312
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07005313int
Michael Hernandez3064ff32009-12-15 21:29:44 -08005314qla2x00_get_data_rate(scsi_qla_host_t *vha)
5315{
5316 int rval;
5317 mbx_cmd_t mc;
5318 mbx_cmd_t *mcp = &mc;
5319 struct qla_hw_data *ha = vha->hw;
5320
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005321 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
5322 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005323
Michael Hernandez3064ff32009-12-15 21:29:44 -08005324 if (!IS_FWI2_CAPABLE(ha))
5325 return QLA_FUNCTION_FAILED;
5326
Michael Hernandez3064ff32009-12-15 21:29:44 -08005327 mcp->mb[0] = MBC_DATA_RATE;
Anil Gurumurthy4910b522019-02-15 14:37:17 -08005328 mcp->mb[1] = QLA_GET_DATA_RATE;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005329 mcp->out_mb = MBX_1|MBX_0;
5330 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Chad Dupuisf73cb692014-02-26 04:15:06 -05005331 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005332 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08005333 mcp->tov = MBX_TOV_SECONDS;
5334 mcp->flags = 0;
5335 rval = qla2x00_mailbox_command(vha, mcp);
5336 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005337 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5338 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005339 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005340 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5341 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08005342 if (mcp->mb[1] != 0x7)
5343 ha->link_data_rate = mcp->mb[1];
5344 }
5345
5346 return rval;
5347}
Sarang Radke09ff7012010-03-19 17:03:59 -07005348
5349int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005350qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5351{
5352 int rval;
5353 mbx_cmd_t mc;
5354 mbx_cmd_t *mcp = &mc;
5355 struct qla_hw_data *ha = vha->hw;
5356
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005357 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5358 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005359
Chad Dupuisf73cb692014-02-26 04:15:06 -05005360 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5361 !IS_QLA27XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005362 return QLA_FUNCTION_FAILED;
5363 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5364 mcp->out_mb = MBX_0;
5365 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5366 mcp->tov = MBX_TOV_SECONDS;
5367 mcp->flags = 0;
5368
5369 rval = qla2x00_mailbox_command(vha, mcp);
5370
5371 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005372 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5373 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005374 } else {
5375 /* Copy all bits to preserve original value */
5376 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5377
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005378 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5379 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005380 }
5381 return rval;
5382}
5383
5384int
5385qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5386{
5387 int rval;
5388 mbx_cmd_t mc;
5389 mbx_cmd_t *mcp = &mc;
5390
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5392 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005393
5394 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5395 /* Copy all bits to preserve original setting */
5396 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5397 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5398 mcp->in_mb = MBX_0;
5399 mcp->tov = MBX_TOV_SECONDS;
5400 mcp->flags = 0;
5401 rval = qla2x00_mailbox_command(vha, mcp);
5402
5403 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005404 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5405 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005406 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005407 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5408 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07005409
5410 return rval;
5411}
5412
5413
5414int
Sarang Radke09ff7012010-03-19 17:03:59 -07005415qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5416 uint16_t *mb)
5417{
5418 int rval;
5419 mbx_cmd_t mc;
5420 mbx_cmd_t *mcp = &mc;
5421 struct qla_hw_data *ha = vha->hw;
5422
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005423 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5424 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005425
Sarang Radke09ff7012010-03-19 17:03:59 -07005426 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5427 return QLA_FUNCTION_FAILED;
5428
Sarang Radke09ff7012010-03-19 17:03:59 -07005429 mcp->mb[0] = MBC_PORT_PARAMS;
5430 mcp->mb[1] = loop_id;
5431 if (ha->flags.fcp_prio_enabled)
5432 mcp->mb[2] = BIT_1;
5433 else
5434 mcp->mb[2] = BIT_2;
5435 mcp->mb[4] = priority & 0xf;
5436 mcp->mb[9] = vha->vp_idx;
5437 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5438 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5439 mcp->tov = 30;
5440 mcp->flags = 0;
5441 rval = qla2x00_mailbox_command(vha, mcp);
5442 if (mb != NULL) {
5443 mb[0] = mcp->mb[0];
5444 mb[1] = mcp->mb[1];
5445 mb[3] = mcp->mb[3];
5446 mb[4] = mcp->mb[4];
5447 }
5448
5449 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005450 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07005451 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005452 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5453 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07005454 }
5455
5456 return rval;
5457}
Giridhar Malavalia9083012010-04-12 17:59:55 -07005458
5459int
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005460qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
Andrew Vasquez794a5692010-12-21 16:00:21 -08005461{
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005462 int rval = QLA_FUNCTION_FAILED;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005463 struct qla_hw_data *ha = vha->hw;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005464 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005465
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005466 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5467 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5468 "Thermal not supported by this card.\n");
5469 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08005470 }
Andrew Vasquez794a5692010-12-21 16:00:21 -08005471
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005472 if (IS_QLA25XX(ha)) {
5473 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5474 ha->pdev->subsystem_device == 0x0175) {
5475 rval = qla2x00_read_sfp(vha, 0, &byte,
5476 0x98, 0x1, 1, BIT_13|BIT_0);
5477 *temp = byte;
5478 return rval;
5479 }
5480 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5481 ha->pdev->subsystem_device == 0x338e) {
5482 rval = qla2x00_read_sfp(vha, 0, &byte,
5483 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5484 *temp = byte;
5485 return rval;
5486 }
5487 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5488 "Thermal not supported by this card.\n");
5489 return rval;
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005490 }
5491
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005492 if (IS_QLA82XX(ha)) {
5493 *temp = qla82xx_read_temperature(vha);
5494 rval = QLA_SUCCESS;
5495 return rval;
5496 } else if (IS_QLA8044(ha)) {
5497 *temp = qla8044_read_temperature(vha);
5498 rval = QLA_SUCCESS;
5499 return rval;
5500 }
Joe Carnucciofe52f6e2013-02-08 01:58:03 -05005501
Joe Carnuccio1ae47cf2013-08-27 01:37:36 -04005502 rval = qla2x00_read_asic_temperature(vha, temp);
Andrew Vasquez794a5692010-12-21 16:00:21 -08005503 return rval;
5504}
5505
5506int
Giridhar Malavalia9083012010-04-12 17:59:55 -07005507qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5508{
5509 int rval;
5510 struct qla_hw_data *ha = vha->hw;
5511 mbx_cmd_t mc;
5512 mbx_cmd_t *mcp = &mc;
5513
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005514 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5515 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005516
Giridhar Malavalia9083012010-04-12 17:59:55 -07005517 if (!IS_FWI2_CAPABLE(ha))
5518 return QLA_FUNCTION_FAILED;
5519
Giridhar Malavalia9083012010-04-12 17:59:55 -07005520 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005521 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005522 mcp->mb[1] = 1;
5523
5524 mcp->out_mb = MBX_1|MBX_0;
5525 mcp->in_mb = MBX_0;
5526 mcp->tov = 30;
5527 mcp->flags = 0;
5528
5529 rval = qla2x00_mailbox_command(vha, mcp);
5530 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005531 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5532 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005533 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005534 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5535 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005536 }
5537
5538 return rval;
5539}
5540
5541int
5542qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5543{
5544 int rval;
5545 struct qla_hw_data *ha = vha->hw;
5546 mbx_cmd_t mc;
5547 mbx_cmd_t *mcp = &mc;
5548
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005549 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5550 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005551
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005552 if (!IS_P3P_TYPE(ha))
Giridhar Malavalia9083012010-04-12 17:59:55 -07005553 return QLA_FUNCTION_FAILED;
5554
Giridhar Malavalia9083012010-04-12 17:59:55 -07005555 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05005556 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005557 mcp->mb[1] = 0;
5558
5559 mcp->out_mb = MBX_1|MBX_0;
5560 mcp->in_mb = MBX_0;
5561 mcp->tov = 30;
5562 mcp->flags = 0;
5563
5564 rval = qla2x00_mailbox_command(vha, mcp);
5565 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07005566 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5567 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005568 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5570 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07005571 }
5572
5573 return rval;
5574}
Giridhar Malavali08de2842011-08-16 11:31:44 -07005575
5576int
5577qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5578{
5579 struct qla_hw_data *ha = vha->hw;
5580 mbx_cmd_t mc;
5581 mbx_cmd_t *mcp = &mc;
5582 int rval = QLA_FUNCTION_FAILED;
5583
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005584 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5585 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005586
5587 memset(mcp->mb, 0 , sizeof(mcp->mb));
5588 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5589 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5590 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5591 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5592
5593 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5594 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5595 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5596
5597 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5598 mcp->tov = MBX_TOV_SECONDS;
5599 rval = qla2x00_mailbox_command(vha, mcp);
5600
5601 /* Always copy back return mailbox values. */
5602 if (rval != QLA_SUCCESS) {
5603 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5604 "mailbox command FAILED=0x%x, subcode=%x.\n",
5605 (mcp->mb[1] << 16) | mcp->mb[0],
5606 (mcp->mb[3] << 16) | mcp->mb[2]);
5607 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005608 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5609 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005610 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5611 if (!ha->md_template_size) {
5612 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5613 "Null template size obtained.\n");
5614 rval = QLA_FUNCTION_FAILED;
5615 }
5616 }
5617 return rval;
5618}
5619
5620int
5621qla82xx_md_get_template(scsi_qla_host_t *vha)
5622{
5623 struct qla_hw_data *ha = vha->hw;
5624 mbx_cmd_t mc;
5625 mbx_cmd_t *mcp = &mc;
5626 int rval = QLA_FUNCTION_FAILED;
5627
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005628 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5629 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005630
5631 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5632 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5633 if (!ha->md_tmplt_hdr) {
5634 ql_log(ql_log_warn, vha, 0x1124,
5635 "Unable to allocate memory for Minidump template.\n");
5636 return rval;
5637 }
5638
5639 memset(mcp->mb, 0 , sizeof(mcp->mb));
5640 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5641 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5642 mcp->mb[2] = LSW(RQST_TMPLT);
5643 mcp->mb[3] = MSW(RQST_TMPLT);
5644 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5645 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5646 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5647 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5648 mcp->mb[8] = LSW(ha->md_template_size);
5649 mcp->mb[9] = MSW(ha->md_template_size);
5650
5651 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5652 mcp->tov = MBX_TOV_SECONDS;
5653 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5654 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5655 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5656 rval = qla2x00_mailbox_command(vha, mcp);
5657
5658 if (rval != QLA_SUCCESS) {
5659 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5660 "mailbox command FAILED=0x%x, subcode=%x.\n",
5661 ((mcp->mb[1] << 16) | mcp->mb[0]),
5662 ((mcp->mb[3] << 16) | mcp->mb[2]));
5663 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005664 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5665 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07005666 return rval;
5667}
Saurav Kashyap999916d2011-08-16 11:31:45 -07005668
5669int
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005670qla8044_md_get_template(scsi_qla_host_t *vha)
5671{
5672 struct qla_hw_data *ha = vha->hw;
5673 mbx_cmd_t mc;
5674 mbx_cmd_t *mcp = &mc;
5675 int rval = QLA_FUNCTION_FAILED;
5676 int offset = 0, size = MINIDUMP_SIZE_36K;
5677 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5678 "Entered %s.\n", __func__);
5679
5680 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5681 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5682 if (!ha->md_tmplt_hdr) {
5683 ql_log(ql_log_warn, vha, 0xb11b,
5684 "Unable to allocate memory for Minidump template.\n");
5685 return rval;
5686 }
5687
5688 memset(mcp->mb, 0 , sizeof(mcp->mb));
5689 while (offset < ha->md_template_size) {
5690 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5691 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5692 mcp->mb[2] = LSW(RQST_TMPLT);
5693 mcp->mb[3] = MSW(RQST_TMPLT);
5694 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5695 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5696 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5697 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5698 mcp->mb[8] = LSW(size);
5699 mcp->mb[9] = MSW(size);
5700 mcp->mb[10] = offset & 0x0000FFFF;
5701 mcp->mb[11] = offset & 0xFFFF0000;
5702 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5703 mcp->tov = MBX_TOV_SECONDS;
5704 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5705 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5706 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5707 rval = qla2x00_mailbox_command(vha, mcp);
5708
5709 if (rval != QLA_SUCCESS) {
5710 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5711 "mailbox command FAILED=0x%x, subcode=%x.\n",
5712 ((mcp->mb[1] << 16) | mcp->mb[0]),
5713 ((mcp->mb[3] << 16) | mcp->mb[2]));
5714 return rval;
5715 } else
5716 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5717 "Done %s.\n", __func__);
5718 offset = offset + size;
5719 }
5720 return rval;
5721}
5722
5723int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005724qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5725{
5726 int rval;
5727 struct qla_hw_data *ha = vha->hw;
5728 mbx_cmd_t mc;
5729 mbx_cmd_t *mcp = &mc;
5730
5731 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5732 return QLA_FUNCTION_FAILED;
5733
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005734 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5735 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005736
5737 memset(mcp, 0, sizeof(mbx_cmd_t));
5738 mcp->mb[0] = MBC_SET_LED_CONFIG;
5739 mcp->mb[1] = led_cfg[0];
5740 mcp->mb[2] = led_cfg[1];
5741 if (IS_QLA8031(ha)) {
5742 mcp->mb[3] = led_cfg[2];
5743 mcp->mb[4] = led_cfg[3];
5744 mcp->mb[5] = led_cfg[4];
5745 mcp->mb[6] = led_cfg[5];
5746 }
5747
5748 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5749 if (IS_QLA8031(ha))
5750 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5751 mcp->in_mb = MBX_0;
5752 mcp->tov = 30;
5753 mcp->flags = 0;
5754
5755 rval = qla2x00_mailbox_command(vha, mcp);
5756 if (rval != QLA_SUCCESS) {
5757 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5758 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5759 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005760 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5761 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005762 }
5763
5764 return rval;
5765}
5766
5767int
5768qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5769{
5770 int rval;
5771 struct qla_hw_data *ha = vha->hw;
5772 mbx_cmd_t mc;
5773 mbx_cmd_t *mcp = &mc;
5774
5775 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5776 return QLA_FUNCTION_FAILED;
5777
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005778 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5779 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005780
5781 memset(mcp, 0, sizeof(mbx_cmd_t));
5782 mcp->mb[0] = MBC_GET_LED_CONFIG;
5783
5784 mcp->out_mb = MBX_0;
5785 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5786 if (IS_QLA8031(ha))
5787 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5788 mcp->tov = 30;
5789 mcp->flags = 0;
5790
5791 rval = qla2x00_mailbox_command(vha, mcp);
5792 if (rval != QLA_SUCCESS) {
5793 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5794 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5795 } else {
5796 led_cfg[0] = mcp->mb[1];
5797 led_cfg[1] = mcp->mb[2];
5798 if (IS_QLA8031(ha)) {
5799 led_cfg[2] = mcp->mb[3];
5800 led_cfg[3] = mcp->mb[4];
5801 led_cfg[4] = mcp->mb[5];
5802 led_cfg[5] = mcp->mb[6];
5803 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005804 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5805 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005806 }
5807
5808 return rval;
5809}
5810
5811int
Saurav Kashyap999916d2011-08-16 11:31:45 -07005812qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5813{
5814 int rval;
5815 struct qla_hw_data *ha = vha->hw;
5816 mbx_cmd_t mc;
5817 mbx_cmd_t *mcp = &mc;
5818
Atul Deshmukh7ec0eff2013-08-27 01:37:28 -04005819 if (!IS_P3P_TYPE(ha))
Saurav Kashyap999916d2011-08-16 11:31:45 -07005820 return QLA_FUNCTION_FAILED;
5821
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005822 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005823 "Entered %s.\n", __func__);
5824
5825 memset(mcp, 0, sizeof(mbx_cmd_t));
5826 mcp->mb[0] = MBC_SET_LED_CONFIG;
5827 if (enable)
5828 mcp->mb[7] = 0xE;
5829 else
5830 mcp->mb[7] = 0xD;
5831
5832 mcp->out_mb = MBX_7|MBX_0;
5833 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005834 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07005835 mcp->flags = 0;
5836
5837 rval = qla2x00_mailbox_command(vha, mcp);
5838 if (rval != QLA_SUCCESS) {
5839 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5840 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5841 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005842 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07005843 "Done %s.\n", __func__);
5844 }
5845
5846 return rval;
5847}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005848
5849int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005850qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005851{
5852 int rval;
5853 struct qla_hw_data *ha = vha->hw;
5854 mbx_cmd_t mc;
5855 mbx_cmd_t *mcp = &mc;
5856
Chad Dupuisf73cb692014-02-26 04:15:06 -05005857 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005858 return QLA_FUNCTION_FAILED;
5859
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005860 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5861 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005862
5863 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5864 mcp->mb[1] = LSW(reg);
5865 mcp->mb[2] = MSW(reg);
5866 mcp->mb[3] = LSW(data);
5867 mcp->mb[4] = MSW(data);
5868 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5869
5870 mcp->in_mb = MBX_1|MBX_0;
5871 mcp->tov = MBX_TOV_SECONDS;
5872 mcp->flags = 0;
5873 rval = qla2x00_mailbox_command(vha, mcp);
5874
5875 if (rval != QLA_SUCCESS) {
5876 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5877 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5878 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005879 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005880 "Done %s.\n", __func__);
5881 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005882
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08005883 return rval;
5884}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005885
5886int
5887qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5888{
5889 int rval;
5890 struct qla_hw_data *ha = vha->hw;
5891 mbx_cmd_t mc;
5892 mbx_cmd_t *mcp = &mc;
5893
5894 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005895 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005896 "Implicit LOGO Unsupported.\n");
5897 return QLA_FUNCTION_FAILED;
5898 }
5899
5900
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005901 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5902 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005903
5904 /* Perform Implicit LOGO. */
5905 mcp->mb[0] = MBC_PORT_LOGOUT;
5906 mcp->mb[1] = fcport->loop_id;
5907 mcp->mb[10] = BIT_15;
5908 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5909 mcp->in_mb = MBX_0;
5910 mcp->tov = MBX_TOV_SECONDS;
5911 mcp->flags = 0;
5912 rval = qla2x00_mailbox_command(vha, mcp);
5913 if (rval != QLA_SUCCESS)
5914 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5915 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5916 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04005917 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5918 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08005919
5920 return rval;
5921}
5922
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005923int
5924qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5925{
5926 int rval;
5927 mbx_cmd_t mc;
5928 mbx_cmd_t *mcp = &mc;
5929 struct qla_hw_data *ha = vha->hw;
5930 unsigned long retry_max_time = jiffies + (2 * HZ);
5931
Chad Dupuisf73cb692014-02-26 04:15:06 -05005932 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005933 return QLA_FUNCTION_FAILED;
5934
5935 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5936
5937retry_rd_reg:
5938 mcp->mb[0] = MBC_READ_REMOTE_REG;
5939 mcp->mb[1] = LSW(reg);
5940 mcp->mb[2] = MSW(reg);
5941 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5942 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5943 mcp->tov = MBX_TOV_SECONDS;
5944 mcp->flags = 0;
5945 rval = qla2x00_mailbox_command(vha, mcp);
5946
5947 if (rval != QLA_SUCCESS) {
5948 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5949 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5950 rval, mcp->mb[0], mcp->mb[1]);
5951 } else {
5952 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5953 if (*data == QLA8XXX_BAD_VALUE) {
5954 /*
5955 * During soft-reset CAMRAM register reads might
5956 * return 0xbad0bad0. So retry for MAX of 2 sec
5957 * while reading camram registers.
5958 */
5959 if (time_after(jiffies, retry_max_time)) {
5960 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5961 "Failure to read CAMRAM register. "
5962 "data=0x%x.\n", *data);
5963 return QLA_FUNCTION_FAILED;
5964 }
5965 msleep(100);
5966 goto retry_rd_reg;
5967 }
5968 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5969 }
5970
5971 return rval;
5972}
5973
5974int
5975qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5976{
5977 int rval;
5978 mbx_cmd_t mc;
5979 mbx_cmd_t *mcp = &mc;
5980 struct qla_hw_data *ha = vha->hw;
5981
Himanshu Madhanib20f02e2015-06-10 11:05:18 -04005982 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04005983 return QLA_FUNCTION_FAILED;
5984
5985 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5986
5987 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5988 mcp->out_mb = MBX_0;
5989 mcp->in_mb = MBX_1|MBX_0;
5990 mcp->tov = MBX_TOV_SECONDS;
5991 mcp->flags = 0;
5992 rval = qla2x00_mailbox_command(vha, mcp);
5993
5994 if (rval != QLA_SUCCESS) {
5995 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5996 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5997 rval, mcp->mb[0], mcp->mb[1]);
5998 ha->isp_ops->fw_dump(vha, 0);
5999 } else {
6000 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
6001 }
6002
6003 return rval;
6004}
6005
6006int
6007qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
6008 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
6009{
6010 int rval;
6011 mbx_cmd_t mc;
6012 mbx_cmd_t *mcp = &mc;
6013 uint8_t subcode = (uint8_t)options;
6014 struct qla_hw_data *ha = vha->hw;
6015
6016 if (!IS_QLA8031(ha))
6017 return QLA_FUNCTION_FAILED;
6018
6019 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
6020
6021 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
6022 mcp->mb[1] = options;
6023 mcp->out_mb = MBX_1|MBX_0;
6024 if (subcode & BIT_2) {
6025 mcp->mb[2] = LSW(start_addr);
6026 mcp->mb[3] = MSW(start_addr);
6027 mcp->mb[4] = LSW(end_addr);
6028 mcp->mb[5] = MSW(end_addr);
6029 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
6030 }
6031 mcp->in_mb = MBX_2|MBX_1|MBX_0;
6032 if (!(subcode & (BIT_2 | BIT_5)))
6033 mcp->in_mb |= MBX_4|MBX_3;
6034 mcp->tov = MBX_TOV_SECONDS;
6035 mcp->flags = 0;
6036 rval = qla2x00_mailbox_command(vha, mcp);
6037
6038 if (rval != QLA_SUCCESS) {
6039 ql_dbg(ql_dbg_mbx, vha, 0x1147,
6040 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
6041 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
6042 mcp->mb[4]);
6043 ha->isp_ops->fw_dump(vha, 0);
6044 } else {
6045 if (subcode & BIT_5)
6046 *sector_size = mcp->mb[1];
6047 else if (subcode & (BIT_6 | BIT_7)) {
6048 ql_dbg(ql_dbg_mbx, vha, 0x1148,
6049 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6050 } else if (subcode & (BIT_3 | BIT_4)) {
6051 ql_dbg(ql_dbg_mbx, vha, 0x1149,
6052 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
6053 }
6054 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
6055 }
6056
6057 return rval;
6058}
Saurav Kashyap81178772012-08-22 14:21:04 -04006059
6060int
6061qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
6062 uint32_t size)
6063{
6064 int rval;
6065 mbx_cmd_t mc;
6066 mbx_cmd_t *mcp = &mc;
6067
6068 if (!IS_MCTP_CAPABLE(vha->hw))
6069 return QLA_FUNCTION_FAILED;
6070
6071 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
6072 "Entered %s.\n", __func__);
6073
6074 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
6075 mcp->mb[1] = LSW(addr);
6076 mcp->mb[2] = MSW(req_dma);
6077 mcp->mb[3] = LSW(req_dma);
6078 mcp->mb[4] = MSW(size);
6079 mcp->mb[5] = LSW(size);
6080 mcp->mb[6] = MSW(MSD(req_dma));
6081 mcp->mb[7] = LSW(MSD(req_dma));
6082 mcp->mb[8] = MSW(addr);
6083 /* Setting RAM ID to valid */
6084 mcp->mb[10] |= BIT_7;
6085 /* For MCTP RAM ID is 0x40 */
6086 mcp->mb[10] |= 0x40;
6087
6088 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
6089 MBX_0;
6090
6091 mcp->in_mb = MBX_0;
6092 mcp->tov = MBX_TOV_SECONDS;
6093 mcp->flags = 0;
6094 rval = qla2x00_mailbox_command(vha, mcp);
6095
6096 if (rval != QLA_SUCCESS) {
6097 ql_dbg(ql_dbg_mbx, vha, 0x114e,
6098 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
6099 } else {
6100 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
6101 "Done %s.\n", __func__);
6102 }
6103
6104 return rval;
6105}
Joe Carnuccioec891462016-07-06 11:14:26 -04006106
6107int
6108qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
6109 void *dd_buf, uint size, uint options)
6110{
6111 int rval;
6112 mbx_cmd_t mc;
6113 mbx_cmd_t *mcp = &mc;
6114 dma_addr_t dd_dma;
6115
6116 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
6117 return QLA_FUNCTION_FAILED;
6118
Quinn Tran83548fe2017-06-02 09:12:01 -07006119 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x119f,
Joe Carnuccioec891462016-07-06 11:14:26 -04006120 "Entered %s.\n", __func__);
6121
Joe Carnuccioec891462016-07-06 11:14:26 -04006122 dd_dma = dma_map_single(&vha->hw->pdev->dev,
6123 dd_buf, size, DMA_FROM_DEVICE);
Pan Bian0b2ce192017-08-08 21:55:30 +08006124 if (dma_mapping_error(&vha->hw->pdev->dev, dd_dma)) {
Joe Carnuccioec891462016-07-06 11:14:26 -04006125 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
6126 return QLA_MEMORY_ALLOC_FAILED;
6127 }
6128
6129 memset(dd_buf, 0, size);
6130
6131 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
6132 mcp->mb[1] = options;
6133 mcp->mb[2] = MSW(LSD(dd_dma));
6134 mcp->mb[3] = LSW(LSD(dd_dma));
6135 mcp->mb[6] = MSW(MSD(dd_dma));
6136 mcp->mb[7] = LSW(MSD(dd_dma));
6137 mcp->mb[8] = size;
6138 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
6139 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
6140 mcp->buf_size = size;
6141 mcp->flags = MBX_DMA_IN;
6142 mcp->tov = MBX_TOV_SECONDS * 4;
6143 rval = qla2x00_mailbox_command(vha, mcp);
6144
6145 if (rval != QLA_SUCCESS) {
6146 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
6147 } else {
6148 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
6149 "Done %s.\n", __func__);
6150 }
6151
6152 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
6153 size, DMA_FROM_DEVICE);
6154
6155 return rval;
6156}
Quinn Tran15f30a52017-03-15 09:48:52 -07006157
6158static void qla2x00_async_mb_sp_done(void *s, int res)
6159{
6160 struct srb *sp = s;
6161
6162 sp->u.iocb_cmd.u.mbx.rc = res;
6163
6164 complete(&sp->u.iocb_cmd.u.mbx.comp);
6165 /* don't free sp here. Let the caller do the free */
6166}
6167
6168/*
6169 * This mailbox uses the iocb interface to send MB command.
6170 * This allows non-critial (non chip setup) command to go
6171 * out in parrallel.
6172 */
6173int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
6174{
6175 int rval = QLA_FUNCTION_FAILED;
6176 srb_t *sp;
6177 struct srb_iocb *c;
6178
6179 if (!vha->hw->flags.fw_started)
6180 goto done;
6181
6182 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
6183 if (!sp)
6184 goto done;
6185
6186 sp->type = SRB_MB_IOCB;
6187 sp->name = mb_to_str(mcp->mb[0]);
6188
Quinn Tran15f30a52017-03-15 09:48:52 -07006189 c = &sp->u.iocb_cmd;
6190 c->timeout = qla2x00_async_iocb_timeout;
6191 init_completion(&c->u.mbx.comp);
6192
Ben Hutchingse74e7d92018-03-20 21:36:14 +00006193 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
6194
6195 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
6196
Quinn Tran15f30a52017-03-15 09:48:52 -07006197 sp->done = qla2x00_async_mb_sp_done;
6198
6199 rval = qla2x00_start_sp(sp);
6200 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006201 ql_dbg(ql_dbg_mbx, vha, 0x1018,
Quinn Tran15f30a52017-03-15 09:48:52 -07006202 "%s: %s Failed submission. %x.\n",
6203 __func__, sp->name, rval);
6204 goto done_free_sp;
6205 }
6206
Quinn Tran83548fe2017-06-02 09:12:01 -07006207 ql_dbg(ql_dbg_mbx, vha, 0x113f, "MB:%s hndl %x submitted\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006208 sp->name, sp->handle);
6209
6210 wait_for_completion(&c->u.mbx.comp);
6211 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
6212
6213 rval = c->u.mbx.rc;
6214 switch (rval) {
6215 case QLA_FUNCTION_TIMEOUT:
Quinn Tran83548fe2017-06-02 09:12:01 -07006216 ql_dbg(ql_dbg_mbx, vha, 0x1140, "%s: %s Timeout. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006217 __func__, sp->name, rval);
6218 break;
6219 case QLA_SUCCESS:
Quinn Tran83548fe2017-06-02 09:12:01 -07006220 ql_dbg(ql_dbg_mbx, vha, 0x119d, "%s: %s done.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006221 __func__, sp->name);
6222 sp->free(sp);
6223 break;
6224 default:
Quinn Tran83548fe2017-06-02 09:12:01 -07006225 ql_dbg(ql_dbg_mbx, vha, 0x119e, "%s: %s Failed. %x.\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006226 __func__, sp->name, rval);
6227 sp->free(sp);
6228 break;
6229 }
6230
6231 return rval;
6232
6233done_free_sp:
6234 sp->free(sp);
6235done:
6236 return rval;
6237}
6238
6239/*
6240 * qla24xx_gpdb_wait
6241 * NOTE: Do not call this routine from DPC thread
6242 */
6243int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
6244{
6245 int rval = QLA_FUNCTION_FAILED;
6246 dma_addr_t pd_dma;
6247 struct port_database_24xx *pd;
6248 struct qla_hw_data *ha = vha->hw;
6249 mbx_cmd_t mc;
6250
6251 if (!vha->hw->flags.fw_started)
6252 goto done;
6253
Thomas Meyer08eb7f42017-09-21 08:15:26 +02006254 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Quinn Tran15f30a52017-03-15 09:48:52 -07006255 if (pd == NULL) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006256 ql_log(ql_log_warn, vha, 0xd047,
6257 "Failed to allocate port database structure.\n");
Quinn Tran15f30a52017-03-15 09:48:52 -07006258 goto done_free_sp;
6259 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006260
6261 memset(&mc, 0, sizeof(mc));
6262 mc.mb[0] = MBC_GET_PORT_DATABASE;
6263 mc.mb[1] = cpu_to_le16(fcport->loop_id);
6264 mc.mb[2] = MSW(pd_dma);
6265 mc.mb[3] = LSW(pd_dma);
6266 mc.mb[6] = MSW(MSD(pd_dma));
6267 mc.mb[7] = LSW(MSD(pd_dma));
6268 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6269 mc.mb[10] = cpu_to_le16((uint16_t)opt);
6270
6271 rval = qla24xx_send_mb_cmd(vha, &mc);
6272 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006273 ql_dbg(ql_dbg_mbx, vha, 0x1193,
Quinn Tran15f30a52017-03-15 09:48:52 -07006274 "%s: %8phC fail\n", __func__, fcport->port_name);
6275 goto done_free_sp;
6276 }
6277
6278 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
6279
Quinn Tran83548fe2017-06-02 09:12:01 -07006280 ql_dbg(ql_dbg_mbx, vha, 0x1197, "%s: %8phC done\n",
Quinn Tran15f30a52017-03-15 09:48:52 -07006281 __func__, fcport->port_name);
6282
6283done_free_sp:
6284 if (pd)
6285 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
6286done:
6287 return rval;
6288}
6289
6290int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
6291 struct port_database_24xx *pd)
6292{
6293 int rval = QLA_SUCCESS;
6294 uint64_t zero = 0;
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006295 u8 current_login_state, last_login_state;
6296
6297 if (fcport->fc4f_nvme) {
6298 current_login_state = pd->current_login_state >> 4;
6299 last_login_state = pd->last_login_state >> 4;
6300 } else {
6301 current_login_state = pd->current_login_state & 0xf;
6302 last_login_state = pd->last_login_state & 0xf;
6303 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006304
6305 /* Check for logged in state. */
Quinn Tran23c64552017-12-04 14:45:08 -08006306 if (current_login_state != PDS_PRLI_COMPLETE) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006307 ql_dbg(ql_dbg_mbx, vha, 0x119a,
6308 "Unable to verify login-state (%x/%x) for loop_id %x.\n",
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006309 current_login_state, last_login_state, fcport->loop_id);
Quinn Tran15f30a52017-03-15 09:48:52 -07006310 rval = QLA_FUNCTION_FAILED;
6311 goto gpd_error_out;
6312 }
6313
6314 if (fcport->loop_id == FC_NO_LOOP_ID ||
6315 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
6316 memcmp(fcport->port_name, pd->port_name, 8))) {
6317 /* We lost the device mid way. */
6318 rval = QLA_NOT_LOGGED_IN;
6319 goto gpd_error_out;
6320 }
6321
6322 /* Names are little-endian. */
6323 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
6324 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
6325
6326 /* Get port_id of device. */
6327 fcport->d_id.b.domain = pd->port_id[0];
6328 fcport->d_id.b.area = pd->port_id[1];
6329 fcport->d_id.b.al_pa = pd->port_id[2];
6330 fcport->d_id.b.rsvd_1 = 0;
6331
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006332 if (fcport->fc4f_nvme) {
Duane Grigsbya5d42f42017-06-21 13:48:41 -07006333 fcport->port_type = FCT_NVME;
6334 } else {
6335 /* If not target must be initiator or unknown type. */
6336 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6337 fcport->port_type = FCT_INITIATOR;
6338 else
6339 fcport->port_type = FCT_TARGET;
6340 }
Quinn Tran15f30a52017-03-15 09:48:52 -07006341 /* Passback COS information. */
6342 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6343 FC_COS_CLASS2 : FC_COS_CLASS3;
6344
6345 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6346 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6347 fcport->conf_compl_supported = 1;
6348 }
6349
6350gpd_error_out:
6351 return rval;
6352}
6353
6354/*
6355 * qla24xx_gidlist__wait
6356 * NOTE: don't call this routine from DPC thread.
6357 */
6358int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6359 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6360{
6361 int rval = QLA_FUNCTION_FAILED;
6362 mbx_cmd_t mc;
6363
6364 if (!vha->hw->flags.fw_started)
6365 goto done;
6366
6367 memset(&mc, 0, sizeof(mc));
6368 mc.mb[0] = MBC_GET_ID_LIST;
6369 mc.mb[2] = MSW(id_list_dma);
6370 mc.mb[3] = LSW(id_list_dma);
6371 mc.mb[6] = MSW(MSD(id_list_dma));
6372 mc.mb[7] = LSW(MSD(id_list_dma));
6373 mc.mb[8] = 0;
6374 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6375
6376 rval = qla24xx_send_mb_cmd(vha, &mc);
6377 if (rval != QLA_SUCCESS) {
Quinn Tran83548fe2017-06-02 09:12:01 -07006378 ql_dbg(ql_dbg_mbx, vha, 0x119b,
6379 "%s: fail\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006380 } else {
6381 *entries = mc.mb[1];
Quinn Tran83548fe2017-06-02 09:12:01 -07006382 ql_dbg(ql_dbg_mbx, vha, 0x119c,
6383 "%s: done\n", __func__);
Quinn Tran15f30a52017-03-15 09:48:52 -07006384 }
6385done:
6386 return rval;
6387}
Duane Grigsbydeeae7a2017-07-21 09:32:25 -07006388
6389int qla27xx_set_zio_threshold(scsi_qla_host_t *vha, uint16_t value)
6390{
6391 int rval;
6392 mbx_cmd_t mc;
6393 mbx_cmd_t *mcp = &mc;
6394
6395 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1200,
6396 "Entered %s\n", __func__);
6397
6398 memset(mcp->mb, 0 , sizeof(mcp->mb));
6399 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6400 mcp->mb[1] = cpu_to_le16(1);
6401 mcp->mb[2] = cpu_to_le16(value);
6402 mcp->out_mb = MBX_2 | MBX_1 | MBX_0;
6403 mcp->in_mb = MBX_2 | MBX_0;
6404 mcp->tov = MBX_TOV_SECONDS;
6405 mcp->flags = 0;
6406
6407 rval = qla2x00_mailbox_command(vha, mcp);
6408
6409 ql_dbg(ql_dbg_mbx, vha, 0x1201, "%s %x\n",
6410 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6411
6412 return rval;
6413}
6414
6415int qla27xx_get_zio_threshold(scsi_qla_host_t *vha, uint16_t *value)
6416{
6417 int rval;
6418 mbx_cmd_t mc;
6419 mbx_cmd_t *mcp = &mc;
6420
6421 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1203,
6422 "Entered %s\n", __func__);
6423
6424 memset(mcp->mb, 0, sizeof(mcp->mb));
6425 mcp->mb[0] = MBC_GET_SET_ZIO_THRESHOLD;
6426 mcp->mb[1] = cpu_to_le16(0);
6427 mcp->out_mb = MBX_1 | MBX_0;
6428 mcp->in_mb = MBX_2 | MBX_0;
6429 mcp->tov = MBX_TOV_SECONDS;
6430 mcp->flags = 0;
6431
6432 rval = qla2x00_mailbox_command(vha, mcp);
6433 if (rval == QLA_SUCCESS)
6434 *value = mc.mb[2];
6435
6436 ql_dbg(ql_dbg_mbx, vha, 0x1205, "%s %x\n",
6437 (rval != QLA_SUCCESS) ? "Failed" : "Done", rval);
6438
6439 return rval;
6440}
Quinn Trane4e3a2c2017-08-23 15:05:07 -07006441
6442int
6443qla2x00_read_sfp_dev(struct scsi_qla_host *vha, char *buf, int count)
6444{
6445 struct qla_hw_data *ha = vha->hw;
6446 uint16_t iter, addr, offset;
6447 dma_addr_t phys_addr;
6448 int rval, c;
6449 u8 *sfp_data;
6450
6451 memset(ha->sfp_data, 0, SFP_DEV_SIZE);
6452 addr = 0xa0;
6453 phys_addr = ha->sfp_data_dma;
6454 sfp_data = ha->sfp_data;
6455 offset = c = 0;
6456
6457 for (iter = 0; iter < SFP_DEV_SIZE / SFP_BLOCK_SIZE; iter++) {
6458 if (iter == 4) {
6459 /* Skip to next device address. */
6460 addr = 0xa2;
6461 offset = 0;
6462 }
6463
6464 rval = qla2x00_read_sfp(vha, phys_addr, sfp_data,
6465 addr, offset, SFP_BLOCK_SIZE, BIT_1);
6466 if (rval != QLA_SUCCESS) {
6467 ql_log(ql_log_warn, vha, 0x706d,
6468 "Unable to read SFP data (%x/%x/%x).\n", rval,
6469 addr, offset);
6470
6471 return rval;
6472 }
6473
6474 if (buf && (c < count)) {
6475 u16 sz;
6476
6477 if ((count - c) >= SFP_BLOCK_SIZE)
6478 sz = SFP_BLOCK_SIZE;
6479 else
6480 sz = count - c;
6481
6482 memcpy(buf, sfp_data, sz);
6483 buf += SFP_BLOCK_SIZE;
6484 c += sz;
6485 }
6486 phys_addr += SFP_BLOCK_SIZE;
6487 sfp_data += SFP_BLOCK_SIZE;
6488 offset += SFP_BLOCK_SIZE;
6489 }
6490
6491 return rval;
6492}
Quinn Tran94d83e32017-12-28 12:33:23 -08006493
6494int qla24xx_res_count_wait(struct scsi_qla_host *vha,
6495 uint16_t *out_mb, int out_mb_sz)
6496{
6497 int rval = QLA_FUNCTION_FAILED;
6498 mbx_cmd_t mc;
6499
6500 if (!vha->hw->flags.fw_started)
6501 goto done;
6502
6503 memset(&mc, 0, sizeof(mc));
6504 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
6505
6506 rval = qla24xx_send_mb_cmd(vha, &mc);
6507 if (rval != QLA_SUCCESS) {
6508 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6509 "%s: fail\n", __func__);
6510 } else {
6511 if (out_mb_sz <= SIZEOF_IOCB_MB_REG)
6512 memcpy(out_mb, mc.mb, out_mb_sz);
6513 else
6514 memcpy(out_mb, mc.mb, SIZEOF_IOCB_MB_REG);
6515
6516 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6517 "%s: done\n", __func__);
6518 }
6519done:
6520 return rval;
6521}