blob: 366522e8a7667c4caec7cca9aaae452e9480243d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 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"
8
9#include <linux/delay.h>
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12/*
13 * qla2x00_mailbox_command
14 * Issue mailbox command and waits for completion.
15 *
16 * Input:
17 * ha = adapter block pointer.
18 * mcp = driver internal mbx struct pointer.
19 *
20 * Output:
21 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
22 *
23 * Returns:
24 * 0 : QLA_SUCCESS = cmd performed success
25 * 1 : QLA_FUNCTION_FAILED (error encountered)
26 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
27 *
28 * Context:
29 * Kernel context.
30 */
31static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080032qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
34 int rval;
35 unsigned long flags = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070036 device_reg_t __iomem *reg;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070037 uint8_t abort_active;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070038 uint8_t io_lock_on;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 uint16_t command;
40 uint16_t *iptr;
41 uint16_t __iomem *optr;
42 uint32_t cnt;
43 uint32_t mboxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 unsigned long wait_time;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080045 struct qla_hw_data *ha = vha->hw;
46 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070047
Seokmann Jub9b12f72009-03-24 09:08:18 -070048 if (ha->pdev->error_state > pci_channel_io_frozen)
49 return QLA_FUNCTION_TIMEOUT;
50
Seokmann Ju2c3dfe32007-07-05 13:16:51 -070051 reg = ha->iobase;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080052 io_lock_on = base_vha->flags.init_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 rval = QLA_SUCCESS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080055 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080057 DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070058
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 /*
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070060 * Wait for active mailbox commands to finish by waiting at most tov
61 * seconds. This is to serialize actual issuing of mailbox cmds during
62 * non ISP abort time.
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -080064 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
65 /* Timeout occurred. Return error. */
66 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
67 "Exiting.\n", __func__, base_vha->host_no));
68 return QLA_FUNCTION_TIMEOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 }
70
71 ha->flags.mbox_busy = 1;
72 /* Save mailbox command for debug */
73 ha->mcp = mcp;
74
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070075 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -080076 base_vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 spin_lock_irqsave(&ha->hardware_lock, flags);
79
80 /* Load mailbox registers. */
Andrew Vasqueze4289242007-07-19 15:05:56 -070081 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070082 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
83 else
84 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86 iptr = mcp->mb;
87 command = mcp->mb[0];
88 mboxes = mcp->out_mb;
89
90 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
91 if (IS_QLA2200(ha) && cnt == 8)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -070092 optr =
93 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 if (mboxes & BIT_0)
95 WRT_REG_WORD(optr, *iptr);
96
97 mboxes >>= 1;
98 optr++;
99 iptr++;
100 }
101
102#if defined(QL_DEBUG_LEVEL_1)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700103 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800104 __func__, base_vha->host_no);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
106 printk("\n");
107 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
108 printk("\n");
109 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
110 printk("\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800111 printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no,
112 optr);
113 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#endif
115
116 /* Issue set host interrupt command to send cmd out. */
117 ha->flags.mbox_int = 0;
118 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
119
120 /* Unlock mbx registers and wait for interrupt */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700121 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800122 "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 /* Wait for mbx cmd completion until timeout */
125
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800126 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
128
Andrew Vasqueze4289242007-07-19 15:05:56 -0700129 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700130 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
131 else
132 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 spin_unlock_irqrestore(&ha->hardware_lock, flags);
134
Marcus Barrow0b05a1f2008-01-17 09:02:13 -0800135 wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700140 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800141 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Andrew Vasqueze4289242007-07-19 15:05:56 -0700143 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700144 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
145 else
146 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
150 while (!ha->flags.mbox_int) {
151 if (time_after(jiffies, wait_time))
152 break;
153
154 /* Check for pending interrupts. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800155 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
andrew.vasquez@qlogic.com59989832006-01-13 17:05:10 -0800157 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
158 !ha->flags.mbox_int)
159 msleep(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 } /* while */
161 }
162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* Check whether we timed out */
164 if (ha->flags.mbox_int) {
165 uint16_t *iptr2;
166
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700167 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800168 base_vha->host_no, command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 /* Got interrupt. Clear the flag. */
171 ha->flags.mbox_int = 0;
172 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
173
Andrew Vasquez 354d6b22005-04-23 02:47:27 -0400174 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 /* Load return mailbox registers. */
178 iptr2 = mcp->mb;
179 iptr = (uint16_t *)&ha->mailbox_out[0];
180 mboxes = mcp->in_mb;
181 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
182 if (mboxes & BIT_0)
183 *iptr2 = *iptr;
184
185 mboxes >>= 1;
186 iptr2++;
187 iptr++;
188 }
189 } else {
190
191#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
192 defined(QL_DEBUG_LEVEL_11)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700193 uint16_t mb0;
194 uint32_t ictrl;
195
Andrew Vasqueze4289242007-07-19 15:05:56 -0700196 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700197 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
198 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
199 } else {
Andrew Vasquezcca53352005-08-26 19:08:30 -0700200 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700201 ictrl = RD_REG_WORD(&reg->isp.ictrl);
202 }
203 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800204 __func__, base_vha->host_no, command);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700205 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800206 base_vha->host_no, ictrl, jiffies);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700207 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800208 base_vha->host_no, mb0);
209 qla2x00_dump_regs(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210#endif
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 rval = QLA_FUNCTION_TIMEOUT;
213 }
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 ha->flags.mbox_busy = 0;
216
217 /* Clean up */
218 ha->mcp = NULL;
219
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800220 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700221 DEBUG11(printk("%s(%ld): checking for additional resp "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800222 "interrupt.\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 /* polling mode for non isp_abort commands. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800225 qla2x00_poll(ha->rsp_q_map[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700228 if (rval == QLA_FUNCTION_TIMEOUT &&
229 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
231 /* not in dpc. schedule it for dpc to take over. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700232 DEBUG(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800233 "isp_abort_needed.\n", __func__,
234 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700235 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800236 "isp_abort_needed.\n", __func__,
237 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 qla_printk(KERN_WARNING, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700239 "Mailbox command timeout occurred. Scheduling ISP "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 "abort.\n");
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800241 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
242 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 } else if (!abort_active) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 /* call abort directly since we are in the DPC thread */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700245 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800246 __func__, base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700247 DEBUG2_3_11(printk("%s(%ld): timeout calling "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800248 "abort_isp\n", __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 qla_printk(KERN_WARNING, ha,
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -0700250 "Mailbox command timeout occurred. Issuing ISP "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 "abort.\n");
252
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800253 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
254 clear_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
255 if (qla2x00_abort_isp(base_vha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700256 /* Failed. retry later. */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800257 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800259 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700260 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800261 base_vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700262 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800263 __func__, base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 }
265 }
266
267 /* Allow next mbx cmd to come in. */
Andrew Vasquez8eca3f32009-01-22 09:45:31 -0800268 complete(&ha->mbx_cmd_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
270 if (rval) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700271 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800272 "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -0700273 mcp->mb[0], mcp->mb[1], mcp->mb[2], command));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800275 DEBUG11(printk("%s(%ld): done.\n", __func__,
276 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 }
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 return rval;
280}
281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800283qla2x00_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 -0800284 uint32_t risc_code_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800287 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 mbx_cmd_t mc;
289 mbx_cmd_t *mcp = &mc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800291 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Andrew Vasqueze4289242007-07-19 15:05:56 -0700293 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800294 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
295 mcp->mb[8] = MSW(risc_addr);
296 mcp->out_mb = MBX_8|MBX_0;
297 } else {
298 mcp->mb[0] = MBC_LOAD_RISC_RAM;
299 mcp->out_mb = MBX_0;
300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 mcp->mb[1] = LSW(risc_addr);
302 mcp->mb[2] = MSW(req_dma);
303 mcp->mb[3] = LSW(req_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 mcp->mb[6] = MSW(MSD(req_dma));
305 mcp->mb[7] = LSW(MSD(req_dma));
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -0800306 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700307 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700308 mcp->mb[4] = MSW(risc_code_size);
309 mcp->mb[5] = LSW(risc_code_size);
310 mcp->out_mb |= MBX_5|MBX_4;
311 } else {
312 mcp->mb[4] = LSW(risc_code_size);
313 mcp->out_mb |= MBX_4;
314 }
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700317 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800319 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700322 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800323 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800325 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 }
327
328 return rval;
329}
330
331/*
332 * qla2x00_execute_fw
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700333 * Start adapter firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 *
335 * Input:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700336 * ha = adapter block pointer.
337 * TARGET_QUEUE_LOCK must be released.
338 * ADAPTER_STATE_LOCK must be released.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 *
340 * Returns:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700341 * qla2x00 local function return status code.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 *
343 * Context:
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700344 * Kernel context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 */
346int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800347qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
349 int rval;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800350 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 mbx_cmd_t mc;
352 mbx_cmd_t *mcp = &mc;
353
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800354 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700357 mcp->out_mb = MBX_0;
358 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -0700359 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700360 mcp->mb[1] = MSW(risc_addr);
361 mcp->mb[2] = LSW(risc_addr);
362 mcp->mb[3] = 0;
Andrew Vasquez8b3253d2007-09-20 14:07:48 -0700363 mcp->mb[4] = 0;
364 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700365 mcp->in_mb |= MBX_1;
366 } else {
367 mcp->mb[1] = LSW(risc_addr);
368 mcp->out_mb |= MBX_1;
369 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
370 mcp->mb[2] = 0;
371 mcp->out_mb |= MBX_2;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 }
374
Ravi Anandb93480e2008-04-03 13:13:25 -0700375 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800377 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700379 if (rval != QLA_SUCCESS) {
380 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800381 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700382 } else {
Andrew Vasqueze4289242007-07-19 15:05:56 -0700383 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700384 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800385 __func__, vha->host_no, mcp->mb[1]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700386 } else {
387 DEBUG11(printk("%s(%ld): done.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800388 vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700389 }
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392 return rval;
393}
394
395/*
396 * qla2x00_get_fw_version
397 * Get firmware version.
398 *
399 * Input:
400 * ha: adapter state pointer.
401 * major: pointer for major number.
402 * minor: pointer for minor number.
403 * subminor: pointer for subminor number.
404 *
405 * Returns:
406 * qla2x00 local function return status code.
407 *
408 * Context:
409 * Kernel context.
410 */
411void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800412qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800413 uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700414 uint32_t *mpi_caps, uint8_t *phy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415{
416 int rval;
417 mbx_cmd_t mc;
418 mbx_cmd_t *mcp = &mc;
419
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800420 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
423 mcp->out_mb = MBX_0;
424 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800425 if (IS_QLA81XX(vha->hw))
Andrew Vasquez55a96152009-03-24 09:08:03 -0700426 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 mcp->flags = 0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700428 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800429 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 /* Return mailbox data. */
432 *major = mcp->mb[1];
433 *minor = mcp->mb[2];
434 *subminor = mcp->mb[3];
435 *attributes = mcp->mb[6];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800436 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 *memory = 0x1FFFF; /* Defaults to 128KB. */
438 else
439 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800440 if (IS_QLA81XX(vha->hw)) {
Andrew Vasquez55a96152009-03-24 09:08:03 -0700441 mpi[0] = mcp->mb[10] & 0xff;
442 mpi[1] = mcp->mb[11] >> 8;
443 mpi[2] = mcp->mb[11] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800444 *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13];
Andrew Vasquez55a96152009-03-24 09:08:03 -0700445 phy[0] = mcp->mb[8] & 0xff;
446 phy[1] = mcp->mb[9] >> 8;
447 phy[2] = mcp->mb[9] & 0xff;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 if (rval != QLA_SUCCESS) {
451 /*EMPTY*/
452 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800453 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 } else {
455 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800456 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 }
458}
459
460/*
461 * qla2x00_get_fw_options
462 * Set firmware options.
463 *
464 * Input:
465 * ha = adapter block pointer.
466 * fwopt = pointer for firmware options.
467 *
468 * Returns:
469 * qla2x00 local function return status code.
470 *
471 * Context:
472 * Kernel context.
473 */
474int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800475qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
477 int rval;
478 mbx_cmd_t mc;
479 mbx_cmd_t *mcp = &mc;
480
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800481 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
484 mcp->out_mb = MBX_0;
485 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700486 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800488 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490 if (rval != QLA_SUCCESS) {
491 /*EMPTY*/
492 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800493 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700495 fwopts[0] = mcp->mb[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 fwopts[1] = mcp->mb[1];
497 fwopts[2] = mcp->mb[2];
498 fwopts[3] = mcp->mb[3];
499
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800500 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502
503 return rval;
504}
505
506
507/*
508 * qla2x00_set_fw_options
509 * Set firmware options.
510 *
511 * Input:
512 * ha = adapter block pointer.
513 * fwopt = pointer for firmware options.
514 *
515 * Returns:
516 * qla2x00 local function return status code.
517 *
518 * Context:
519 * Kernel context.
520 */
521int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800522qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523{
524 int rval;
525 mbx_cmd_t mc;
526 mbx_cmd_t *mcp = &mc;
527
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800528 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
531 mcp->mb[1] = fwopts[1];
532 mcp->mb[2] = fwopts[2];
533 mcp->mb[3] = fwopts[3];
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700534 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800536 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700537 mcp->in_mb |= MBX_1;
538 } else {
539 mcp->mb[10] = fwopts[10];
540 mcp->mb[11] = fwopts[11];
541 mcp->mb[12] = 0; /* Undocumented, but used */
542 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
543 }
Ravi Anandb93480e2008-04-03 13:13:25 -0700544 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800546 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700548 fwopts[0] = mcp->mb[0];
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 if (rval != QLA_SUCCESS) {
551 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700552 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800553 vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 } else {
555 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800556 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558
559 return rval;
560}
561
562/*
563 * qla2x00_mbx_reg_test
564 * Mailbox register wrap test.
565 *
566 * Input:
567 * ha = adapter block pointer.
568 * TARGET_QUEUE_LOCK must be released.
569 * ADAPTER_STATE_LOCK must be released.
570 *
571 * Returns:
572 * qla2x00 local function return status code.
573 *
574 * Context:
575 * Kernel context.
576 */
577int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800578qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
580 int rval;
581 mbx_cmd_t mc;
582 mbx_cmd_t *mcp = &mc;
583
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800584 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
587 mcp->mb[1] = 0xAAAA;
588 mcp->mb[2] = 0x5555;
589 mcp->mb[3] = 0xAA55;
590 mcp->mb[4] = 0x55AA;
591 mcp->mb[5] = 0xA5A5;
592 mcp->mb[6] = 0x5A5A;
593 mcp->mb[7] = 0x2525;
594 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
595 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 -0700596 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800598 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
600 if (rval == QLA_SUCCESS) {
601 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
602 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
603 rval = QLA_FUNCTION_FAILED;
604 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
605 mcp->mb[7] != 0x2525)
606 rval = QLA_FUNCTION_FAILED;
607 }
608
609 if (rval != QLA_SUCCESS) {
610 /*EMPTY*/
611 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800612 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 } else {
614 /*EMPTY*/
615 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800616 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 }
618
619 return rval;
620}
621
622/*
623 * qla2x00_verify_checksum
624 * Verify firmware checksum.
625 *
626 * Input:
627 * ha = adapter block pointer.
628 * TARGET_QUEUE_LOCK must be released.
629 * ADAPTER_STATE_LOCK must be released.
630 *
631 * Returns:
632 * qla2x00 local function return status code.
633 *
634 * Context:
635 * Kernel context.
636 */
637int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800638qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
640 int rval;
641 mbx_cmd_t mc;
642 mbx_cmd_t *mcp = &mc;
643
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800644 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
646 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700647 mcp->out_mb = MBX_0;
648 mcp->in_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800649 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700650 mcp->mb[1] = MSW(risc_addr);
651 mcp->mb[2] = LSW(risc_addr);
652 mcp->out_mb |= MBX_2|MBX_1;
653 mcp->in_mb |= MBX_2|MBX_1;
654 } else {
655 mcp->mb[1] = LSW(risc_addr);
656 mcp->out_mb |= MBX_1;
657 mcp->in_mb |= MBX_1;
658 }
659
Ravi Anandb93480e2008-04-03 13:13:25 -0700660 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800662 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700665 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800666 vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ?
Andrew Vasqueze4289242007-07-19 15:05:56 -0700667 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800669 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 }
671
672 return rval;
673}
674
675/*
676 * qla2x00_issue_iocb
677 * Issue IOCB using mailbox command
678 *
679 * Input:
680 * ha = adapter state pointer.
681 * buffer = buffer pointer.
682 * phys_addr = physical address of buffer.
683 * size = size of buffer.
684 * TARGET_QUEUE_LOCK must be released.
685 * ADAPTER_STATE_LOCK must be released.
686 *
687 * Returns:
688 * qla2x00 local function return status code.
689 *
690 * Context:
691 * Kernel context.
692 */
Adrian Bunk3b8117b2008-04-24 15:21:28 -0700693static int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800694qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700695 dma_addr_t phys_addr, size_t size, uint32_t tov)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696{
697 int rval;
698 mbx_cmd_t mc;
699 mbx_cmd_t *mcp = &mc;
700
701 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
702 mcp->mb[1] = 0;
703 mcp->mb[2] = MSW(phys_addr);
704 mcp->mb[3] = LSW(phys_addr);
705 mcp->mb[6] = MSW(MSD(phys_addr));
706 mcp->mb[7] = LSW(MSD(phys_addr));
707 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
708 mcp->in_mb = MBX_2|MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700709 mcp->tov = tov;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800711 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713 if (rval != QLA_SUCCESS) {
714 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700715 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800716 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 } else {
Andrew Vasquez8c958a92005-07-06 10:30:47 -0700718 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
719
720 /* Mask reserved bits. */
721 sts_entry->entry_status &=
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800722 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724
725 return rval;
726}
727
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700728int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800729qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700730 size_t size)
731{
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800732 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700733 MBX_TOV_SECONDS);
734}
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736/*
737 * qla2x00_abort_command
738 * Abort command aborts a specified IOCB.
739 *
740 * Input:
741 * ha = adapter block pointer.
742 * sp = SB structure pointer.
743 *
744 * Returns:
745 * qla2x00 local function return status code.
746 *
747 * Context:
748 * Kernel context.
749 */
750int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700751qla2x00_abort_command(srb_t *sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752{
753 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 int rval;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800755 uint32_t handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 mbx_cmd_t mc;
757 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700758 fc_port_t *fcport = sp->fcport;
759 scsi_qla_host_t *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800760 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700761 struct req_que *req = vha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800763 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700765 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800767 if (req->outstanding_cmds[handle] == sp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 break;
769 }
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -0700770 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
772 if (handle == MAX_OUTSTANDING_COMMANDS) {
773 /* command not found */
774 return QLA_FUNCTION_FAILED;
775 }
776
777 mcp->mb[0] = MBC_ABORT_COMMAND;
778 if (HAS_EXTENDED_IDS(ha))
779 mcp->mb[1] = fcport->loop_id;
780 else
781 mcp->mb[1] = fcport->loop_id << 8;
782 mcp->mb[2] = (uint16_t)handle;
783 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79622005-04-17 15:06:53 -0500784 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
786 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700787 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800789 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 if (rval != QLA_SUCCESS) {
792 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800793 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800796 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
798
799 return rval;
800}
801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700803qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Andrew Vasquez523ec772008-04-03 13:13:24 -0700805 int rval, rval2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 mbx_cmd_t mc;
807 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800808 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800809 struct req_que *req;
810 struct rsp_que *rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800812 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -0700813
Andrew Vasquez523ec772008-04-03 13:13:24 -0700814 l = l;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800815 vha = fcport->vha;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700816 req = vha->hw->req_q_map[tag];
817 rsp = vha->hw->rsp_q_map[tag];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 mcp->mb[0] = MBC_ABORT_TARGET;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700819 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800820 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 mcp->mb[1] = fcport->loop_id;
822 mcp->mb[10] = 0;
823 mcp->out_mb |= MBX_10;
824 } else {
825 mcp->mb[1] = fcport->loop_id << 8;
826 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800827 mcp->mb[2] = vha->hw->loop_reset_delay;
828 mcp->mb[9] = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700831 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800833 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -0700835 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800836 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700837 }
838
839 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800840 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
841 MK_SYNC_ID);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700842 if (rval2 != QLA_SUCCESS) {
843 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800844 "(%x).\n", __func__, vha->host_no, rval2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800846 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700847 }
848
849 return rval;
850}
851
852int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700853qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700854{
855 int rval, rval2;
856 mbx_cmd_t mc;
857 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800858 scsi_qla_host_t *vha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800859 struct req_que *req;
860 struct rsp_que *rsp;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700861
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800862 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700863
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800864 vha = fcport->vha;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700865 req = vha->hw->req_q_map[tag];
866 rsp = vha->hw->rsp_q_map[tag];
Andrew Vasquez523ec772008-04-03 13:13:24 -0700867 mcp->mb[0] = MBC_LUN_RESET;
868 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800869 if (HAS_EXTENDED_IDS(vha->hw))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700870 mcp->mb[1] = fcport->loop_id;
871 else
872 mcp->mb[1] = fcport->loop_id << 8;
873 mcp->mb[2] = l;
874 mcp->mb[3] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800875 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700876
877 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -0700878 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez523ec772008-04-03 13:13:24 -0700879 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800880 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700881 if (rval != QLA_SUCCESS) {
882 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800883 vha->host_no, rval));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700884 }
885
886 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800887 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
888 MK_SYNC_ID_LUN);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700889 if (rval2 != QLA_SUCCESS) {
890 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800891 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez523ec772008-04-03 13:13:24 -0700892 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800893 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 }
895
896 return rval;
897}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 * qla2x00_get_adapter_id
901 * Get adapter ID and topology.
902 *
903 * Input:
904 * ha = adapter block pointer.
905 * id = pointer for loop ID.
906 * al_pa = pointer for AL_PA.
907 * area = pointer for area.
908 * domain = pointer for domain.
909 * top = pointer for topology.
910 * TARGET_QUEUE_LOCK must be released.
911 * ADAPTER_STATE_LOCK must be released.
912 *
913 * Returns:
914 * qla2x00 local function return status code.
915 *
916 * Context:
917 * Kernel context.
918 */
919int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800920qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700921 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
923 int rval;
924 mbx_cmd_t mc;
925 mbx_cmd_t *mcp = &mc;
926
927 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800928 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
930 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800931 mcp->mb[9] = vha->vp_idx;
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800932 mcp->out_mb = MBX_9|MBX_0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700933 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Andrew Vasquezbad70012009-04-06 22:33:38 -0700934 if (IS_QLA81XX(vha->hw))
935 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
Ravi Anandb93480e2008-04-03 13:13:25 -0700936 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800938 rval = qla2x00_mailbox_command(vha, mcp);
Ravi Anand33135aa2005-11-08 14:37:20 -0800939 if (mcp->mb[0] == MBS_COMMAND_ERROR)
940 rval = QLA_COMMAND_ERROR;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700941 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
942 rval = QLA_INVALID_COMMAND;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
944 /* Return data. */
945 *id = mcp->mb[1];
946 *al_pa = LSB(mcp->mb[2]);
947 *area = MSB(mcp->mb[2]);
948 *domain = LSB(mcp->mb[3]);
949 *top = mcp->mb[6];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700950 *sw_cap = mcp->mb[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (rval != QLA_SUCCESS) {
953 /*EMPTY*/
954 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800955 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800958 vha->host_no));
Andrew Vasquezbad70012009-04-06 22:33:38 -0700959
960 if (IS_QLA81XX(vha->hw)) {
961 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
962 vha->fcoe_fcf_idx = mcp->mb[10];
963 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
964 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
965 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
966 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
967 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
968 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
969 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 }
971
972 return rval;
973}
974
975/*
976 * qla2x00_get_retry_cnt
977 * Get current firmware login retry count and delay.
978 *
979 * Input:
980 * ha = adapter block pointer.
981 * retry_cnt = pointer to login retry count.
982 * tov = pointer to login timeout value.
983 *
984 * Returns:
985 * qla2x00 local function return status code.
986 *
987 * Context:
988 * Kernel context.
989 */
990int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -0800991qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 uint16_t *r_a_tov)
993{
994 int rval;
995 uint16_t ratov;
996 mbx_cmd_t mc;
997 mbx_cmd_t *mcp = &mc;
998
999 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001000 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1003 mcp->out_mb = MBX_0;
1004 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001005 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001007 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 if (rval != QLA_SUCCESS) {
1010 /*EMPTY*/
1011 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001012 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 } else {
1014 /* Convert returned data and check our values. */
1015 *r_a_tov = mcp->mb[3] / 2;
1016 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1017 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1018 /* Update to the larger values */
1019 *retry_cnt = (uint8_t)mcp->mb[1];
1020 *tov = ratov;
1021 }
1022
1023 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001024 "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026
1027 return rval;
1028}
1029
1030/*
1031 * qla2x00_init_firmware
1032 * Initialize adapter firmware.
1033 *
1034 * Input:
1035 * ha = adapter block pointer.
1036 * dptr = Initialization control block pointer.
1037 * size = size of initialization control block.
1038 * TARGET_QUEUE_LOCK must be released.
1039 * ADAPTER_STATE_LOCK must be released.
1040 *
1041 * Returns:
1042 * qla2x00 local function return status code.
1043 *
1044 * Context:
1045 * Kernel context.
1046 */
1047int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001048qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049{
1050 int rval;
1051 mbx_cmd_t mc;
1052 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001053 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
1055 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001056 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Andrew Vasqueze6e074f2008-01-31 12:33:53 -08001058 if (ha->flags.npiv_supported)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001059 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1060 else
1061 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1062
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001063 mcp->mb[1] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 mcp->mb[2] = MSW(ha->init_cb_dma);
1065 mcp->mb[3] = LSW(ha->init_cb_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1067 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07001068 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1069 if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) {
1070 mcp->mb[1] = BIT_0;
1071 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1072 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1073 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1074 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1075 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1076 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1077 }
1078 mcp->in_mb = MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 mcp->buf_size = size;
1080 mcp->flags = MBX_DMA_OUT;
Ravi Anandb93480e2008-04-03 13:13:25 -07001081 mcp->tov = MBX_TOV_SECONDS;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001082 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
1084 if (rval != QLA_SUCCESS) {
1085 /*EMPTY*/
1086 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1087 "mb0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001088 vha->host_no, rval, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 } else {
1090 /*EMPTY*/
1091 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001092 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 }
1094
1095 return rval;
1096}
1097
1098/*
1099 * qla2x00_get_port_database
1100 * Issue normal/enhanced get port database mailbox command
1101 * and copy device name as necessary.
1102 *
1103 * Input:
1104 * ha = adapter state pointer.
1105 * dev = structure pointer.
1106 * opt = enhanced cmd option byte.
1107 *
1108 * Returns:
1109 * qla2x00 local function return status code.
1110 *
1111 * Context:
1112 * Kernel context.
1113 */
1114int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001115qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116{
1117 int rval;
1118 mbx_cmd_t mc;
1119 mbx_cmd_t *mcp = &mc;
1120 port_database_t *pd;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001121 struct port_database_24xx *pd24;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 dma_addr_t pd_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001123 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001125 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001127 pd24 = NULL;
1128 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 if (pd == NULL) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001130 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001131 "structure.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 return QLA_MEMORY_ALLOC_FAILED;
1133 }
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001134 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001136 mcp->mb[0] = MBC_GET_PORT_DATABASE;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001137 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 mcp->mb[2] = MSW(pd_dma);
1140 mcp->mb[3] = LSW(pd_dma);
1141 mcp->mb[6] = MSW(MSD(pd_dma));
1142 mcp->mb[7] = LSW(MSD(pd_dma));
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001143 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001144 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001146 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001147 mcp->mb[1] = fcport->loop_id;
1148 mcp->mb[10] = opt;
1149 mcp->out_mb |= MBX_10|MBX_1;
1150 mcp->in_mb |= MBX_1;
1151 } else if (HAS_EXTENDED_IDS(ha)) {
1152 mcp->mb[1] = fcport->loop_id;
1153 mcp->mb[10] = opt;
1154 mcp->out_mb |= MBX_10|MBX_1;
1155 } else {
1156 mcp->mb[1] = fcport->loop_id << 8 | opt;
1157 mcp->out_mb |= MBX_1;
1158 }
Andrew Vasqueze4289242007-07-19 15:05:56 -07001159 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1160 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 mcp->flags = MBX_DMA_IN;
1162 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001163 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 if (rval != QLA_SUCCESS)
1165 goto gpd_error_out;
1166
Andrew Vasqueze4289242007-07-19 15:05:56 -07001167 if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001168 pd24 = (struct port_database_24xx *) pd;
1169
1170 /* Check for logged in state. */
1171 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1172 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1173 DEBUG2(printk("%s(%ld): Unable to verify "
1174 "login-state (%x/%x) for loop_id %x\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001175 __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001176 pd24->current_login_state,
1177 pd24->last_login_state, fcport->loop_id));
1178 rval = QLA_FUNCTION_FAILED;
1179 goto gpd_error_out;
1180 }
1181
1182 /* Names are little-endian. */
1183 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1184 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1185
1186 /* Get port_id of device. */
1187 fcport->d_id.b.domain = pd24->port_id[0];
1188 fcport->d_id.b.area = pd24->port_id[1];
1189 fcport->d_id.b.al_pa = pd24->port_id[2];
1190 fcport->d_id.b.rsvd_1 = 0;
1191
1192 /* If not target must be initiator or unknown type. */
1193 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1194 fcport->port_type = FCT_INITIATOR;
1195 else
1196 fcport->port_type = FCT_TARGET;
1197 } else {
1198 /* Check for logged in state. */
1199 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1200 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1201 rval = QLA_FUNCTION_FAILED;
1202 goto gpd_error_out;
1203 }
1204
1205 /* Names are little-endian. */
1206 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1207 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1208
1209 /* Get port_id of device. */
1210 fcport->d_id.b.domain = pd->port_id[0];
1211 fcport->d_id.b.area = pd->port_id[3];
1212 fcport->d_id.b.al_pa = pd->port_id[2];
1213 fcport->d_id.b.rsvd_1 = 0;
1214
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001215 /* If not target must be initiator or unknown type. */
1216 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1217 fcport->port_type = FCT_INITIATOR;
1218 else
1219 fcport->port_type = FCT_TARGET;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001220
1221 /* Passback COS information. */
1222 fcport->supported_classes = (pd->options & BIT_4) ?
1223 FC_COS_CLASS2: FC_COS_CLASS3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 }
1225
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226gpd_error_out:
1227 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1228
1229 if (rval != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001230 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001231 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001233 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 }
1235
1236 return rval;
1237}
1238
1239/*
1240 * qla2x00_get_firmware_state
1241 * Get adapter firmware state.
1242 *
1243 * Input:
1244 * ha = adapter block pointer.
1245 * dptr = pointer for firmware state.
1246 * TARGET_QUEUE_LOCK must be released.
1247 * ADAPTER_STATE_LOCK must be released.
1248 *
1249 * Returns:
1250 * qla2x00 local function return status code.
1251 *
1252 * Context:
1253 * Kernel context.
1254 */
1255int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001256qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
1258 int rval;
1259 mbx_cmd_t mc;
1260 mbx_cmd_t *mcp = &mc;
1261
1262 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001263 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1266 mcp->out_mb = MBX_0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001267 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001268 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001270 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001272 /* Return firmware states. */
1273 states[0] = mcp->mb[1];
1274 states[1] = mcp->mb[2];
1275 states[2] = mcp->mb[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 if (rval != QLA_SUCCESS) {
1278 /*EMPTY*/
1279 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001280 "failed=%x.\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 } else {
1282 /*EMPTY*/
1283 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001284 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
1286
1287 return rval;
1288}
1289
1290/*
1291 * qla2x00_get_port_name
1292 * Issue get port name mailbox command.
1293 * Returned name is in big endian format.
1294 *
1295 * Input:
1296 * ha = adapter block pointer.
1297 * loop_id = loop ID of device.
1298 * name = pointer for name.
1299 * TARGET_QUEUE_LOCK must be released.
1300 * ADAPTER_STATE_LOCK must be released.
1301 *
1302 * Returns:
1303 * qla2x00 local function return status code.
1304 *
1305 * Context:
1306 * Kernel context.
1307 */
1308int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001309qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 uint8_t opt)
1311{
1312 int rval;
1313 mbx_cmd_t mc;
1314 mbx_cmd_t *mcp = &mc;
1315
1316 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001317 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 mcp->mb[0] = MBC_GET_PORT_NAME;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001320 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001321 mcp->out_mb = MBX_9|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001322 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 mcp->mb[1] = loop_id;
1324 mcp->mb[10] = opt;
1325 mcp->out_mb |= MBX_10;
1326 } else {
1327 mcp->mb[1] = loop_id << 8 | opt;
1328 }
1329
1330 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001331 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001333 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334
1335 if (rval != QLA_SUCCESS) {
1336 /*EMPTY*/
1337 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001338 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 } else {
1340 if (name != NULL) {
1341 /* This function returns name in big endian. */
Richard Lary1196ae02007-03-22 10:53:19 -05001342 name[0] = MSB(mcp->mb[2]);
1343 name[1] = LSB(mcp->mb[2]);
1344 name[2] = MSB(mcp->mb[3]);
1345 name[3] = LSB(mcp->mb[3]);
1346 name[4] = MSB(mcp->mb[6]);
1347 name[5] = LSB(mcp->mb[6]);
1348 name[6] = MSB(mcp->mb[7]);
1349 name[7] = LSB(mcp->mb[7]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 }
1351
1352 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001353 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
1355
1356 return rval;
1357}
1358
1359/*
1360 * qla2x00_lip_reset
1361 * Issue LIP reset mailbox command.
1362 *
1363 * Input:
1364 * ha = adapter block pointer.
1365 * TARGET_QUEUE_LOCK must be released.
1366 * ADAPTER_STATE_LOCK must be released.
1367 *
1368 * Returns:
1369 * qla2x00 local function return status code.
1370 *
1371 * Context:
1372 * Kernel context.
1373 */
1374int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001375qla2x00_lip_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
1377 int rval;
1378 mbx_cmd_t mc;
1379 mbx_cmd_t *mcp = &mc;
1380
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001381 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001383 if (IS_QLA81XX(vha->hw)) {
1384 /* Logout across all FCFs. */
1385 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1386 mcp->mb[1] = BIT_1;
1387 mcp->mb[2] = 0;
1388 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1389 } else if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001390 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001391 mcp->mb[1] = BIT_6;
1392 mcp->mb[2] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001393 mcp->mb[3] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001394 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 } else {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001396 mcp->mb[0] = MBC_LIP_RESET;
1397 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001398 if (HAS_EXTENDED_IDS(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001399 mcp->mb[1] = 0x00ff;
1400 mcp->mb[10] = 0;
1401 mcp->out_mb |= MBX_10;
1402 } else {
1403 mcp->mb[1] = 0xff00;
1404 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001405 mcp->mb[2] = vha->hw->loop_reset_delay;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001406 mcp->mb[3] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001409 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001411 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413 if (rval != QLA_SUCCESS) {
1414 /*EMPTY*/
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001415 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001416 __func__, vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 } else {
1418 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001419 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 }
1421
1422 return rval;
1423}
1424
1425/*
1426 * qla2x00_send_sns
1427 * Send SNS command.
1428 *
1429 * Input:
1430 * ha = adapter block pointer.
1431 * sns = pointer for command.
1432 * cmd_size = command size.
1433 * buf_size = response/command size.
1434 * TARGET_QUEUE_LOCK must be released.
1435 * ADAPTER_STATE_LOCK must be released.
1436 *
1437 * Returns:
1438 * qla2x00 local function return status code.
1439 *
1440 * Context:
1441 * Kernel context.
1442 */
1443int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001444qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 uint16_t cmd_size, size_t buf_size)
1446{
1447 int rval;
1448 mbx_cmd_t mc;
1449 mbx_cmd_t *mcp = &mc;
1450
1451 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001452 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001455 "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout,
1456 mcp->tov));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457
1458 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1459 mcp->mb[1] = cmd_size;
1460 mcp->mb[2] = MSW(sns_phys_address);
1461 mcp->mb[3] = LSW(sns_phys_address);
1462 mcp->mb[6] = MSW(MSD(sns_phys_address));
1463 mcp->mb[7] = LSW(MSD(sns_phys_address));
1464 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1465 mcp->in_mb = MBX_0|MBX_1;
1466 mcp->buf_size = buf_size;
1467 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001468 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
1469 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470
1471 if (rval != QLA_SUCCESS) {
1472 /*EMPTY*/
1473 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001474 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001476 "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 } else {
1478 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001479 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 }
1481
1482 return rval;
1483}
1484
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001485int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001486qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001487 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1488{
1489 int rval;
1490
1491 struct logio_entry_24xx *lg;
1492 dma_addr_t lg_dma;
1493 uint32_t iop[2];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001494 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001495 struct req_que *req;
1496 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001497
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001498 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001499
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001500 if (ql2xmultique_tag)
1501 req = ha->req_q_map[0];
1502 else
1503 req = vha->req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001504 rsp = req->rsp;
1505
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001506 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1507 if (lg == NULL) {
1508 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001509 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001510 return QLA_MEMORY_ALLOC_FAILED;
1511 }
1512 memset(lg, 0, sizeof(struct logio_entry_24xx));
1513
1514 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1515 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001516 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001517 lg->nport_handle = cpu_to_le16(loop_id);
1518 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1519 if (opt & BIT_0)
1520 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
Andrew Vasquez8baa51a2006-06-23 16:10:44 -07001521 if (opt & BIT_1)
1522 lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001523 lg->port_id[0] = al_pa;
1524 lg->port_id[1] = area;
1525 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001526 lg->vp_index = vha->vp_idx;
1527 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001528 if (rval != QLA_SUCCESS) {
1529 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001530 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001531 } else if (lg->entry_status != 0) {
1532 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001533 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001534 lg->entry_status));
1535 rval = QLA_FUNCTION_FAILED;
1536 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1537 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1538 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1539
1540 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1541 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001542 vha->host_no, le16_to_cpu(lg->comp_status), iop[0],
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001543 iop[1]));
1544
1545 switch (iop[0]) {
1546 case LSC_SCODE_PORTID_USED:
1547 mb[0] = MBS_PORT_ID_USED;
1548 mb[1] = LSW(iop[1]);
1549 break;
1550 case LSC_SCODE_NPORT_USED:
1551 mb[0] = MBS_LOOP_ID_USED;
1552 break;
1553 case LSC_SCODE_NOLINK:
1554 case LSC_SCODE_NOIOCB:
1555 case LSC_SCODE_NOXCB:
1556 case LSC_SCODE_CMD_FAILED:
1557 case LSC_SCODE_NOFABRIC:
1558 case LSC_SCODE_FW_NOT_READY:
1559 case LSC_SCODE_NOT_LOGGED_IN:
1560 case LSC_SCODE_NOPCB:
1561 case LSC_SCODE_ELS_REJECT:
1562 case LSC_SCODE_CMD_PARAM_ERR:
1563 case LSC_SCODE_NONPORT:
1564 case LSC_SCODE_LOGGED_IN:
1565 case LSC_SCODE_NOFLOGI_ACC:
1566 default:
1567 mb[0] = MBS_COMMAND_ERROR;
1568 break;
1569 }
1570 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001571 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001572
1573 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1574
1575 mb[0] = MBS_COMMAND_COMPLETE;
1576 mb[1] = 0;
1577 if (iop[0] & BIT_4) {
1578 if (iop[0] & BIT_8)
1579 mb[1] |= BIT_1;
1580 } else
1581 mb[1] = BIT_0;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001582
1583 /* Passback COS information. */
1584 mb[10] = 0;
1585 if (lg->io_parameter[7] || lg->io_parameter[8])
1586 mb[10] |= BIT_0; /* Class 2. */
1587 if (lg->io_parameter[9] || lg->io_parameter[10])
1588 mb[10] |= BIT_1; /* Class 3. */
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001589 }
1590
1591 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1592
1593 return rval;
1594}
1595
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596/*
1597 * qla2x00_login_fabric
1598 * Issue login fabric port mailbox command.
1599 *
1600 * Input:
1601 * ha = adapter block pointer.
1602 * loop_id = device loop ID.
1603 * domain = device domain.
1604 * area = device area.
1605 * al_pa = device AL_PA.
1606 * status = pointer for return status.
1607 * opt = command options.
1608 * TARGET_QUEUE_LOCK must be released.
1609 * ADAPTER_STATE_LOCK must be released.
1610 *
1611 * Returns:
1612 * qla2x00 local function return status code.
1613 *
1614 * Context:
1615 * Kernel context.
1616 */
1617int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001618qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1620{
1621 int rval;
1622 mbx_cmd_t mc;
1623 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001624 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001626 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
1628 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1629 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1630 if (HAS_EXTENDED_IDS(ha)) {
1631 mcp->mb[1] = loop_id;
1632 mcp->mb[10] = opt;
1633 mcp->out_mb |= MBX_10;
1634 } else {
1635 mcp->mb[1] = (loop_id << 8) | opt;
1636 }
1637 mcp->mb[2] = domain;
1638 mcp->mb[3] = area << 8 | al_pa;
1639
1640 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1641 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1642 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001643 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 /* Return mailbox statuses. */
1646 if (mb != NULL) {
1647 mb[0] = mcp->mb[0];
1648 mb[1] = mcp->mb[1];
1649 mb[2] = mcp->mb[2];
1650 mb[6] = mcp->mb[6];
1651 mb[7] = mcp->mb[7];
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001652 /* COS retrieved from Get-Port-Database mailbox command. */
1653 mb[10] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 }
1655
1656 if (rval != QLA_SUCCESS) {
1657 /* RLU tmp code: need to change main mailbox_command function to
1658 * return ok even when the mailbox completion value is not
1659 * SUCCESS. The caller needs to be responsible to interpret
1660 * the return values of this mailbox command if we're not
1661 * to change too much of the existing code.
1662 */
1663 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1664 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1665 mcp->mb[0] == 0x4006)
1666 rval = QLA_SUCCESS;
1667
1668 /*EMPTY*/
1669 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001670 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001671 mcp->mb[0], mcp->mb[1], mcp->mb[2]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 } else {
1673 /*EMPTY*/
1674 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001675 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 }
1677
1678 return rval;
1679}
1680
1681/*
1682 * qla2x00_login_local_device
1683 * Issue login loop port mailbox command.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001684 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 * Input:
1686 * ha = adapter block pointer.
1687 * loop_id = device loop ID.
1688 * opt = command options.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001689 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 * Returns:
1691 * Return status code.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001692 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 * Context:
1694 * Kernel context.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001695 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 */
1697int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001698qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 uint16_t *mb_ret, uint8_t opt)
1700{
1701 int rval;
1702 mbx_cmd_t mc;
1703 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001704 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Andrew Vasqueze4289242007-07-19 15:05:56 -07001706 if (IS_FWI2_CAPABLE(ha))
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001707 return qla24xx_login_fabric(vha, fcport->loop_id,
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001708 fcport->d_id.b.domain, fcport->d_id.b.area,
1709 fcport->d_id.b.al_pa, mb_ret, opt);
1710
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001711 DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712
1713 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1714 if (HAS_EXTENDED_IDS(ha))
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001715 mcp->mb[1] = fcport->loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 else
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08001717 mcp->mb[1] = fcport->loop_id << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 mcp->mb[2] = opt;
1719 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1720 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1721 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1722 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001723 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 /* Return mailbox statuses. */
1726 if (mb_ret != NULL) {
1727 mb_ret[0] = mcp->mb[0];
1728 mb_ret[1] = mcp->mb[1];
1729 mb_ret[6] = mcp->mb[6];
1730 mb_ret[7] = mcp->mb[7];
1731 }
1732
1733 if (rval != QLA_SUCCESS) {
1734 /* AV tmp code: need to change main mailbox_command function to
1735 * return ok even when the mailbox completion value is not
1736 * SUCCESS. The caller needs to be responsible to interpret
1737 * the return values of this mailbox command if we're not
1738 * to change too much of the existing code.
1739 */
1740 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1741 rval = QLA_SUCCESS;
1742
1743 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001744 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001745 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001747 "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001748 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 } else {
1750 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001751 DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 }
1753
1754 return (rval);
1755}
1756
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001757int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001758qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001759 uint8_t area, uint8_t al_pa)
1760{
1761 int rval;
1762 struct logio_entry_24xx *lg;
1763 dma_addr_t lg_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001764 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001765 struct req_que *req;
1766 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001767
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001768 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001769
1770 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1771 if (lg == NULL) {
1772 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001773 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001774 return QLA_MEMORY_ALLOC_FAILED;
1775 }
1776 memset(lg, 0, sizeof(struct logio_entry_24xx));
1777
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001778 if (ql2xmaxqueues > 1)
1779 req = ha->req_q_map[0];
1780 else
1781 req = vha->req;
1782 rsp = req->rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001783 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1784 lg->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001785 lg->handle = MAKE_HANDLE(req->id, lg->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001786 lg->nport_handle = cpu_to_le16(loop_id);
1787 lg->control_flags =
Lalit Chandivadeb1372bc2007-01-29 10:22:22 -08001788 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001789 lg->port_id[0] = al_pa;
1790 lg->port_id[1] = area;
1791 lg->port_id[2] = domain;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001792 lg->vp_index = vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001793
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001794 rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001795 if (rval != QLA_SUCCESS) {
1796 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001797 "(%x).\n", __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001798 } else if (lg->entry_status != 0) {
1799 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001800 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001801 lg->entry_status));
1802 rval = QLA_FUNCTION_FAILED;
1803 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001804 DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB "
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001805 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001806 vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status),
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001807 le32_to_cpu(lg->io_parameter[0]),
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07001808 le32_to_cpu(lg->io_parameter[1])));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001809 } else {
1810 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001811 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001812 }
1813
1814 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1815
1816 return rval;
1817}
1818
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819/*
1820 * qla2x00_fabric_logout
1821 * Issue logout fabric port mailbox command.
1822 *
1823 * Input:
1824 * ha = adapter block pointer.
1825 * loop_id = device loop ID.
1826 * TARGET_QUEUE_LOCK must be released.
1827 * ADAPTER_STATE_LOCK must be released.
1828 *
1829 * Returns:
1830 * qla2x00 local function return status code.
1831 *
1832 * Context:
1833 * Kernel context.
1834 */
1835int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001836qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001837 uint8_t area, uint8_t al_pa)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838{
1839 int rval;
1840 mbx_cmd_t mc;
1841 mbx_cmd_t *mcp = &mc;
1842
1843 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001844 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1847 mcp->out_mb = MBX_1|MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001848 if (HAS_EXTENDED_IDS(vha->hw)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 mcp->mb[1] = loop_id;
1850 mcp->mb[10] = 0;
1851 mcp->out_mb |= MBX_10;
1852 } else {
1853 mcp->mb[1] = loop_id << 8;
1854 }
1855
1856 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001857 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001859 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 if (rval != QLA_SUCCESS) {
1862 /*EMPTY*/
1863 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001864 "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 } else {
1866 /*EMPTY*/
1867 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001868 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 }
1870
1871 return rval;
1872}
1873
1874/*
1875 * qla2x00_full_login_lip
1876 * Issue full login LIP mailbox command.
1877 *
1878 * Input:
1879 * ha = adapter block pointer.
1880 * TARGET_QUEUE_LOCK must be released.
1881 * ADAPTER_STATE_LOCK must be released.
1882 *
1883 * Returns:
1884 * qla2x00 local function return status code.
1885 *
1886 * Context:
1887 * Kernel context.
1888 */
1889int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001890qla2x00_full_login_lip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
1892 int rval;
1893 mbx_cmd_t mc;
1894 mbx_cmd_t *mcp = &mc;
1895
1896 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001897 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001900 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001901 mcp->mb[2] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 mcp->mb[3] = 0;
1903 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1904 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001905 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001907 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 if (rval != QLA_SUCCESS) {
1910 /*EMPTY*/
1911 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001912 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 } else {
1914 /*EMPTY*/
1915 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001916 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 }
1918
1919 return rval;
1920}
1921
1922/*
1923 * qla2x00_get_id_list
1924 *
1925 * Input:
1926 * ha = adapter block pointer.
1927 *
1928 * Returns:
1929 * qla2x00 local function return status code.
1930 *
1931 * Context:
1932 * Kernel context.
1933 */
1934int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001935qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 uint16_t *entries)
1937{
1938 int rval;
1939 mbx_cmd_t mc;
1940 mbx_cmd_t *mcp = &mc;
1941
1942 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001943 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
1945 if (id_list == NULL)
1946 return QLA_FUNCTION_FAILED;
1947
1948 mcp->mb[0] = MBC_GET_ID_LIST;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001949 mcp->out_mb = MBX_0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001950 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001951 mcp->mb[2] = MSW(id_list_dma);
1952 mcp->mb[3] = LSW(id_list_dma);
1953 mcp->mb[6] = MSW(MSD(id_list_dma));
1954 mcp->mb[7] = LSW(MSD(id_list_dma));
andrew.vasquez@qlogic.com247ec452006-02-07 08:45:40 -08001955 mcp->mb[8] = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001956 mcp->mb[9] = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001957 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07001958 } else {
1959 mcp->mb[1] = MSW(id_list_dma);
1960 mcp->mb[2] = LSW(id_list_dma);
1961 mcp->mb[3] = MSW(MSD(id_list_dma));
1962 mcp->mb[6] = LSW(MSD(id_list_dma));
1963 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1964 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07001966 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001968 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
1970 if (rval != QLA_SUCCESS) {
1971 /*EMPTY*/
1972 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001973 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 } else {
1975 *entries = mcp->mb[1];
1976 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001977 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 }
1979
1980 return rval;
1981}
1982
1983/*
1984 * qla2x00_get_resource_cnts
1985 * Get current firmware resource counts.
1986 *
1987 * Input:
1988 * ha = adapter block pointer.
1989 *
1990 * Returns:
1991 * qla2x00 local function return status code.
1992 *
1993 * Context:
1994 * Kernel context.
1995 */
1996int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08001997qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt,
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001998 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt,
1999 uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000{
2001 int rval;
2002 mbx_cmd_t mc;
2003 mbx_cmd_t *mcp = &mc;
2004
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002005 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2008 mcp->out_mb = MBX_0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002009 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002010 mcp->tov = MBX_TOV_SECONDS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002012 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 if (rval != QLA_SUCCESS) {
2015 /*EMPTY*/
2016 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002017 vha->host_no, mcp->mb[0]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 } else {
2019 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002020 "mb7=%x mb10=%x mb11=%x.\n", __func__, vha->host_no,
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002021 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002022 mcp->mb[10], mcp->mb[11]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023
2024 if (cur_xchg_cnt)
2025 *cur_xchg_cnt = mcp->mb[3];
2026 if (orig_xchg_cnt)
2027 *orig_xchg_cnt = mcp->mb[6];
2028 if (cur_iocb_cnt)
2029 *cur_iocb_cnt = mcp->mb[7];
2030 if (orig_iocb_cnt)
2031 *orig_iocb_cnt = mcp->mb[10];
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002032 if (vha->hw->flags.npiv_supported && max_npiv_vports)
Seokmann Ju4d0ea242007-09-20 14:07:43 -07002033 *max_npiv_vports = mcp->mb[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 }
2035
2036 return (rval);
2037}
2038
2039#if defined(QL_DEBUG_LEVEL_3)
2040/*
2041 * qla2x00_get_fcal_position_map
2042 * Get FCAL (LILP) position map using mailbox command
2043 *
2044 * Input:
2045 * ha = adapter state pointer.
2046 * pos_map = buffer pointer (can be NULL).
2047 *
2048 * Returns:
2049 * qla2x00 local function return status code.
2050 *
2051 * Context:
2052 * Kernel context.
2053 */
2054int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002055qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
2057 int rval;
2058 mbx_cmd_t mc;
2059 mbx_cmd_t *mcp = &mc;
2060 char *pmap;
2061 dma_addr_t pmap_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002062 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
Andrew Vasquez4b892582008-09-11 21:22:48 -07002064 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 if (pmap == NULL) {
2066 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002067 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 return QLA_MEMORY_ALLOC_FAILED;
2069 }
2070 memset(pmap, 0, FCAL_MAP_SIZE);
2071
2072 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2073 mcp->mb[2] = MSW(pmap_dma);
2074 mcp->mb[3] = LSW(pmap_dma);
2075 mcp->mb[6] = MSW(MSD(pmap_dma));
2076 mcp->mb[7] = LSW(MSD(pmap_dma));
2077 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2078 mcp->in_mb = MBX_1|MBX_0;
2079 mcp->buf_size = FCAL_MAP_SIZE;
2080 mcp->flags = MBX_DMA_IN;
2081 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002082 rval = qla2x00_mailbox_command(vha, mcp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083
2084 if (rval == QLA_SUCCESS) {
2085 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002086 "size (%x)\n", __func__, vha->host_no, mcp->mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 mcp->mb[1], (unsigned)pmap[0]));
2088 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2089
2090 if (pos_map)
2091 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2092 }
2093 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2094
2095 if (rval != QLA_SUCCESS) {
2096 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002097 vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002099 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 }
2101
2102 return rval;
2103}
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002104#endif
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002105
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002106/*
2107 * qla2x00_get_link_status
2108 *
2109 * Input:
2110 * ha = adapter block pointer.
2111 * loop_id = device loop ID.
2112 * ret_buf = pointer to link status return buffer.
2113 *
2114 * Returns:
2115 * 0 = success.
2116 * BIT_0 = mem alloc error.
2117 * BIT_1 = mailbox error.
2118 */
2119int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002120qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002121 struct link_statistics *stats, dma_addr_t stats_dma)
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002122{
2123 int rval;
2124 mbx_cmd_t mc;
2125 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002126 uint32_t *siter, *diter, dwords;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002127 struct qla_hw_data *ha = vha->hw;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002128
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002129 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002130
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002131 mcp->mb[0] = MBC_GET_LINK_STATUS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002132 mcp->mb[2] = MSW(stats_dma);
2133 mcp->mb[3] = LSW(stats_dma);
2134 mcp->mb[6] = MSW(MSD(stats_dma));
2135 mcp->mb[7] = LSW(MSD(stats_dma));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002136 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2137 mcp->in_mb = MBX_0;
Andrew Vasqueze4289242007-07-19 15:05:56 -07002138 if (IS_FWI2_CAPABLE(ha)) {
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002139 mcp->mb[1] = loop_id;
2140 mcp->mb[4] = 0;
2141 mcp->mb[10] = 0;
2142 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2143 mcp->in_mb |= MBX_1;
2144 } else if (HAS_EXTENDED_IDS(ha)) {
2145 mcp->mb[1] = loop_id;
2146 mcp->mb[10] = 0;
2147 mcp->out_mb |= MBX_10|MBX_1;
2148 } else {
2149 mcp->mb[1] = loop_id << 8;
2150 mcp->out_mb |= MBX_1;
2151 }
Ravi Anandb93480e2008-04-03 13:13:25 -07002152 mcp->tov = MBX_TOV_SECONDS;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002153 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002154 rval = qla2x00_mailbox_command(vha, mcp);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002155
2156 if (rval == QLA_SUCCESS) {
2157 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2158 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002159 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002160 rval = QLA_FUNCTION_FAILED;
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002161 } else {
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002162 /* Copy over data -- firmware data is LE. */
2163 dwords = offsetof(struct link_statistics, unused1) / 4;
2164 siter = diter = &stats->link_fail_cnt;
2165 while (dwords--)
2166 *diter++ = le32_to_cpu(*siter++);
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002167 }
2168 } else {
2169 /* Failed. */
2170 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002171 vha->host_no, rval));
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002172 }
2173
andrew.vasquez@qlogic.com392e2f62006-01-31 16:05:02 -08002174 return rval;
2175}
2176
2177int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002178qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002179 dma_addr_t stats_dma)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002180{
2181 int rval;
2182 mbx_cmd_t mc;
2183 mbx_cmd_t *mcp = &mc;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002184 uint32_t *siter, *diter, dwords;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002185
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002186 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002187
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002188 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002189 mcp->mb[2] = MSW(stats_dma);
2190 mcp->mb[3] = LSW(stats_dma);
2191 mcp->mb[6] = MSW(MSD(stats_dma));
2192 mcp->mb[7] = LSW(MSD(stats_dma));
2193 mcp->mb[8] = sizeof(struct link_statistics) / 4;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002194 mcp->mb[9] = vha->vp_idx;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002195 mcp->mb[10] = 0;
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002196 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 -07002197 mcp->in_mb = MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002198 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002199 mcp->flags = IOCTL_CMD;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002200 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002201
2202 if (rval == QLA_SUCCESS) {
2203 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2204 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002205 __func__, vha->host_no, mcp->mb[0]));
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002206 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002207 } else {
2208 /* Copy over data -- firmware data is LE. */
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002209 dwords = sizeof(struct link_statistics) / 4;
2210 siter = diter = &stats->link_fail_cnt;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002211 while (dwords--)
Andrew Vasquez43ef0582008-01-17 09:02:08 -08002212 *diter++ = le32_to_cpu(*siter++);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002213 }
2214 } else {
2215 /* Failed. */
2216 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002217 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002218 }
2219
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002220 return rval;
2221}
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002222
2223int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002224qla24xx_abort_command(srb_t *sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002225{
2226 int rval;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002227 unsigned long flags = 0;
2228
2229 struct abort_entry_24xx *abt;
2230 dma_addr_t abt_dma;
2231 uint32_t handle;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002232 fc_port_t *fcport = sp->fcport;
2233 struct scsi_qla_host *vha = fcport->vha;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002234 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002235 struct req_que *req = sp->que;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002236
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002237 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002238
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002239 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002240 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002241 if (req->outstanding_cmds[handle] == sp)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002242 break;
2243 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002244 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002245 if (handle == MAX_OUTSTANDING_COMMANDS) {
2246 /* Command not found. */
2247 return QLA_FUNCTION_FAILED;
2248 }
2249
2250 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2251 if (abt == NULL) {
2252 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002253 __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002254 return QLA_MEMORY_ALLOC_FAILED;
2255 }
2256 memset(abt, 0, sizeof(struct abort_entry_24xx));
2257
2258 abt->entry_type = ABORT_IOCB_TYPE;
2259 abt->entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002260 abt->handle = MAKE_HANDLE(req->id, abt->handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002261 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2262 abt->handle_to_abort = handle;
2263 abt->port_id[0] = fcport->d_id.b.al_pa;
2264 abt->port_id[1] = fcport->d_id.b.area;
2265 abt->port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002266 abt->vp_index = fcport->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002267
2268 abt->req_que_no = cpu_to_le16(req->id);
2269
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002270 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002271 if (rval != QLA_SUCCESS) {
2272 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002273 __func__, vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002274 } else if (abt->entry_status != 0) {
2275 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002276 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002277 abt->entry_status));
2278 rval = QLA_FUNCTION_FAILED;
2279 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2280 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002281 "-- completion status (%x).\n", __func__, vha->host_no,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07002282 le16_to_cpu(abt->nport_handle)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002283 rval = QLA_FUNCTION_FAILED;
2284 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002285 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002286 }
2287
2288 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2289
2290 return rval;
2291}
2292
2293struct tsk_mgmt_cmd {
2294 union {
2295 struct tsk_mgmt_entry tsk;
2296 struct sts_entry_24xx sts;
2297 } p;
2298};
2299
Andrew Vasquez523ec772008-04-03 13:13:24 -07002300static int
2301__qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002302 unsigned int l, int tag)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002303{
Andrew Vasquez523ec772008-04-03 13:13:24 -07002304 int rval, rval2;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002305 struct tsk_mgmt_cmd *tsk;
2306 dma_addr_t tsk_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002307 scsi_qla_host_t *vha;
2308 struct qla_hw_data *ha;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002309 struct req_que *req;
2310 struct rsp_que *rsp;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002311
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08002312 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002313
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002314 vha = fcport->vha;
2315 ha = vha->hw;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002316 req = vha->req;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002317 if (ql2xmultique_tag)
2318 rsp = ha->rsp_q_map[tag + 1];
2319 else
2320 rsp = req->rsp;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002321 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002322 if (tsk == NULL) {
2323 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002324 "IOCB.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002325 return QLA_MEMORY_ALLOC_FAILED;
2326 }
2327 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2328
2329 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2330 tsk->p.tsk.entry_count = 1;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002331 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002332 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002333 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002334 tsk->p.tsk.control_flags = cpu_to_le32(type);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002335 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2336 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2337 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002338 tsk->p.tsk.vp_index = fcport->vp_idx;
Andrew Vasquez523ec772008-04-03 13:13:24 -07002339 if (type == TCF_LUN_RESET) {
2340 int_to_scsilun(l, &tsk->p.tsk.lun);
2341 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
2342 sizeof(tsk->p.tsk.lun));
2343 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002344
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002345 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002346 if (rval != QLA_SUCCESS) {
Andrew Vasquez523ec772008-04-03 13:13:24 -07002347 DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002348 "(%x).\n", __func__, vha->host_no, name, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002349 } else if (tsk->p.sts.entry_status != 0) {
2350 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002351 "-- error status (%x).\n", __func__, vha->host_no,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002352 tsk->p.sts.entry_status));
2353 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002354 } else if (tsk->p.sts.comp_status !=
2355 __constant_cpu_to_le16(CS_COMPLETE)) {
2356 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2357 "-- completion status (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002358 vha->host_no, le16_to_cpu(tsk->p.sts.comp_status)));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002359 rval = QLA_FUNCTION_FAILED;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002360 }
2361
2362 /* Issue marker IOCB. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002363 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
Andrew Vasquez523ec772008-04-03 13:13:24 -07002364 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
2365 if (rval2 != QLA_SUCCESS) {
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002366 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002367 "(%x).\n", __func__, vha->host_no, rval2));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002368 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002369 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002370 }
2371
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002372 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002373
2374 return rval;
2375}
2376
Andrew Vasquez523ec772008-04-03 13:13:24 -07002377int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002378qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002379{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002380 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002381}
2382
2383int
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002384qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag)
Andrew Vasquez523ec772008-04-03 13:13:24 -07002385{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002386 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
Andrew Vasquez523ec772008-04-03 13:13:24 -07002387}
2388
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002389int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002390qla2x00_system_error(scsi_qla_host_t *vha)
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002391{
2392 int rval;
2393 mbx_cmd_t mc;
2394 mbx_cmd_t *mcp = &mc;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002395 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002396
Andrew Vasquez68af0812008-05-12 22:21:13 -07002397 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002398 return QLA_FUNCTION_FAILED;
2399
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002400 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002401
2402 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2403 mcp->out_mb = MBX_0;
2404 mcp->in_mb = MBX_0;
2405 mcp->tov = 5;
2406 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002407 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002408
2409 if (rval != QLA_SUCCESS) {
2410 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002411 vha->host_no, rval));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002412 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002413 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002414 }
2415
2416 return rval;
2417}
2418
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002419/**
2420 * qla2x00_set_serdes_params() -
2421 * @ha: HA context
2422 *
2423 * Returns
2424 */
2425int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002426qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002427 uint16_t sw_em_2g, uint16_t sw_em_4g)
2428{
2429 int rval;
2430 mbx_cmd_t mc;
2431 mbx_cmd_t *mcp = &mc;
2432
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002433 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002434
2435 mcp->mb[0] = MBC_SERDES_PARAMS;
2436 mcp->mb[1] = BIT_0;
andrew.vasquez@qlogic.comfdbc6832006-03-09 14:27:29 -08002437 mcp->mb[2] = sw_em_1g | BIT_15;
2438 mcp->mb[3] = sw_em_2g | BIT_15;
2439 mcp->mb[4] = sw_em_4g | BIT_15;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002440 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2441 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002442 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002443 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002444 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002445
2446 if (rval != QLA_SUCCESS) {
2447 /*EMPTY*/
2448 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002449 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002450 } else {
2451 /*EMPTY*/
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002452 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002453 }
2454
2455 return rval;
2456}
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002457
2458int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002459qla2x00_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002460{
2461 int rval;
2462 mbx_cmd_t mc;
2463 mbx_cmd_t *mcp = &mc;
2464
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002465 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002466 return QLA_FUNCTION_FAILED;
2467
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002468 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002469
2470 mcp->mb[0] = MBC_STOP_FIRMWARE;
2471 mcp->out_mb = MBX_0;
2472 mcp->in_mb = MBX_0;
2473 mcp->tov = 5;
2474 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002475 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002476
2477 if (rval != QLA_SUCCESS) {
2478 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002479 vha->host_no, rval));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002480 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002481 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002482 }
2483
2484 return rval;
2485}
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002486
2487int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002488qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002489 uint16_t buffers)
2490{
2491 int rval;
2492 mbx_cmd_t mc;
2493 mbx_cmd_t *mcp = &mc;
2494
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002495 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002496 return QLA_FUNCTION_FAILED;
2497
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002498 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002499
2500 mcp->mb[0] = MBC_TRACE_CONTROL;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002501 mcp->mb[1] = TC_EFT_ENABLE;
2502 mcp->mb[2] = LSW(eft_dma);
2503 mcp->mb[3] = MSW(eft_dma);
2504 mcp->mb[4] = LSW(MSD(eft_dma));
2505 mcp->mb[5] = MSW(MSD(eft_dma));
2506 mcp->mb[6] = buffers;
2507 mcp->mb[7] = TC_AEN_DISABLE;
2508 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 -07002509 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002510 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002511 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002512 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002513 if (rval != QLA_SUCCESS) {
2514 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002515 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002516 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002517 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002518 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002519
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002520 return rval;
2521}
2522
2523int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002524qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002525{
2526 int rval;
2527 mbx_cmd_t mc;
2528 mbx_cmd_t *mcp = &mc;
2529
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002530 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002531 return QLA_FUNCTION_FAILED;
2532
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002533 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002534
2535 mcp->mb[0] = MBC_TRACE_CONTROL;
2536 mcp->mb[1] = TC_EFT_DISABLE;
2537 mcp->out_mb = MBX_1|MBX_0;
2538 mcp->in_mb = MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002539 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08002540 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002541 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002542 if (rval != QLA_SUCCESS) {
2543 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002544 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002545 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002546 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002547 }
2548
2549 return rval;
2550}
2551
Andrew Vasquez88729e52006-06-23 16:10:50 -07002552int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002553qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002554 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
2555{
2556 int rval;
2557 mbx_cmd_t mc;
2558 mbx_cmd_t *mcp = &mc;
2559
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002560 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002561 return QLA_FUNCTION_FAILED;
2562
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002563 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002564
2565 mcp->mb[0] = MBC_TRACE_CONTROL;
2566 mcp->mb[1] = TC_FCE_ENABLE;
2567 mcp->mb[2] = LSW(fce_dma);
2568 mcp->mb[3] = MSW(fce_dma);
2569 mcp->mb[4] = LSW(MSD(fce_dma));
2570 mcp->mb[5] = MSW(MSD(fce_dma));
2571 mcp->mb[6] = buffers;
2572 mcp->mb[7] = TC_AEN_DISABLE;
2573 mcp->mb[8] = 0;
2574 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
2575 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
2576 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2577 MBX_1|MBX_0;
2578 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002579 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002580 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002581 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002582 if (rval != QLA_SUCCESS) {
2583 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002584 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002585 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002586 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002587
2588 if (mb)
2589 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
2590 if (dwords)
Andrew Vasquezfa0926d2008-05-12 22:21:12 -07002591 *dwords = buffers;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002592 }
2593
2594 return rval;
2595}
2596
2597int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002598qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002599{
2600 int rval;
2601 mbx_cmd_t mc;
2602 mbx_cmd_t *mcp = &mc;
2603
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002604 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002605 return QLA_FUNCTION_FAILED;
2606
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002607 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002608
2609 mcp->mb[0] = MBC_TRACE_CONTROL;
2610 mcp->mb[1] = TC_FCE_DISABLE;
2611 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
2612 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2613 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
2614 MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002615 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002616 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002617 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002618 if (rval != QLA_SUCCESS) {
2619 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002620 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002621 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002622 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002623
2624 if (wr)
2625 *wr = (uint64_t) mcp->mb[5] << 48 |
2626 (uint64_t) mcp->mb[4] << 32 |
2627 (uint64_t) mcp->mb[3] << 16 |
2628 (uint64_t) mcp->mb[2];
2629 if (rd)
2630 *rd = (uint64_t) mcp->mb[9] << 48 |
2631 (uint64_t) mcp->mb[8] << 32 |
2632 (uint64_t) mcp->mb[7] << 16 |
2633 (uint64_t) mcp->mb[6];
2634 }
2635
2636 return rval;
2637}
2638
2639int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002640qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr,
Andrew Vasquez88729e52006-06-23 16:10:50 -07002641 uint16_t off, uint16_t count)
2642{
2643 int rval;
2644 mbx_cmd_t mc;
2645 mbx_cmd_t *mcp = &mc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002646
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002647 if (!IS_FWI2_CAPABLE(vha->hw))
Andrew Vasquez88729e52006-06-23 16:10:50 -07002648 return QLA_FUNCTION_FAILED;
2649
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002650 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002651
2652 mcp->mb[0] = MBC_READ_SFP;
2653 mcp->mb[1] = addr;
2654 mcp->mb[2] = MSW(sfp_dma);
2655 mcp->mb[3] = LSW(sfp_dma);
2656 mcp->mb[6] = MSW(MSD(sfp_dma));
2657 mcp->mb[7] = LSW(MSD(sfp_dma));
2658 mcp->mb[8] = count;
2659 mcp->mb[9] = off;
2660 mcp->mb[10] = 0;
2661 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2662 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002663 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez88729e52006-06-23 16:10:50 -07002664 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002665 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez88729e52006-06-23 16:10:50 -07002666
2667 if (rval != QLA_SUCCESS) {
2668 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002669 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002670 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002671 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez88729e52006-06-23 16:10:50 -07002672 }
2673
2674 return rval;
2675}
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002676
2677int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002678qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002679 uint16_t port_speed, uint16_t *mb)
2680{
2681 int rval;
2682 mbx_cmd_t mc;
2683 mbx_cmd_t *mcp = &mc;
2684
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002685 if (!IS_IIDMA_CAPABLE(vha->hw))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002686 return QLA_FUNCTION_FAILED;
2687
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002688 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002689
2690 mcp->mb[0] = MBC_PORT_PARAMS;
2691 mcp->mb[1] = loop_id;
2692 mcp->mb[2] = BIT_0;
2693 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
2694 mcp->mb[4] = mcp->mb[5] = 0;
2695 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2696 mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07002697 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002698 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002699 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002700
2701 /* Return mailbox statuses. */
2702 if (mb != NULL) {
2703 mb[0] = mcp->mb[0];
2704 mb[1] = mcp->mb[1];
2705 mb[3] = mcp->mb[3];
2706 mb[4] = mcp->mb[4];
2707 mb[5] = mcp->mb[5];
2708 }
2709
2710 if (rval != QLA_SUCCESS) {
2711 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002712 vha->host_no, rval));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002713 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002714 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002715 }
2716
2717 return rval;
2718}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002719
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002720void
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002721qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002722 struct vp_rpt_id_entry_24xx *rptid_entry)
2723{
2724 uint8_t vp_idx;
Seokmann Juc6852c42008-04-24 15:21:29 -07002725 uint16_t stat = le16_to_cpu(rptid_entry->vp_idx);
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002726 struct qla_hw_data *ha = vha->hw;
2727 scsi_qla_host_t *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002728 scsi_qla_host_t *tvp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002729
2730 if (rptid_entry->entry_status != 0)
2731 return;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002732
2733 if (rptid_entry->format == 0) {
2734 DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d,"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002735 " number of VPs acquired %d\n", __func__, vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002736 MSB(rptid_entry->vp_count), LSB(rptid_entry->vp_count)));
2737 DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__,
2738 rptid_entry->port_id[2], rptid_entry->port_id[1],
2739 rptid_entry->port_id[0]));
2740 } else if (rptid_entry->format == 1) {
Seokmann Juc6852c42008-04-24 15:21:29 -07002741 vp_idx = LSB(stat);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002742 DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled "
2743 "- status %d - "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002744 "with port id %02x%02x%02x\n", __func__, vha->host_no,
Seokmann Juc6852c42008-04-24 15:21:29 -07002745 vp_idx, MSB(stat),
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002746 rptid_entry->port_id[2], rptid_entry->port_id[1],
2747 rptid_entry->port_id[0]));
2748 if (vp_idx == 0)
2749 return;
2750
Seokmann Juc6852c42008-04-24 15:21:29 -07002751 if (MSB(stat) == 1)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002752 return;
2753
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002754 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002755 if (vp_idx == vp->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002756 break;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002757 if (!vp)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002758 return;
2759
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002760 vp->d_id.b.domain = rptid_entry->port_id[2];
2761 vp->d_id.b.area = rptid_entry->port_id[1];
2762 vp->d_id.b.al_pa = rptid_entry->port_id[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002763
2764 /*
2765 * Cannot configure here as we are still sitting on the
2766 * response queue. Handle it in dpc context.
2767 */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002768 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
2769 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002770
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002771 qla2xxx_wake_dpc(vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002772 }
2773}
2774
2775/*
2776 * qla24xx_modify_vp_config
2777 * Change VP configuration for vha
2778 *
2779 * Input:
2780 * vha = adapter block pointer.
2781 *
2782 * Returns:
2783 * qla2xxx local function return status code.
2784 *
2785 * Context:
2786 * Kernel context.
2787 */
2788int
2789qla24xx_modify_vp_config(scsi_qla_host_t *vha)
2790{
2791 int rval;
2792 struct vp_config_entry_24xx *vpmod;
2793 dma_addr_t vpmod_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002794 struct qla_hw_data *ha = vha->hw;
2795 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002796
2797 /* This can be called by the parent */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002798
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002799 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002800 if (!vpmod) {
2801 DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002802 "IOCB.\n", __func__, vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002803 return QLA_MEMORY_ALLOC_FAILED;
2804 }
2805
2806 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
2807 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
2808 vpmod->entry_count = 1;
2809 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
2810 vpmod->vp_count = 1;
2811 vpmod->vp_index1 = vha->vp_idx;
2812 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
2813 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
2814 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
2815 vpmod->entry_count = 1;
2816
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002817 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002818 if (rval != QLA_SUCCESS) {
2819 DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002820 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002821 } else if (vpmod->comp_status != 0) {
2822 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002823 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002824 vpmod->comp_status));
2825 rval = QLA_FUNCTION_FAILED;
2826 } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2827 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002828 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002829 le16_to_cpu(vpmod->comp_status)));
2830 rval = QLA_FUNCTION_FAILED;
2831 } else {
2832 /* EMPTY */
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002833 DEBUG11(printk("%s(%ld): done.\n", __func__,
2834 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002835 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
2836 }
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002837 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002838
2839 return rval;
2840}
2841
2842/*
2843 * qla24xx_control_vp
2844 * Enable a virtual port for given host
2845 *
2846 * Input:
2847 * ha = adapter block pointer.
2848 * vhba = virtual adapter (unused)
2849 * index = index number for enabled VP
2850 *
2851 * Returns:
2852 * qla2xxx local function return status code.
2853 *
2854 * Context:
2855 * Kernel context.
2856 */
2857int
2858qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
2859{
2860 int rval;
2861 int map, pos;
2862 struct vp_ctrl_entry_24xx *vce;
2863 dma_addr_t vce_dma;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002864 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002865 int vp_index = vha->vp_idx;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002866 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002867
2868 DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002869 vha->host_no, vp_index));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002870
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002871 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002872 return QLA_PARAMETER_ERROR;
2873
2874 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
2875 if (!vce) {
2876 DEBUG2_3(printk("%s(%ld): "
2877 "failed to allocate VP Control IOCB.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002878 base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002879 return QLA_MEMORY_ALLOC_FAILED;
2880 }
2881 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
2882
2883 vce->entry_type = VP_CTRL_IOCB_TYPE;
2884 vce->entry_count = 1;
2885 vce->command = cpu_to_le16(cmd);
2886 vce->vp_count = __constant_cpu_to_le16(1);
2887
2888 /* index map in firmware starts with 1; decrement index
2889 * this is ok as we never use index 0
2890 */
2891 map = (vp_index - 1) / 8;
2892 pos = (vp_index - 1) & 7;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002893 mutex_lock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002894 vce->vp_idx_map[map] |= 1 << pos;
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07002895 mutex_unlock(&ha->vport_lock);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002896
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002897 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002898 if (rval != QLA_SUCCESS) {
2899 DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002900 "(%x).\n", __func__, base_vha->host_no, rval));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002901 printk("%s(%ld): failed to issue VP control IOCB"
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002902 "(%x).\n", __func__, base_vha->host_no, rval);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002903 } else if (vce->entry_status != 0) {
2904 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002905 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002906 vce->entry_status));
2907 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002908 "-- error status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002909 vce->entry_status);
2910 rval = QLA_FUNCTION_FAILED;
2911 } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
2912 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002913 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002914 le16_to_cpu(vce->comp_status)));
2915 printk("%s(%ld): failed to complete IOCB "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002916 "-- completion status (%x).\n", __func__, base_vha->host_no,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002917 le16_to_cpu(vce->comp_status));
2918 rval = QLA_FUNCTION_FAILED;
2919 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002920 DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002921 }
2922
2923 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
2924
2925 return rval;
2926}
2927
2928/*
2929 * qla2x00_send_change_request
2930 * Receive or disable RSCN request from fabric controller
2931 *
2932 * Input:
2933 * ha = adapter block pointer
2934 * format = registration format:
2935 * 0 - Reserved
2936 * 1 - Fabric detected registration
2937 * 2 - N_port detected registration
2938 * 3 - Full registration
2939 * FF - clear registration
2940 * vp_idx = Virtual port index
2941 *
2942 * Returns:
2943 * qla2x00 local function return status code.
2944 *
2945 * Context:
2946 * Kernel Context
2947 */
2948
2949int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002950qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002951 uint16_t vp_idx)
2952{
2953 int rval;
2954 mbx_cmd_t mc;
2955 mbx_cmd_t *mcp = &mc;
2956
2957 /*
2958 * This command is implicitly executed by firmware during login for the
2959 * physical hosts
2960 */
2961 if (vp_idx == 0)
2962 return QLA_FUNCTION_FAILED;
2963
2964 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
2965 mcp->mb[1] = format;
2966 mcp->mb[9] = vp_idx;
2967 mcp->out_mb = MBX_9|MBX_1|MBX_0;
2968 mcp->in_mb = MBX_0|MBX_1;
2969 mcp->tov = MBX_TOV_SECONDS;
2970 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002971 rval = qla2x00_mailbox_command(vha, mcp);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002972
2973 if (rval == QLA_SUCCESS) {
2974 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2975 rval = BIT_1;
2976 }
2977 } else
2978 rval = BIT_1;
2979
2980 return rval;
2981}
Andrew Vasquez338c9162007-09-20 14:07:33 -07002982
2983int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002984qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
Andrew Vasquez338c9162007-09-20 14:07:33 -07002985 uint32_t size)
2986{
2987 int rval;
2988 mbx_cmd_t mc;
2989 mbx_cmd_t *mcp = &mc;
2990
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002991 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07002992
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08002993 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07002994 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
2995 mcp->mb[8] = MSW(addr);
2996 mcp->out_mb = MBX_8|MBX_0;
2997 } else {
2998 mcp->mb[0] = MBC_DUMP_RISC_RAM;
2999 mcp->out_mb = MBX_0;
3000 }
3001 mcp->mb[1] = LSW(addr);
3002 mcp->mb[2] = MSW(req_dma);
3003 mcp->mb[3] = LSW(req_dma);
3004 mcp->mb[6] = MSW(MSD(req_dma));
3005 mcp->mb[7] = LSW(MSD(req_dma));
3006 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003007 if (IS_FWI2_CAPABLE(vha->hw)) {
Andrew Vasquez338c9162007-09-20 14:07:33 -07003008 mcp->mb[4] = MSW(size);
3009 mcp->mb[5] = LSW(size);
3010 mcp->out_mb |= MBX_5|MBX_4;
3011 } else {
3012 mcp->mb[4] = LSW(size);
3013 mcp->out_mb |= MBX_4;
3014 }
3015
3016 mcp->in_mb = MBX_0;
Ravi Anandb93480e2008-04-03 13:13:25 -07003017 mcp->tov = MBX_TOV_SECONDS;
Andrew Vasquez338c9162007-09-20 14:07:33 -07003018 mcp->flags = 0;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003019 rval = qla2x00_mailbox_command(vha, mcp);
Andrew Vasquez338c9162007-09-20 14:07:33 -07003020
3021 if (rval != QLA_SUCCESS) {
3022 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003023 vha->host_no, rval, mcp->mb[0]));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003024 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003025 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Andrew Vasquez338c9162007-09-20 14:07:33 -07003026 }
3027
3028 return rval;
3029}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003030
3031/* 84XX Support **************************************************************/
3032
3033struct cs84xx_mgmt_cmd {
3034 union {
3035 struct verify_chip_entry_84xx req;
3036 struct verify_chip_rsp_84xx rsp;
3037 } p;
3038};
3039
3040int
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003041qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003042{
3043 int rval, retry;
3044 struct cs84xx_mgmt_cmd *mn;
3045 dma_addr_t mn_dma;
3046 uint16_t options;
3047 unsigned long flags;
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003048 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003049
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003050 DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003051
3052 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
3053 if (mn == NULL) {
3054 DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003055 "IOCB.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003056 return QLA_MEMORY_ALLOC_FAILED;
3057 }
3058
3059 /* Force Update? */
3060 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
3061 /* Diagnostic firmware? */
3062 /* options |= MENLO_DIAG_FW; */
3063 /* We update the firmware with only one data sequence. */
3064 options |= VCO_END_OF_DATA;
3065
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003066 do {
Andrew Vasquezc1ec1f12008-04-24 15:21:24 -07003067 retry = 0;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003068 memset(mn, 0, sizeof(*mn));
3069 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
3070 mn->p.req.entry_count = 1;
3071 mn->p.req.options = cpu_to_le16(options);
3072
3073 DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003074 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003075 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3076 sizeof(*mn)));
3077
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003078 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003079 if (rval != QLA_SUCCESS) {
3080 DEBUG2_16(printk("%s(%ld): failed to issue Verify "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003081 "IOCB (%x).\n", __func__, vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003082 goto verify_done;
3083 }
3084
3085 DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003086 vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003087 DEBUG16(qla2x00_dump_buffer((uint8_t *)mn,
3088 sizeof(*mn)));
3089
3090 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
3091 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
3092 le16_to_cpu(mn->p.rsp.failure_code) : 0;
3093 DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003094 vha->host_no, status[0], status[1]));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003095
3096 if (status[0] != CS_COMPLETE) {
3097 rval = QLA_FUNCTION_FAILED;
3098 if (!(options & VCO_DONT_UPDATE_FW)) {
3099 DEBUG2_16(printk("%s(%ld): Firmware update "
3100 "failed. Retrying without update "
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003101 "firmware.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003102 options |= VCO_DONT_UPDATE_FW;
3103 options &= ~VCO_FORCE_UPDATE;
3104 retry = 1;
3105 }
3106 } else {
3107 DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n",
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003108 __func__, vha->host_no,
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003109 le32_to_cpu(mn->p.rsp.fw_ver)));
3110
3111 /* NOTE: we only update OP firmware. */
3112 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
3113 ha->cs84xx->op_fw_version =
3114 le32_to_cpu(mn->p.rsp.fw_ver);
3115 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
3116 flags);
3117 }
3118 } while (retry);
3119
3120verify_done:
3121 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
3122
3123 if (rval != QLA_SUCCESS) {
3124 DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__,
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003125 vha->host_no, rval));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003126 } else {
Anirban Chakraborty7b867cf2008-11-06 10:40:19 -08003127 DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003128 }
3129
3130 return rval;
3131}
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003132
3133int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003134qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003135{
3136 int rval;
3137 unsigned long flags;
3138 mbx_cmd_t mc;
3139 mbx_cmd_t *mcp = &mc;
3140 struct device_reg_25xxmq __iomem *reg;
3141 struct qla_hw_data *ha = vha->hw;
3142
3143 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003144 mcp->mb[1] = req->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003145 mcp->mb[2] = MSW(LSD(req->dma));
3146 mcp->mb[3] = LSW(LSD(req->dma));
3147 mcp->mb[6] = MSW(MSD(req->dma));
3148 mcp->mb[7] = LSW(MSD(req->dma));
3149 mcp->mb[5] = req->length;
3150 if (req->rsp)
3151 mcp->mb[10] = req->rsp->id;
3152 mcp->mb[12] = req->qos;
3153 mcp->mb[11] = req->vp_idx;
3154 mcp->mb[13] = req->rid;
3155
3156 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3157 QLA_QUE_PAGE * req->id);
3158
3159 mcp->mb[4] = req->id;
3160 /* que in ptr index */
3161 mcp->mb[8] = 0;
3162 /* que out ptr index */
3163 mcp->mb[9] = 0;
3164 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
3165 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3166 mcp->in_mb = MBX_0;
3167 mcp->flags = MBX_DMA_OUT;
3168 mcp->tov = 60;
3169
3170 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003171 if (!(req->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003172 WRT_REG_DWORD(&reg->req_q_in, 0);
3173 WRT_REG_DWORD(&reg->req_q_out, 0);
3174 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003175 req->req_q_in = &reg->req_q_in;
3176 req->req_q_out = &reg->req_q_out;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003177 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3178
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003179 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003180 if (rval != QLA_SUCCESS)
3181 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n",
3182 __func__, vha->host_no, rval, mcp->mb[0]));
3183 return rval;
3184}
3185
3186int
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003187qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003188{
3189 int rval;
3190 unsigned long flags;
3191 mbx_cmd_t mc;
3192 mbx_cmd_t *mcp = &mc;
3193 struct device_reg_25xxmq __iomem *reg;
3194 struct qla_hw_data *ha = vha->hw;
3195
3196 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003197 mcp->mb[1] = rsp->options;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003198 mcp->mb[2] = MSW(LSD(rsp->dma));
3199 mcp->mb[3] = LSW(LSD(rsp->dma));
3200 mcp->mb[6] = MSW(MSD(rsp->dma));
3201 mcp->mb[7] = LSW(MSD(rsp->dma));
3202 mcp->mb[5] = rsp->length;
Andrew Vasquez444786d2009-01-05 11:18:10 -08003203 mcp->mb[14] = rsp->msix->entry;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003204 mcp->mb[13] = rsp->rid;
3205
3206 reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) +
3207 QLA_QUE_PAGE * rsp->id);
3208
3209 mcp->mb[4] = rsp->id;
3210 /* que in ptr index */
3211 mcp->mb[8] = 0;
3212 /* que out ptr index */
3213 mcp->mb[9] = 0;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003214 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003215 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3216 mcp->in_mb = MBX_0;
3217 mcp->flags = MBX_DMA_OUT;
3218 mcp->tov = 60;
3219
3220 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003221 if (!(rsp->options & BIT_0)) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003222 WRT_REG_DWORD(&reg->rsp_q_out, 0);
3223 WRT_REG_DWORD(&reg->rsp_q_in, 0);
3224 }
3225
3226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3227
Anirban Chakraborty17d98632008-12-18 10:06:15 -08003228 rval = qla2x00_mailbox_command(vha, mcp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003229 if (rval != QLA_SUCCESS)
3230 DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x "
3231 "mb0=%x.\n", __func__,
3232 vha->host_no, rval, mcp->mb[0]));
3233 return rval;
3234}
3235
Andrew Vasquez8a659572009-02-08 20:50:12 -08003236int
3237qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
3238{
3239 int rval;
3240 mbx_cmd_t mc;
3241 mbx_cmd_t *mcp = &mc;
3242
3243 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3244
3245 mcp->mb[0] = MBC_IDC_ACK;
3246 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3247 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3248 mcp->in_mb = MBX_0;
3249 mcp->tov = MBX_TOV_SECONDS;
3250 mcp->flags = 0;
3251 rval = qla2x00_mailbox_command(vha, mcp);
3252
3253 if (rval != QLA_SUCCESS) {
3254 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3255 vha->host_no, rval, mcp->mb[0]));
3256 } else {
3257 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3258 }
3259
3260 return rval;
3261}
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07003262
3263int
3264qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
3265{
3266 int rval;
3267 mbx_cmd_t mc;
3268 mbx_cmd_t *mcp = &mc;
3269
3270 if (!IS_QLA81XX(vha->hw))
3271 return QLA_FUNCTION_FAILED;
3272
3273 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3274
3275 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3276 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
3277 mcp->out_mb = MBX_1|MBX_0;
3278 mcp->in_mb = MBX_1|MBX_0;
3279 mcp->tov = MBX_TOV_SECONDS;
3280 mcp->flags = 0;
3281 rval = qla2x00_mailbox_command(vha, mcp);
3282
3283 if (rval != QLA_SUCCESS) {
3284 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3285 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3286 } else {
3287 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3288 *sector_size = mcp->mb[1];
3289 }
3290
3291 return rval;
3292}
3293
3294int
3295qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
3296{
3297 int rval;
3298 mbx_cmd_t mc;
3299 mbx_cmd_t *mcp = &mc;
3300
3301 if (!IS_QLA81XX(vha->hw))
3302 return QLA_FUNCTION_FAILED;
3303
3304 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3305
3306 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3307 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
3308 FAC_OPT_CMD_WRITE_PROTECT;
3309 mcp->out_mb = MBX_1|MBX_0;
3310 mcp->in_mb = MBX_1|MBX_0;
3311 mcp->tov = MBX_TOV_SECONDS;
3312 mcp->flags = 0;
3313 rval = qla2x00_mailbox_command(vha, mcp);
3314
3315 if (rval != QLA_SUCCESS) {
3316 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
3317 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3318 } else {
3319 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3320 }
3321
3322 return rval;
3323}
3324
3325int
3326qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
3327{
3328 int rval;
3329 mbx_cmd_t mc;
3330 mbx_cmd_t *mcp = &mc;
3331
3332 if (!IS_QLA81XX(vha->hw))
3333 return QLA_FUNCTION_FAILED;
3334
3335 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3336
3337 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
3338 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
3339 mcp->mb[2] = LSW(start);
3340 mcp->mb[3] = MSW(start);
3341 mcp->mb[4] = LSW(finish);
3342 mcp->mb[5] = MSW(finish);
3343 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3344 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3345 mcp->tov = MBX_TOV_SECONDS;
3346 mcp->flags = 0;
3347 rval = qla2x00_mailbox_command(vha, mcp);
3348
3349 if (rval != QLA_SUCCESS) {
3350 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
3351 "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0],
3352 mcp->mb[1], mcp->mb[2]));
3353 } else {
3354 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3355 }
3356
3357 return rval;
3358}
Lalit Chandivade6e181be2009-03-26 08:49:17 -07003359
3360int
3361qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
3362{
3363 int rval = 0;
3364 mbx_cmd_t mc;
3365 mbx_cmd_t *mcp = &mc;
3366
3367 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3368
3369 mcp->mb[0] = MBC_RESTART_MPI_FW;
3370 mcp->out_mb = MBX_0;
3371 mcp->in_mb = MBX_0|MBX_1;
3372 mcp->tov = MBX_TOV_SECONDS;
3373 mcp->flags = 0;
3374 rval = qla2x00_mailbox_command(vha, mcp);
3375
3376 if (rval != QLA_SUCCESS) {
3377 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n",
3378 __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1]));
3379 } else {
3380 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3381 }
3382
3383 return rval;
3384}
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003385
3386int
3387qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3388 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3389{
3390 int rval;
3391 mbx_cmd_t mc;
3392 mbx_cmd_t *mcp = &mc;
3393
3394 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3395
3396 mcp->mb[0] = MBC_READ_SFP;
3397 mcp->mb[1] = dev;
3398 mcp->mb[2] = MSW(sfp_dma);
3399 mcp->mb[3] = LSW(sfp_dma);
3400 mcp->mb[6] = MSW(MSD(sfp_dma));
3401 mcp->mb[7] = LSW(MSD(sfp_dma));
3402 mcp->mb[8] = len;
3403 mcp->mb[9] = adr;
3404 mcp->mb[10] = opt;
3405 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3406 mcp->in_mb = MBX_0;
3407 mcp->tov = MBX_TOV_SECONDS;
3408 mcp->flags = 0;
3409 rval = qla2x00_mailbox_command(vha, mcp);
3410
3411 if (opt & BIT_0)
3412 if (sfp)
3413 *sfp = mcp->mb[8];
3414
3415 if (rval != QLA_SUCCESS) {
3416 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3417 vha->host_no, rval, mcp->mb[0]));
3418 } else {
Andrew Vasquez76403352009-04-06 22:33:39 -07003419 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07003420 }
3421
3422 return rval;
3423}
3424
3425int
3426qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr,
3427 dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt)
3428{
3429 int rval;
3430 mbx_cmd_t mc;
3431 mbx_cmd_t *mcp = &mc;
3432
3433 DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no));
3434
3435 if (opt & BIT_0)
3436 if (sfp)
3437 len = *sfp;
3438
3439 mcp->mb[0] = MBC_WRITE_SFP;
3440 mcp->mb[1] = dev;
3441 mcp->mb[2] = MSW(sfp_dma);
3442 mcp->mb[3] = LSW(sfp_dma);
3443 mcp->mb[6] = MSW(MSD(sfp_dma));
3444 mcp->mb[7] = LSW(MSD(sfp_dma));
3445 mcp->mb[8] = len;
3446 mcp->mb[9] = adr;
3447 mcp->mb[10] = opt;
3448 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
3449 mcp->in_mb = MBX_0;
3450 mcp->tov = MBX_TOV_SECONDS;
3451 mcp->flags = 0;
3452 rval = qla2x00_mailbox_command(vha, mcp);
3453
3454 if (rval != QLA_SUCCESS) {
3455 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
3456 vha->host_no, rval, mcp->mb[0]));
3457 } else {
3458 DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no));
3459 }
3460
3461 return rval;
3462}