Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
fa90c54f | 2 | * QLogic Fibre Channel HBA Driver |
01e58d8e | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
1da177e4 | 4 | * |
fa90c54f | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
1da177e4 LT |
6 | */ |
7 | #include "qla_def.h" | |
8 | ||
9 | #include <linux/delay.h> | |
10 | ||
1da177e4 LT |
11 | |
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 | */ | |
31 | static int | |
7b867cf7 | 32 | qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp) |
1da177e4 LT |
33 | { |
34 | int rval; | |
35 | unsigned long flags = 0; | |
2c3dfe3f | 36 | device_reg_t __iomem *reg; |
1c7c6357 | 37 | uint8_t abort_active; |
2c3dfe3f | 38 | uint8_t io_lock_on; |
1da177e4 LT |
39 | uint16_t command; |
40 | uint16_t *iptr; | |
41 | uint16_t __iomem *optr; | |
42 | uint32_t cnt; | |
43 | uint32_t mboxes; | |
1da177e4 | 44 | unsigned long wait_time; |
7b867cf7 AC |
45 | struct qla_hw_data *ha = vha->hw; |
46 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); | |
2c3dfe3f | 47 | |
b9b12f73 SJ |
48 | if (ha->pdev->error_state > pci_channel_io_frozen) |
49 | return QLA_FUNCTION_TIMEOUT; | |
50 | ||
2c3dfe3f | 51 | reg = ha->iobase; |
7b867cf7 | 52 | io_lock_on = base_vha->flags.init_done; |
1da177e4 LT |
53 | |
54 | rval = QLA_SUCCESS; | |
7b867cf7 | 55 | abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
1c7c6357 | 56 | |
7b867cf7 | 57 | DEBUG11(printk("%s(%ld): entered.\n", __func__, base_vha->host_no)); |
1da177e4 | 58 | |
1da177e4 | 59 | /* |
1c7c6357 AV |
60 | * 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. | |
1da177e4 | 63 | */ |
8eca3f39 AV |
64 | 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; | |
1da177e4 LT |
69 | } |
70 | ||
71 | ha->flags.mbox_busy = 1; | |
72 | /* Save mailbox command for debug */ | |
73 | ha->mcp = mcp; | |
74 | ||
1c7c6357 | 75 | DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n", |
7b867cf7 | 76 | base_vha->host_no, mcp->mb[0])); |
1da177e4 LT |
77 | |
78 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
79 | ||
80 | /* Load mailbox registers. */ | |
e428924c | 81 | if (IS_FWI2_CAPABLE(ha)) |
1c7c6357 AV |
82 | optr = (uint16_t __iomem *)®->isp24.mailbox0; |
83 | else | |
84 | optr = (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 0); | |
1da177e4 LT |
85 | |
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) | |
1c7c6357 AV |
92 | optr = |
93 | (uint16_t __iomem *)MAILBOX_REG(ha, ®->isp, 8); | |
1da177e4 LT |
94 | 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) | |
1c7c6357 | 103 | printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n", |
7b867cf7 | 104 | __func__, base_vha->host_no); |
1da177e4 LT |
105 | 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"); | |
7b867cf7 AC |
111 | printk("%s(%ld): I/O address = %p.\n", __func__, base_vha->host_no, |
112 | optr); | |
113 | qla2x00_dump_regs(base_vha); | |
1da177e4 LT |
114 | #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 */ | |
1c7c6357 | 121 | DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. " |
7b867cf7 | 122 | "jiffies=%lx.\n", __func__, base_vha->host_no, jiffies)); |
1da177e4 LT |
123 | |
124 | /* Wait for mbx cmd completion until timeout */ | |
125 | ||
124f85e6 | 126 | if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) { |
1da177e4 LT |
127 | set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); |
128 | ||
e428924c | 129 | if (IS_FWI2_CAPABLE(ha)) |
1c7c6357 AV |
130 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT); |
131 | else | |
132 | WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT); | |
1da177e4 LT |
133 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
134 | ||
0b05a1f0 | 135 | wait_for_completion_timeout(&ha->mbx_intr_comp, mcp->tov * HZ); |
1da177e4 | 136 | |
1da177e4 LT |
137 | clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags); |
138 | ||
1da177e4 | 139 | } else { |
1c7c6357 | 140 | DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__, |
7b867cf7 | 141 | base_vha->host_no, command)); |
1da177e4 | 142 | |
e428924c | 143 | if (IS_FWI2_CAPABLE(ha)) |
1c7c6357 AV |
144 | WRT_REG_DWORD(®->isp24.hccr, HCCRX_SET_HOST_INT); |
145 | else | |
146 | WRT_REG_WORD(®->isp.hccr, HCCR_SET_HOST_INT); | |
1da177e4 | 147 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
1da177e4 LT |
148 | |
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. */ | |
73208dfd | 155 | qla2x00_poll(ha->rsp_q_map[0]); |
1da177e4 | 156 | |
59989831 | 157 | if (command != MBC_LOAD_RISC_RAM_EXTENDED && |
158 | !ha->flags.mbox_int) | |
159 | msleep(10); | |
1da177e4 LT |
160 | } /* while */ |
161 | } | |
162 | ||
1da177e4 LT |
163 | /* Check whether we timed out */ |
164 | if (ha->flags.mbox_int) { | |
165 | uint16_t *iptr2; | |
166 | ||
1c7c6357 | 167 | DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__, |
7b867cf7 | 168 | base_vha->host_no, command)); |
1da177e4 LT |
169 | |
170 | /* Got interrupt. Clear the flag. */ | |
171 | ha->flags.mbox_int = 0; | |
172 | clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); | |
173 | ||
354d6b21 | 174 | if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE) |
1da177e4 | 175 | rval = QLA_FUNCTION_FAILED; |
1da177e4 LT |
176 | |
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) | |
1c7c6357 AV |
193 | uint16_t mb0; |
194 | uint32_t ictrl; | |
195 | ||
e428924c | 196 | if (IS_FWI2_CAPABLE(ha)) { |
1c7c6357 AV |
197 | mb0 = RD_REG_WORD(®->isp24.mailbox0); |
198 | ictrl = RD_REG_DWORD(®->isp24.ictrl); | |
199 | } else { | |
cca5335c | 200 | mb0 = RD_MAILBOX_REG(ha, ®->isp, 0); |
1c7c6357 AV |
201 | ictrl = RD_REG_WORD(®->isp.ictrl); |
202 | } | |
203 | printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n", | |
7b867cf7 | 204 | __func__, base_vha->host_no, command); |
1c7c6357 | 205 | printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__, |
7b867cf7 | 206 | base_vha->host_no, ictrl, jiffies); |
1c7c6357 | 207 | printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__, |
7b867cf7 AC |
208 | base_vha->host_no, mb0); |
209 | qla2x00_dump_regs(base_vha); | |
1da177e4 LT |
210 | #endif |
211 | ||
1da177e4 LT |
212 | rval = QLA_FUNCTION_TIMEOUT; |
213 | } | |
214 | ||
1da177e4 LT |
215 | ha->flags.mbox_busy = 0; |
216 | ||
217 | /* Clean up */ | |
218 | ha->mcp = NULL; | |
219 | ||
124f85e6 | 220 | if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) { |
1c7c6357 | 221 | DEBUG11(printk("%s(%ld): checking for additional resp " |
7b867cf7 | 222 | "interrupt.\n", __func__, base_vha->host_no)); |
1da177e4 LT |
223 | |
224 | /* polling mode for non isp_abort commands. */ | |
73208dfd | 225 | qla2x00_poll(ha->rsp_q_map[0]); |
1da177e4 LT |
226 | } |
227 | ||
1c7c6357 AV |
228 | if (rval == QLA_FUNCTION_TIMEOUT && |
229 | mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) { | |
1da177e4 LT |
230 | if (!io_lock_on || (mcp->flags & IOCTL_CMD)) { |
231 | /* not in dpc. schedule it for dpc to take over. */ | |
1c7c6357 | 232 | DEBUG(printk("%s(%ld): timeout schedule " |
7b867cf7 AC |
233 | "isp_abort_needed.\n", __func__, |
234 | base_vha->host_no)); | |
1c7c6357 | 235 | DEBUG2_3_11(printk("%s(%ld): timeout schedule " |
7b867cf7 AC |
236 | "isp_abort_needed.\n", __func__, |
237 | base_vha->host_no)); | |
1da177e4 | 238 | qla_printk(KERN_WARNING, ha, |
cc3ef7bc | 239 | "Mailbox command timeout occurred. Scheduling ISP " |
1da177e4 | 240 | "abort.\n"); |
7b867cf7 AC |
241 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
242 | qla2xxx_wake_dpc(vha); | |
1da177e4 | 243 | } else if (!abort_active) { |
1da177e4 | 244 | /* call abort directly since we are in the DPC thread */ |
1c7c6357 | 245 | DEBUG(printk("%s(%ld): timeout calling abort_isp\n", |
7b867cf7 | 246 | __func__, base_vha->host_no)); |
1c7c6357 | 247 | DEBUG2_3_11(printk("%s(%ld): timeout calling " |
7b867cf7 | 248 | "abort_isp\n", __func__, base_vha->host_no)); |
1da177e4 | 249 | qla_printk(KERN_WARNING, ha, |
cc3ef7bc | 250 | "Mailbox command timeout occurred. Issuing ISP " |
1da177e4 LT |
251 | "abort.\n"); |
252 | ||
7b867cf7 AC |
253 | 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)) { | |
1c7c6357 | 256 | /* Failed. retry later. */ |
7b867cf7 | 257 | set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags); |
1da177e4 | 258 | } |
7b867cf7 | 259 | clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags); |
1c7c6357 | 260 | DEBUG(printk("%s(%ld): finished abort_isp\n", __func__, |
7b867cf7 | 261 | base_vha->host_no)); |
1c7c6357 | 262 | DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n", |
7b867cf7 | 263 | __func__, base_vha->host_no)); |
1da177e4 LT |
264 | } |
265 | } | |
266 | ||
267 | /* Allow next mbx cmd to come in. */ | |
8eca3f39 | 268 | complete(&ha->mbx_cmd_comp); |
1da177e4 LT |
269 | |
270 | if (rval) { | |
1c7c6357 | 271 | DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, " |
7b867cf7 | 272 | "mbx2=%x, cmd=%x ****\n", __func__, base_vha->host_no, |
744f11fd | 273 | mcp->mb[0], mcp->mb[1], mcp->mb[2], command)); |
1da177e4 | 274 | } else { |
7b867cf7 AC |
275 | DEBUG11(printk("%s(%ld): done.\n", __func__, |
276 | base_vha->host_no)); | |
1da177e4 LT |
277 | } |
278 | ||
1da177e4 LT |
279 | return rval; |
280 | } | |
281 | ||
1da177e4 | 282 | int |
7b867cf7 | 283 | qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr, |
590f98e5 | 284 | uint32_t risc_code_size) |
1da177e4 LT |
285 | { |
286 | int rval; | |
7b867cf7 | 287 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
288 | mbx_cmd_t mc; |
289 | mbx_cmd_t *mcp = &mc; | |
1da177e4 | 290 | |
7b867cf7 | 291 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 | 292 | |
e428924c | 293 | if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) { |
590f98e5 | 294 | mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED; |
295 | mcp->mb[8] = MSW(risc_addr); | |
296 | mcp->out_mb = MBX_8|MBX_0; | |
1da177e4 | 297 | } else { |
590f98e5 | 298 | mcp->mb[0] = MBC_LOAD_RISC_RAM; |
299 | mcp->out_mb = MBX_0; | |
1da177e4 | 300 | } |
1da177e4 LT |
301 | mcp->mb[1] = LSW(risc_addr); |
302 | mcp->mb[2] = MSW(req_dma); | |
303 | mcp->mb[3] = LSW(req_dma); | |
1da177e4 LT |
304 | mcp->mb[6] = MSW(MSD(req_dma)); |
305 | mcp->mb[7] = LSW(MSD(req_dma)); | |
590f98e5 | 306 | mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1; |
e428924c | 307 | if (IS_FWI2_CAPABLE(ha)) { |
1c7c6357 AV |
308 | 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 | ||
1da177e4 | 316 | mcp->in_mb = MBX_0; |
b93480e3 | 317 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 318 | mcp->flags = 0; |
7b867cf7 | 319 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 | 320 | |
1da177e4 | 321 | if (rval != QLA_SUCCESS) { |
1c7c6357 | 322 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, |
7b867cf7 | 323 | vha->host_no, rval, mcp->mb[0])); |
1da177e4 | 324 | } else { |
7b867cf7 | 325 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
326 | } |
327 | ||
328 | return rval; | |
329 | } | |
330 | ||
331 | /* | |
332 | * qla2x00_execute_fw | |
1c7c6357 | 333 | * Start adapter firmware. |
1da177e4 LT |
334 | * |
335 | * Input: | |
1c7c6357 AV |
336 | * ha = adapter block pointer. |
337 | * TARGET_QUEUE_LOCK must be released. | |
338 | * ADAPTER_STATE_LOCK must be released. | |
1da177e4 LT |
339 | * |
340 | * Returns: | |
1c7c6357 | 341 | * qla2x00 local function return status code. |
1da177e4 LT |
342 | * |
343 | * Context: | |
1c7c6357 | 344 | * Kernel context. |
1da177e4 LT |
345 | */ |
346 | int | |
7b867cf7 | 347 | qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr) |
1da177e4 LT |
348 | { |
349 | int rval; | |
7b867cf7 | 350 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
351 | mbx_cmd_t mc; |
352 | mbx_cmd_t *mcp = &mc; | |
353 | ||
7b867cf7 | 354 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
355 | |
356 | mcp->mb[0] = MBC_EXECUTE_FIRMWARE; | |
1c7c6357 AV |
357 | mcp->out_mb = MBX_0; |
358 | mcp->in_mb = MBX_0; | |
e428924c | 359 | if (IS_FWI2_CAPABLE(ha)) { |
1c7c6357 AV |
360 | mcp->mb[1] = MSW(risc_addr); |
361 | mcp->mb[2] = LSW(risc_addr); | |
362 | mcp->mb[3] = 0; | |
8b3253d1 AV |
363 | mcp->mb[4] = 0; |
364 | mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1; | |
1c7c6357 AV |
365 | 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 | } | |
1da177e4 LT |
373 | } |
374 | ||
b93480e3 | 375 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 376 | mcp->flags = 0; |
7b867cf7 | 377 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 | 378 | |
1c7c6357 AV |
379 | if (rval != QLA_SUCCESS) { |
380 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, | |
7b867cf7 | 381 | vha->host_no, rval, mcp->mb[0])); |
1c7c6357 | 382 | } else { |
e428924c | 383 | if (IS_FWI2_CAPABLE(ha)) { |
1c7c6357 | 384 | DEBUG11(printk("%s(%ld): done exchanges=%x.\n", |
7b867cf7 | 385 | __func__, vha->host_no, mcp->mb[1])); |
1c7c6357 AV |
386 | } else { |
387 | DEBUG11(printk("%s(%ld): done.\n", __func__, | |
7b867cf7 | 388 | vha->host_no)); |
1c7c6357 AV |
389 | } |
390 | } | |
1da177e4 LT |
391 | |
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 | */ | |
ca9e9c3e | 411 | int |
7b867cf7 | 412 | qla2x00_get_fw_version(scsi_qla_host_t *vha, uint16_t *major, uint16_t *minor, |
3a03eb79 | 413 | uint16_t *subminor, uint16_t *attributes, uint32_t *memory, uint8_t *mpi, |
55a96158 | 414 | uint32_t *mpi_caps, uint8_t *phy) |
1da177e4 LT |
415 | { |
416 | int rval; | |
417 | mbx_cmd_t mc; | |
418 | mbx_cmd_t *mcp = &mc; | |
419 | ||
7b867cf7 | 420 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
421 | |
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; | |
3a03eb79 | 425 | if (IS_QLA81XX(vha->hw)) |
55a96158 | 426 | mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8; |
1da177e4 | 427 | mcp->flags = 0; |
b93480e3 | 428 | mcp->tov = MBX_TOV_SECONDS; |
7b867cf7 | 429 | rval = qla2x00_mailbox_command(vha, mcp); |
ca9e9c3e AV |
430 | if (rval != QLA_SUCCESS) |
431 | goto failed; | |
1da177e4 LT |
432 | |
433 | /* Return mailbox data. */ | |
434 | *major = mcp->mb[1]; | |
435 | *minor = mcp->mb[2]; | |
436 | *subminor = mcp->mb[3]; | |
437 | *attributes = mcp->mb[6]; | |
7b867cf7 | 438 | if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw)) |
1da177e4 LT |
439 | *memory = 0x1FFFF; /* Defaults to 128KB. */ |
440 | else | |
441 | *memory = (mcp->mb[5] << 16) | mcp->mb[4]; | |
3a03eb79 | 442 | if (IS_QLA81XX(vha->hw)) { |
55a96158 AV |
443 | mpi[0] = mcp->mb[10] & 0xff; |
444 | mpi[1] = mcp->mb[11] >> 8; | |
445 | mpi[2] = mcp->mb[11] & 0xff; | |
3a03eb79 | 446 | *mpi_caps = (mcp->mb[12] << 16) | mcp->mb[13]; |
55a96158 AV |
447 | phy[0] = mcp->mb[8] & 0xff; |
448 | phy[1] = mcp->mb[9] >> 8; | |
449 | phy[2] = mcp->mb[9] & 0xff; | |
3a03eb79 | 450 | } |
ca9e9c3e | 451 | failed: |
1da177e4 LT |
452 | if (rval != QLA_SUCCESS) { |
453 | /*EMPTY*/ | |
454 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 455 | vha->host_no, rval)); |
1da177e4 LT |
456 | } else { |
457 | /*EMPTY*/ | |
7b867cf7 | 458 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 | 459 | } |
ca9e9c3e | 460 | return rval; |
1da177e4 LT |
461 | } |
462 | ||
463 | /* | |
464 | * qla2x00_get_fw_options | |
465 | * Set firmware options. | |
466 | * | |
467 | * Input: | |
468 | * ha = adapter block pointer. | |
469 | * fwopt = pointer for firmware options. | |
470 | * | |
471 | * Returns: | |
472 | * qla2x00 local function return status code. | |
473 | * | |
474 | * Context: | |
475 | * Kernel context. | |
476 | */ | |
477 | int | |
7b867cf7 | 478 | qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts) |
1da177e4 LT |
479 | { |
480 | int rval; | |
481 | mbx_cmd_t mc; | |
482 | mbx_cmd_t *mcp = &mc; | |
483 | ||
7b867cf7 | 484 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
485 | |
486 | mcp->mb[0] = MBC_GET_FIRMWARE_OPTION; | |
487 | mcp->out_mb = MBX_0; | |
488 | mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0; | |
b93480e3 | 489 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 490 | mcp->flags = 0; |
7b867cf7 | 491 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
492 | |
493 | if (rval != QLA_SUCCESS) { | |
494 | /*EMPTY*/ | |
495 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 496 | vha->host_no, rval)); |
1da177e4 | 497 | } else { |
1c7c6357 | 498 | fwopts[0] = mcp->mb[0]; |
1da177e4 LT |
499 | fwopts[1] = mcp->mb[1]; |
500 | fwopts[2] = mcp->mb[2]; | |
501 | fwopts[3] = mcp->mb[3]; | |
502 | ||
7b867cf7 | 503 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
504 | } |
505 | ||
506 | return rval; | |
507 | } | |
508 | ||
509 | ||
510 | /* | |
511 | * qla2x00_set_fw_options | |
512 | * Set firmware options. | |
513 | * | |
514 | * Input: | |
515 | * ha = adapter block pointer. | |
516 | * fwopt = pointer for firmware options. | |
517 | * | |
518 | * Returns: | |
519 | * qla2x00 local function return status code. | |
520 | * | |
521 | * Context: | |
522 | * Kernel context. | |
523 | */ | |
524 | int | |
7b867cf7 | 525 | qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts) |
1da177e4 LT |
526 | { |
527 | int rval; | |
528 | mbx_cmd_t mc; | |
529 | mbx_cmd_t *mcp = &mc; | |
530 | ||
7b867cf7 | 531 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
532 | |
533 | mcp->mb[0] = MBC_SET_FIRMWARE_OPTION; | |
534 | mcp->mb[1] = fwopts[1]; | |
535 | mcp->mb[2] = fwopts[2]; | |
536 | mcp->mb[3] = fwopts[3]; | |
1c7c6357 | 537 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
1da177e4 | 538 | mcp->in_mb = MBX_0; |
7b867cf7 | 539 | if (IS_FWI2_CAPABLE(vha->hw)) { |
1c7c6357 AV |
540 | mcp->in_mb |= MBX_1; |
541 | } else { | |
542 | mcp->mb[10] = fwopts[10]; | |
543 | mcp->mb[11] = fwopts[11]; | |
544 | mcp->mb[12] = 0; /* Undocumented, but used */ | |
545 | mcp->out_mb |= MBX_12|MBX_11|MBX_10; | |
546 | } | |
b93480e3 | 547 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 548 | mcp->flags = 0; |
7b867cf7 | 549 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 | 550 | |
1c7c6357 AV |
551 | fwopts[0] = mcp->mb[0]; |
552 | ||
1da177e4 LT |
553 | if (rval != QLA_SUCCESS) { |
554 | /*EMPTY*/ | |
1c7c6357 | 555 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__, |
7b867cf7 | 556 | vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
1da177e4 LT |
557 | } else { |
558 | /*EMPTY*/ | |
7b867cf7 | 559 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
560 | } |
561 | ||
562 | return rval; | |
563 | } | |
564 | ||
565 | /* | |
566 | * qla2x00_mbx_reg_test | |
567 | * Mailbox register wrap test. | |
568 | * | |
569 | * Input: | |
570 | * ha = adapter block pointer. | |
571 | * TARGET_QUEUE_LOCK must be released. | |
572 | * ADAPTER_STATE_LOCK must be released. | |
573 | * | |
574 | * Returns: | |
575 | * qla2x00 local function return status code. | |
576 | * | |
577 | * Context: | |
578 | * Kernel context. | |
579 | */ | |
580 | int | |
7b867cf7 | 581 | qla2x00_mbx_reg_test(scsi_qla_host_t *vha) |
1da177e4 LT |
582 | { |
583 | int rval; | |
584 | mbx_cmd_t mc; | |
585 | mbx_cmd_t *mcp = &mc; | |
586 | ||
7b867cf7 | 587 | DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", vha->host_no)); |
1da177e4 LT |
588 | |
589 | mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST; | |
590 | mcp->mb[1] = 0xAAAA; | |
591 | mcp->mb[2] = 0x5555; | |
592 | mcp->mb[3] = 0xAA55; | |
593 | mcp->mb[4] = 0x55AA; | |
594 | mcp->mb[5] = 0xA5A5; | |
595 | mcp->mb[6] = 0x5A5A; | |
596 | mcp->mb[7] = 0x2525; | |
597 | mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
598 | mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
b93480e3 | 599 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 600 | mcp->flags = 0; |
7b867cf7 | 601 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
602 | |
603 | if (rval == QLA_SUCCESS) { | |
604 | if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 || | |
605 | mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA) | |
606 | rval = QLA_FUNCTION_FAILED; | |
607 | if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A || | |
608 | mcp->mb[7] != 0x2525) | |
609 | rval = QLA_FUNCTION_FAILED; | |
610 | } | |
611 | ||
612 | if (rval != QLA_SUCCESS) { | |
613 | /*EMPTY*/ | |
614 | DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n", | |
7b867cf7 | 615 | vha->host_no, rval)); |
1da177e4 LT |
616 | } else { |
617 | /*EMPTY*/ | |
618 | DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n", | |
7b867cf7 | 619 | vha->host_no)); |
1da177e4 LT |
620 | } |
621 | ||
622 | return rval; | |
623 | } | |
624 | ||
625 | /* | |
626 | * qla2x00_verify_checksum | |
627 | * Verify firmware checksum. | |
628 | * | |
629 | * Input: | |
630 | * ha = adapter block pointer. | |
631 | * TARGET_QUEUE_LOCK must be released. | |
632 | * ADAPTER_STATE_LOCK must be released. | |
633 | * | |
634 | * Returns: | |
635 | * qla2x00 local function return status code. | |
636 | * | |
637 | * Context: | |
638 | * Kernel context. | |
639 | */ | |
640 | int | |
7b867cf7 | 641 | qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr) |
1da177e4 LT |
642 | { |
643 | int rval; | |
644 | mbx_cmd_t mc; | |
645 | mbx_cmd_t *mcp = &mc; | |
646 | ||
7b867cf7 | 647 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
648 | |
649 | mcp->mb[0] = MBC_VERIFY_CHECKSUM; | |
1c7c6357 AV |
650 | mcp->out_mb = MBX_0; |
651 | mcp->in_mb = MBX_0; | |
7b867cf7 | 652 | if (IS_FWI2_CAPABLE(vha->hw)) { |
1c7c6357 AV |
653 | mcp->mb[1] = MSW(risc_addr); |
654 | mcp->mb[2] = LSW(risc_addr); | |
655 | mcp->out_mb |= MBX_2|MBX_1; | |
656 | mcp->in_mb |= MBX_2|MBX_1; | |
657 | } else { | |
658 | mcp->mb[1] = LSW(risc_addr); | |
659 | mcp->out_mb |= MBX_1; | |
660 | mcp->in_mb |= MBX_1; | |
661 | } | |
662 | ||
b93480e3 | 663 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 664 | mcp->flags = 0; |
7b867cf7 | 665 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
666 | |
667 | if (rval != QLA_SUCCESS) { | |
1c7c6357 | 668 | DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__, |
7b867cf7 | 669 | vha->host_no, rval, IS_FWI2_CAPABLE(vha->hw) ? |
e428924c | 670 | (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1])); |
1da177e4 | 671 | } else { |
7b867cf7 | 672 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
673 | } |
674 | ||
675 | return rval; | |
676 | } | |
677 | ||
678 | /* | |
679 | * qla2x00_issue_iocb | |
680 | * Issue IOCB using mailbox command | |
681 | * | |
682 | * Input: | |
683 | * ha = adapter state pointer. | |
684 | * buffer = buffer pointer. | |
685 | * phys_addr = physical address of buffer. | |
686 | * size = size of buffer. | |
687 | * TARGET_QUEUE_LOCK must be released. | |
688 | * ADAPTER_STATE_LOCK must be released. | |
689 | * | |
690 | * Returns: | |
691 | * qla2x00 local function return status code. | |
692 | * | |
693 | * Context: | |
694 | * Kernel context. | |
695 | */ | |
3b8117b8 | 696 | static int |
7b867cf7 | 697 | qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer, |
4d4df193 | 698 | dma_addr_t phys_addr, size_t size, uint32_t tov) |
1da177e4 LT |
699 | { |
700 | int rval; | |
701 | mbx_cmd_t mc; | |
702 | mbx_cmd_t *mcp = &mc; | |
703 | ||
704 | mcp->mb[0] = MBC_IOCB_COMMAND_A64; | |
705 | mcp->mb[1] = 0; | |
706 | mcp->mb[2] = MSW(phys_addr); | |
707 | mcp->mb[3] = LSW(phys_addr); | |
708 | mcp->mb[6] = MSW(MSD(phys_addr)); | |
709 | mcp->mb[7] = LSW(MSD(phys_addr)); | |
710 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
711 | mcp->in_mb = MBX_2|MBX_0; | |
4d4df193 | 712 | mcp->tov = tov; |
1da177e4 | 713 | mcp->flags = 0; |
7b867cf7 | 714 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
715 | |
716 | if (rval != QLA_SUCCESS) { | |
717 | /*EMPTY*/ | |
1c7c6357 | 718 | DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n", |
7b867cf7 | 719 | vha->host_no, rval)); |
1da177e4 | 720 | } else { |
8c958a99 AV |
721 | sts_entry_t *sts_entry = (sts_entry_t *) buffer; |
722 | ||
723 | /* Mask reserved bits. */ | |
724 | sts_entry->entry_status &= | |
7b867cf7 | 725 | IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK; |
1da177e4 LT |
726 | } |
727 | ||
728 | return rval; | |
729 | } | |
730 | ||
4d4df193 | 731 | int |
7b867cf7 | 732 | qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr, |
4d4df193 HK |
733 | size_t size) |
734 | { | |
7b867cf7 | 735 | return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size, |
4d4df193 HK |
736 | MBX_TOV_SECONDS); |
737 | } | |
738 | ||
1da177e4 LT |
739 | /* |
740 | * qla2x00_abort_command | |
741 | * Abort command aborts a specified IOCB. | |
742 | * | |
743 | * Input: | |
744 | * ha = adapter block pointer. | |
745 | * sp = SB structure pointer. | |
746 | * | |
747 | * Returns: | |
748 | * qla2x00 local function return status code. | |
749 | * | |
750 | * Context: | |
751 | * Kernel context. | |
752 | */ | |
753 | int | |
2afa19a9 | 754 | qla2x00_abort_command(srb_t *sp) |
1da177e4 LT |
755 | { |
756 | unsigned long flags = 0; | |
1da177e4 | 757 | int rval; |
73208dfd | 758 | uint32_t handle = 0; |
1da177e4 LT |
759 | mbx_cmd_t mc; |
760 | mbx_cmd_t *mcp = &mc; | |
2afa19a9 AC |
761 | fc_port_t *fcport = sp->fcport; |
762 | scsi_qla_host_t *vha = fcport->vha; | |
7b867cf7 | 763 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 | 764 | struct req_que *req = vha->req; |
1da177e4 | 765 | |
7b867cf7 | 766 | DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", vha->host_no)); |
1da177e4 | 767 | |
c9c5ced9 | 768 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1da177e4 | 769 | for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) { |
7b867cf7 | 770 | if (req->outstanding_cmds[handle] == sp) |
1da177e4 LT |
771 | break; |
772 | } | |
c9c5ced9 | 773 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
1da177e4 LT |
774 | |
775 | if (handle == MAX_OUTSTANDING_COMMANDS) { | |
776 | /* command not found */ | |
777 | return QLA_FUNCTION_FAILED; | |
778 | } | |
779 | ||
780 | mcp->mb[0] = MBC_ABORT_COMMAND; | |
781 | if (HAS_EXTENDED_IDS(ha)) | |
782 | mcp->mb[1] = fcport->loop_id; | |
783 | else | |
784 | mcp->mb[1] = fcport->loop_id << 8; | |
785 | mcp->mb[2] = (uint16_t)handle; | |
786 | mcp->mb[3] = (uint16_t)(handle >> 16); | |
bdf79621 | 787 | mcp->mb[6] = (uint16_t)sp->cmd->device->lun; |
1da177e4 LT |
788 | mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
789 | mcp->in_mb = MBX_0; | |
b93480e3 | 790 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 791 | mcp->flags = 0; |
7b867cf7 | 792 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
793 | |
794 | if (rval != QLA_SUCCESS) { | |
795 | DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n", | |
7b867cf7 | 796 | vha->host_no, rval)); |
1da177e4 | 797 | } else { |
1da177e4 | 798 | DEBUG11(printk("qla2x00_abort_command(%ld): done.\n", |
7b867cf7 | 799 | vha->host_no)); |
1da177e4 LT |
800 | } |
801 | ||
802 | return rval; | |
803 | } | |
804 | ||
1da177e4 | 805 | int |
2afa19a9 | 806 | qla2x00_abort_target(struct fc_port *fcport, unsigned int l, int tag) |
1da177e4 | 807 | { |
523ec773 | 808 | int rval, rval2; |
1da177e4 LT |
809 | mbx_cmd_t mc; |
810 | mbx_cmd_t *mcp = &mc; | |
7b867cf7 | 811 | scsi_qla_host_t *vha; |
73208dfd AC |
812 | struct req_que *req; |
813 | struct rsp_que *rsp; | |
1da177e4 | 814 | |
7b867cf7 | 815 | DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no)); |
1c7c6357 | 816 | |
523ec773 | 817 | l = l; |
7b867cf7 | 818 | vha = fcport->vha; |
2afa19a9 AC |
819 | req = vha->hw->req_q_map[tag]; |
820 | rsp = vha->hw->rsp_q_map[tag]; | |
1da177e4 | 821 | mcp->mb[0] = MBC_ABORT_TARGET; |
523ec773 | 822 | mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0; |
7b867cf7 | 823 | if (HAS_EXTENDED_IDS(vha->hw)) { |
1da177e4 LT |
824 | mcp->mb[1] = fcport->loop_id; |
825 | mcp->mb[10] = 0; | |
826 | mcp->out_mb |= MBX_10; | |
827 | } else { | |
828 | mcp->mb[1] = fcport->loop_id << 8; | |
829 | } | |
7b867cf7 AC |
830 | mcp->mb[2] = vha->hw->loop_reset_delay; |
831 | mcp->mb[9] = vha->vp_idx; | |
1da177e4 LT |
832 | |
833 | mcp->in_mb = MBX_0; | |
b93480e3 | 834 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 835 | mcp->flags = 0; |
7b867cf7 | 836 | rval = qla2x00_mailbox_command(vha, mcp); |
523ec773 AV |
837 | if (rval != QLA_SUCCESS) { |
838 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 839 | vha->host_no, rval)); |
523ec773 AV |
840 | } |
841 | ||
842 | /* Issue marker IOCB. */ | |
73208dfd AC |
843 | rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0, |
844 | MK_SYNC_ID); | |
523ec773 AV |
845 | if (rval2 != QLA_SUCCESS) { |
846 | DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB " | |
7b867cf7 | 847 | "(%x).\n", __func__, vha->host_no, rval2)); |
523ec773 | 848 | } else { |
7b867cf7 | 849 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
523ec773 AV |
850 | } |
851 | ||
852 | return rval; | |
853 | } | |
854 | ||
855 | int | |
2afa19a9 | 856 | qla2x00_lun_reset(struct fc_port *fcport, unsigned int l, int tag) |
523ec773 AV |
857 | { |
858 | int rval, rval2; | |
859 | mbx_cmd_t mc; | |
860 | mbx_cmd_t *mcp = &mc; | |
7b867cf7 | 861 | scsi_qla_host_t *vha; |
73208dfd AC |
862 | struct req_que *req; |
863 | struct rsp_que *rsp; | |
523ec773 | 864 | |
7b867cf7 | 865 | DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no)); |
1da177e4 | 866 | |
7b867cf7 | 867 | vha = fcport->vha; |
2afa19a9 AC |
868 | req = vha->hw->req_q_map[tag]; |
869 | rsp = vha->hw->rsp_q_map[tag]; | |
523ec773 AV |
870 | mcp->mb[0] = MBC_LUN_RESET; |
871 | mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0; | |
7b867cf7 | 872 | if (HAS_EXTENDED_IDS(vha->hw)) |
523ec773 AV |
873 | mcp->mb[1] = fcport->loop_id; |
874 | else | |
875 | mcp->mb[1] = fcport->loop_id << 8; | |
876 | mcp->mb[2] = l; | |
877 | mcp->mb[3] = 0; | |
7b867cf7 | 878 | mcp->mb[9] = vha->vp_idx; |
1da177e4 | 879 | |
523ec773 | 880 | mcp->in_mb = MBX_0; |
b93480e3 | 881 | mcp->tov = MBX_TOV_SECONDS; |
523ec773 | 882 | mcp->flags = 0; |
7b867cf7 | 883 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 | 884 | if (rval != QLA_SUCCESS) { |
523ec773 | 885 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, |
7b867cf7 | 886 | vha->host_no, rval)); |
523ec773 AV |
887 | } |
888 | ||
889 | /* Issue marker IOCB. */ | |
73208dfd AC |
890 | rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l, |
891 | MK_SYNC_ID_LUN); | |
523ec773 AV |
892 | if (rval2 != QLA_SUCCESS) { |
893 | DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB " | |
7b867cf7 | 894 | "(%x).\n", __func__, vha->host_no, rval2)); |
1da177e4 | 895 | } else { |
7b867cf7 | 896 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
897 | } |
898 | ||
899 | return rval; | |
900 | } | |
1da177e4 | 901 | |
1da177e4 LT |
902 | /* |
903 | * qla2x00_get_adapter_id | |
904 | * Get adapter ID and topology. | |
905 | * | |
906 | * Input: | |
907 | * ha = adapter block pointer. | |
908 | * id = pointer for loop ID. | |
909 | * al_pa = pointer for AL_PA. | |
910 | * area = pointer for area. | |
911 | * domain = pointer for domain. | |
912 | * top = pointer for topology. | |
913 | * TARGET_QUEUE_LOCK must be released. | |
914 | * ADAPTER_STATE_LOCK must be released. | |
915 | * | |
916 | * Returns: | |
917 | * qla2x00 local function return status code. | |
918 | * | |
919 | * Context: | |
920 | * Kernel context. | |
921 | */ | |
922 | int | |
7b867cf7 | 923 | qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa, |
2c3dfe3f | 924 | uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap) |
1da177e4 LT |
925 | { |
926 | int rval; | |
927 | mbx_cmd_t mc; | |
928 | mbx_cmd_t *mcp = &mc; | |
929 | ||
930 | DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n", | |
7b867cf7 | 931 | vha->host_no)); |
1da177e4 LT |
932 | |
933 | mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID; | |
7b867cf7 | 934 | mcp->mb[9] = vha->vp_idx; |
eb66dc60 | 935 | mcp->out_mb = MBX_9|MBX_0; |
2c3dfe3f | 936 | mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
bad7001c AV |
937 | if (IS_QLA81XX(vha->hw)) |
938 | mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10; | |
b93480e3 | 939 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 940 | mcp->flags = 0; |
7b867cf7 | 941 | rval = qla2x00_mailbox_command(vha, mcp); |
33135aa2 RA |
942 | if (mcp->mb[0] == MBS_COMMAND_ERROR) |
943 | rval = QLA_COMMAND_ERROR; | |
42e421b1 AV |
944 | else if (mcp->mb[0] == MBS_INVALID_COMMAND) |
945 | rval = QLA_INVALID_COMMAND; | |
1da177e4 LT |
946 | |
947 | /* Return data. */ | |
948 | *id = mcp->mb[1]; | |
949 | *al_pa = LSB(mcp->mb[2]); | |
950 | *area = MSB(mcp->mb[2]); | |
951 | *domain = LSB(mcp->mb[3]); | |
952 | *top = mcp->mb[6]; | |
2c3dfe3f | 953 | *sw_cap = mcp->mb[7]; |
1da177e4 LT |
954 | |
955 | if (rval != QLA_SUCCESS) { | |
956 | /*EMPTY*/ | |
957 | DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n", | |
7b867cf7 | 958 | vha->host_no, rval)); |
1da177e4 | 959 | } else { |
1da177e4 | 960 | DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n", |
7b867cf7 | 961 | vha->host_no)); |
bad7001c AV |
962 | |
963 | if (IS_QLA81XX(vha->hw)) { | |
964 | vha->fcoe_vlan_id = mcp->mb[9] & 0xfff; | |
965 | vha->fcoe_fcf_idx = mcp->mb[10]; | |
966 | vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8; | |
967 | vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff; | |
968 | vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8; | |
969 | vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff; | |
970 | vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8; | |
971 | vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff; | |
972 | } | |
1da177e4 LT |
973 | } |
974 | ||
975 | return rval; | |
976 | } | |
977 | ||
978 | /* | |
979 | * qla2x00_get_retry_cnt | |
980 | * Get current firmware login retry count and delay. | |
981 | * | |
982 | * Input: | |
983 | * ha = adapter block pointer. | |
984 | * retry_cnt = pointer to login retry count. | |
985 | * tov = pointer to login timeout value. | |
986 | * | |
987 | * Returns: | |
988 | * qla2x00 local function return status code. | |
989 | * | |
990 | * Context: | |
991 | * Kernel context. | |
992 | */ | |
993 | int | |
7b867cf7 | 994 | qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov, |
1da177e4 LT |
995 | uint16_t *r_a_tov) |
996 | { | |
997 | int rval; | |
998 | uint16_t ratov; | |
999 | mbx_cmd_t mc; | |
1000 | mbx_cmd_t *mcp = &mc; | |
1001 | ||
1002 | DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n", | |
7b867cf7 | 1003 | vha->host_no)); |
1da177e4 LT |
1004 | |
1005 | mcp->mb[0] = MBC_GET_RETRY_COUNT; | |
1006 | mcp->out_mb = MBX_0; | |
1007 | mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0; | |
b93480e3 | 1008 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1009 | mcp->flags = 0; |
7b867cf7 | 1010 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1011 | |
1012 | if (rval != QLA_SUCCESS) { | |
1013 | /*EMPTY*/ | |
1014 | DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n", | |
7b867cf7 | 1015 | vha->host_no, mcp->mb[0])); |
1da177e4 LT |
1016 | } else { |
1017 | /* Convert returned data and check our values. */ | |
1018 | *r_a_tov = mcp->mb[3] / 2; | |
1019 | ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */ | |
1020 | if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) { | |
1021 | /* Update to the larger values */ | |
1022 | *retry_cnt = (uint8_t)mcp->mb[1]; | |
1023 | *tov = ratov; | |
1024 | } | |
1025 | ||
1026 | DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d " | |
7b867cf7 | 1027 | "ratov=%d.\n", vha->host_no, mcp->mb[3], ratov)); |
1da177e4 LT |
1028 | } |
1029 | ||
1030 | return rval; | |
1031 | } | |
1032 | ||
1033 | /* | |
1034 | * qla2x00_init_firmware | |
1035 | * Initialize adapter firmware. | |
1036 | * | |
1037 | * Input: | |
1038 | * ha = adapter block pointer. | |
1039 | * dptr = Initialization control block pointer. | |
1040 | * size = size of initialization control block. | |
1041 | * TARGET_QUEUE_LOCK must be released. | |
1042 | * ADAPTER_STATE_LOCK must be released. | |
1043 | * | |
1044 | * Returns: | |
1045 | * qla2x00 local function return status code. | |
1046 | * | |
1047 | * Context: | |
1048 | * Kernel context. | |
1049 | */ | |
1050 | int | |
7b867cf7 | 1051 | qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size) |
1da177e4 LT |
1052 | { |
1053 | int rval; | |
1054 | mbx_cmd_t mc; | |
1055 | mbx_cmd_t *mcp = &mc; | |
7b867cf7 | 1056 | struct qla_hw_data *ha = vha->hw; |
1da177e4 LT |
1057 | |
1058 | DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n", | |
7b867cf7 | 1059 | vha->host_no)); |
1da177e4 | 1060 | |
e6e074f1 | 1061 | if (ha->flags.npiv_supported) |
2c3dfe3f SJ |
1062 | mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE; |
1063 | else | |
1064 | mcp->mb[0] = MBC_INITIALIZE_FIRMWARE; | |
1065 | ||
b64b0e8f | 1066 | mcp->mb[1] = 0; |
1da177e4 LT |
1067 | mcp->mb[2] = MSW(ha->init_cb_dma); |
1068 | mcp->mb[3] = LSW(ha->init_cb_dma); | |
1da177e4 LT |
1069 | mcp->mb[6] = MSW(MSD(ha->init_cb_dma)); |
1070 | mcp->mb[7] = LSW(MSD(ha->init_cb_dma)); | |
b64b0e8f AV |
1071 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
1072 | if (IS_QLA81XX(ha) && ha->ex_init_cb->ex_version) { | |
1073 | mcp->mb[1] = BIT_0; | |
1074 | mcp->mb[10] = MSW(ha->ex_init_cb_dma); | |
1075 | mcp->mb[11] = LSW(ha->ex_init_cb_dma); | |
1076 | mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma)); | |
1077 | mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma)); | |
1078 | mcp->mb[14] = sizeof(*ha->ex_init_cb); | |
1079 | mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10; | |
1080 | } | |
1081 | mcp->in_mb = MBX_0; | |
1da177e4 LT |
1082 | mcp->buf_size = size; |
1083 | mcp->flags = MBX_DMA_OUT; | |
b93480e3 | 1084 | mcp->tov = MBX_TOV_SECONDS; |
7b867cf7 | 1085 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1086 | |
1087 | if (rval != QLA_SUCCESS) { | |
1088 | /*EMPTY*/ | |
1089 | DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x " | |
1090 | "mb0=%x.\n", | |
7b867cf7 | 1091 | vha->host_no, rval, mcp->mb[0])); |
1da177e4 LT |
1092 | } else { |
1093 | /*EMPTY*/ | |
1094 | DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n", | |
7b867cf7 | 1095 | vha->host_no)); |
1da177e4 LT |
1096 | } |
1097 | ||
1098 | return rval; | |
1099 | } | |
1100 | ||
1101 | /* | |
1102 | * qla2x00_get_port_database | |
1103 | * Issue normal/enhanced get port database mailbox command | |
1104 | * and copy device name as necessary. | |
1105 | * | |
1106 | * Input: | |
1107 | * ha = adapter state pointer. | |
1108 | * dev = structure pointer. | |
1109 | * opt = enhanced cmd option byte. | |
1110 | * | |
1111 | * Returns: | |
1112 | * qla2x00 local function return status code. | |
1113 | * | |
1114 | * Context: | |
1115 | * Kernel context. | |
1116 | */ | |
1117 | int | |
7b867cf7 | 1118 | qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt) |
1da177e4 LT |
1119 | { |
1120 | int rval; | |
1121 | mbx_cmd_t mc; | |
1122 | mbx_cmd_t *mcp = &mc; | |
1123 | port_database_t *pd; | |
1c7c6357 | 1124 | struct port_database_24xx *pd24; |
1da177e4 | 1125 | dma_addr_t pd_dma; |
7b867cf7 | 1126 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 1127 | |
7b867cf7 | 1128 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 | 1129 | |
1c7c6357 AV |
1130 | pd24 = NULL; |
1131 | pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma); | |
1da177e4 | 1132 | if (pd == NULL) { |
1c7c6357 | 1133 | DEBUG2_3(printk("%s(%ld): failed to allocate Port Database " |
7b867cf7 | 1134 | "structure.\n", __func__, vha->host_no)); |
1da177e4 LT |
1135 | return QLA_MEMORY_ALLOC_FAILED; |
1136 | } | |
1c7c6357 | 1137 | memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE)); |
1da177e4 | 1138 | |
1c7c6357 | 1139 | mcp->mb[0] = MBC_GET_PORT_DATABASE; |
e428924c | 1140 | if (opt != 0 && !IS_FWI2_CAPABLE(ha)) |
1da177e4 | 1141 | mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE; |
1da177e4 LT |
1142 | mcp->mb[2] = MSW(pd_dma); |
1143 | mcp->mb[3] = LSW(pd_dma); | |
1144 | mcp->mb[6] = MSW(MSD(pd_dma)); | |
1145 | mcp->mb[7] = LSW(MSD(pd_dma)); | |
7b867cf7 | 1146 | mcp->mb[9] = vha->vp_idx; |
2c3dfe3f | 1147 | mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
1da177e4 | 1148 | mcp->in_mb = MBX_0; |
e428924c | 1149 | if (IS_FWI2_CAPABLE(ha)) { |
1c7c6357 AV |
1150 | mcp->mb[1] = fcport->loop_id; |
1151 | mcp->mb[10] = opt; | |
1152 | mcp->out_mb |= MBX_10|MBX_1; | |
1153 | mcp->in_mb |= MBX_1; | |
1154 | } else if (HAS_EXTENDED_IDS(ha)) { | |
1155 | mcp->mb[1] = fcport->loop_id; | |
1156 | mcp->mb[10] = opt; | |
1157 | mcp->out_mb |= MBX_10|MBX_1; | |
1158 | } else { | |
1159 | mcp->mb[1] = fcport->loop_id << 8 | opt; | |
1160 | mcp->out_mb |= MBX_1; | |
1161 | } | |
e428924c AV |
1162 | mcp->buf_size = IS_FWI2_CAPABLE(ha) ? |
1163 | PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE; | |
1da177e4 LT |
1164 | mcp->flags = MBX_DMA_IN; |
1165 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | |
7b867cf7 | 1166 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1167 | if (rval != QLA_SUCCESS) |
1168 | goto gpd_error_out; | |
1169 | ||
e428924c | 1170 | if (IS_FWI2_CAPABLE(ha)) { |
1c7c6357 AV |
1171 | pd24 = (struct port_database_24xx *) pd; |
1172 | ||
1173 | /* Check for logged in state. */ | |
1174 | if (pd24->current_login_state != PDS_PRLI_COMPLETE && | |
1175 | pd24->last_login_state != PDS_PRLI_COMPLETE) { | |
1176 | DEBUG2(printk("%s(%ld): Unable to verify " | |
1177 | "login-state (%x/%x) for loop_id %x\n", | |
7b867cf7 | 1178 | __func__, vha->host_no, |
1c7c6357 AV |
1179 | pd24->current_login_state, |
1180 | pd24->last_login_state, fcport->loop_id)); | |
1181 | rval = QLA_FUNCTION_FAILED; | |
1182 | goto gpd_error_out; | |
1183 | } | |
1da177e4 | 1184 | |
1c7c6357 AV |
1185 | /* Names are little-endian. */ |
1186 | memcpy(fcport->node_name, pd24->node_name, WWN_SIZE); | |
1187 | memcpy(fcport->port_name, pd24->port_name, WWN_SIZE); | |
1188 | ||
1189 | /* Get port_id of device. */ | |
1190 | fcport->d_id.b.domain = pd24->port_id[0]; | |
1191 | fcport->d_id.b.area = pd24->port_id[1]; | |
1192 | fcport->d_id.b.al_pa = pd24->port_id[2]; | |
1193 | fcport->d_id.b.rsvd_1 = 0; | |
1194 | ||
1195 | /* If not target must be initiator or unknown type. */ | |
1196 | if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0) | |
1197 | fcport->port_type = FCT_INITIATOR; | |
1198 | else | |
1199 | fcport->port_type = FCT_TARGET; | |
1200 | } else { | |
1201 | /* Check for logged in state. */ | |
1202 | if (pd->master_state != PD_STATE_PORT_LOGGED_IN && | |
1203 | pd->slave_state != PD_STATE_PORT_LOGGED_IN) { | |
1204 | rval = QLA_FUNCTION_FAILED; | |
1205 | goto gpd_error_out; | |
1206 | } | |
1da177e4 | 1207 | |
1c7c6357 AV |
1208 | /* Names are little-endian. */ |
1209 | memcpy(fcport->node_name, pd->node_name, WWN_SIZE); | |
1210 | memcpy(fcport->port_name, pd->port_name, WWN_SIZE); | |
1211 | ||
1212 | /* Get port_id of device. */ | |
1213 | fcport->d_id.b.domain = pd->port_id[0]; | |
1214 | fcport->d_id.b.area = pd->port_id[3]; | |
1215 | fcport->d_id.b.al_pa = pd->port_id[2]; | |
1216 | fcport->d_id.b.rsvd_1 = 0; | |
1217 | ||
1c7c6357 AV |
1218 | /* If not target must be initiator or unknown type. */ |
1219 | if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0) | |
1220 | fcport->port_type = FCT_INITIATOR; | |
1221 | else | |
1222 | fcport->port_type = FCT_TARGET; | |
ad3e0eda AV |
1223 | |
1224 | /* Passback COS information. */ | |
1225 | fcport->supported_classes = (pd->options & BIT_4) ? | |
1226 | FC_COS_CLASS2: FC_COS_CLASS3; | |
1c7c6357 | 1227 | } |
1da177e4 LT |
1228 | |
1229 | gpd_error_out: | |
1230 | dma_pool_free(ha->s_dma_pool, pd, pd_dma); | |
1231 | ||
1232 | if (rval != QLA_SUCCESS) { | |
1c7c6357 | 1233 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", |
7b867cf7 | 1234 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
1da177e4 | 1235 | } else { |
7b867cf7 | 1236 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
1237 | } |
1238 | ||
1239 | return rval; | |
1240 | } | |
1241 | ||
1242 | /* | |
1243 | * qla2x00_get_firmware_state | |
1244 | * Get adapter firmware state. | |
1245 | * | |
1246 | * Input: | |
1247 | * ha = adapter block pointer. | |
1248 | * dptr = pointer for firmware state. | |
1249 | * TARGET_QUEUE_LOCK must be released. | |
1250 | * ADAPTER_STATE_LOCK must be released. | |
1251 | * | |
1252 | * Returns: | |
1253 | * qla2x00 local function return status code. | |
1254 | * | |
1255 | * Context: | |
1256 | * Kernel context. | |
1257 | */ | |
1258 | int | |
7b867cf7 | 1259 | qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states) |
1da177e4 LT |
1260 | { |
1261 | int rval; | |
1262 | mbx_cmd_t mc; | |
1263 | mbx_cmd_t *mcp = &mc; | |
1264 | ||
1265 | DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n", | |
7b867cf7 | 1266 | vha->host_no)); |
1da177e4 LT |
1267 | |
1268 | mcp->mb[0] = MBC_GET_FIRMWARE_STATE; | |
1269 | mcp->out_mb = MBX_0; | |
9d2683c0 AV |
1270 | if (IS_FWI2_CAPABLE(vha->hw)) |
1271 | mcp->in_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
1272 | else | |
1273 | mcp->in_mb = MBX_1|MBX_0; | |
b93480e3 | 1274 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1275 | mcp->flags = 0; |
7b867cf7 | 1276 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 | 1277 | |
4d4df193 HK |
1278 | /* Return firmware states. */ |
1279 | states[0] = mcp->mb[1]; | |
9d2683c0 AV |
1280 | if (IS_FWI2_CAPABLE(vha->hw)) { |
1281 | states[1] = mcp->mb[2]; | |
1282 | states[2] = mcp->mb[3]; | |
1283 | states[3] = mcp->mb[4]; | |
1284 | states[4] = mcp->mb[5]; | |
1285 | } | |
1da177e4 LT |
1286 | |
1287 | if (rval != QLA_SUCCESS) { | |
1288 | /*EMPTY*/ | |
1289 | DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): " | |
7b867cf7 | 1290 | "failed=%x.\n", vha->host_no, rval)); |
1da177e4 LT |
1291 | } else { |
1292 | /*EMPTY*/ | |
1293 | DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n", | |
7b867cf7 | 1294 | vha->host_no)); |
1da177e4 LT |
1295 | } |
1296 | ||
1297 | return rval; | |
1298 | } | |
1299 | ||
1300 | /* | |
1301 | * qla2x00_get_port_name | |
1302 | * Issue get port name mailbox command. | |
1303 | * Returned name is in big endian format. | |
1304 | * | |
1305 | * Input: | |
1306 | * ha = adapter block pointer. | |
1307 | * loop_id = loop ID of device. | |
1308 | * name = pointer for name. | |
1309 | * TARGET_QUEUE_LOCK must be released. | |
1310 | * ADAPTER_STATE_LOCK must be released. | |
1311 | * | |
1312 | * Returns: | |
1313 | * qla2x00 local function return status code. | |
1314 | * | |
1315 | * Context: | |
1316 | * Kernel context. | |
1317 | */ | |
1318 | int | |
7b867cf7 | 1319 | qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name, |
1da177e4 LT |
1320 | uint8_t opt) |
1321 | { | |
1322 | int rval; | |
1323 | mbx_cmd_t mc; | |
1324 | mbx_cmd_t *mcp = &mc; | |
1325 | ||
1326 | DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n", | |
7b867cf7 | 1327 | vha->host_no)); |
1da177e4 LT |
1328 | |
1329 | mcp->mb[0] = MBC_GET_PORT_NAME; | |
7b867cf7 | 1330 | mcp->mb[9] = vha->vp_idx; |
2c3dfe3f | 1331 | mcp->out_mb = MBX_9|MBX_1|MBX_0; |
7b867cf7 | 1332 | if (HAS_EXTENDED_IDS(vha->hw)) { |
1da177e4 LT |
1333 | mcp->mb[1] = loop_id; |
1334 | mcp->mb[10] = opt; | |
1335 | mcp->out_mb |= MBX_10; | |
1336 | } else { | |
1337 | mcp->mb[1] = loop_id << 8 | opt; | |
1338 | } | |
1339 | ||
1340 | mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
b93480e3 | 1341 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1342 | mcp->flags = 0; |
7b867cf7 | 1343 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1344 | |
1345 | if (rval != QLA_SUCCESS) { | |
1346 | /*EMPTY*/ | |
1347 | DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n", | |
7b867cf7 | 1348 | vha->host_no, rval)); |
1da177e4 LT |
1349 | } else { |
1350 | if (name != NULL) { | |
1351 | /* This function returns name in big endian. */ | |
1196ae02 RL |
1352 | name[0] = MSB(mcp->mb[2]); |
1353 | name[1] = LSB(mcp->mb[2]); | |
1354 | name[2] = MSB(mcp->mb[3]); | |
1355 | name[3] = LSB(mcp->mb[3]); | |
1356 | name[4] = MSB(mcp->mb[6]); | |
1357 | name[5] = LSB(mcp->mb[6]); | |
1358 | name[6] = MSB(mcp->mb[7]); | |
1359 | name[7] = LSB(mcp->mb[7]); | |
1da177e4 LT |
1360 | } |
1361 | ||
1362 | DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n", | |
7b867cf7 | 1363 | vha->host_no)); |
1da177e4 LT |
1364 | } |
1365 | ||
1366 | return rval; | |
1367 | } | |
1368 | ||
1369 | /* | |
1370 | * qla2x00_lip_reset | |
1371 | * Issue LIP reset mailbox command. | |
1372 | * | |
1373 | * Input: | |
1374 | * ha = adapter block pointer. | |
1375 | * TARGET_QUEUE_LOCK must be released. | |
1376 | * ADAPTER_STATE_LOCK must be released. | |
1377 | * | |
1378 | * Returns: | |
1379 | * qla2x00 local function return status code. | |
1380 | * | |
1381 | * Context: | |
1382 | * Kernel context. | |
1383 | */ | |
1384 | int | |
7b867cf7 | 1385 | qla2x00_lip_reset(scsi_qla_host_t *vha) |
1da177e4 LT |
1386 | { |
1387 | int rval; | |
1388 | mbx_cmd_t mc; | |
1389 | mbx_cmd_t *mcp = &mc; | |
1390 | ||
7b867cf7 | 1391 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 | 1392 | |
3a03eb79 AV |
1393 | if (IS_QLA81XX(vha->hw)) { |
1394 | /* Logout across all FCFs. */ | |
1395 | mcp->mb[0] = MBC_LIP_FULL_LOGIN; | |
1396 | mcp->mb[1] = BIT_1; | |
1397 | mcp->mb[2] = 0; | |
1398 | mcp->out_mb = MBX_2|MBX_1|MBX_0; | |
1399 | } else if (IS_FWI2_CAPABLE(vha->hw)) { | |
1c7c6357 | 1400 | mcp->mb[0] = MBC_LIP_FULL_LOGIN; |
0c8c39af AV |
1401 | mcp->mb[1] = BIT_6; |
1402 | mcp->mb[2] = 0; | |
7b867cf7 | 1403 | mcp->mb[3] = vha->hw->loop_reset_delay; |
1c7c6357 | 1404 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; |
1da177e4 | 1405 | } else { |
1c7c6357 AV |
1406 | mcp->mb[0] = MBC_LIP_RESET; |
1407 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; | |
7b867cf7 | 1408 | if (HAS_EXTENDED_IDS(vha->hw)) { |
1c7c6357 AV |
1409 | mcp->mb[1] = 0x00ff; |
1410 | mcp->mb[10] = 0; | |
1411 | mcp->out_mb |= MBX_10; | |
1412 | } else { | |
1413 | mcp->mb[1] = 0xff00; | |
1414 | } | |
7b867cf7 | 1415 | mcp->mb[2] = vha->hw->loop_reset_delay; |
1c7c6357 | 1416 | mcp->mb[3] = 0; |
1da177e4 | 1417 | } |
1da177e4 | 1418 | mcp->in_mb = MBX_0; |
b93480e3 | 1419 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1420 | mcp->flags = 0; |
7b867cf7 | 1421 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1422 | |
1423 | if (rval != QLA_SUCCESS) { | |
1424 | /*EMPTY*/ | |
1c7c6357 | 1425 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", |
7b867cf7 | 1426 | __func__, vha->host_no, rval)); |
1da177e4 LT |
1427 | } else { |
1428 | /*EMPTY*/ | |
7b867cf7 | 1429 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
1430 | } |
1431 | ||
1432 | return rval; | |
1433 | } | |
1434 | ||
1435 | /* | |
1436 | * qla2x00_send_sns | |
1437 | * Send SNS command. | |
1438 | * | |
1439 | * Input: | |
1440 | * ha = adapter block pointer. | |
1441 | * sns = pointer for command. | |
1442 | * cmd_size = command size. | |
1443 | * buf_size = response/command size. | |
1444 | * TARGET_QUEUE_LOCK must be released. | |
1445 | * ADAPTER_STATE_LOCK must be released. | |
1446 | * | |
1447 | * Returns: | |
1448 | * qla2x00 local function return status code. | |
1449 | * | |
1450 | * Context: | |
1451 | * Kernel context. | |
1452 | */ | |
1453 | int | |
7b867cf7 | 1454 | qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address, |
1da177e4 LT |
1455 | uint16_t cmd_size, size_t buf_size) |
1456 | { | |
1457 | int rval; | |
1458 | mbx_cmd_t mc; | |
1459 | mbx_cmd_t *mcp = &mc; | |
1460 | ||
1461 | DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n", | |
7b867cf7 | 1462 | vha->host_no)); |
1da177e4 LT |
1463 | |
1464 | DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total " | |
7b867cf7 AC |
1465 | "tov=%d.\n", vha->hw->retry_count, vha->hw->login_timeout, |
1466 | mcp->tov)); | |
1da177e4 LT |
1467 | |
1468 | mcp->mb[0] = MBC_SEND_SNS_COMMAND; | |
1469 | mcp->mb[1] = cmd_size; | |
1470 | mcp->mb[2] = MSW(sns_phys_address); | |
1471 | mcp->mb[3] = LSW(sns_phys_address); | |
1472 | mcp->mb[6] = MSW(MSD(sns_phys_address)); | |
1473 | mcp->mb[7] = LSW(MSD(sns_phys_address)); | |
1474 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
1475 | mcp->in_mb = MBX_0|MBX_1; | |
1476 | mcp->buf_size = buf_size; | |
1477 | mcp->flags = MBX_DMA_OUT|MBX_DMA_IN; | |
7b867cf7 AC |
1478 | mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2); |
1479 | rval = qla2x00_mailbox_command(vha, mcp); | |
1da177e4 LT |
1480 | |
1481 | if (rval != QLA_SUCCESS) { | |
1482 | /*EMPTY*/ | |
1483 | DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " | |
7b867cf7 | 1484 | "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
1da177e4 | 1485 | DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x " |
7b867cf7 | 1486 | "mb[1]=%x.\n", vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
1da177e4 LT |
1487 | } else { |
1488 | /*EMPTY*/ | |
7b867cf7 | 1489 | DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", vha->host_no)); |
1da177e4 LT |
1490 | } |
1491 | ||
1492 | return rval; | |
1493 | } | |
1494 | ||
1c7c6357 | 1495 | int |
7b867cf7 | 1496 | qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, |
1c7c6357 AV |
1497 | uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt) |
1498 | { | |
1499 | int rval; | |
1500 | ||
1501 | struct logio_entry_24xx *lg; | |
1502 | dma_addr_t lg_dma; | |
1503 | uint32_t iop[2]; | |
7b867cf7 | 1504 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
1505 | struct req_que *req; |
1506 | struct rsp_que *rsp; | |
1c7c6357 | 1507 | |
7b867cf7 | 1508 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1c7c6357 | 1509 | |
7163ea81 | 1510 | if (ha->flags.cpu_affinity_enabled) |
68ca949c AC |
1511 | req = ha->req_q_map[0]; |
1512 | else | |
1513 | req = vha->req; | |
2afa19a9 AC |
1514 | rsp = req->rsp; |
1515 | ||
1c7c6357 AV |
1516 | lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma); |
1517 | if (lg == NULL) { | |
1518 | DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n", | |
7b867cf7 | 1519 | __func__, vha->host_no)); |
1c7c6357 AV |
1520 | return QLA_MEMORY_ALLOC_FAILED; |
1521 | } | |
1522 | memset(lg, 0, sizeof(struct logio_entry_24xx)); | |
1523 | ||
1524 | lg->entry_type = LOGINOUT_PORT_IOCB_TYPE; | |
1525 | lg->entry_count = 1; | |
2afa19a9 | 1526 | lg->handle = MAKE_HANDLE(req->id, lg->handle); |
1c7c6357 AV |
1527 | lg->nport_handle = cpu_to_le16(loop_id); |
1528 | lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI); | |
1529 | if (opt & BIT_0) | |
1530 | lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI); | |
8baa51a6 AV |
1531 | if (opt & BIT_1) |
1532 | lg->control_flags |= __constant_cpu_to_le16(LCF_SKIP_PRLI); | |
1c7c6357 AV |
1533 | lg->port_id[0] = al_pa; |
1534 | lg->port_id[1] = area; | |
1535 | lg->port_id[2] = domain; | |
7b867cf7 AC |
1536 | lg->vp_index = vha->vp_idx; |
1537 | rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0); | |
1c7c6357 AV |
1538 | if (rval != QLA_SUCCESS) { |
1539 | DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB " | |
7b867cf7 | 1540 | "(%x).\n", __func__, vha->host_no, rval)); |
1c7c6357 AV |
1541 | } else if (lg->entry_status != 0) { |
1542 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 1543 | "-- error status (%x).\n", __func__, vha->host_no, |
1c7c6357 AV |
1544 | lg->entry_status)); |
1545 | rval = QLA_FUNCTION_FAILED; | |
1546 | } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) { | |
1547 | iop[0] = le32_to_cpu(lg->io_parameter[0]); | |
1548 | iop[1] = le32_to_cpu(lg->io_parameter[1]); | |
1549 | ||
1550 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
1551 | "-- completion status (%x) ioparam=%x/%x.\n", __func__, | |
7b867cf7 | 1552 | vha->host_no, le16_to_cpu(lg->comp_status), iop[0], |
1c7c6357 AV |
1553 | iop[1])); |
1554 | ||
1555 | switch (iop[0]) { | |
1556 | case LSC_SCODE_PORTID_USED: | |
1557 | mb[0] = MBS_PORT_ID_USED; | |
1558 | mb[1] = LSW(iop[1]); | |
1559 | break; | |
1560 | case LSC_SCODE_NPORT_USED: | |
1561 | mb[0] = MBS_LOOP_ID_USED; | |
1562 | break; | |
1563 | case LSC_SCODE_NOLINK: | |
1564 | case LSC_SCODE_NOIOCB: | |
1565 | case LSC_SCODE_NOXCB: | |
1566 | case LSC_SCODE_CMD_FAILED: | |
1567 | case LSC_SCODE_NOFABRIC: | |
1568 | case LSC_SCODE_FW_NOT_READY: | |
1569 | case LSC_SCODE_NOT_LOGGED_IN: | |
1570 | case LSC_SCODE_NOPCB: | |
1571 | case LSC_SCODE_ELS_REJECT: | |
1572 | case LSC_SCODE_CMD_PARAM_ERR: | |
1573 | case LSC_SCODE_NONPORT: | |
1574 | case LSC_SCODE_LOGGED_IN: | |
1575 | case LSC_SCODE_NOFLOGI_ACC: | |
1576 | default: | |
1577 | mb[0] = MBS_COMMAND_ERROR; | |
1578 | break; | |
1579 | } | |
1580 | } else { | |
7b867cf7 | 1581 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1c7c6357 AV |
1582 | |
1583 | iop[0] = le32_to_cpu(lg->io_parameter[0]); | |
1584 | ||
1585 | mb[0] = MBS_COMMAND_COMPLETE; | |
1586 | mb[1] = 0; | |
1587 | if (iop[0] & BIT_4) { | |
1588 | if (iop[0] & BIT_8) | |
1589 | mb[1] |= BIT_1; | |
1590 | } else | |
1591 | mb[1] = BIT_0; | |
ad3e0eda AV |
1592 | |
1593 | /* Passback COS information. */ | |
1594 | mb[10] = 0; | |
1595 | if (lg->io_parameter[7] || lg->io_parameter[8]) | |
1596 | mb[10] |= BIT_0; /* Class 2. */ | |
1597 | if (lg->io_parameter[9] || lg->io_parameter[10]) | |
1598 | mb[10] |= BIT_1; /* Class 3. */ | |
1c7c6357 AV |
1599 | } |
1600 | ||
1601 | dma_pool_free(ha->s_dma_pool, lg, lg_dma); | |
1602 | ||
1603 | return rval; | |
1604 | } | |
1605 | ||
1da177e4 LT |
1606 | /* |
1607 | * qla2x00_login_fabric | |
1608 | * Issue login fabric port mailbox command. | |
1609 | * | |
1610 | * Input: | |
1611 | * ha = adapter block pointer. | |
1612 | * loop_id = device loop ID. | |
1613 | * domain = device domain. | |
1614 | * area = device area. | |
1615 | * al_pa = device AL_PA. | |
1616 | * status = pointer for return status. | |
1617 | * opt = command options. | |
1618 | * TARGET_QUEUE_LOCK must be released. | |
1619 | * ADAPTER_STATE_LOCK must be released. | |
1620 | * | |
1621 | * Returns: | |
1622 | * qla2x00 local function return status code. | |
1623 | * | |
1624 | * Context: | |
1625 | * Kernel context. | |
1626 | */ | |
1627 | int | |
7b867cf7 | 1628 | qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, |
1da177e4 LT |
1629 | uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt) |
1630 | { | |
1631 | int rval; | |
1632 | mbx_cmd_t mc; | |
1633 | mbx_cmd_t *mcp = &mc; | |
7b867cf7 | 1634 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 1635 | |
7b867cf7 | 1636 | DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", vha->host_no)); |
1da177e4 LT |
1637 | |
1638 | mcp->mb[0] = MBC_LOGIN_FABRIC_PORT; | |
1639 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; | |
1640 | if (HAS_EXTENDED_IDS(ha)) { | |
1641 | mcp->mb[1] = loop_id; | |
1642 | mcp->mb[10] = opt; | |
1643 | mcp->out_mb |= MBX_10; | |
1644 | } else { | |
1645 | mcp->mb[1] = (loop_id << 8) | opt; | |
1646 | } | |
1647 | mcp->mb[2] = domain; | |
1648 | mcp->mb[3] = area << 8 | al_pa; | |
1649 | ||
1650 | mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0; | |
1651 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | |
1652 | mcp->flags = 0; | |
7b867cf7 | 1653 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1654 | |
1655 | /* Return mailbox statuses. */ | |
1656 | if (mb != NULL) { | |
1657 | mb[0] = mcp->mb[0]; | |
1658 | mb[1] = mcp->mb[1]; | |
1659 | mb[2] = mcp->mb[2]; | |
1660 | mb[6] = mcp->mb[6]; | |
1661 | mb[7] = mcp->mb[7]; | |
ad3e0eda AV |
1662 | /* COS retrieved from Get-Port-Database mailbox command. */ |
1663 | mb[10] = 0; | |
1da177e4 LT |
1664 | } |
1665 | ||
1666 | if (rval != QLA_SUCCESS) { | |
1667 | /* RLU tmp code: need to change main mailbox_command function to | |
1668 | * return ok even when the mailbox completion value is not | |
1669 | * SUCCESS. The caller needs to be responsible to interpret | |
1670 | * the return values of this mailbox command if we're not | |
1671 | * to change too much of the existing code. | |
1672 | */ | |
1673 | if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 || | |
1674 | mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 || | |
1675 | mcp->mb[0] == 0x4006) | |
1676 | rval = QLA_SUCCESS; | |
1677 | ||
1678 | /*EMPTY*/ | |
1679 | DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x " | |
7b867cf7 | 1680 | "mb[0]=%x mb[1]=%x mb[2]=%x.\n", vha->host_no, rval, |
744f11fd | 1681 | mcp->mb[0], mcp->mb[1], mcp->mb[2])); |
1da177e4 LT |
1682 | } else { |
1683 | /*EMPTY*/ | |
1684 | DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n", | |
7b867cf7 | 1685 | vha->host_no)); |
1da177e4 LT |
1686 | } |
1687 | ||
1688 | return rval; | |
1689 | } | |
1690 | ||
1691 | /* | |
1692 | * qla2x00_login_local_device | |
1693 | * Issue login loop port mailbox command. | |
fa2a1ce5 | 1694 | * |
1da177e4 LT |
1695 | * Input: |
1696 | * ha = adapter block pointer. | |
1697 | * loop_id = device loop ID. | |
1698 | * opt = command options. | |
fa2a1ce5 | 1699 | * |
1da177e4 LT |
1700 | * Returns: |
1701 | * Return status code. | |
fa2a1ce5 | 1702 | * |
1da177e4 LT |
1703 | * Context: |
1704 | * Kernel context. | |
fa2a1ce5 | 1705 | * |
1da177e4 LT |
1706 | */ |
1707 | int | |
7b867cf7 | 1708 | qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport, |
1da177e4 LT |
1709 | uint16_t *mb_ret, uint8_t opt) |
1710 | { | |
1711 | int rval; | |
1712 | mbx_cmd_t mc; | |
1713 | mbx_cmd_t *mcp = &mc; | |
7b867cf7 | 1714 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 1715 | |
e428924c | 1716 | if (IS_FWI2_CAPABLE(ha)) |
7b867cf7 | 1717 | return qla24xx_login_fabric(vha, fcport->loop_id, |
9a52a57c | 1718 | fcport->d_id.b.domain, fcport->d_id.b.area, |
1719 | fcport->d_id.b.al_pa, mb_ret, opt); | |
1720 | ||
7b867cf7 | 1721 | DEBUG3(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
1722 | |
1723 | mcp->mb[0] = MBC_LOGIN_LOOP_PORT; | |
1724 | if (HAS_EXTENDED_IDS(ha)) | |
9a52a57c | 1725 | mcp->mb[1] = fcport->loop_id; |
1da177e4 | 1726 | else |
9a52a57c | 1727 | mcp->mb[1] = fcport->loop_id << 8; |
1da177e4 LT |
1728 | mcp->mb[2] = opt; |
1729 | mcp->out_mb = MBX_2|MBX_1|MBX_0; | |
1730 | mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0; | |
1731 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | |
1732 | mcp->flags = 0; | |
7b867cf7 | 1733 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1734 | |
1735 | /* Return mailbox statuses. */ | |
1736 | if (mb_ret != NULL) { | |
1737 | mb_ret[0] = mcp->mb[0]; | |
1738 | mb_ret[1] = mcp->mb[1]; | |
1739 | mb_ret[6] = mcp->mb[6]; | |
1740 | mb_ret[7] = mcp->mb[7]; | |
1741 | } | |
1742 | ||
1743 | if (rval != QLA_SUCCESS) { | |
1744 | /* AV tmp code: need to change main mailbox_command function to | |
1745 | * return ok even when the mailbox completion value is not | |
1746 | * SUCCESS. The caller needs to be responsible to interpret | |
1747 | * the return values of this mailbox command if we're not | |
1748 | * to change too much of the existing code. | |
1749 | */ | |
1750 | if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006) | |
1751 | rval = QLA_SUCCESS; | |
1752 | ||
1753 | DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " | |
7b867cf7 | 1754 | "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval, |
744f11fd | 1755 | mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7])); |
1da177e4 | 1756 | DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " |
7b867cf7 | 1757 | "mb[6]=%x mb[7]=%x.\n", __func__, vha->host_no, rval, |
744f11fd | 1758 | mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7])); |
1da177e4 LT |
1759 | } else { |
1760 | /*EMPTY*/ | |
7b867cf7 | 1761 | DEBUG3(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
1762 | } |
1763 | ||
1764 | return (rval); | |
1765 | } | |
1766 | ||
1c7c6357 | 1767 | int |
7b867cf7 | 1768 | qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, |
1c7c6357 AV |
1769 | uint8_t area, uint8_t al_pa) |
1770 | { | |
1771 | int rval; | |
1772 | struct logio_entry_24xx *lg; | |
1773 | dma_addr_t lg_dma; | |
7b867cf7 | 1774 | struct qla_hw_data *ha = vha->hw; |
2afa19a9 AC |
1775 | struct req_que *req; |
1776 | struct rsp_que *rsp; | |
1c7c6357 | 1777 | |
7b867cf7 | 1778 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1c7c6357 AV |
1779 | |
1780 | lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma); | |
1781 | if (lg == NULL) { | |
1782 | DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n", | |
7b867cf7 | 1783 | __func__, vha->host_no)); |
1c7c6357 AV |
1784 | return QLA_MEMORY_ALLOC_FAILED; |
1785 | } | |
1786 | memset(lg, 0, sizeof(struct logio_entry_24xx)); | |
1787 | ||
2afa19a9 AC |
1788 | if (ql2xmaxqueues > 1) |
1789 | req = ha->req_q_map[0]; | |
1790 | else | |
1791 | req = vha->req; | |
1792 | rsp = req->rsp; | |
1c7c6357 AV |
1793 | lg->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
1794 | lg->entry_count = 1; | |
2afa19a9 | 1795 | lg->handle = MAKE_HANDLE(req->id, lg->handle); |
1c7c6357 AV |
1796 | lg->nport_handle = cpu_to_le16(loop_id); |
1797 | lg->control_flags = | |
b1372bc9 | 1798 | __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO); |
1c7c6357 AV |
1799 | lg->port_id[0] = al_pa; |
1800 | lg->port_id[1] = area; | |
1801 | lg->port_id[2] = domain; | |
7b867cf7 | 1802 | lg->vp_index = vha->vp_idx; |
73208dfd | 1803 | |
7b867cf7 | 1804 | rval = qla2x00_issue_iocb(vha, lg, lg_dma, 0); |
1c7c6357 AV |
1805 | if (rval != QLA_SUCCESS) { |
1806 | DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB " | |
7b867cf7 | 1807 | "(%x).\n", __func__, vha->host_no, rval)); |
1c7c6357 AV |
1808 | } else if (lg->entry_status != 0) { |
1809 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 1810 | "-- error status (%x).\n", __func__, vha->host_no, |
1c7c6357 AV |
1811 | lg->entry_status)); |
1812 | rval = QLA_FUNCTION_FAILED; | |
1813 | } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) { | |
73208dfd | 1814 | DEBUG2_3_11(printk("%s(%ld %d): failed to complete IOCB " |
1c7c6357 | 1815 | "-- completion status (%x) ioparam=%x/%x.\n", __func__, |
73208dfd | 1816 | vha->host_no, vha->vp_idx, le16_to_cpu(lg->comp_status), |
1c7c6357 | 1817 | le32_to_cpu(lg->io_parameter[0]), |
744f11fd | 1818 | le32_to_cpu(lg->io_parameter[1]))); |
1c7c6357 AV |
1819 | } else { |
1820 | /*EMPTY*/ | |
7b867cf7 | 1821 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1c7c6357 AV |
1822 | } |
1823 | ||
1824 | dma_pool_free(ha->s_dma_pool, lg, lg_dma); | |
1825 | ||
1826 | return rval; | |
1827 | } | |
1828 | ||
1da177e4 LT |
1829 | /* |
1830 | * qla2x00_fabric_logout | |
1831 | * Issue logout fabric port mailbox command. | |
1832 | * | |
1833 | * Input: | |
1834 | * ha = adapter block pointer. | |
1835 | * loop_id = device loop ID. | |
1836 | * TARGET_QUEUE_LOCK must be released. | |
1837 | * ADAPTER_STATE_LOCK must be released. | |
1838 | * | |
1839 | * Returns: | |
1840 | * qla2x00 local function return status code. | |
1841 | * | |
1842 | * Context: | |
1843 | * Kernel context. | |
1844 | */ | |
1845 | int | |
7b867cf7 | 1846 | qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain, |
1c7c6357 | 1847 | uint8_t area, uint8_t al_pa) |
1da177e4 LT |
1848 | { |
1849 | int rval; | |
1850 | mbx_cmd_t mc; | |
1851 | mbx_cmd_t *mcp = &mc; | |
1852 | ||
1853 | DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n", | |
7b867cf7 | 1854 | vha->host_no)); |
1da177e4 LT |
1855 | |
1856 | mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT; | |
1857 | mcp->out_mb = MBX_1|MBX_0; | |
7b867cf7 | 1858 | if (HAS_EXTENDED_IDS(vha->hw)) { |
1da177e4 LT |
1859 | mcp->mb[1] = loop_id; |
1860 | mcp->mb[10] = 0; | |
1861 | mcp->out_mb |= MBX_10; | |
1862 | } else { | |
1863 | mcp->mb[1] = loop_id << 8; | |
1864 | } | |
1865 | ||
1866 | mcp->in_mb = MBX_1|MBX_0; | |
b93480e3 | 1867 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1868 | mcp->flags = 0; |
7b867cf7 | 1869 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1870 | |
1871 | if (rval != QLA_SUCCESS) { | |
1872 | /*EMPTY*/ | |
1873 | DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x " | |
7b867cf7 | 1874 | "mbx1=%x.\n", vha->host_no, rval, mcp->mb[1])); |
1da177e4 LT |
1875 | } else { |
1876 | /*EMPTY*/ | |
1877 | DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n", | |
7b867cf7 | 1878 | vha->host_no)); |
1da177e4 LT |
1879 | } |
1880 | ||
1881 | return rval; | |
1882 | } | |
1883 | ||
1884 | /* | |
1885 | * qla2x00_full_login_lip | |
1886 | * Issue full login LIP mailbox command. | |
1887 | * | |
1888 | * Input: | |
1889 | * ha = adapter block pointer. | |
1890 | * TARGET_QUEUE_LOCK must be released. | |
1891 | * ADAPTER_STATE_LOCK must be released. | |
1892 | * | |
1893 | * Returns: | |
1894 | * qla2x00 local function return status code. | |
1895 | * | |
1896 | * Context: | |
1897 | * Kernel context. | |
1898 | */ | |
1899 | int | |
7b867cf7 | 1900 | qla2x00_full_login_lip(scsi_qla_host_t *vha) |
1da177e4 LT |
1901 | { |
1902 | int rval; | |
1903 | mbx_cmd_t mc; | |
1904 | mbx_cmd_t *mcp = &mc; | |
1905 | ||
1906 | DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n", | |
7b867cf7 | 1907 | vha->host_no)); |
1da177e4 LT |
1908 | |
1909 | mcp->mb[0] = MBC_LIP_FULL_LOGIN; | |
7b867cf7 | 1910 | mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0; |
0c8c39af | 1911 | mcp->mb[2] = 0; |
1da177e4 LT |
1912 | mcp->mb[3] = 0; |
1913 | mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0; | |
1914 | mcp->in_mb = MBX_0; | |
b93480e3 | 1915 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1916 | mcp->flags = 0; |
7b867cf7 | 1917 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1918 | |
1919 | if (rval != QLA_SUCCESS) { | |
1920 | /*EMPTY*/ | |
1921 | DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n", | |
7b867cf7 | 1922 | vha->host_no, rval)); |
1da177e4 LT |
1923 | } else { |
1924 | /*EMPTY*/ | |
1925 | DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n", | |
7b867cf7 | 1926 | vha->host_no)); |
1da177e4 LT |
1927 | } |
1928 | ||
1929 | return rval; | |
1930 | } | |
1931 | ||
1932 | /* | |
1933 | * qla2x00_get_id_list | |
1934 | * | |
1935 | * Input: | |
1936 | * ha = adapter block pointer. | |
1937 | * | |
1938 | * Returns: | |
1939 | * qla2x00 local function return status code. | |
1940 | * | |
1941 | * Context: | |
1942 | * Kernel context. | |
1943 | */ | |
1944 | int | |
7b867cf7 | 1945 | qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma, |
1da177e4 LT |
1946 | uint16_t *entries) |
1947 | { | |
1948 | int rval; | |
1949 | mbx_cmd_t mc; | |
1950 | mbx_cmd_t *mcp = &mc; | |
1951 | ||
1952 | DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n", | |
7b867cf7 | 1953 | vha->host_no)); |
1da177e4 LT |
1954 | |
1955 | if (id_list == NULL) | |
1956 | return QLA_FUNCTION_FAILED; | |
1957 | ||
1958 | mcp->mb[0] = MBC_GET_ID_LIST; | |
1c7c6357 | 1959 | mcp->out_mb = MBX_0; |
7b867cf7 | 1960 | if (IS_FWI2_CAPABLE(vha->hw)) { |
1c7c6357 AV |
1961 | mcp->mb[2] = MSW(id_list_dma); |
1962 | mcp->mb[3] = LSW(id_list_dma); | |
1963 | mcp->mb[6] = MSW(MSD(id_list_dma)); | |
1964 | mcp->mb[7] = LSW(MSD(id_list_dma)); | |
247ec457 | 1965 | mcp->mb[8] = 0; |
7b867cf7 | 1966 | mcp->mb[9] = vha->vp_idx; |
2c3dfe3f | 1967 | mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2; |
1c7c6357 AV |
1968 | } else { |
1969 | mcp->mb[1] = MSW(id_list_dma); | |
1970 | mcp->mb[2] = LSW(id_list_dma); | |
1971 | mcp->mb[3] = MSW(MSD(id_list_dma)); | |
1972 | mcp->mb[6] = LSW(MSD(id_list_dma)); | |
1973 | mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1; | |
1974 | } | |
1da177e4 | 1975 | mcp->in_mb = MBX_1|MBX_0; |
b93480e3 | 1976 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 1977 | mcp->flags = 0; |
7b867cf7 | 1978 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
1979 | |
1980 | if (rval != QLA_SUCCESS) { | |
1981 | /*EMPTY*/ | |
1982 | DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n", | |
7b867cf7 | 1983 | vha->host_no, rval)); |
1da177e4 LT |
1984 | } else { |
1985 | *entries = mcp->mb[1]; | |
1986 | DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n", | |
7b867cf7 | 1987 | vha->host_no)); |
1da177e4 LT |
1988 | } |
1989 | ||
1990 | return rval; | |
1991 | } | |
1992 | ||
1993 | /* | |
1994 | * qla2x00_get_resource_cnts | |
1995 | * Get current firmware resource counts. | |
1996 | * | |
1997 | * Input: | |
1998 | * ha = adapter block pointer. | |
1999 | * | |
2000 | * Returns: | |
2001 | * qla2x00 local function return status code. | |
2002 | * | |
2003 | * Context: | |
2004 | * Kernel context. | |
2005 | */ | |
2006 | int | |
7b867cf7 | 2007 | qla2x00_get_resource_cnts(scsi_qla_host_t *vha, uint16_t *cur_xchg_cnt, |
4d0ea247 | 2008 | uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, |
f3a0a77e | 2009 | uint16_t *orig_iocb_cnt, uint16_t *max_npiv_vports, uint16_t *max_fcfs) |
1da177e4 LT |
2010 | { |
2011 | int rval; | |
2012 | mbx_cmd_t mc; | |
2013 | mbx_cmd_t *mcp = &mc; | |
2014 | ||
7b867cf7 | 2015 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1da177e4 LT |
2016 | |
2017 | mcp->mb[0] = MBC_GET_RESOURCE_COUNTS; | |
2018 | mcp->out_mb = MBX_0; | |
4d0ea247 | 2019 | mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; |
f3a0a77e AV |
2020 | if (IS_QLA81XX(vha->hw)) |
2021 | mcp->in_mb |= MBX_12; | |
b93480e3 | 2022 | mcp->tov = MBX_TOV_SECONDS; |
1da177e4 | 2023 | mcp->flags = 0; |
7b867cf7 | 2024 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
2025 | |
2026 | if (rval != QLA_SUCCESS) { | |
2027 | /*EMPTY*/ | |
2028 | DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__, | |
7b867cf7 | 2029 | vha->host_no, mcp->mb[0])); |
1da177e4 LT |
2030 | } else { |
2031 | DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x " | |
f3a0a77e AV |
2032 | "mb7=%x mb10=%x mb11=%x mb12=%x.\n", __func__, |
2033 | vha->host_no, mcp->mb[1], mcp->mb[2], mcp->mb[3], | |
2034 | mcp->mb[6], mcp->mb[7], mcp->mb[10], mcp->mb[11], | |
2035 | mcp->mb[12])); | |
1da177e4 LT |
2036 | |
2037 | if (cur_xchg_cnt) | |
2038 | *cur_xchg_cnt = mcp->mb[3]; | |
2039 | if (orig_xchg_cnt) | |
2040 | *orig_xchg_cnt = mcp->mb[6]; | |
2041 | if (cur_iocb_cnt) | |
2042 | *cur_iocb_cnt = mcp->mb[7]; | |
2043 | if (orig_iocb_cnt) | |
2044 | *orig_iocb_cnt = mcp->mb[10]; | |
7b867cf7 | 2045 | if (vha->hw->flags.npiv_supported && max_npiv_vports) |
4d0ea247 | 2046 | *max_npiv_vports = mcp->mb[11]; |
f3a0a77e AV |
2047 | if (IS_QLA81XX(vha->hw) && max_fcfs) |
2048 | *max_fcfs = mcp->mb[12]; | |
1da177e4 LT |
2049 | } |
2050 | ||
2051 | return (rval); | |
2052 | } | |
2053 | ||
2054 | #if defined(QL_DEBUG_LEVEL_3) | |
2055 | /* | |
2056 | * qla2x00_get_fcal_position_map | |
2057 | * Get FCAL (LILP) position map using mailbox command | |
2058 | * | |
2059 | * Input: | |
2060 | * ha = adapter state pointer. | |
2061 | * pos_map = buffer pointer (can be NULL). | |
2062 | * | |
2063 | * Returns: | |
2064 | * qla2x00 local function return status code. | |
2065 | * | |
2066 | * Context: | |
2067 | * Kernel context. | |
2068 | */ | |
2069 | int | |
7b867cf7 | 2070 | qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map) |
1da177e4 LT |
2071 | { |
2072 | int rval; | |
2073 | mbx_cmd_t mc; | |
2074 | mbx_cmd_t *mcp = &mc; | |
2075 | char *pmap; | |
2076 | dma_addr_t pmap_dma; | |
7b867cf7 | 2077 | struct qla_hw_data *ha = vha->hw; |
1da177e4 | 2078 | |
4b89258c | 2079 | pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma); |
1da177e4 LT |
2080 | if (pmap == NULL) { |
2081 | DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****", | |
7b867cf7 | 2082 | __func__, vha->host_no)); |
1da177e4 LT |
2083 | return QLA_MEMORY_ALLOC_FAILED; |
2084 | } | |
2085 | memset(pmap, 0, FCAL_MAP_SIZE); | |
2086 | ||
2087 | mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP; | |
2088 | mcp->mb[2] = MSW(pmap_dma); | |
2089 | mcp->mb[3] = LSW(pmap_dma); | |
2090 | mcp->mb[6] = MSW(MSD(pmap_dma)); | |
2091 | mcp->mb[7] = LSW(MSD(pmap_dma)); | |
2092 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; | |
2093 | mcp->in_mb = MBX_1|MBX_0; | |
2094 | mcp->buf_size = FCAL_MAP_SIZE; | |
2095 | mcp->flags = MBX_DMA_IN; | |
2096 | mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2); | |
7b867cf7 | 2097 | rval = qla2x00_mailbox_command(vha, mcp); |
1da177e4 LT |
2098 | |
2099 | if (rval == QLA_SUCCESS) { | |
2100 | DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map " | |
7b867cf7 | 2101 | "size (%x)\n", __func__, vha->host_no, mcp->mb[0], |
1da177e4 LT |
2102 | mcp->mb[1], (unsigned)pmap[0])); |
2103 | DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1)); | |
2104 | ||
2105 | if (pos_map) | |
2106 | memcpy(pos_map, pmap, FCAL_MAP_SIZE); | |
2107 | } | |
2108 | dma_pool_free(ha->s_dma_pool, pmap, pmap_dma); | |
2109 | ||
2110 | if (rval != QLA_SUCCESS) { | |
2111 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 2112 | vha->host_no, rval)); |
1da177e4 | 2113 | } else { |
7b867cf7 | 2114 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1da177e4 LT |
2115 | } |
2116 | ||
2117 | return rval; | |
2118 | } | |
392e2f65 | 2119 | #endif |
2120 | ||
2121 | /* | |
2122 | * qla2x00_get_link_status | |
2123 | * | |
2124 | * Input: | |
2125 | * ha = adapter block pointer. | |
2126 | * loop_id = device loop ID. | |
2127 | * ret_buf = pointer to link status return buffer. | |
2128 | * | |
2129 | * Returns: | |
2130 | * 0 = success. | |
2131 | * BIT_0 = mem alloc error. | |
2132 | * BIT_1 = mailbox error. | |
2133 | */ | |
2134 | int | |
7b867cf7 | 2135 | qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id, |
43ef0580 | 2136 | struct link_statistics *stats, dma_addr_t stats_dma) |
392e2f65 | 2137 | { |
2138 | int rval; | |
2139 | mbx_cmd_t mc; | |
2140 | mbx_cmd_t *mcp = &mc; | |
43ef0580 | 2141 | uint32_t *siter, *diter, dwords; |
7b867cf7 | 2142 | struct qla_hw_data *ha = vha->hw; |
392e2f65 | 2143 | |
7b867cf7 | 2144 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
392e2f65 | 2145 | |
392e2f65 | 2146 | mcp->mb[0] = MBC_GET_LINK_STATUS; |
43ef0580 AV |
2147 | mcp->mb[2] = MSW(stats_dma); |
2148 | mcp->mb[3] = LSW(stats_dma); | |
2149 | mcp->mb[6] = MSW(MSD(stats_dma)); | |
2150 | mcp->mb[7] = LSW(MSD(stats_dma)); | |
392e2f65 | 2151 | mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
2152 | mcp->in_mb = MBX_0; | |
e428924c | 2153 | if (IS_FWI2_CAPABLE(ha)) { |
392e2f65 | 2154 | mcp->mb[1] = loop_id; |
2155 | mcp->mb[4] = 0; | |
2156 | mcp->mb[10] = 0; | |
2157 | mcp->out_mb |= MBX_10|MBX_4|MBX_1; | |
2158 | mcp->in_mb |= MBX_1; | |
2159 | } else if (HAS_EXTENDED_IDS(ha)) { | |
2160 | mcp->mb[1] = loop_id; | |
2161 | mcp->mb[10] = 0; | |
2162 | mcp->out_mb |= MBX_10|MBX_1; | |
2163 | } else { | |
2164 | mcp->mb[1] = loop_id << 8; | |
2165 | mcp->out_mb |= MBX_1; | |
2166 | } | |
b93480e3 | 2167 | mcp->tov = MBX_TOV_SECONDS; |
392e2f65 | 2168 | mcp->flags = IOCTL_CMD; |
7b867cf7 | 2169 | rval = qla2x00_mailbox_command(vha, mcp); |
392e2f65 | 2170 | |
2171 | if (rval == QLA_SUCCESS) { | |
2172 | if (mcp->mb[0] != MBS_COMMAND_COMPLETE) { | |
2173 | DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n", | |
7b867cf7 | 2174 | __func__, vha->host_no, mcp->mb[0])); |
43ef0580 | 2175 | rval = QLA_FUNCTION_FAILED; |
392e2f65 | 2176 | } else { |
43ef0580 AV |
2177 | /* Copy over data -- firmware data is LE. */ |
2178 | dwords = offsetof(struct link_statistics, unused1) / 4; | |
2179 | siter = diter = &stats->link_fail_cnt; | |
2180 | while (dwords--) | |
2181 | *diter++ = le32_to_cpu(*siter++); | |
392e2f65 | 2182 | } |
2183 | } else { | |
2184 | /* Failed. */ | |
2185 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 2186 | vha->host_no, rval)); |
392e2f65 | 2187 | } |
2188 | ||
392e2f65 | 2189 | return rval; |
2190 | } | |
2191 | ||
2192 | int | |
7b867cf7 | 2193 | qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats, |
43ef0580 | 2194 | dma_addr_t stats_dma) |
1c7c6357 AV |
2195 | { |
2196 | int rval; | |
2197 | mbx_cmd_t mc; | |
2198 | mbx_cmd_t *mcp = &mc; | |
43ef0580 | 2199 | uint32_t *siter, *diter, dwords; |
1c7c6357 | 2200 | |
7b867cf7 | 2201 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1c7c6357 | 2202 | |
1c7c6357 | 2203 | mcp->mb[0] = MBC_GET_LINK_PRIV_STATS; |
43ef0580 AV |
2204 | mcp->mb[2] = MSW(stats_dma); |
2205 | mcp->mb[3] = LSW(stats_dma); | |
2206 | mcp->mb[6] = MSW(MSD(stats_dma)); | |
2207 | mcp->mb[7] = LSW(MSD(stats_dma)); | |
2208 | mcp->mb[8] = sizeof(struct link_statistics) / 4; | |
7b867cf7 | 2209 | mcp->mb[9] = vha->vp_idx; |
1c7c6357 | 2210 | mcp->mb[10] = 0; |
43ef0580 | 2211 | mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; |
1c7c6357 | 2212 | mcp->in_mb = MBX_2|MBX_1|MBX_0; |
b93480e3 | 2213 | mcp->tov = MBX_TOV_SECONDS; |
1c7c6357 | 2214 | mcp->flags = IOCTL_CMD; |
7b867cf7 | 2215 | rval = qla2x00_mailbox_command(vha, mcp); |
1c7c6357 AV |
2216 | |
2217 | if (rval == QLA_SUCCESS) { | |
2218 | if (mcp->mb[0] != MBS_COMMAND_COMPLETE) { | |
2219 | DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n", | |
7b867cf7 | 2220 | __func__, vha->host_no, mcp->mb[0])); |
43ef0580 | 2221 | rval = QLA_FUNCTION_FAILED; |
1c7c6357 AV |
2222 | } else { |
2223 | /* Copy over data -- firmware data is LE. */ | |
43ef0580 AV |
2224 | dwords = sizeof(struct link_statistics) / 4; |
2225 | siter = diter = &stats->link_fail_cnt; | |
1c7c6357 | 2226 | while (dwords--) |
43ef0580 | 2227 | *diter++ = le32_to_cpu(*siter++); |
1c7c6357 AV |
2228 | } |
2229 | } else { | |
2230 | /* Failed. */ | |
2231 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 2232 | vha->host_no, rval)); |
1c7c6357 AV |
2233 | } |
2234 | ||
1c7c6357 AV |
2235 | return rval; |
2236 | } | |
1c7c6357 AV |
2237 | |
2238 | int | |
2afa19a9 | 2239 | qla24xx_abort_command(srb_t *sp) |
1c7c6357 AV |
2240 | { |
2241 | int rval; | |
1c7c6357 AV |
2242 | unsigned long flags = 0; |
2243 | ||
2244 | struct abort_entry_24xx *abt; | |
2245 | dma_addr_t abt_dma; | |
2246 | uint32_t handle; | |
2afa19a9 AC |
2247 | fc_port_t *fcport = sp->fcport; |
2248 | struct scsi_qla_host *vha = fcport->vha; | |
7b867cf7 | 2249 | struct qla_hw_data *ha = vha->hw; |
67c2e93a | 2250 | struct req_que *req = vha->req; |
1c7c6357 | 2251 | |
7b867cf7 | 2252 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1c7c6357 | 2253 | |
7b867cf7 | 2254 | spin_lock_irqsave(&ha->hardware_lock, flags); |
1c7c6357 | 2255 | for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) { |
7b867cf7 | 2256 | if (req->outstanding_cmds[handle] == sp) |
1c7c6357 AV |
2257 | break; |
2258 | } | |
7b867cf7 | 2259 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
1c7c6357 AV |
2260 | if (handle == MAX_OUTSTANDING_COMMANDS) { |
2261 | /* Command not found. */ | |
2262 | return QLA_FUNCTION_FAILED; | |
2263 | } | |
2264 | ||
2265 | abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma); | |
2266 | if (abt == NULL) { | |
2267 | DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n", | |
7b867cf7 | 2268 | __func__, vha->host_no)); |
1c7c6357 AV |
2269 | return QLA_MEMORY_ALLOC_FAILED; |
2270 | } | |
2271 | memset(abt, 0, sizeof(struct abort_entry_24xx)); | |
2272 | ||
2273 | abt->entry_type = ABORT_IOCB_TYPE; | |
2274 | abt->entry_count = 1; | |
2afa19a9 | 2275 | abt->handle = MAKE_HANDLE(req->id, abt->handle); |
1c7c6357 AV |
2276 | abt->nport_handle = cpu_to_le16(fcport->loop_id); |
2277 | abt->handle_to_abort = handle; | |
2278 | abt->port_id[0] = fcport->d_id.b.al_pa; | |
2279 | abt->port_id[1] = fcport->d_id.b.area; | |
2280 | abt->port_id[2] = fcport->d_id.b.domain; | |
2c3dfe3f | 2281 | abt->vp_index = fcport->vp_idx; |
73208dfd AC |
2282 | |
2283 | abt->req_que_no = cpu_to_le16(req->id); | |
2284 | ||
7b867cf7 | 2285 | rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0); |
1c7c6357 AV |
2286 | if (rval != QLA_SUCCESS) { |
2287 | DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n", | |
7b867cf7 | 2288 | __func__, vha->host_no, rval)); |
1c7c6357 AV |
2289 | } else if (abt->entry_status != 0) { |
2290 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2291 | "-- error status (%x).\n", __func__, vha->host_no, |
1c7c6357 AV |
2292 | abt->entry_status)); |
2293 | rval = QLA_FUNCTION_FAILED; | |
2294 | } else if (abt->nport_handle != __constant_cpu_to_le16(0)) { | |
2295 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2296 | "-- completion status (%x).\n", __func__, vha->host_no, |
744f11fd | 2297 | le16_to_cpu(abt->nport_handle))); |
1c7c6357 AV |
2298 | rval = QLA_FUNCTION_FAILED; |
2299 | } else { | |
7b867cf7 | 2300 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2301 | } |
2302 | ||
2303 | dma_pool_free(ha->s_dma_pool, abt, abt_dma); | |
2304 | ||
2305 | return rval; | |
2306 | } | |
2307 | ||
2308 | struct tsk_mgmt_cmd { | |
2309 | union { | |
2310 | struct tsk_mgmt_entry tsk; | |
2311 | struct sts_entry_24xx sts; | |
2312 | } p; | |
2313 | }; | |
2314 | ||
523ec773 AV |
2315 | static int |
2316 | __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport, | |
2afa19a9 | 2317 | unsigned int l, int tag) |
1c7c6357 | 2318 | { |
523ec773 | 2319 | int rval, rval2; |
1c7c6357 | 2320 | struct tsk_mgmt_cmd *tsk; |
9ca1d01f | 2321 | struct sts_entry_24xx *sts; |
1c7c6357 | 2322 | dma_addr_t tsk_dma; |
7b867cf7 AC |
2323 | scsi_qla_host_t *vha; |
2324 | struct qla_hw_data *ha; | |
73208dfd AC |
2325 | struct req_que *req; |
2326 | struct rsp_que *rsp; | |
1c7c6357 | 2327 | |
749af3d5 | 2328 | DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->vha->host_no)); |
1c7c6357 | 2329 | |
7b867cf7 AC |
2330 | vha = fcport->vha; |
2331 | ha = vha->hw; | |
2afa19a9 | 2332 | req = vha->req; |
7163ea81 | 2333 | if (ha->flags.cpu_affinity_enabled) |
68ca949c AC |
2334 | rsp = ha->rsp_q_map[tag + 1]; |
2335 | else | |
2336 | rsp = req->rsp; | |
7b867cf7 | 2337 | tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma); |
1c7c6357 AV |
2338 | if (tsk == NULL) { |
2339 | DEBUG2_3(printk("%s(%ld): failed to allocate Task Management " | |
7b867cf7 | 2340 | "IOCB.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2341 | return QLA_MEMORY_ALLOC_FAILED; |
2342 | } | |
2343 | memset(tsk, 0, sizeof(struct tsk_mgmt_cmd)); | |
2344 | ||
2345 | tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE; | |
2346 | tsk->p.tsk.entry_count = 1; | |
2afa19a9 | 2347 | tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle); |
1c7c6357 | 2348 | tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id); |
00a537b8 | 2349 | tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
523ec773 | 2350 | tsk->p.tsk.control_flags = cpu_to_le32(type); |
1c7c6357 AV |
2351 | tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa; |
2352 | tsk->p.tsk.port_id[1] = fcport->d_id.b.area; | |
2353 | tsk->p.tsk.port_id[2] = fcport->d_id.b.domain; | |
2c3dfe3f | 2354 | tsk->p.tsk.vp_index = fcport->vp_idx; |
523ec773 AV |
2355 | if (type == TCF_LUN_RESET) { |
2356 | int_to_scsilun(l, &tsk->p.tsk.lun); | |
2357 | host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun, | |
2358 | sizeof(tsk->p.tsk.lun)); | |
2359 | } | |
2c3dfe3f | 2360 | |
9ca1d01f | 2361 | sts = &tsk->p.sts; |
7b867cf7 | 2362 | rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0); |
1c7c6357 | 2363 | if (rval != QLA_SUCCESS) { |
523ec773 | 2364 | DEBUG2_3_11(printk("%s(%ld): failed to issue %s Reset IOCB " |
7b867cf7 | 2365 | "(%x).\n", __func__, vha->host_no, name, rval)); |
9ca1d01f | 2366 | } else if (sts->entry_status != 0) { |
1c7c6357 | 2367 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " |
7b867cf7 | 2368 | "-- error status (%x).\n", __func__, vha->host_no, |
9ca1d01f | 2369 | sts->entry_status)); |
1c7c6357 | 2370 | rval = QLA_FUNCTION_FAILED; |
9ca1d01f | 2371 | } else if (sts->comp_status != |
1c7c6357 AV |
2372 | __constant_cpu_to_le16(CS_COMPLETE)) { |
2373 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
2374 | "-- completion status (%x).\n", __func__, | |
9ca1d01f AV |
2375 | vha->host_no, le16_to_cpu(sts->comp_status))); |
2376 | rval = QLA_FUNCTION_FAILED; | |
2377 | } else if (!(le16_to_cpu(sts->scsi_status) & | |
2378 | SS_RESPONSE_INFO_LEN_VALID)) { | |
2379 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
2380 | "-- no response info (%x).\n", __func__, vha->host_no, | |
2381 | le16_to_cpu(sts->scsi_status))); | |
2382 | rval = QLA_FUNCTION_FAILED; | |
2383 | } else if (le32_to_cpu(sts->rsp_data_len) < 4) { | |
2384 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
2385 | "-- not enough response info (%d).\n", __func__, | |
2386 | vha->host_no, le32_to_cpu(sts->rsp_data_len))); | |
2387 | rval = QLA_FUNCTION_FAILED; | |
2388 | } else if (sts->data[3]) { | |
2389 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
2390 | "-- response (%x).\n", __func__, | |
2391 | vha->host_no, sts->data[3])); | |
1c7c6357 | 2392 | rval = QLA_FUNCTION_FAILED; |
1c7c6357 AV |
2393 | } |
2394 | ||
2395 | /* Issue marker IOCB. */ | |
73208dfd | 2396 | rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l, |
523ec773 AV |
2397 | type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID); |
2398 | if (rval2 != QLA_SUCCESS) { | |
1c7c6357 | 2399 | DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB " |
7b867cf7 | 2400 | "(%x).\n", __func__, vha->host_no, rval2)); |
1c7c6357 | 2401 | } else { |
7b867cf7 | 2402 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2403 | } |
2404 | ||
7b867cf7 | 2405 | dma_pool_free(ha->s_dma_pool, tsk, tsk_dma); |
1c7c6357 AV |
2406 | |
2407 | return rval; | |
2408 | } | |
2409 | ||
523ec773 | 2410 | int |
2afa19a9 | 2411 | qla24xx_abort_target(struct fc_port *fcport, unsigned int l, int tag) |
523ec773 | 2412 | { |
2afa19a9 | 2413 | return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag); |
523ec773 AV |
2414 | } |
2415 | ||
2416 | int | |
2afa19a9 | 2417 | qla24xx_lun_reset(struct fc_port *fcport, unsigned int l, int tag) |
523ec773 | 2418 | { |
2afa19a9 | 2419 | return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag); |
523ec773 AV |
2420 | } |
2421 | ||
1c7c6357 | 2422 | int |
7b867cf7 | 2423 | qla2x00_system_error(scsi_qla_host_t *vha) |
1c7c6357 AV |
2424 | { |
2425 | int rval; | |
2426 | mbx_cmd_t mc; | |
2427 | mbx_cmd_t *mcp = &mc; | |
7b867cf7 | 2428 | struct qla_hw_data *ha = vha->hw; |
1c7c6357 | 2429 | |
68af0811 | 2430 | if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha)) |
1c7c6357 AV |
2431 | return QLA_FUNCTION_FAILED; |
2432 | ||
7b867cf7 | 2433 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2434 | |
2435 | mcp->mb[0] = MBC_GEN_SYSTEM_ERROR; | |
2436 | mcp->out_mb = MBX_0; | |
2437 | mcp->in_mb = MBX_0; | |
2438 | mcp->tov = 5; | |
2439 | mcp->flags = 0; | |
7b867cf7 | 2440 | rval = qla2x00_mailbox_command(vha, mcp); |
1c7c6357 AV |
2441 | |
2442 | if (rval != QLA_SUCCESS) { | |
2443 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 2444 | vha->host_no, rval)); |
1c7c6357 | 2445 | } else { |
7b867cf7 | 2446 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2447 | } |
2448 | ||
2449 | return rval; | |
2450 | } | |
2451 | ||
1c7c6357 AV |
2452 | /** |
2453 | * qla2x00_set_serdes_params() - | |
2454 | * @ha: HA context | |
2455 | * | |
2456 | * Returns | |
2457 | */ | |
2458 | int | |
7b867cf7 | 2459 | qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g, |
1c7c6357 AV |
2460 | uint16_t sw_em_2g, uint16_t sw_em_4g) |
2461 | { | |
2462 | int rval; | |
2463 | mbx_cmd_t mc; | |
2464 | mbx_cmd_t *mcp = &mc; | |
2465 | ||
7b867cf7 | 2466 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2467 | |
2468 | mcp->mb[0] = MBC_SERDES_PARAMS; | |
2469 | mcp->mb[1] = BIT_0; | |
fdbc6833 | 2470 | mcp->mb[2] = sw_em_1g | BIT_15; |
2471 | mcp->mb[3] = sw_em_2g | BIT_15; | |
2472 | mcp->mb[4] = sw_em_4g | BIT_15; | |
1c7c6357 AV |
2473 | mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
2474 | mcp->in_mb = MBX_0; | |
b93480e3 | 2475 | mcp->tov = MBX_TOV_SECONDS; |
1c7c6357 | 2476 | mcp->flags = 0; |
7b867cf7 | 2477 | rval = qla2x00_mailbox_command(vha, mcp); |
1c7c6357 AV |
2478 | |
2479 | if (rval != QLA_SUCCESS) { | |
2480 | /*EMPTY*/ | |
2481 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, | |
7b867cf7 | 2482 | vha->host_no, rval, mcp->mb[0])); |
1c7c6357 AV |
2483 | } else { |
2484 | /*EMPTY*/ | |
7b867cf7 | 2485 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
1c7c6357 AV |
2486 | } |
2487 | ||
2488 | return rval; | |
2489 | } | |
f6ef3b18 AV |
2490 | |
2491 | int | |
7b867cf7 | 2492 | qla2x00_stop_firmware(scsi_qla_host_t *vha) |
f6ef3b18 AV |
2493 | { |
2494 | int rval; | |
2495 | mbx_cmd_t mc; | |
2496 | mbx_cmd_t *mcp = &mc; | |
2497 | ||
7b867cf7 | 2498 | if (!IS_FWI2_CAPABLE(vha->hw)) |
f6ef3b18 AV |
2499 | return QLA_FUNCTION_FAILED; |
2500 | ||
7b867cf7 | 2501 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
f6ef3b18 AV |
2502 | |
2503 | mcp->mb[0] = MBC_STOP_FIRMWARE; | |
2504 | mcp->out_mb = MBX_0; | |
2505 | mcp->in_mb = MBX_0; | |
2506 | mcp->tov = 5; | |
2507 | mcp->flags = 0; | |
7b867cf7 | 2508 | rval = qla2x00_mailbox_command(vha, mcp); |
f6ef3b18 AV |
2509 | |
2510 | if (rval != QLA_SUCCESS) { | |
2511 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 2512 | vha->host_no, rval)); |
b469a7cb AV |
2513 | if (mcp->mb[0] == MBS_INVALID_COMMAND) |
2514 | rval = QLA_INVALID_COMMAND; | |
f6ef3b18 | 2515 | } else { |
7b867cf7 | 2516 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
f6ef3b18 AV |
2517 | } |
2518 | ||
2519 | return rval; | |
2520 | } | |
a7a167bf AV |
2521 | |
2522 | int | |
7b867cf7 | 2523 | qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma, |
a7a167bf AV |
2524 | uint16_t buffers) |
2525 | { | |
2526 | int rval; | |
2527 | mbx_cmd_t mc; | |
2528 | mbx_cmd_t *mcp = &mc; | |
2529 | ||
7b867cf7 | 2530 | if (!IS_FWI2_CAPABLE(vha->hw)) |
a7a167bf AV |
2531 | return QLA_FUNCTION_FAILED; |
2532 | ||
7b867cf7 | 2533 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
a7a167bf AV |
2534 | |
2535 | mcp->mb[0] = MBC_TRACE_CONTROL; | |
00b6bd25 AV |
2536 | mcp->mb[1] = TC_EFT_ENABLE; |
2537 | mcp->mb[2] = LSW(eft_dma); | |
2538 | mcp->mb[3] = MSW(eft_dma); | |
2539 | mcp->mb[4] = LSW(MSD(eft_dma)); | |
2540 | mcp->mb[5] = MSW(MSD(eft_dma)); | |
2541 | mcp->mb[6] = buffers; | |
2542 | mcp->mb[7] = TC_AEN_DISABLE; | |
2543 | mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
a7a167bf | 2544 | mcp->in_mb = MBX_1|MBX_0; |
b93480e3 | 2545 | mcp->tov = MBX_TOV_SECONDS; |
a7a167bf | 2546 | mcp->flags = 0; |
7b867cf7 | 2547 | rval = qla2x00_mailbox_command(vha, mcp); |
00b6bd25 AV |
2548 | if (rval != QLA_SUCCESS) { |
2549 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", | |
7b867cf7 | 2550 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
00b6bd25 | 2551 | } else { |
7b867cf7 | 2552 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
00b6bd25 AV |
2553 | } |
2554 | ||
2555 | return rval; | |
2556 | } | |
a7a167bf | 2557 | |
00b6bd25 | 2558 | int |
7b867cf7 | 2559 | qla2x00_disable_eft_trace(scsi_qla_host_t *vha) |
00b6bd25 AV |
2560 | { |
2561 | int rval; | |
2562 | mbx_cmd_t mc; | |
2563 | mbx_cmd_t *mcp = &mc; | |
2564 | ||
7b867cf7 | 2565 | if (!IS_FWI2_CAPABLE(vha->hw)) |
00b6bd25 AV |
2566 | return QLA_FUNCTION_FAILED; |
2567 | ||
7b867cf7 | 2568 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
00b6bd25 AV |
2569 | |
2570 | mcp->mb[0] = MBC_TRACE_CONTROL; | |
2571 | mcp->mb[1] = TC_EFT_DISABLE; | |
2572 | mcp->out_mb = MBX_1|MBX_0; | |
2573 | mcp->in_mb = MBX_1|MBX_0; | |
b93480e3 | 2574 | mcp->tov = MBX_TOV_SECONDS; |
00b6bd25 | 2575 | mcp->flags = 0; |
7b867cf7 | 2576 | rval = qla2x00_mailbox_command(vha, mcp); |
a7a167bf AV |
2577 | if (rval != QLA_SUCCESS) { |
2578 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", | |
7b867cf7 | 2579 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
a7a167bf | 2580 | } else { |
7b867cf7 | 2581 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
a7a167bf AV |
2582 | } |
2583 | ||
2584 | return rval; | |
2585 | } | |
2586 | ||
df613b96 | 2587 | int |
7b867cf7 | 2588 | qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma, |
df613b96 AV |
2589 | uint16_t buffers, uint16_t *mb, uint32_t *dwords) |
2590 | { | |
2591 | int rval; | |
2592 | mbx_cmd_t mc; | |
2593 | mbx_cmd_t *mcp = &mc; | |
2594 | ||
3a03eb79 | 2595 | if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw)) |
df613b96 AV |
2596 | return QLA_FUNCTION_FAILED; |
2597 | ||
7b867cf7 | 2598 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
df613b96 AV |
2599 | |
2600 | mcp->mb[0] = MBC_TRACE_CONTROL; | |
2601 | mcp->mb[1] = TC_FCE_ENABLE; | |
2602 | mcp->mb[2] = LSW(fce_dma); | |
2603 | mcp->mb[3] = MSW(fce_dma); | |
2604 | mcp->mb[4] = LSW(MSD(fce_dma)); | |
2605 | mcp->mb[5] = MSW(MSD(fce_dma)); | |
2606 | mcp->mb[6] = buffers; | |
2607 | mcp->mb[7] = TC_AEN_DISABLE; | |
2608 | mcp->mb[8] = 0; | |
2609 | mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE; | |
2610 | mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE; | |
2611 | mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2| | |
2612 | MBX_1|MBX_0; | |
2613 | mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
b93480e3 | 2614 | mcp->tov = MBX_TOV_SECONDS; |
df613b96 | 2615 | mcp->flags = 0; |
7b867cf7 | 2616 | rval = qla2x00_mailbox_command(vha, mcp); |
df613b96 AV |
2617 | if (rval != QLA_SUCCESS) { |
2618 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", | |
7b867cf7 | 2619 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
df613b96 | 2620 | } else { |
7b867cf7 | 2621 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
df613b96 AV |
2622 | |
2623 | if (mb) | |
2624 | memcpy(mb, mcp->mb, 8 * sizeof(*mb)); | |
2625 | if (dwords) | |
fa0926df | 2626 | *dwords = buffers; |
df613b96 AV |
2627 | } |
2628 | ||
2629 | return rval; | |
2630 | } | |
2631 | ||
2632 | int | |
7b867cf7 | 2633 | qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd) |
df613b96 AV |
2634 | { |
2635 | int rval; | |
2636 | mbx_cmd_t mc; | |
2637 | mbx_cmd_t *mcp = &mc; | |
2638 | ||
7b867cf7 | 2639 | if (!IS_FWI2_CAPABLE(vha->hw)) |
df613b96 AV |
2640 | return QLA_FUNCTION_FAILED; |
2641 | ||
7b867cf7 | 2642 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
df613b96 AV |
2643 | |
2644 | mcp->mb[0] = MBC_TRACE_CONTROL; | |
2645 | mcp->mb[1] = TC_FCE_DISABLE; | |
2646 | mcp->mb[2] = TC_FCE_DISABLE_TRACE; | |
2647 | mcp->out_mb = MBX_2|MBX_1|MBX_0; | |
2648 | mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2| | |
2649 | MBX_1|MBX_0; | |
b93480e3 | 2650 | mcp->tov = MBX_TOV_SECONDS; |
df613b96 | 2651 | mcp->flags = 0; |
7b867cf7 | 2652 | rval = qla2x00_mailbox_command(vha, mcp); |
df613b96 AV |
2653 | if (rval != QLA_SUCCESS) { |
2654 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", | |
7b867cf7 | 2655 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); |
df613b96 | 2656 | } else { |
7b867cf7 | 2657 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
df613b96 AV |
2658 | |
2659 | if (wr) | |
2660 | *wr = (uint64_t) mcp->mb[5] << 48 | | |
2661 | (uint64_t) mcp->mb[4] << 32 | | |
2662 | (uint64_t) mcp->mb[3] << 16 | | |
2663 | (uint64_t) mcp->mb[2]; | |
2664 | if (rd) | |
2665 | *rd = (uint64_t) mcp->mb[9] << 48 | | |
2666 | (uint64_t) mcp->mb[8] << 32 | | |
2667 | (uint64_t) mcp->mb[7] << 16 | | |
2668 | (uint64_t) mcp->mb[6]; | |
2669 | } | |
2670 | ||
2671 | return rval; | |
2672 | } | |
2673 | ||
88729e53 | 2674 | int |
7b867cf7 | 2675 | qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint16_t addr, |
88729e53 AV |
2676 | uint16_t off, uint16_t count) |
2677 | { | |
2678 | int rval; | |
2679 | mbx_cmd_t mc; | |
2680 | mbx_cmd_t *mcp = &mc; | |
a7a167bf | 2681 | |
7b867cf7 | 2682 | if (!IS_FWI2_CAPABLE(vha->hw)) |
88729e53 AV |
2683 | return QLA_FUNCTION_FAILED; |
2684 | ||
7b867cf7 | 2685 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
88729e53 AV |
2686 | |
2687 | mcp->mb[0] = MBC_READ_SFP; | |
2688 | mcp->mb[1] = addr; | |
2689 | mcp->mb[2] = MSW(sfp_dma); | |
2690 | mcp->mb[3] = LSW(sfp_dma); | |
2691 | mcp->mb[6] = MSW(MSD(sfp_dma)); | |
2692 | mcp->mb[7] = LSW(MSD(sfp_dma)); | |
2693 | mcp->mb[8] = count; | |
2694 | mcp->mb[9] = off; | |
2695 | mcp->mb[10] = 0; | |
2696 | mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
2697 | mcp->in_mb = MBX_0; | |
b93480e3 | 2698 | mcp->tov = MBX_TOV_SECONDS; |
88729e53 | 2699 | mcp->flags = 0; |
7b867cf7 | 2700 | rval = qla2x00_mailbox_command(vha, mcp); |
88729e53 AV |
2701 | |
2702 | if (rval != QLA_SUCCESS) { | |
2703 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, | |
7b867cf7 | 2704 | vha->host_no, rval, mcp->mb[0])); |
88729e53 | 2705 | } else { |
7b867cf7 | 2706 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
88729e53 AV |
2707 | } |
2708 | ||
2709 | return rval; | |
2710 | } | |
d8b45213 | 2711 | |
d8b45213 | 2712 | int |
7b867cf7 | 2713 | qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id, |
d8b45213 AV |
2714 | uint16_t port_speed, uint16_t *mb) |
2715 | { | |
2716 | int rval; | |
2717 | mbx_cmd_t mc; | |
2718 | mbx_cmd_t *mcp = &mc; | |
2719 | ||
7b867cf7 | 2720 | if (!IS_IIDMA_CAPABLE(vha->hw)) |
d8b45213 AV |
2721 | return QLA_FUNCTION_FAILED; |
2722 | ||
7b867cf7 | 2723 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
d8b45213 AV |
2724 | |
2725 | mcp->mb[0] = MBC_PORT_PARAMS; | |
2726 | mcp->mb[1] = loop_id; | |
2727 | mcp->mb[2] = BIT_0; | |
1bb39548 HZ |
2728 | if (IS_QLA81XX(vha->hw)) |
2729 | mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0); | |
2730 | else | |
2731 | mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0); | |
2732 | mcp->mb[9] = vha->vp_idx; | |
2733 | mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0; | |
2734 | mcp->in_mb = MBX_3|MBX_1|MBX_0; | |
b93480e3 | 2735 | mcp->tov = MBX_TOV_SECONDS; |
d8b45213 | 2736 | mcp->flags = 0; |
7b867cf7 | 2737 | rval = qla2x00_mailbox_command(vha, mcp); |
d8b45213 AV |
2738 | |
2739 | /* Return mailbox statuses. */ | |
2740 | if (mb != NULL) { | |
2741 | mb[0] = mcp->mb[0]; | |
2742 | mb[1] = mcp->mb[1]; | |
2743 | mb[3] = mcp->mb[3]; | |
d8b45213 AV |
2744 | } |
2745 | ||
2746 | if (rval != QLA_SUCCESS) { | |
2747 | DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 2748 | vha->host_no, rval)); |
d8b45213 | 2749 | } else { |
7b867cf7 | 2750 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
d8b45213 AV |
2751 | } |
2752 | ||
2753 | return rval; | |
2754 | } | |
2c3dfe3f | 2755 | |
2c3dfe3f | 2756 | void |
7b867cf7 | 2757 | qla24xx_report_id_acquisition(scsi_qla_host_t *vha, |
2c3dfe3f SJ |
2758 | struct vp_rpt_id_entry_24xx *rptid_entry) |
2759 | { | |
2760 | uint8_t vp_idx; | |
c6852c4c | 2761 | uint16_t stat = le16_to_cpu(rptid_entry->vp_idx); |
7b867cf7 AC |
2762 | struct qla_hw_data *ha = vha->hw; |
2763 | scsi_qla_host_t *vp; | |
ee546b6e | 2764 | scsi_qla_host_t *tvp; |
2c3dfe3f SJ |
2765 | |
2766 | if (rptid_entry->entry_status != 0) | |
2767 | return; | |
2c3dfe3f SJ |
2768 | |
2769 | if (rptid_entry->format == 0) { | |
2770 | DEBUG15(printk("%s:format 0 : scsi(%ld) number of VPs setup %d," | |
7b867cf7 | 2771 | " number of VPs acquired %d\n", __func__, vha->host_no, |
09ccbcc6 AV |
2772 | MSB(le16_to_cpu(rptid_entry->vp_count)), |
2773 | LSB(le16_to_cpu(rptid_entry->vp_count)))); | |
2c3dfe3f SJ |
2774 | DEBUG15(printk("%s primary port id %02x%02x%02x\n", __func__, |
2775 | rptid_entry->port_id[2], rptid_entry->port_id[1], | |
2776 | rptid_entry->port_id[0])); | |
2777 | } else if (rptid_entry->format == 1) { | |
c6852c4c | 2778 | vp_idx = LSB(stat); |
2c3dfe3f SJ |
2779 | DEBUG15(printk("%s:format 1: scsi(%ld): VP[%d] enabled " |
2780 | "- status %d - " | |
7b867cf7 | 2781 | "with port id %02x%02x%02x\n", __func__, vha->host_no, |
c6852c4c | 2782 | vp_idx, MSB(stat), |
2c3dfe3f SJ |
2783 | rptid_entry->port_id[2], rptid_entry->port_id[1], |
2784 | rptid_entry->port_id[0])); | |
531a82d1 AV |
2785 | |
2786 | vp = vha; | |
2787 | if (vp_idx == 0 && (MSB(stat) != 1)) | |
2788 | goto reg_needed; | |
2c3dfe3f | 2789 | |
81eb9b49 AV |
2790 | if (MSB(stat) == 1) { |
2791 | DEBUG2(printk("scsi(%ld): Could not acquire ID for " | |
2792 | "VP[%d].\n", vha->host_no, vp_idx)); | |
2c3dfe3f | 2793 | return; |
81eb9b49 | 2794 | } |
2c3dfe3f | 2795 | |
ee546b6e | 2796 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) |
7b867cf7 | 2797 | if (vp_idx == vp->vp_idx) |
2c3dfe3f | 2798 | break; |
7b867cf7 | 2799 | if (!vp) |
2c3dfe3f SJ |
2800 | return; |
2801 | ||
7b867cf7 AC |
2802 | vp->d_id.b.domain = rptid_entry->port_id[2]; |
2803 | vp->d_id.b.area = rptid_entry->port_id[1]; | |
2804 | vp->d_id.b.al_pa = rptid_entry->port_id[0]; | |
2c3dfe3f SJ |
2805 | |
2806 | /* | |
2807 | * Cannot configure here as we are still sitting on the | |
2808 | * response queue. Handle it in dpc context. | |
2809 | */ | |
7b867cf7 | 2810 | set_bit(VP_IDX_ACQUIRED, &vp->vp_flags); |
2c3dfe3f | 2811 | |
531a82d1 AV |
2812 | reg_needed: |
2813 | set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags); | |
2814 | set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags); | |
2815 | set_bit(VP_DPC_NEEDED, &vha->dpc_flags); | |
7b867cf7 | 2816 | qla2xxx_wake_dpc(vha); |
2c3dfe3f SJ |
2817 | } |
2818 | } | |
2819 | ||
2820 | /* | |
2821 | * qla24xx_modify_vp_config | |
2822 | * Change VP configuration for vha | |
2823 | * | |
2824 | * Input: | |
2825 | * vha = adapter block pointer. | |
2826 | * | |
2827 | * Returns: | |
2828 | * qla2xxx local function return status code. | |
2829 | * | |
2830 | * Context: | |
2831 | * Kernel context. | |
2832 | */ | |
2833 | int | |
2834 | qla24xx_modify_vp_config(scsi_qla_host_t *vha) | |
2835 | { | |
2836 | int rval; | |
2837 | struct vp_config_entry_24xx *vpmod; | |
2838 | dma_addr_t vpmod_dma; | |
7b867cf7 AC |
2839 | struct qla_hw_data *ha = vha->hw; |
2840 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); | |
2c3dfe3f SJ |
2841 | |
2842 | /* This can be called by the parent */ | |
2c3dfe3f | 2843 | |
7b867cf7 | 2844 | vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma); |
2c3dfe3f SJ |
2845 | if (!vpmod) { |
2846 | DEBUG2_3(printk("%s(%ld): failed to allocate Modify VP " | |
7b867cf7 | 2847 | "IOCB.\n", __func__, vha->host_no)); |
2c3dfe3f SJ |
2848 | return QLA_MEMORY_ALLOC_FAILED; |
2849 | } | |
2850 | ||
2851 | memset(vpmod, 0, sizeof(struct vp_config_entry_24xx)); | |
2852 | vpmod->entry_type = VP_CONFIG_IOCB_TYPE; | |
2853 | vpmod->entry_count = 1; | |
2854 | vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS; | |
2855 | vpmod->vp_count = 1; | |
2856 | vpmod->vp_index1 = vha->vp_idx; | |
2857 | vpmod->options_idx1 = BIT_3|BIT_4|BIT_5; | |
2858 | memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE); | |
2859 | memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE); | |
2860 | vpmod->entry_count = 1; | |
2861 | ||
7b867cf7 | 2862 | rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0); |
2c3dfe3f SJ |
2863 | if (rval != QLA_SUCCESS) { |
2864 | DEBUG2_3_11(printk("%s(%ld): failed to issue VP config IOCB" | |
7b867cf7 | 2865 | "(%x).\n", __func__, base_vha->host_no, rval)); |
2c3dfe3f SJ |
2866 | } else if (vpmod->comp_status != 0) { |
2867 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2868 | "-- error status (%x).\n", __func__, base_vha->host_no, |
2c3dfe3f SJ |
2869 | vpmod->comp_status)); |
2870 | rval = QLA_FUNCTION_FAILED; | |
2871 | } else if (vpmod->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) { | |
2872 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2873 | "-- completion status (%x).\n", __func__, base_vha->host_no, |
2c3dfe3f SJ |
2874 | le16_to_cpu(vpmod->comp_status))); |
2875 | rval = QLA_FUNCTION_FAILED; | |
2876 | } else { | |
2877 | /* EMPTY */ | |
7b867cf7 AC |
2878 | DEBUG11(printk("%s(%ld): done.\n", __func__, |
2879 | base_vha->host_no)); | |
2c3dfe3f SJ |
2880 | fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING); |
2881 | } | |
7b867cf7 | 2882 | dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma); |
2c3dfe3f SJ |
2883 | |
2884 | return rval; | |
2885 | } | |
2886 | ||
2887 | /* | |
2888 | * qla24xx_control_vp | |
2889 | * Enable a virtual port for given host | |
2890 | * | |
2891 | * Input: | |
2892 | * ha = adapter block pointer. | |
2893 | * vhba = virtual adapter (unused) | |
2894 | * index = index number for enabled VP | |
2895 | * | |
2896 | * Returns: | |
2897 | * qla2xxx local function return status code. | |
2898 | * | |
2899 | * Context: | |
2900 | * Kernel context. | |
2901 | */ | |
2902 | int | |
2903 | qla24xx_control_vp(scsi_qla_host_t *vha, int cmd) | |
2904 | { | |
2905 | int rval; | |
2906 | int map, pos; | |
2907 | struct vp_ctrl_entry_24xx *vce; | |
2908 | dma_addr_t vce_dma; | |
7b867cf7 | 2909 | struct qla_hw_data *ha = vha->hw; |
2c3dfe3f | 2910 | int vp_index = vha->vp_idx; |
7b867cf7 | 2911 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
2c3dfe3f SJ |
2912 | |
2913 | DEBUG11(printk("%s(%ld): entered. Enabling index %d\n", __func__, | |
7b867cf7 | 2914 | vha->host_no, vp_index)); |
2c3dfe3f | 2915 | |
eb66dc60 | 2916 | if (vp_index == 0 || vp_index >= ha->max_npiv_vports) |
2c3dfe3f SJ |
2917 | return QLA_PARAMETER_ERROR; |
2918 | ||
2919 | vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma); | |
2920 | if (!vce) { | |
2921 | DEBUG2_3(printk("%s(%ld): " | |
2922 | "failed to allocate VP Control IOCB.\n", __func__, | |
7b867cf7 | 2923 | base_vha->host_no)); |
2c3dfe3f SJ |
2924 | return QLA_MEMORY_ALLOC_FAILED; |
2925 | } | |
2926 | memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx)); | |
2927 | ||
2928 | vce->entry_type = VP_CTRL_IOCB_TYPE; | |
2929 | vce->entry_count = 1; | |
2930 | vce->command = cpu_to_le16(cmd); | |
2931 | vce->vp_count = __constant_cpu_to_le16(1); | |
2932 | ||
2933 | /* index map in firmware starts with 1; decrement index | |
2934 | * this is ok as we never use index 0 | |
2935 | */ | |
2936 | map = (vp_index - 1) / 8; | |
2937 | pos = (vp_index - 1) & 7; | |
6c2f527c | 2938 | mutex_lock(&ha->vport_lock); |
2c3dfe3f | 2939 | vce->vp_idx_map[map] |= 1 << pos; |
6c2f527c | 2940 | mutex_unlock(&ha->vport_lock); |
2c3dfe3f | 2941 | |
7b867cf7 | 2942 | rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0); |
2c3dfe3f SJ |
2943 | if (rval != QLA_SUCCESS) { |
2944 | DEBUG2_3_11(printk("%s(%ld): failed to issue VP control IOCB" | |
7b867cf7 | 2945 | "(%x).\n", __func__, base_vha->host_no, rval)); |
2c3dfe3f | 2946 | printk("%s(%ld): failed to issue VP control IOCB" |
7b867cf7 | 2947 | "(%x).\n", __func__, base_vha->host_no, rval); |
2c3dfe3f SJ |
2948 | } else if (vce->entry_status != 0) { |
2949 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2950 | "-- error status (%x).\n", __func__, base_vha->host_no, |
2c3dfe3f SJ |
2951 | vce->entry_status)); |
2952 | printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2953 | "-- error status (%x).\n", __func__, base_vha->host_no, |
2c3dfe3f SJ |
2954 | vce->entry_status); |
2955 | rval = QLA_FUNCTION_FAILED; | |
2956 | } else if (vce->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) { | |
2957 | DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2958 | "-- completion status (%x).\n", __func__, base_vha->host_no, |
2c3dfe3f SJ |
2959 | le16_to_cpu(vce->comp_status))); |
2960 | printk("%s(%ld): failed to complete IOCB " | |
7b867cf7 | 2961 | "-- completion status (%x).\n", __func__, base_vha->host_no, |
2c3dfe3f SJ |
2962 | le16_to_cpu(vce->comp_status)); |
2963 | rval = QLA_FUNCTION_FAILED; | |
2964 | } else { | |
7b867cf7 | 2965 | DEBUG2(printk("%s(%ld): done.\n", __func__, base_vha->host_no)); |
2c3dfe3f SJ |
2966 | } |
2967 | ||
2968 | dma_pool_free(ha->s_dma_pool, vce, vce_dma); | |
2969 | ||
2970 | return rval; | |
2971 | } | |
2972 | ||
2973 | /* | |
2974 | * qla2x00_send_change_request | |
2975 | * Receive or disable RSCN request from fabric controller | |
2976 | * | |
2977 | * Input: | |
2978 | * ha = adapter block pointer | |
2979 | * format = registration format: | |
2980 | * 0 - Reserved | |
2981 | * 1 - Fabric detected registration | |
2982 | * 2 - N_port detected registration | |
2983 | * 3 - Full registration | |
2984 | * FF - clear registration | |
2985 | * vp_idx = Virtual port index | |
2986 | * | |
2987 | * Returns: | |
2988 | * qla2x00 local function return status code. | |
2989 | * | |
2990 | * Context: | |
2991 | * Kernel Context | |
2992 | */ | |
2993 | ||
2994 | int | |
7b867cf7 | 2995 | qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format, |
2c3dfe3f SJ |
2996 | uint16_t vp_idx) |
2997 | { | |
2998 | int rval; | |
2999 | mbx_cmd_t mc; | |
3000 | mbx_cmd_t *mcp = &mc; | |
3001 | ||
3002 | /* | |
3003 | * This command is implicitly executed by firmware during login for the | |
3004 | * physical hosts | |
3005 | */ | |
3006 | if (vp_idx == 0) | |
3007 | return QLA_FUNCTION_FAILED; | |
3008 | ||
3009 | mcp->mb[0] = MBC_SEND_CHANGE_REQUEST; | |
3010 | mcp->mb[1] = format; | |
3011 | mcp->mb[9] = vp_idx; | |
3012 | mcp->out_mb = MBX_9|MBX_1|MBX_0; | |
3013 | mcp->in_mb = MBX_0|MBX_1; | |
3014 | mcp->tov = MBX_TOV_SECONDS; | |
3015 | mcp->flags = 0; | |
7b867cf7 | 3016 | rval = qla2x00_mailbox_command(vha, mcp); |
2c3dfe3f SJ |
3017 | |
3018 | if (rval == QLA_SUCCESS) { | |
3019 | if (mcp->mb[0] != MBS_COMMAND_COMPLETE) { | |
3020 | rval = BIT_1; | |
3021 | } | |
3022 | } else | |
3023 | rval = BIT_1; | |
3024 | ||
3025 | return rval; | |
3026 | } | |
338c9161 AV |
3027 | |
3028 | int | |
7b867cf7 | 3029 | qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr, |
338c9161 AV |
3030 | uint32_t size) |
3031 | { | |
3032 | int rval; | |
3033 | mbx_cmd_t mc; | |
3034 | mbx_cmd_t *mcp = &mc; | |
3035 | ||
7b867cf7 | 3036 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
338c9161 | 3037 | |
7b867cf7 | 3038 | if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) { |
338c9161 AV |
3039 | mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED; |
3040 | mcp->mb[8] = MSW(addr); | |
3041 | mcp->out_mb = MBX_8|MBX_0; | |
3042 | } else { | |
3043 | mcp->mb[0] = MBC_DUMP_RISC_RAM; | |
3044 | mcp->out_mb = MBX_0; | |
3045 | } | |
3046 | mcp->mb[1] = LSW(addr); | |
3047 | mcp->mb[2] = MSW(req_dma); | |
3048 | mcp->mb[3] = LSW(req_dma); | |
3049 | mcp->mb[6] = MSW(MSD(req_dma)); | |
3050 | mcp->mb[7] = LSW(MSD(req_dma)); | |
3051 | mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1; | |
7b867cf7 | 3052 | if (IS_FWI2_CAPABLE(vha->hw)) { |
338c9161 AV |
3053 | mcp->mb[4] = MSW(size); |
3054 | mcp->mb[5] = LSW(size); | |
3055 | mcp->out_mb |= MBX_5|MBX_4; | |
3056 | } else { | |
3057 | mcp->mb[4] = LSW(size); | |
3058 | mcp->out_mb |= MBX_4; | |
3059 | } | |
3060 | ||
3061 | mcp->in_mb = MBX_0; | |
b93480e3 | 3062 | mcp->tov = MBX_TOV_SECONDS; |
338c9161 | 3063 | mcp->flags = 0; |
7b867cf7 | 3064 | rval = qla2x00_mailbox_command(vha, mcp); |
338c9161 AV |
3065 | |
3066 | if (rval != QLA_SUCCESS) { | |
3067 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, | |
7b867cf7 | 3068 | vha->host_no, rval, mcp->mb[0])); |
338c9161 | 3069 | } else { |
7b867cf7 | 3070 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
338c9161 AV |
3071 | } |
3072 | ||
3073 | return rval; | |
3074 | } | |
4d4df193 HK |
3075 | |
3076 | /* 84XX Support **************************************************************/ | |
3077 | ||
3078 | struct cs84xx_mgmt_cmd { | |
3079 | union { | |
3080 | struct verify_chip_entry_84xx req; | |
3081 | struct verify_chip_rsp_84xx rsp; | |
3082 | } p; | |
3083 | }; | |
3084 | ||
3085 | int | |
7b867cf7 | 3086 | qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status) |
4d4df193 HK |
3087 | { |
3088 | int rval, retry; | |
3089 | struct cs84xx_mgmt_cmd *mn; | |
3090 | dma_addr_t mn_dma; | |
3091 | uint16_t options; | |
3092 | unsigned long flags; | |
7b867cf7 | 3093 | struct qla_hw_data *ha = vha->hw; |
4d4df193 | 3094 | |
7b867cf7 | 3095 | DEBUG16(printk("%s(%ld): entered.\n", __func__, vha->host_no)); |
4d4df193 HK |
3096 | |
3097 | mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma); | |
3098 | if (mn == NULL) { | |
3099 | DEBUG2_3(printk("%s(%ld): failed to allocate Verify ISP84XX " | |
7b867cf7 | 3100 | "IOCB.\n", __func__, vha->host_no)); |
4d4df193 HK |
3101 | return QLA_MEMORY_ALLOC_FAILED; |
3102 | } | |
3103 | ||
3104 | /* Force Update? */ | |
3105 | options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0; | |
3106 | /* Diagnostic firmware? */ | |
3107 | /* options |= MENLO_DIAG_FW; */ | |
3108 | /* We update the firmware with only one data sequence. */ | |
3109 | options |= VCO_END_OF_DATA; | |
3110 | ||
4d4df193 | 3111 | do { |
c1ec1f1b | 3112 | retry = 0; |
4d4df193 HK |
3113 | memset(mn, 0, sizeof(*mn)); |
3114 | mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE; | |
3115 | mn->p.req.entry_count = 1; | |
3116 | mn->p.req.options = cpu_to_le16(options); | |
3117 | ||
3118 | DEBUG16(printk("%s(%ld): Dump of Verify Request.\n", __func__, | |
7b867cf7 | 3119 | vha->host_no)); |
4d4df193 HK |
3120 | DEBUG16(qla2x00_dump_buffer((uint8_t *)mn, |
3121 | sizeof(*mn))); | |
3122 | ||
7b867cf7 | 3123 | rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120); |
4d4df193 HK |
3124 | if (rval != QLA_SUCCESS) { |
3125 | DEBUG2_16(printk("%s(%ld): failed to issue Verify " | |
7b867cf7 | 3126 | "IOCB (%x).\n", __func__, vha->host_no, rval)); |
4d4df193 HK |
3127 | goto verify_done; |
3128 | } | |
3129 | ||
3130 | DEBUG16(printk("%s(%ld): Dump of Verify Response.\n", __func__, | |
7b867cf7 | 3131 | vha->host_no)); |
4d4df193 HK |
3132 | DEBUG16(qla2x00_dump_buffer((uint8_t *)mn, |
3133 | sizeof(*mn))); | |
3134 | ||
3135 | status[0] = le16_to_cpu(mn->p.rsp.comp_status); | |
3136 | status[1] = status[0] == CS_VCS_CHIP_FAILURE ? | |
3137 | le16_to_cpu(mn->p.rsp.failure_code) : 0; | |
3138 | DEBUG2_16(printk("%s(%ld): cs=%x fc=%x\n", __func__, | |
7b867cf7 | 3139 | vha->host_no, status[0], status[1])); |
4d4df193 HK |
3140 | |
3141 | if (status[0] != CS_COMPLETE) { | |
3142 | rval = QLA_FUNCTION_FAILED; | |
3143 | if (!(options & VCO_DONT_UPDATE_FW)) { | |
3144 | DEBUG2_16(printk("%s(%ld): Firmware update " | |
3145 | "failed. Retrying without update " | |
7b867cf7 | 3146 | "firmware.\n", __func__, vha->host_no)); |
4d4df193 HK |
3147 | options |= VCO_DONT_UPDATE_FW; |
3148 | options &= ~VCO_FORCE_UPDATE; | |
3149 | retry = 1; | |
3150 | } | |
3151 | } else { | |
3152 | DEBUG2_16(printk("%s(%ld): firmware updated to %x.\n", | |
7b867cf7 | 3153 | __func__, vha->host_no, |
4d4df193 HK |
3154 | le32_to_cpu(mn->p.rsp.fw_ver))); |
3155 | ||
3156 | /* NOTE: we only update OP firmware. */ | |
3157 | spin_lock_irqsave(&ha->cs84xx->access_lock, flags); | |
3158 | ha->cs84xx->op_fw_version = | |
3159 | le32_to_cpu(mn->p.rsp.fw_ver); | |
3160 | spin_unlock_irqrestore(&ha->cs84xx->access_lock, | |
3161 | flags); | |
3162 | } | |
3163 | } while (retry); | |
3164 | ||
3165 | verify_done: | |
3166 | dma_pool_free(ha->s_dma_pool, mn, mn_dma); | |
3167 | ||
3168 | if (rval != QLA_SUCCESS) { | |
3169 | DEBUG2_16(printk("%s(%ld): failed=%x.\n", __func__, | |
7b867cf7 | 3170 | vha->host_no, rval)); |
4d4df193 | 3171 | } else { |
7b867cf7 | 3172 | DEBUG16(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
4d4df193 HK |
3173 | } |
3174 | ||
3175 | return rval; | |
3176 | } | |
73208dfd AC |
3177 | |
3178 | int | |
618a7523 | 3179 | qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req) |
73208dfd AC |
3180 | { |
3181 | int rval; | |
3182 | unsigned long flags; | |
3183 | mbx_cmd_t mc; | |
3184 | mbx_cmd_t *mcp = &mc; | |
3185 | struct device_reg_25xxmq __iomem *reg; | |
3186 | struct qla_hw_data *ha = vha->hw; | |
3187 | ||
3188 | mcp->mb[0] = MBC_INITIALIZE_MULTIQ; | |
618a7523 | 3189 | mcp->mb[1] = req->options; |
73208dfd AC |
3190 | mcp->mb[2] = MSW(LSD(req->dma)); |
3191 | mcp->mb[3] = LSW(LSD(req->dma)); | |
3192 | mcp->mb[6] = MSW(MSD(req->dma)); | |
3193 | mcp->mb[7] = LSW(MSD(req->dma)); | |
3194 | mcp->mb[5] = req->length; | |
3195 | if (req->rsp) | |
3196 | mcp->mb[10] = req->rsp->id; | |
3197 | mcp->mb[12] = req->qos; | |
3198 | mcp->mb[11] = req->vp_idx; | |
3199 | mcp->mb[13] = req->rid; | |
3200 | ||
3201 | reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) + | |
3202 | QLA_QUE_PAGE * req->id); | |
3203 | ||
3204 | mcp->mb[4] = req->id; | |
3205 | /* que in ptr index */ | |
3206 | mcp->mb[8] = 0; | |
3207 | /* que out ptr index */ | |
3208 | mcp->mb[9] = 0; | |
3209 | mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7| | |
3210 | MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
3211 | mcp->in_mb = MBX_0; | |
3212 | mcp->flags = MBX_DMA_OUT; | |
3213 | mcp->tov = 60; | |
3214 | ||
3215 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
618a7523 | 3216 | if (!(req->options & BIT_0)) { |
73208dfd AC |
3217 | WRT_REG_DWORD(®->req_q_in, 0); |
3218 | WRT_REG_DWORD(®->req_q_out, 0); | |
3219 | } | |
2afa19a9 AC |
3220 | req->req_q_in = ®->req_q_in; |
3221 | req->req_q_out = ®->req_q_out; | |
73208dfd AC |
3222 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
3223 | ||
17d98630 | 3224 | rval = qla2x00_mailbox_command(vha, mcp); |
73208dfd AC |
3225 | if (rval != QLA_SUCCESS) |
3226 | DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x mb0=%x.\n", | |
3227 | __func__, vha->host_no, rval, mcp->mb[0])); | |
3228 | return rval; | |
3229 | } | |
3230 | ||
3231 | int | |
618a7523 | 3232 | qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp) |
73208dfd AC |
3233 | { |
3234 | int rval; | |
3235 | unsigned long flags; | |
3236 | mbx_cmd_t mc; | |
3237 | mbx_cmd_t *mcp = &mc; | |
3238 | struct device_reg_25xxmq __iomem *reg; | |
3239 | struct qla_hw_data *ha = vha->hw; | |
3240 | ||
3241 | mcp->mb[0] = MBC_INITIALIZE_MULTIQ; | |
618a7523 | 3242 | mcp->mb[1] = rsp->options; |
73208dfd AC |
3243 | mcp->mb[2] = MSW(LSD(rsp->dma)); |
3244 | mcp->mb[3] = LSW(LSD(rsp->dma)); | |
3245 | mcp->mb[6] = MSW(MSD(rsp->dma)); | |
3246 | mcp->mb[7] = LSW(MSD(rsp->dma)); | |
3247 | mcp->mb[5] = rsp->length; | |
444786d7 | 3248 | mcp->mb[14] = rsp->msix->entry; |
73208dfd AC |
3249 | mcp->mb[13] = rsp->rid; |
3250 | ||
3251 | reg = (struct device_reg_25xxmq *)((void *)(ha->mqiobase) + | |
3252 | QLA_QUE_PAGE * rsp->id); | |
3253 | ||
3254 | mcp->mb[4] = rsp->id; | |
3255 | /* que in ptr index */ | |
3256 | mcp->mb[8] = 0; | |
3257 | /* que out ptr index */ | |
3258 | mcp->mb[9] = 0; | |
2afa19a9 | 3259 | mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7 |
73208dfd AC |
3260 | |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; |
3261 | mcp->in_mb = MBX_0; | |
3262 | mcp->flags = MBX_DMA_OUT; | |
3263 | mcp->tov = 60; | |
3264 | ||
3265 | spin_lock_irqsave(&ha->hardware_lock, flags); | |
618a7523 | 3266 | if (!(rsp->options & BIT_0)) { |
73208dfd AC |
3267 | WRT_REG_DWORD(®->rsp_q_out, 0); |
3268 | WRT_REG_DWORD(®->rsp_q_in, 0); | |
3269 | } | |
3270 | ||
3271 | spin_unlock_irqrestore(&ha->hardware_lock, flags); | |
3272 | ||
17d98630 | 3273 | rval = qla2x00_mailbox_command(vha, mcp); |
73208dfd AC |
3274 | if (rval != QLA_SUCCESS) |
3275 | DEBUG2_3_11(printk(KERN_WARNING "%s(%ld): failed=%x " | |
3276 | "mb0=%x.\n", __func__, | |
3277 | vha->host_no, rval, mcp->mb[0])); | |
3278 | return rval; | |
3279 | } | |
3280 | ||
8a659571 AV |
3281 | int |
3282 | qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb) | |
3283 | { | |
3284 | int rval; | |
3285 | mbx_cmd_t mc; | |
3286 | mbx_cmd_t *mcp = &mc; | |
3287 | ||
3288 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3289 | ||
3290 | mcp->mb[0] = MBC_IDC_ACK; | |
3291 | memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t)); | |
3292 | mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
3293 | mcp->in_mb = MBX_0; | |
3294 | mcp->tov = MBX_TOV_SECONDS; | |
3295 | mcp->flags = 0; | |
3296 | rval = qla2x00_mailbox_command(vha, mcp); | |
3297 | ||
3298 | if (rval != QLA_SUCCESS) { | |
3299 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, | |
3300 | vha->host_no, rval, mcp->mb[0])); | |
3301 | } else { | |
3302 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3303 | } | |
3304 | ||
3305 | return rval; | |
3306 | } | |
1d2874de JC |
3307 | |
3308 | int | |
3309 | qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size) | |
3310 | { | |
3311 | int rval; | |
3312 | mbx_cmd_t mc; | |
3313 | mbx_cmd_t *mcp = &mc; | |
3314 | ||
3315 | if (!IS_QLA81XX(vha->hw)) | |
3316 | return QLA_FUNCTION_FAILED; | |
3317 | ||
3318 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3319 | ||
3320 | mcp->mb[0] = MBC_FLASH_ACCESS_CTRL; | |
3321 | mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE; | |
3322 | mcp->out_mb = MBX_1|MBX_0; | |
3323 | mcp->in_mb = MBX_1|MBX_0; | |
3324 | mcp->tov = MBX_TOV_SECONDS; | |
3325 | mcp->flags = 0; | |
3326 | rval = qla2x00_mailbox_command(vha, mcp); | |
3327 | ||
3328 | if (rval != QLA_SUCCESS) { | |
3329 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", | |
3330 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); | |
3331 | } else { | |
3332 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3333 | *sector_size = mcp->mb[1]; | |
3334 | } | |
3335 | ||
3336 | return rval; | |
3337 | } | |
3338 | ||
3339 | int | |
3340 | qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable) | |
3341 | { | |
3342 | int rval; | |
3343 | mbx_cmd_t mc; | |
3344 | mbx_cmd_t *mcp = &mc; | |
3345 | ||
3346 | if (!IS_QLA81XX(vha->hw)) | |
3347 | return QLA_FUNCTION_FAILED; | |
3348 | ||
3349 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3350 | ||
3351 | mcp->mb[0] = MBC_FLASH_ACCESS_CTRL; | |
3352 | mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE : | |
3353 | FAC_OPT_CMD_WRITE_PROTECT; | |
3354 | mcp->out_mb = MBX_1|MBX_0; | |
3355 | mcp->in_mb = MBX_1|MBX_0; | |
3356 | mcp->tov = MBX_TOV_SECONDS; | |
3357 | mcp->flags = 0; | |
3358 | rval = qla2x00_mailbox_command(vha, mcp); | |
3359 | ||
3360 | if (rval != QLA_SUCCESS) { | |
3361 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n", | |
3362 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); | |
3363 | } else { | |
3364 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3365 | } | |
3366 | ||
3367 | return rval; | |
3368 | } | |
3369 | ||
3370 | int | |
3371 | qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish) | |
3372 | { | |
3373 | int rval; | |
3374 | mbx_cmd_t mc; | |
3375 | mbx_cmd_t *mcp = &mc; | |
3376 | ||
3377 | if (!IS_QLA81XX(vha->hw)) | |
3378 | return QLA_FUNCTION_FAILED; | |
3379 | ||
3380 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3381 | ||
3382 | mcp->mb[0] = MBC_FLASH_ACCESS_CTRL; | |
3383 | mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR; | |
3384 | mcp->mb[2] = LSW(start); | |
3385 | mcp->mb[3] = MSW(start); | |
3386 | mcp->mb[4] = LSW(finish); | |
3387 | mcp->mb[5] = MSW(finish); | |
3388 | mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0; | |
3389 | mcp->in_mb = MBX_2|MBX_1|MBX_0; | |
3390 | mcp->tov = MBX_TOV_SECONDS; | |
3391 | mcp->flags = 0; | |
3392 | rval = qla2x00_mailbox_command(vha, mcp); | |
3393 | ||
3394 | if (rval != QLA_SUCCESS) { | |
3395 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x " | |
3396 | "mb[2]=%x.\n", __func__, vha->host_no, rval, mcp->mb[0], | |
3397 | mcp->mb[1], mcp->mb[2])); | |
3398 | } else { | |
3399 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3400 | } | |
3401 | ||
3402 | return rval; | |
3403 | } | |
6e181be5 LC |
3404 | |
3405 | int | |
3406 | qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha) | |
3407 | { | |
3408 | int rval = 0; | |
3409 | mbx_cmd_t mc; | |
3410 | mbx_cmd_t *mcp = &mc; | |
3411 | ||
3412 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3413 | ||
3414 | mcp->mb[0] = MBC_RESTART_MPI_FW; | |
3415 | mcp->out_mb = MBX_0; | |
3416 | mcp->in_mb = MBX_0|MBX_1; | |
3417 | mcp->tov = MBX_TOV_SECONDS; | |
3418 | mcp->flags = 0; | |
3419 | rval = qla2x00_mailbox_command(vha, mcp); | |
3420 | ||
3421 | if (rval != QLA_SUCCESS) { | |
3422 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x mb[1]=0x%x.\n", | |
3423 | __func__, vha->host_no, rval, mcp->mb[0], mcp->mb[1])); | |
3424 | } else { | |
3425 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3426 | } | |
3427 | ||
3428 | return rval; | |
3429 | } | |
ad0ecd61 JC |
3430 | |
3431 | int | |
3432 | qla2x00_read_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr, | |
3433 | dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt) | |
3434 | { | |
3435 | int rval; | |
3436 | mbx_cmd_t mc; | |
3437 | mbx_cmd_t *mcp = &mc; | |
3438 | ||
3439 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3440 | ||
3441 | mcp->mb[0] = MBC_READ_SFP; | |
3442 | mcp->mb[1] = dev; | |
3443 | mcp->mb[2] = MSW(sfp_dma); | |
3444 | mcp->mb[3] = LSW(sfp_dma); | |
3445 | mcp->mb[6] = MSW(MSD(sfp_dma)); | |
3446 | mcp->mb[7] = LSW(MSD(sfp_dma)); | |
3447 | mcp->mb[8] = len; | |
3448 | mcp->mb[9] = adr; | |
3449 | mcp->mb[10] = opt; | |
3450 | mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
3451 | mcp->in_mb = MBX_0; | |
3452 | mcp->tov = MBX_TOV_SECONDS; | |
3453 | mcp->flags = 0; | |
3454 | rval = qla2x00_mailbox_command(vha, mcp); | |
3455 | ||
3456 | if (opt & BIT_0) | |
3457 | if (sfp) | |
3458 | *sfp = mcp->mb[8]; | |
3459 | ||
3460 | if (rval != QLA_SUCCESS) { | |
3461 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, | |
3462 | vha->host_no, rval, mcp->mb[0])); | |
3463 | } else { | |
7640335e | 3464 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); |
ad0ecd61 JC |
3465 | } |
3466 | ||
3467 | return rval; | |
3468 | } | |
3469 | ||
3470 | int | |
3471 | qla2x00_write_edc(scsi_qla_host_t *vha, uint16_t dev, uint16_t adr, | |
3472 | dma_addr_t sfp_dma, uint8_t *sfp, uint16_t len, uint16_t opt) | |
3473 | { | |
3474 | int rval; | |
3475 | mbx_cmd_t mc; | |
3476 | mbx_cmd_t *mcp = &mc; | |
3477 | ||
3478 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3479 | ||
3480 | if (opt & BIT_0) | |
3481 | if (sfp) | |
3482 | len = *sfp; | |
3483 | ||
3484 | mcp->mb[0] = MBC_WRITE_SFP; | |
3485 | mcp->mb[1] = dev; | |
3486 | mcp->mb[2] = MSW(sfp_dma); | |
3487 | mcp->mb[3] = LSW(sfp_dma); | |
3488 | mcp->mb[6] = MSW(MSD(sfp_dma)); | |
3489 | mcp->mb[7] = LSW(MSD(sfp_dma)); | |
3490 | mcp->mb[8] = len; | |
3491 | mcp->mb[9] = adr; | |
3492 | mcp->mb[10] = opt; | |
3493 | mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
3494 | mcp->in_mb = MBX_0; | |
3495 | mcp->tov = MBX_TOV_SECONDS; | |
3496 | mcp->flags = 0; | |
3497 | rval = qla2x00_mailbox_command(vha, mcp); | |
3498 | ||
3499 | if (rval != QLA_SUCCESS) { | |
3500 | DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__, | |
3501 | vha->host_no, rval, mcp->mb[0])); | |
3502 | } else { | |
3503 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3504 | } | |
3505 | ||
3506 | return rval; | |
3507 | } | |
ce0423f4 AV |
3508 | |
3509 | int | |
3510 | qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma, | |
3511 | uint16_t size_in_bytes, uint16_t *actual_size) | |
3512 | { | |
3513 | int rval; | |
3514 | mbx_cmd_t mc; | |
3515 | mbx_cmd_t *mcp = &mc; | |
3516 | ||
3517 | if (!IS_QLA81XX(vha->hw)) | |
3518 | return QLA_FUNCTION_FAILED; | |
3519 | ||
3520 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3521 | ||
3522 | mcp->mb[0] = MBC_GET_XGMAC_STATS; | |
3523 | mcp->mb[2] = MSW(stats_dma); | |
3524 | mcp->mb[3] = LSW(stats_dma); | |
3525 | mcp->mb[6] = MSW(MSD(stats_dma)); | |
3526 | mcp->mb[7] = LSW(MSD(stats_dma)); | |
3527 | mcp->mb[8] = size_in_bytes >> 2; | |
3528 | mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0; | |
3529 | mcp->in_mb = MBX_2|MBX_1|MBX_0; | |
3530 | mcp->tov = MBX_TOV_SECONDS; | |
3531 | mcp->flags = 0; | |
3532 | rval = qla2x00_mailbox_command(vha, mcp); | |
3533 | ||
3534 | if (rval != QLA_SUCCESS) { | |
3535 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x " | |
3536 | "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval, | |
3537 | mcp->mb[0], mcp->mb[1], mcp->mb[2])); | |
3538 | } else { | |
3539 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3540 | ||
3541 | *actual_size = mcp->mb[2] << 2; | |
3542 | } | |
3543 | ||
3544 | return rval; | |
3545 | } | |
11bbc1d8 AV |
3546 | |
3547 | int | |
3548 | qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma, | |
3549 | uint16_t size) | |
3550 | { | |
3551 | int rval; | |
3552 | mbx_cmd_t mc; | |
3553 | mbx_cmd_t *mcp = &mc; | |
3554 | ||
3555 | if (!IS_QLA81XX(vha->hw)) | |
3556 | return QLA_FUNCTION_FAILED; | |
3557 | ||
3558 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3559 | ||
3560 | mcp->mb[0] = MBC_GET_DCBX_PARAMS; | |
3561 | mcp->mb[1] = 0; | |
3562 | mcp->mb[2] = MSW(tlv_dma); | |
3563 | mcp->mb[3] = LSW(tlv_dma); | |
3564 | mcp->mb[6] = MSW(MSD(tlv_dma)); | |
3565 | mcp->mb[7] = LSW(MSD(tlv_dma)); | |
3566 | mcp->mb[8] = size; | |
3567 | mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0; | |
3568 | mcp->in_mb = MBX_2|MBX_1|MBX_0; | |
3569 | mcp->tov = MBX_TOV_SECONDS; | |
3570 | mcp->flags = 0; | |
3571 | rval = qla2x00_mailbox_command(vha, mcp); | |
3572 | ||
3573 | if (rval != QLA_SUCCESS) { | |
3574 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=0x%x " | |
3575 | "mb[1]=0x%x mb[2]=0x%x.\n", __func__, vha->host_no, rval, | |
3576 | mcp->mb[0], mcp->mb[1], mcp->mb[2])); | |
3577 | } else { | |
3578 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3579 | } | |
3580 | ||
3581 | return rval; | |
3582 | } | |
18e7555a AV |
3583 | |
3584 | int | |
3585 | qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data) | |
3586 | { | |
3587 | int rval; | |
3588 | mbx_cmd_t mc; | |
3589 | mbx_cmd_t *mcp = &mc; | |
3590 | ||
3591 | if (!IS_FWI2_CAPABLE(vha->hw)) | |
3592 | return QLA_FUNCTION_FAILED; | |
3593 | ||
3594 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3595 | ||
3596 | mcp->mb[0] = MBC_READ_RAM_EXTENDED; | |
3597 | mcp->mb[1] = LSW(risc_addr); | |
3598 | mcp->mb[8] = MSW(risc_addr); | |
3599 | mcp->out_mb = MBX_8|MBX_1|MBX_0; | |
3600 | mcp->in_mb = MBX_3|MBX_2|MBX_0; | |
3601 | mcp->tov = 30; | |
3602 | mcp->flags = 0; | |
3603 | rval = qla2x00_mailbox_command(vha, mcp); | |
3604 | if (rval != QLA_SUCCESS) { | |
3605 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, | |
3606 | vha->host_no, rval, mcp->mb[0])); | |
3607 | } else { | |
3608 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3609 | *data = mcp->mb[3] << 16 | mcp->mb[2]; | |
3610 | } | |
3611 | ||
3612 | return rval; | |
3613 | } | |
3614 | ||
3615 | int | |
3616 | qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data) | |
3617 | { | |
3618 | int rval; | |
3619 | mbx_cmd_t mc; | |
3620 | mbx_cmd_t *mcp = &mc; | |
3621 | ||
3622 | if (!IS_FWI2_CAPABLE(vha->hw)) | |
3623 | return QLA_FUNCTION_FAILED; | |
3624 | ||
3625 | DEBUG11(printk("%s(%ld): entered.\n", __func__, vha->host_no)); | |
3626 | ||
3627 | mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED; | |
3628 | mcp->mb[1] = LSW(risc_addr); | |
3629 | mcp->mb[2] = LSW(data); | |
3630 | mcp->mb[3] = MSW(data); | |
3631 | mcp->mb[8] = MSW(risc_addr); | |
3632 | mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0; | |
3633 | mcp->in_mb = MBX_0; | |
3634 | mcp->tov = 30; | |
3635 | mcp->flags = 0; | |
3636 | rval = qla2x00_mailbox_command(vha, mcp); | |
3637 | if (rval != QLA_SUCCESS) { | |
3638 | DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__, | |
3639 | vha->host_no, rval, mcp->mb[0])); | |
3640 | } else { | |
3641 | DEBUG11(printk("%s(%ld): done.\n", __func__, vha->host_no)); | |
3642 | } | |
3643 | ||
3644 | return rval; | |
3645 | } |