blob: 550f75a3269b08c225557ca4786e07c5b3c6d2a0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Chad Dupuis46152ce2012-08-22 14:21:08 -04003 * Copyright (c) 2003-2012 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14/*
15 * qla2x00_mailbox_command
16 * Issue mailbox command and waits for completion.
17 *
18 * Input:
19 * ha = adapter block pointer.
20 * mcp = driver internal mbx struct pointer.
21 *
22 * Output:
23 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
24 *
25 * Returns:
26 * 0 : QLA_SUCCESS = cmd performed success
27 * 1 : QLA_FUNCTION_FAILED (error encountered)
28 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
29 *
30 * Context:
31 * Kernel context.
32 */
33static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080034qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070035{
36 int rval;
37 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070038 device_reg_t __iomem *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070039 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070040 uint8_t io_lock_on;
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -070041 uint16_t command = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 uint16_t *iptr;
43 uint16_t __iomem *optr;
44 uint32_t cnt;
45 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080047 struct qla_hw_data *ha = vha->hw;
48 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070049
Arun Easi5e19ed92012-02-09 11:15:51 -080050 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -070051
52 if (ha->pdev->error_state > pci_channel_io_frozen) {
Arun Easi5e19ed92012-02-09 11:15:51 -080053 ql_log(ql_log_warn, vha, 0x1001,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070054 "error_state is greater than pci_channel_io_frozen, "
55 "exiting.\n");
Seokmann Jub9b12f72009-03-24 09:08:18 -070056 return QLA_FUNCTION_TIMEOUT;
Saurav Kashyap7c3df132011-07-14 12:00:13 -070057 }
Seokmann Jub9b12f72009-03-24 09:08:18 -070058
Giridhar Malavalia9083012010-04-12 17:59:55 -070059 if (vha->device_flags & DFLG_DEV_FAILED) {
Arun Easi5e19ed92012-02-09 11:15:51 -080060 ql_log(ql_log_warn, vha, 0x1002,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070061 "Device in failed state, exiting.\n");
Giridhar Malavalia9083012010-04-12 17:59:55 -070062 return QLA_FUNCTION_TIMEOUT;
63 }
64
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070065 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080066 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080069 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070071
Andrew Vasquez85880802009-12-15 21:29:46 -080072 if (ha->flags.pci_channel_io_perm_failure) {
Arun Easi5e19ed92012-02-09 11:15:51 -080073 ql_log(ql_log_warn, vha, 0x1003,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070074 "Perm failure on EEH timeout MBX, exiting.\n");
Andrew Vasquez85880802009-12-15 21:29:46 -080075 return QLA_FUNCTION_TIMEOUT;
76 }
77
Santosh Vernekar7d613ac2012-08-22 14:21:03 -040078 if (IS_QLA82XX(ha) && ha->flags.isp82xx_fw_hung) {
Giridhar Malavali862cd012011-02-23 15:27:11 -080079 /* Setting Link-Down error */
80 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
Arun Easi5e19ed92012-02-09 11:15:51 -080081 ql_log(ql_log_warn, vha, 0x1004,
Saurav Kashyap7c3df132011-07-14 12:00:13 -070082 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Andrew Vasquez1806fcd2011-11-18 09:02:15 -080083 return QLA_FUNCTION_TIMEOUT;
Giridhar Malavali862cd012011-02-23 15:27:11 -080084 }
85
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070087 * Wait for active mailbox commands to finish by waiting at most tov
88 * seconds. This is to serialize actual issuing of mailbox cmds during
89 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080091 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
92 /* Timeout occurred. Return error. */
Arun Easi5e19ed92012-02-09 11:15:51 -080093 ql_log(ql_log_warn, vha, 0x1005,
Chad Dupuisd8c0d542012-02-09 11:15:46 -080094 "Cmd access timeout, cmd=0x%x, Exiting.\n",
95 mcp->mb[0]);
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080096 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 }
98
99 ha->flags.mbox_busy = 1;
100 /* Save mailbox command for debug */
101 ha->mcp = mcp;
102
Arun Easi5e19ed92012-02-09 11:15:51 -0800103 ql_dbg(ql_dbg_mbx, vha, 0x1006,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700104 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 spin_lock_irqsave(&ha->hardware_lock, flags);
107
108 /* Load mailbox registers. */
Giridhar Malavalia9083012010-04-12 17:59:55 -0700109 if (IS_QLA82XX(ha))
110 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
111 else if (IS_FWI2_CAPABLE(ha) && !IS_QLA82XX(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700112 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
113 else
114 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 iptr = mcp->mb;
117 command = mcp->mb[0];
118 mboxes = mcp->out_mb;
119
120 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
121 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700122 optr =
123 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 if (mboxes & BIT_0)
125 WRT_REG_WORD(optr, *iptr);
126
127 mboxes >>= 1;
128 optr++;
129 iptr++;
130 }
131
Arun Easi5e19ed92012-02-09 11:15:51 -0800132 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1111,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700133 "Loaded MBX registers (displayed in bytes) =.\n");
Arun Easi5e19ed92012-02-09 11:15:51 -0800134 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1112,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700135 (uint8_t *)mcp->mb, 16);
Arun Easi5e19ed92012-02-09 11:15:51 -0800136 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1113,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700137 ".\n");
Arun Easi5e19ed92012-02-09 11:15:51 -0800138 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1114,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700139 ((uint8_t *)mcp->mb + 0x10), 16);
Arun Easi5e19ed92012-02-09 11:15:51 -0800140 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1115,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700141 ".\n");
Arun Easi5e19ed92012-02-09 11:15:51 -0800142 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1116,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700143 ((uint8_t *)mcp->mb + 0x20), 8);
Arun Easi5e19ed92012-02-09 11:15:51 -0800144 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700145 "I/O Address = %p.\n", optr);
Arun Easi5e19ed92012-02-09 11:15:51 -0800146 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x100e);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148 /* Issue set host interrupt command to send cmd out. */
149 ha->flags.mbox_int = 0;
150 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
151
152 /* Unlock mbx registers and wait for interrupt */
Arun Easi5e19ed92012-02-09 11:15:51 -0800153 ql_dbg(ql_dbg_mbx, vha, 0x100f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700154 "Going to unlock irq & waiting for interrupts. "
155 "jiffies=%lx.\n", jiffies);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 /* Wait for mbx cmd completion until timeout */
158
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800159 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
161
Giridhar Malavalia9083012010-04-12 17:59:55 -0700162 if (IS_QLA82XX(ha)) {
163 if (RD_REG_DWORD(&reg->isp82.hint) &
164 HINT_MBX_INT_PENDING) {
165 spin_unlock_irqrestore(&ha->hardware_lock,
166 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800167 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800168 ql_dbg(ql_dbg_mbx, vha, 0x1010,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700169 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700170 rval = QLA_FUNCTION_TIMEOUT;
171 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700172 }
173 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
174 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700175 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
176 else
177 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
179
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800180 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 } else {
Arun Easi5e19ed92012-02-09 11:15:51 -0800185 ql_dbg(ql_dbg_mbx, vha, 0x1011,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700186 "Cmd=%x Polling Mode.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Giridhar Malavalia9083012010-04-12 17:59:55 -0700188 if (IS_QLA82XX(ha)) {
189 if (RD_REG_DWORD(&reg->isp82.hint) &
190 HINT_MBX_INT_PENDING) {
191 spin_unlock_irqrestore(&ha->hardware_lock,
192 flags);
Giridhar Malavali8937f2f2011-11-18 09:02:18 -0800193 ha->flags.mbox_busy = 0;
Arun Easi5e19ed92012-02-09 11:15:51 -0800194 ql_dbg(ql_dbg_mbx, vha, 0x1012,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700195 "Pending mailbox timeout, exiting.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700196 rval = QLA_FUNCTION_TIMEOUT;
197 goto premature_exit;
Giridhar Malavalia9083012010-04-12 17:59:55 -0700198 }
199 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
200 } else if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700201 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
202 else
203 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
207 while (!ha->flags.mbox_int) {
208 if (time_after(jiffies, wait_time))
209 break;
210
211 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800212 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Andrew Vasquez85880802009-12-15 21:29:46 -0800214 if (!ha->flags.mbox_int &&
215 !(IS_QLA2200(ha) &&
216 command == MBC_LOAD_RISC_RAM_EXTENDED))
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800217 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 } /* while */
Arun Easi5e19ed92012-02-09 11:15:51 -0800219 ql_dbg(ql_dbg_mbx, vha, 0x1013,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700220 "Waited %d sec.\n",
221 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 /* Check whether we timed out */
225 if (ha->flags.mbox_int) {
226 uint16_t *iptr2;
227
Arun Easi5e19ed92012-02-09 11:15:51 -0800228 ql_dbg(ql_dbg_mbx, vha, 0x1014,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700229 "Cmd=%x completed.\n", command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 /* Got interrupt. Clear the flag. */
232 ha->flags.mbox_int = 0;
233 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
234
Santosh Vernekar7d613ac2012-08-22 14:21:03 -0400235 if ((IS_QLA82XX(ha) && ha->flags.isp82xx_fw_hung)) {
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700236 ha->flags.mbox_busy = 0;
237 /* Setting Link-Down error */
238 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
239 ha->mcp = NULL;
240 rval = QLA_FUNCTION_FAILED;
Arun Easi5e19ed92012-02-09 11:15:51 -0800241 ql_log(ql_log_warn, vha, 0x1015,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700242 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700243 goto premature_exit;
244 }
245
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400246 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 /* Load return mailbox registers. */
250 iptr2 = mcp->mb;
251 iptr = (uint16_t *)&ha->mailbox_out[0];
252 mboxes = mcp->in_mb;
253 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
254 if (mboxes & BIT_0)
255 *iptr2 = *iptr;
256
257 mboxes >>= 1;
258 iptr2++;
259 iptr++;
260 }
261 } else {
262
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700263 uint16_t mb0;
264 uint32_t ictrl;
265
Andrew Vasqueze4289242007-07-19 15:05:56 -0700266 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700267 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
268 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
269 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700270 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700271 ictrl = RD_REG_WORD(&reg->isp.ictrl);
272 }
Arun Easi5e19ed92012-02-09 11:15:51 -0800273 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400274 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
275 "mb[0]=0x%x\n", command, ictrl, jiffies, mb0);
Arun Easi5e19ed92012-02-09 11:15:51 -0800276 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Chad Dupuisf55bfc82012-02-09 11:15:53 -0800278 /*
279 * Attempt to capture a firmware dump for further analysis
280 * of the current firmware state
281 */
282 ha->isp_ops->fw_dump(vha, 0);
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 rval = QLA_FUNCTION_TIMEOUT;
285 }
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 ha->flags.mbox_busy = 0;
288
289 /* Clean up */
290 ha->mcp = NULL;
291
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800292 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Arun Easi5e19ed92012-02-09 11:15:51 -0800293 ql_dbg(ql_dbg_mbx, vha, 0x101a,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700294 "Checking for additional resp interrupt.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
296 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800297 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 }
299
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700300 if (rval == QLA_FUNCTION_TIMEOUT &&
301 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Andrew Vasquez85880802009-12-15 21:29:46 -0800302 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
303 ha->flags.eeh_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 /* not in dpc. schedule it for dpc to take over. */
Arun Easi5e19ed92012-02-09 11:15:51 -0800305 ql_dbg(ql_dbg_mbx, vha, 0x101b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700306 "Timeout, schedule isp_abort_needed.\n");
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700307
308 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
309 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
310 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800311 if (IS_QLA82XX(ha)) {
312 ql_dbg(ql_dbg_mbx, vha, 0x112a,
313 "disabling pause transmit on port "
314 "0 & 1.\n");
315 qla82xx_wr_32(ha,
316 QLA82XX_CRB_NIU + 0x98,
317 CRB_NIU_XG_PAUSE_CTL_P0|
318 CRB_NIU_XG_PAUSE_CTL_P1);
319 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700320 ql_log(ql_log_info, base_vha, 0x101c,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400321 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800322 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
323 "abort.\n", command, mcp->mb[0],
324 ha->flags.eeh_busy);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700325 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
326 qla2xxx_wake_dpc(vha);
327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 /* call abort directly since we are in the DPC thread */
Arun Easi5e19ed92012-02-09 11:15:51 -0800330 ql_dbg(ql_dbg_mbx, vha, 0x101d,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700331 "Timeout, calling abort_isp.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700333 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
334 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
335 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Giridhar Malavali63154912011-11-18 09:02:19 -0800336 if (IS_QLA82XX(ha)) {
337 ql_dbg(ql_dbg_mbx, vha, 0x112b,
338 "disabling pause transmit on port "
339 "0 & 1.\n");
340 qla82xx_wr_32(ha,
341 QLA82XX_CRB_NIU + 0x98,
342 CRB_NIU_XG_PAUSE_CTL_P0|
343 CRB_NIU_XG_PAUSE_CTL_P1);
344 }
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700345 ql_log(ql_log_info, base_vha, 0x101e,
Masanari Iida24d9ee82012-05-15 14:34:10 -0400346 "Mailbox cmd timeout occurred, cmd=0x%x, "
Chad Dupuisd8c0d542012-02-09 11:15:46 -0800347 "mb[0]=0x%x. Scheduling ISP abort ",
348 command, mcp->mb[0]);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700349 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
350 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Giridhar Malavalid3360962012-02-09 11:14:10 -0800351 /* Allow next mbx cmd to come in. */
352 complete(&ha->mbx_cmd_comp);
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700353 if (ha->isp_ops->abort_isp(vha)) {
354 /* Failed. retry later. */
355 set_bit(ISP_ABORT_NEEDED,
356 &vha->dpc_flags);
357 }
358 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
Arun Easi5e19ed92012-02-09 11:15:51 -0800359 ql_dbg(ql_dbg_mbx, vha, 0x101f,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700360 "Finished abort_isp.\n");
Giridhar Malavalid3360962012-02-09 11:14:10 -0800361 goto mbx_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 }
364 }
365
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -0700366premature_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800368 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Giridhar Malavalid3360962012-02-09 11:14:10 -0800370mbx_done:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 if (rval) {
Saurav Kashyap09543c092012-08-22 14:20:59 -0400372 ql_log(ql_log_warn, base_vha, 0x1020,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800373 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
374 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 } else {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700376 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 return rval;
380}
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800383qla2x00_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 -0800384 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
386 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800387 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 mbx_cmd_t mc;
389 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400391 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
392 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andrew Vasqueze4289242007-07-19 15:05:56 -0700394 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800395 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
396 mcp->mb[8] = MSW(risc_addr);
397 mcp->out_mb = MBX_8|MBX_0;
398 } else {
399 mcp->mb[0] = MBC_LOAD_RISC_RAM;
400 mcp->out_mb = MBX_0;
401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 mcp->mb[1] = LSW(risc_addr);
403 mcp->mb[2] = MSW(req_dma);
404 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 mcp->mb[6] = MSW(MSD(req_dma));
406 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800407 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700408 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700409 mcp->mb[4] = MSW(risc_code_size);
410 mcp->mb[5] = LSW(risc_code_size);
411 mcp->out_mb |= MBX_5|MBX_4;
412 } else {
413 mcp->mb[4] = LSW(risc_code_size);
414 mcp->out_mb |= MBX_4;
415 }
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700418 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800420 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700423 ql_dbg(ql_dbg_mbx, vha, 0x1023,
424 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400426 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
427 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 return rval;
431}
432
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700433#define EXTENDED_BB_CREDITS BIT_0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434/*
435 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700436 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 *
438 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700439 * ha = adapter block pointer.
440 * TARGET_QUEUE_LOCK must be released.
441 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700444 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 *
446 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700447 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 */
449int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800450qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
452 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800453 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 mbx_cmd_t mc;
455 mbx_cmd_t *mcp = &mc;
456
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400457 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
458 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700461 mcp->out_mb = MBX_0;
462 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700463 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700464 mcp->mb[1] = MSW(risc_addr);
465 mcp->mb[2] = LSW(risc_addr);
466 mcp->mb[3] = 0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800467 if (IS_QLA81XX(ha) || IS_QLA83XX(ha)) {
Santosh Vernekarcad454b2010-03-19 16:59:16 -0700468 struct nvram_81xx *nv = ha->nvram;
469 mcp->mb[4] = (nv->enhanced_features &
470 EXTENDED_BB_CREDITS);
471 } else
472 mcp->mb[4] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700473 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700474 mcp->in_mb |= MBX_1;
475 } else {
476 mcp->mb[1] = LSW(risc_addr);
477 mcp->out_mb |= MBX_1;
478 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
479 mcp->mb[2] = 0;
480 mcp->out_mb |= MBX_2;
481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 }
483
Ravi Anandb93480e2008-04-03 13:13:25 -0700484 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800486 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700488 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700489 ql_dbg(ql_dbg_mbx, vha, 0x1026,
490 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700491 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700492 if (IS_FWI2_CAPABLE(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400493 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700494 "Done exchanges=%x.\n", mcp->mb[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700495 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400496 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
497 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700498 }
499 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501 return rval;
502}
503
504/*
505 * qla2x00_get_fw_version
506 * Get firmware version.
507 *
508 * Input:
509 * ha: adapter state pointer.
510 * major: pointer for major number.
511 * minor: pointer for minor number.
512 * subminor: pointer for subminor number.
513 *
514 * Returns:
515 * qla2x00 local function return status code.
516 *
517 * Context:
518 * Kernel context.
519 */
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700520int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800521qla2x00_get_fw_version(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522{
523 int rval;
524 mbx_cmd_t mc;
525 mbx_cmd_t *mcp = &mc;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800526 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400528 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
529 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
531 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
532 mcp->out_mb = MBX_0;
533 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800534 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700535 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Saurav Kashyapfb0effe2012-08-22 14:21:28 -0400536 if (IS_FWI2_CAPABLE(ha))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800537 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700539 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800540 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700541 if (rval != QLA_SUCCESS)
542 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
544 /* Return mailbox data. */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800545 ha->fw_major_version = mcp->mb[1];
546 ha->fw_minor_version = mcp->mb[2];
547 ha->fw_subminor_version = mcp->mb[3];
548 ha->fw_attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800549 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800550 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 else
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800552 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
553 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw)) {
554 ha->mpi_version[0] = mcp->mb[10] & 0xff;
555 ha->mpi_version[1] = mcp->mb[11] >> 8;
556 ha->mpi_version[2] = mcp->mb[11] & 0xff;
557 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
558 ha->phy_version[0] = mcp->mb[8] & 0xff;
559 ha->phy_version[1] = mcp->mb[9] >> 8;
560 ha->phy_version[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800561 }
Saurav Kashyap81178772012-08-22 14:21:04 -0400562 if (IS_FWI2_CAPABLE(ha)) {
563 ha->fw_attributes_h = mcp->mb[15];
564 ha->fw_attributes_ext[0] = mcp->mb[16];
565 ha->fw_attributes_ext[1] = mcp->mb[17];
566 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
567 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
568 __func__, mcp->mb[15], mcp->mb[6]);
569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
570 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
571 __func__, mcp->mb[17], mcp->mb[16]);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -0800572 }
573
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700574failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 if (rval != QLA_SUCCESS) {
576 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700577 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 } else {
579 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
581 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700583 return rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584}
585
586/*
587 * qla2x00_get_fw_options
588 * Set firmware options.
589 *
590 * Input:
591 * ha = adapter block pointer.
592 * fwopt = pointer for firmware options.
593 *
594 * Returns:
595 * qla2x00 local function return status code.
596 *
597 * Context:
598 * Kernel context.
599 */
600int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800601qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int rval;
604 mbx_cmd_t mc;
605 mbx_cmd_t *mcp = &mc;
606
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400607 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
608 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
611 mcp->out_mb = MBX_0;
612 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700613 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800615 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 if (rval != QLA_SUCCESS) {
618 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700619 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700621 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 fwopts[1] = mcp->mb[1];
623 fwopts[2] = mcp->mb[2];
624 fwopts[3] = mcp->mb[3];
625
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400626 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
627 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629
630 return rval;
631}
632
633
634/*
635 * qla2x00_set_fw_options
636 * Set firmware options.
637 *
638 * Input:
639 * ha = adapter block pointer.
640 * fwopt = pointer for firmware options.
641 *
642 * Returns:
643 * qla2x00 local function return status code.
644 *
645 * Context:
646 * Kernel context.
647 */
648int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800649qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650{
651 int rval;
652 mbx_cmd_t mc;
653 mbx_cmd_t *mcp = &mc;
654
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400655 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
656 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
659 mcp->mb[1] = fwopts[1];
660 mcp->mb[2] = fwopts[2];
661 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700662 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800664 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700665 mcp->in_mb |= MBX_1;
666 } else {
667 mcp->mb[10] = fwopts[10];
668 mcp->mb[11] = fwopts[11];
669 mcp->mb[12] = 0; /* Undocumented, but used */
670 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
671 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700672 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800674 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700676 fwopts[0] = mcp->mb[0];
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if (rval != QLA_SUCCESS) {
679 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700680 ql_dbg(ql_dbg_mbx, vha, 0x1030,
681 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 } else {
683 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400684 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
685 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687
688 return rval;
689}
690
691/*
692 * qla2x00_mbx_reg_test
693 * Mailbox register wrap test.
694 *
695 * Input:
696 * ha = adapter block pointer.
697 * TARGET_QUEUE_LOCK must be released.
698 * ADAPTER_STATE_LOCK must be released.
699 *
700 * Returns:
701 * qla2x00 local function return status code.
702 *
703 * Context:
704 * Kernel context.
705 */
706int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800707qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
709 int rval;
710 mbx_cmd_t mc;
711 mbx_cmd_t *mcp = &mc;
712
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
714 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715
716 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
717 mcp->mb[1] = 0xAAAA;
718 mcp->mb[2] = 0x5555;
719 mcp->mb[3] = 0xAA55;
720 mcp->mb[4] = 0x55AA;
721 mcp->mb[5] = 0xA5A5;
722 mcp->mb[6] = 0x5A5A;
723 mcp->mb[7] = 0x2525;
724 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
725 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 -0700726 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800728 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
730 if (rval == QLA_SUCCESS) {
731 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
732 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
733 rval = QLA_FUNCTION_FAILED;
734 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
735 mcp->mb[7] != 0x2525)
736 rval = QLA_FUNCTION_FAILED;
737 }
738
739 if (rval != QLA_SUCCESS) {
740 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700741 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 } else {
743 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400744 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
745 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747
748 return rval;
749}
750
751/*
752 * qla2x00_verify_checksum
753 * Verify firmware checksum.
754 *
755 * Input:
756 * ha = adapter block pointer.
757 * TARGET_QUEUE_LOCK must be released.
758 * ADAPTER_STATE_LOCK must be released.
759 *
760 * Returns:
761 * qla2x00 local function return status code.
762 *
763 * Context:
764 * Kernel context.
765 */
766int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800767qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 int rval;
770 mbx_cmd_t mc;
771 mbx_cmd_t *mcp = &mc;
772
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400773 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
774 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700777 mcp->out_mb = MBX_0;
778 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800779 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700780 mcp->mb[1] = MSW(risc_addr);
781 mcp->mb[2] = LSW(risc_addr);
782 mcp->out_mb |= MBX_2|MBX_1;
783 mcp->in_mb |= MBX_2|MBX_1;
784 } else {
785 mcp->mb[1] = LSW(risc_addr);
786 mcp->out_mb |= MBX_1;
787 mcp->in_mb |= MBX_1;
788 }
789
Ravi Anandb93480e2008-04-03 13:13:25 -0700790 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800792 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700795 ql_dbg(ql_dbg_mbx, vha, 0x1036,
796 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
797 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400799 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
800 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 }
802
803 return rval;
804}
805
806/*
807 * qla2x00_issue_iocb
808 * Issue IOCB using mailbox command
809 *
810 * Input:
811 * ha = adapter state pointer.
812 * buffer = buffer pointer.
813 * phys_addr = physical address of buffer.
814 * size = size of buffer.
815 * TARGET_QUEUE_LOCK must be released.
816 * ADAPTER_STATE_LOCK must be released.
817 *
818 * Returns:
819 * qla2x00 local function return status code.
820 *
821 * Context:
822 * Kernel context.
823 */
Giridhar Malavali6e980162010-03-19 17:03:58 -0700824int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800825qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700826 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827{
828 int rval;
829 mbx_cmd_t mc;
830 mbx_cmd_t *mcp = &mc;
831
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400832 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
833 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
836 mcp->mb[1] = 0;
837 mcp->mb[2] = MSW(phys_addr);
838 mcp->mb[3] = LSW(phys_addr);
839 mcp->mb[6] = MSW(MSD(phys_addr));
840 mcp->mb[7] = LSW(MSD(phys_addr));
841 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
842 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700843 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800845 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 if (rval != QLA_SUCCESS) {
848 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700849 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700851 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
852
853 /* Mask reserved bits. */
854 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800855 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400856 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
857 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 }
859
860 return rval;
861}
862
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700863int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800864qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700865 size_t size)
866{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800867 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700868 MBX_TOV_SECONDS);
869}
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*
872 * qla2x00_abort_command
873 * Abort command aborts a specified IOCB.
874 *
875 * Input:
876 * ha = adapter block pointer.
877 * sp = SB structure pointer.
878 *
879 * Returns:
880 * qla2x00 local function return status code.
881 *
882 * Context:
883 * Kernel context.
884 */
885int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700886qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887{
888 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800890 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 mbx_cmd_t mc;
892 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700893 fc_port_t *fcport = sp->fcport;
894 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800895 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700896 struct req_que *req = vha->req;
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800897 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400899 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
900 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700902 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -0500903 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800904 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 break;
906 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700907 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
Chad Dupuis8d93f552013-01-30 03:34:37 -0500909 if (handle == req->num_outstanding_cmds) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 /* command not found */
911 return QLA_FUNCTION_FAILED;
912 }
913
914 mcp->mb[0] = MBC_ABORT_COMMAND;
915 if (HAS_EXTENDED_IDS(ha))
916 mcp->mb[1] = fcport->loop_id;
917 else
918 mcp->mb[1] = fcport->loop_id << 8;
919 mcp->mb[2] = (uint16_t)handle;
920 mcp->mb[3] = (uint16_t)(handle >> 16);
Giridhar Malavali9ba56b92012-02-09 11:15:36 -0800921 mcp->mb[6] = (uint16_t)cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
923 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700924 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800926 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
928 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700929 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400931 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
932 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934
935 return rval;
936}
937
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700939qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700941 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 mbx_cmd_t mc;
943 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800944 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800945 struct req_que *req;
946 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Andrew Vasquez523ec772008-04-03 13:13:24 -0700948 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800949 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700950
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400951 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
952 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700953
Giridhar Malavali7e2b8952010-05-28 15:08:17 -0700954 req = vha->hw->req_q_map[0];
955 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700957 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 mcp->mb[1] = fcport->loop_id;
960 mcp->mb[10] = 0;
961 mcp->out_mb |= MBX_10;
962 } else {
963 mcp->mb[1] = fcport->loop_id << 8;
964 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800965 mcp->mb[2] = vha->hw->loop_reset_delay;
966 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700969 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800971 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400973 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
974 "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700975 }
976
977 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800978 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
979 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700980 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -0700981 ql_dbg(ql_dbg_mbx, vha, 0x1040,
982 "Failed to issue marker IOCB (%x).\n", rval2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -0400984 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
985 "Done %s.\n", __func__);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700986 }
987
988 return rval;
989}
990
991int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700992qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700993{
994 int rval, rval2;
995 mbx_cmd_t mc;
996 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800997 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800998 struct req_que *req;
999 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001000
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001001 vha = fcport->vha;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001002
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001003 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1004 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001005
Giridhar Malavali7e2b8952010-05-28 15:08:17 -07001006 req = vha->hw->req_q_map[0];
1007 rsp = req->rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001008 mcp->mb[0] = MBC_LUN_RESET;
1009 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001010 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -07001011 mcp->mb[1] = fcport->loop_id;
1012 else
1013 mcp->mb[1] = fcport->loop_id << 8;
1014 mcp->mb[2] = l;
1015 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001016 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001017
1018 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001019 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -07001020 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001021 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001022 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001023 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001024 }
1025
1026 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001027 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1028 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001029 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001030 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1031 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07001032 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001033 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1034 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036
1037 return rval;
1038}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
1040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 * qla2x00_get_adapter_id
1042 * Get adapter ID and topology.
1043 *
1044 * Input:
1045 * ha = adapter block pointer.
1046 * id = pointer for loop ID.
1047 * al_pa = pointer for AL_PA.
1048 * area = pointer for area.
1049 * domain = pointer for domain.
1050 * top = pointer for topology.
1051 * TARGET_QUEUE_LOCK must be released.
1052 * ADAPTER_STATE_LOCK must be released.
1053 *
1054 * Returns:
1055 * qla2x00 local function return status code.
1056 *
1057 * Context:
1058 * Kernel context.
1059 */
1060int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001061qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001062 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063{
1064 int rval;
1065 mbx_cmd_t mc;
1066 mbx_cmd_t *mcp = &mc;
1067
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001068 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1069 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001072 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001073 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001074 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001075 if (IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezbad70012009-04-06 22:33:38 -07001076 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -07001077 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001079 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -08001080 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1081 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -07001082 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1083 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
1085 /* Return data. */
1086 *id = mcp->mb[1];
1087 *al_pa = LSB(mcp->mb[2]);
1088 *area = MSB(mcp->mb[2]);
1089 *domain = LSB(mcp->mb[3]);
1090 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001091 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 if (rval != QLA_SUCCESS) {
1094 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001095 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1098 "Done %s.\n", __func__);
Andrew Vasquezbad70012009-04-06 22:33:38 -07001099
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001100 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquezbad70012009-04-06 22:33:38 -07001101 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1102 vha->fcoe_fcf_idx = mcp->mb[10];
1103 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1104 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1105 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1106 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1107 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1108 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1109 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111
1112 return rval;
1113}
1114
1115/*
1116 * qla2x00_get_retry_cnt
1117 * Get current firmware login retry count and delay.
1118 *
1119 * Input:
1120 * ha = adapter block pointer.
1121 * retry_cnt = pointer to login retry count.
1122 * tov = pointer to login timeout value.
1123 *
1124 * Returns:
1125 * qla2x00 local function return status code.
1126 *
1127 * Context:
1128 * Kernel context.
1129 */
1130int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001131qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 uint16_t *r_a_tov)
1133{
1134 int rval;
1135 uint16_t ratov;
1136 mbx_cmd_t mc;
1137 mbx_cmd_t *mcp = &mc;
1138
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001139 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1140 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
1142 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1143 mcp->out_mb = MBX_0;
1144 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001145 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001147 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
1149 if (rval != QLA_SUCCESS) {
1150 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001151 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1152 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 } else {
1154 /* Convert returned data and check our values. */
1155 *r_a_tov = mcp->mb[3] / 2;
1156 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1157 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1158 /* Update to the larger values */
1159 *retry_cnt = (uint8_t)mcp->mb[1];
1160 *tov = ratov;
1161 }
1162
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001163 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001164 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166
1167 return rval;
1168}
1169
1170/*
1171 * qla2x00_init_firmware
1172 * Initialize adapter firmware.
1173 *
1174 * Input:
1175 * ha = adapter block pointer.
1176 * dptr = Initialization control block pointer.
1177 * size = size of initialization control block.
1178 * TARGET_QUEUE_LOCK must be released.
1179 * ADAPTER_STATE_LOCK must be released.
1180 *
1181 * Returns:
1182 * qla2x00 local function return status code.
1183 *
1184 * Context:
1185 * Kernel context.
1186 */
1187int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001188qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189{
1190 int rval;
1191 mbx_cmd_t mc;
1192 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001193 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001195 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1196 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Giridhar Malavalia9083012010-04-12 17:59:55 -07001198 if (IS_QLA82XX(ha) && ql2xdbwr)
1199 qla82xx_wr_32(ha, ha->nxdb_wr_ptr,
1200 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1201
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001202 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001203 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1204 else
1205 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1206
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001207 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 mcp->mb[2] = MSW(ha->init_cb_dma);
1209 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1211 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001212 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001213 if ((IS_QLA81XX(ha) || IS_QLA83XX(ha)) && ha->ex_init_cb->ex_version) {
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001214 mcp->mb[1] = BIT_0;
1215 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1216 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1217 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1218 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1219 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1220 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1221 }
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001222 /* 1 and 2 should normally be captured. */
1223 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1224 if (IS_QLA83XX(ha))
1225 /* mb3 is additional info about the installed SFP. */
1226 mcp->in_mb |= MBX_3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 mcp->buf_size = size;
1228 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001229 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001230 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231
1232 if (rval != QLA_SUCCESS) {
1233 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001234 ql_dbg(ql_dbg_mbx, vha, 0x104d,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001235 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1236 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 } else {
1238 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001239 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1240 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 }
1242
1243 return rval;
1244}
1245
1246/*
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001247 * qla2x00_get_node_name_list
1248 * Issue get node name list mailbox command, kmalloc()
1249 * and return the resulting list. Caller must kfree() it!
1250 *
1251 * Input:
1252 * ha = adapter state pointer.
1253 * out_data = resulting list
1254 * out_len = length of the resulting list
1255 *
1256 * Returns:
1257 * qla2x00 local function return status code.
1258 *
1259 * Context:
1260 * Kernel context.
1261 */
1262int
1263qla2x00_get_node_name_list(scsi_qla_host_t *vha, void **out_data, int *out_len)
1264{
1265 struct qla_hw_data *ha = vha->hw;
1266 struct qla_port_24xx_data *list = NULL;
1267 void *pmap;
1268 mbx_cmd_t mc;
1269 dma_addr_t pmap_dma;
1270 ulong dma_size;
1271 int rval, left;
1272
1273 left = 1;
1274 while (left > 0) {
1275 dma_size = left * sizeof(*list);
1276 pmap = dma_alloc_coherent(&ha->pdev->dev, dma_size,
1277 &pmap_dma, GFP_KERNEL);
1278 if (!pmap) {
1279 ql_log(ql_log_warn, vha, 0x113f,
1280 "%s(%ld): DMA Alloc failed of %ld\n",
1281 __func__, vha->host_no, dma_size);
1282 rval = QLA_MEMORY_ALLOC_FAILED;
1283 goto out;
1284 }
1285
1286 mc.mb[0] = MBC_PORT_NODE_NAME_LIST;
1287 mc.mb[1] = BIT_1 | BIT_3;
1288 mc.mb[2] = MSW(pmap_dma);
1289 mc.mb[3] = LSW(pmap_dma);
1290 mc.mb[6] = MSW(MSD(pmap_dma));
1291 mc.mb[7] = LSW(MSD(pmap_dma));
1292 mc.mb[8] = dma_size;
1293 mc.out_mb = MBX_0|MBX_1|MBX_2|MBX_3|MBX_6|MBX_7|MBX_8;
1294 mc.in_mb = MBX_0|MBX_1;
1295 mc.tov = 30;
1296 mc.flags = MBX_DMA_IN;
1297
1298 rval = qla2x00_mailbox_command(vha, &mc);
1299 if (rval != QLA_SUCCESS) {
1300 if ((mc.mb[0] == MBS_COMMAND_ERROR) &&
1301 (mc.mb[1] == 0xA)) {
1302 left += le16_to_cpu(mc.mb[2]) /
1303 sizeof(struct qla_port_24xx_data);
1304 goto restart;
1305 }
1306 goto out_free;
1307 }
1308
1309 left = 0;
1310
1311 list = kzalloc(dma_size, GFP_KERNEL);
1312 if (!list) {
1313 ql_log(ql_log_warn, vha, 0x1140,
1314 "%s(%ld): failed to allocate node names list "
1315 "structure.\n", __func__, vha->host_no);
1316 rval = QLA_MEMORY_ALLOC_FAILED;
1317 goto out_free;
1318 }
1319
1320 memcpy(list, pmap, dma_size);
1321restart:
1322 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1323 }
1324
1325 *out_data = list;
1326 *out_len = dma_size;
1327
1328out:
1329 return rval;
1330
1331out_free:
1332 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
1333 return rval;
1334}
1335
1336/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 * qla2x00_get_port_database
1338 * Issue normal/enhanced get port database mailbox command
1339 * and copy device name as necessary.
1340 *
1341 * Input:
1342 * ha = adapter state pointer.
1343 * dev = structure pointer.
1344 * opt = enhanced cmd option byte.
1345 *
1346 * Returns:
1347 * qla2x00 local function return status code.
1348 *
1349 * Context:
1350 * Kernel context.
1351 */
1352int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001353qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
1355 int rval;
1356 mbx_cmd_t mc;
1357 mbx_cmd_t *mcp = &mc;
1358 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001359 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001361 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001363 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1364 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001366 pd24 = NULL;
1367 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if (pd == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001369 ql_log(ql_log_warn, vha, 0x1050,
1370 "Failed to allocate port database structure.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 return QLA_MEMORY_ALLOC_FAILED;
1372 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001373 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001375 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001376 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 mcp->mb[2] = MSW(pd_dma);
1379 mcp->mb[3] = LSW(pd_dma);
1380 mcp->mb[6] = MSW(MSD(pd_dma));
1381 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001382 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001383 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001385 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001386 mcp->mb[1] = fcport->loop_id;
1387 mcp->mb[10] = opt;
1388 mcp->out_mb |= MBX_10|MBX_1;
1389 mcp->in_mb |= MBX_1;
1390 } else if (HAS_EXTENDED_IDS(ha)) {
1391 mcp->mb[1] = fcport->loop_id;
1392 mcp->mb[10] = opt;
1393 mcp->out_mb |= MBX_10|MBX_1;
1394 } else {
1395 mcp->mb[1] = fcport->loop_id << 8 | opt;
1396 mcp->out_mb |= MBX_1;
1397 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001398 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1399 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 mcp->flags = MBX_DMA_IN;
1401 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001402 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 if (rval != QLA_SUCCESS)
1404 goto gpd_error_out;
1405
Andrew Vasqueze4289242007-07-19 15:05:56 -07001406 if (IS_FWI2_CAPABLE(ha)) {
Arun Easi0eba25d2012-02-09 11:15:58 -08001407 uint64_t zero = 0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001408 pd24 = (struct port_database_24xx *) pd;
1409
1410 /* Check for logged in state. */
1411 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1412 pd24->last_login_state != PDS_PRLI_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001413 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1414 "Unable to verify login-state (%x/%x) for "
1415 "loop_id %x.\n", pd24->current_login_state,
1416 pd24->last_login_state, fcport->loop_id);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001417 rval = QLA_FUNCTION_FAILED;
1418 goto gpd_error_out;
1419 }
1420
Arun Easi0eba25d2012-02-09 11:15:58 -08001421 if (fcport->loop_id == FC_NO_LOOP_ID ||
1422 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1423 memcmp(fcport->port_name, pd24->port_name, 8))) {
1424 /* We lost the device mid way. */
1425 rval = QLA_NOT_LOGGED_IN;
1426 goto gpd_error_out;
1427 }
1428
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001429 /* Names are little-endian. */
1430 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1431 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1432
1433 /* Get port_id of device. */
1434 fcport->d_id.b.domain = pd24->port_id[0];
1435 fcport->d_id.b.area = pd24->port_id[1];
1436 fcport->d_id.b.al_pa = pd24->port_id[2];
1437 fcport->d_id.b.rsvd_1 = 0;
1438
1439 /* If not target must be initiator or unknown type. */
1440 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1441 fcport->port_type = FCT_INITIATOR;
1442 else
1443 fcport->port_type = FCT_TARGET;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001444
1445 /* Passback COS information. */
1446 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1447 FC_COS_CLASS2 : FC_COS_CLASS3;
1448
1449 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1450 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001451 } else {
Arun Easi0eba25d2012-02-09 11:15:58 -08001452 uint64_t zero = 0;
1453
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001454 /* Check for logged in state. */
1455 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1456 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001457 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1458 "Unable to verify login-state (%x/%x) - "
1459 "portid=%02x%02x%02x.\n", pd->master_state,
1460 pd->slave_state, fcport->d_id.b.domain,
1461 fcport->d_id.b.area, fcport->d_id.b.al_pa);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001462 rval = QLA_FUNCTION_FAILED;
1463 goto gpd_error_out;
1464 }
1465
Arun Easi0eba25d2012-02-09 11:15:58 -08001466 if (fcport->loop_id == FC_NO_LOOP_ID ||
1467 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1468 memcmp(fcport->port_name, pd->port_name, 8))) {
1469 /* We lost the device mid way. */
1470 rval = QLA_NOT_LOGGED_IN;
1471 goto gpd_error_out;
1472 }
1473
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001474 /* Names are little-endian. */
1475 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1476 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1477
1478 /* Get port_id of device. */
1479 fcport->d_id.b.domain = pd->port_id[0];
1480 fcport->d_id.b.area = pd->port_id[3];
1481 fcport->d_id.b.al_pa = pd->port_id[2];
1482 fcport->d_id.b.rsvd_1 = 0;
1483
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001484 /* If not target must be initiator or unknown type. */
1485 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1486 fcport->port_type = FCT_INITIATOR;
1487 else
1488 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001489
1490 /* Passback COS information. */
1491 fcport->supported_classes = (pd->options & BIT_4) ?
1492 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 }
1494
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495gpd_error_out:
1496 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1497
1498 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001499 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1500 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1501 mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1504 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
1506
1507 return rval;
1508}
1509
1510/*
1511 * qla2x00_get_firmware_state
1512 * Get adapter firmware state.
1513 *
1514 * Input:
1515 * ha = adapter block pointer.
1516 * dptr = pointer for firmware state.
1517 * TARGET_QUEUE_LOCK must be released.
1518 * ADAPTER_STATE_LOCK must be released.
1519 *
1520 * Returns:
1521 * qla2x00 local function return status code.
1522 *
1523 * Context:
1524 * Kernel context.
1525 */
1526int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001527qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528{
1529 int rval;
1530 mbx_cmd_t mc;
1531 mbx_cmd_t *mcp = &mc;
1532
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1534 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1537 mcp->out_mb = MBX_0;
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001538 if (IS_FWI2_CAPABLE(vha->hw))
1539 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1540 else
1541 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001542 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001544 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001546 /* Return firmware states. */
1547 states[0] = mcp->mb[1];
Andrew Vasquez9d2683c2009-06-17 10:30:30 -07001548 if (IS_FWI2_CAPABLE(vha->hw)) {
1549 states[1] = mcp->mb[2];
1550 states[2] = mcp->mb[3];
1551 states[3] = mcp->mb[4];
1552 states[4] = mcp->mb[5];
1553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 if (rval != QLA_SUCCESS) {
1556 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001557 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 } else {
1559 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001560 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1561 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 }
1563
1564 return rval;
1565}
1566
1567/*
1568 * qla2x00_get_port_name
1569 * Issue get port name mailbox command.
1570 * Returned name is in big endian format.
1571 *
1572 * Input:
1573 * ha = adapter block pointer.
1574 * loop_id = loop ID of device.
1575 * name = pointer for name.
1576 * TARGET_QUEUE_LOCK must be released.
1577 * ADAPTER_STATE_LOCK must be released.
1578 *
1579 * Returns:
1580 * qla2x00 local function return status code.
1581 *
1582 * Context:
1583 * Kernel context.
1584 */
1585int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001586qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 uint8_t opt)
1588{
1589 int rval;
1590 mbx_cmd_t mc;
1591 mbx_cmd_t *mcp = &mc;
1592
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001593 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1594 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001597 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001598 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001599 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600 mcp->mb[1] = loop_id;
1601 mcp->mb[10] = opt;
1602 mcp->out_mb |= MBX_10;
1603 } else {
1604 mcp->mb[1] = loop_id << 8 | opt;
1605 }
1606
1607 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001608 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001610 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 if (rval != QLA_SUCCESS) {
1613 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001614 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 } else {
1616 if (name != NULL) {
1617 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001618 name[0] = MSB(mcp->mb[2]);
1619 name[1] = LSB(mcp->mb[2]);
1620 name[2] = MSB(mcp->mb[3]);
1621 name[3] = LSB(mcp->mb[3]);
1622 name[4] = MSB(mcp->mb[6]);
1623 name[5] = LSB(mcp->mb[6]);
1624 name[6] = MSB(mcp->mb[7]);
1625 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 }
1627
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001628 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1629 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
1631
1632 return rval;
1633}
1634
1635/*
Joe Carnuccio61e1b262013-02-08 01:57:48 -05001636 * qla24xx_link_initialization
1637 * Issue link initialization mailbox command.
1638 *
1639 * Input:
1640 * ha = adapter block pointer.
1641 * TARGET_QUEUE_LOCK must be released.
1642 * ADAPTER_STATE_LOCK must be released.
1643 *
1644 * Returns:
1645 * qla2x00 local function return status code.
1646 *
1647 * Context:
1648 * Kernel context.
1649 */
1650int
1651qla24xx_link_initialize(scsi_qla_host_t *vha)
1652{
1653 int rval;
1654 mbx_cmd_t mc;
1655 mbx_cmd_t *mcp = &mc;
1656
1657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
1658 "Entered %s.\n", __func__);
1659
1660 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
1661 return QLA_FUNCTION_FAILED;
1662
1663 mcp->mb[0] = MBC_LINK_INITIALIZATION;
1664 mcp->mb[1] = BIT_6|BIT_4;
1665 mcp->mb[2] = 0;
1666 mcp->mb[3] = 0;
1667 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1668 mcp->in_mb = MBX_0;
1669 mcp->tov = MBX_TOV_SECONDS;
1670 mcp->flags = 0;
1671 rval = qla2x00_mailbox_command(vha, mcp);
1672
1673 if (rval != QLA_SUCCESS) {
1674 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
1675 } else {
1676 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
1677 "Done %s.\n", __func__);
1678 }
1679
1680 return rval;
1681}
1682
1683/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 * qla2x00_lip_reset
1685 * Issue LIP reset mailbox command.
1686 *
1687 * Input:
1688 * ha = adapter block pointer.
1689 * TARGET_QUEUE_LOCK must be released.
1690 * ADAPTER_STATE_LOCK must be released.
1691 *
1692 * Returns:
1693 * qla2x00 local function return status code.
1694 *
1695 * Context:
1696 * Kernel context.
1697 */
1698int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001699qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700{
1701 int rval;
1702 mbx_cmd_t mc;
1703 mbx_cmd_t *mcp = &mc;
1704
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001705 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
1706 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08001708 if (IS_CNA_CAPABLE(vha->hw)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001709 /* Logout across all FCFs. */
1710 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1711 mcp->mb[1] = BIT_1;
1712 mcp->mb[2] = 0;
1713 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1714 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001715 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001716 mcp->mb[1] = BIT_6;
1717 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001718 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001719 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001721 mcp->mb[0] = MBC_LIP_RESET;
1722 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001723 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001724 mcp->mb[1] = 0x00ff;
1725 mcp->mb[10] = 0;
1726 mcp->out_mb |= MBX_10;
1727 } else {
1728 mcp->mb[1] = 0xff00;
1729 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001730 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001731 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001734 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001736 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 if (rval != QLA_SUCCESS) {
1739 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001740 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 } else {
1742 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001743 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
1744 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
1746
1747 return rval;
1748}
1749
1750/*
1751 * qla2x00_send_sns
1752 * Send SNS command.
1753 *
1754 * Input:
1755 * ha = adapter block pointer.
1756 * sns = pointer for command.
1757 * cmd_size = command size.
1758 * buf_size = response/command size.
1759 * TARGET_QUEUE_LOCK must be released.
1760 * ADAPTER_STATE_LOCK must be released.
1761 *
1762 * Returns:
1763 * qla2x00 local function return status code.
1764 *
1765 * Context:
1766 * Kernel context.
1767 */
1768int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001769qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 uint16_t cmd_size, size_t buf_size)
1771{
1772 int rval;
1773 mbx_cmd_t mc;
1774 mbx_cmd_t *mcp = &mc;
1775
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001776 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
1777 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001779 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001780 "Retry cnt=%d ratov=%d total tov=%d.\n",
1781 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782
1783 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1784 mcp->mb[1] = cmd_size;
1785 mcp->mb[2] = MSW(sns_phys_address);
1786 mcp->mb[3] = LSW(sns_phys_address);
1787 mcp->mb[6] = MSW(MSD(sns_phys_address));
1788 mcp->mb[7] = LSW(MSD(sns_phys_address));
1789 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1790 mcp->in_mb = MBX_0|MBX_1;
1791 mcp->buf_size = buf_size;
1792 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001793 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1794 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 if (rval != QLA_SUCCESS) {
1797 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001798 ql_dbg(ql_dbg_mbx, vha, 0x105f,
1799 "Failed=%x mb[0]=%x mb[1]=%x.\n",
1800 rval, mcp->mb[0], mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 } else {
1802 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001803 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
1804 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 }
1806
1807 return rval;
1808}
1809
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001810int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001811qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001812 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1813{
1814 int rval;
1815
1816 struct logio_entry_24xx *lg;
1817 dma_addr_t lg_dma;
1818 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001819 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001820 struct req_que *req;
1821 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001822
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001823 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
1824 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001825
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07001826 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001827 req = ha->req_q_map[0];
1828 else
1829 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001830 rsp = req->rsp;
1831
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001832 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1833 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001834 ql_log(ql_log_warn, vha, 0x1062,
1835 "Failed to allocate login IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001836 return QLA_MEMORY_ALLOC_FAILED;
1837 }
1838 memset(lg, 0, sizeof(struct logio_entry_24xx));
1839
1840 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1841 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001842 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001843 lg->nport_handle = cpu_to_le16(loop_id);
1844 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1845 if (opt & BIT_0)
1846 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001847 if (opt & BIT_1)
1848 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001849 lg->port_id[0] = al_pa;
1850 lg->port_id[1] = area;
1851 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001852 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08001853 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
1854 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001855 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001856 ql_dbg(ql_dbg_mbx, vha, 0x1063,
1857 "Failed to issue login IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001858 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001859 ql_dbg(ql_dbg_mbx, vha, 0x1064,
1860 "Failed to complete IOCB -- error status (%x).\n",
1861 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001862 rval = QLA_FUNCTION_FAILED;
1863 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1864 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1865 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1866
Saurav Kashyap7c3df132011-07-14 12:00:13 -07001867 ql_dbg(ql_dbg_mbx, vha, 0x1065,
1868 "Failed to complete IOCB -- completion status (%x) "
1869 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
1870 iop[0], iop[1]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001871
1872 switch (iop[0]) {
1873 case LSC_SCODE_PORTID_USED:
1874 mb[0] = MBS_PORT_ID_USED;
1875 mb[1] = LSW(iop[1]);
1876 break;
1877 case LSC_SCODE_NPORT_USED:
1878 mb[0] = MBS_LOOP_ID_USED;
1879 break;
1880 case LSC_SCODE_NOLINK:
1881 case LSC_SCODE_NOIOCB:
1882 case LSC_SCODE_NOXCB:
1883 case LSC_SCODE_CMD_FAILED:
1884 case LSC_SCODE_NOFABRIC:
1885 case LSC_SCODE_FW_NOT_READY:
1886 case LSC_SCODE_NOT_LOGGED_IN:
1887 case LSC_SCODE_NOPCB:
1888 case LSC_SCODE_ELS_REJECT:
1889 case LSC_SCODE_CMD_PARAM_ERR:
1890 case LSC_SCODE_NONPORT:
1891 case LSC_SCODE_LOGGED_IN:
1892 case LSC_SCODE_NOFLOGI_ACC:
1893 default:
1894 mb[0] = MBS_COMMAND_ERROR;
1895 break;
1896 }
1897 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001898 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
1899 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001900
1901 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1902
1903 mb[0] = MBS_COMMAND_COMPLETE;
1904 mb[1] = 0;
1905 if (iop[0] & BIT_4) {
1906 if (iop[0] & BIT_8)
1907 mb[1] |= BIT_1;
1908 } else
1909 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001910
1911 /* Passback COS information. */
1912 mb[10] = 0;
1913 if (lg->io_parameter[7] || lg->io_parameter[8])
1914 mb[10] |= BIT_0; /* Class 2. */
1915 if (lg->io_parameter[9] || lg->io_parameter[10])
1916 mb[10] |= BIT_1; /* Class 3. */
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04001917 if (lg->io_parameter[0] & __constant_cpu_to_le32(BIT_7))
1918 mb[10] |= BIT_7; /* Confirmed Completion
1919 * Allowed
1920 */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001921 }
1922
1923 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1924
1925 return rval;
1926}
1927
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928/*
1929 * qla2x00_login_fabric
1930 * Issue login fabric port mailbox command.
1931 *
1932 * Input:
1933 * ha = adapter block pointer.
1934 * loop_id = device loop ID.
1935 * domain = device domain.
1936 * area = device area.
1937 * al_pa = device AL_PA.
1938 * status = pointer for return status.
1939 * opt = command options.
1940 * TARGET_QUEUE_LOCK must be released.
1941 * ADAPTER_STATE_LOCK must be released.
1942 *
1943 * Returns:
1944 * qla2x00 local function return status code.
1945 *
1946 * Context:
1947 * Kernel context.
1948 */
1949int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001950qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1952{
1953 int rval;
1954 mbx_cmd_t mc;
1955 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001956 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04001958 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
1959 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1962 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1963 if (HAS_EXTENDED_IDS(ha)) {
1964 mcp->mb[1] = loop_id;
1965 mcp->mb[10] = opt;
1966 mcp->out_mb |= MBX_10;
1967 } else {
1968 mcp->mb[1] = (loop_id << 8) | opt;
1969 }
1970 mcp->mb[2] = domain;
1971 mcp->mb[3] = area << 8 | al_pa;
1972
1973 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1974 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1975 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001976 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
1978 /* Return mailbox statuses. */
1979 if (mb != NULL) {
1980 mb[0] = mcp->mb[0];
1981 mb[1] = mcp->mb[1];
1982 mb[2] = mcp->mb[2];
1983 mb[6] = mcp->mb[6];
1984 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001985 /* COS retrieved from Get-Port-Database mailbox command. */
1986 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 }
1988
1989 if (rval != QLA_SUCCESS) {
1990 /* RLU tmp code: need to change main mailbox_command function to
1991 * return ok even when the mailbox completion value is not
1992 * SUCCESS. The caller needs to be responsible to interpret
1993 * the return values of this mailbox command if we're not
1994 * to change too much of the existing code.
1995 */
1996 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1997 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1998 mcp->mb[0] == 0x4006)
1999 rval = QLA_SUCCESS;
2000
2001 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002002 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2003 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2004 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 } else {
2006 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2008 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
2010
2011 return rval;
2012}
2013
2014/*
2015 * qla2x00_login_local_device
2016 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002017 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 * Input:
2019 * ha = adapter block pointer.
2020 * loop_id = device loop ID.
2021 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002022 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 * Returns:
2024 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002025 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 * Context:
2027 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002028 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 */
2030int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002031qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 uint16_t *mb_ret, uint8_t opt)
2033{
2034 int rval;
2035 mbx_cmd_t mc;
2036 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002037 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002039 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2040 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002041
Andrew Vasqueze4289242007-07-19 15:05:56 -07002042 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002043 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002044 fcport->d_id.b.domain, fcport->d_id.b.area,
2045 fcport->d_id.b.al_pa, mb_ret, opt);
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2048 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002049 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08002051 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 mcp->mb[2] = opt;
2053 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2054 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2055 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2056 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002057 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
2059 /* Return mailbox statuses. */
2060 if (mb_ret != NULL) {
2061 mb_ret[0] = mcp->mb[0];
2062 mb_ret[1] = mcp->mb[1];
2063 mb_ret[6] = mcp->mb[6];
2064 mb_ret[7] = mcp->mb[7];
2065 }
2066
2067 if (rval != QLA_SUCCESS) {
2068 /* AV tmp code: need to change main mailbox_command function to
2069 * return ok even when the mailbox completion value is not
2070 * SUCCESS. The caller needs to be responsible to interpret
2071 * the return values of this mailbox command if we're not
2072 * to change too much of the existing code.
2073 */
2074 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2075 rval = QLA_SUCCESS;
2076
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002077 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2078 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2079 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 } else {
2081 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2083 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 }
2085
2086 return (rval);
2087}
2088
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002089int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002090qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002091 uint8_t area, uint8_t al_pa)
2092{
2093 int rval;
2094 struct logio_entry_24xx *lg;
2095 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002096 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002097 struct req_que *req;
2098 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002099
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002100 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2101 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002102
2103 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2104 if (lg == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002105 ql_log(ql_log_warn, vha, 0x106e,
2106 "Failed to allocate logout IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002107 return QLA_MEMORY_ALLOC_FAILED;
2108 }
2109 memset(lg, 0, sizeof(struct logio_entry_24xx));
2110
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002111 if (ql2xmaxqueues > 1)
2112 req = ha->req_q_map[0];
2113 else
2114 req = vha->req;
2115 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002116 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2117 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002118 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002119 lg->nport_handle = cpu_to_le16(loop_id);
2120 lg->control_flags =
Andrew Vasquezc8d66912011-03-30 11:46:21 -07002121 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
2122 LCF_FREE_NPORT);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002123 lg->port_id[0] = al_pa;
2124 lg->port_id[1] = area;
2125 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002126 lg->vp_index = vha->vp_idx;
Andrew Vasquez7f45dd02012-02-09 11:15:45 -08002127 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2128 (ha->r_a_tov / 10 * 2) + 2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002129 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002130 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2131 "Failed to issue logout IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002132 } else if (lg->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002133 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2134 "Failed to complete IOCB -- error status (%x).\n",
2135 lg->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002136 rval = QLA_FUNCTION_FAILED;
2137 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002138 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2139 "Failed to complete IOCB -- completion status (%x) "
2140 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002141 le32_to_cpu(lg->io_parameter[0]),
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002142 le32_to_cpu(lg->io_parameter[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002143 } else {
2144 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002145 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2146 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002147 }
2148
2149 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2150
2151 return rval;
2152}
2153
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154/*
2155 * qla2x00_fabric_logout
2156 * Issue logout fabric port mailbox command.
2157 *
2158 * Input:
2159 * ha = adapter block pointer.
2160 * loop_id = device loop ID.
2161 * TARGET_QUEUE_LOCK must be released.
2162 * ADAPTER_STATE_LOCK must be released.
2163 *
2164 * Returns:
2165 * qla2x00 local function return status code.
2166 *
2167 * Context:
2168 * Kernel context.
2169 */
2170int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002171qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002172 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
2174 int rval;
2175 mbx_cmd_t mc;
2176 mbx_cmd_t *mcp = &mc;
2177
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002178 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2179 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180
2181 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2182 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002183 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 mcp->mb[1] = loop_id;
2185 mcp->mb[10] = 0;
2186 mcp->out_mb |= MBX_10;
2187 } else {
2188 mcp->mb[1] = loop_id << 8;
2189 }
2190
2191 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002192 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002194 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 if (rval != QLA_SUCCESS) {
2197 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002198 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2199 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 } else {
2201 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002202 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2203 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 }
2205
2206 return rval;
2207}
2208
2209/*
2210 * qla2x00_full_login_lip
2211 * Issue full login LIP mailbox command.
2212 *
2213 * Input:
2214 * ha = adapter block pointer.
2215 * TARGET_QUEUE_LOCK must be released.
2216 * ADAPTER_STATE_LOCK must be released.
2217 *
2218 * Returns:
2219 * qla2x00 local function return status code.
2220 *
2221 * Context:
2222 * Kernel context.
2223 */
2224int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002225qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226{
2227 int rval;
2228 mbx_cmd_t mc;
2229 mbx_cmd_t *mcp = &mc;
2230
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002231 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2232 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233
2234 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002235 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08002236 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 mcp->mb[3] = 0;
2238 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2239 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002240 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002242 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244 if (rval != QLA_SUCCESS) {
2245 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002246 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 } else {
2248 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2250 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 }
2252
2253 return rval;
2254}
2255
2256/*
2257 * qla2x00_get_id_list
2258 *
2259 * Input:
2260 * ha = adapter block pointer.
2261 *
2262 * Returns:
2263 * qla2x00 local function return status code.
2264 *
2265 * Context:
2266 * Kernel context.
2267 */
2268int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002269qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 uint16_t *entries)
2271{
2272 int rval;
2273 mbx_cmd_t mc;
2274 mbx_cmd_t *mcp = &mc;
2275
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002276 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2277 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
2279 if (id_list == NULL)
2280 return QLA_FUNCTION_FAILED;
2281
2282 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002284 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002285 mcp->mb[2] = MSW(id_list_dma);
2286 mcp->mb[3] = LSW(id_list_dma);
2287 mcp->mb[6] = MSW(MSD(id_list_dma));
2288 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08002289 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002290 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002291 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002292 } else {
2293 mcp->mb[1] = MSW(id_list_dma);
2294 mcp->mb[2] = LSW(id_list_dma);
2295 mcp->mb[3] = MSW(MSD(id_list_dma));
2296 mcp->mb[6] = LSW(MSD(id_list_dma));
2297 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002300 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002302 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303
2304 if (rval != QLA_SUCCESS) {
2305 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002306 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 } else {
2308 *entries = mcp->mb[1];
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002309 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2310 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312
2313 return rval;
2314}
2315
2316/*
2317 * qla2x00_get_resource_cnts
2318 * Get current firmware resource counts.
2319 *
2320 * Input:
2321 * ha = adapter block pointer.
2322 *
2323 * Returns:
2324 * qla2x00 local function return status code.
2325 *
2326 * Context:
2327 * Kernel context.
2328 */
2329int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002330qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002331 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002332 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333{
2334 int rval;
2335 mbx_cmd_t mc;
2336 mbx_cmd_t *mcp = &mc;
2337
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2339 "Entered %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340
2341 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2342 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002343 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002344 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw))
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002345 mcp->in_mb |= MBX_12;
Ravi Anandb93480e2008-04-03 13:13:25 -07002346 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002348 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
2350 if (rval != QLA_SUCCESS) {
2351 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002352 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2353 "Failed mb[0]=%x.\n", mcp->mb[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002355 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002356 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2357 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2358 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2359 mcp->mb[11], mcp->mb[12]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
2361 if (cur_xchg_cnt)
2362 *cur_xchg_cnt = mcp->mb[3];
2363 if (orig_xchg_cnt)
2364 *orig_xchg_cnt = mcp->mb[6];
2365 if (cur_iocb_cnt)
2366 *cur_iocb_cnt = mcp->mb[7];
2367 if (orig_iocb_cnt)
2368 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002369 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002370 *max_npiv_vports = mcp->mb[11];
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002371 if ((IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw)) && max_fcfs)
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07002372 *max_fcfs = mcp->mb[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 }
2374
2375 return (rval);
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378/*
2379 * qla2x00_get_fcal_position_map
2380 * Get FCAL (LILP) position map using mailbox command
2381 *
2382 * Input:
2383 * ha = adapter state pointer.
2384 * pos_map = buffer pointer (can be NULL).
2385 *
2386 * Returns:
2387 * qla2x00 local function return status code.
2388 *
2389 * Context:
2390 * Kernel context.
2391 */
2392int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002393qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
2395 int rval;
2396 mbx_cmd_t mc;
2397 mbx_cmd_t *mcp = &mc;
2398 char *pmap;
2399 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002400 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002402 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2403 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002404
Andrew Vasquez4b892582008-09-11 21:22:48 -07002405 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 if (pmap == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002407 ql_log(ql_log_warn, vha, 0x1080,
2408 "Memory alloc failed.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 return QLA_MEMORY_ALLOC_FAILED;
2410 }
2411 memset(pmap, 0, FCAL_MAP_SIZE);
2412
2413 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2414 mcp->mb[2] = MSW(pmap_dma);
2415 mcp->mb[3] = LSW(pmap_dma);
2416 mcp->mb[6] = MSW(MSD(pmap_dma));
2417 mcp->mb[7] = LSW(MSD(pmap_dma));
2418 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2419 mcp->in_mb = MBX_1|MBX_0;
2420 mcp->buf_size = FCAL_MAP_SIZE;
2421 mcp->flags = MBX_DMA_IN;
2422 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002423 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424
2425 if (rval == QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002426 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002427 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2428 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2429 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2430 pmap, pmap[0] + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
2432 if (pos_map)
2433 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2434 }
2435 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2436
2437 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002438 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002440 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2441 "Done %s.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 }
2443
2444 return rval;
2445}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002446
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002447/*
2448 * qla2x00_get_link_status
2449 *
2450 * Input:
2451 * ha = adapter block pointer.
2452 * loop_id = device loop ID.
2453 * ret_buf = pointer to link status return buffer.
2454 *
2455 * Returns:
2456 * 0 = success.
2457 * BIT_0 = mem alloc error.
2458 * BIT_1 = mailbox error.
2459 */
2460int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002461qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002462 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002463{
2464 int rval;
2465 mbx_cmd_t mc;
2466 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002467 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002468 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002469
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2471 "Entered %s.\n", __func__);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002472
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002473 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002474 mcp->mb[2] = MSW(stats_dma);
2475 mcp->mb[3] = LSW(stats_dma);
2476 mcp->mb[6] = MSW(MSD(stats_dma));
2477 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002478 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2479 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002480 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002481 mcp->mb[1] = loop_id;
2482 mcp->mb[4] = 0;
2483 mcp->mb[10] = 0;
2484 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2485 mcp->in_mb |= MBX_1;
2486 } else if (HAS_EXTENDED_IDS(ha)) {
2487 mcp->mb[1] = loop_id;
2488 mcp->mb[10] = 0;
2489 mcp->out_mb |= MBX_10|MBX_1;
2490 } else {
2491 mcp->mb[1] = loop_id << 8;
2492 mcp->out_mb |= MBX_1;
2493 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002494 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002495 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002496 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002497
2498 if (rval == QLA_SUCCESS) {
2499 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002500 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2501 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002502 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002503 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002504 /* Copy over data -- firmware data is LE. */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002505 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2506 "Done %s.\n", __func__);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002507 dwords = offsetof(struct link_statistics, unused1) / 4;
2508 siter = diter = &stats->link_fail_cnt;
2509 while (dwords--)
2510 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002511 }
2512 } else {
2513 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002514 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002515 }
2516
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002517 return rval;
2518}
2519
2520int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002521qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002522 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002523{
2524 int rval;
2525 mbx_cmd_t mc;
2526 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002527 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002528
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002529 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2530 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002531
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002532 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002533 mcp->mb[2] = MSW(stats_dma);
2534 mcp->mb[3] = LSW(stats_dma);
2535 mcp->mb[6] = MSW(MSD(stats_dma));
2536 mcp->mb[7] = LSW(MSD(stats_dma));
2537 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002538 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002539 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002540 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002541 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002542 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002543 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002544 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002545
2546 if (rval == QLA_SUCCESS) {
2547 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002548 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2549 "Failed mb[0]=%x.\n", mcp->mb[0]);
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002550 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002551 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002552 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2553 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002554 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002555 dwords = sizeof(struct link_statistics) / 4;
2556 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002557 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002558 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002559 }
2560 } else {
2561 /* Failed. */
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002562 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002563 }
2564
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002565 return rval;
2566}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002567
2568int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002569qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002570{
2571 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002572 unsigned long flags = 0;
2573
2574 struct abort_entry_24xx *abt;
2575 dma_addr_t abt_dma;
2576 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002577 fc_port_t *fcport = sp->fcport;
2578 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002579 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07002580 struct req_que *req = vha->req;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002581
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002582 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2583 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002584
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002585 spin_lock_irqsave(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002586 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002587 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002588 break;
2589 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002590 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Chad Dupuis8d93f552013-01-30 03:34:37 -05002591 if (handle == req->num_outstanding_cmds) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002592 /* Command not found. */
2593 return QLA_FUNCTION_FAILED;
2594 }
2595
2596 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2597 if (abt == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002598 ql_log(ql_log_warn, vha, 0x108d,
2599 "Failed to allocate abort IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002600 return QLA_MEMORY_ALLOC_FAILED;
2601 }
2602 memset(abt, 0, sizeof(struct abort_entry_24xx));
2603
2604 abt->entry_type = ABORT_IOCB_TYPE;
2605 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002606 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002607 abt->nport_handle = cpu_to_le16(fcport->loop_id);
Mike Hernandeza74ec142011-03-30 11:46:20 -07002608 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002609 abt->port_id[0] = fcport->d_id.b.al_pa;
2610 abt->port_id[1] = fcport->d_id.b.area;
2611 abt->port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002612 abt->vp_index = fcport->vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002613
2614 abt->req_que_no = cpu_to_le16(req->id);
2615
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002616 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002617 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002618 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2619 "Failed to issue IOCB (%x).\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002620 } else if (abt->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002621 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2622 "Failed to complete IOCB -- error status (%x).\n",
2623 abt->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002624 rval = QLA_FUNCTION_FAILED;
2625 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002626 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2627 "Failed to complete IOCB -- completion status (%x).\n",
2628 le16_to_cpu(abt->nport_handle));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002629 rval = QLA_FUNCTION_FAILED;
2630 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002631 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2632 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002633 }
2634
2635 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2636
2637 return rval;
2638}
2639
2640struct tsk_mgmt_cmd {
2641 union {
2642 struct tsk_mgmt_entry tsk;
2643 struct sts_entry_24xx sts;
2644 } p;
2645};
2646
Andrew Vasquez523ec772008-04-03 13:13:24 -07002647static int
2648__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002649 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002650{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002651 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002652 struct tsk_mgmt_cmd *tsk;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002653 struct sts_entry_24xx *sts;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002654 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002655 scsi_qla_host_t *vha;
2656 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002657 struct req_que *req;
2658 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002659
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002660 vha = fcport->vha;
2661 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002662 req = vha->req;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002663
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002664 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
2665 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002666
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07002667 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002668 rsp = ha->rsp_q_map[tag + 1];
2669 else
2670 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002671 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002672 if (tsk == NULL) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002673 ql_log(ql_log_warn, vha, 0x1093,
2674 "Failed to allocate task management IOCB.\n");
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002675 return QLA_MEMORY_ALLOC_FAILED;
2676 }
2677 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2678
2679 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2680 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002681 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002682 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002683 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002684 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002685 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2686 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2687 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Joe Carnuccioc6d39e22012-05-15 14:34:20 -04002688 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002689 if (type == TCF_LUN_RESET) {
2690 int_to_scsilun(l, &tsk->p.tsk.lun);
2691 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2692 sizeof(tsk->p.tsk.lun));
2693 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002694
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002695 sts = &tsk->p.sts;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002696 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002697 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002698 ql_dbg(ql_dbg_mbx, vha, 0x1094,
2699 "Failed to issue %s reset IOCB (%x).\n", name, rval);
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002700 } else if (sts->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002701 ql_dbg(ql_dbg_mbx, vha, 0x1095,
2702 "Failed to complete IOCB -- error status (%x).\n",
2703 sts->entry_status);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002704 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002705 } else if (sts->comp_status !=
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002706 __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002707 ql_dbg(ql_dbg_mbx, vha, 0x1096,
2708 "Failed to complete IOCB -- completion status (%x).\n",
2709 le16_to_cpu(sts->comp_status));
Andrew Vasquez9ca1d012009-10-13 15:16:50 -07002710 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez97dec562011-02-23 15:27:14 -08002711 } else if (le16_to_cpu(sts->scsi_status) &
2712 SS_RESPONSE_INFO_LEN_VALID) {
2713 if (le32_to_cpu(sts->rsp_data_len) < 4) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002714 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002715 "Ignoring inconsistent data length -- not enough "
2716 "response info (%d).\n",
2717 le32_to_cpu(sts->rsp_data_len));
Andrew Vasquez97dec562011-02-23 15:27:14 -08002718 } else if (sts->data[3]) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002719 ql_dbg(ql_dbg_mbx, vha, 0x1098,
2720 "Failed to complete IOCB -- response (%x).\n",
2721 sts->data[3]);
Andrew Vasquez97dec562011-02-23 15:27:14 -08002722 rval = QLA_FUNCTION_FAILED;
2723 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002724 }
2725
2726 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002727 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002728 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2729 if (rval2 != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002730 ql_dbg(ql_dbg_mbx, vha, 0x1099,
2731 "Failed to issue marker IOCB (%x).\n", rval2);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002732 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002733 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
2734 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002735 }
2736
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002737 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002738
2739 return rval;
2740}
2741
Andrew Vasquez523ec772008-04-03 13:13:24 -07002742int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002743qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002744{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002745 struct qla_hw_data *ha = fcport->vha->hw;
2746
2747 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2748 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
2749
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002750 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002751}
2752
2753int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002754qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002755{
Madhuranath Iyengar38222632010-05-04 15:01:29 -07002756 struct qla_hw_data *ha = fcport->vha->hw;
2757
2758 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
2759 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
2760
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002761 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002762}
2763
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002764int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002765qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002766{
2767 int rval;
2768 mbx_cmd_t mc;
2769 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002770 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002771
Andrew Vasquez68af0812008-05-12 22:21:13 -07002772 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002773 return QLA_FUNCTION_FAILED;
2774
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002775 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
2776 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002777
2778 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2779 mcp->out_mb = MBX_0;
2780 mcp->in_mb = MBX_0;
2781 mcp->tov = 5;
2782 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002783 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002784
2785 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002786 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002787 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002788 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
2789 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002790 }
2791
2792 return rval;
2793}
2794
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002795/**
2796 * qla2x00_set_serdes_params() -
2797 * @ha: HA context
2798 *
2799 * Returns
2800 */
2801int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002802qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002803 uint16_t sw_em_2g, uint16_t sw_em_4g)
2804{
2805 int rval;
2806 mbx_cmd_t mc;
2807 mbx_cmd_t *mcp = &mc;
2808
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002809 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
2810 "Entered %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002811
2812 mcp->mb[0] = MBC_SERDES_PARAMS;
2813 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002814 mcp->mb[2] = sw_em_1g | BIT_15;
2815 mcp->mb[3] = sw_em_2g | BIT_15;
2816 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002817 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2818 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002819 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002820 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002821 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002822
2823 if (rval != QLA_SUCCESS) {
2824 /*EMPTY*/
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002825 ql_dbg(ql_dbg_mbx, vha, 0x109f,
2826 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002827 } else {
2828 /*EMPTY*/
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002829 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
2830 "Done %s.\n", __func__);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002831 }
2832
2833 return rval;
2834}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002835
2836int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002837qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002838{
2839 int rval;
2840 mbx_cmd_t mc;
2841 mbx_cmd_t *mcp = &mc;
2842
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002843 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002844 return QLA_FUNCTION_FAILED;
2845
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002846 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
2847 "Entered %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002848
2849 mcp->mb[0] = MBC_STOP_FIRMWARE;
Andrew Vasquez4ba988d2012-02-09 11:14:06 -08002850 mcp->mb[1] = 0;
2851 mcp->out_mb = MBX_1|MBX_0;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002852 mcp->in_mb = MBX_0;
2853 mcp->tov = 5;
2854 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002855 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002856
2857 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002858 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07002859 if (mcp->mb[0] == MBS_INVALID_COMMAND)
2860 rval = QLA_INVALID_COMMAND;
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002861 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002862 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
2863 "Done %s.\n", __func__);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002864 }
2865
2866 return rval;
2867}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002868
2869int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002870qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002871 uint16_t buffers)
2872{
2873 int rval;
2874 mbx_cmd_t mc;
2875 mbx_cmd_t *mcp = &mc;
2876
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002877 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
2878 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002879
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002880 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002881 return QLA_FUNCTION_FAILED;
2882
Andrew Vasquez85880802009-12-15 21:29:46 -08002883 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2884 return QLA_FUNCTION_FAILED;
2885
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002886 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002887 mcp->mb[1] = TC_EFT_ENABLE;
2888 mcp->mb[2] = LSW(eft_dma);
2889 mcp->mb[3] = MSW(eft_dma);
2890 mcp->mb[4] = LSW(MSD(eft_dma));
2891 mcp->mb[5] = MSW(MSD(eft_dma));
2892 mcp->mb[6] = buffers;
2893 mcp->mb[7] = TC_AEN_DISABLE;
2894 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 -07002895 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002896 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002897 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002898 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002899 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002900 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
2901 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2902 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002903 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
2905 "Done %s.\n", __func__);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002906 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002907
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002908 return rval;
2909}
2910
2911int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002912qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002913{
2914 int rval;
2915 mbx_cmd_t mc;
2916 mbx_cmd_t *mcp = &mc;
2917
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002918 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
2919 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002920
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002921 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002922 return QLA_FUNCTION_FAILED;
2923
Andrew Vasquez85880802009-12-15 21:29:46 -08002924 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2925 return QLA_FUNCTION_FAILED;
2926
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002927 mcp->mb[0] = MBC_TRACE_CONTROL;
2928 mcp->mb[1] = TC_EFT_DISABLE;
2929 mcp->out_mb = MBX_1|MBX_0;
2930 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002931 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002932 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002933 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002934 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002935 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
2936 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2937 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002938 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002939 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
2940 "Done %s.\n", __func__);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002941 }
2942
2943 return rval;
2944}
2945
Andrew Vasquez88729e52006-06-23 16:10:50 -07002946int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002947qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002948 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2949{
2950 int rval;
2951 mbx_cmd_t mc;
2952 mbx_cmd_t *mcp = &mc;
2953
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002954 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
2955 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002956
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08002957 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
2958 !IS_QLA83XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002959 return QLA_FUNCTION_FAILED;
2960
Andrew Vasquez85880802009-12-15 21:29:46 -08002961 if (unlikely(pci_channel_offline(vha->hw->pdev)))
2962 return QLA_FUNCTION_FAILED;
2963
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002964 mcp->mb[0] = MBC_TRACE_CONTROL;
2965 mcp->mb[1] = TC_FCE_ENABLE;
2966 mcp->mb[2] = LSW(fce_dma);
2967 mcp->mb[3] = MSW(fce_dma);
2968 mcp->mb[4] = LSW(MSD(fce_dma));
2969 mcp->mb[5] = MSW(MSD(fce_dma));
2970 mcp->mb[6] = buffers;
2971 mcp->mb[7] = TC_AEN_DISABLE;
2972 mcp->mb[8] = 0;
2973 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2974 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2975 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2976 MBX_1|MBX_0;
2977 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002978 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002979 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002980 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002981 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07002982 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
2983 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2984 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002985 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04002986 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
2987 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002988
2989 if (mb)
2990 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2991 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002992 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002993 }
2994
2995 return rval;
2996}
2997
2998int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002999qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003000{
3001 int rval;
3002 mbx_cmd_t mc;
3003 mbx_cmd_t *mcp = &mc;
3004
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003005 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3006 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003007
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003008 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003009 return QLA_FUNCTION_FAILED;
3010
Andrew Vasquez85880802009-12-15 21:29:46 -08003011 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3012 return QLA_FUNCTION_FAILED;
3013
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003014 mcp->mb[0] = MBC_TRACE_CONTROL;
3015 mcp->mb[1] = TC_FCE_DISABLE;
3016 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3017 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3018 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3019 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003020 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003021 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003022 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003023 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003024 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3025 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3026 rval, mcp->mb[0], mcp->mb[1]);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003027 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003028 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3029 "Done %s.\n", __func__);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003030
3031 if (wr)
3032 *wr = (uint64_t) mcp->mb[5] << 48 |
3033 (uint64_t) mcp->mb[4] << 32 |
3034 (uint64_t) mcp->mb[3] << 16 |
3035 (uint64_t) mcp->mb[2];
3036 if (rd)
3037 *rd = (uint64_t) mcp->mb[9] << 48 |
3038 (uint64_t) mcp->mb[8] << 32 |
3039 (uint64_t) mcp->mb[7] << 16 |
3040 (uint64_t) mcp->mb[6];
3041 }
3042
3043 return rval;
3044}
3045
3046int
Giridhar Malavali6e980162010-03-19 17:03:58 -07003047qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3048 uint16_t *port_speed, uint16_t *mb)
3049{
3050 int rval;
3051 mbx_cmd_t mc;
3052 mbx_cmd_t *mcp = &mc;
3053
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003054 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3055 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003056
Giridhar Malavali6e980162010-03-19 17:03:58 -07003057 if (!IS_IIDMA_CAPABLE(vha->hw))
3058 return QLA_FUNCTION_FAILED;
3059
Giridhar Malavali6e980162010-03-19 17:03:58 -07003060 mcp->mb[0] = MBC_PORT_PARAMS;
3061 mcp->mb[1] = loop_id;
3062 mcp->mb[2] = mcp->mb[3] = 0;
3063 mcp->mb[9] = vha->vp_idx;
3064 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3065 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3066 mcp->tov = MBX_TOV_SECONDS;
3067 mcp->flags = 0;
3068 rval = qla2x00_mailbox_command(vha, mcp);
3069
3070 /* Return mailbox statuses. */
3071 if (mb != NULL) {
3072 mb[0] = mcp->mb[0];
3073 mb[1] = mcp->mb[1];
3074 mb[3] = mcp->mb[3];
3075 }
3076
3077 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003078 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003079 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003080 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3081 "Done %s.\n", __func__);
Giridhar Malavali6e980162010-03-19 17:03:58 -07003082 if (port_speed)
3083 *port_speed = mcp->mb[3];
3084 }
3085
3086 return rval;
3087}
3088
3089int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003090qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003091 uint16_t port_speed, uint16_t *mb)
3092{
3093 int rval;
3094 mbx_cmd_t mc;
3095 mbx_cmd_t *mcp = &mc;
3096
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3098 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003099
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003100 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003101 return QLA_FUNCTION_FAILED;
3102
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003103 mcp->mb[0] = MBC_PORT_PARAMS;
3104 mcp->mb[1] = loop_id;
3105 mcp->mb[2] = BIT_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003106 if (IS_CNA_CAPABLE(vha->hw))
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07003107 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3108 else
3109 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3110 mcp->mb[9] = vha->vp_idx;
3111 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3112 mcp->in_mb = MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003113 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003114 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003115 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003116
3117 /* Return mailbox statuses. */
3118 if (mb != NULL) {
3119 mb[0] = mcp->mb[0];
3120 mb[1] = mcp->mb[1];
3121 mb[3] = mcp->mb[3];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003122 }
3123
3124 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003125 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3126 "Failed=%x.\n", rval);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003127 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003128 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3129 "Done %s.\n", __func__);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003130 }
3131
3132 return rval;
3133}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003134
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003135void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003136qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003137 struct vp_rpt_id_entry_24xx *rptid_entry)
3138{
3139 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07003140 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003141 struct qla_hw_data *ha = vha->hw;
3142 scsi_qla_host_t *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003143 unsigned long flags;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003144
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003145 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3146 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003147
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003148 if (rptid_entry->entry_status != 0)
3149 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003150
3151 if (rptid_entry->format == 0) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003152 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b7,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003153 "Format 0 : Number of VPs setup %d, number of "
3154 "VPs acquired %d.\n",
3155 MSB(le16_to_cpu(rptid_entry->vp_count)),
3156 LSB(le16_to_cpu(rptid_entry->vp_count)));
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003157 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b8,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003158 "Primary port id %02x%02x%02x.\n",
3159 rptid_entry->port_id[2], rptid_entry->port_id[1],
3160 rptid_entry->port_id[0]);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003161 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07003162 vp_idx = LSB(stat);
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003163 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b9,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003164 "Format 1: VP[%d] enabled - status %d - with "
3165 "port id %02x%02x%02x.\n", vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003166 rptid_entry->port_id[2], rptid_entry->port_id[1],
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003167 rptid_entry->port_id[0]);
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003168
3169 vp = vha;
3170 if (vp_idx == 0 && (MSB(stat) != 1))
3171 goto reg_needed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003172
Saurav Kashyap681e0142012-11-21 02:40:28 -05003173 if (MSB(stat) != 0 && MSB(stat) != 2) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003174 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3175 "Could not acquire ID for VP[%d].\n", vp_idx);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003176 return;
Andrew Vasquez81eb9b42009-06-03 09:55:23 -07003177 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003178
Arun Easifeafb7b2010-09-03 14:57:00 -07003179 spin_lock_irqsave(&ha->vport_slock, flags);
3180 list_for_each_entry(vp, &ha->vp_list, list)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003181 if (vp_idx == vp->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003182 break;
Arun Easifeafb7b2010-09-03 14:57:00 -07003183 spin_unlock_irqrestore(&ha->vport_slock, flags);
3184
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003185 if (!vp)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003186 return;
3187
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003188 vp->d_id.b.domain = rptid_entry->port_id[2];
3189 vp->d_id.b.area = rptid_entry->port_id[1];
3190 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003191
3192 /*
3193 * Cannot configure here as we are still sitting on the
3194 * response queue. Handle it in dpc context.
3195 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003196 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003197
Andrew Vasquez531a82d2009-10-13 15:16:51 -07003198reg_needed:
3199 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3200 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
3201 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003202 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003203 }
3204}
3205
3206/*
3207 * qla24xx_modify_vp_config
3208 * Change VP configuration for vha
3209 *
3210 * Input:
3211 * vha = adapter block pointer.
3212 *
3213 * Returns:
3214 * qla2xxx local function return status code.
3215 *
3216 * Context:
3217 * Kernel context.
3218 */
3219int
3220qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3221{
3222 int rval;
3223 struct vp_config_entry_24xx *vpmod;
3224 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003225 struct qla_hw_data *ha = vha->hw;
3226 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003227
3228 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003229
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003230 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3231 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003232
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003233 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003234 if (!vpmod) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003235 ql_log(ql_log_warn, vha, 0x10bc,
3236 "Failed to allocate modify VP IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003237 return QLA_MEMORY_ALLOC_FAILED;
3238 }
3239
3240 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3241 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3242 vpmod->entry_count = 1;
3243 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3244 vpmod->vp_count = 1;
3245 vpmod->vp_index1 = vha->vp_idx;
3246 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
Nicholas Bellinger2d70c102012-05-15 14:34:28 -04003247
3248 qlt_modify_vp_config(vha, vpmod);
3249
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003250 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3251 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3252 vpmod->entry_count = 1;
3253
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003254 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003255 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003256 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3257 "Failed to issue VP config IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003258 } else if (vpmod->comp_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003259 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3260 "Failed to complete IOCB -- error status (%x).\n",
3261 vpmod->comp_status);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003262 rval = QLA_FUNCTION_FAILED;
3263 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003264 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3265 "Failed to complete IOCB -- completion status (%x).\n",
3266 le16_to_cpu(vpmod->comp_status));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003267 rval = QLA_FUNCTION_FAILED;
3268 } else {
3269 /* EMPTY */
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003270 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3271 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003272 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3273 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003274 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003275
3276 return rval;
3277}
3278
3279/*
3280 * qla24xx_control_vp
3281 * Enable a virtual port for given host
3282 *
3283 * Input:
3284 * ha = adapter block pointer.
3285 * vhba = virtual adapter (unused)
3286 * index = index number for enabled VP
3287 *
3288 * Returns:
3289 * qla2xxx local function return status code.
3290 *
3291 * Context:
3292 * Kernel context.
3293 */
3294int
3295qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3296{
3297 int rval;
3298 int map, pos;
3299 struct vp_ctrl_entry_24xx *vce;
3300 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003301 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003302 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003303 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003304
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003305 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003306 "Entered %s enabling index %d.\n", __func__, vp_index);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003307
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08003308 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003309 return QLA_PARAMETER_ERROR;
3310
3311 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3312 if (!vce) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003313 ql_log(ql_log_warn, vha, 0x10c2,
3314 "Failed to allocate VP control IOCB.\n");
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003315 return QLA_MEMORY_ALLOC_FAILED;
3316 }
3317 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3318
3319 vce->entry_type = VP_CTRL_IOCB_TYPE;
3320 vce->entry_count = 1;
3321 vce->command = cpu_to_le16(cmd);
3322 vce->vp_count = __constant_cpu_to_le16(1);
3323
3324 /* index map in firmware starts with 1; decrement index
3325 * this is ok as we never use index 0
3326 */
3327 map = (vp_index - 1) / 8;
3328 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003329 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003330 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07003331 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003332
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003333 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003334 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003335 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3336 "Failed to issue VP control IOCB (%x).\n", rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003337 } else if (vce->entry_status != 0) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003338 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3339 "Failed to complete IOCB -- error status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003340 vce->entry_status);
3341 rval = QLA_FUNCTION_FAILED;
3342 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003343 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3344 "Failed to complet IOCB -- completion status (%x).\n",
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003345 le16_to_cpu(vce->comp_status));
3346 rval = QLA_FUNCTION_FAILED;
3347 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003348 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3349 "Done %s.\n", __func__);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003350 }
3351
3352 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3353
3354 return rval;
3355}
3356
3357/*
3358 * qla2x00_send_change_request
3359 * Receive or disable RSCN request from fabric controller
3360 *
3361 * Input:
3362 * ha = adapter block pointer
3363 * format = registration format:
3364 * 0 - Reserved
3365 * 1 - Fabric detected registration
3366 * 2 - N_port detected registration
3367 * 3 - Full registration
3368 * FF - clear registration
3369 * vp_idx = Virtual port index
3370 *
3371 * Returns:
3372 * qla2x00 local function return status code.
3373 *
3374 * Context:
3375 * Kernel Context
3376 */
3377
3378int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003379qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003380 uint16_t vp_idx)
3381{
3382 int rval;
3383 mbx_cmd_t mc;
3384 mbx_cmd_t *mcp = &mc;
3385
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003386 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3387 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003388
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003389 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3390 mcp->mb[1] = format;
3391 mcp->mb[9] = vp_idx;
3392 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3393 mcp->in_mb = MBX_0|MBX_1;
3394 mcp->tov = MBX_TOV_SECONDS;
3395 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003396 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003397
3398 if (rval == QLA_SUCCESS) {
3399 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3400 rval = BIT_1;
3401 }
3402 } else
3403 rval = BIT_1;
3404
3405 return rval;
3406}
Andrew Vasquez338c9162007-09-20 14:07:33 -07003407
3408int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003409qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07003410 uint32_t size)
3411{
3412 int rval;
3413 mbx_cmd_t mc;
3414 mbx_cmd_t *mcp = &mc;
3415
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003416 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3417 "Entered %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003418
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003419 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003420 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3421 mcp->mb[8] = MSW(addr);
3422 mcp->out_mb = MBX_8|MBX_0;
3423 } else {
3424 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3425 mcp->out_mb = MBX_0;
3426 }
3427 mcp->mb[1] = LSW(addr);
3428 mcp->mb[2] = MSW(req_dma);
3429 mcp->mb[3] = LSW(req_dma);
3430 mcp->mb[6] = MSW(MSD(req_dma));
3431 mcp->mb[7] = LSW(MSD(req_dma));
3432 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003433 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003434 mcp->mb[4] = MSW(size);
3435 mcp->mb[5] = LSW(size);
3436 mcp->out_mb |= MBX_5|MBX_4;
3437 } else {
3438 mcp->mb[4] = LSW(size);
3439 mcp->out_mb |= MBX_4;
3440 }
3441
3442 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003443 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003444 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003445 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003446
3447 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003448 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3449 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003450 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003451 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3452 "Done %s.\n", __func__);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003453 }
3454
3455 return rval;
3456}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003457/* 84XX Support **************************************************************/
3458
3459struct cs84xx_mgmt_cmd {
3460 union {
3461 struct verify_chip_entry_84xx req;
3462 struct verify_chip_rsp_84xx rsp;
3463 } p;
3464};
3465
3466int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003467qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003468{
3469 int rval, retry;
3470 struct cs84xx_mgmt_cmd *mn;
3471 dma_addr_t mn_dma;
3472 uint16_t options;
3473 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003474 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003475
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003476 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
3477 "Entered %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003478
3479 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3480 if (mn == NULL) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003481 return QLA_MEMORY_ALLOC_FAILED;
3482 }
3483
3484 /* Force Update? */
3485 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3486 /* Diagnostic firmware? */
3487 /* options |= MENLO_DIAG_FW; */
3488 /* We update the firmware with only one data sequence. */
3489 options |= VCO_END_OF_DATA;
3490
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003491 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003492 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003493 memset(mn, 0, sizeof(*mn));
3494 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3495 mn->p.req.entry_count = 1;
3496 mn->p.req.options = cpu_to_le16(options);
3497
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003498 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
3499 "Dump of Verify Request.\n");
3500 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
3501 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003502
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003503 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003504 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003505 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
3506 "Failed to issue verify IOCB (%x).\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003507 goto verify_done;
3508 }
3509
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003510 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
3511 "Dump of Verify Response.\n");
3512 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
3513 (uint8_t *)mn, sizeof(*mn));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003514
3515 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3516 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3517 le16_to_cpu(mn->p.rsp.failure_code) : 0;
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003518 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003519 "cs=%x fc=%x.\n", status[0], status[1]);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003520
3521 if (status[0] != CS_COMPLETE) {
3522 rval = QLA_FUNCTION_FAILED;
3523 if (!(options & VCO_DONT_UPDATE_FW)) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003524 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
3525 "Firmware update failed. Retrying "
3526 "without update firmware.\n");
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003527 options |= VCO_DONT_UPDATE_FW;
3528 options &= ~VCO_FORCE_UPDATE;
3529 retry = 1;
3530 }
3531 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003532 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003533 "Firmware updated to %x.\n",
3534 le32_to_cpu(mn->p.rsp.fw_ver));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003535
3536 /* NOTE: we only update OP firmware. */
3537 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3538 ha->cs84xx->op_fw_version =
3539 le32_to_cpu(mn->p.rsp.fw_ver);
3540 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3541 flags);
3542 }
3543 } while (retry);
3544
3545verify_done:
3546 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3547
3548 if (rval != QLA_SUCCESS) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003549 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
3550 "Failed=%x.\n", rval);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003551 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003552 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
3553 "Done %s.\n", __func__);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003554 }
3555
3556 return rval;
3557}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003558
3559int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003560qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003561{
3562 int rval;
3563 unsigned long flags;
3564 mbx_cmd_t mc;
3565 mbx_cmd_t *mcp = &mc;
3566 struct device_reg_25xxmq __iomem *reg;
3567 struct qla_hw_data *ha = vha->hw;
3568
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
3570 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003571
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003572 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003573 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003574 mcp->mb[2] = MSW(LSD(req->dma));
3575 mcp->mb[3] = LSW(LSD(req->dma));
3576 mcp->mb[6] = MSW(MSD(req->dma));
3577 mcp->mb[7] = LSW(MSD(req->dma));
3578 mcp->mb[5] = req->length;
3579 if (req->rsp)
3580 mcp->mb[10] = req->rsp->id;
3581 mcp->mb[12] = req->qos;
3582 mcp->mb[11] = req->vp_idx;
3583 mcp->mb[13] = req->rid;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003584 if (IS_QLA83XX(ha))
3585 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003586
Saurav Kashyapfa492632012-11-21 02:40:29 -05003587 reg = (struct device_reg_25xxmq __iomem *)((ha->mqiobase) +
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003588 QLA_QUE_PAGE * req->id);
3589
3590 mcp->mb[4] = req->id;
3591 /* que in ptr index */
3592 mcp->mb[8] = 0;
3593 /* que out ptr index */
3594 mcp->mb[9] = 0;
3595 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3596 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3597 mcp->in_mb = MBX_0;
3598 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003599 mcp->tov = MBX_TOV_SECONDS * 2;
3600
3601 if (IS_QLA81XX(ha) || IS_QLA83XX(ha))
3602 mcp->in_mb |= MBX_1;
3603 if (IS_QLA83XX(ha)) {
3604 mcp->out_mb |= MBX_15;
3605 /* debug q create issue in SR-IOV */
3606 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
3607 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003608
3609 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003610 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003611 WRT_REG_DWORD(&reg->req_q_in, 0);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003612 if (!IS_QLA83XX(ha))
3613 WRT_REG_DWORD(&reg->req_q_out, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003614 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003615 req->req_q_in = &reg->req_q_in;
3616 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003617 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3618
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003619 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003620 if (rval != QLA_SUCCESS) {
3621 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
3622 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3623 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003624 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
3625 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003626 }
3627
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003628 return rval;
3629}
3630
3631int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003632qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003633{
3634 int rval;
3635 unsigned long flags;
3636 mbx_cmd_t mc;
3637 mbx_cmd_t *mcp = &mc;
3638 struct device_reg_25xxmq __iomem *reg;
3639 struct qla_hw_data *ha = vha->hw;
3640
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003641 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
3642 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003643
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003644 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003645 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003646 mcp->mb[2] = MSW(LSD(rsp->dma));
3647 mcp->mb[3] = LSW(LSD(rsp->dma));
3648 mcp->mb[6] = MSW(MSD(rsp->dma));
3649 mcp->mb[7] = LSW(MSD(rsp->dma));
3650 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003651 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003652 mcp->mb[13] = rsp->rid;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003653 if (IS_QLA83XX(ha))
3654 mcp->mb[15] = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003655
Saurav Kashyapfa492632012-11-21 02:40:29 -05003656 reg = (struct device_reg_25xxmq __iomem *)((ha->mqiobase) +
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003657 QLA_QUE_PAGE * rsp->id);
3658
3659 mcp->mb[4] = rsp->id;
3660 /* que in ptr index */
3661 mcp->mb[8] = 0;
3662 /* que out ptr index */
3663 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003664 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003665 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3666 mcp->in_mb = MBX_0;
3667 mcp->flags = MBX_DMA_OUT;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003668 mcp->tov = MBX_TOV_SECONDS * 2;
3669
3670 if (IS_QLA81XX(ha)) {
3671 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
3672 mcp->in_mb |= MBX_1;
3673 } else if (IS_QLA83XX(ha)) {
3674 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
3675 mcp->in_mb |= MBX_1;
3676 /* debug q create issue in SR-IOV */
3677 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
3678 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003679
3680 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003681 if (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003682 WRT_REG_DWORD(&reg->rsp_q_out, 0);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003683 if (!IS_QLA83XX(ha))
3684 WRT_REG_DWORD(&reg->rsp_q_in, 0);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003685 }
3686
3687 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3688
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003689 rval = qla2x00_mailbox_command(vha, mcp);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003690 if (rval != QLA_SUCCESS) {
3691 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
3692 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3693 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003694 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
3695 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003696 }
3697
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003698 return rval;
3699}
3700
Andrew Vasquez8a659572009-02-08 20:50:12 -08003701int
3702qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3703{
3704 int rval;
3705 mbx_cmd_t mc;
3706 mbx_cmd_t *mcp = &mc;
3707
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003708 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
3709 "Entered %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003710
3711 mcp->mb[0] = MBC_IDC_ACK;
3712 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3713 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3714 mcp->in_mb = MBX_0;
3715 mcp->tov = MBX_TOV_SECONDS;
3716 mcp->flags = 0;
3717 rval = qla2x00_mailbox_command(vha, mcp);
3718
3719 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003720 ql_dbg(ql_dbg_mbx, vha, 0x10da,
3721 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003722 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003723 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
3724 "Done %s.\n", __func__);
Andrew Vasquez8a659572009-02-08 20:50:12 -08003725 }
3726
3727 return rval;
3728}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003729
3730int
3731qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3732{
3733 int rval;
3734 mbx_cmd_t mc;
3735 mbx_cmd_t *mcp = &mc;
3736
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003737 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
3738 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003739
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003740 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003741 return QLA_FUNCTION_FAILED;
3742
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003743 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3744 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3745 mcp->out_mb = MBX_1|MBX_0;
3746 mcp->in_mb = MBX_1|MBX_0;
3747 mcp->tov = MBX_TOV_SECONDS;
3748 mcp->flags = 0;
3749 rval = qla2x00_mailbox_command(vha, mcp);
3750
3751 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003752 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
3753 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3754 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003755 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003756 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
3757 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003758 *sector_size = mcp->mb[1];
3759 }
3760
3761 return rval;
3762}
3763
3764int
3765qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3766{
3767 int rval;
3768 mbx_cmd_t mc;
3769 mbx_cmd_t *mcp = &mc;
3770
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003771 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003772 return QLA_FUNCTION_FAILED;
3773
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003774 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
3775 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003776
3777 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3778 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3779 FAC_OPT_CMD_WRITE_PROTECT;
3780 mcp->out_mb = MBX_1|MBX_0;
3781 mcp->in_mb = MBX_1|MBX_0;
3782 mcp->tov = MBX_TOV_SECONDS;
3783 mcp->flags = 0;
3784 rval = qla2x00_mailbox_command(vha, mcp);
3785
3786 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003787 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
3788 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3789 rval, mcp->mb[0], mcp->mb[1]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003790 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003791 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
3792 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003793 }
3794
3795 return rval;
3796}
3797
3798int
3799qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3800{
3801 int rval;
3802 mbx_cmd_t mc;
3803 mbx_cmd_t *mcp = &mc;
3804
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003805 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw))
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003806 return QLA_FUNCTION_FAILED;
3807
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003808 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
3809 "Entered %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003810
3811 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3812 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3813 mcp->mb[2] = LSW(start);
3814 mcp->mb[3] = MSW(start);
3815 mcp->mb[4] = LSW(finish);
3816 mcp->mb[5] = MSW(finish);
3817 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3818 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3819 mcp->tov = MBX_TOV_SECONDS;
3820 mcp->flags = 0;
3821 rval = qla2x00_mailbox_command(vha, mcp);
3822
3823 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003824 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
3825 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
3826 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003827 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003828 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
3829 "Done %s.\n", __func__);
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003830 }
3831
3832 return rval;
3833}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003834
3835int
3836qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3837{
3838 int rval = 0;
3839 mbx_cmd_t mc;
3840 mbx_cmd_t *mcp = &mc;
3841
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003842 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
3843 "Entered %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003844
3845 mcp->mb[0] = MBC_RESTART_MPI_FW;
3846 mcp->out_mb = MBX_0;
3847 mcp->in_mb = MBX_0|MBX_1;
3848 mcp->tov = MBX_TOV_SECONDS;
3849 mcp->flags = 0;
3850 rval = qla2x00_mailbox_command(vha, mcp);
3851
3852 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003853 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
3854 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3855 rval, mcp->mb[0], mcp->mb[1]);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003856 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003857 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
3858 "Done %s.\n", __func__);
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003859 }
3860
3861 return rval;
3862}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003863
3864int
Joe Carnuccio6766df92011-05-10 11:30:15 -07003865qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
3866 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003867{
3868 int rval;
3869 mbx_cmd_t mc;
3870 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003871 struct qla_hw_data *ha = vha->hw;
3872
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003873 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
3874 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003875
Joe Carnuccio6766df92011-05-10 11:30:15 -07003876 if (!IS_FWI2_CAPABLE(ha))
3877 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003878
Joe Carnuccio6766df92011-05-10 11:30:15 -07003879 if (len == 1)
3880 opt |= BIT_0;
3881
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003882 mcp->mb[0] = MBC_READ_SFP;
3883 mcp->mb[1] = dev;
3884 mcp->mb[2] = MSW(sfp_dma);
3885 mcp->mb[3] = LSW(sfp_dma);
3886 mcp->mb[6] = MSW(MSD(sfp_dma));
3887 mcp->mb[7] = LSW(MSD(sfp_dma));
3888 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003889 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003890 mcp->mb[10] = opt;
3891 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 -07003892 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003893 mcp->tov = MBX_TOV_SECONDS;
3894 mcp->flags = 0;
3895 rval = qla2x00_mailbox_command(vha, mcp);
3896
3897 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07003898 *sfp = mcp->mb[1];
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003899
3900 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003901 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
3902 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003903 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003904 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
3905 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003906 }
3907
3908 return rval;
3909}
3910
3911int
Joe Carnuccio6766df92011-05-10 11:30:15 -07003912qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
3913 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003914{
3915 int rval;
3916 mbx_cmd_t mc;
3917 mbx_cmd_t *mcp = &mc;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003918 struct qla_hw_data *ha = vha->hw;
3919
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003920 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
3921 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003922
Joe Carnuccio6766df92011-05-10 11:30:15 -07003923 if (!IS_FWI2_CAPABLE(ha))
3924 return QLA_FUNCTION_FAILED;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003925
Joe Carnuccio6766df92011-05-10 11:30:15 -07003926 if (len == 1)
3927 opt |= BIT_0;
3928
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003929 if (opt & BIT_0)
Joe Carnuccio6766df92011-05-10 11:30:15 -07003930 len = *sfp;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003931
3932 mcp->mb[0] = MBC_WRITE_SFP;
3933 mcp->mb[1] = dev;
3934 mcp->mb[2] = MSW(sfp_dma);
3935 mcp->mb[3] = LSW(sfp_dma);
3936 mcp->mb[6] = MSW(MSD(sfp_dma));
3937 mcp->mb[7] = LSW(MSD(sfp_dma));
3938 mcp->mb[8] = len;
Joe Carnuccio6766df92011-05-10 11:30:15 -07003939 mcp->mb[9] = off;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003940 mcp->mb[10] = opt;
3941 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 -07003942 mcp->in_mb = MBX_1|MBX_0;
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003943 mcp->tov = MBX_TOV_SECONDS;
3944 mcp->flags = 0;
3945 rval = qla2x00_mailbox_command(vha, mcp);
3946
3947 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003948 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
3949 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003950 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003951 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
3952 "Done %s.\n", __func__);
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003953 }
3954
3955 return rval;
3956}
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003957
3958int
3959qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
3960 uint16_t size_in_bytes, uint16_t *actual_size)
3961{
3962 int rval;
3963 mbx_cmd_t mc;
3964 mbx_cmd_t *mcp = &mc;
3965
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003966 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
3967 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003968
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08003969 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003970 return QLA_FUNCTION_FAILED;
3971
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003972 mcp->mb[0] = MBC_GET_XGMAC_STATS;
3973 mcp->mb[2] = MSW(stats_dma);
3974 mcp->mb[3] = LSW(stats_dma);
3975 mcp->mb[6] = MSW(MSD(stats_dma));
3976 mcp->mb[7] = LSW(MSD(stats_dma));
3977 mcp->mb[8] = size_in_bytes >> 2;
3978 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
3979 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3980 mcp->tov = MBX_TOV_SECONDS;
3981 mcp->flags = 0;
3982 rval = qla2x00_mailbox_command(vha, mcp);
3983
3984 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003985 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
3986 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
3987 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003988 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04003989 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
3990 "Done %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07003991
Andrew Vasquezce0423f2009-06-03 09:55:13 -07003992
3993 *actual_size = mcp->mb[2] << 2;
3994 }
3995
3996 return rval;
3997}
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07003998
3999int
4000qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4001 uint16_t size)
4002{
4003 int rval;
4004 mbx_cmd_t mc;
4005 mbx_cmd_t *mcp = &mc;
4006
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004007 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4008 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004009
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004010 if (!IS_CNA_CAPABLE(vha->hw))
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004011 return QLA_FUNCTION_FAILED;
4012
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004013 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4014 mcp->mb[1] = 0;
4015 mcp->mb[2] = MSW(tlv_dma);
4016 mcp->mb[3] = LSW(tlv_dma);
4017 mcp->mb[6] = MSW(MSD(tlv_dma));
4018 mcp->mb[7] = LSW(MSD(tlv_dma));
4019 mcp->mb[8] = size;
4020 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4021 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4022 mcp->tov = MBX_TOV_SECONDS;
4023 mcp->flags = 0;
4024 rval = qla2x00_mailbox_command(vha, mcp);
4025
4026 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004027 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4028 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4029 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004030 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004031 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4032 "Done %s.\n", __func__);
Andrew Vasquez11bbc1d2009-06-03 09:55:14 -07004033 }
4034
4035 return rval;
4036}
Andrew Vasquez18e75552009-06-03 09:55:30 -07004037
4038int
4039qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4040{
4041 int rval;
4042 mbx_cmd_t mc;
4043 mbx_cmd_t *mcp = &mc;
4044
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004045 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4046 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004047
Andrew Vasquez18e75552009-06-03 09:55:30 -07004048 if (!IS_FWI2_CAPABLE(vha->hw))
4049 return QLA_FUNCTION_FAILED;
4050
Andrew Vasquez18e75552009-06-03 09:55:30 -07004051 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4052 mcp->mb[1] = LSW(risc_addr);
4053 mcp->mb[8] = MSW(risc_addr);
4054 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4055 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4056 mcp->tov = 30;
4057 mcp->flags = 0;
4058 rval = qla2x00_mailbox_command(vha, mcp);
4059 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004060 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4061 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004062 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004063 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4064 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004065 *data = mcp->mb[3] << 16 | mcp->mb[2];
4066 }
4067
4068 return rval;
4069}
4070
4071int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004072qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4073 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004074{
4075 int rval;
4076 mbx_cmd_t mc;
4077 mbx_cmd_t *mcp = &mc;
4078 uint32_t iter_cnt = 0x1;
4079
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004080 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4081 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004082
4083 memset(mcp->mb, 0 , sizeof(mcp->mb));
4084 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4085 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4086
4087 /* transfer count */
4088 mcp->mb[10] = LSW(mreq->transfer_size);
4089 mcp->mb[11] = MSW(mreq->transfer_size);
4090
4091 /* send data address */
4092 mcp->mb[14] = LSW(mreq->send_dma);
4093 mcp->mb[15] = MSW(mreq->send_dma);
4094 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4095 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4096
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004097 /* receive data address */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004098 mcp->mb[16] = LSW(mreq->rcv_dma);
4099 mcp->mb[17] = MSW(mreq->rcv_dma);
4100 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4101 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4102
4103 /* Iteration count */
4104 mcp->mb[18] = LSW(iter_cnt);
4105 mcp->mb[19] = MSW(iter_cnt);
4106
4107 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4108 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 -08004109 if (IS_CNA_CAPABLE(vha->hw))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004110 mcp->out_mb |= MBX_2;
4111 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4112
4113 mcp->buf_size = mreq->transfer_size;
4114 mcp->tov = MBX_TOV_SECONDS;
4115 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4116
4117 rval = qla2x00_mailbox_command(vha, mcp);
4118
4119 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004120 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4121 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4122 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4123 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004124 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004125 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4126 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004127 }
4128
4129 /* Copy mailbox information */
4130 memcpy( mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004131 return rval;
4132}
4133
4134int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004135qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4136 uint16_t *mresp)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004137{
4138 int rval;
4139 mbx_cmd_t mc;
4140 mbx_cmd_t *mcp = &mc;
4141 struct qla_hw_data *ha = vha->hw;
4142
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004143 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4144 "Entered %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004145
4146 memset(mcp->mb, 0 , sizeof(mcp->mb));
4147 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
4148 mcp->mb[1] = mreq->options | BIT_6; /* BIT_6 specifies 64bit address */
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004149 if (IS_CNA_CAPABLE(ha)) {
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004150 mcp->mb[1] |= BIT_15;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004151 mcp->mb[2] = vha->fcoe_fcf_idx;
4152 }
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004153 mcp->mb[16] = LSW(mreq->rcv_dma);
4154 mcp->mb[17] = MSW(mreq->rcv_dma);
4155 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4156 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4157
4158 mcp->mb[10] = LSW(mreq->transfer_size);
4159
4160 mcp->mb[14] = LSW(mreq->send_dma);
4161 mcp->mb[15] = MSW(mreq->send_dma);
4162 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4163 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4164
4165 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4166 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004167 if (IS_CNA_CAPABLE(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004168 mcp->out_mb |= MBX_2;
4169
4170 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004171 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4172 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004173 mcp->in_mb |= MBX_1;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004174 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004175 mcp->in_mb |= MBX_3;
4176
4177 mcp->tov = MBX_TOV_SECONDS;
4178 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4179 mcp->buf_size = mreq->transfer_size;
4180
4181 rval = qla2x00_mailbox_command(vha, mcp);
4182
4183 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004184 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4185 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4186 rval, mcp->mb[0], mcp->mb[1]);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004187 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4189 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004190 }
4191
4192 /* Copy mailbox information */
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004193 memcpy(mresp, mcp->mb, 64);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004194 return rval;
4195}
Giridhar Malavali6dbdda42010-09-03 15:20:49 -07004196
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004197int
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004198qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004199{
4200 int rval;
4201 mbx_cmd_t mc;
4202 mbx_cmd_t *mcp = &mc;
4203
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004204 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004205 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004206
4207 mcp->mb[0] = MBC_ISP84XX_RESET;
4208 mcp->mb[1] = enable_diagnostic;
4209 mcp->out_mb = MBX_1|MBX_0;
4210 mcp->in_mb = MBX_1|MBX_0;
4211 mcp->tov = MBX_TOV_SECONDS;
4212 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004213 rval = qla2x00_mailbox_command(vha, mcp);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004214
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004215 if (rval != QLA_SUCCESS)
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004216 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004217 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004218 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4219 "Done %s.\n", __func__);
Giridhar Malavali9a069e12010-01-12 13:02:47 -08004220
4221 return rval;
4222}
4223
4224int
Andrew Vasquez18e75552009-06-03 09:55:30 -07004225qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4226{
4227 int rval;
4228 mbx_cmd_t mc;
4229 mbx_cmd_t *mcp = &mc;
4230
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004231 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4232 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004233
Andrew Vasquez18e75552009-06-03 09:55:30 -07004234 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez6c452a42010-03-19 17:04:02 -07004235 return QLA_FUNCTION_FAILED;
Andrew Vasquez18e75552009-06-03 09:55:30 -07004236
Andrew Vasquez18e75552009-06-03 09:55:30 -07004237 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4238 mcp->mb[1] = LSW(risc_addr);
4239 mcp->mb[2] = LSW(data);
4240 mcp->mb[3] = MSW(data);
4241 mcp->mb[8] = MSW(risc_addr);
4242 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4243 mcp->in_mb = MBX_0;
4244 mcp->tov = 30;
4245 mcp->flags = 0;
4246 rval = qla2x00_mailbox_command(vha, mcp);
4247 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004248 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4249 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004250 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004251 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4252 "Done %s.\n", __func__);
Andrew Vasquez18e75552009-06-03 09:55:30 -07004253 }
4254
4255 return rval;
4256}
Michael Hernandez3064ff32009-12-15 21:29:44 -08004257
4258int
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004259qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4260{
4261 int rval;
4262 uint32_t stat, timer;
4263 uint16_t mb0 = 0;
4264 struct qla_hw_data *ha = vha->hw;
4265 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4266
4267 rval = QLA_SUCCESS;
4268
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004269 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4270 "Entered %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004271
4272 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4273
4274 /* Write the MBC data to the registers */
4275 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4276 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4277 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4278 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4279 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4280
4281 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4282
4283 /* Poll for MBC interrupt */
4284 for (timer = 6000000; timer; timer--) {
4285 /* Check for pending interrupts. */
4286 stat = RD_REG_DWORD(&reg->host_status);
4287 if (stat & HSRX_RISC_INT) {
4288 stat &= 0xff;
4289
4290 if (stat == 0x1 || stat == 0x2 ||
4291 stat == 0x10 || stat == 0x11) {
4292 set_bit(MBX_INTERRUPT,
4293 &ha->mbx_cmd_flags);
4294 mb0 = RD_REG_WORD(&reg->mailbox0);
4295 WRT_REG_DWORD(&reg->hccr,
4296 HCCRX_CLR_RISC_INT);
4297 RD_REG_DWORD(&reg->hccr);
4298 break;
4299 }
4300 }
4301 udelay(5);
4302 }
4303
4304 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4305 rval = mb0 & MBS_MASK;
4306 else
4307 rval = QLA_FUNCTION_FAILED;
4308
4309 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004310 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4311 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004312 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004313 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4314 "Done %s.\n", __func__);
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004315 }
4316
4317 return rval;
4318}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004319
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07004320int
Michael Hernandez3064ff32009-12-15 21:29:44 -08004321qla2x00_get_data_rate(scsi_qla_host_t *vha)
4322{
4323 int rval;
4324 mbx_cmd_t mc;
4325 mbx_cmd_t *mcp = &mc;
4326 struct qla_hw_data *ha = vha->hw;
4327
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004328 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
4329 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004330
Michael Hernandez3064ff32009-12-15 21:29:44 -08004331 if (!IS_FWI2_CAPABLE(ha))
4332 return QLA_FUNCTION_FAILED;
4333
Michael Hernandez3064ff32009-12-15 21:29:44 -08004334 mcp->mb[0] = MBC_DATA_RATE;
4335 mcp->mb[1] = 0;
4336 mcp->out_mb = MBX_1|MBX_0;
4337 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004338 if (IS_QLA83XX(ha))
4339 mcp->in_mb |= MBX_3;
Michael Hernandez3064ff32009-12-15 21:29:44 -08004340 mcp->tov = MBX_TOV_SECONDS;
4341 mcp->flags = 0;
4342 rval = qla2x00_mailbox_command(vha, mcp);
4343 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004344 ql_dbg(ql_dbg_mbx, vha, 0x1107,
4345 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Michael Hernandez3064ff32009-12-15 21:29:44 -08004346 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004347 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
4348 "Done %s.\n", __func__);
Michael Hernandez3064ff32009-12-15 21:29:44 -08004349 if (mcp->mb[1] != 0x7)
4350 ha->link_data_rate = mcp->mb[1];
4351 }
4352
4353 return rval;
4354}
Sarang Radke09ff7012010-03-19 17:03:59 -07004355
4356int
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004357qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4358{
4359 int rval;
4360 mbx_cmd_t mc;
4361 mbx_cmd_t *mcp = &mc;
4362 struct qla_hw_data *ha = vha->hw;
4363
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004364 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
4365 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004366
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004367 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004368 return QLA_FUNCTION_FAILED;
4369 mcp->mb[0] = MBC_GET_PORT_CONFIG;
4370 mcp->out_mb = MBX_0;
4371 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4372 mcp->tov = MBX_TOV_SECONDS;
4373 mcp->flags = 0;
4374
4375 rval = qla2x00_mailbox_command(vha, mcp);
4376
4377 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004378 ql_dbg(ql_dbg_mbx, vha, 0x110a,
4379 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004380 } else {
4381 /* Copy all bits to preserve original value */
4382 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
4383
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004384 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
4385 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004386 }
4387 return rval;
4388}
4389
4390int
4391qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
4392{
4393 int rval;
4394 mbx_cmd_t mc;
4395 mbx_cmd_t *mcp = &mc;
4396
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004397 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
4398 "Entered %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004399
4400 mcp->mb[0] = MBC_SET_PORT_CONFIG;
4401 /* Copy all bits to preserve original setting */
4402 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
4403 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4404 mcp->in_mb = MBX_0;
4405 mcp->tov = MBX_TOV_SECONDS;
4406 mcp->flags = 0;
4407 rval = qla2x00_mailbox_command(vha, mcp);
4408
4409 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004410 ql_dbg(ql_dbg_mbx, vha, 0x110d,
4411 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004412 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004413 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
4414 "Done %s.\n", __func__);
Sarang Radke23f2ebd2010-05-28 15:08:21 -07004415
4416 return rval;
4417}
4418
4419
4420int
Sarang Radke09ff7012010-03-19 17:03:59 -07004421qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
4422 uint16_t *mb)
4423{
4424 int rval;
4425 mbx_cmd_t mc;
4426 mbx_cmd_t *mcp = &mc;
4427 struct qla_hw_data *ha = vha->hw;
4428
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004429 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
4430 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004431
Sarang Radke09ff7012010-03-19 17:03:59 -07004432 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
4433 return QLA_FUNCTION_FAILED;
4434
Sarang Radke09ff7012010-03-19 17:03:59 -07004435 mcp->mb[0] = MBC_PORT_PARAMS;
4436 mcp->mb[1] = loop_id;
4437 if (ha->flags.fcp_prio_enabled)
4438 mcp->mb[2] = BIT_1;
4439 else
4440 mcp->mb[2] = BIT_2;
4441 mcp->mb[4] = priority & 0xf;
4442 mcp->mb[9] = vha->vp_idx;
4443 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4444 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4445 mcp->tov = 30;
4446 mcp->flags = 0;
4447 rval = qla2x00_mailbox_command(vha, mcp);
4448 if (mb != NULL) {
4449 mb[0] = mcp->mb[0];
4450 mb[1] = mcp->mb[1];
4451 mb[3] = mcp->mb[3];
4452 mb[4] = mcp->mb[4];
4453 }
4454
4455 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004456 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
Sarang Radke09ff7012010-03-19 17:03:59 -07004457 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004458 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
4459 "Done %s.\n", __func__);
Sarang Radke09ff7012010-03-19 17:03:59 -07004460 }
4461
4462 return rval;
4463}
Giridhar Malavalia9083012010-04-12 17:59:55 -07004464
4465int
Andrew Vasquez794a5692010-12-21 16:00:21 -08004466qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp, uint16_t *frac)
4467{
4468 int rval;
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004469 uint8_t byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004470 struct qla_hw_data *ha = vha->hw;
4471
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004472 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ca,
4473 "Entered %s.\n", __func__);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004474
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004475 /* Integer part */
Joe Carnucciof9322ee2012-08-22 14:21:05 -04004476 rval = qla2x00_read_sfp(vha, 0, &byte, 0x98, 0x01, 1,
4477 BIT_13|BIT_12|BIT_0);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004478 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004479 ql_dbg(ql_dbg_mbx, vha, 0x10c9, "Failed=%x.\n", rval);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004480 ha->flags.thermal_supported = 0;
4481 goto fail;
4482 }
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004483 *temp = byte;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004484
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004485 /* Fraction part */
Joe Carnucciof9322ee2012-08-22 14:21:05 -04004486 rval = qla2x00_read_sfp(vha, 0, &byte, 0x98, 0x10, 1,
4487 BIT_13|BIT_12|BIT_0);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004488 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004489 ql_dbg(ql_dbg_mbx, vha, 0x1019, "Failed=%x.\n", rval);
Andrew Vasquez794a5692010-12-21 16:00:21 -08004490 ha->flags.thermal_supported = 0;
4491 goto fail;
4492 }
Joe Carnuccio6ad11ea2011-05-10 11:30:16 -07004493 *frac = (byte >> 6) * 25;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004494
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004495 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1018,
4496 "Done %s.\n", __func__);
Joe Carnuccio37f489b2013-02-08 01:57:45 -05004497 return rval;
Andrew Vasquez794a5692010-12-21 16:00:21 -08004498fail:
Joe Carnuccio37f489b2013-02-08 01:57:45 -05004499 ql_log(ql_log_warn, vha, 0x1150,
4500 "Thermal not supported by this card "
4501 "(ignoring further requests).\n");
Andrew Vasquez794a5692010-12-21 16:00:21 -08004502 return rval;
4503}
4504
4505int
Giridhar Malavalia9083012010-04-12 17:59:55 -07004506qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
4507{
4508 int rval;
4509 struct qla_hw_data *ha = vha->hw;
4510 mbx_cmd_t mc;
4511 mbx_cmd_t *mcp = &mc;
4512
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004513 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
4514 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004515
Giridhar Malavalia9083012010-04-12 17:59:55 -07004516 if (!IS_FWI2_CAPABLE(ha))
4517 return QLA_FUNCTION_FAILED;
4518
Giridhar Malavalia9083012010-04-12 17:59:55 -07004519 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004520 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004521 mcp->mb[1] = 1;
4522
4523 mcp->out_mb = MBX_1|MBX_0;
4524 mcp->in_mb = MBX_0;
4525 mcp->tov = 30;
4526 mcp->flags = 0;
4527
4528 rval = qla2x00_mailbox_command(vha, mcp);
4529 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004530 ql_dbg(ql_dbg_mbx, vha, 0x1016,
4531 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004532 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004533 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
4534 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004535 }
4536
4537 return rval;
4538}
4539
4540int
4541qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
4542{
4543 int rval;
4544 struct qla_hw_data *ha = vha->hw;
4545 mbx_cmd_t mc;
4546 mbx_cmd_t *mcp = &mc;
4547
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004548 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
4549 "Entered %s.\n", __func__);
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004550
Giridhar Malavalia9083012010-04-12 17:59:55 -07004551 if (!IS_QLA82XX(ha))
4552 return QLA_FUNCTION_FAILED;
4553
Giridhar Malavalia9083012010-04-12 17:59:55 -07004554 memset(mcp, 0, sizeof(mbx_cmd_t));
Giridhar Malavali37113332010-07-23 15:28:34 +05004555 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004556 mcp->mb[1] = 0;
4557
4558 mcp->out_mb = MBX_1|MBX_0;
4559 mcp->in_mb = MBX_0;
4560 mcp->tov = 30;
4561 mcp->flags = 0;
4562
4563 rval = qla2x00_mailbox_command(vha, mcp);
4564 if (rval != QLA_SUCCESS) {
Saurav Kashyap7c3df132011-07-14 12:00:13 -07004565 ql_dbg(ql_dbg_mbx, vha, 0x100c,
4566 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004567 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004568 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
4569 "Done %s.\n", __func__);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004570 }
4571
4572 return rval;
4573}
Giridhar Malavali08de2842011-08-16 11:31:44 -07004574
4575int
4576qla82xx_md_get_template_size(scsi_qla_host_t *vha)
4577{
4578 struct qla_hw_data *ha = vha->hw;
4579 mbx_cmd_t mc;
4580 mbx_cmd_t *mcp = &mc;
4581 int rval = QLA_FUNCTION_FAILED;
4582
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004583 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
4584 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004585
4586 memset(mcp->mb, 0 , sizeof(mcp->mb));
4587 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4588 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4589 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
4590 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
4591
4592 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4593 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
4594 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4595
4596 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4597 mcp->tov = MBX_TOV_SECONDS;
4598 rval = qla2x00_mailbox_command(vha, mcp);
4599
4600 /* Always copy back return mailbox values. */
4601 if (rval != QLA_SUCCESS) {
4602 ql_dbg(ql_dbg_mbx, vha, 0x1120,
4603 "mailbox command FAILED=0x%x, subcode=%x.\n",
4604 (mcp->mb[1] << 16) | mcp->mb[0],
4605 (mcp->mb[3] << 16) | mcp->mb[2]);
4606 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004607 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
4608 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004609 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
4610 if (!ha->md_template_size) {
4611 ql_dbg(ql_dbg_mbx, vha, 0x1122,
4612 "Null template size obtained.\n");
4613 rval = QLA_FUNCTION_FAILED;
4614 }
4615 }
4616 return rval;
4617}
4618
4619int
4620qla82xx_md_get_template(scsi_qla_host_t *vha)
4621{
4622 struct qla_hw_data *ha = vha->hw;
4623 mbx_cmd_t mc;
4624 mbx_cmd_t *mcp = &mc;
4625 int rval = QLA_FUNCTION_FAILED;
4626
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004627 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
4628 "Entered %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004629
4630 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
4631 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
4632 if (!ha->md_tmplt_hdr) {
4633 ql_log(ql_log_warn, vha, 0x1124,
4634 "Unable to allocate memory for Minidump template.\n");
4635 return rval;
4636 }
4637
4638 memset(mcp->mb, 0 , sizeof(mcp->mb));
4639 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4640 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
4641 mcp->mb[2] = LSW(RQST_TMPLT);
4642 mcp->mb[3] = MSW(RQST_TMPLT);
4643 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
4644 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
4645 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
4646 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
4647 mcp->mb[8] = LSW(ha->md_template_size);
4648 mcp->mb[9] = MSW(ha->md_template_size);
4649
4650 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4651 mcp->tov = MBX_TOV_SECONDS;
4652 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
4653 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4654 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
4655 rval = qla2x00_mailbox_command(vha, mcp);
4656
4657 if (rval != QLA_SUCCESS) {
4658 ql_dbg(ql_dbg_mbx, vha, 0x1125,
4659 "mailbox command FAILED=0x%x, subcode=%x.\n",
4660 ((mcp->mb[1] << 16) | mcp->mb[0]),
4661 ((mcp->mb[3] << 16) | mcp->mb[2]));
4662 } else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004663 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
4664 "Done %s.\n", __func__);
Giridhar Malavali08de2842011-08-16 11:31:44 -07004665 return rval;
4666}
Saurav Kashyap999916d2011-08-16 11:31:45 -07004667
4668int
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004669qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
4670{
4671 int rval;
4672 struct qla_hw_data *ha = vha->hw;
4673 mbx_cmd_t mc;
4674 mbx_cmd_t *mcp = &mc;
4675
4676 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
4677 return QLA_FUNCTION_FAILED;
4678
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004679 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
4680 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004681
4682 memset(mcp, 0, sizeof(mbx_cmd_t));
4683 mcp->mb[0] = MBC_SET_LED_CONFIG;
4684 mcp->mb[1] = led_cfg[0];
4685 mcp->mb[2] = led_cfg[1];
4686 if (IS_QLA8031(ha)) {
4687 mcp->mb[3] = led_cfg[2];
4688 mcp->mb[4] = led_cfg[3];
4689 mcp->mb[5] = led_cfg[4];
4690 mcp->mb[6] = led_cfg[5];
4691 }
4692
4693 mcp->out_mb = MBX_2|MBX_1|MBX_0;
4694 if (IS_QLA8031(ha))
4695 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
4696 mcp->in_mb = MBX_0;
4697 mcp->tov = 30;
4698 mcp->flags = 0;
4699
4700 rval = qla2x00_mailbox_command(vha, mcp);
4701 if (rval != QLA_SUCCESS) {
4702 ql_dbg(ql_dbg_mbx, vha, 0x1134,
4703 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4704 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004705 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
4706 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004707 }
4708
4709 return rval;
4710}
4711
4712int
4713qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
4714{
4715 int rval;
4716 struct qla_hw_data *ha = vha->hw;
4717 mbx_cmd_t mc;
4718 mbx_cmd_t *mcp = &mc;
4719
4720 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
4721 return QLA_FUNCTION_FAILED;
4722
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004723 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
4724 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004725
4726 memset(mcp, 0, sizeof(mbx_cmd_t));
4727 mcp->mb[0] = MBC_GET_LED_CONFIG;
4728
4729 mcp->out_mb = MBX_0;
4730 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4731 if (IS_QLA8031(ha))
4732 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
4733 mcp->tov = 30;
4734 mcp->flags = 0;
4735
4736 rval = qla2x00_mailbox_command(vha, mcp);
4737 if (rval != QLA_SUCCESS) {
4738 ql_dbg(ql_dbg_mbx, vha, 0x1137,
4739 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4740 } else {
4741 led_cfg[0] = mcp->mb[1];
4742 led_cfg[1] = mcp->mb[2];
4743 if (IS_QLA8031(ha)) {
4744 led_cfg[2] = mcp->mb[3];
4745 led_cfg[3] = mcp->mb[4];
4746 led_cfg[4] = mcp->mb[5];
4747 led_cfg[5] = mcp->mb[6];
4748 }
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004749 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
4750 "Done %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004751 }
4752
4753 return rval;
4754}
4755
4756int
Saurav Kashyap999916d2011-08-16 11:31:45 -07004757qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
4758{
4759 int rval;
4760 struct qla_hw_data *ha = vha->hw;
4761 mbx_cmd_t mc;
4762 mbx_cmd_t *mcp = &mc;
4763
4764 if (!IS_QLA82XX(ha))
4765 return QLA_FUNCTION_FAILED;
4766
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004767 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
Saurav Kashyap999916d2011-08-16 11:31:45 -07004768 "Entered %s.\n", __func__);
4769
4770 memset(mcp, 0, sizeof(mbx_cmd_t));
4771 mcp->mb[0] = MBC_SET_LED_CONFIG;
4772 if (enable)
4773 mcp->mb[7] = 0xE;
4774 else
4775 mcp->mb[7] = 0xD;
4776
4777 mcp->out_mb = MBX_7|MBX_0;
4778 mcp->in_mb = MBX_0;
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004779 mcp->tov = MBX_TOV_SECONDS;
Saurav Kashyap999916d2011-08-16 11:31:45 -07004780 mcp->flags = 0;
4781
4782 rval = qla2x00_mailbox_command(vha, mcp);
4783 if (rval != QLA_SUCCESS) {
4784 ql_dbg(ql_dbg_mbx, vha, 0x1128,
4785 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4786 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004787 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
Saurav Kashyap999916d2011-08-16 11:31:45 -07004788 "Done %s.\n", __func__);
4789 }
4790
4791 return rval;
4792}
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004793
4794int
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004795qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004796{
4797 int rval;
4798 struct qla_hw_data *ha = vha->hw;
4799 mbx_cmd_t mc;
4800 mbx_cmd_t *mcp = &mc;
4801
4802 if (!IS_QLA83XX(ha))
4803 return QLA_FUNCTION_FAILED;
4804
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004805 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
4806 "Entered %s.\n", __func__);
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004807
4808 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
4809 mcp->mb[1] = LSW(reg);
4810 mcp->mb[2] = MSW(reg);
4811 mcp->mb[3] = LSW(data);
4812 mcp->mb[4] = MSW(data);
4813 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4814
4815 mcp->in_mb = MBX_1|MBX_0;
4816 mcp->tov = MBX_TOV_SECONDS;
4817 mcp->flags = 0;
4818 rval = qla2x00_mailbox_command(vha, mcp);
4819
4820 if (rval != QLA_SUCCESS) {
4821 ql_dbg(ql_dbg_mbx, vha, 0x1131,
4822 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4823 } else {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004824 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004825 "Done %s.\n", __func__);
4826 }
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004827
Giridhar Malavali6246b8a2012-02-09 11:15:34 -08004828 return rval;
4829}
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004830
4831int
4832qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
4833{
4834 int rval;
4835 struct qla_hw_data *ha = vha->hw;
4836 mbx_cmd_t mc;
4837 mbx_cmd_t *mcp = &mc;
4838
4839 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004840 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004841 "Implicit LOGO Unsupported.\n");
4842 return QLA_FUNCTION_FAILED;
4843 }
4844
4845
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004846 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
4847 "Entering %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004848
4849 /* Perform Implicit LOGO. */
4850 mcp->mb[0] = MBC_PORT_LOGOUT;
4851 mcp->mb[1] = fcport->loop_id;
4852 mcp->mb[10] = BIT_15;
4853 mcp->out_mb = MBX_10|MBX_1|MBX_0;
4854 mcp->in_mb = MBX_0;
4855 mcp->tov = MBX_TOV_SECONDS;
4856 mcp->flags = 0;
4857 rval = qla2x00_mailbox_command(vha, mcp);
4858 if (rval != QLA_SUCCESS)
4859 ql_dbg(ql_dbg_mbx, vha, 0x113d,
4860 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4861 else
Saurav Kashyap5f28d2d2012-05-15 14:34:15 -04004862 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
4863 "Done %s.\n", __func__);
Andrew Vasquezaf11f642012-02-09 11:15:43 -08004864
4865 return rval;
4866}
4867
Santosh Vernekar7d613ac2012-08-22 14:21:03 -04004868int
4869qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
4870{
4871 int rval;
4872 mbx_cmd_t mc;
4873 mbx_cmd_t *mcp = &mc;
4874 struct qla_hw_data *ha = vha->hw;
4875 unsigned long retry_max_time = jiffies + (2 * HZ);
4876
4877 if (!IS_QLA83XX(ha))
4878 return QLA_FUNCTION_FAILED;
4879
4880 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
4881
4882retry_rd_reg:
4883 mcp->mb[0] = MBC_READ_REMOTE_REG;
4884 mcp->mb[1] = LSW(reg);
4885 mcp->mb[2] = MSW(reg);
4886 mcp->out_mb = MBX_2|MBX_1|MBX_0;
4887 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
4888 mcp->tov = MBX_TOV_SECONDS;
4889 mcp->flags = 0;
4890 rval = qla2x00_mailbox_command(vha, mcp);
4891
4892 if (rval != QLA_SUCCESS) {
4893 ql_dbg(ql_dbg_mbx, vha, 0x114c,
4894 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4895 rval, mcp->mb[0], mcp->mb[1]);
4896 } else {
4897 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
4898 if (*data == QLA8XXX_BAD_VALUE) {
4899 /*
4900 * During soft-reset CAMRAM register reads might
4901 * return 0xbad0bad0. So retry for MAX of 2 sec
4902 * while reading camram registers.
4903 */
4904 if (time_after(jiffies, retry_max_time)) {
4905 ql_dbg(ql_dbg_mbx, vha, 0x1141,
4906 "Failure to read CAMRAM register. "
4907 "data=0x%x.\n", *data);
4908 return QLA_FUNCTION_FAILED;
4909 }
4910 msleep(100);
4911 goto retry_rd_reg;
4912 }
4913 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
4914 }
4915
4916 return rval;
4917}
4918
4919int
4920qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
4921{
4922 int rval;
4923 mbx_cmd_t mc;
4924 mbx_cmd_t *mcp = &mc;
4925 struct qla_hw_data *ha = vha->hw;
4926
4927 if (!IS_QLA83XX(ha))
4928 return QLA_FUNCTION_FAILED;
4929
4930 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
4931
4932 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
4933 mcp->out_mb = MBX_0;
4934 mcp->in_mb = MBX_1|MBX_0;
4935 mcp->tov = MBX_TOV_SECONDS;
4936 mcp->flags = 0;
4937 rval = qla2x00_mailbox_command(vha, mcp);
4938
4939 if (rval != QLA_SUCCESS) {
4940 ql_dbg(ql_dbg_mbx, vha, 0x1144,
4941 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4942 rval, mcp->mb[0], mcp->mb[1]);
4943 ha->isp_ops->fw_dump(vha, 0);
4944 } else {
4945 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
4946 }
4947
4948 return rval;
4949}
4950
4951int
4952qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
4953 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
4954{
4955 int rval;
4956 mbx_cmd_t mc;
4957 mbx_cmd_t *mcp = &mc;
4958 uint8_t subcode = (uint8_t)options;
4959 struct qla_hw_data *ha = vha->hw;
4960
4961 if (!IS_QLA8031(ha))
4962 return QLA_FUNCTION_FAILED;
4963
4964 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
4965
4966 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
4967 mcp->mb[1] = options;
4968 mcp->out_mb = MBX_1|MBX_0;
4969 if (subcode & BIT_2) {
4970 mcp->mb[2] = LSW(start_addr);
4971 mcp->mb[3] = MSW(start_addr);
4972 mcp->mb[4] = LSW(end_addr);
4973 mcp->mb[5] = MSW(end_addr);
4974 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
4975 }
4976 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4977 if (!(subcode & (BIT_2 | BIT_5)))
4978 mcp->in_mb |= MBX_4|MBX_3;
4979 mcp->tov = MBX_TOV_SECONDS;
4980 mcp->flags = 0;
4981 rval = qla2x00_mailbox_command(vha, mcp);
4982
4983 if (rval != QLA_SUCCESS) {
4984 ql_dbg(ql_dbg_mbx, vha, 0x1147,
4985 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
4986 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
4987 mcp->mb[4]);
4988 ha->isp_ops->fw_dump(vha, 0);
4989 } else {
4990 if (subcode & BIT_5)
4991 *sector_size = mcp->mb[1];
4992 else if (subcode & (BIT_6 | BIT_7)) {
4993 ql_dbg(ql_dbg_mbx, vha, 0x1148,
4994 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
4995 } else if (subcode & (BIT_3 | BIT_4)) {
4996 ql_dbg(ql_dbg_mbx, vha, 0x1149,
4997 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
4998 }
4999 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5000 }
5001
5002 return rval;
5003}
Saurav Kashyap81178772012-08-22 14:21:04 -04005004
5005int
5006qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5007 uint32_t size)
5008{
5009 int rval;
5010 mbx_cmd_t mc;
5011 mbx_cmd_t *mcp = &mc;
5012
5013 if (!IS_MCTP_CAPABLE(vha->hw))
5014 return QLA_FUNCTION_FAILED;
5015
5016 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5017 "Entered %s.\n", __func__);
5018
5019 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5020 mcp->mb[1] = LSW(addr);
5021 mcp->mb[2] = MSW(req_dma);
5022 mcp->mb[3] = LSW(req_dma);
5023 mcp->mb[4] = MSW(size);
5024 mcp->mb[5] = LSW(size);
5025 mcp->mb[6] = MSW(MSD(req_dma));
5026 mcp->mb[7] = LSW(MSD(req_dma));
5027 mcp->mb[8] = MSW(addr);
5028 /* Setting RAM ID to valid */
5029 mcp->mb[10] |= BIT_7;
5030 /* For MCTP RAM ID is 0x40 */
5031 mcp->mb[10] |= 0x40;
5032
5033 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5034 MBX_0;
5035
5036 mcp->in_mb = MBX_0;
5037 mcp->tov = MBX_TOV_SECONDS;
5038 mcp->flags = 0;
5039 rval = qla2x00_mailbox_command(vha, mcp);
5040
5041 if (rval != QLA_SUCCESS) {
5042 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5043 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5044 } else {
5045 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5046 "Done %s.\n", __func__);
5047 }
5048
5049 return rval;
5050}