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