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