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