x86/mm/pat: Don't report PAT on CPUs that don't support it
[linux/fpc-iii.git] / drivers / scsi / qla2xxx / qla_mbx.c
blobcba1fc5e8be9d58fce789694b508734790689a83
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
8 #include "qla_target.h"
10 #include <linux/delay.h>
11 #include <linux/gfp.h>
13 static struct mb_cmd_name {
14 uint16_t cmd;
15 const char *str;
16 } mb_str[] = {
17 {MBC_GET_PORT_DATABASE, "GPDB"},
18 {MBC_GET_ID_LIST, "GIDList"},
19 {MBC_GET_LINK_PRIV_STATS, "Stats"},
22 static const char *mb_to_str(uint16_t cmd)
24 int i;
25 struct mb_cmd_name *e;
27 for (i = 0; i < ARRAY_SIZE(mb_str); i++) {
28 e = mb_str + i;
29 if (cmd == e->cmd)
30 return e->str;
32 return "unknown";
35 static struct rom_cmd {
36 uint16_t cmd;
37 } rom_cmds[] = {
38 { MBC_LOAD_RAM },
39 { MBC_EXECUTE_FIRMWARE },
40 { MBC_READ_RAM_WORD },
41 { MBC_MAILBOX_REGISTER_TEST },
42 { MBC_VERIFY_CHECKSUM },
43 { MBC_GET_FIRMWARE_VERSION },
44 { MBC_LOAD_RISC_RAM },
45 { MBC_DUMP_RISC_RAM },
46 { MBC_LOAD_RISC_RAM_EXTENDED },
47 { MBC_DUMP_RISC_RAM_EXTENDED },
48 { MBC_WRITE_RAM_WORD_EXTENDED },
49 { MBC_READ_RAM_EXTENDED },
50 { MBC_GET_RESOURCE_COUNTS },
51 { MBC_SET_FIRMWARE_OPTION },
52 { MBC_MID_INITIALIZE_FIRMWARE },
53 { MBC_GET_FIRMWARE_STATE },
54 { MBC_GET_MEM_OFFLOAD_CNTRL_STAT },
55 { MBC_GET_RETRY_COUNT },
56 { MBC_TRACE_CONTROL },
59 static int is_rom_cmd(uint16_t cmd)
61 int i;
62 struct rom_cmd *wc;
64 for (i = 0; i < ARRAY_SIZE(rom_cmds); i++) {
65 wc = rom_cmds + i;
66 if (wc->cmd == cmd)
67 return 1;
70 return 0;
74 * qla2x00_mailbox_command
75 * Issue mailbox command and waits for completion.
77 * Input:
78 * ha = adapter block pointer.
79 * mcp = driver internal mbx struct pointer.
81 * Output:
82 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
84 * Returns:
85 * 0 : QLA_SUCCESS = cmd performed success
86 * 1 : QLA_FUNCTION_FAILED (error encountered)
87 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
89 * Context:
90 * Kernel context.
92 static int
93 qla2x00_mailbox_command(scsi_qla_host_t *vha, mbx_cmd_t *mcp)
95 int rval, i;
96 unsigned long flags = 0;
97 device_reg_t *reg;
98 uint8_t abort_active;
99 uint8_t io_lock_on;
100 uint16_t command = 0;
101 uint16_t *iptr;
102 uint16_t __iomem *optr;
103 uint32_t cnt;
104 uint32_t mboxes;
105 uint16_t __iomem *mbx_reg;
106 unsigned long wait_time;
107 struct qla_hw_data *ha = vha->hw;
108 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
111 ql_dbg(ql_dbg_mbx, vha, 0x1000, "Entered %s.\n", __func__);
113 if (ha->pdev->error_state > pci_channel_io_frozen) {
114 ql_log(ql_log_warn, vha, 0x1001,
115 "error_state is greater than pci_channel_io_frozen, "
116 "exiting.\n");
117 return QLA_FUNCTION_TIMEOUT;
120 if (vha->device_flags & DFLG_DEV_FAILED) {
121 ql_log(ql_log_warn, vha, 0x1002,
122 "Device in failed state, exiting.\n");
123 return QLA_FUNCTION_TIMEOUT;
126 /* if PCI error, then avoid mbx processing.*/
127 if (test_bit(PCI_ERR, &base_vha->dpc_flags)) {
128 ql_log(ql_log_warn, vha, 0x1191,
129 "PCI error, exiting.\n");
130 return QLA_FUNCTION_TIMEOUT;
133 reg = ha->iobase;
134 io_lock_on = base_vha->flags.init_done;
136 rval = QLA_SUCCESS;
137 abort_active = test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
140 if (ha->flags.pci_channel_io_perm_failure) {
141 ql_log(ql_log_warn, vha, 0x1003,
142 "Perm failure on EEH timeout MBX, exiting.\n");
143 return QLA_FUNCTION_TIMEOUT;
146 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
147 /* Setting Link-Down error */
148 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
149 ql_log(ql_log_warn, vha, 0x1004,
150 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
151 return QLA_FUNCTION_TIMEOUT;
154 /* check if ISP abort is active and return cmd with timeout */
155 if ((test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
156 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
157 test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) &&
158 !is_rom_cmd(mcp->mb[0])) {
159 ql_log(ql_log_info, vha, 0x1005,
160 "Cmd 0x%x aborted with timeout since ISP Abort is pending\n",
161 mcp->mb[0]);
162 return QLA_FUNCTION_TIMEOUT;
166 * Wait for active mailbox commands to finish by waiting at most tov
167 * seconds. This is to serialize actual issuing of mailbox cmds during
168 * non ISP abort time.
170 if (!wait_for_completion_timeout(&ha->mbx_cmd_comp, mcp->tov * HZ)) {
171 /* Timeout occurred. Return error. */
172 ql_log(ql_log_warn, vha, 0x1005,
173 "Cmd access timeout, cmd=0x%x, Exiting.\n",
174 mcp->mb[0]);
175 return QLA_FUNCTION_TIMEOUT;
178 ha->flags.mbox_busy = 1;
179 /* Save mailbox command for debug */
180 ha->mcp = mcp;
182 ql_dbg(ql_dbg_mbx, vha, 0x1006,
183 "Prepare to issue mbox cmd=0x%x.\n", mcp->mb[0]);
185 spin_lock_irqsave(&ha->hardware_lock, flags);
187 /* Load mailbox registers. */
188 if (IS_P3P_TYPE(ha))
189 optr = (uint16_t __iomem *)&reg->isp82.mailbox_in[0];
190 else if (IS_FWI2_CAPABLE(ha) && !(IS_P3P_TYPE(ha)))
191 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
192 else
193 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
195 iptr = mcp->mb;
196 command = mcp->mb[0];
197 mboxes = mcp->out_mb;
199 ql_dbg(ql_dbg_mbx, vha, 0x1111,
200 "Mailbox registers (OUT):\n");
201 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
202 if (IS_QLA2200(ha) && cnt == 8)
203 optr =
204 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
205 if (mboxes & BIT_0) {
206 ql_dbg(ql_dbg_mbx, vha, 0x1112,
207 "mbox[%d]<-0x%04x\n", cnt, *iptr);
208 WRT_REG_WORD(optr, *iptr);
211 mboxes >>= 1;
212 optr++;
213 iptr++;
216 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1117,
217 "I/O Address = %p.\n", optr);
219 /* Issue set host interrupt command to send cmd out. */
220 ha->flags.mbox_int = 0;
221 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
223 /* Unlock mbx registers and wait for interrupt */
224 ql_dbg(ql_dbg_mbx, vha, 0x100f,
225 "Going to unlock irq & waiting for interrupts. "
226 "jiffies=%lx.\n", jiffies);
228 /* Wait for mbx cmd completion until timeout */
230 if ((!abort_active && io_lock_on) || IS_NOPOLLING_TYPE(ha)) {
231 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
233 if (IS_P3P_TYPE(ha)) {
234 if (RD_REG_DWORD(&reg->isp82.hint) &
235 HINT_MBX_INT_PENDING) {
236 spin_unlock_irqrestore(&ha->hardware_lock,
237 flags);
238 ha->flags.mbox_busy = 0;
239 ql_dbg(ql_dbg_mbx, vha, 0x1010,
240 "Pending mailbox timeout, exiting.\n");
241 rval = QLA_FUNCTION_TIMEOUT;
242 goto premature_exit;
244 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
245 } else if (IS_FWI2_CAPABLE(ha))
246 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
247 else
248 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
249 spin_unlock_irqrestore(&ha->hardware_lock, flags);
251 wait_time = jiffies;
252 if (!wait_for_completion_timeout(&ha->mbx_intr_comp,
253 mcp->tov * HZ)) {
254 ql_dbg(ql_dbg_mbx, vha, 0x117a,
255 "cmd=%x Timeout.\n", command);
256 spin_lock_irqsave(&ha->hardware_lock, flags);
257 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
258 spin_unlock_irqrestore(&ha->hardware_lock, flags);
260 if (time_after(jiffies, wait_time + 5 * HZ))
261 ql_log(ql_log_warn, vha, 0x1015, "cmd=0x%x, waited %d msecs\n",
262 command, jiffies_to_msecs(jiffies - wait_time));
263 } else {
264 ql_dbg(ql_dbg_mbx, vha, 0x1011,
265 "Cmd=%x Polling Mode.\n", command);
267 if (IS_P3P_TYPE(ha)) {
268 if (RD_REG_DWORD(&reg->isp82.hint) &
269 HINT_MBX_INT_PENDING) {
270 spin_unlock_irqrestore(&ha->hardware_lock,
271 flags);
272 ha->flags.mbox_busy = 0;
273 ql_dbg(ql_dbg_mbx, vha, 0x1012,
274 "Pending mailbox timeout, exiting.\n");
275 rval = QLA_FUNCTION_TIMEOUT;
276 goto premature_exit;
278 WRT_REG_DWORD(&reg->isp82.hint, HINT_MBX_INT_PENDING);
279 } else if (IS_FWI2_CAPABLE(ha))
280 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
281 else
282 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
283 spin_unlock_irqrestore(&ha->hardware_lock, flags);
285 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
286 while (!ha->flags.mbox_int) {
287 if (time_after(jiffies, wait_time))
288 break;
290 /* Check for pending interrupts. */
291 qla2x00_poll(ha->rsp_q_map[0]);
293 if (!ha->flags.mbox_int &&
294 !(IS_QLA2200(ha) &&
295 command == MBC_LOAD_RISC_RAM_EXTENDED))
296 msleep(10);
297 } /* while */
298 ql_dbg(ql_dbg_mbx, vha, 0x1013,
299 "Waited %d sec.\n",
300 (uint)((jiffies - (wait_time - (mcp->tov * HZ)))/HZ));
303 /* Check whether we timed out */
304 if (ha->flags.mbox_int) {
305 uint16_t *iptr2;
307 ql_dbg(ql_dbg_mbx, vha, 0x1014,
308 "Cmd=%x completed.\n", command);
310 /* Got interrupt. Clear the flag. */
311 ha->flags.mbox_int = 0;
312 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
314 if (IS_P3P_TYPE(ha) && ha->flags.isp82xx_fw_hung) {
315 ha->flags.mbox_busy = 0;
316 /* Setting Link-Down error */
317 mcp->mb[0] = MBS_LINK_DOWN_ERROR;
318 ha->mcp = NULL;
319 rval = QLA_FUNCTION_FAILED;
320 ql_log(ql_log_warn, vha, 0x1015,
321 "FW hung = %d.\n", ha->flags.isp82xx_fw_hung);
322 goto premature_exit;
325 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
326 rval = QLA_FUNCTION_FAILED;
328 /* Load return mailbox registers. */
329 iptr2 = mcp->mb;
330 iptr = (uint16_t *)&ha->mailbox_out[0];
331 mboxes = mcp->in_mb;
333 ql_dbg(ql_dbg_mbx, vha, 0x1113,
334 "Mailbox registers (IN):\n");
335 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
336 if (mboxes & BIT_0) {
337 *iptr2 = *iptr;
338 ql_dbg(ql_dbg_mbx, vha, 0x1114,
339 "mbox[%d]->0x%04x\n", cnt, *iptr2);
342 mboxes >>= 1;
343 iptr2++;
344 iptr++;
346 } else {
348 uint16_t mb[8];
349 uint32_t ictrl, host_status, hccr;
350 uint16_t w;
352 if (IS_FWI2_CAPABLE(ha)) {
353 mb[0] = RD_REG_WORD(&reg->isp24.mailbox0);
354 mb[1] = RD_REG_WORD(&reg->isp24.mailbox1);
355 mb[2] = RD_REG_WORD(&reg->isp24.mailbox2);
356 mb[3] = RD_REG_WORD(&reg->isp24.mailbox3);
357 mb[7] = RD_REG_WORD(&reg->isp24.mailbox7);
358 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
359 host_status = RD_REG_DWORD(&reg->isp24.host_status);
360 hccr = RD_REG_DWORD(&reg->isp24.hccr);
362 ql_log(ql_log_warn, vha, 0x1119,
363 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
364 "mb[0-3]=[0x%x 0x%x 0x%x 0x%x] mb7 0x%x host_status 0x%x hccr 0x%x\n",
365 command, ictrl, jiffies, mb[0], mb[1], mb[2], mb[3],
366 mb[7], host_status, hccr);
368 } else {
369 mb[0] = RD_MAILBOX_REG(ha, &reg->isp, 0);
370 ictrl = RD_REG_WORD(&reg->isp.ictrl);
371 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1119,
372 "MBX Command timeout for cmd %x, iocontrol=%x jiffies=%lx "
373 "mb[0]=0x%x\n", command, ictrl, jiffies, mb[0]);
375 ql_dump_regs(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1019);
377 /* Capture FW dump only, if PCI device active */
378 if (!pci_channel_offline(vha->hw->pdev)) {
379 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
380 if (w == 0xffff || ictrl == 0xffffffff) {
381 /* This is special case if there is unload
382 * of driver happening and if PCI device go
383 * into bad state due to PCI error condition
384 * then only PCI ERR flag would be set.
385 * we will do premature exit for above case.
387 if (test_bit(UNLOADING, &base_vha->dpc_flags))
388 set_bit(PCI_ERR, &base_vha->dpc_flags);
389 ha->flags.mbox_busy = 0;
390 rval = QLA_FUNCTION_TIMEOUT;
391 goto premature_exit;
394 /* Attempt to capture firmware dump for further
395 * anallysis of the current formware state. we do not
396 * need to do this if we are intentionally generating
397 * a dump
399 if (mcp->mb[0] != MBC_GEN_SYSTEM_ERROR)
400 ha->isp_ops->fw_dump(vha, 0);
401 rval = QLA_FUNCTION_TIMEOUT;
405 ha->flags.mbox_busy = 0;
407 /* Clean up */
408 ha->mcp = NULL;
410 if ((abort_active || !io_lock_on) && !IS_NOPOLLING_TYPE(ha)) {
411 ql_dbg(ql_dbg_mbx, vha, 0x101a,
412 "Checking for additional resp interrupt.\n");
414 /* polling mode for non isp_abort commands. */
415 qla2x00_poll(ha->rsp_q_map[0]);
418 if (rval == QLA_FUNCTION_TIMEOUT &&
419 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
420 if (!io_lock_on || (mcp->flags & IOCTL_CMD) ||
421 ha->flags.eeh_busy) {
422 /* not in dpc. schedule it for dpc to take over. */
423 ql_dbg(ql_dbg_mbx, vha, 0x101b,
424 "Timeout, schedule isp_abort_needed.\n");
426 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
427 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
428 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
429 if (IS_QLA82XX(ha)) {
430 ql_dbg(ql_dbg_mbx, vha, 0x112a,
431 "disabling pause transmit on port "
432 "0 & 1.\n");
433 qla82xx_wr_32(ha,
434 QLA82XX_CRB_NIU + 0x98,
435 CRB_NIU_XG_PAUSE_CTL_P0|
436 CRB_NIU_XG_PAUSE_CTL_P1);
438 ql_log(ql_log_info, base_vha, 0x101c,
439 "Mailbox cmd timeout occurred, cmd=0x%x, "
440 "mb[0]=0x%x, eeh_busy=0x%x. Scheduling ISP "
441 "abort.\n", command, mcp->mb[0],
442 ha->flags.eeh_busy);
443 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
444 qla2xxx_wake_dpc(vha);
446 } else if (!abort_active) {
447 /* call abort directly since we are in the DPC thread */
448 ql_dbg(ql_dbg_mbx, vha, 0x101d,
449 "Timeout, calling abort_isp.\n");
451 if (!test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) &&
452 !test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) &&
453 !test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
454 if (IS_QLA82XX(ha)) {
455 ql_dbg(ql_dbg_mbx, vha, 0x112b,
456 "disabling pause transmit on port "
457 "0 & 1.\n");
458 qla82xx_wr_32(ha,
459 QLA82XX_CRB_NIU + 0x98,
460 CRB_NIU_XG_PAUSE_CTL_P0|
461 CRB_NIU_XG_PAUSE_CTL_P1);
463 ql_log(ql_log_info, base_vha, 0x101e,
464 "Mailbox cmd timeout occurred, cmd=0x%x, "
465 "mb[0]=0x%x. Scheduling ISP abort ",
466 command, mcp->mb[0]);
467 set_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
468 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
469 /* Allow next mbx cmd to come in. */
470 complete(&ha->mbx_cmd_comp);
471 if (ha->isp_ops->abort_isp(vha)) {
472 /* Failed. retry later. */
473 set_bit(ISP_ABORT_NEEDED,
474 &vha->dpc_flags);
476 clear_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags);
477 ql_dbg(ql_dbg_mbx, vha, 0x101f,
478 "Finished abort_isp.\n");
479 goto mbx_done;
484 premature_exit:
485 /* Allow next mbx cmd to come in. */
486 complete(&ha->mbx_cmd_comp);
488 mbx_done:
489 if (rval) {
490 ql_dbg(ql_dbg_disc, base_vha, 0x1020,
491 "**** Failed mbx[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x, cmd=%x ****.\n",
492 mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3], command);
494 ql_dbg(ql_dbg_mbx, vha, 0x1198,
495 "host status: 0x%x, flags:0x%lx, intr ctrl reg:0x%x, intr status:0x%x\n",
496 RD_REG_DWORD(&reg->isp24.host_status),
497 ha->fw_dump_cap_flags,
498 RD_REG_DWORD(&reg->isp24.ictrl),
499 RD_REG_DWORD(&reg->isp24.istatus));
501 mbx_reg = &reg->isp24.mailbox0;
502 for (i = 0; i < 6; i++)
503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1199,
504 "mbox[%d] 0x%04x\n", i, RD_REG_WORD(mbx_reg++));
505 } else {
506 ql_dbg(ql_dbg_mbx, base_vha, 0x1021, "Done %s.\n", __func__);
509 return rval;
513 qla2x00_load_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t risc_addr,
514 uint32_t risc_code_size)
516 int rval;
517 struct qla_hw_data *ha = vha->hw;
518 mbx_cmd_t mc;
519 mbx_cmd_t *mcp = &mc;
521 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1022,
522 "Entered %s.\n", __func__);
524 if (MSW(risc_addr) || IS_FWI2_CAPABLE(ha)) {
525 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
526 mcp->mb[8] = MSW(risc_addr);
527 mcp->out_mb = MBX_8|MBX_0;
528 } else {
529 mcp->mb[0] = MBC_LOAD_RISC_RAM;
530 mcp->out_mb = MBX_0;
532 mcp->mb[1] = LSW(risc_addr);
533 mcp->mb[2] = MSW(req_dma);
534 mcp->mb[3] = LSW(req_dma);
535 mcp->mb[6] = MSW(MSD(req_dma));
536 mcp->mb[7] = LSW(MSD(req_dma));
537 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
538 if (IS_FWI2_CAPABLE(ha)) {
539 mcp->mb[4] = MSW(risc_code_size);
540 mcp->mb[5] = LSW(risc_code_size);
541 mcp->out_mb |= MBX_5|MBX_4;
542 } else {
543 mcp->mb[4] = LSW(risc_code_size);
544 mcp->out_mb |= MBX_4;
547 mcp->in_mb = MBX_0;
548 mcp->tov = MBX_TOV_SECONDS;
549 mcp->flags = 0;
550 rval = qla2x00_mailbox_command(vha, mcp);
552 if (rval != QLA_SUCCESS) {
553 ql_dbg(ql_dbg_mbx, vha, 0x1023,
554 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
555 } else {
556 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1024,
557 "Done %s.\n", __func__);
560 return rval;
563 #define EXTENDED_BB_CREDITS BIT_0
565 * qla2x00_execute_fw
566 * Start adapter firmware.
568 * Input:
569 * ha = adapter block pointer.
570 * TARGET_QUEUE_LOCK must be released.
571 * ADAPTER_STATE_LOCK must be released.
573 * Returns:
574 * qla2x00 local function return status code.
576 * Context:
577 * Kernel context.
580 qla2x00_execute_fw(scsi_qla_host_t *vha, uint32_t risc_addr)
582 int rval;
583 struct qla_hw_data *ha = vha->hw;
584 mbx_cmd_t mc;
585 mbx_cmd_t *mcp = &mc;
587 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1025,
588 "Entered %s.\n", __func__);
590 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
591 mcp->out_mb = MBX_0;
592 mcp->in_mb = MBX_0;
593 if (IS_FWI2_CAPABLE(ha)) {
594 mcp->mb[1] = MSW(risc_addr);
595 mcp->mb[2] = LSW(risc_addr);
596 mcp->mb[3] = 0;
597 if (IS_QLA25XX(ha) || IS_QLA81XX(ha) || IS_QLA83XX(ha) ||
598 IS_QLA27XX(ha)) {
599 struct nvram_81xx *nv = ha->nvram;
600 mcp->mb[4] = (nv->enhanced_features &
601 EXTENDED_BB_CREDITS);
602 } else
603 mcp->mb[4] = 0;
605 if (ha->flags.exlogins_enabled)
606 mcp->mb[4] |= ENABLE_EXTENDED_LOGIN;
608 if (ha->flags.exchoffld_enabled)
609 mcp->mb[4] |= ENABLE_EXCHANGE_OFFLD;
611 mcp->out_mb |= MBX_4|MBX_3|MBX_2|MBX_1;
612 mcp->in_mb |= MBX_1;
613 } else {
614 mcp->mb[1] = LSW(risc_addr);
615 mcp->out_mb |= MBX_1;
616 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
617 mcp->mb[2] = 0;
618 mcp->out_mb |= MBX_2;
622 mcp->tov = MBX_TOV_SECONDS;
623 mcp->flags = 0;
624 rval = qla2x00_mailbox_command(vha, mcp);
626 if (rval != QLA_SUCCESS) {
627 ql_dbg(ql_dbg_mbx, vha, 0x1026,
628 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
629 } else {
630 if (IS_FWI2_CAPABLE(ha)) {
631 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1027,
632 "Done exchanges=%x.\n", mcp->mb[1]);
633 } else {
634 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1028,
635 "Done %s.\n", __func__);
639 return rval;
643 * qla_get_exlogin_status
644 * Get extended login status
645 * uses the memory offload control/status Mailbox
647 * Input:
648 * ha: adapter state pointer.
649 * fwopt: firmware options
651 * Returns:
652 * qla2x00 local function status
654 * Context:
655 * Kernel context.
657 #define FETCH_XLOGINS_STAT 0x8
659 qla_get_exlogin_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
660 uint16_t *ex_logins_cnt)
662 int rval;
663 mbx_cmd_t mc;
664 mbx_cmd_t *mcp = &mc;
666 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118f,
667 "Entered %s\n", __func__);
669 memset(mcp->mb, 0 , sizeof(mcp->mb));
670 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
671 mcp->mb[1] = FETCH_XLOGINS_STAT;
672 mcp->out_mb = MBX_1|MBX_0;
673 mcp->in_mb = MBX_10|MBX_4|MBX_0;
674 mcp->tov = MBX_TOV_SECONDS;
675 mcp->flags = 0;
677 rval = qla2x00_mailbox_command(vha, mcp);
678 if (rval != QLA_SUCCESS) {
679 ql_dbg(ql_dbg_mbx, vha, 0x1115, "Failed=%x.\n", rval);
680 } else {
681 *buf_sz = mcp->mb[4];
682 *ex_logins_cnt = mcp->mb[10];
684 ql_log(ql_log_info, vha, 0x1190,
685 "buffer size 0x%x, exchange login count=%d\n",
686 mcp->mb[4], mcp->mb[10]);
688 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1116,
689 "Done %s.\n", __func__);
692 return rval;
696 * qla_set_exlogin_mem_cfg
697 * set extended login memory configuration
698 * Mbx needs to be issues before init_cb is set
700 * Input:
701 * ha: adapter state pointer.
702 * buffer: buffer pointer
703 * phys_addr: physical address of buffer
704 * size: size of buffer
705 * TARGET_QUEUE_LOCK must be released
706 * ADAPTER_STATE_LOCK must be release
708 * Returns:
709 * qla2x00 local funxtion status code.
711 * Context:
712 * Kernel context.
714 #define CONFIG_XLOGINS_MEM 0x3
716 qla_set_exlogin_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
718 int rval;
719 mbx_cmd_t mc;
720 mbx_cmd_t *mcp = &mc;
721 struct qla_hw_data *ha = vha->hw;
723 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111a,
724 "Entered %s.\n", __func__);
726 memset(mcp->mb, 0 , sizeof(mcp->mb));
727 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
728 mcp->mb[1] = CONFIG_XLOGINS_MEM;
729 mcp->mb[2] = MSW(phys_addr);
730 mcp->mb[3] = LSW(phys_addr);
731 mcp->mb[6] = MSW(MSD(phys_addr));
732 mcp->mb[7] = LSW(MSD(phys_addr));
733 mcp->mb[8] = MSW(ha->exlogin_size);
734 mcp->mb[9] = LSW(ha->exlogin_size);
735 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
736 mcp->in_mb = MBX_11|MBX_0;
737 mcp->tov = MBX_TOV_SECONDS;
738 mcp->flags = 0;
739 rval = qla2x00_mailbox_command(vha, mcp);
740 if (rval != QLA_SUCCESS) {
741 /*EMPTY*/
742 ql_dbg(ql_dbg_mbx, vha, 0x111b, "Failed=%x.\n", rval);
743 } else {
744 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118c,
745 "Done %s.\n", __func__);
748 return rval;
752 * qla_get_exchoffld_status
753 * Get exchange offload status
754 * uses the memory offload control/status Mailbox
756 * Input:
757 * ha: adapter state pointer.
758 * fwopt: firmware options
760 * Returns:
761 * qla2x00 local function status
763 * Context:
764 * Kernel context.
766 #define FETCH_XCHOFFLD_STAT 0x2
768 qla_get_exchoffld_status(scsi_qla_host_t *vha, uint16_t *buf_sz,
769 uint16_t *ex_logins_cnt)
771 int rval;
772 mbx_cmd_t mc;
773 mbx_cmd_t *mcp = &mc;
775 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1019,
776 "Entered %s\n", __func__);
778 memset(mcp->mb, 0 , sizeof(mcp->mb));
779 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
780 mcp->mb[1] = FETCH_XCHOFFLD_STAT;
781 mcp->out_mb = MBX_1|MBX_0;
782 mcp->in_mb = MBX_10|MBX_4|MBX_0;
783 mcp->tov = MBX_TOV_SECONDS;
784 mcp->flags = 0;
786 rval = qla2x00_mailbox_command(vha, mcp);
787 if (rval != QLA_SUCCESS) {
788 ql_dbg(ql_dbg_mbx, vha, 0x1155, "Failed=%x.\n", rval);
789 } else {
790 *buf_sz = mcp->mb[4];
791 *ex_logins_cnt = mcp->mb[10];
793 ql_log(ql_log_info, vha, 0x118e,
794 "buffer size 0x%x, exchange offload count=%d\n",
795 mcp->mb[4], mcp->mb[10]);
797 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1156,
798 "Done %s.\n", __func__);
801 return rval;
805 * qla_set_exchoffld_mem_cfg
806 * Set exchange offload memory configuration
807 * Mbx needs to be issues before init_cb is set
809 * Input:
810 * ha: adapter state pointer.
811 * buffer: buffer pointer
812 * phys_addr: physical address of buffer
813 * size: size of buffer
814 * TARGET_QUEUE_LOCK must be released
815 * ADAPTER_STATE_LOCK must be release
817 * Returns:
818 * qla2x00 local funxtion status code.
820 * Context:
821 * Kernel context.
823 #define CONFIG_XCHOFFLD_MEM 0x3
825 qla_set_exchoffld_mem_cfg(scsi_qla_host_t *vha, dma_addr_t phys_addr)
827 int rval;
828 mbx_cmd_t mc;
829 mbx_cmd_t *mcp = &mc;
830 struct qla_hw_data *ha = vha->hw;
832 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1157,
833 "Entered %s.\n", __func__);
835 memset(mcp->mb, 0 , sizeof(mcp->mb));
836 mcp->mb[0] = MBC_GET_MEM_OFFLOAD_CNTRL_STAT;
837 mcp->mb[1] = CONFIG_XCHOFFLD_MEM;
838 mcp->mb[2] = MSW(phys_addr);
839 mcp->mb[3] = LSW(phys_addr);
840 mcp->mb[6] = MSW(MSD(phys_addr));
841 mcp->mb[7] = LSW(MSD(phys_addr));
842 mcp->mb[8] = MSW(ha->exlogin_size);
843 mcp->mb[9] = LSW(ha->exlogin_size);
844 mcp->out_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
845 mcp->in_mb = MBX_11|MBX_0;
846 mcp->tov = MBX_TOV_SECONDS;
847 mcp->flags = 0;
848 rval = qla2x00_mailbox_command(vha, mcp);
849 if (rval != QLA_SUCCESS) {
850 /*EMPTY*/
851 ql_dbg(ql_dbg_mbx, vha, 0x1158, "Failed=%x.\n", rval);
852 } else {
853 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
854 "Done %s.\n", __func__);
857 return rval;
861 * qla2x00_get_fw_version
862 * Get firmware version.
864 * Input:
865 * ha: adapter state pointer.
866 * major: pointer for major number.
867 * minor: pointer for minor number.
868 * subminor: pointer for subminor number.
870 * Returns:
871 * qla2x00 local function return status code.
873 * Context:
874 * Kernel context.
877 qla2x00_get_fw_version(scsi_qla_host_t *vha)
879 int rval;
880 mbx_cmd_t mc;
881 mbx_cmd_t *mcp = &mc;
882 struct qla_hw_data *ha = vha->hw;
884 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1029,
885 "Entered %s.\n", __func__);
887 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
888 mcp->out_mb = MBX_0;
889 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
890 if (IS_QLA81XX(vha->hw) || IS_QLA8031(ha) || IS_QLA8044(ha))
891 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8;
892 if (IS_FWI2_CAPABLE(ha))
893 mcp->in_mb |= MBX_17|MBX_16|MBX_15;
894 if (IS_QLA27XX(ha))
895 mcp->in_mb |=
896 MBX_25|MBX_24|MBX_23|MBX_22|MBX_21|MBX_20|MBX_19|MBX_18|
897 MBX_14|MBX_13|MBX_11|MBX_10|MBX_9|MBX_8;
899 mcp->flags = 0;
900 mcp->tov = MBX_TOV_SECONDS;
901 rval = qla2x00_mailbox_command(vha, mcp);
902 if (rval != QLA_SUCCESS)
903 goto failed;
905 /* Return mailbox data. */
906 ha->fw_major_version = mcp->mb[1];
907 ha->fw_minor_version = mcp->mb[2];
908 ha->fw_subminor_version = mcp->mb[3];
909 ha->fw_attributes = mcp->mb[6];
910 if (IS_QLA2100(vha->hw) || IS_QLA2200(vha->hw))
911 ha->fw_memory_size = 0x1FFFF; /* Defaults to 128KB. */
912 else
913 ha->fw_memory_size = (mcp->mb[5] << 16) | mcp->mb[4];
915 if (IS_QLA81XX(vha->hw) || IS_QLA8031(vha->hw) || IS_QLA8044(ha)) {
916 ha->mpi_version[0] = mcp->mb[10] & 0xff;
917 ha->mpi_version[1] = mcp->mb[11] >> 8;
918 ha->mpi_version[2] = mcp->mb[11] & 0xff;
919 ha->mpi_capabilities = (mcp->mb[12] << 16) | mcp->mb[13];
920 ha->phy_version[0] = mcp->mb[8] & 0xff;
921 ha->phy_version[1] = mcp->mb[9] >> 8;
922 ha->phy_version[2] = mcp->mb[9] & 0xff;
925 if (IS_FWI2_CAPABLE(ha)) {
926 ha->fw_attributes_h = mcp->mb[15];
927 ha->fw_attributes_ext[0] = mcp->mb[16];
928 ha->fw_attributes_ext[1] = mcp->mb[17];
929 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1139,
930 "%s: FW_attributes Upper: 0x%x, Lower: 0x%x.\n",
931 __func__, mcp->mb[15], mcp->mb[6]);
932 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x112f,
933 "%s: Ext_FwAttributes Upper: 0x%x, Lower: 0x%x.\n",
934 __func__, mcp->mb[17], mcp->mb[16]);
936 if (ha->fw_attributes_h & 0x4)
937 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118d,
938 "%s: Firmware supports Extended Login 0x%x\n",
939 __func__, ha->fw_attributes_h);
941 if (ha->fw_attributes_h & 0x8)
942 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1191,
943 "%s: Firmware supports Exchange Offload 0x%x\n",
944 __func__, ha->fw_attributes_h);
947 if (IS_QLA27XX(ha)) {
948 ha->mpi_version[0] = mcp->mb[10] & 0xff;
949 ha->mpi_version[1] = mcp->mb[11] >> 8;
950 ha->mpi_version[2] = mcp->mb[11] & 0xff;
951 ha->pep_version[0] = mcp->mb[13] & 0xff;
952 ha->pep_version[1] = mcp->mb[14] >> 8;
953 ha->pep_version[2] = mcp->mb[14] & 0xff;
954 ha->fw_shared_ram_start = (mcp->mb[19] << 16) | mcp->mb[18];
955 ha->fw_shared_ram_end = (mcp->mb[21] << 16) | mcp->mb[20];
956 ha->fw_ddr_ram_start = (mcp->mb[23] << 16) | mcp->mb[22];
957 ha->fw_ddr_ram_end = (mcp->mb[25] << 16) | mcp->mb[24];
960 failed:
961 if (rval != QLA_SUCCESS) {
962 /*EMPTY*/
963 ql_dbg(ql_dbg_mbx, vha, 0x102a, "Failed=%x.\n", rval);
964 } else {
965 /*EMPTY*/
966 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102b,
967 "Done %s.\n", __func__);
969 return rval;
973 * qla2x00_get_fw_options
974 * Set firmware options.
976 * Input:
977 * ha = adapter block pointer.
978 * fwopt = pointer for firmware options.
980 * Returns:
981 * qla2x00 local function return status code.
983 * Context:
984 * Kernel context.
987 qla2x00_get_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
989 int rval;
990 mbx_cmd_t mc;
991 mbx_cmd_t *mcp = &mc;
993 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102c,
994 "Entered %s.\n", __func__);
996 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
997 mcp->out_mb = MBX_0;
998 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
999 mcp->tov = MBX_TOV_SECONDS;
1000 mcp->flags = 0;
1001 rval = qla2x00_mailbox_command(vha, mcp);
1003 if (rval != QLA_SUCCESS) {
1004 /*EMPTY*/
1005 ql_dbg(ql_dbg_mbx, vha, 0x102d, "Failed=%x.\n", rval);
1006 } else {
1007 fwopts[0] = mcp->mb[0];
1008 fwopts[1] = mcp->mb[1];
1009 fwopts[2] = mcp->mb[2];
1010 fwopts[3] = mcp->mb[3];
1012 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102e,
1013 "Done %s.\n", __func__);
1016 return rval;
1021 * qla2x00_set_fw_options
1022 * Set firmware options.
1024 * Input:
1025 * ha = adapter block pointer.
1026 * fwopt = pointer for firmware options.
1028 * Returns:
1029 * qla2x00 local function return status code.
1031 * Context:
1032 * Kernel context.
1035 qla2x00_set_fw_options(scsi_qla_host_t *vha, uint16_t *fwopts)
1037 int rval;
1038 mbx_cmd_t mc;
1039 mbx_cmd_t *mcp = &mc;
1041 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x102f,
1042 "Entered %s.\n", __func__);
1044 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
1045 mcp->mb[1] = fwopts[1];
1046 mcp->mb[2] = fwopts[2];
1047 mcp->mb[3] = fwopts[3];
1048 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1049 mcp->in_mb = MBX_0;
1050 if (IS_FWI2_CAPABLE(vha->hw)) {
1051 mcp->in_mb |= MBX_1;
1052 } else {
1053 mcp->mb[10] = fwopts[10];
1054 mcp->mb[11] = fwopts[11];
1055 mcp->mb[12] = 0; /* Undocumented, but used */
1056 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
1058 mcp->tov = MBX_TOV_SECONDS;
1059 mcp->flags = 0;
1060 rval = qla2x00_mailbox_command(vha, mcp);
1062 fwopts[0] = mcp->mb[0];
1064 if (rval != QLA_SUCCESS) {
1065 /*EMPTY*/
1066 ql_dbg(ql_dbg_mbx, vha, 0x1030,
1067 "Failed=%x (%x/%x).\n", rval, mcp->mb[0], mcp->mb[1]);
1068 } else {
1069 /*EMPTY*/
1070 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1031,
1071 "Done %s.\n", __func__);
1074 return rval;
1078 * qla2x00_mbx_reg_test
1079 * Mailbox register wrap test.
1081 * Input:
1082 * ha = adapter block pointer.
1083 * TARGET_QUEUE_LOCK must be released.
1084 * ADAPTER_STATE_LOCK must be released.
1086 * Returns:
1087 * qla2x00 local function return status code.
1089 * Context:
1090 * Kernel context.
1093 qla2x00_mbx_reg_test(scsi_qla_host_t *vha)
1095 int rval;
1096 mbx_cmd_t mc;
1097 mbx_cmd_t *mcp = &mc;
1099 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1032,
1100 "Entered %s.\n", __func__);
1102 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
1103 mcp->mb[1] = 0xAAAA;
1104 mcp->mb[2] = 0x5555;
1105 mcp->mb[3] = 0xAA55;
1106 mcp->mb[4] = 0x55AA;
1107 mcp->mb[5] = 0xA5A5;
1108 mcp->mb[6] = 0x5A5A;
1109 mcp->mb[7] = 0x2525;
1110 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1111 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1112 mcp->tov = MBX_TOV_SECONDS;
1113 mcp->flags = 0;
1114 rval = qla2x00_mailbox_command(vha, mcp);
1116 if (rval == QLA_SUCCESS) {
1117 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
1118 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
1119 rval = QLA_FUNCTION_FAILED;
1120 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
1121 mcp->mb[7] != 0x2525)
1122 rval = QLA_FUNCTION_FAILED;
1125 if (rval != QLA_SUCCESS) {
1126 /*EMPTY*/
1127 ql_dbg(ql_dbg_mbx, vha, 0x1033, "Failed=%x.\n", rval);
1128 } else {
1129 /*EMPTY*/
1130 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1034,
1131 "Done %s.\n", __func__);
1134 return rval;
1138 * qla2x00_verify_checksum
1139 * Verify firmware checksum.
1141 * Input:
1142 * ha = adapter block pointer.
1143 * TARGET_QUEUE_LOCK must be released.
1144 * ADAPTER_STATE_LOCK must be released.
1146 * Returns:
1147 * qla2x00 local function return status code.
1149 * Context:
1150 * Kernel context.
1153 qla2x00_verify_checksum(scsi_qla_host_t *vha, uint32_t risc_addr)
1155 int rval;
1156 mbx_cmd_t mc;
1157 mbx_cmd_t *mcp = &mc;
1159 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1035,
1160 "Entered %s.\n", __func__);
1162 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
1163 mcp->out_mb = MBX_0;
1164 mcp->in_mb = MBX_0;
1165 if (IS_FWI2_CAPABLE(vha->hw)) {
1166 mcp->mb[1] = MSW(risc_addr);
1167 mcp->mb[2] = LSW(risc_addr);
1168 mcp->out_mb |= MBX_2|MBX_1;
1169 mcp->in_mb |= MBX_2|MBX_1;
1170 } else {
1171 mcp->mb[1] = LSW(risc_addr);
1172 mcp->out_mb |= MBX_1;
1173 mcp->in_mb |= MBX_1;
1176 mcp->tov = MBX_TOV_SECONDS;
1177 mcp->flags = 0;
1178 rval = qla2x00_mailbox_command(vha, mcp);
1180 if (rval != QLA_SUCCESS) {
1181 ql_dbg(ql_dbg_mbx, vha, 0x1036,
1182 "Failed=%x chm sum=%x.\n", rval, IS_FWI2_CAPABLE(vha->hw) ?
1183 (mcp->mb[2] << 16) | mcp->mb[1] : mcp->mb[1]);
1184 } else {
1185 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1037,
1186 "Done %s.\n", __func__);
1189 return rval;
1193 * qla2x00_issue_iocb
1194 * Issue IOCB using mailbox command
1196 * Input:
1197 * ha = adapter state pointer.
1198 * buffer = buffer pointer.
1199 * phys_addr = physical address of buffer.
1200 * size = size of buffer.
1201 * TARGET_QUEUE_LOCK must be released.
1202 * ADAPTER_STATE_LOCK must be released.
1204 * Returns:
1205 * qla2x00 local function return status code.
1207 * Context:
1208 * Kernel context.
1211 qla2x00_issue_iocb_timeout(scsi_qla_host_t *vha, void *buffer,
1212 dma_addr_t phys_addr, size_t size, uint32_t tov)
1214 int rval;
1215 mbx_cmd_t mc;
1216 mbx_cmd_t *mcp = &mc;
1218 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1038,
1219 "Entered %s.\n", __func__);
1221 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
1222 mcp->mb[1] = 0;
1223 mcp->mb[2] = MSW(phys_addr);
1224 mcp->mb[3] = LSW(phys_addr);
1225 mcp->mb[6] = MSW(MSD(phys_addr));
1226 mcp->mb[7] = LSW(MSD(phys_addr));
1227 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1228 mcp->in_mb = MBX_2|MBX_0;
1229 mcp->tov = tov;
1230 mcp->flags = 0;
1231 rval = qla2x00_mailbox_command(vha, mcp);
1233 if (rval != QLA_SUCCESS) {
1234 /*EMPTY*/
1235 ql_dbg(ql_dbg_mbx, vha, 0x1039, "Failed=%x.\n", rval);
1236 } else {
1237 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
1239 /* Mask reserved bits. */
1240 sts_entry->entry_status &=
1241 IS_FWI2_CAPABLE(vha->hw) ? RF_MASK_24XX : RF_MASK;
1242 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103a,
1243 "Done %s.\n", __func__);
1246 return rval;
1250 qla2x00_issue_iocb(scsi_qla_host_t *vha, void *buffer, dma_addr_t phys_addr,
1251 size_t size)
1253 return qla2x00_issue_iocb_timeout(vha, buffer, phys_addr, size,
1254 MBX_TOV_SECONDS);
1258 * qla2x00_abort_command
1259 * Abort command aborts a specified IOCB.
1261 * Input:
1262 * ha = adapter block pointer.
1263 * sp = SB structure pointer.
1265 * Returns:
1266 * qla2x00 local function return status code.
1268 * Context:
1269 * Kernel context.
1272 qla2x00_abort_command(srb_t *sp)
1274 unsigned long flags = 0;
1275 int rval;
1276 uint32_t handle = 0;
1277 mbx_cmd_t mc;
1278 mbx_cmd_t *mcp = &mc;
1279 fc_port_t *fcport = sp->fcport;
1280 scsi_qla_host_t *vha = fcport->vha;
1281 struct qla_hw_data *ha = vha->hw;
1282 struct req_que *req;
1283 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
1285 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103b,
1286 "Entered %s.\n", __func__);
1288 if (vha->flags.qpairs_available && sp->qpair)
1289 req = sp->qpair->req;
1290 else
1291 req = vha->req;
1293 spin_lock_irqsave(&ha->hardware_lock, flags);
1294 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1295 if (req->outstanding_cmds[handle] == sp)
1296 break;
1298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1300 if (handle == req->num_outstanding_cmds) {
1301 /* command not found */
1302 return QLA_FUNCTION_FAILED;
1305 mcp->mb[0] = MBC_ABORT_COMMAND;
1306 if (HAS_EXTENDED_IDS(ha))
1307 mcp->mb[1] = fcport->loop_id;
1308 else
1309 mcp->mb[1] = fcport->loop_id << 8;
1310 mcp->mb[2] = (uint16_t)handle;
1311 mcp->mb[3] = (uint16_t)(handle >> 16);
1312 mcp->mb[6] = (uint16_t)cmd->device->lun;
1313 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1314 mcp->in_mb = MBX_0;
1315 mcp->tov = MBX_TOV_SECONDS;
1316 mcp->flags = 0;
1317 rval = qla2x00_mailbox_command(vha, mcp);
1319 if (rval != QLA_SUCCESS) {
1320 ql_dbg(ql_dbg_mbx, vha, 0x103c, "Failed=%x.\n", rval);
1321 } else {
1322 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103d,
1323 "Done %s.\n", __func__);
1326 return rval;
1330 qla2x00_abort_target(struct fc_port *fcport, uint64_t l, int tag)
1332 int rval, rval2;
1333 mbx_cmd_t mc;
1334 mbx_cmd_t *mcp = &mc;
1335 scsi_qla_host_t *vha;
1336 struct req_que *req;
1337 struct rsp_que *rsp;
1339 l = l;
1340 vha = fcport->vha;
1342 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103e,
1343 "Entered %s.\n", __func__);
1345 req = vha->hw->req_q_map[0];
1346 rsp = req->rsp;
1347 mcp->mb[0] = MBC_ABORT_TARGET;
1348 mcp->out_mb = MBX_9|MBX_2|MBX_1|MBX_0;
1349 if (HAS_EXTENDED_IDS(vha->hw)) {
1350 mcp->mb[1] = fcport->loop_id;
1351 mcp->mb[10] = 0;
1352 mcp->out_mb |= MBX_10;
1353 } else {
1354 mcp->mb[1] = fcport->loop_id << 8;
1356 mcp->mb[2] = vha->hw->loop_reset_delay;
1357 mcp->mb[9] = vha->vp_idx;
1359 mcp->in_mb = MBX_0;
1360 mcp->tov = MBX_TOV_SECONDS;
1361 mcp->flags = 0;
1362 rval = qla2x00_mailbox_command(vha, mcp);
1363 if (rval != QLA_SUCCESS) {
1364 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x103f,
1365 "Failed=%x.\n", rval);
1368 /* Issue marker IOCB. */
1369 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, 0,
1370 MK_SYNC_ID);
1371 if (rval2 != QLA_SUCCESS) {
1372 ql_dbg(ql_dbg_mbx, vha, 0x1040,
1373 "Failed to issue marker IOCB (%x).\n", rval2);
1374 } else {
1375 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1041,
1376 "Done %s.\n", __func__);
1379 return rval;
1383 qla2x00_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
1385 int rval, rval2;
1386 mbx_cmd_t mc;
1387 mbx_cmd_t *mcp = &mc;
1388 scsi_qla_host_t *vha;
1389 struct req_que *req;
1390 struct rsp_que *rsp;
1392 vha = fcport->vha;
1394 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1042,
1395 "Entered %s.\n", __func__);
1397 req = vha->hw->req_q_map[0];
1398 rsp = req->rsp;
1399 mcp->mb[0] = MBC_LUN_RESET;
1400 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
1401 if (HAS_EXTENDED_IDS(vha->hw))
1402 mcp->mb[1] = fcport->loop_id;
1403 else
1404 mcp->mb[1] = fcport->loop_id << 8;
1405 mcp->mb[2] = (u32)l;
1406 mcp->mb[3] = 0;
1407 mcp->mb[9] = vha->vp_idx;
1409 mcp->in_mb = MBX_0;
1410 mcp->tov = MBX_TOV_SECONDS;
1411 mcp->flags = 0;
1412 rval = qla2x00_mailbox_command(vha, mcp);
1413 if (rval != QLA_SUCCESS) {
1414 ql_dbg(ql_dbg_mbx, vha, 0x1043, "Failed=%x.\n", rval);
1417 /* Issue marker IOCB. */
1418 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
1419 MK_SYNC_ID_LUN);
1420 if (rval2 != QLA_SUCCESS) {
1421 ql_dbg(ql_dbg_mbx, vha, 0x1044,
1422 "Failed to issue marker IOCB (%x).\n", rval2);
1423 } else {
1424 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1045,
1425 "Done %s.\n", __func__);
1428 return rval;
1432 * qla2x00_get_adapter_id
1433 * Get adapter ID and topology.
1435 * Input:
1436 * ha = adapter block pointer.
1437 * id = pointer for loop ID.
1438 * al_pa = pointer for AL_PA.
1439 * area = pointer for area.
1440 * domain = pointer for domain.
1441 * top = pointer for topology.
1442 * TARGET_QUEUE_LOCK must be released.
1443 * ADAPTER_STATE_LOCK must be released.
1445 * Returns:
1446 * qla2x00 local function return status code.
1448 * Context:
1449 * Kernel context.
1452 qla2x00_get_adapter_id(scsi_qla_host_t *vha, uint16_t *id, uint8_t *al_pa,
1453 uint8_t *area, uint8_t *domain, uint16_t *top, uint16_t *sw_cap)
1455 int rval;
1456 mbx_cmd_t mc;
1457 mbx_cmd_t *mcp = &mc;
1459 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1046,
1460 "Entered %s.\n", __func__);
1462 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
1463 mcp->mb[9] = vha->vp_idx;
1464 mcp->out_mb = MBX_9|MBX_0;
1465 mcp->in_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1466 if (IS_CNA_CAPABLE(vha->hw))
1467 mcp->in_mb |= MBX_13|MBX_12|MBX_11|MBX_10;
1468 if (IS_FWI2_CAPABLE(vha->hw))
1469 mcp->in_mb |= MBX_19|MBX_18|MBX_17|MBX_16;
1470 if (IS_QLA27XX(vha->hw))
1471 mcp->in_mb |= MBX_15;
1472 mcp->tov = MBX_TOV_SECONDS;
1473 mcp->flags = 0;
1474 rval = qla2x00_mailbox_command(vha, mcp);
1475 if (mcp->mb[0] == MBS_COMMAND_ERROR)
1476 rval = QLA_COMMAND_ERROR;
1477 else if (mcp->mb[0] == MBS_INVALID_COMMAND)
1478 rval = QLA_INVALID_COMMAND;
1480 /* Return data. */
1481 *id = mcp->mb[1];
1482 *al_pa = LSB(mcp->mb[2]);
1483 *area = MSB(mcp->mb[2]);
1484 *domain = LSB(mcp->mb[3]);
1485 *top = mcp->mb[6];
1486 *sw_cap = mcp->mb[7];
1488 if (rval != QLA_SUCCESS) {
1489 /*EMPTY*/
1490 ql_dbg(ql_dbg_mbx, vha, 0x1047, "Failed=%x.\n", rval);
1491 } else {
1492 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1048,
1493 "Done %s.\n", __func__);
1495 if (IS_CNA_CAPABLE(vha->hw)) {
1496 vha->fcoe_vlan_id = mcp->mb[9] & 0xfff;
1497 vha->fcoe_fcf_idx = mcp->mb[10];
1498 vha->fcoe_vn_port_mac[5] = mcp->mb[11] >> 8;
1499 vha->fcoe_vn_port_mac[4] = mcp->mb[11] & 0xff;
1500 vha->fcoe_vn_port_mac[3] = mcp->mb[12] >> 8;
1501 vha->fcoe_vn_port_mac[2] = mcp->mb[12] & 0xff;
1502 vha->fcoe_vn_port_mac[1] = mcp->mb[13] >> 8;
1503 vha->fcoe_vn_port_mac[0] = mcp->mb[13] & 0xff;
1505 /* If FA-WWN supported */
1506 if (IS_FAWWN_CAPABLE(vha->hw)) {
1507 if (mcp->mb[7] & BIT_14) {
1508 vha->port_name[0] = MSB(mcp->mb[16]);
1509 vha->port_name[1] = LSB(mcp->mb[16]);
1510 vha->port_name[2] = MSB(mcp->mb[17]);
1511 vha->port_name[3] = LSB(mcp->mb[17]);
1512 vha->port_name[4] = MSB(mcp->mb[18]);
1513 vha->port_name[5] = LSB(mcp->mb[18]);
1514 vha->port_name[6] = MSB(mcp->mb[19]);
1515 vha->port_name[7] = LSB(mcp->mb[19]);
1516 fc_host_port_name(vha->host) =
1517 wwn_to_u64(vha->port_name);
1518 ql_dbg(ql_dbg_mbx, vha, 0x10ca,
1519 "FA-WWN acquired %016llx\n",
1520 wwn_to_u64(vha->port_name));
1524 if (IS_QLA27XX(vha->hw))
1525 vha->bbcr = mcp->mb[15];
1528 return rval;
1532 * qla2x00_get_retry_cnt
1533 * Get current firmware login retry count and delay.
1535 * Input:
1536 * ha = adapter block pointer.
1537 * retry_cnt = pointer to login retry count.
1538 * tov = pointer to login timeout value.
1540 * Returns:
1541 * qla2x00 local function return status code.
1543 * Context:
1544 * Kernel context.
1547 qla2x00_get_retry_cnt(scsi_qla_host_t *vha, uint8_t *retry_cnt, uint8_t *tov,
1548 uint16_t *r_a_tov)
1550 int rval;
1551 uint16_t ratov;
1552 mbx_cmd_t mc;
1553 mbx_cmd_t *mcp = &mc;
1555 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1049,
1556 "Entered %s.\n", __func__);
1558 mcp->mb[0] = MBC_GET_RETRY_COUNT;
1559 mcp->out_mb = MBX_0;
1560 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1561 mcp->tov = MBX_TOV_SECONDS;
1562 mcp->flags = 0;
1563 rval = qla2x00_mailbox_command(vha, mcp);
1565 if (rval != QLA_SUCCESS) {
1566 /*EMPTY*/
1567 ql_dbg(ql_dbg_mbx, vha, 0x104a,
1568 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
1569 } else {
1570 /* Convert returned data and check our values. */
1571 *r_a_tov = mcp->mb[3] / 2;
1572 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
1573 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
1574 /* Update to the larger values */
1575 *retry_cnt = (uint8_t)mcp->mb[1];
1576 *tov = ratov;
1579 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104b,
1580 "Done %s mb3=%d ratov=%d.\n", __func__, mcp->mb[3], ratov);
1583 return rval;
1587 * qla2x00_init_firmware
1588 * Initialize adapter firmware.
1590 * Input:
1591 * ha = adapter block pointer.
1592 * dptr = Initialization control block pointer.
1593 * size = size of initialization control block.
1594 * TARGET_QUEUE_LOCK must be released.
1595 * ADAPTER_STATE_LOCK must be released.
1597 * Returns:
1598 * qla2x00 local function return status code.
1600 * Context:
1601 * Kernel context.
1604 qla2x00_init_firmware(scsi_qla_host_t *vha, uint16_t size)
1606 int rval;
1607 mbx_cmd_t mc;
1608 mbx_cmd_t *mcp = &mc;
1609 struct qla_hw_data *ha = vha->hw;
1611 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104c,
1612 "Entered %s.\n", __func__);
1614 if (IS_P3P_TYPE(ha) && ql2xdbwr)
1615 qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr,
1616 (0x04 | (ha->portnum << 5) | (0 << 8) | (0 << 16)));
1618 if (ha->flags.npiv_supported)
1619 mcp->mb[0] = MBC_MID_INITIALIZE_FIRMWARE;
1620 else
1621 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1623 mcp->mb[1] = 0;
1624 mcp->mb[2] = MSW(ha->init_cb_dma);
1625 mcp->mb[3] = LSW(ha->init_cb_dma);
1626 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1627 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1628 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1629 if (ha->ex_init_cb && ha->ex_init_cb->ex_version) {
1630 mcp->mb[1] = BIT_0;
1631 mcp->mb[10] = MSW(ha->ex_init_cb_dma);
1632 mcp->mb[11] = LSW(ha->ex_init_cb_dma);
1633 mcp->mb[12] = MSW(MSD(ha->ex_init_cb_dma));
1634 mcp->mb[13] = LSW(MSD(ha->ex_init_cb_dma));
1635 mcp->mb[14] = sizeof(*ha->ex_init_cb);
1636 mcp->out_mb |= MBX_14|MBX_13|MBX_12|MBX_11|MBX_10;
1638 /* 1 and 2 should normally be captured. */
1639 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1640 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
1641 /* mb3 is additional info about the installed SFP. */
1642 mcp->in_mb |= MBX_3;
1643 mcp->buf_size = size;
1644 mcp->flags = MBX_DMA_OUT;
1645 mcp->tov = MBX_TOV_SECONDS;
1646 rval = qla2x00_mailbox_command(vha, mcp);
1648 if (rval != QLA_SUCCESS) {
1649 /*EMPTY*/
1650 ql_dbg(ql_dbg_mbx, vha, 0x104d,
1651 "Failed=%x mb[0]=%x, mb[1]=%x, mb[2]=%x, mb[3]=%x,.\n",
1652 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3]);
1653 } else {
1654 /*EMPTY*/
1655 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104e,
1656 "Done %s.\n", __func__);
1659 return rval;
1664 * qla2x00_get_port_database
1665 * Issue normal/enhanced get port database mailbox command
1666 * and copy device name as necessary.
1668 * Input:
1669 * ha = adapter state pointer.
1670 * dev = structure pointer.
1671 * opt = enhanced cmd option byte.
1673 * Returns:
1674 * qla2x00 local function return status code.
1676 * Context:
1677 * Kernel context.
1680 qla2x00_get_port_database(scsi_qla_host_t *vha, fc_port_t *fcport, uint8_t opt)
1682 int rval;
1683 mbx_cmd_t mc;
1684 mbx_cmd_t *mcp = &mc;
1685 port_database_t *pd;
1686 struct port_database_24xx *pd24;
1687 dma_addr_t pd_dma;
1688 struct qla_hw_data *ha = vha->hw;
1690 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x104f,
1691 "Entered %s.\n", __func__);
1693 pd24 = NULL;
1694 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1695 if (pd == NULL) {
1696 ql_log(ql_log_warn, vha, 0x1050,
1697 "Failed to allocate port database structure.\n");
1698 return QLA_MEMORY_ALLOC_FAILED;
1700 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1702 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1703 if (opt != 0 && !IS_FWI2_CAPABLE(ha))
1704 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1705 mcp->mb[2] = MSW(pd_dma);
1706 mcp->mb[3] = LSW(pd_dma);
1707 mcp->mb[6] = MSW(MSD(pd_dma));
1708 mcp->mb[7] = LSW(MSD(pd_dma));
1709 mcp->mb[9] = vha->vp_idx;
1710 mcp->out_mb = MBX_9|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1711 mcp->in_mb = MBX_0;
1712 if (IS_FWI2_CAPABLE(ha)) {
1713 mcp->mb[1] = fcport->loop_id;
1714 mcp->mb[10] = opt;
1715 mcp->out_mb |= MBX_10|MBX_1;
1716 mcp->in_mb |= MBX_1;
1717 } else if (HAS_EXTENDED_IDS(ha)) {
1718 mcp->mb[1] = fcport->loop_id;
1719 mcp->mb[10] = opt;
1720 mcp->out_mb |= MBX_10|MBX_1;
1721 } else {
1722 mcp->mb[1] = fcport->loop_id << 8 | opt;
1723 mcp->out_mb |= MBX_1;
1725 mcp->buf_size = IS_FWI2_CAPABLE(ha) ?
1726 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE;
1727 mcp->flags = MBX_DMA_IN;
1728 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1729 rval = qla2x00_mailbox_command(vha, mcp);
1730 if (rval != QLA_SUCCESS)
1731 goto gpd_error_out;
1733 if (IS_FWI2_CAPABLE(ha)) {
1734 uint64_t zero = 0;
1735 pd24 = (struct port_database_24xx *) pd;
1737 /* Check for logged in state. */
1738 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1739 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1740 ql_dbg(ql_dbg_mbx, vha, 0x1051,
1741 "Unable to verify login-state (%x/%x) for "
1742 "loop_id %x.\n", pd24->current_login_state,
1743 pd24->last_login_state, fcport->loop_id);
1744 rval = QLA_FUNCTION_FAILED;
1745 goto gpd_error_out;
1748 if (fcport->loop_id == FC_NO_LOOP_ID ||
1749 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1750 memcmp(fcport->port_name, pd24->port_name, 8))) {
1751 /* We lost the device mid way. */
1752 rval = QLA_NOT_LOGGED_IN;
1753 goto gpd_error_out;
1756 /* Names are little-endian. */
1757 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1758 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1760 /* Get port_id of device. */
1761 fcport->d_id.b.domain = pd24->port_id[0];
1762 fcport->d_id.b.area = pd24->port_id[1];
1763 fcport->d_id.b.al_pa = pd24->port_id[2];
1764 fcport->d_id.b.rsvd_1 = 0;
1766 /* If not target must be initiator or unknown type. */
1767 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1768 fcport->port_type = FCT_INITIATOR;
1769 else
1770 fcport->port_type = FCT_TARGET;
1772 /* Passback COS information. */
1773 fcport->supported_classes = (pd24->flags & PDF_CLASS_2) ?
1774 FC_COS_CLASS2 : FC_COS_CLASS3;
1776 if (pd24->prli_svc_param_word_3[0] & BIT_7)
1777 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
1778 } else {
1779 uint64_t zero = 0;
1781 /* Check for logged in state. */
1782 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1783 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1784 ql_dbg(ql_dbg_mbx, vha, 0x100a,
1785 "Unable to verify login-state (%x/%x) - "
1786 "portid=%02x%02x%02x.\n", pd->master_state,
1787 pd->slave_state, fcport->d_id.b.domain,
1788 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1789 rval = QLA_FUNCTION_FAILED;
1790 goto gpd_error_out;
1793 if (fcport->loop_id == FC_NO_LOOP_ID ||
1794 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
1795 memcmp(fcport->port_name, pd->port_name, 8))) {
1796 /* We lost the device mid way. */
1797 rval = QLA_NOT_LOGGED_IN;
1798 goto gpd_error_out;
1801 /* Names are little-endian. */
1802 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1803 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1805 /* Get port_id of device. */
1806 fcport->d_id.b.domain = pd->port_id[0];
1807 fcport->d_id.b.area = pd->port_id[3];
1808 fcport->d_id.b.al_pa = pd->port_id[2];
1809 fcport->d_id.b.rsvd_1 = 0;
1811 /* If not target must be initiator or unknown type. */
1812 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1813 fcport->port_type = FCT_INITIATOR;
1814 else
1815 fcport->port_type = FCT_TARGET;
1817 /* Passback COS information. */
1818 fcport->supported_classes = (pd->options & BIT_4) ?
1819 FC_COS_CLASS2: FC_COS_CLASS3;
1822 gpd_error_out:
1823 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1825 if (rval != QLA_SUCCESS) {
1826 ql_dbg(ql_dbg_mbx, vha, 0x1052,
1827 "Failed=%x mb[0]=%x mb[1]=%x.\n", rval,
1828 mcp->mb[0], mcp->mb[1]);
1829 } else {
1830 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1053,
1831 "Done %s.\n", __func__);
1834 return rval;
1838 * qla2x00_get_firmware_state
1839 * Get adapter firmware state.
1841 * Input:
1842 * ha = adapter block pointer.
1843 * dptr = pointer for firmware state.
1844 * TARGET_QUEUE_LOCK must be released.
1845 * ADAPTER_STATE_LOCK must be released.
1847 * Returns:
1848 * qla2x00 local function return status code.
1850 * Context:
1851 * Kernel context.
1854 qla2x00_get_firmware_state(scsi_qla_host_t *vha, uint16_t *states)
1856 int rval;
1857 mbx_cmd_t mc;
1858 mbx_cmd_t *mcp = &mc;
1860 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1054,
1861 "Entered %s.\n", __func__);
1863 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1864 mcp->out_mb = MBX_0;
1865 if (IS_FWI2_CAPABLE(vha->hw))
1866 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
1867 else
1868 mcp->in_mb = MBX_1|MBX_0;
1869 mcp->tov = MBX_TOV_SECONDS;
1870 mcp->flags = 0;
1871 rval = qla2x00_mailbox_command(vha, mcp);
1873 /* Return firmware states. */
1874 states[0] = mcp->mb[1];
1875 if (IS_FWI2_CAPABLE(vha->hw)) {
1876 states[1] = mcp->mb[2];
1877 states[2] = mcp->mb[3]; /* SFP info */
1878 states[3] = mcp->mb[4];
1879 states[4] = mcp->mb[5];
1880 states[5] = mcp->mb[6]; /* DPORT status */
1883 if (rval != QLA_SUCCESS) {
1884 /*EMPTY*/
1885 ql_dbg(ql_dbg_mbx, vha, 0x1055, "Failed=%x.\n", rval);
1886 } else {
1887 /*EMPTY*/
1888 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1056,
1889 "Done %s.\n", __func__);
1892 return rval;
1896 * qla2x00_get_port_name
1897 * Issue get port name mailbox command.
1898 * Returned name is in big endian format.
1900 * Input:
1901 * ha = adapter block pointer.
1902 * loop_id = loop ID of device.
1903 * name = pointer for name.
1904 * TARGET_QUEUE_LOCK must be released.
1905 * ADAPTER_STATE_LOCK must be released.
1907 * Returns:
1908 * qla2x00 local function return status code.
1910 * Context:
1911 * Kernel context.
1914 qla2x00_get_port_name(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t *name,
1915 uint8_t opt)
1917 int rval;
1918 mbx_cmd_t mc;
1919 mbx_cmd_t *mcp = &mc;
1921 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1057,
1922 "Entered %s.\n", __func__);
1924 mcp->mb[0] = MBC_GET_PORT_NAME;
1925 mcp->mb[9] = vha->vp_idx;
1926 mcp->out_mb = MBX_9|MBX_1|MBX_0;
1927 if (HAS_EXTENDED_IDS(vha->hw)) {
1928 mcp->mb[1] = loop_id;
1929 mcp->mb[10] = opt;
1930 mcp->out_mb |= MBX_10;
1931 } else {
1932 mcp->mb[1] = loop_id << 8 | opt;
1935 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1936 mcp->tov = MBX_TOV_SECONDS;
1937 mcp->flags = 0;
1938 rval = qla2x00_mailbox_command(vha, mcp);
1940 if (rval != QLA_SUCCESS) {
1941 /*EMPTY*/
1942 ql_dbg(ql_dbg_mbx, vha, 0x1058, "Failed=%x.\n", rval);
1943 } else {
1944 if (name != NULL) {
1945 /* This function returns name in big endian. */
1946 name[0] = MSB(mcp->mb[2]);
1947 name[1] = LSB(mcp->mb[2]);
1948 name[2] = MSB(mcp->mb[3]);
1949 name[3] = LSB(mcp->mb[3]);
1950 name[4] = MSB(mcp->mb[6]);
1951 name[5] = LSB(mcp->mb[6]);
1952 name[6] = MSB(mcp->mb[7]);
1953 name[7] = LSB(mcp->mb[7]);
1956 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1059,
1957 "Done %s.\n", __func__);
1960 return rval;
1964 * qla24xx_link_initialization
1965 * Issue link initialization mailbox command.
1967 * Input:
1968 * ha = adapter block pointer.
1969 * TARGET_QUEUE_LOCK must be released.
1970 * ADAPTER_STATE_LOCK must be released.
1972 * Returns:
1973 * qla2x00 local function return status code.
1975 * Context:
1976 * Kernel context.
1979 qla24xx_link_initialize(scsi_qla_host_t *vha)
1981 int rval;
1982 mbx_cmd_t mc;
1983 mbx_cmd_t *mcp = &mc;
1985 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1152,
1986 "Entered %s.\n", __func__);
1988 if (!IS_FWI2_CAPABLE(vha->hw) || IS_CNA_CAPABLE(vha->hw))
1989 return QLA_FUNCTION_FAILED;
1991 mcp->mb[0] = MBC_LINK_INITIALIZATION;
1992 mcp->mb[1] = BIT_4;
1993 if (vha->hw->operating_mode == LOOP)
1994 mcp->mb[1] |= BIT_6;
1995 else
1996 mcp->mb[1] |= BIT_5;
1997 mcp->mb[2] = 0;
1998 mcp->mb[3] = 0;
1999 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2000 mcp->in_mb = MBX_0;
2001 mcp->tov = MBX_TOV_SECONDS;
2002 mcp->flags = 0;
2003 rval = qla2x00_mailbox_command(vha, mcp);
2005 if (rval != QLA_SUCCESS) {
2006 ql_dbg(ql_dbg_mbx, vha, 0x1153, "Failed=%x.\n", rval);
2007 } else {
2008 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1154,
2009 "Done %s.\n", __func__);
2012 return rval;
2016 * qla2x00_lip_reset
2017 * Issue LIP reset mailbox command.
2019 * Input:
2020 * ha = adapter block pointer.
2021 * TARGET_QUEUE_LOCK must be released.
2022 * ADAPTER_STATE_LOCK must be released.
2024 * Returns:
2025 * qla2x00 local function return status code.
2027 * Context:
2028 * Kernel context.
2031 qla2x00_lip_reset(scsi_qla_host_t *vha)
2033 int rval;
2034 mbx_cmd_t mc;
2035 mbx_cmd_t *mcp = &mc;
2037 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105a,
2038 "Entered %s.\n", __func__);
2040 if (IS_CNA_CAPABLE(vha->hw)) {
2041 /* Logout across all FCFs. */
2042 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2043 mcp->mb[1] = BIT_1;
2044 mcp->mb[2] = 0;
2045 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2046 } else if (IS_FWI2_CAPABLE(vha->hw)) {
2047 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2048 mcp->mb[1] = BIT_6;
2049 mcp->mb[2] = 0;
2050 mcp->mb[3] = vha->hw->loop_reset_delay;
2051 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2052 } else {
2053 mcp->mb[0] = MBC_LIP_RESET;
2054 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2055 if (HAS_EXTENDED_IDS(vha->hw)) {
2056 mcp->mb[1] = 0x00ff;
2057 mcp->mb[10] = 0;
2058 mcp->out_mb |= MBX_10;
2059 } else {
2060 mcp->mb[1] = 0xff00;
2062 mcp->mb[2] = vha->hw->loop_reset_delay;
2063 mcp->mb[3] = 0;
2065 mcp->in_mb = MBX_0;
2066 mcp->tov = MBX_TOV_SECONDS;
2067 mcp->flags = 0;
2068 rval = qla2x00_mailbox_command(vha, mcp);
2070 if (rval != QLA_SUCCESS) {
2071 /*EMPTY*/
2072 ql_dbg(ql_dbg_mbx, vha, 0x105b, "Failed=%x.\n", rval);
2073 } else {
2074 /*EMPTY*/
2075 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105c,
2076 "Done %s.\n", __func__);
2079 return rval;
2083 * qla2x00_send_sns
2084 * Send SNS command.
2086 * Input:
2087 * ha = adapter block pointer.
2088 * sns = pointer for command.
2089 * cmd_size = command size.
2090 * buf_size = response/command size.
2091 * TARGET_QUEUE_LOCK must be released.
2092 * ADAPTER_STATE_LOCK must be released.
2094 * Returns:
2095 * qla2x00 local function return status code.
2097 * Context:
2098 * Kernel context.
2101 qla2x00_send_sns(scsi_qla_host_t *vha, dma_addr_t sns_phys_address,
2102 uint16_t cmd_size, size_t buf_size)
2104 int rval;
2105 mbx_cmd_t mc;
2106 mbx_cmd_t *mcp = &mc;
2108 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105d,
2109 "Entered %s.\n", __func__);
2111 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x105e,
2112 "Retry cnt=%d ratov=%d total tov=%d.\n",
2113 vha->hw->retry_count, vha->hw->login_timeout, mcp->tov);
2115 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
2116 mcp->mb[1] = cmd_size;
2117 mcp->mb[2] = MSW(sns_phys_address);
2118 mcp->mb[3] = LSW(sns_phys_address);
2119 mcp->mb[6] = MSW(MSD(sns_phys_address));
2120 mcp->mb[7] = LSW(MSD(sns_phys_address));
2121 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2122 mcp->in_mb = MBX_0|MBX_1;
2123 mcp->buf_size = buf_size;
2124 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
2125 mcp->tov = (vha->hw->login_timeout * 2) + (vha->hw->login_timeout / 2);
2126 rval = qla2x00_mailbox_command(vha, mcp);
2128 if (rval != QLA_SUCCESS) {
2129 /*EMPTY*/
2130 ql_dbg(ql_dbg_mbx, vha, 0x105f,
2131 "Failed=%x mb[0]=%x mb[1]=%x.\n",
2132 rval, mcp->mb[0], mcp->mb[1]);
2133 } else {
2134 /*EMPTY*/
2135 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1060,
2136 "Done %s.\n", __func__);
2139 return rval;
2143 qla24xx_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
2144 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2146 int rval;
2148 struct logio_entry_24xx *lg;
2149 dma_addr_t lg_dma;
2150 uint32_t iop[2];
2151 struct qla_hw_data *ha = vha->hw;
2152 struct req_que *req;
2154 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1061,
2155 "Entered %s.\n", __func__);
2157 if (vha->vp_idx && vha->qpair)
2158 req = vha->qpair->req;
2159 else
2160 req = ha->req_q_map[0];
2162 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2163 if (lg == NULL) {
2164 ql_log(ql_log_warn, vha, 0x1062,
2165 "Failed to allocate login IOCB.\n");
2166 return QLA_MEMORY_ALLOC_FAILED;
2168 memset(lg, 0, sizeof(struct logio_entry_24xx));
2170 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2171 lg->entry_count = 1;
2172 lg->handle = MAKE_HANDLE(req->id, lg->handle);
2173 lg->nport_handle = cpu_to_le16(loop_id);
2174 lg->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI);
2175 if (opt & BIT_0)
2176 lg->control_flags |= cpu_to_le16(LCF_COND_PLOGI);
2177 if (opt & BIT_1)
2178 lg->control_flags |= cpu_to_le16(LCF_SKIP_PRLI);
2179 lg->port_id[0] = al_pa;
2180 lg->port_id[1] = area;
2181 lg->port_id[2] = domain;
2182 lg->vp_index = vha->vp_idx;
2183 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2184 (ha->r_a_tov / 10 * 2) + 2);
2185 if (rval != QLA_SUCCESS) {
2186 ql_dbg(ql_dbg_mbx, vha, 0x1063,
2187 "Failed to issue login IOCB (%x).\n", rval);
2188 } else if (lg->entry_status != 0) {
2189 ql_dbg(ql_dbg_mbx, vha, 0x1064,
2190 "Failed to complete IOCB -- error status (%x).\n",
2191 lg->entry_status);
2192 rval = QLA_FUNCTION_FAILED;
2193 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
2194 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2195 iop[1] = le32_to_cpu(lg->io_parameter[1]);
2197 ql_dbg(ql_dbg_mbx, vha, 0x1065,
2198 "Failed to complete IOCB -- completion status (%x) "
2199 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2200 iop[0], iop[1]);
2202 switch (iop[0]) {
2203 case LSC_SCODE_PORTID_USED:
2204 mb[0] = MBS_PORT_ID_USED;
2205 mb[1] = LSW(iop[1]);
2206 break;
2207 case LSC_SCODE_NPORT_USED:
2208 mb[0] = MBS_LOOP_ID_USED;
2209 break;
2210 case LSC_SCODE_NOLINK:
2211 case LSC_SCODE_NOIOCB:
2212 case LSC_SCODE_NOXCB:
2213 case LSC_SCODE_CMD_FAILED:
2214 case LSC_SCODE_NOFABRIC:
2215 case LSC_SCODE_FW_NOT_READY:
2216 case LSC_SCODE_NOT_LOGGED_IN:
2217 case LSC_SCODE_NOPCB:
2218 case LSC_SCODE_ELS_REJECT:
2219 case LSC_SCODE_CMD_PARAM_ERR:
2220 case LSC_SCODE_NONPORT:
2221 case LSC_SCODE_LOGGED_IN:
2222 case LSC_SCODE_NOFLOGI_ACC:
2223 default:
2224 mb[0] = MBS_COMMAND_ERROR;
2225 break;
2227 } else {
2228 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1066,
2229 "Done %s.\n", __func__);
2231 iop[0] = le32_to_cpu(lg->io_parameter[0]);
2233 mb[0] = MBS_COMMAND_COMPLETE;
2234 mb[1] = 0;
2235 if (iop[0] & BIT_4) {
2236 if (iop[0] & BIT_8)
2237 mb[1] |= BIT_1;
2238 } else
2239 mb[1] = BIT_0;
2241 /* Passback COS information. */
2242 mb[10] = 0;
2243 if (lg->io_parameter[7] || lg->io_parameter[8])
2244 mb[10] |= BIT_0; /* Class 2. */
2245 if (lg->io_parameter[9] || lg->io_parameter[10])
2246 mb[10] |= BIT_1; /* Class 3. */
2247 if (lg->io_parameter[0] & cpu_to_le32(BIT_7))
2248 mb[10] |= BIT_7; /* Confirmed Completion
2249 * Allowed
2253 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2255 return rval;
2259 * qla2x00_login_fabric
2260 * Issue login fabric port mailbox command.
2262 * Input:
2263 * ha = adapter block pointer.
2264 * loop_id = device loop ID.
2265 * domain = device domain.
2266 * area = device area.
2267 * al_pa = device AL_PA.
2268 * status = pointer for return status.
2269 * opt = command options.
2270 * TARGET_QUEUE_LOCK must be released.
2271 * ADAPTER_STATE_LOCK must be released.
2273 * Returns:
2274 * qla2x00 local function return status code.
2276 * Context:
2277 * Kernel context.
2280 qla2x00_login_fabric(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
2281 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
2283 int rval;
2284 mbx_cmd_t mc;
2285 mbx_cmd_t *mcp = &mc;
2286 struct qla_hw_data *ha = vha->hw;
2288 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1067,
2289 "Entered %s.\n", __func__);
2291 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
2292 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2293 if (HAS_EXTENDED_IDS(ha)) {
2294 mcp->mb[1] = loop_id;
2295 mcp->mb[10] = opt;
2296 mcp->out_mb |= MBX_10;
2297 } else {
2298 mcp->mb[1] = (loop_id << 8) | opt;
2300 mcp->mb[2] = domain;
2301 mcp->mb[3] = area << 8 | al_pa;
2303 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
2304 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2305 mcp->flags = 0;
2306 rval = qla2x00_mailbox_command(vha, mcp);
2308 /* Return mailbox statuses. */
2309 if (mb != NULL) {
2310 mb[0] = mcp->mb[0];
2311 mb[1] = mcp->mb[1];
2312 mb[2] = mcp->mb[2];
2313 mb[6] = mcp->mb[6];
2314 mb[7] = mcp->mb[7];
2315 /* COS retrieved from Get-Port-Database mailbox command. */
2316 mb[10] = 0;
2319 if (rval != QLA_SUCCESS) {
2320 /* RLU tmp code: need to change main mailbox_command function to
2321 * return ok even when the mailbox completion value is not
2322 * SUCCESS. The caller needs to be responsible to interpret
2323 * the return values of this mailbox command if we're not
2324 * to change too much of the existing code.
2326 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
2327 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
2328 mcp->mb[0] == 0x4006)
2329 rval = QLA_SUCCESS;
2331 /*EMPTY*/
2332 ql_dbg(ql_dbg_mbx, vha, 0x1068,
2333 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
2334 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
2335 } else {
2336 /*EMPTY*/
2337 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1069,
2338 "Done %s.\n", __func__);
2341 return rval;
2345 * qla2x00_login_local_device
2346 * Issue login loop port mailbox command.
2348 * Input:
2349 * ha = adapter block pointer.
2350 * loop_id = device loop ID.
2351 * opt = command options.
2353 * Returns:
2354 * Return status code.
2356 * Context:
2357 * Kernel context.
2361 qla2x00_login_local_device(scsi_qla_host_t *vha, fc_port_t *fcport,
2362 uint16_t *mb_ret, uint8_t opt)
2364 int rval;
2365 mbx_cmd_t mc;
2366 mbx_cmd_t *mcp = &mc;
2367 struct qla_hw_data *ha = vha->hw;
2369 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106a,
2370 "Entered %s.\n", __func__);
2372 if (IS_FWI2_CAPABLE(ha))
2373 return qla24xx_login_fabric(vha, fcport->loop_id,
2374 fcport->d_id.b.domain, fcport->d_id.b.area,
2375 fcport->d_id.b.al_pa, mb_ret, opt);
2377 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
2378 if (HAS_EXTENDED_IDS(ha))
2379 mcp->mb[1] = fcport->loop_id;
2380 else
2381 mcp->mb[1] = fcport->loop_id << 8;
2382 mcp->mb[2] = opt;
2383 mcp->out_mb = MBX_2|MBX_1|MBX_0;
2384 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
2385 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2386 mcp->flags = 0;
2387 rval = qla2x00_mailbox_command(vha, mcp);
2389 /* Return mailbox statuses. */
2390 if (mb_ret != NULL) {
2391 mb_ret[0] = mcp->mb[0];
2392 mb_ret[1] = mcp->mb[1];
2393 mb_ret[6] = mcp->mb[6];
2394 mb_ret[7] = mcp->mb[7];
2397 if (rval != QLA_SUCCESS) {
2398 /* AV tmp code: need to change main mailbox_command function to
2399 * return ok even when the mailbox completion value is not
2400 * SUCCESS. The caller needs to be responsible to interpret
2401 * the return values of this mailbox command if we're not
2402 * to change too much of the existing code.
2404 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
2405 rval = QLA_SUCCESS;
2407 ql_dbg(ql_dbg_mbx, vha, 0x106b,
2408 "Failed=%x mb[0]=%x mb[1]=%x mb[6]=%x mb[7]=%x.\n",
2409 rval, mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);
2410 } else {
2411 /*EMPTY*/
2412 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106c,
2413 "Done %s.\n", __func__);
2416 return (rval);
2420 qla24xx_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
2421 uint8_t area, uint8_t al_pa)
2423 int rval;
2424 struct logio_entry_24xx *lg;
2425 dma_addr_t lg_dma;
2426 struct qla_hw_data *ha = vha->hw;
2427 struct req_que *req;
2429 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x106d,
2430 "Entered %s.\n", __func__);
2432 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
2433 if (lg == NULL) {
2434 ql_log(ql_log_warn, vha, 0x106e,
2435 "Failed to allocate logout IOCB.\n");
2436 return QLA_MEMORY_ALLOC_FAILED;
2438 memset(lg, 0, sizeof(struct logio_entry_24xx));
2440 req = vha->req;
2441 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
2442 lg->entry_count = 1;
2443 lg->handle = MAKE_HANDLE(req->id, lg->handle);
2444 lg->nport_handle = cpu_to_le16(loop_id);
2445 lg->control_flags =
2446 cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO|
2447 LCF_FREE_NPORT);
2448 lg->port_id[0] = al_pa;
2449 lg->port_id[1] = area;
2450 lg->port_id[2] = domain;
2451 lg->vp_index = vha->vp_idx;
2452 rval = qla2x00_issue_iocb_timeout(vha, lg, lg_dma, 0,
2453 (ha->r_a_tov / 10 * 2) + 2);
2454 if (rval != QLA_SUCCESS) {
2455 ql_dbg(ql_dbg_mbx, vha, 0x106f,
2456 "Failed to issue logout IOCB (%x).\n", rval);
2457 } else if (lg->entry_status != 0) {
2458 ql_dbg(ql_dbg_mbx, vha, 0x1070,
2459 "Failed to complete IOCB -- error status (%x).\n",
2460 lg->entry_status);
2461 rval = QLA_FUNCTION_FAILED;
2462 } else if (lg->comp_status != cpu_to_le16(CS_COMPLETE)) {
2463 ql_dbg(ql_dbg_mbx, vha, 0x1071,
2464 "Failed to complete IOCB -- completion status (%x) "
2465 "ioparam=%x/%x.\n", le16_to_cpu(lg->comp_status),
2466 le32_to_cpu(lg->io_parameter[0]),
2467 le32_to_cpu(lg->io_parameter[1]));
2468 } else {
2469 /*EMPTY*/
2470 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1072,
2471 "Done %s.\n", __func__);
2474 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
2476 return rval;
2480 * qla2x00_fabric_logout
2481 * Issue logout fabric port mailbox command.
2483 * Input:
2484 * ha = adapter block pointer.
2485 * loop_id = device loop ID.
2486 * TARGET_QUEUE_LOCK must be released.
2487 * ADAPTER_STATE_LOCK must be released.
2489 * Returns:
2490 * qla2x00 local function return status code.
2492 * Context:
2493 * Kernel context.
2496 qla2x00_fabric_logout(scsi_qla_host_t *vha, uint16_t loop_id, uint8_t domain,
2497 uint8_t area, uint8_t al_pa)
2499 int rval;
2500 mbx_cmd_t mc;
2501 mbx_cmd_t *mcp = &mc;
2503 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1073,
2504 "Entered %s.\n", __func__);
2506 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
2507 mcp->out_mb = MBX_1|MBX_0;
2508 if (HAS_EXTENDED_IDS(vha->hw)) {
2509 mcp->mb[1] = loop_id;
2510 mcp->mb[10] = 0;
2511 mcp->out_mb |= MBX_10;
2512 } else {
2513 mcp->mb[1] = loop_id << 8;
2516 mcp->in_mb = MBX_1|MBX_0;
2517 mcp->tov = MBX_TOV_SECONDS;
2518 mcp->flags = 0;
2519 rval = qla2x00_mailbox_command(vha, mcp);
2521 if (rval != QLA_SUCCESS) {
2522 /*EMPTY*/
2523 ql_dbg(ql_dbg_mbx, vha, 0x1074,
2524 "Failed=%x mb[1]=%x.\n", rval, mcp->mb[1]);
2525 } else {
2526 /*EMPTY*/
2527 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1075,
2528 "Done %s.\n", __func__);
2531 return rval;
2535 * qla2x00_full_login_lip
2536 * Issue full login LIP mailbox command.
2538 * Input:
2539 * ha = adapter block pointer.
2540 * TARGET_QUEUE_LOCK must be released.
2541 * ADAPTER_STATE_LOCK must be released.
2543 * Returns:
2544 * qla2x00 local function return status code.
2546 * Context:
2547 * Kernel context.
2550 qla2x00_full_login_lip(scsi_qla_host_t *vha)
2552 int rval;
2553 mbx_cmd_t mc;
2554 mbx_cmd_t *mcp = &mc;
2556 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1076,
2557 "Entered %s.\n", __func__);
2559 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
2560 mcp->mb[1] = IS_FWI2_CAPABLE(vha->hw) ? BIT_3 : 0;
2561 mcp->mb[2] = 0;
2562 mcp->mb[3] = 0;
2563 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
2564 mcp->in_mb = MBX_0;
2565 mcp->tov = MBX_TOV_SECONDS;
2566 mcp->flags = 0;
2567 rval = qla2x00_mailbox_command(vha, mcp);
2569 if (rval != QLA_SUCCESS) {
2570 /*EMPTY*/
2571 ql_dbg(ql_dbg_mbx, vha, 0x1077, "Failed=%x.\n", rval);
2572 } else {
2573 /*EMPTY*/
2574 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1078,
2575 "Done %s.\n", __func__);
2578 return rval;
2582 * qla2x00_get_id_list
2584 * Input:
2585 * ha = adapter block pointer.
2587 * Returns:
2588 * qla2x00 local function return status code.
2590 * Context:
2591 * Kernel context.
2594 qla2x00_get_id_list(scsi_qla_host_t *vha, void *id_list, dma_addr_t id_list_dma,
2595 uint16_t *entries)
2597 int rval;
2598 mbx_cmd_t mc;
2599 mbx_cmd_t *mcp = &mc;
2601 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1079,
2602 "Entered %s.\n", __func__);
2604 if (id_list == NULL)
2605 return QLA_FUNCTION_FAILED;
2607 mcp->mb[0] = MBC_GET_ID_LIST;
2608 mcp->out_mb = MBX_0;
2609 if (IS_FWI2_CAPABLE(vha->hw)) {
2610 mcp->mb[2] = MSW(id_list_dma);
2611 mcp->mb[3] = LSW(id_list_dma);
2612 mcp->mb[6] = MSW(MSD(id_list_dma));
2613 mcp->mb[7] = LSW(MSD(id_list_dma));
2614 mcp->mb[8] = 0;
2615 mcp->mb[9] = vha->vp_idx;
2616 mcp->out_mb |= MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2;
2617 } else {
2618 mcp->mb[1] = MSW(id_list_dma);
2619 mcp->mb[2] = LSW(id_list_dma);
2620 mcp->mb[3] = MSW(MSD(id_list_dma));
2621 mcp->mb[6] = LSW(MSD(id_list_dma));
2622 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
2624 mcp->in_mb = MBX_1|MBX_0;
2625 mcp->tov = MBX_TOV_SECONDS;
2626 mcp->flags = 0;
2627 rval = qla2x00_mailbox_command(vha, mcp);
2629 if (rval != QLA_SUCCESS) {
2630 /*EMPTY*/
2631 ql_dbg(ql_dbg_mbx, vha, 0x107a, "Failed=%x.\n", rval);
2632 } else {
2633 *entries = mcp->mb[1];
2634 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107b,
2635 "Done %s.\n", __func__);
2638 return rval;
2642 * qla2x00_get_resource_cnts
2643 * Get current firmware resource counts.
2645 * Input:
2646 * ha = adapter block pointer.
2648 * Returns:
2649 * qla2x00 local function return status code.
2651 * Context:
2652 * Kernel context.
2655 qla2x00_get_resource_cnts(scsi_qla_host_t *vha)
2657 struct qla_hw_data *ha = vha->hw;
2658 int rval;
2659 mbx_cmd_t mc;
2660 mbx_cmd_t *mcp = &mc;
2662 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107c,
2663 "Entered %s.\n", __func__);
2665 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
2666 mcp->out_mb = MBX_0;
2667 mcp->in_mb = MBX_11|MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
2668 if (IS_QLA81XX(vha->hw) || IS_QLA83XX(vha->hw) || IS_QLA27XX(vha->hw))
2669 mcp->in_mb |= MBX_12;
2670 mcp->tov = MBX_TOV_SECONDS;
2671 mcp->flags = 0;
2672 rval = qla2x00_mailbox_command(vha, mcp);
2674 if (rval != QLA_SUCCESS) {
2675 /*EMPTY*/
2676 ql_dbg(ql_dbg_mbx, vha, 0x107d,
2677 "Failed mb[0]=%x.\n", mcp->mb[0]);
2678 } else {
2679 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107e,
2680 "Done %s mb1=%x mb2=%x mb3=%x mb6=%x mb7=%x mb10=%x "
2681 "mb11=%x mb12=%x.\n", __func__, mcp->mb[1], mcp->mb[2],
2682 mcp->mb[3], mcp->mb[6], mcp->mb[7], mcp->mb[10],
2683 mcp->mb[11], mcp->mb[12]);
2685 ha->orig_fw_tgt_xcb_count = mcp->mb[1];
2686 ha->cur_fw_tgt_xcb_count = mcp->mb[2];
2687 ha->cur_fw_xcb_count = mcp->mb[3];
2688 ha->orig_fw_xcb_count = mcp->mb[6];
2689 ha->cur_fw_iocb_count = mcp->mb[7];
2690 ha->orig_fw_iocb_count = mcp->mb[10];
2691 if (ha->flags.npiv_supported)
2692 ha->max_npiv_vports = mcp->mb[11];
2693 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
2694 ha->fw_max_fcf_count = mcp->mb[12];
2697 return (rval);
2701 * qla2x00_get_fcal_position_map
2702 * Get FCAL (LILP) position map using mailbox command
2704 * Input:
2705 * ha = adapter state pointer.
2706 * pos_map = buffer pointer (can be NULL).
2708 * Returns:
2709 * qla2x00 local function return status code.
2711 * Context:
2712 * Kernel context.
2715 qla2x00_get_fcal_position_map(scsi_qla_host_t *vha, char *pos_map)
2717 int rval;
2718 mbx_cmd_t mc;
2719 mbx_cmd_t *mcp = &mc;
2720 char *pmap;
2721 dma_addr_t pmap_dma;
2722 struct qla_hw_data *ha = vha->hw;
2724 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x107f,
2725 "Entered %s.\n", __func__);
2727 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pmap_dma);
2728 if (pmap == NULL) {
2729 ql_log(ql_log_warn, vha, 0x1080,
2730 "Memory alloc failed.\n");
2731 return QLA_MEMORY_ALLOC_FAILED;
2733 memset(pmap, 0, FCAL_MAP_SIZE);
2735 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
2736 mcp->mb[2] = MSW(pmap_dma);
2737 mcp->mb[3] = LSW(pmap_dma);
2738 mcp->mb[6] = MSW(MSD(pmap_dma));
2739 mcp->mb[7] = LSW(MSD(pmap_dma));
2740 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2741 mcp->in_mb = MBX_1|MBX_0;
2742 mcp->buf_size = FCAL_MAP_SIZE;
2743 mcp->flags = MBX_DMA_IN;
2744 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
2745 rval = qla2x00_mailbox_command(vha, mcp);
2747 if (rval == QLA_SUCCESS) {
2748 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1081,
2749 "mb0/mb1=%x/%X FC/AL position map size (%x).\n",
2750 mcp->mb[0], mcp->mb[1], (unsigned)pmap[0]);
2751 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111d,
2752 pmap, pmap[0] + 1);
2754 if (pos_map)
2755 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2757 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2759 if (rval != QLA_SUCCESS) {
2760 ql_dbg(ql_dbg_mbx, vha, 0x1082, "Failed=%x.\n", rval);
2761 } else {
2762 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1083,
2763 "Done %s.\n", __func__);
2766 return rval;
2770 * qla2x00_get_link_status
2772 * Input:
2773 * ha = adapter block pointer.
2774 * loop_id = device loop ID.
2775 * ret_buf = pointer to link status return buffer.
2777 * Returns:
2778 * 0 = success.
2779 * BIT_0 = mem alloc error.
2780 * BIT_1 = mailbox error.
2783 qla2x00_get_link_status(scsi_qla_host_t *vha, uint16_t loop_id,
2784 struct link_statistics *stats, dma_addr_t stats_dma)
2786 int rval;
2787 mbx_cmd_t mc;
2788 mbx_cmd_t *mcp = &mc;
2789 uint32_t *iter = (void *)stats;
2790 ushort dwords = offsetof(typeof(*stats), link_up_cnt)/sizeof(*iter);
2791 struct qla_hw_data *ha = vha->hw;
2793 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1084,
2794 "Entered %s.\n", __func__);
2796 mcp->mb[0] = MBC_GET_LINK_STATUS;
2797 mcp->mb[2] = MSW(LSD(stats_dma));
2798 mcp->mb[3] = LSW(LSD(stats_dma));
2799 mcp->mb[6] = MSW(MSD(stats_dma));
2800 mcp->mb[7] = LSW(MSD(stats_dma));
2801 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2802 mcp->in_mb = MBX_0;
2803 if (IS_FWI2_CAPABLE(ha)) {
2804 mcp->mb[1] = loop_id;
2805 mcp->mb[4] = 0;
2806 mcp->mb[10] = 0;
2807 mcp->out_mb |= MBX_10|MBX_4|MBX_1;
2808 mcp->in_mb |= MBX_1;
2809 } else if (HAS_EXTENDED_IDS(ha)) {
2810 mcp->mb[1] = loop_id;
2811 mcp->mb[10] = 0;
2812 mcp->out_mb |= MBX_10|MBX_1;
2813 } else {
2814 mcp->mb[1] = loop_id << 8;
2815 mcp->out_mb |= MBX_1;
2817 mcp->tov = MBX_TOV_SECONDS;
2818 mcp->flags = IOCTL_CMD;
2819 rval = qla2x00_mailbox_command(vha, mcp);
2821 if (rval == QLA_SUCCESS) {
2822 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2823 ql_dbg(ql_dbg_mbx, vha, 0x1085,
2824 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
2825 rval = QLA_FUNCTION_FAILED;
2826 } else {
2827 /* Re-endianize - firmware data is le32. */
2828 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1086,
2829 "Done %s.\n", __func__);
2830 for ( ; dwords--; iter++)
2831 le32_to_cpus(iter);
2833 } else {
2834 /* Failed. */
2835 ql_dbg(ql_dbg_mbx, vha, 0x1087, "Failed=%x.\n", rval);
2838 return rval;
2842 qla24xx_get_isp_stats(scsi_qla_host_t *vha, struct link_statistics *stats,
2843 dma_addr_t stats_dma, uint16_t options)
2845 int rval;
2846 mbx_cmd_t mc;
2847 mbx_cmd_t *mcp = &mc;
2848 uint32_t *iter, dwords;
2850 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1088,
2851 "Entered %s.\n", __func__);
2853 memset(&mc, 0, sizeof(mc));
2854 mc.mb[0] = MBC_GET_LINK_PRIV_STATS;
2855 mc.mb[2] = MSW(stats_dma);
2856 mc.mb[3] = LSW(stats_dma);
2857 mc.mb[6] = MSW(MSD(stats_dma));
2858 mc.mb[7] = LSW(MSD(stats_dma));
2859 mc.mb[8] = sizeof(struct link_statistics) / 4;
2860 mc.mb[9] = cpu_to_le16(vha->vp_idx);
2861 mc.mb[10] = cpu_to_le16(options);
2863 rval = qla24xx_send_mb_cmd(vha, &mc);
2865 if (rval == QLA_SUCCESS) {
2866 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2867 ql_dbg(ql_dbg_mbx, vha, 0x1089,
2868 "Failed mb[0]=%x.\n", mcp->mb[0]);
2869 rval = QLA_FUNCTION_FAILED;
2870 } else {
2871 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108a,
2872 "Done %s.\n", __func__);
2873 /* Re-endianize - firmware data is le32. */
2874 dwords = sizeof(struct link_statistics) / 4;
2875 iter = &stats->link_fail_cnt;
2876 for ( ; dwords--; iter++)
2877 le32_to_cpus(iter);
2879 } else {
2880 /* Failed. */
2881 ql_dbg(ql_dbg_mbx, vha, 0x108b, "Failed=%x.\n", rval);
2884 return rval;
2888 qla24xx_abort_command(srb_t *sp)
2890 int rval;
2891 unsigned long flags = 0;
2893 struct abort_entry_24xx *abt;
2894 dma_addr_t abt_dma;
2895 uint32_t handle;
2896 fc_port_t *fcport = sp->fcport;
2897 struct scsi_qla_host *vha = fcport->vha;
2898 struct qla_hw_data *ha = vha->hw;
2899 struct req_que *req = vha->req;
2901 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x108c,
2902 "Entered %s.\n", __func__);
2904 if (vha->flags.qpairs_available && sp->qpair)
2905 req = sp->qpair->req;
2907 if (ql2xasynctmfenable)
2908 return qla24xx_async_abort_command(sp);
2910 spin_lock_irqsave(&ha->hardware_lock, flags);
2911 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
2912 if (req->outstanding_cmds[handle] == sp)
2913 break;
2915 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2916 if (handle == req->num_outstanding_cmds) {
2917 /* Command not found. */
2918 return QLA_FUNCTION_FAILED;
2921 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2922 if (abt == NULL) {
2923 ql_log(ql_log_warn, vha, 0x108d,
2924 "Failed to allocate abort IOCB.\n");
2925 return QLA_MEMORY_ALLOC_FAILED;
2927 memset(abt, 0, sizeof(struct abort_entry_24xx));
2929 abt->entry_type = ABORT_IOCB_TYPE;
2930 abt->entry_count = 1;
2931 abt->handle = MAKE_HANDLE(req->id, abt->handle);
2932 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2933 abt->handle_to_abort = MAKE_HANDLE(req->id, handle);
2934 abt->port_id[0] = fcport->d_id.b.al_pa;
2935 abt->port_id[1] = fcport->d_id.b.area;
2936 abt->port_id[2] = fcport->d_id.b.domain;
2937 abt->vp_index = fcport->vha->vp_idx;
2939 abt->req_que_no = cpu_to_le16(req->id);
2941 rval = qla2x00_issue_iocb(vha, abt, abt_dma, 0);
2942 if (rval != QLA_SUCCESS) {
2943 ql_dbg(ql_dbg_mbx, vha, 0x108e,
2944 "Failed to issue IOCB (%x).\n", rval);
2945 } else if (abt->entry_status != 0) {
2946 ql_dbg(ql_dbg_mbx, vha, 0x108f,
2947 "Failed to complete IOCB -- error status (%x).\n",
2948 abt->entry_status);
2949 rval = QLA_FUNCTION_FAILED;
2950 } else if (abt->nport_handle != cpu_to_le16(0)) {
2951 ql_dbg(ql_dbg_mbx, vha, 0x1090,
2952 "Failed to complete IOCB -- completion status (%x).\n",
2953 le16_to_cpu(abt->nport_handle));
2954 if (abt->nport_handle == CS_IOCB_ERROR)
2955 rval = QLA_FUNCTION_PARAMETER_ERROR;
2956 else
2957 rval = QLA_FUNCTION_FAILED;
2958 } else {
2959 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1091,
2960 "Done %s.\n", __func__);
2963 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2965 return rval;
2968 struct tsk_mgmt_cmd {
2969 union {
2970 struct tsk_mgmt_entry tsk;
2971 struct sts_entry_24xx sts;
2972 } p;
2975 static int
2976 __qla24xx_issue_tmf(char *name, uint32_t type, struct fc_port *fcport,
2977 uint64_t l, int tag)
2979 int rval, rval2;
2980 struct tsk_mgmt_cmd *tsk;
2981 struct sts_entry_24xx *sts;
2982 dma_addr_t tsk_dma;
2983 scsi_qla_host_t *vha;
2984 struct qla_hw_data *ha;
2985 struct req_que *req;
2986 struct rsp_que *rsp;
2987 struct qla_qpair *qpair;
2989 vha = fcport->vha;
2990 ha = vha->hw;
2991 req = vha->req;
2993 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1092,
2994 "Entered %s.\n", __func__);
2996 if (vha->vp_idx && vha->qpair) {
2997 /* NPIV port */
2998 qpair = vha->qpair;
2999 rsp = qpair->rsp;
3000 req = qpair->req;
3001 } else {
3002 rsp = req->rsp;
3005 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
3006 if (tsk == NULL) {
3007 ql_log(ql_log_warn, vha, 0x1093,
3008 "Failed to allocate task management IOCB.\n");
3009 return QLA_MEMORY_ALLOC_FAILED;
3011 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
3013 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
3014 tsk->p.tsk.entry_count = 1;
3015 tsk->p.tsk.handle = MAKE_HANDLE(req->id, tsk->p.tsk.handle);
3016 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
3017 tsk->p.tsk.timeout = cpu_to_le16(ha->r_a_tov / 10 * 2);
3018 tsk->p.tsk.control_flags = cpu_to_le32(type);
3019 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
3020 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
3021 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
3022 tsk->p.tsk.vp_index = fcport->vha->vp_idx;
3023 if (type == TCF_LUN_RESET) {
3024 int_to_scsilun(l, &tsk->p.tsk.lun);
3025 host_to_fcp_swap((uint8_t *)&tsk->p.tsk.lun,
3026 sizeof(tsk->p.tsk.lun));
3029 sts = &tsk->p.sts;
3030 rval = qla2x00_issue_iocb(vha, tsk, tsk_dma, 0);
3031 if (rval != QLA_SUCCESS) {
3032 ql_dbg(ql_dbg_mbx, vha, 0x1094,
3033 "Failed to issue %s reset IOCB (%x).\n", name, rval);
3034 } else if (sts->entry_status != 0) {
3035 ql_dbg(ql_dbg_mbx, vha, 0x1095,
3036 "Failed to complete IOCB -- error status (%x).\n",
3037 sts->entry_status);
3038 rval = QLA_FUNCTION_FAILED;
3039 } else if (sts->comp_status != cpu_to_le16(CS_COMPLETE)) {
3040 ql_dbg(ql_dbg_mbx, vha, 0x1096,
3041 "Failed to complete IOCB -- completion status (%x).\n",
3042 le16_to_cpu(sts->comp_status));
3043 rval = QLA_FUNCTION_FAILED;
3044 } else if (le16_to_cpu(sts->scsi_status) &
3045 SS_RESPONSE_INFO_LEN_VALID) {
3046 if (le32_to_cpu(sts->rsp_data_len) < 4) {
3047 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1097,
3048 "Ignoring inconsistent data length -- not enough "
3049 "response info (%d).\n",
3050 le32_to_cpu(sts->rsp_data_len));
3051 } else if (sts->data[3]) {
3052 ql_dbg(ql_dbg_mbx, vha, 0x1098,
3053 "Failed to complete IOCB -- response (%x).\n",
3054 sts->data[3]);
3055 rval = QLA_FUNCTION_FAILED;
3059 /* Issue marker IOCB. */
3060 rval2 = qla2x00_marker(vha, req, rsp, fcport->loop_id, l,
3061 type == TCF_LUN_RESET ? MK_SYNC_ID_LUN: MK_SYNC_ID);
3062 if (rval2 != QLA_SUCCESS) {
3063 ql_dbg(ql_dbg_mbx, vha, 0x1099,
3064 "Failed to issue marker IOCB (%x).\n", rval2);
3065 } else {
3066 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109a,
3067 "Done %s.\n", __func__);
3070 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
3072 return rval;
3076 qla24xx_abort_target(struct fc_port *fcport, uint64_t l, int tag)
3078 struct qla_hw_data *ha = fcport->vha->hw;
3080 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3081 return qla2x00_async_tm_cmd(fcport, TCF_TARGET_RESET, l, tag);
3083 return __qla24xx_issue_tmf("Target", TCF_TARGET_RESET, fcport, l, tag);
3087 qla24xx_lun_reset(struct fc_port *fcport, uint64_t l, int tag)
3089 struct qla_hw_data *ha = fcport->vha->hw;
3091 if ((ql2xasynctmfenable) && IS_FWI2_CAPABLE(ha))
3092 return qla2x00_async_tm_cmd(fcport, TCF_LUN_RESET, l, tag);
3094 return __qla24xx_issue_tmf("Lun", TCF_LUN_RESET, fcport, l, tag);
3098 qla2x00_system_error(scsi_qla_host_t *vha)
3100 int rval;
3101 mbx_cmd_t mc;
3102 mbx_cmd_t *mcp = &mc;
3103 struct qla_hw_data *ha = vha->hw;
3105 if (!IS_QLA23XX(ha) && !IS_FWI2_CAPABLE(ha))
3106 return QLA_FUNCTION_FAILED;
3108 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109b,
3109 "Entered %s.\n", __func__);
3111 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
3112 mcp->out_mb = MBX_0;
3113 mcp->in_mb = MBX_0;
3114 mcp->tov = 5;
3115 mcp->flags = 0;
3116 rval = qla2x00_mailbox_command(vha, mcp);
3118 if (rval != QLA_SUCCESS) {
3119 ql_dbg(ql_dbg_mbx, vha, 0x109c, "Failed=%x.\n", rval);
3120 } else {
3121 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109d,
3122 "Done %s.\n", __func__);
3125 return rval;
3129 qla2x00_write_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t data)
3131 int rval;
3132 mbx_cmd_t mc;
3133 mbx_cmd_t *mcp = &mc;
3135 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3136 !IS_QLA27XX(vha->hw))
3137 return QLA_FUNCTION_FAILED;
3139 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1182,
3140 "Entered %s.\n", __func__);
3142 mcp->mb[0] = MBC_WRITE_SERDES;
3143 mcp->mb[1] = addr;
3144 if (IS_QLA2031(vha->hw))
3145 mcp->mb[2] = data & 0xff;
3146 else
3147 mcp->mb[2] = data;
3149 mcp->mb[3] = 0;
3150 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
3151 mcp->in_mb = MBX_0;
3152 mcp->tov = MBX_TOV_SECONDS;
3153 mcp->flags = 0;
3154 rval = qla2x00_mailbox_command(vha, mcp);
3156 if (rval != QLA_SUCCESS) {
3157 ql_dbg(ql_dbg_mbx, vha, 0x1183,
3158 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3159 } else {
3160 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1184,
3161 "Done %s.\n", __func__);
3164 return rval;
3168 qla2x00_read_serdes_word(scsi_qla_host_t *vha, uint16_t addr, uint16_t *data)
3170 int rval;
3171 mbx_cmd_t mc;
3172 mbx_cmd_t *mcp = &mc;
3174 if (!IS_QLA25XX(vha->hw) && !IS_QLA2031(vha->hw) &&
3175 !IS_QLA27XX(vha->hw))
3176 return QLA_FUNCTION_FAILED;
3178 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1185,
3179 "Entered %s.\n", __func__);
3181 mcp->mb[0] = MBC_READ_SERDES;
3182 mcp->mb[1] = addr;
3183 mcp->mb[3] = 0;
3184 mcp->out_mb = MBX_3|MBX_1|MBX_0;
3185 mcp->in_mb = MBX_1|MBX_0;
3186 mcp->tov = MBX_TOV_SECONDS;
3187 mcp->flags = 0;
3188 rval = qla2x00_mailbox_command(vha, mcp);
3190 if (IS_QLA2031(vha->hw))
3191 *data = mcp->mb[1] & 0xff;
3192 else
3193 *data = mcp->mb[1];
3195 if (rval != QLA_SUCCESS) {
3196 ql_dbg(ql_dbg_mbx, vha, 0x1186,
3197 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3198 } else {
3199 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1187,
3200 "Done %s.\n", __func__);
3203 return rval;
3207 qla8044_write_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t data)
3209 int rval;
3210 mbx_cmd_t mc;
3211 mbx_cmd_t *mcp = &mc;
3213 if (!IS_QLA8044(vha->hw))
3214 return QLA_FUNCTION_FAILED;
3216 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1186,
3217 "Entered %s.\n", __func__);
3219 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3220 mcp->mb[1] = HCS_WRITE_SERDES;
3221 mcp->mb[3] = LSW(addr);
3222 mcp->mb[4] = MSW(addr);
3223 mcp->mb[5] = LSW(data);
3224 mcp->mb[6] = MSW(data);
3225 mcp->out_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_1|MBX_0;
3226 mcp->in_mb = MBX_0;
3227 mcp->tov = MBX_TOV_SECONDS;
3228 mcp->flags = 0;
3229 rval = qla2x00_mailbox_command(vha, mcp);
3231 if (rval != QLA_SUCCESS) {
3232 ql_dbg(ql_dbg_mbx, vha, 0x1187,
3233 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3234 } else {
3235 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1188,
3236 "Done %s.\n", __func__);
3239 return rval;
3243 qla8044_read_serdes_word(scsi_qla_host_t *vha, uint32_t addr, uint32_t *data)
3245 int rval;
3246 mbx_cmd_t mc;
3247 mbx_cmd_t *mcp = &mc;
3249 if (!IS_QLA8044(vha->hw))
3250 return QLA_FUNCTION_FAILED;
3252 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1189,
3253 "Entered %s.\n", __func__);
3255 mcp->mb[0] = MBC_SET_GET_ETH_SERDES_REG;
3256 mcp->mb[1] = HCS_READ_SERDES;
3257 mcp->mb[3] = LSW(addr);
3258 mcp->mb[4] = MSW(addr);
3259 mcp->out_mb = MBX_4|MBX_3|MBX_1|MBX_0;
3260 mcp->in_mb = MBX_2|MBX_1|MBX_0;
3261 mcp->tov = MBX_TOV_SECONDS;
3262 mcp->flags = 0;
3263 rval = qla2x00_mailbox_command(vha, mcp);
3265 *data = mcp->mb[2] << 16 | mcp->mb[1];
3267 if (rval != QLA_SUCCESS) {
3268 ql_dbg(ql_dbg_mbx, vha, 0x118a,
3269 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3270 } else {
3271 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x118b,
3272 "Done %s.\n", __func__);
3275 return rval;
3279 * qla2x00_set_serdes_params() -
3280 * @ha: HA context
3282 * Returns
3285 qla2x00_set_serdes_params(scsi_qla_host_t *vha, uint16_t sw_em_1g,
3286 uint16_t sw_em_2g, uint16_t sw_em_4g)
3288 int rval;
3289 mbx_cmd_t mc;
3290 mbx_cmd_t *mcp = &mc;
3292 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x109e,
3293 "Entered %s.\n", __func__);
3295 mcp->mb[0] = MBC_SERDES_PARAMS;
3296 mcp->mb[1] = BIT_0;
3297 mcp->mb[2] = sw_em_1g | BIT_15;
3298 mcp->mb[3] = sw_em_2g | BIT_15;
3299 mcp->mb[4] = sw_em_4g | BIT_15;
3300 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3301 mcp->in_mb = MBX_0;
3302 mcp->tov = MBX_TOV_SECONDS;
3303 mcp->flags = 0;
3304 rval = qla2x00_mailbox_command(vha, mcp);
3306 if (rval != QLA_SUCCESS) {
3307 /*EMPTY*/
3308 ql_dbg(ql_dbg_mbx, vha, 0x109f,
3309 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3310 } else {
3311 /*EMPTY*/
3312 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a0,
3313 "Done %s.\n", __func__);
3316 return rval;
3320 qla2x00_stop_firmware(scsi_qla_host_t *vha)
3322 int rval;
3323 mbx_cmd_t mc;
3324 mbx_cmd_t *mcp = &mc;
3326 if (!IS_FWI2_CAPABLE(vha->hw))
3327 return QLA_FUNCTION_FAILED;
3329 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a1,
3330 "Entered %s.\n", __func__);
3332 mcp->mb[0] = MBC_STOP_FIRMWARE;
3333 mcp->mb[1] = 0;
3334 mcp->out_mb = MBX_1|MBX_0;
3335 mcp->in_mb = MBX_0;
3336 mcp->tov = 5;
3337 mcp->flags = 0;
3338 rval = qla2x00_mailbox_command(vha, mcp);
3340 if (rval != QLA_SUCCESS) {
3341 ql_dbg(ql_dbg_mbx, vha, 0x10a2, "Failed=%x.\n", rval);
3342 if (mcp->mb[0] == MBS_INVALID_COMMAND)
3343 rval = QLA_INVALID_COMMAND;
3344 } else {
3345 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a3,
3346 "Done %s.\n", __func__);
3349 return rval;
3353 qla2x00_enable_eft_trace(scsi_qla_host_t *vha, dma_addr_t eft_dma,
3354 uint16_t buffers)
3356 int rval;
3357 mbx_cmd_t mc;
3358 mbx_cmd_t *mcp = &mc;
3360 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a4,
3361 "Entered %s.\n", __func__);
3363 if (!IS_FWI2_CAPABLE(vha->hw))
3364 return QLA_FUNCTION_FAILED;
3366 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3367 return QLA_FUNCTION_FAILED;
3369 mcp->mb[0] = MBC_TRACE_CONTROL;
3370 mcp->mb[1] = TC_EFT_ENABLE;
3371 mcp->mb[2] = LSW(eft_dma);
3372 mcp->mb[3] = MSW(eft_dma);
3373 mcp->mb[4] = LSW(MSD(eft_dma));
3374 mcp->mb[5] = MSW(MSD(eft_dma));
3375 mcp->mb[6] = buffers;
3376 mcp->mb[7] = TC_AEN_DISABLE;
3377 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|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 if (rval != QLA_SUCCESS) {
3383 ql_dbg(ql_dbg_mbx, vha, 0x10a5,
3384 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3385 rval, mcp->mb[0], mcp->mb[1]);
3386 } else {
3387 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a6,
3388 "Done %s.\n", __func__);
3391 return rval;
3395 qla2x00_disable_eft_trace(scsi_qla_host_t *vha)
3397 int rval;
3398 mbx_cmd_t mc;
3399 mbx_cmd_t *mcp = &mc;
3401 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a7,
3402 "Entered %s.\n", __func__);
3404 if (!IS_FWI2_CAPABLE(vha->hw))
3405 return QLA_FUNCTION_FAILED;
3407 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3408 return QLA_FUNCTION_FAILED;
3410 mcp->mb[0] = MBC_TRACE_CONTROL;
3411 mcp->mb[1] = TC_EFT_DISABLE;
3412 mcp->out_mb = MBX_1|MBX_0;
3413 mcp->in_mb = MBX_1|MBX_0;
3414 mcp->tov = MBX_TOV_SECONDS;
3415 mcp->flags = 0;
3416 rval = qla2x00_mailbox_command(vha, mcp);
3417 if (rval != QLA_SUCCESS) {
3418 ql_dbg(ql_dbg_mbx, vha, 0x10a8,
3419 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3420 rval, mcp->mb[0], mcp->mb[1]);
3421 } else {
3422 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10a9,
3423 "Done %s.\n", __func__);
3426 return rval;
3430 qla2x00_enable_fce_trace(scsi_qla_host_t *vha, dma_addr_t fce_dma,
3431 uint16_t buffers, uint16_t *mb, uint32_t *dwords)
3433 int rval;
3434 mbx_cmd_t mc;
3435 mbx_cmd_t *mcp = &mc;
3437 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10aa,
3438 "Entered %s.\n", __func__);
3440 if (!IS_QLA25XX(vha->hw) && !IS_QLA81XX(vha->hw) &&
3441 !IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
3442 return QLA_FUNCTION_FAILED;
3444 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3445 return QLA_FUNCTION_FAILED;
3447 mcp->mb[0] = MBC_TRACE_CONTROL;
3448 mcp->mb[1] = TC_FCE_ENABLE;
3449 mcp->mb[2] = LSW(fce_dma);
3450 mcp->mb[3] = MSW(fce_dma);
3451 mcp->mb[4] = LSW(MSD(fce_dma));
3452 mcp->mb[5] = MSW(MSD(fce_dma));
3453 mcp->mb[6] = buffers;
3454 mcp->mb[7] = TC_AEN_DISABLE;
3455 mcp->mb[8] = 0;
3456 mcp->mb[9] = TC_FCE_DEFAULT_RX_SIZE;
3457 mcp->mb[10] = TC_FCE_DEFAULT_TX_SIZE;
3458 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3459 MBX_1|MBX_0;
3460 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
3461 mcp->tov = MBX_TOV_SECONDS;
3462 mcp->flags = 0;
3463 rval = qla2x00_mailbox_command(vha, mcp);
3464 if (rval != QLA_SUCCESS) {
3465 ql_dbg(ql_dbg_mbx, vha, 0x10ab,
3466 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3467 rval, mcp->mb[0], mcp->mb[1]);
3468 } else {
3469 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ac,
3470 "Done %s.\n", __func__);
3472 if (mb)
3473 memcpy(mb, mcp->mb, 8 * sizeof(*mb));
3474 if (dwords)
3475 *dwords = buffers;
3478 return rval;
3482 qla2x00_disable_fce_trace(scsi_qla_host_t *vha, uint64_t *wr, uint64_t *rd)
3484 int rval;
3485 mbx_cmd_t mc;
3486 mbx_cmd_t *mcp = &mc;
3488 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ad,
3489 "Entered %s.\n", __func__);
3491 if (!IS_FWI2_CAPABLE(vha->hw))
3492 return QLA_FUNCTION_FAILED;
3494 if (unlikely(pci_channel_offline(vha->hw->pdev)))
3495 return QLA_FUNCTION_FAILED;
3497 mcp->mb[0] = MBC_TRACE_CONTROL;
3498 mcp->mb[1] = TC_FCE_DISABLE;
3499 mcp->mb[2] = TC_FCE_DISABLE_TRACE;
3500 mcp->out_mb = MBX_2|MBX_1|MBX_0;
3501 mcp->in_mb = MBX_9|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|
3502 MBX_1|MBX_0;
3503 mcp->tov = MBX_TOV_SECONDS;
3504 mcp->flags = 0;
3505 rval = qla2x00_mailbox_command(vha, mcp);
3506 if (rval != QLA_SUCCESS) {
3507 ql_dbg(ql_dbg_mbx, vha, 0x10ae,
3508 "Failed=%x mb[0]=%x mb[1]=%x.\n",
3509 rval, mcp->mb[0], mcp->mb[1]);
3510 } else {
3511 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10af,
3512 "Done %s.\n", __func__);
3514 if (wr)
3515 *wr = (uint64_t) mcp->mb[5] << 48 |
3516 (uint64_t) mcp->mb[4] << 32 |
3517 (uint64_t) mcp->mb[3] << 16 |
3518 (uint64_t) mcp->mb[2];
3519 if (rd)
3520 *rd = (uint64_t) mcp->mb[9] << 48 |
3521 (uint64_t) mcp->mb[8] << 32 |
3522 (uint64_t) mcp->mb[7] << 16 |
3523 (uint64_t) mcp->mb[6];
3526 return rval;
3530 qla2x00_get_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3531 uint16_t *port_speed, uint16_t *mb)
3533 int rval;
3534 mbx_cmd_t mc;
3535 mbx_cmd_t *mcp = &mc;
3537 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b0,
3538 "Entered %s.\n", __func__);
3540 if (!IS_IIDMA_CAPABLE(vha->hw))
3541 return QLA_FUNCTION_FAILED;
3543 mcp->mb[0] = MBC_PORT_PARAMS;
3544 mcp->mb[1] = loop_id;
3545 mcp->mb[2] = mcp->mb[3] = 0;
3546 mcp->mb[9] = vha->vp_idx;
3547 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3548 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3549 mcp->tov = MBX_TOV_SECONDS;
3550 mcp->flags = 0;
3551 rval = qla2x00_mailbox_command(vha, mcp);
3553 /* Return mailbox statuses. */
3554 if (mb != NULL) {
3555 mb[0] = mcp->mb[0];
3556 mb[1] = mcp->mb[1];
3557 mb[3] = mcp->mb[3];
3560 if (rval != QLA_SUCCESS) {
3561 ql_dbg(ql_dbg_mbx, vha, 0x10b1, "Failed=%x.\n", rval);
3562 } else {
3563 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b2,
3564 "Done %s.\n", __func__);
3565 if (port_speed)
3566 *port_speed = mcp->mb[3];
3569 return rval;
3573 qla2x00_set_idma_speed(scsi_qla_host_t *vha, uint16_t loop_id,
3574 uint16_t port_speed, uint16_t *mb)
3576 int rval;
3577 mbx_cmd_t mc;
3578 mbx_cmd_t *mcp = &mc;
3580 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b3,
3581 "Entered %s.\n", __func__);
3583 if (!IS_IIDMA_CAPABLE(vha->hw))
3584 return QLA_FUNCTION_FAILED;
3586 mcp->mb[0] = MBC_PORT_PARAMS;
3587 mcp->mb[1] = loop_id;
3588 mcp->mb[2] = BIT_0;
3589 if (IS_CNA_CAPABLE(vha->hw))
3590 mcp->mb[3] = port_speed & (BIT_5|BIT_4|BIT_3|BIT_2|BIT_1|BIT_0);
3591 else
3592 mcp->mb[3] = port_speed & (BIT_2|BIT_1|BIT_0);
3593 mcp->mb[9] = vha->vp_idx;
3594 mcp->out_mb = MBX_9|MBX_3|MBX_2|MBX_1|MBX_0;
3595 mcp->in_mb = MBX_3|MBX_1|MBX_0;
3596 mcp->tov = MBX_TOV_SECONDS;
3597 mcp->flags = 0;
3598 rval = qla2x00_mailbox_command(vha, mcp);
3600 /* Return mailbox statuses. */
3601 if (mb != NULL) {
3602 mb[0] = mcp->mb[0];
3603 mb[1] = mcp->mb[1];
3604 mb[3] = mcp->mb[3];
3607 if (rval != QLA_SUCCESS) {
3608 ql_dbg(ql_dbg_mbx, vha, 0x10b4,
3609 "Failed=%x.\n", rval);
3610 } else {
3611 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b5,
3612 "Done %s.\n", __func__);
3615 return rval;
3618 void
3619 qla24xx_report_id_acquisition(scsi_qla_host_t *vha,
3620 struct vp_rpt_id_entry_24xx *rptid_entry)
3622 struct qla_hw_data *ha = vha->hw;
3623 scsi_qla_host_t *vp = NULL;
3624 unsigned long flags;
3625 int found;
3626 port_id_t id;
3628 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10b6,
3629 "Entered %s.\n", __func__);
3631 if (rptid_entry->entry_status != 0)
3632 return;
3634 id.b.domain = rptid_entry->port_id[2];
3635 id.b.area = rptid_entry->port_id[1];
3636 id.b.al_pa = rptid_entry->port_id[0];
3637 id.b.rsvd_1 = 0;
3639 if (rptid_entry->format == 0) {
3640 /* loop */
3641 ql_dbg(ql_dbg_async, vha, 0x10b7,
3642 "Format 0 : Number of VPs setup %d, number of "
3643 "VPs acquired %d.\n", rptid_entry->vp_setup,
3644 rptid_entry->vp_acquired);
3645 ql_dbg(ql_dbg_async, vha, 0x10b8,
3646 "Primary port id %02x%02x%02x.\n",
3647 rptid_entry->port_id[2], rptid_entry->port_id[1],
3648 rptid_entry->port_id[0]);
3650 qlt_update_host_map(vha, id);
3652 } else if (rptid_entry->format == 1) {
3653 /* fabric */
3654 ql_dbg(ql_dbg_async, vha, 0x10b9,
3655 "Format 1: VP[%d] enabled - status %d - with "
3656 "port id %02x%02x%02x.\n", rptid_entry->vp_idx,
3657 rptid_entry->vp_status,
3658 rptid_entry->port_id[2], rptid_entry->port_id[1],
3659 rptid_entry->port_id[0]);
3661 /* buffer to buffer credit flag */
3662 vha->flags.bbcr_enable = (rptid_entry->u.f1.bbcr & 0xf) != 0;
3664 if (rptid_entry->vp_idx == 0) {
3665 if (rptid_entry->vp_status == VP_STAT_COMPL) {
3666 /* FA-WWN is only for physical port */
3667 if (qla_ini_mode_enabled(vha) &&
3668 ha->flags.fawwpn_enabled &&
3669 (rptid_entry->u.f1.flags &
3670 VP_FLAGS_NAME_VALID)) {
3671 memcpy(vha->port_name,
3672 rptid_entry->u.f1.port_name,
3673 WWN_SIZE);
3676 qlt_update_host_map(vha, id);
3679 set_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags);
3680 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
3681 } else {
3682 if (rptid_entry->vp_status != VP_STAT_COMPL &&
3683 rptid_entry->vp_status != VP_STAT_ID_CHG) {
3684 ql_dbg(ql_dbg_mbx, vha, 0x10ba,
3685 "Could not acquire ID for VP[%d].\n",
3686 rptid_entry->vp_idx);
3687 return;
3690 found = 0;
3691 spin_lock_irqsave(&ha->vport_slock, flags);
3692 list_for_each_entry(vp, &ha->vp_list, list) {
3693 if (rptid_entry->vp_idx == vp->vp_idx) {
3694 found = 1;
3695 break;
3698 spin_unlock_irqrestore(&ha->vport_slock, flags);
3700 if (!found)
3701 return;
3703 qlt_update_host_map(vp, id);
3706 * Cannot configure here as we are still sitting on the
3707 * response queue. Handle it in dpc context.
3709 set_bit(VP_IDX_ACQUIRED, &vp->vp_flags);
3710 set_bit(REGISTER_FC4_NEEDED, &vp->dpc_flags);
3711 set_bit(REGISTER_FDMI_NEEDED, &vp->dpc_flags);
3713 set_bit(VP_DPC_NEEDED, &vha->dpc_flags);
3714 qla2xxx_wake_dpc(vha);
3715 } else if (rptid_entry->format == 2) {
3716 ql_dbg(ql_dbg_async, vha, 0xffff,
3717 "RIDA: format 2/N2N Primary port id %02x%02x%02x.\n",
3718 rptid_entry->port_id[2], rptid_entry->port_id[1],
3719 rptid_entry->port_id[0]);
3721 ql_dbg(ql_dbg_async, vha, 0xffff,
3722 "N2N: Remote WWPN %8phC.\n",
3723 rptid_entry->u.f2.port_name);
3725 /* N2N. direct connect */
3726 vha->d_id.b.domain = rptid_entry->port_id[2];
3727 vha->d_id.b.area = rptid_entry->port_id[1];
3728 vha->d_id.b.al_pa = rptid_entry->port_id[0];
3730 spin_lock_irqsave(&ha->vport_slock, flags);
3731 qlt_update_vp_map(vha, SET_AL_PA);
3732 spin_unlock_irqrestore(&ha->vport_slock, flags);
3737 * qla24xx_modify_vp_config
3738 * Change VP configuration for vha
3740 * Input:
3741 * vha = adapter block pointer.
3743 * Returns:
3744 * qla2xxx local function return status code.
3746 * Context:
3747 * Kernel context.
3750 qla24xx_modify_vp_config(scsi_qla_host_t *vha)
3752 int rval;
3753 struct vp_config_entry_24xx *vpmod;
3754 dma_addr_t vpmod_dma;
3755 struct qla_hw_data *ha = vha->hw;
3756 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3758 /* This can be called by the parent */
3760 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10bb,
3761 "Entered %s.\n", __func__);
3763 vpmod = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vpmod_dma);
3764 if (!vpmod) {
3765 ql_log(ql_log_warn, vha, 0x10bc,
3766 "Failed to allocate modify VP IOCB.\n");
3767 return QLA_MEMORY_ALLOC_FAILED;
3770 memset(vpmod, 0, sizeof(struct vp_config_entry_24xx));
3771 vpmod->entry_type = VP_CONFIG_IOCB_TYPE;
3772 vpmod->entry_count = 1;
3773 vpmod->command = VCT_COMMAND_MOD_ENABLE_VPS;
3774 vpmod->vp_count = 1;
3775 vpmod->vp_index1 = vha->vp_idx;
3776 vpmod->options_idx1 = BIT_3|BIT_4|BIT_5;
3778 qlt_modify_vp_config(vha, vpmod);
3780 memcpy(vpmod->node_name_idx1, vha->node_name, WWN_SIZE);
3781 memcpy(vpmod->port_name_idx1, vha->port_name, WWN_SIZE);
3782 vpmod->entry_count = 1;
3784 rval = qla2x00_issue_iocb(base_vha, vpmod, vpmod_dma, 0);
3785 if (rval != QLA_SUCCESS) {
3786 ql_dbg(ql_dbg_mbx, vha, 0x10bd,
3787 "Failed to issue VP config IOCB (%x).\n", rval);
3788 } else if (vpmod->comp_status != 0) {
3789 ql_dbg(ql_dbg_mbx, vha, 0x10be,
3790 "Failed to complete IOCB -- error status (%x).\n",
3791 vpmod->comp_status);
3792 rval = QLA_FUNCTION_FAILED;
3793 } else if (vpmod->comp_status != cpu_to_le16(CS_COMPLETE)) {
3794 ql_dbg(ql_dbg_mbx, vha, 0x10bf,
3795 "Failed to complete IOCB -- completion status (%x).\n",
3796 le16_to_cpu(vpmod->comp_status));
3797 rval = QLA_FUNCTION_FAILED;
3798 } else {
3799 /* EMPTY */
3800 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c0,
3801 "Done %s.\n", __func__);
3802 fc_vport_set_state(vha->fc_vport, FC_VPORT_INITIALIZING);
3804 dma_pool_free(ha->s_dma_pool, vpmod, vpmod_dma);
3806 return rval;
3810 * qla24xx_control_vp
3811 * Enable a virtual port for given host
3813 * Input:
3814 * ha = adapter block pointer.
3815 * vhba = virtual adapter (unused)
3816 * index = index number for enabled VP
3818 * Returns:
3819 * qla2xxx local function return status code.
3821 * Context:
3822 * Kernel context.
3825 qla24xx_control_vp(scsi_qla_host_t *vha, int cmd)
3827 int rval;
3828 int map, pos;
3829 struct vp_ctrl_entry_24xx *vce;
3830 dma_addr_t vce_dma;
3831 struct qla_hw_data *ha = vha->hw;
3832 int vp_index = vha->vp_idx;
3833 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3835 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c1,
3836 "Entered %s enabling index %d.\n", __func__, vp_index);
3838 if (vp_index == 0 || vp_index >= ha->max_npiv_vports)
3839 return QLA_PARAMETER_ERROR;
3841 vce = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &vce_dma);
3842 if (!vce) {
3843 ql_log(ql_log_warn, vha, 0x10c2,
3844 "Failed to allocate VP control IOCB.\n");
3845 return QLA_MEMORY_ALLOC_FAILED;
3847 memset(vce, 0, sizeof(struct vp_ctrl_entry_24xx));
3849 vce->entry_type = VP_CTRL_IOCB_TYPE;
3850 vce->entry_count = 1;
3851 vce->command = cpu_to_le16(cmd);
3852 vce->vp_count = cpu_to_le16(1);
3854 /* index map in firmware starts with 1; decrement index
3855 * this is ok as we never use index 0
3857 map = (vp_index - 1) / 8;
3858 pos = (vp_index - 1) & 7;
3859 mutex_lock(&ha->vport_lock);
3860 vce->vp_idx_map[map] |= 1 << pos;
3861 mutex_unlock(&ha->vport_lock);
3863 rval = qla2x00_issue_iocb(base_vha, vce, vce_dma, 0);
3864 if (rval != QLA_SUCCESS) {
3865 ql_dbg(ql_dbg_mbx, vha, 0x10c3,
3866 "Failed to issue VP control IOCB (%x).\n", rval);
3867 } else if (vce->entry_status != 0) {
3868 ql_dbg(ql_dbg_mbx, vha, 0x10c4,
3869 "Failed to complete IOCB -- error status (%x).\n",
3870 vce->entry_status);
3871 rval = QLA_FUNCTION_FAILED;
3872 } else if (vce->comp_status != cpu_to_le16(CS_COMPLETE)) {
3873 ql_dbg(ql_dbg_mbx, vha, 0x10c5,
3874 "Failed to complet IOCB -- completion status (%x).\n",
3875 le16_to_cpu(vce->comp_status));
3876 rval = QLA_FUNCTION_FAILED;
3877 } else {
3878 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c6,
3879 "Done %s.\n", __func__);
3882 dma_pool_free(ha->s_dma_pool, vce, vce_dma);
3884 return rval;
3888 * qla2x00_send_change_request
3889 * Receive or disable RSCN request from fabric controller
3891 * Input:
3892 * ha = adapter block pointer
3893 * format = registration format:
3894 * 0 - Reserved
3895 * 1 - Fabric detected registration
3896 * 2 - N_port detected registration
3897 * 3 - Full registration
3898 * FF - clear registration
3899 * vp_idx = Virtual port index
3901 * Returns:
3902 * qla2x00 local function return status code.
3904 * Context:
3905 * Kernel Context
3909 qla2x00_send_change_request(scsi_qla_host_t *vha, uint16_t format,
3910 uint16_t vp_idx)
3912 int rval;
3913 mbx_cmd_t mc;
3914 mbx_cmd_t *mcp = &mc;
3916 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c7,
3917 "Entered %s.\n", __func__);
3919 mcp->mb[0] = MBC_SEND_CHANGE_REQUEST;
3920 mcp->mb[1] = format;
3921 mcp->mb[9] = vp_idx;
3922 mcp->out_mb = MBX_9|MBX_1|MBX_0;
3923 mcp->in_mb = MBX_0|MBX_1;
3924 mcp->tov = MBX_TOV_SECONDS;
3925 mcp->flags = 0;
3926 rval = qla2x00_mailbox_command(vha, mcp);
3928 if (rval == QLA_SUCCESS) {
3929 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
3930 rval = BIT_1;
3932 } else
3933 rval = BIT_1;
3935 return rval;
3939 qla2x00_dump_ram(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
3940 uint32_t size)
3942 int rval;
3943 mbx_cmd_t mc;
3944 mbx_cmd_t *mcp = &mc;
3946 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1009,
3947 "Entered %s.\n", __func__);
3949 if (MSW(addr) || IS_FWI2_CAPABLE(vha->hw)) {
3950 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
3951 mcp->mb[8] = MSW(addr);
3952 mcp->out_mb = MBX_8|MBX_0;
3953 } else {
3954 mcp->mb[0] = MBC_DUMP_RISC_RAM;
3955 mcp->out_mb = MBX_0;
3957 mcp->mb[1] = LSW(addr);
3958 mcp->mb[2] = MSW(req_dma);
3959 mcp->mb[3] = LSW(req_dma);
3960 mcp->mb[6] = MSW(MSD(req_dma));
3961 mcp->mb[7] = LSW(MSD(req_dma));
3962 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
3963 if (IS_FWI2_CAPABLE(vha->hw)) {
3964 mcp->mb[4] = MSW(size);
3965 mcp->mb[5] = LSW(size);
3966 mcp->out_mb |= MBX_5|MBX_4;
3967 } else {
3968 mcp->mb[4] = LSW(size);
3969 mcp->out_mb |= MBX_4;
3972 mcp->in_mb = MBX_0;
3973 mcp->tov = MBX_TOV_SECONDS;
3974 mcp->flags = 0;
3975 rval = qla2x00_mailbox_command(vha, mcp);
3977 if (rval != QLA_SUCCESS) {
3978 ql_dbg(ql_dbg_mbx, vha, 0x1008,
3979 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
3980 } else {
3981 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1007,
3982 "Done %s.\n", __func__);
3985 return rval;
3987 /* 84XX Support **************************************************************/
3989 struct cs84xx_mgmt_cmd {
3990 union {
3991 struct verify_chip_entry_84xx req;
3992 struct verify_chip_rsp_84xx rsp;
3993 } p;
3997 qla84xx_verify_chip(struct scsi_qla_host *vha, uint16_t *status)
3999 int rval, retry;
4000 struct cs84xx_mgmt_cmd *mn;
4001 dma_addr_t mn_dma;
4002 uint16_t options;
4003 unsigned long flags;
4004 struct qla_hw_data *ha = vha->hw;
4006 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10c8,
4007 "Entered %s.\n", __func__);
4009 mn = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &mn_dma);
4010 if (mn == NULL) {
4011 return QLA_MEMORY_ALLOC_FAILED;
4014 /* Force Update? */
4015 options = ha->cs84xx->fw_update ? VCO_FORCE_UPDATE : 0;
4016 /* Diagnostic firmware? */
4017 /* options |= MENLO_DIAG_FW; */
4018 /* We update the firmware with only one data sequence. */
4019 options |= VCO_END_OF_DATA;
4021 do {
4022 retry = 0;
4023 memset(mn, 0, sizeof(*mn));
4024 mn->p.req.entry_type = VERIFY_CHIP_IOCB_TYPE;
4025 mn->p.req.entry_count = 1;
4026 mn->p.req.options = cpu_to_le16(options);
4028 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111c,
4029 "Dump of Verify Request.\n");
4030 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x111e,
4031 (uint8_t *)mn, sizeof(*mn));
4033 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
4034 if (rval != QLA_SUCCESS) {
4035 ql_dbg(ql_dbg_mbx, vha, 0x10cb,
4036 "Failed to issue verify IOCB (%x).\n", rval);
4037 goto verify_done;
4040 ql_dbg(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1110,
4041 "Dump of Verify Response.\n");
4042 ql_dump_buffer(ql_dbg_mbx + ql_dbg_buffer, vha, 0x1118,
4043 (uint8_t *)mn, sizeof(*mn));
4045 status[0] = le16_to_cpu(mn->p.rsp.comp_status);
4046 status[1] = status[0] == CS_VCS_CHIP_FAILURE ?
4047 le16_to_cpu(mn->p.rsp.failure_code) : 0;
4048 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ce,
4049 "cs=%x fc=%x.\n", status[0], status[1]);
4051 if (status[0] != CS_COMPLETE) {
4052 rval = QLA_FUNCTION_FAILED;
4053 if (!(options & VCO_DONT_UPDATE_FW)) {
4054 ql_dbg(ql_dbg_mbx, vha, 0x10cf,
4055 "Firmware update failed. Retrying "
4056 "without update firmware.\n");
4057 options |= VCO_DONT_UPDATE_FW;
4058 options &= ~VCO_FORCE_UPDATE;
4059 retry = 1;
4061 } else {
4062 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d0,
4063 "Firmware updated to %x.\n",
4064 le32_to_cpu(mn->p.rsp.fw_ver));
4066 /* NOTE: we only update OP firmware. */
4067 spin_lock_irqsave(&ha->cs84xx->access_lock, flags);
4068 ha->cs84xx->op_fw_version =
4069 le32_to_cpu(mn->p.rsp.fw_ver);
4070 spin_unlock_irqrestore(&ha->cs84xx->access_lock,
4071 flags);
4073 } while (retry);
4075 verify_done:
4076 dma_pool_free(ha->s_dma_pool, mn, mn_dma);
4078 if (rval != QLA_SUCCESS) {
4079 ql_dbg(ql_dbg_mbx, vha, 0x10d1,
4080 "Failed=%x.\n", rval);
4081 } else {
4082 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d2,
4083 "Done %s.\n", __func__);
4086 return rval;
4090 qla25xx_init_req_que(struct scsi_qla_host *vha, struct req_que *req)
4092 int rval;
4093 unsigned long flags;
4094 mbx_cmd_t mc;
4095 mbx_cmd_t *mcp = &mc;
4096 struct qla_hw_data *ha = vha->hw;
4098 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d3,
4099 "Entered %s.\n", __func__);
4101 if (IS_SHADOW_REG_CAPABLE(ha))
4102 req->options |= BIT_13;
4104 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
4105 mcp->mb[1] = req->options;
4106 mcp->mb[2] = MSW(LSD(req->dma));
4107 mcp->mb[3] = LSW(LSD(req->dma));
4108 mcp->mb[6] = MSW(MSD(req->dma));
4109 mcp->mb[7] = LSW(MSD(req->dma));
4110 mcp->mb[5] = req->length;
4111 if (req->rsp)
4112 mcp->mb[10] = req->rsp->id;
4113 mcp->mb[12] = req->qos;
4114 mcp->mb[11] = req->vp_idx;
4115 mcp->mb[13] = req->rid;
4116 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
4117 mcp->mb[15] = 0;
4119 mcp->mb[4] = req->id;
4120 /* que in ptr index */
4121 mcp->mb[8] = 0;
4122 /* que out ptr index */
4123 mcp->mb[9] = *req->out_ptr = 0;
4124 mcp->out_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|MBX_7|
4125 MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4126 mcp->in_mb = MBX_0;
4127 mcp->flags = MBX_DMA_OUT;
4128 mcp->tov = MBX_TOV_SECONDS * 2;
4130 if (IS_QLA81XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha))
4131 mcp->in_mb |= MBX_1;
4132 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
4133 mcp->out_mb |= MBX_15;
4134 /* debug q create issue in SR-IOV */
4135 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4138 spin_lock_irqsave(&ha->hardware_lock, flags);
4139 if (!(req->options & BIT_0)) {
4140 WRT_REG_DWORD(req->req_q_in, 0);
4141 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
4142 WRT_REG_DWORD(req->req_q_out, 0);
4144 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4146 rval = qla2x00_mailbox_command(vha, mcp);
4147 if (rval != QLA_SUCCESS) {
4148 ql_dbg(ql_dbg_mbx, vha, 0x10d4,
4149 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4150 } else {
4151 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d5,
4152 "Done %s.\n", __func__);
4155 return rval;
4159 qla25xx_init_rsp_que(struct scsi_qla_host *vha, struct rsp_que *rsp)
4161 int rval;
4162 unsigned long flags;
4163 mbx_cmd_t mc;
4164 mbx_cmd_t *mcp = &mc;
4165 struct qla_hw_data *ha = vha->hw;
4167 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d6,
4168 "Entered %s.\n", __func__);
4170 if (IS_SHADOW_REG_CAPABLE(ha))
4171 rsp->options |= BIT_13;
4173 mcp->mb[0] = MBC_INITIALIZE_MULTIQ;
4174 mcp->mb[1] = rsp->options;
4175 mcp->mb[2] = MSW(LSD(rsp->dma));
4176 mcp->mb[3] = LSW(LSD(rsp->dma));
4177 mcp->mb[6] = MSW(MSD(rsp->dma));
4178 mcp->mb[7] = LSW(MSD(rsp->dma));
4179 mcp->mb[5] = rsp->length;
4180 mcp->mb[14] = rsp->msix->entry;
4181 mcp->mb[13] = rsp->rid;
4182 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
4183 mcp->mb[15] = 0;
4185 mcp->mb[4] = rsp->id;
4186 /* que in ptr index */
4187 mcp->mb[8] = *rsp->in_ptr = 0;
4188 /* que out ptr index */
4189 mcp->mb[9] = 0;
4190 mcp->out_mb = MBX_14|MBX_13|MBX_9|MBX_8|MBX_7
4191 |MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4192 mcp->in_mb = MBX_0;
4193 mcp->flags = MBX_DMA_OUT;
4194 mcp->tov = MBX_TOV_SECONDS * 2;
4196 if (IS_QLA81XX(ha)) {
4197 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
4198 mcp->in_mb |= MBX_1;
4199 } else if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
4200 mcp->out_mb |= MBX_15|MBX_12|MBX_11|MBX_10;
4201 mcp->in_mb |= MBX_1;
4202 /* debug q create issue in SR-IOV */
4203 mcp->in_mb |= MBX_9 | MBX_8 | MBX_7;
4206 spin_lock_irqsave(&ha->hardware_lock, flags);
4207 if (!(rsp->options & BIT_0)) {
4208 WRT_REG_DWORD(rsp->rsp_q_out, 0);
4209 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
4210 WRT_REG_DWORD(rsp->rsp_q_in, 0);
4213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4215 rval = qla2x00_mailbox_command(vha, mcp);
4216 if (rval != QLA_SUCCESS) {
4217 ql_dbg(ql_dbg_mbx, vha, 0x10d7,
4218 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4219 } else {
4220 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d8,
4221 "Done %s.\n", __func__);
4224 return rval;
4228 qla81xx_idc_ack(scsi_qla_host_t *vha, uint16_t *mb)
4230 int rval;
4231 mbx_cmd_t mc;
4232 mbx_cmd_t *mcp = &mc;
4234 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10d9,
4235 "Entered %s.\n", __func__);
4237 mcp->mb[0] = MBC_IDC_ACK;
4238 memcpy(&mcp->mb[1], mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
4239 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4240 mcp->in_mb = MBX_0;
4241 mcp->tov = MBX_TOV_SECONDS;
4242 mcp->flags = 0;
4243 rval = qla2x00_mailbox_command(vha, mcp);
4245 if (rval != QLA_SUCCESS) {
4246 ql_dbg(ql_dbg_mbx, vha, 0x10da,
4247 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4248 } else {
4249 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10db,
4250 "Done %s.\n", __func__);
4253 return rval;
4257 qla81xx_fac_get_sector_size(scsi_qla_host_t *vha, uint32_t *sector_size)
4259 int rval;
4260 mbx_cmd_t mc;
4261 mbx_cmd_t *mcp = &mc;
4263 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10dc,
4264 "Entered %s.\n", __func__);
4266 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4267 !IS_QLA27XX(vha->hw))
4268 return QLA_FUNCTION_FAILED;
4270 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4271 mcp->mb[1] = FAC_OPT_CMD_GET_SECTOR_SIZE;
4272 mcp->out_mb = MBX_1|MBX_0;
4273 mcp->in_mb = MBX_1|MBX_0;
4274 mcp->tov = MBX_TOV_SECONDS;
4275 mcp->flags = 0;
4276 rval = qla2x00_mailbox_command(vha, mcp);
4278 if (rval != QLA_SUCCESS) {
4279 ql_dbg(ql_dbg_mbx, vha, 0x10dd,
4280 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4281 rval, mcp->mb[0], mcp->mb[1]);
4282 } else {
4283 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10de,
4284 "Done %s.\n", __func__);
4285 *sector_size = mcp->mb[1];
4288 return rval;
4292 qla81xx_fac_do_write_enable(scsi_qla_host_t *vha, int enable)
4294 int rval;
4295 mbx_cmd_t mc;
4296 mbx_cmd_t *mcp = &mc;
4298 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4299 !IS_QLA27XX(vha->hw))
4300 return QLA_FUNCTION_FAILED;
4302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10df,
4303 "Entered %s.\n", __func__);
4305 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4306 mcp->mb[1] = enable ? FAC_OPT_CMD_WRITE_ENABLE :
4307 FAC_OPT_CMD_WRITE_PROTECT;
4308 mcp->out_mb = MBX_1|MBX_0;
4309 mcp->in_mb = MBX_1|MBX_0;
4310 mcp->tov = MBX_TOV_SECONDS;
4311 mcp->flags = 0;
4312 rval = qla2x00_mailbox_command(vha, mcp);
4314 if (rval != QLA_SUCCESS) {
4315 ql_dbg(ql_dbg_mbx, vha, 0x10e0,
4316 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4317 rval, mcp->mb[0], mcp->mb[1]);
4318 } else {
4319 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e1,
4320 "Done %s.\n", __func__);
4323 return rval;
4327 qla81xx_fac_erase_sector(scsi_qla_host_t *vha, uint32_t start, uint32_t finish)
4329 int rval;
4330 mbx_cmd_t mc;
4331 mbx_cmd_t *mcp = &mc;
4333 if (!IS_QLA81XX(vha->hw) && !IS_QLA83XX(vha->hw) &&
4334 !IS_QLA27XX(vha->hw))
4335 return QLA_FUNCTION_FAILED;
4337 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e2,
4338 "Entered %s.\n", __func__);
4340 mcp->mb[0] = MBC_FLASH_ACCESS_CTRL;
4341 mcp->mb[1] = FAC_OPT_CMD_ERASE_SECTOR;
4342 mcp->mb[2] = LSW(start);
4343 mcp->mb[3] = MSW(start);
4344 mcp->mb[4] = LSW(finish);
4345 mcp->mb[5] = MSW(finish);
4346 mcp->out_mb = MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
4347 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4348 mcp->tov = MBX_TOV_SECONDS;
4349 mcp->flags = 0;
4350 rval = qla2x00_mailbox_command(vha, mcp);
4352 if (rval != QLA_SUCCESS) {
4353 ql_dbg(ql_dbg_mbx, vha, 0x10e3,
4354 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4355 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
4356 } else {
4357 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e4,
4358 "Done %s.\n", __func__);
4361 return rval;
4365 qla81xx_restart_mpi_firmware(scsi_qla_host_t *vha)
4367 int rval = 0;
4368 mbx_cmd_t mc;
4369 mbx_cmd_t *mcp = &mc;
4371 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e5,
4372 "Entered %s.\n", __func__);
4374 mcp->mb[0] = MBC_RESTART_MPI_FW;
4375 mcp->out_mb = MBX_0;
4376 mcp->in_mb = MBX_0|MBX_1;
4377 mcp->tov = MBX_TOV_SECONDS;
4378 mcp->flags = 0;
4379 rval = qla2x00_mailbox_command(vha, mcp);
4381 if (rval != QLA_SUCCESS) {
4382 ql_dbg(ql_dbg_mbx, vha, 0x10e6,
4383 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4384 rval, mcp->mb[0], mcp->mb[1]);
4385 } else {
4386 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e7,
4387 "Done %s.\n", __func__);
4390 return rval;
4394 qla82xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4396 int rval;
4397 mbx_cmd_t mc;
4398 mbx_cmd_t *mcp = &mc;
4399 int i;
4400 int len;
4401 uint16_t *str;
4402 struct qla_hw_data *ha = vha->hw;
4404 if (!IS_P3P_TYPE(ha))
4405 return QLA_FUNCTION_FAILED;
4407 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117b,
4408 "Entered %s.\n", __func__);
4410 str = (void *)version;
4411 len = strlen(version);
4413 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4414 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8;
4415 mcp->out_mb = MBX_1|MBX_0;
4416 for (i = 4; i < 16 && len; i++, str++, len -= 2) {
4417 mcp->mb[i] = cpu_to_le16p(str);
4418 mcp->out_mb |= 1<<i;
4420 for (; i < 16; i++) {
4421 mcp->mb[i] = 0;
4422 mcp->out_mb |= 1<<i;
4424 mcp->in_mb = MBX_1|MBX_0;
4425 mcp->tov = MBX_TOV_SECONDS;
4426 mcp->flags = 0;
4427 rval = qla2x00_mailbox_command(vha, mcp);
4429 if (rval != QLA_SUCCESS) {
4430 ql_dbg(ql_dbg_mbx, vha, 0x117c,
4431 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4432 } else {
4433 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117d,
4434 "Done %s.\n", __func__);
4437 return rval;
4441 qla25xx_set_driver_version(scsi_qla_host_t *vha, char *version)
4443 int rval;
4444 mbx_cmd_t mc;
4445 mbx_cmd_t *mcp = &mc;
4446 int len;
4447 uint16_t dwlen;
4448 uint8_t *str;
4449 dma_addr_t str_dma;
4450 struct qla_hw_data *ha = vha->hw;
4452 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha) ||
4453 IS_P3P_TYPE(ha))
4454 return QLA_FUNCTION_FAILED;
4456 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x117e,
4457 "Entered %s.\n", __func__);
4459 str = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &str_dma);
4460 if (!str) {
4461 ql_log(ql_log_warn, vha, 0x117f,
4462 "Failed to allocate driver version param.\n");
4463 return QLA_MEMORY_ALLOC_FAILED;
4466 memcpy(str, "\x7\x3\x11\x0", 4);
4467 dwlen = str[0];
4468 len = dwlen * 4 - 4;
4469 memset(str + 4, 0, len);
4470 if (len > strlen(version))
4471 len = strlen(version);
4472 memcpy(str + 4, version, len);
4474 mcp->mb[0] = MBC_SET_RNID_PARAMS;
4475 mcp->mb[1] = RNID_TYPE_SET_VERSION << 8 | dwlen;
4476 mcp->mb[2] = MSW(LSD(str_dma));
4477 mcp->mb[3] = LSW(LSD(str_dma));
4478 mcp->mb[6] = MSW(MSD(str_dma));
4479 mcp->mb[7] = LSW(MSD(str_dma));
4480 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4481 mcp->in_mb = MBX_1|MBX_0;
4482 mcp->tov = MBX_TOV_SECONDS;
4483 mcp->flags = 0;
4484 rval = qla2x00_mailbox_command(vha, mcp);
4486 if (rval != QLA_SUCCESS) {
4487 ql_dbg(ql_dbg_mbx, vha, 0x1180,
4488 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4489 } else {
4490 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1181,
4491 "Done %s.\n", __func__);
4494 dma_pool_free(ha->s_dma_pool, str, str_dma);
4496 return rval;
4499 static int
4500 qla2x00_read_asic_temperature(scsi_qla_host_t *vha, uint16_t *temp)
4502 int rval;
4503 mbx_cmd_t mc;
4504 mbx_cmd_t *mcp = &mc;
4506 if (!IS_FWI2_CAPABLE(vha->hw))
4507 return QLA_FUNCTION_FAILED;
4509 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1159,
4510 "Entered %s.\n", __func__);
4512 mcp->mb[0] = MBC_GET_RNID_PARAMS;
4513 mcp->mb[1] = RNID_TYPE_ASIC_TEMP << 8;
4514 mcp->out_mb = MBX_1|MBX_0;
4515 mcp->in_mb = MBX_1|MBX_0;
4516 mcp->tov = MBX_TOV_SECONDS;
4517 mcp->flags = 0;
4518 rval = qla2x00_mailbox_command(vha, mcp);
4519 *temp = mcp->mb[1];
4521 if (rval != QLA_SUCCESS) {
4522 ql_dbg(ql_dbg_mbx, vha, 0x115a,
4523 "Failed=%x mb[0]=%x,%x.\n", rval, mcp->mb[0], mcp->mb[1]);
4524 } else {
4525 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x115b,
4526 "Done %s.\n", __func__);
4529 return rval;
4533 qla2x00_read_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4534 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
4536 int rval;
4537 mbx_cmd_t mc;
4538 mbx_cmd_t *mcp = &mc;
4539 struct qla_hw_data *ha = vha->hw;
4541 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10e8,
4542 "Entered %s.\n", __func__);
4544 if (!IS_FWI2_CAPABLE(ha))
4545 return QLA_FUNCTION_FAILED;
4547 if (len == 1)
4548 opt |= BIT_0;
4550 mcp->mb[0] = MBC_READ_SFP;
4551 mcp->mb[1] = dev;
4552 mcp->mb[2] = MSW(sfp_dma);
4553 mcp->mb[3] = LSW(sfp_dma);
4554 mcp->mb[6] = MSW(MSD(sfp_dma));
4555 mcp->mb[7] = LSW(MSD(sfp_dma));
4556 mcp->mb[8] = len;
4557 mcp->mb[9] = off;
4558 mcp->mb[10] = opt;
4559 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4560 mcp->in_mb = MBX_1|MBX_0;
4561 mcp->tov = MBX_TOV_SECONDS;
4562 mcp->flags = 0;
4563 rval = qla2x00_mailbox_command(vha, mcp);
4565 if (opt & BIT_0)
4566 *sfp = mcp->mb[1];
4568 if (rval != QLA_SUCCESS) {
4569 ql_dbg(ql_dbg_mbx, vha, 0x10e9,
4570 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4571 } else {
4572 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ea,
4573 "Done %s.\n", __func__);
4576 return rval;
4580 qla2x00_write_sfp(scsi_qla_host_t *vha, dma_addr_t sfp_dma, uint8_t *sfp,
4581 uint16_t dev, uint16_t off, uint16_t len, uint16_t opt)
4583 int rval;
4584 mbx_cmd_t mc;
4585 mbx_cmd_t *mcp = &mc;
4586 struct qla_hw_data *ha = vha->hw;
4588 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10eb,
4589 "Entered %s.\n", __func__);
4591 if (!IS_FWI2_CAPABLE(ha))
4592 return QLA_FUNCTION_FAILED;
4594 if (len == 1)
4595 opt |= BIT_0;
4597 if (opt & BIT_0)
4598 len = *sfp;
4600 mcp->mb[0] = MBC_WRITE_SFP;
4601 mcp->mb[1] = dev;
4602 mcp->mb[2] = MSW(sfp_dma);
4603 mcp->mb[3] = LSW(sfp_dma);
4604 mcp->mb[6] = MSW(MSD(sfp_dma));
4605 mcp->mb[7] = LSW(MSD(sfp_dma));
4606 mcp->mb[8] = len;
4607 mcp->mb[9] = off;
4608 mcp->mb[10] = opt;
4609 mcp->out_mb = MBX_10|MBX_9|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4610 mcp->in_mb = MBX_1|MBX_0;
4611 mcp->tov = MBX_TOV_SECONDS;
4612 mcp->flags = 0;
4613 rval = qla2x00_mailbox_command(vha, mcp);
4615 if (rval != QLA_SUCCESS) {
4616 ql_dbg(ql_dbg_mbx, vha, 0x10ec,
4617 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4618 } else {
4619 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ed,
4620 "Done %s.\n", __func__);
4623 return rval;
4627 qla2x00_get_xgmac_stats(scsi_qla_host_t *vha, dma_addr_t stats_dma,
4628 uint16_t size_in_bytes, uint16_t *actual_size)
4630 int rval;
4631 mbx_cmd_t mc;
4632 mbx_cmd_t *mcp = &mc;
4634 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ee,
4635 "Entered %s.\n", __func__);
4637 if (!IS_CNA_CAPABLE(vha->hw))
4638 return QLA_FUNCTION_FAILED;
4640 mcp->mb[0] = MBC_GET_XGMAC_STATS;
4641 mcp->mb[2] = MSW(stats_dma);
4642 mcp->mb[3] = LSW(stats_dma);
4643 mcp->mb[6] = MSW(MSD(stats_dma));
4644 mcp->mb[7] = LSW(MSD(stats_dma));
4645 mcp->mb[8] = size_in_bytes >> 2;
4646 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
4647 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4648 mcp->tov = MBX_TOV_SECONDS;
4649 mcp->flags = 0;
4650 rval = qla2x00_mailbox_command(vha, mcp);
4652 if (rval != QLA_SUCCESS) {
4653 ql_dbg(ql_dbg_mbx, vha, 0x10ef,
4654 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4655 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
4656 } else {
4657 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f0,
4658 "Done %s.\n", __func__);
4661 *actual_size = mcp->mb[2] << 2;
4664 return rval;
4668 qla2x00_get_dcbx_params(scsi_qla_host_t *vha, dma_addr_t tlv_dma,
4669 uint16_t size)
4671 int rval;
4672 mbx_cmd_t mc;
4673 mbx_cmd_t *mcp = &mc;
4675 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f1,
4676 "Entered %s.\n", __func__);
4678 if (!IS_CNA_CAPABLE(vha->hw))
4679 return QLA_FUNCTION_FAILED;
4681 mcp->mb[0] = MBC_GET_DCBX_PARAMS;
4682 mcp->mb[1] = 0;
4683 mcp->mb[2] = MSW(tlv_dma);
4684 mcp->mb[3] = LSW(tlv_dma);
4685 mcp->mb[6] = MSW(MSD(tlv_dma));
4686 mcp->mb[7] = LSW(MSD(tlv_dma));
4687 mcp->mb[8] = size;
4688 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
4689 mcp->in_mb = MBX_2|MBX_1|MBX_0;
4690 mcp->tov = MBX_TOV_SECONDS;
4691 mcp->flags = 0;
4692 rval = qla2x00_mailbox_command(vha, mcp);
4694 if (rval != QLA_SUCCESS) {
4695 ql_dbg(ql_dbg_mbx, vha, 0x10f2,
4696 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x.\n",
4697 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2]);
4698 } else {
4699 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f3,
4700 "Done %s.\n", __func__);
4703 return rval;
4707 qla2x00_read_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t *data)
4709 int rval;
4710 mbx_cmd_t mc;
4711 mbx_cmd_t *mcp = &mc;
4713 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f4,
4714 "Entered %s.\n", __func__);
4716 if (!IS_FWI2_CAPABLE(vha->hw))
4717 return QLA_FUNCTION_FAILED;
4719 mcp->mb[0] = MBC_READ_RAM_EXTENDED;
4720 mcp->mb[1] = LSW(risc_addr);
4721 mcp->mb[8] = MSW(risc_addr);
4722 mcp->out_mb = MBX_8|MBX_1|MBX_0;
4723 mcp->in_mb = MBX_3|MBX_2|MBX_0;
4724 mcp->tov = 30;
4725 mcp->flags = 0;
4726 rval = qla2x00_mailbox_command(vha, mcp);
4727 if (rval != QLA_SUCCESS) {
4728 ql_dbg(ql_dbg_mbx, vha, 0x10f5,
4729 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4730 } else {
4731 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f6,
4732 "Done %s.\n", __func__);
4733 *data = mcp->mb[3] << 16 | mcp->mb[2];
4736 return rval;
4740 qla2x00_loopback_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4741 uint16_t *mresp)
4743 int rval;
4744 mbx_cmd_t mc;
4745 mbx_cmd_t *mcp = &mc;
4747 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f7,
4748 "Entered %s.\n", __func__);
4750 memset(mcp->mb, 0 , sizeof(mcp->mb));
4751 mcp->mb[0] = MBC_DIAGNOSTIC_LOOP_BACK;
4752 mcp->mb[1] = mreq->options | BIT_6; // BIT_6 specifies 64 bit addressing
4754 /* transfer count */
4755 mcp->mb[10] = LSW(mreq->transfer_size);
4756 mcp->mb[11] = MSW(mreq->transfer_size);
4758 /* send data address */
4759 mcp->mb[14] = LSW(mreq->send_dma);
4760 mcp->mb[15] = MSW(mreq->send_dma);
4761 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4762 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4764 /* receive data address */
4765 mcp->mb[16] = LSW(mreq->rcv_dma);
4766 mcp->mb[17] = MSW(mreq->rcv_dma);
4767 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4768 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4770 /* Iteration count */
4771 mcp->mb[18] = LSW(mreq->iteration_count);
4772 mcp->mb[19] = MSW(mreq->iteration_count);
4774 mcp->out_mb = MBX_21|MBX_20|MBX_19|MBX_18|MBX_17|MBX_16|MBX_15|
4775 MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
4776 if (IS_CNA_CAPABLE(vha->hw))
4777 mcp->out_mb |= MBX_2;
4778 mcp->in_mb = MBX_19|MBX_18|MBX_3|MBX_2|MBX_1|MBX_0;
4780 mcp->buf_size = mreq->transfer_size;
4781 mcp->tov = MBX_TOV_SECONDS;
4782 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4784 rval = qla2x00_mailbox_command(vha, mcp);
4786 if (rval != QLA_SUCCESS) {
4787 ql_dbg(ql_dbg_mbx, vha, 0x10f8,
4788 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[18]=%x "
4789 "mb[19]=%x.\n", rval, mcp->mb[0], mcp->mb[1], mcp->mb[2],
4790 mcp->mb[3], mcp->mb[18], mcp->mb[19]);
4791 } else {
4792 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10f9,
4793 "Done %s.\n", __func__);
4796 /* Copy mailbox information */
4797 memcpy( mresp, mcp->mb, 64);
4798 return rval;
4802 qla2x00_echo_test(scsi_qla_host_t *vha, struct msg_echo_lb *mreq,
4803 uint16_t *mresp)
4805 int rval;
4806 mbx_cmd_t mc;
4807 mbx_cmd_t *mcp = &mc;
4808 struct qla_hw_data *ha = vha->hw;
4810 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fa,
4811 "Entered %s.\n", __func__);
4813 memset(mcp->mb, 0 , sizeof(mcp->mb));
4814 mcp->mb[0] = MBC_DIAGNOSTIC_ECHO;
4815 /* BIT_6 specifies 64bit address */
4816 mcp->mb[1] = mreq->options | BIT_15 | BIT_6;
4817 if (IS_CNA_CAPABLE(ha)) {
4818 mcp->mb[2] = vha->fcoe_fcf_idx;
4820 mcp->mb[16] = LSW(mreq->rcv_dma);
4821 mcp->mb[17] = MSW(mreq->rcv_dma);
4822 mcp->mb[6] = LSW(MSD(mreq->rcv_dma));
4823 mcp->mb[7] = MSW(MSD(mreq->rcv_dma));
4825 mcp->mb[10] = LSW(mreq->transfer_size);
4827 mcp->mb[14] = LSW(mreq->send_dma);
4828 mcp->mb[15] = MSW(mreq->send_dma);
4829 mcp->mb[20] = LSW(MSD(mreq->send_dma));
4830 mcp->mb[21] = MSW(MSD(mreq->send_dma));
4832 mcp->out_mb = MBX_21|MBX_20|MBX_17|MBX_16|MBX_15|
4833 MBX_14|MBX_10|MBX_7|MBX_6|MBX_1|MBX_0;
4834 if (IS_CNA_CAPABLE(ha))
4835 mcp->out_mb |= MBX_2;
4837 mcp->in_mb = MBX_0;
4838 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
4839 IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
4840 mcp->in_mb |= MBX_1;
4841 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha))
4842 mcp->in_mb |= MBX_3;
4844 mcp->tov = MBX_TOV_SECONDS;
4845 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4846 mcp->buf_size = mreq->transfer_size;
4848 rval = qla2x00_mailbox_command(vha, mcp);
4850 if (rval != QLA_SUCCESS) {
4851 ql_dbg(ql_dbg_mbx, vha, 0x10fb,
4852 "Failed=%x mb[0]=%x mb[1]=%x.\n",
4853 rval, mcp->mb[0], mcp->mb[1]);
4854 } else {
4855 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fc,
4856 "Done %s.\n", __func__);
4859 /* Copy mailbox information */
4860 memcpy(mresp, mcp->mb, 64);
4861 return rval;
4865 qla84xx_reset_chip(scsi_qla_host_t *vha, uint16_t enable_diagnostic)
4867 int rval;
4868 mbx_cmd_t mc;
4869 mbx_cmd_t *mcp = &mc;
4871 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10fd,
4872 "Entered %s enable_diag=%d.\n", __func__, enable_diagnostic);
4874 mcp->mb[0] = MBC_ISP84XX_RESET;
4875 mcp->mb[1] = enable_diagnostic;
4876 mcp->out_mb = MBX_1|MBX_0;
4877 mcp->in_mb = MBX_1|MBX_0;
4878 mcp->tov = MBX_TOV_SECONDS;
4879 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
4880 rval = qla2x00_mailbox_command(vha, mcp);
4882 if (rval != QLA_SUCCESS)
4883 ql_dbg(ql_dbg_mbx, vha, 0x10fe, "Failed=%x.\n", rval);
4884 else
4885 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10ff,
4886 "Done %s.\n", __func__);
4888 return rval;
4892 qla2x00_write_ram_word(scsi_qla_host_t *vha, uint32_t risc_addr, uint32_t data)
4894 int rval;
4895 mbx_cmd_t mc;
4896 mbx_cmd_t *mcp = &mc;
4898 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1100,
4899 "Entered %s.\n", __func__);
4901 if (!IS_FWI2_CAPABLE(vha->hw))
4902 return QLA_FUNCTION_FAILED;
4904 mcp->mb[0] = MBC_WRITE_RAM_WORD_EXTENDED;
4905 mcp->mb[1] = LSW(risc_addr);
4906 mcp->mb[2] = LSW(data);
4907 mcp->mb[3] = MSW(data);
4908 mcp->mb[8] = MSW(risc_addr);
4909 mcp->out_mb = MBX_8|MBX_3|MBX_2|MBX_1|MBX_0;
4910 mcp->in_mb = MBX_0;
4911 mcp->tov = 30;
4912 mcp->flags = 0;
4913 rval = qla2x00_mailbox_command(vha, mcp);
4914 if (rval != QLA_SUCCESS) {
4915 ql_dbg(ql_dbg_mbx, vha, 0x1101,
4916 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
4917 } else {
4918 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1102,
4919 "Done %s.\n", __func__);
4922 return rval;
4926 qla81xx_write_mpi_register(scsi_qla_host_t *vha, uint16_t *mb)
4928 int rval;
4929 uint32_t stat, timer;
4930 uint16_t mb0 = 0;
4931 struct qla_hw_data *ha = vha->hw;
4932 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4934 rval = QLA_SUCCESS;
4936 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1103,
4937 "Entered %s.\n", __func__);
4939 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
4941 /* Write the MBC data to the registers */
4942 WRT_REG_WORD(&reg->mailbox0, MBC_WRITE_MPI_REGISTER);
4943 WRT_REG_WORD(&reg->mailbox1, mb[0]);
4944 WRT_REG_WORD(&reg->mailbox2, mb[1]);
4945 WRT_REG_WORD(&reg->mailbox3, mb[2]);
4946 WRT_REG_WORD(&reg->mailbox4, mb[3]);
4948 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_HOST_INT);
4950 /* Poll for MBC interrupt */
4951 for (timer = 6000000; timer; timer--) {
4952 /* Check for pending interrupts. */
4953 stat = RD_REG_DWORD(&reg->host_status);
4954 if (stat & HSRX_RISC_INT) {
4955 stat &= 0xff;
4957 if (stat == 0x1 || stat == 0x2 ||
4958 stat == 0x10 || stat == 0x11) {
4959 set_bit(MBX_INTERRUPT,
4960 &ha->mbx_cmd_flags);
4961 mb0 = RD_REG_WORD(&reg->mailbox0);
4962 WRT_REG_DWORD(&reg->hccr,
4963 HCCRX_CLR_RISC_INT);
4964 RD_REG_DWORD(&reg->hccr);
4965 break;
4968 udelay(5);
4971 if (test_and_clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags))
4972 rval = mb0 & MBS_MASK;
4973 else
4974 rval = QLA_FUNCTION_FAILED;
4976 if (rval != QLA_SUCCESS) {
4977 ql_dbg(ql_dbg_mbx, vha, 0x1104,
4978 "Failed=%x mb[0]=%x.\n", rval, mb[0]);
4979 } else {
4980 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1105,
4981 "Done %s.\n", __func__);
4984 return rval;
4988 qla2x00_get_data_rate(scsi_qla_host_t *vha)
4990 int rval;
4991 mbx_cmd_t mc;
4992 mbx_cmd_t *mcp = &mc;
4993 struct qla_hw_data *ha = vha->hw;
4995 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1106,
4996 "Entered %s.\n", __func__);
4998 if (!IS_FWI2_CAPABLE(ha))
4999 return QLA_FUNCTION_FAILED;
5001 mcp->mb[0] = MBC_DATA_RATE;
5002 mcp->mb[1] = 0;
5003 mcp->out_mb = MBX_1|MBX_0;
5004 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5005 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
5006 mcp->in_mb |= MBX_3;
5007 mcp->tov = MBX_TOV_SECONDS;
5008 mcp->flags = 0;
5009 rval = qla2x00_mailbox_command(vha, mcp);
5010 if (rval != QLA_SUCCESS) {
5011 ql_dbg(ql_dbg_mbx, vha, 0x1107,
5012 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5013 } else {
5014 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1108,
5015 "Done %s.\n", __func__);
5016 if (mcp->mb[1] != 0x7)
5017 ha->link_data_rate = mcp->mb[1];
5020 return rval;
5024 qla81xx_get_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5026 int rval;
5027 mbx_cmd_t mc;
5028 mbx_cmd_t *mcp = &mc;
5029 struct qla_hw_data *ha = vha->hw;
5031 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1109,
5032 "Entered %s.\n", __func__);
5034 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA8044(ha) &&
5035 !IS_QLA27XX(ha))
5036 return QLA_FUNCTION_FAILED;
5037 mcp->mb[0] = MBC_GET_PORT_CONFIG;
5038 mcp->out_mb = MBX_0;
5039 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5040 mcp->tov = MBX_TOV_SECONDS;
5041 mcp->flags = 0;
5043 rval = qla2x00_mailbox_command(vha, mcp);
5045 if (rval != QLA_SUCCESS) {
5046 ql_dbg(ql_dbg_mbx, vha, 0x110a,
5047 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5048 } else {
5049 /* Copy all bits to preserve original value */
5050 memcpy(mb, &mcp->mb[1], sizeof(uint16_t) * 4);
5052 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110b,
5053 "Done %s.\n", __func__);
5055 return rval;
5059 qla81xx_set_port_config(scsi_qla_host_t *vha, uint16_t *mb)
5061 int rval;
5062 mbx_cmd_t mc;
5063 mbx_cmd_t *mcp = &mc;
5065 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110c,
5066 "Entered %s.\n", __func__);
5068 mcp->mb[0] = MBC_SET_PORT_CONFIG;
5069 /* Copy all bits to preserve original setting */
5070 memcpy(&mcp->mb[1], mb, sizeof(uint16_t) * 4);
5071 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5072 mcp->in_mb = MBX_0;
5073 mcp->tov = MBX_TOV_SECONDS;
5074 mcp->flags = 0;
5075 rval = qla2x00_mailbox_command(vha, mcp);
5077 if (rval != QLA_SUCCESS) {
5078 ql_dbg(ql_dbg_mbx, vha, 0x110d,
5079 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5080 } else
5081 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110e,
5082 "Done %s.\n", __func__);
5084 return rval;
5089 qla24xx_set_fcp_prio(scsi_qla_host_t *vha, uint16_t loop_id, uint16_t priority,
5090 uint16_t *mb)
5092 int rval;
5093 mbx_cmd_t mc;
5094 mbx_cmd_t *mcp = &mc;
5095 struct qla_hw_data *ha = vha->hw;
5097 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x110f,
5098 "Entered %s.\n", __func__);
5100 if (!IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha))
5101 return QLA_FUNCTION_FAILED;
5103 mcp->mb[0] = MBC_PORT_PARAMS;
5104 mcp->mb[1] = loop_id;
5105 if (ha->flags.fcp_prio_enabled)
5106 mcp->mb[2] = BIT_1;
5107 else
5108 mcp->mb[2] = BIT_2;
5109 mcp->mb[4] = priority & 0xf;
5110 mcp->mb[9] = vha->vp_idx;
5111 mcp->out_mb = MBX_9|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5112 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5113 mcp->tov = 30;
5114 mcp->flags = 0;
5115 rval = qla2x00_mailbox_command(vha, mcp);
5116 if (mb != NULL) {
5117 mb[0] = mcp->mb[0];
5118 mb[1] = mcp->mb[1];
5119 mb[3] = mcp->mb[3];
5120 mb[4] = mcp->mb[4];
5123 if (rval != QLA_SUCCESS) {
5124 ql_dbg(ql_dbg_mbx, vha, 0x10cd, "Failed=%x.\n", rval);
5125 } else {
5126 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x10cc,
5127 "Done %s.\n", __func__);
5130 return rval;
5134 qla2x00_get_thermal_temp(scsi_qla_host_t *vha, uint16_t *temp)
5136 int rval = QLA_FUNCTION_FAILED;
5137 struct qla_hw_data *ha = vha->hw;
5138 uint8_t byte;
5140 if (!IS_FWI2_CAPABLE(ha) || IS_QLA24XX_TYPE(ha) || IS_QLA81XX(ha)) {
5141 ql_dbg(ql_dbg_mbx, vha, 0x1150,
5142 "Thermal not supported by this card.\n");
5143 return rval;
5146 if (IS_QLA25XX(ha)) {
5147 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
5148 ha->pdev->subsystem_device == 0x0175) {
5149 rval = qla2x00_read_sfp(vha, 0, &byte,
5150 0x98, 0x1, 1, BIT_13|BIT_0);
5151 *temp = byte;
5152 return rval;
5154 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_HP &&
5155 ha->pdev->subsystem_device == 0x338e) {
5156 rval = qla2x00_read_sfp(vha, 0, &byte,
5157 0x98, 0x1, 1, BIT_15|BIT_14|BIT_0);
5158 *temp = byte;
5159 return rval;
5161 ql_dbg(ql_dbg_mbx, vha, 0x10c9,
5162 "Thermal not supported by this card.\n");
5163 return rval;
5166 if (IS_QLA82XX(ha)) {
5167 *temp = qla82xx_read_temperature(vha);
5168 rval = QLA_SUCCESS;
5169 return rval;
5170 } else if (IS_QLA8044(ha)) {
5171 *temp = qla8044_read_temperature(vha);
5172 rval = QLA_SUCCESS;
5173 return rval;
5176 rval = qla2x00_read_asic_temperature(vha, temp);
5177 return rval;
5181 qla82xx_mbx_intr_enable(scsi_qla_host_t *vha)
5183 int rval;
5184 struct qla_hw_data *ha = vha->hw;
5185 mbx_cmd_t mc;
5186 mbx_cmd_t *mcp = &mc;
5188 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1017,
5189 "Entered %s.\n", __func__);
5191 if (!IS_FWI2_CAPABLE(ha))
5192 return QLA_FUNCTION_FAILED;
5194 memset(mcp, 0, sizeof(mbx_cmd_t));
5195 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
5196 mcp->mb[1] = 1;
5198 mcp->out_mb = MBX_1|MBX_0;
5199 mcp->in_mb = MBX_0;
5200 mcp->tov = 30;
5201 mcp->flags = 0;
5203 rval = qla2x00_mailbox_command(vha, mcp);
5204 if (rval != QLA_SUCCESS) {
5205 ql_dbg(ql_dbg_mbx, vha, 0x1016,
5206 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5207 } else {
5208 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100e,
5209 "Done %s.\n", __func__);
5212 return rval;
5216 qla82xx_mbx_intr_disable(scsi_qla_host_t *vha)
5218 int rval;
5219 struct qla_hw_data *ha = vha->hw;
5220 mbx_cmd_t mc;
5221 mbx_cmd_t *mcp = &mc;
5223 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100d,
5224 "Entered %s.\n", __func__);
5226 if (!IS_P3P_TYPE(ha))
5227 return QLA_FUNCTION_FAILED;
5229 memset(mcp, 0, sizeof(mbx_cmd_t));
5230 mcp->mb[0] = MBC_TOGGLE_INTERRUPT;
5231 mcp->mb[1] = 0;
5233 mcp->out_mb = MBX_1|MBX_0;
5234 mcp->in_mb = MBX_0;
5235 mcp->tov = 30;
5236 mcp->flags = 0;
5238 rval = qla2x00_mailbox_command(vha, mcp);
5239 if (rval != QLA_SUCCESS) {
5240 ql_dbg(ql_dbg_mbx, vha, 0x100c,
5241 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5242 } else {
5243 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x100b,
5244 "Done %s.\n", __func__);
5247 return rval;
5251 qla82xx_md_get_template_size(scsi_qla_host_t *vha)
5253 struct qla_hw_data *ha = vha->hw;
5254 mbx_cmd_t mc;
5255 mbx_cmd_t *mcp = &mc;
5256 int rval = QLA_FUNCTION_FAILED;
5258 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x111f,
5259 "Entered %s.\n", __func__);
5261 memset(mcp->mb, 0 , sizeof(mcp->mb));
5262 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5263 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5264 mcp->mb[2] = LSW(RQST_TMPLT_SIZE);
5265 mcp->mb[3] = MSW(RQST_TMPLT_SIZE);
5267 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5268 mcp->in_mb = MBX_14|MBX_13|MBX_12|MBX_11|MBX_10|MBX_9|MBX_8|
5269 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5271 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5272 mcp->tov = MBX_TOV_SECONDS;
5273 rval = qla2x00_mailbox_command(vha, mcp);
5275 /* Always copy back return mailbox values. */
5276 if (rval != QLA_SUCCESS) {
5277 ql_dbg(ql_dbg_mbx, vha, 0x1120,
5278 "mailbox command FAILED=0x%x, subcode=%x.\n",
5279 (mcp->mb[1] << 16) | mcp->mb[0],
5280 (mcp->mb[3] << 16) | mcp->mb[2]);
5281 } else {
5282 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1121,
5283 "Done %s.\n", __func__);
5284 ha->md_template_size = ((mcp->mb[3] << 16) | mcp->mb[2]);
5285 if (!ha->md_template_size) {
5286 ql_dbg(ql_dbg_mbx, vha, 0x1122,
5287 "Null template size obtained.\n");
5288 rval = QLA_FUNCTION_FAILED;
5291 return rval;
5295 qla82xx_md_get_template(scsi_qla_host_t *vha)
5297 struct qla_hw_data *ha = vha->hw;
5298 mbx_cmd_t mc;
5299 mbx_cmd_t *mcp = &mc;
5300 int rval = QLA_FUNCTION_FAILED;
5302 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1123,
5303 "Entered %s.\n", __func__);
5305 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5306 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5307 if (!ha->md_tmplt_hdr) {
5308 ql_log(ql_log_warn, vha, 0x1124,
5309 "Unable to allocate memory for Minidump template.\n");
5310 return rval;
5313 memset(mcp->mb, 0 , sizeof(mcp->mb));
5314 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5315 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5316 mcp->mb[2] = LSW(RQST_TMPLT);
5317 mcp->mb[3] = MSW(RQST_TMPLT);
5318 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma));
5319 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma));
5320 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma));
5321 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma));
5322 mcp->mb[8] = LSW(ha->md_template_size);
5323 mcp->mb[9] = MSW(ha->md_template_size);
5325 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5326 mcp->tov = MBX_TOV_SECONDS;
5327 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5328 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5329 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5330 rval = qla2x00_mailbox_command(vha, mcp);
5332 if (rval != QLA_SUCCESS) {
5333 ql_dbg(ql_dbg_mbx, vha, 0x1125,
5334 "mailbox command FAILED=0x%x, subcode=%x.\n",
5335 ((mcp->mb[1] << 16) | mcp->mb[0]),
5336 ((mcp->mb[3] << 16) | mcp->mb[2]));
5337 } else
5338 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1126,
5339 "Done %s.\n", __func__);
5340 return rval;
5344 qla8044_md_get_template(scsi_qla_host_t *vha)
5346 struct qla_hw_data *ha = vha->hw;
5347 mbx_cmd_t mc;
5348 mbx_cmd_t *mcp = &mc;
5349 int rval = QLA_FUNCTION_FAILED;
5350 int offset = 0, size = MINIDUMP_SIZE_36K;
5351 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11f,
5352 "Entered %s.\n", __func__);
5354 ha->md_tmplt_hdr = dma_alloc_coherent(&ha->pdev->dev,
5355 ha->md_template_size, &ha->md_tmplt_hdr_dma, GFP_KERNEL);
5356 if (!ha->md_tmplt_hdr) {
5357 ql_log(ql_log_warn, vha, 0xb11b,
5358 "Unable to allocate memory for Minidump template.\n");
5359 return rval;
5362 memset(mcp->mb, 0 , sizeof(mcp->mb));
5363 while (offset < ha->md_template_size) {
5364 mcp->mb[0] = LSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5365 mcp->mb[1] = MSW(MBC_DIAGNOSTIC_MINIDUMP_TEMPLATE);
5366 mcp->mb[2] = LSW(RQST_TMPLT);
5367 mcp->mb[3] = MSW(RQST_TMPLT);
5368 mcp->mb[4] = LSW(LSD(ha->md_tmplt_hdr_dma + offset));
5369 mcp->mb[5] = MSW(LSD(ha->md_tmplt_hdr_dma + offset));
5370 mcp->mb[6] = LSW(MSD(ha->md_tmplt_hdr_dma + offset));
5371 mcp->mb[7] = MSW(MSD(ha->md_tmplt_hdr_dma + offset));
5372 mcp->mb[8] = LSW(size);
5373 mcp->mb[9] = MSW(size);
5374 mcp->mb[10] = offset & 0x0000FFFF;
5375 mcp->mb[11] = offset & 0xFFFF0000;
5376 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN|IOCTL_CMD;
5377 mcp->tov = MBX_TOV_SECONDS;
5378 mcp->out_mb = MBX_11|MBX_10|MBX_9|MBX_8|
5379 MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5380 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5381 rval = qla2x00_mailbox_command(vha, mcp);
5383 if (rval != QLA_SUCCESS) {
5384 ql_dbg(ql_dbg_mbx, vha, 0xb11c,
5385 "mailbox command FAILED=0x%x, subcode=%x.\n",
5386 ((mcp->mb[1] << 16) | mcp->mb[0]),
5387 ((mcp->mb[3] << 16) | mcp->mb[2]));
5388 return rval;
5389 } else
5390 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0xb11d,
5391 "Done %s.\n", __func__);
5392 offset = offset + size;
5394 return rval;
5398 qla81xx_set_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5400 int rval;
5401 struct qla_hw_data *ha = vha->hw;
5402 mbx_cmd_t mc;
5403 mbx_cmd_t *mcp = &mc;
5405 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5406 return QLA_FUNCTION_FAILED;
5408 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1133,
5409 "Entered %s.\n", __func__);
5411 memset(mcp, 0, sizeof(mbx_cmd_t));
5412 mcp->mb[0] = MBC_SET_LED_CONFIG;
5413 mcp->mb[1] = led_cfg[0];
5414 mcp->mb[2] = led_cfg[1];
5415 if (IS_QLA8031(ha)) {
5416 mcp->mb[3] = led_cfg[2];
5417 mcp->mb[4] = led_cfg[3];
5418 mcp->mb[5] = led_cfg[4];
5419 mcp->mb[6] = led_cfg[5];
5422 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5423 if (IS_QLA8031(ha))
5424 mcp->out_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5425 mcp->in_mb = MBX_0;
5426 mcp->tov = 30;
5427 mcp->flags = 0;
5429 rval = qla2x00_mailbox_command(vha, mcp);
5430 if (rval != QLA_SUCCESS) {
5431 ql_dbg(ql_dbg_mbx, vha, 0x1134,
5432 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5433 } else {
5434 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1135,
5435 "Done %s.\n", __func__);
5438 return rval;
5442 qla81xx_get_led_config(scsi_qla_host_t *vha, uint16_t *led_cfg)
5444 int rval;
5445 struct qla_hw_data *ha = vha->hw;
5446 mbx_cmd_t mc;
5447 mbx_cmd_t *mcp = &mc;
5449 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
5450 return QLA_FUNCTION_FAILED;
5452 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1136,
5453 "Entered %s.\n", __func__);
5455 memset(mcp, 0, sizeof(mbx_cmd_t));
5456 mcp->mb[0] = MBC_GET_LED_CONFIG;
5458 mcp->out_mb = MBX_0;
5459 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5460 if (IS_QLA8031(ha))
5461 mcp->in_mb |= MBX_6|MBX_5|MBX_4|MBX_3;
5462 mcp->tov = 30;
5463 mcp->flags = 0;
5465 rval = qla2x00_mailbox_command(vha, mcp);
5466 if (rval != QLA_SUCCESS) {
5467 ql_dbg(ql_dbg_mbx, vha, 0x1137,
5468 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5469 } else {
5470 led_cfg[0] = mcp->mb[1];
5471 led_cfg[1] = mcp->mb[2];
5472 if (IS_QLA8031(ha)) {
5473 led_cfg[2] = mcp->mb[3];
5474 led_cfg[3] = mcp->mb[4];
5475 led_cfg[4] = mcp->mb[5];
5476 led_cfg[5] = mcp->mb[6];
5478 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1138,
5479 "Done %s.\n", __func__);
5482 return rval;
5486 qla82xx_mbx_beacon_ctl(scsi_qla_host_t *vha, int enable)
5488 int rval;
5489 struct qla_hw_data *ha = vha->hw;
5490 mbx_cmd_t mc;
5491 mbx_cmd_t *mcp = &mc;
5493 if (!IS_P3P_TYPE(ha))
5494 return QLA_FUNCTION_FAILED;
5496 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1127,
5497 "Entered %s.\n", __func__);
5499 memset(mcp, 0, sizeof(mbx_cmd_t));
5500 mcp->mb[0] = MBC_SET_LED_CONFIG;
5501 if (enable)
5502 mcp->mb[7] = 0xE;
5503 else
5504 mcp->mb[7] = 0xD;
5506 mcp->out_mb = MBX_7|MBX_0;
5507 mcp->in_mb = MBX_0;
5508 mcp->tov = MBX_TOV_SECONDS;
5509 mcp->flags = 0;
5511 rval = qla2x00_mailbox_command(vha, mcp);
5512 if (rval != QLA_SUCCESS) {
5513 ql_dbg(ql_dbg_mbx, vha, 0x1128,
5514 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5515 } else {
5516 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1129,
5517 "Done %s.\n", __func__);
5520 return rval;
5524 qla83xx_wr_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t data)
5526 int rval;
5527 struct qla_hw_data *ha = vha->hw;
5528 mbx_cmd_t mc;
5529 mbx_cmd_t *mcp = &mc;
5531 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
5532 return QLA_FUNCTION_FAILED;
5534 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1130,
5535 "Entered %s.\n", __func__);
5537 mcp->mb[0] = MBC_WRITE_REMOTE_REG;
5538 mcp->mb[1] = LSW(reg);
5539 mcp->mb[2] = MSW(reg);
5540 mcp->mb[3] = LSW(data);
5541 mcp->mb[4] = MSW(data);
5542 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
5544 mcp->in_mb = MBX_1|MBX_0;
5545 mcp->tov = MBX_TOV_SECONDS;
5546 mcp->flags = 0;
5547 rval = qla2x00_mailbox_command(vha, mcp);
5549 if (rval != QLA_SUCCESS) {
5550 ql_dbg(ql_dbg_mbx, vha, 0x1131,
5551 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5552 } else {
5553 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1132,
5554 "Done %s.\n", __func__);
5557 return rval;
5561 qla2x00_port_logout(scsi_qla_host_t *vha, struct fc_port *fcport)
5563 int rval;
5564 struct qla_hw_data *ha = vha->hw;
5565 mbx_cmd_t mc;
5566 mbx_cmd_t *mcp = &mc;
5568 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
5569 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113b,
5570 "Implicit LOGO Unsupported.\n");
5571 return QLA_FUNCTION_FAILED;
5575 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113c,
5576 "Entering %s.\n", __func__);
5578 /* Perform Implicit LOGO. */
5579 mcp->mb[0] = MBC_PORT_LOGOUT;
5580 mcp->mb[1] = fcport->loop_id;
5581 mcp->mb[10] = BIT_15;
5582 mcp->out_mb = MBX_10|MBX_1|MBX_0;
5583 mcp->in_mb = MBX_0;
5584 mcp->tov = MBX_TOV_SECONDS;
5585 mcp->flags = 0;
5586 rval = qla2x00_mailbox_command(vha, mcp);
5587 if (rval != QLA_SUCCESS)
5588 ql_dbg(ql_dbg_mbx, vha, 0x113d,
5589 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5590 else
5591 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x113e,
5592 "Done %s.\n", __func__);
5594 return rval;
5598 qla83xx_rd_reg(scsi_qla_host_t *vha, uint32_t reg, uint32_t *data)
5600 int rval;
5601 mbx_cmd_t mc;
5602 mbx_cmd_t *mcp = &mc;
5603 struct qla_hw_data *ha = vha->hw;
5604 unsigned long retry_max_time = jiffies + (2 * HZ);
5606 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
5607 return QLA_FUNCTION_FAILED;
5609 ql_dbg(ql_dbg_mbx, vha, 0x114b, "Entered %s.\n", __func__);
5611 retry_rd_reg:
5612 mcp->mb[0] = MBC_READ_REMOTE_REG;
5613 mcp->mb[1] = LSW(reg);
5614 mcp->mb[2] = MSW(reg);
5615 mcp->out_mb = MBX_2|MBX_1|MBX_0;
5616 mcp->in_mb = MBX_4|MBX_3|MBX_1|MBX_0;
5617 mcp->tov = MBX_TOV_SECONDS;
5618 mcp->flags = 0;
5619 rval = qla2x00_mailbox_command(vha, mcp);
5621 if (rval != QLA_SUCCESS) {
5622 ql_dbg(ql_dbg_mbx, vha, 0x114c,
5623 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5624 rval, mcp->mb[0], mcp->mb[1]);
5625 } else {
5626 *data = (mcp->mb[3] | (mcp->mb[4] << 16));
5627 if (*data == QLA8XXX_BAD_VALUE) {
5629 * During soft-reset CAMRAM register reads might
5630 * return 0xbad0bad0. So retry for MAX of 2 sec
5631 * while reading camram registers.
5633 if (time_after(jiffies, retry_max_time)) {
5634 ql_dbg(ql_dbg_mbx, vha, 0x1141,
5635 "Failure to read CAMRAM register. "
5636 "data=0x%x.\n", *data);
5637 return QLA_FUNCTION_FAILED;
5639 msleep(100);
5640 goto retry_rd_reg;
5642 ql_dbg(ql_dbg_mbx, vha, 0x1142, "Done %s.\n", __func__);
5645 return rval;
5649 qla83xx_restart_nic_firmware(scsi_qla_host_t *vha)
5651 int rval;
5652 mbx_cmd_t mc;
5653 mbx_cmd_t *mcp = &mc;
5654 struct qla_hw_data *ha = vha->hw;
5656 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
5657 return QLA_FUNCTION_FAILED;
5659 ql_dbg(ql_dbg_mbx, vha, 0x1143, "Entered %s.\n", __func__);
5661 mcp->mb[0] = MBC_RESTART_NIC_FIRMWARE;
5662 mcp->out_mb = MBX_0;
5663 mcp->in_mb = MBX_1|MBX_0;
5664 mcp->tov = MBX_TOV_SECONDS;
5665 mcp->flags = 0;
5666 rval = qla2x00_mailbox_command(vha, mcp);
5668 if (rval != QLA_SUCCESS) {
5669 ql_dbg(ql_dbg_mbx, vha, 0x1144,
5670 "Failed=%x mb[0]=%x mb[1]=%x.\n",
5671 rval, mcp->mb[0], mcp->mb[1]);
5672 ha->isp_ops->fw_dump(vha, 0);
5673 } else {
5674 ql_dbg(ql_dbg_mbx, vha, 0x1145, "Done %s.\n", __func__);
5677 return rval;
5681 qla83xx_access_control(scsi_qla_host_t *vha, uint16_t options,
5682 uint32_t start_addr, uint32_t end_addr, uint16_t *sector_size)
5684 int rval;
5685 mbx_cmd_t mc;
5686 mbx_cmd_t *mcp = &mc;
5687 uint8_t subcode = (uint8_t)options;
5688 struct qla_hw_data *ha = vha->hw;
5690 if (!IS_QLA8031(ha))
5691 return QLA_FUNCTION_FAILED;
5693 ql_dbg(ql_dbg_mbx, vha, 0x1146, "Entered %s.\n", __func__);
5695 mcp->mb[0] = MBC_SET_ACCESS_CONTROL;
5696 mcp->mb[1] = options;
5697 mcp->out_mb = MBX_1|MBX_0;
5698 if (subcode & BIT_2) {
5699 mcp->mb[2] = LSW(start_addr);
5700 mcp->mb[3] = MSW(start_addr);
5701 mcp->mb[4] = LSW(end_addr);
5702 mcp->mb[5] = MSW(end_addr);
5703 mcp->out_mb |= MBX_5|MBX_4|MBX_3|MBX_2;
5705 mcp->in_mb = MBX_2|MBX_1|MBX_0;
5706 if (!(subcode & (BIT_2 | BIT_5)))
5707 mcp->in_mb |= MBX_4|MBX_3;
5708 mcp->tov = MBX_TOV_SECONDS;
5709 mcp->flags = 0;
5710 rval = qla2x00_mailbox_command(vha, mcp);
5712 if (rval != QLA_SUCCESS) {
5713 ql_dbg(ql_dbg_mbx, vha, 0x1147,
5714 "Failed=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[3]=%x mb[4]=%x.\n",
5715 rval, mcp->mb[0], mcp->mb[1], mcp->mb[2], mcp->mb[3],
5716 mcp->mb[4]);
5717 ha->isp_ops->fw_dump(vha, 0);
5718 } else {
5719 if (subcode & BIT_5)
5720 *sector_size = mcp->mb[1];
5721 else if (subcode & (BIT_6 | BIT_7)) {
5722 ql_dbg(ql_dbg_mbx, vha, 0x1148,
5723 "Driver-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5724 } else if (subcode & (BIT_3 | BIT_4)) {
5725 ql_dbg(ql_dbg_mbx, vha, 0x1149,
5726 "Flash-lock id=%x%x", mcp->mb[4], mcp->mb[3]);
5728 ql_dbg(ql_dbg_mbx, vha, 0x114a, "Done %s.\n", __func__);
5731 return rval;
5735 qla2x00_dump_mctp_data(scsi_qla_host_t *vha, dma_addr_t req_dma, uint32_t addr,
5736 uint32_t size)
5738 int rval;
5739 mbx_cmd_t mc;
5740 mbx_cmd_t *mcp = &mc;
5742 if (!IS_MCTP_CAPABLE(vha->hw))
5743 return QLA_FUNCTION_FAILED;
5745 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114f,
5746 "Entered %s.\n", __func__);
5748 mcp->mb[0] = MBC_DUMP_RISC_RAM_EXTENDED;
5749 mcp->mb[1] = LSW(addr);
5750 mcp->mb[2] = MSW(req_dma);
5751 mcp->mb[3] = LSW(req_dma);
5752 mcp->mb[4] = MSW(size);
5753 mcp->mb[5] = LSW(size);
5754 mcp->mb[6] = MSW(MSD(req_dma));
5755 mcp->mb[7] = LSW(MSD(req_dma));
5756 mcp->mb[8] = MSW(addr);
5757 /* Setting RAM ID to valid */
5758 mcp->mb[10] |= BIT_7;
5759 /* For MCTP RAM ID is 0x40 */
5760 mcp->mb[10] |= 0x40;
5762 mcp->out_mb |= MBX_10|MBX_8|MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|
5763 MBX_0;
5765 mcp->in_mb = MBX_0;
5766 mcp->tov = MBX_TOV_SECONDS;
5767 mcp->flags = 0;
5768 rval = qla2x00_mailbox_command(vha, mcp);
5770 if (rval != QLA_SUCCESS) {
5771 ql_dbg(ql_dbg_mbx, vha, 0x114e,
5772 "Failed=%x mb[0]=%x.\n", rval, mcp->mb[0]);
5773 } else {
5774 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x114d,
5775 "Done %s.\n", __func__);
5778 return rval;
5782 qla26xx_dport_diagnostics(scsi_qla_host_t *vha,
5783 void *dd_buf, uint size, uint options)
5785 int rval;
5786 mbx_cmd_t mc;
5787 mbx_cmd_t *mcp = &mc;
5788 dma_addr_t dd_dma;
5790 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
5791 return QLA_FUNCTION_FAILED;
5793 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1192,
5794 "Entered %s.\n", __func__);
5796 dd_dma = dma_map_single(&vha->hw->pdev->dev,
5797 dd_buf, size, DMA_FROM_DEVICE);
5798 if (!dd_dma) {
5799 ql_log(ql_log_warn, vha, 0x1194, "Failed to map dma buffer.\n");
5800 return QLA_MEMORY_ALLOC_FAILED;
5803 memset(dd_buf, 0, size);
5805 mcp->mb[0] = MBC_DPORT_DIAGNOSTICS;
5806 mcp->mb[1] = options;
5807 mcp->mb[2] = MSW(LSD(dd_dma));
5808 mcp->mb[3] = LSW(LSD(dd_dma));
5809 mcp->mb[6] = MSW(MSD(dd_dma));
5810 mcp->mb[7] = LSW(MSD(dd_dma));
5811 mcp->mb[8] = size;
5812 mcp->out_mb = MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
5813 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
5814 mcp->buf_size = size;
5815 mcp->flags = MBX_DMA_IN;
5816 mcp->tov = MBX_TOV_SECONDS * 4;
5817 rval = qla2x00_mailbox_command(vha, mcp);
5819 if (rval != QLA_SUCCESS) {
5820 ql_dbg(ql_dbg_mbx, vha, 0x1195, "Failed=%x.\n", rval);
5821 } else {
5822 ql_dbg(ql_dbg_mbx + ql_dbg_verbose, vha, 0x1196,
5823 "Done %s.\n", __func__);
5826 dma_unmap_single(&vha->hw->pdev->dev, dd_dma,
5827 size, DMA_FROM_DEVICE);
5829 return rval;
5832 static void qla2x00_async_mb_sp_done(void *s, int res)
5834 struct srb *sp = s;
5836 sp->u.iocb_cmd.u.mbx.rc = res;
5838 complete(&sp->u.iocb_cmd.u.mbx.comp);
5839 /* don't free sp here. Let the caller do the free */
5843 * This mailbox uses the iocb interface to send MB command.
5844 * This allows non-critial (non chip setup) command to go
5845 * out in parrallel.
5847 int qla24xx_send_mb_cmd(struct scsi_qla_host *vha, mbx_cmd_t *mcp)
5849 int rval = QLA_FUNCTION_FAILED;
5850 srb_t *sp;
5851 struct srb_iocb *c;
5853 if (!vha->hw->flags.fw_started)
5854 goto done;
5856 sp = qla2x00_get_sp(vha, NULL, GFP_KERNEL);
5857 if (!sp)
5858 goto done;
5860 sp->type = SRB_MB_IOCB;
5861 sp->name = mb_to_str(mcp->mb[0]);
5863 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
5865 memcpy(sp->u.iocb_cmd.u.mbx.out_mb, mcp->mb, SIZEOF_IOCB_MB_REG);
5867 c = &sp->u.iocb_cmd;
5868 c->timeout = qla2x00_async_iocb_timeout;
5869 init_completion(&c->u.mbx.comp);
5871 sp->done = qla2x00_async_mb_sp_done;
5873 rval = qla2x00_start_sp(sp);
5874 if (rval != QLA_SUCCESS) {
5875 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5876 "%s: %s Failed submission. %x.\n",
5877 __func__, sp->name, rval);
5878 goto done_free_sp;
5881 ql_dbg(ql_dbg_mbx, vha, 0xffff, "MB:%s hndl %x submitted\n",
5882 sp->name, sp->handle);
5884 wait_for_completion(&c->u.mbx.comp);
5885 memcpy(mcp->mb, sp->u.iocb_cmd.u.mbx.in_mb, SIZEOF_IOCB_MB_REG);
5887 rval = c->u.mbx.rc;
5888 switch (rval) {
5889 case QLA_FUNCTION_TIMEOUT:
5890 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s Timeout. %x.\n",
5891 __func__, sp->name, rval);
5892 break;
5893 case QLA_SUCCESS:
5894 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s done.\n",
5895 __func__, sp->name);
5896 sp->free(sp);
5897 break;
5898 default:
5899 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %s Failed. %x.\n",
5900 __func__, sp->name, rval);
5901 sp->free(sp);
5902 break;
5905 return rval;
5907 done_free_sp:
5908 sp->free(sp);
5909 done:
5910 return rval;
5914 * qla24xx_gpdb_wait
5915 * NOTE: Do not call this routine from DPC thread
5917 int qla24xx_gpdb_wait(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
5919 int rval = QLA_FUNCTION_FAILED;
5920 dma_addr_t pd_dma;
5921 struct port_database_24xx *pd;
5922 struct qla_hw_data *ha = vha->hw;
5923 mbx_cmd_t mc;
5925 if (!vha->hw->flags.fw_started)
5926 goto done;
5928 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
5929 if (pd == NULL) {
5930 ql_log(ql_log_warn, vha, 0xffff,
5931 "Failed to allocate port database structure.\n");
5932 goto done_free_sp;
5934 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
5936 memset(&mc, 0, sizeof(mc));
5937 mc.mb[0] = MBC_GET_PORT_DATABASE;
5938 mc.mb[1] = cpu_to_le16(fcport->loop_id);
5939 mc.mb[2] = MSW(pd_dma);
5940 mc.mb[3] = LSW(pd_dma);
5941 mc.mb[6] = MSW(MSD(pd_dma));
5942 mc.mb[7] = LSW(MSD(pd_dma));
5943 mc.mb[9] = cpu_to_le16(vha->vp_idx);
5944 mc.mb[10] = cpu_to_le16((uint16_t)opt);
5946 rval = qla24xx_send_mb_cmd(vha, &mc);
5947 if (rval != QLA_SUCCESS) {
5948 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5949 "%s: %8phC fail\n", __func__, fcport->port_name);
5950 goto done_free_sp;
5953 rval = __qla24xx_parse_gpdb(vha, fcport, pd);
5955 ql_dbg(ql_dbg_mbx, vha, 0xffff, "%s: %8phC done\n",
5956 __func__, fcport->port_name);
5958 done_free_sp:
5959 if (pd)
5960 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
5961 done:
5962 return rval;
5965 int __qla24xx_parse_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport,
5966 struct port_database_24xx *pd)
5968 int rval = QLA_SUCCESS;
5969 uint64_t zero = 0;
5971 /* Check for logged in state. */
5972 if (pd->current_login_state != PDS_PRLI_COMPLETE &&
5973 pd->last_login_state != PDS_PRLI_COMPLETE) {
5974 ql_dbg(ql_dbg_mbx, vha, 0xffff,
5975 "Unable to verify login-state (%x/%x) for "
5976 "loop_id %x.\n", pd->current_login_state,
5977 pd->last_login_state, fcport->loop_id);
5978 rval = QLA_FUNCTION_FAILED;
5979 goto gpd_error_out;
5982 if (fcport->loop_id == FC_NO_LOOP_ID ||
5983 (memcmp(fcport->port_name, (uint8_t *)&zero, 8) &&
5984 memcmp(fcport->port_name, pd->port_name, 8))) {
5985 /* We lost the device mid way. */
5986 rval = QLA_NOT_LOGGED_IN;
5987 goto gpd_error_out;
5990 /* Names are little-endian. */
5991 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
5992 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
5994 /* Get port_id of device. */
5995 fcport->d_id.b.domain = pd->port_id[0];
5996 fcport->d_id.b.area = pd->port_id[1];
5997 fcport->d_id.b.al_pa = pd->port_id[2];
5998 fcport->d_id.b.rsvd_1 = 0;
6000 /* If not target must be initiator or unknown type. */
6001 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
6002 fcport->port_type = FCT_INITIATOR;
6003 else
6004 fcport->port_type = FCT_TARGET;
6006 /* Passback COS information. */
6007 fcport->supported_classes = (pd->flags & PDF_CLASS_2) ?
6008 FC_COS_CLASS2 : FC_COS_CLASS3;
6010 if (pd->prli_svc_param_word_3[0] & BIT_7) {
6011 fcport->flags |= FCF_CONF_COMP_SUPPORTED;
6012 fcport->conf_compl_supported = 1;
6015 gpd_error_out:
6016 return rval;
6020 * qla24xx_gidlist__wait
6021 * NOTE: don't call this routine from DPC thread.
6023 int qla24xx_gidlist_wait(struct scsi_qla_host *vha,
6024 void *id_list, dma_addr_t id_list_dma, uint16_t *entries)
6026 int rval = QLA_FUNCTION_FAILED;
6027 mbx_cmd_t mc;
6029 if (!vha->hw->flags.fw_started)
6030 goto done;
6032 memset(&mc, 0, sizeof(mc));
6033 mc.mb[0] = MBC_GET_ID_LIST;
6034 mc.mb[2] = MSW(id_list_dma);
6035 mc.mb[3] = LSW(id_list_dma);
6036 mc.mb[6] = MSW(MSD(id_list_dma));
6037 mc.mb[7] = LSW(MSD(id_list_dma));
6038 mc.mb[8] = 0;
6039 mc.mb[9] = cpu_to_le16(vha->vp_idx);
6041 rval = qla24xx_send_mb_cmd(vha, &mc);
6042 if (rval != QLA_SUCCESS) {
6043 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6044 "%s: fail\n", __func__);
6045 } else {
6046 *entries = mc.mb[1];
6047 ql_dbg(ql_dbg_mbx, vha, 0xffff,
6048 "%s: done\n", __func__);
6050 done:
6051 return rval;