]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/scsi/qla2xxx/qla_mbx.c
[SCSI] qla2xxx: Add host port-type FC transport attribute.
[net-next-2.6.git] / drivers / scsi / qla2xxx / qla_mbx.c
CommitLineData
1da177e4 1/*
fa90c54f
AV
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
1da177e4 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
1da177e4
LT
6 */
7#include "qla_def.h"
8
9#include <linux/delay.h>
ad3e0eda 10#include <scsi/scsi_transport_fc.h>
1da177e4
LT
11
12static void
13qla2x00_mbx_sem_timeout(unsigned long data)
14{
15 struct semaphore *sem_ptr = (struct semaphore *)data;
16
17 DEBUG11(printk("qla2x00_sem_timeout: entered.\n");)
18
19 if (sem_ptr != NULL) {
20 up(sem_ptr);
21 }
22
23 DEBUG11(printk("qla2x00_mbx_sem_timeout: exiting.\n");)
24}
25
26/*
27 * qla2x00_mailbox_command
28 * Issue mailbox command and waits for completion.
29 *
30 * Input:
31 * ha = adapter block pointer.
32 * mcp = driver internal mbx struct pointer.
33 *
34 * Output:
35 * mb[MAX_MAILBOX_REGISTER_COUNT] = returned mailbox data.
36 *
37 * Returns:
38 * 0 : QLA_SUCCESS = cmd performed success
39 * 1 : QLA_FUNCTION_FAILED (error encountered)
40 * 6 : QLA_FUNCTION_TIMEOUT (timeout condition encountered)
41 *
42 * Context:
43 * Kernel context.
44 */
45static int
46qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
47{
48 int rval;
49 unsigned long flags = 0;
1c7c6357 50 device_reg_t __iomem *reg = ha->iobase;
1da177e4 51 struct timer_list tmp_intr_timer;
1c7c6357 52 uint8_t abort_active;
1da177e4
LT
53 uint8_t io_lock_on = ha->flags.init_done;
54 uint16_t command;
55 uint16_t *iptr;
56 uint16_t __iomem *optr;
57 uint32_t cnt;
58 uint32_t mboxes;
59 unsigned long mbx_flags = 0;
60 unsigned long wait_time;
61
62 rval = QLA_SUCCESS;
1c7c6357
AV
63 abort_active = test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
64
65 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1da177e4 66
1da177e4 67 /*
1c7c6357
AV
68 * Wait for active mailbox commands to finish by waiting at most tov
69 * seconds. This is to serialize actual issuing of mailbox cmds during
70 * non ISP abort time.
1da177e4
LT
71 */
72 if (!abort_active) {
73 if (qla2x00_down_timeout(&ha->mbx_cmd_sem, mcp->tov * HZ)) {
74 /* Timeout occurred. Return error. */
1c7c6357
AV
75 DEBUG2_3_11(printk("%s(%ld): cmd access timeout. "
76 "Exiting.\n", __func__, ha->host_no);)
1da177e4
LT
77 return QLA_FUNCTION_TIMEOUT;
78 }
79 }
80
81 ha->flags.mbox_busy = 1;
82 /* Save mailbox command for debug */
83 ha->mcp = mcp;
84
85 /* Try to get mailbox register access */
86 if (!abort_active)
87 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
88
1c7c6357
AV
89 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
90 ha->host_no, mcp->mb[0]);)
1da177e4
LT
91
92 spin_lock_irqsave(&ha->hardware_lock, flags);
93
94 /* Load mailbox registers. */
1c7c6357
AV
95 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
96 optr = (uint16_t __iomem *)&reg->isp24.mailbox0;
97 else
98 optr = (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 0);
1da177e4
LT
99
100 iptr = mcp->mb;
101 command = mcp->mb[0];
102 mboxes = mcp->out_mb;
103
104 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
105 if (IS_QLA2200(ha) && cnt == 8)
1c7c6357
AV
106 optr =
107 (uint16_t __iomem *)MAILBOX_REG(ha, &reg->isp, 8);
1da177e4
LT
108 if (mboxes & BIT_0)
109 WRT_REG_WORD(optr, *iptr);
110
111 mboxes >>= 1;
112 optr++;
113 iptr++;
114 }
115
116#if defined(QL_DEBUG_LEVEL_1)
1c7c6357
AV
117 printk("%s(%ld): Loaded MBX registers (displayed in bytes) = \n",
118 __func__, ha->host_no);
1da177e4
LT
119 qla2x00_dump_buffer((uint8_t *)mcp->mb, 16);
120 printk("\n");
121 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x10), 16);
122 printk("\n");
123 qla2x00_dump_buffer(((uint8_t *)mcp->mb + 0x20), 8);
124 printk("\n");
1c7c6357 125 printk("%s(%ld): I/O address = %p.\n", __func__, ha->host_no, optr);
1da177e4
LT
126 qla2x00_dump_regs(ha);
127#endif
128
129 /* Issue set host interrupt command to send cmd out. */
130 ha->flags.mbox_int = 0;
131 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
132
133 /* Unlock mbx registers and wait for interrupt */
1c7c6357
AV
134 DEBUG11(printk("%s(%ld): going to unlock irq & waiting for interrupt. "
135 "jiffies=%lx.\n", __func__, ha->host_no, jiffies);)
1da177e4
LT
136
137 /* Wait for mbx cmd completion until timeout */
138
139 if (!abort_active && io_lock_on) {
140 /* sleep on completion semaphore */
1c7c6357
AV
141 DEBUG11(printk("%s(%ld): INTERRUPT MODE. Initializing timer.\n",
142 __func__, ha->host_no);)
1da177e4
LT
143
144 init_timer(&tmp_intr_timer);
145 tmp_intr_timer.data = (unsigned long)&ha->mbx_intr_sem;
146 tmp_intr_timer.expires = jiffies + mcp->tov * HZ;
147 tmp_intr_timer.function =
148 (void (*)(unsigned long))qla2x00_mbx_sem_timeout;
149
1c7c6357
AV
150 DEBUG11(printk("%s(%ld): Adding timer.\n", __func__,
151 ha->host_no);)
1da177e4
LT
152 add_timer(&tmp_intr_timer);
153
1c7c6357
AV
154 DEBUG11(printk("%s(%ld): going to unlock & sleep. "
155 "time=0x%lx.\n", __func__, ha->host_no, jiffies);)
1da177e4
LT
156
157 set_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
158
1c7c6357
AV
159 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
160 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
161 else
162 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
1da177e4
LT
163 spin_unlock_irqrestore(&ha->hardware_lock, flags);
164
165 if (!abort_active)
166 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
167
168 /* Wait for either the timer to expire
169 * or the mbox completion interrupt
170 */
171 down(&ha->mbx_intr_sem);
172
1c7c6357
AV
173 DEBUG11(printk("%s(%ld): waking up. time=0x%lx\n", __func__,
174 ha->host_no, jiffies);)
1da177e4
LT
175 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
176
177 /* delete the timer */
178 del_timer(&tmp_intr_timer);
179 } else {
1c7c6357
AV
180 DEBUG3_11(printk("%s(%ld): cmd=%x POLLING MODE.\n", __func__,
181 ha->host_no, command);)
1da177e4 182
1c7c6357
AV
183 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
184 WRT_REG_DWORD(&reg->isp24.hccr, HCCRX_SET_HOST_INT);
185 else
186 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
1da177e4
LT
187 spin_unlock_irqrestore(&ha->hardware_lock, flags);
188 if (!abort_active)
189 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
190
191 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
192 while (!ha->flags.mbox_int) {
193 if (time_after(jiffies, wait_time))
194 break;
195
196 /* Check for pending interrupts. */
197 qla2x00_poll(ha);
198
59989831
AV
199 if (command != MBC_LOAD_RISC_RAM_EXTENDED &&
200 !ha->flags.mbox_int)
201 msleep(10);
1da177e4
LT
202 } /* while */
203 }
204
205 if (!abort_active)
206 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
207
208 /* Check whether we timed out */
209 if (ha->flags.mbox_int) {
210 uint16_t *iptr2;
211
1c7c6357
AV
212 DEBUG3_11(printk("%s(%ld): cmd %x completed.\n", __func__,
213 ha->host_no, command);)
1da177e4
LT
214
215 /* Got interrupt. Clear the flag. */
216 ha->flags.mbox_int = 0;
217 clear_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
218
354d6b21 219 if (ha->mailbox_out[0] != MBS_COMMAND_COMPLETE)
1da177e4 220 rval = QLA_FUNCTION_FAILED;
1da177e4
LT
221
222 /* Load return mailbox registers. */
223 iptr2 = mcp->mb;
224 iptr = (uint16_t *)&ha->mailbox_out[0];
225 mboxes = mcp->in_mb;
226 for (cnt = 0; cnt < ha->mbx_count; cnt++) {
227 if (mboxes & BIT_0)
228 *iptr2 = *iptr;
229
230 mboxes >>= 1;
231 iptr2++;
232 iptr++;
233 }
234 } else {
235
236#if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3) || \
237 defined(QL_DEBUG_LEVEL_11)
1c7c6357
AV
238 uint16_t mb0;
239 uint32_t ictrl;
240
241 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
242 mb0 = RD_REG_WORD(&reg->isp24.mailbox0);
243 ictrl = RD_REG_DWORD(&reg->isp24.ictrl);
244 } else {
cca5335c 245 mb0 = RD_MAILBOX_REG(ha, &reg->isp, 0);
1c7c6357
AV
246 ictrl = RD_REG_WORD(&reg->isp.ictrl);
247 }
248 printk("%s(%ld): **** MB Command Timeout for cmd %x ****\n",
249 __func__, ha->host_no, command);
250 printk("%s(%ld): icontrol=%x jiffies=%lx\n", __func__,
251 ha->host_no, ictrl, jiffies);
252 printk("%s(%ld): *** mailbox[0] = 0x%x ***\n", __func__,
253 ha->host_no, mb0);
1da177e4
LT
254 qla2x00_dump_regs(ha);
255#endif
256
1da177e4
LT
257 rval = QLA_FUNCTION_TIMEOUT;
258 }
259
260 if (!abort_active)
261 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
262
263 ha->flags.mbox_busy = 0;
264
265 /* Clean up */
266 ha->mcp = NULL;
267
268 if (!abort_active) {
1c7c6357
AV
269 DEBUG11(printk("%s(%ld): checking for additional resp "
270 "interrupt.\n", __func__, ha->host_no);)
1da177e4
LT
271
272 /* polling mode for non isp_abort commands. */
273 qla2x00_poll(ha);
274 }
275
1c7c6357
AV
276 if (rval == QLA_FUNCTION_TIMEOUT &&
277 mcp->mb[0] != MBC_GEN_SYSTEM_ERROR) {
1da177e4
LT
278 if (!io_lock_on || (mcp->flags & IOCTL_CMD)) {
279 /* not in dpc. schedule it for dpc to take over. */
1c7c6357
AV
280 DEBUG(printk("%s(%ld): timeout schedule "
281 "isp_abort_needed.\n", __func__, ha->host_no);)
282 DEBUG2_3_11(printk("%s(%ld): timeout schedule "
283 "isp_abort_needed.\n", __func__, ha->host_no);)
1da177e4
LT
284 qla_printk(KERN_WARNING, ha,
285 "Mailbox command timeout occured. Scheduling ISP "
286 "abort.\n");
287 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
fa2a1ce5 288 if (ha->dpc_wait && !ha->dpc_active)
1da177e4
LT
289 up(ha->dpc_wait);
290
291 } else if (!abort_active) {
1da177e4 292 /* call abort directly since we are in the DPC thread */
1c7c6357
AV
293 DEBUG(printk("%s(%ld): timeout calling abort_isp\n",
294 __func__, ha->host_no);)
295 DEBUG2_3_11(printk("%s(%ld): timeout calling "
296 "abort_isp\n", __func__, ha->host_no);)
1da177e4
LT
297 qla_printk(KERN_WARNING, ha,
298 "Mailbox command timeout occured. Issuing ISP "
299 "abort.\n");
300
301 set_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
302 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
303 if (qla2x00_abort_isp(ha)) {
1c7c6357 304 /* Failed. retry later. */
1da177e4
LT
305 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
306 }
307 clear_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags);
1c7c6357
AV
308 DEBUG(printk("%s(%ld): finished abort_isp\n", __func__,
309 ha->host_no);)
310 DEBUG2_3_11(printk("%s(%ld): finished abort_isp\n",
311 __func__, ha->host_no);)
1da177e4
LT
312 }
313 }
314
315 /* Allow next mbx cmd to come in. */
316 if (!abort_active)
317 up(&ha->mbx_cmd_sem);
318
319 if (rval) {
1c7c6357
AV
320 DEBUG2_3_11(printk("%s(%ld): **** FAILED. mbx0=%x, mbx1=%x, "
321 "mbx2=%x, cmd=%x ****\n", __func__, ha->host_no,
322 mcp->mb[0], mcp->mb[1], mcp->mb[2], command);)
1da177e4 323 } else {
1c7c6357 324 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1da177e4
LT
325 }
326
1da177e4
LT
327 return rval;
328}
329
1da177e4 330int
590f98e5
AV
331qla2x00_load_ram(scsi_qla_host_t *ha, dma_addr_t req_dma, uint32_t risc_addr,
332 uint32_t risc_code_size)
1da177e4
LT
333{
334 int rval;
335 mbx_cmd_t mc;
336 mbx_cmd_t *mcp = &mc;
1da177e4 337
590f98e5 338 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1da177e4 339
590f98e5
AV
340 if (MSW(risc_addr) || IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
341 mcp->mb[0] = MBC_LOAD_RISC_RAM_EXTENDED;
342 mcp->mb[8] = MSW(risc_addr);
343 mcp->out_mb = MBX_8|MBX_0;
1da177e4 344 } else {
590f98e5
AV
345 mcp->mb[0] = MBC_LOAD_RISC_RAM;
346 mcp->out_mb = MBX_0;
1da177e4 347 }
1da177e4
LT
348 mcp->mb[1] = LSW(risc_addr);
349 mcp->mb[2] = MSW(req_dma);
350 mcp->mb[3] = LSW(req_dma);
1da177e4
LT
351 mcp->mb[6] = MSW(MSD(req_dma));
352 mcp->mb[7] = LSW(MSD(req_dma));
590f98e5 353 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2|MBX_1;
1c7c6357
AV
354 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
355 mcp->mb[4] = MSW(risc_code_size);
356 mcp->mb[5] = LSW(risc_code_size);
357 mcp->out_mb |= MBX_5|MBX_4;
358 } else {
359 mcp->mb[4] = LSW(risc_code_size);
360 mcp->out_mb |= MBX_4;
361 }
362
1da177e4
LT
363 mcp->in_mb = MBX_0;
364 mcp->tov = 30;
365 mcp->flags = 0;
366 rval = qla2x00_mailbox_command(ha, mcp);
367
1da177e4 368 if (rval != QLA_SUCCESS) {
1c7c6357
AV
369 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
370 ha->host_no, rval, mcp->mb[0]));
1da177e4 371 } else {
1da177e4
LT
372 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
373 }
374
375 return rval;
376}
377
378/*
379 * qla2x00_execute_fw
1c7c6357 380 * Start adapter firmware.
1da177e4
LT
381 *
382 * Input:
1c7c6357
AV
383 * ha = adapter block pointer.
384 * TARGET_QUEUE_LOCK must be released.
385 * ADAPTER_STATE_LOCK must be released.
1da177e4
LT
386 *
387 * Returns:
1c7c6357 388 * qla2x00 local function return status code.
1da177e4
LT
389 *
390 * Context:
1c7c6357 391 * Kernel context.
1da177e4
LT
392 */
393int
1c7c6357 394qla2x00_execute_fw(scsi_qla_host_t *ha, uint32_t risc_addr)
1da177e4
LT
395{
396 int rval;
397 mbx_cmd_t mc;
398 mbx_cmd_t *mcp = &mc;
399
1c7c6357 400 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1da177e4
LT
401
402 mcp->mb[0] = MBC_EXECUTE_FIRMWARE;
1c7c6357
AV
403 mcp->out_mb = MBX_0;
404 mcp->in_mb = MBX_0;
405 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
406 mcp->mb[1] = MSW(risc_addr);
407 mcp->mb[2] = LSW(risc_addr);
408 mcp->mb[3] = 0;
409 mcp->out_mb |= MBX_3|MBX_2|MBX_1;
410 mcp->in_mb |= MBX_1;
411 } else {
412 mcp->mb[1] = LSW(risc_addr);
413 mcp->out_mb |= MBX_1;
414 if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
415 mcp->mb[2] = 0;
416 mcp->out_mb |= MBX_2;
417 }
1da177e4
LT
418 }
419
1da177e4
LT
420 mcp->tov = 30;
421 mcp->flags = 0;
422 rval = qla2x00_mailbox_command(ha, mcp);
423
1c7c6357
AV
424 if (rval != QLA_SUCCESS) {
425 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x.\n", __func__,
426 ha->host_no, rval, mcp->mb[0]));
427 } else {
428 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
429 DEBUG11(printk("%s(%ld): done exchanges=%x.\n",
430 __func__, ha->host_no, mcp->mb[1]);)
431 } else {
432 DEBUG11(printk("%s(%ld): done.\n", __func__,
433 ha->host_no);)
434 }
435 }
1da177e4
LT
436
437 return rval;
438}
439
440/*
441 * qla2x00_get_fw_version
442 * Get firmware version.
443 *
444 * Input:
445 * ha: adapter state pointer.
446 * major: pointer for major number.
447 * minor: pointer for minor number.
448 * subminor: pointer for subminor number.
449 *
450 * Returns:
451 * qla2x00 local function return status code.
452 *
453 * Context:
454 * Kernel context.
455 */
456void
457qla2x00_get_fw_version(scsi_qla_host_t *ha, uint16_t *major, uint16_t *minor,
458 uint16_t *subminor, uint16_t *attributes, uint32_t *memory)
459{
460 int rval;
461 mbx_cmd_t mc;
462 mbx_cmd_t *mcp = &mc;
463
464 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
465
466 mcp->mb[0] = MBC_GET_FIRMWARE_VERSION;
467 mcp->out_mb = MBX_0;
468 mcp->in_mb = MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
469 mcp->flags = 0;
470 mcp->tov = 30;
471 rval = qla2x00_mailbox_command(ha, mcp);
472
473 /* Return mailbox data. */
474 *major = mcp->mb[1];
475 *minor = mcp->mb[2];
476 *subminor = mcp->mb[3];
477 *attributes = mcp->mb[6];
478 if (IS_QLA2100(ha) || IS_QLA2200(ha))
479 *memory = 0x1FFFF; /* Defaults to 128KB. */
480 else
481 *memory = (mcp->mb[5] << 16) | mcp->mb[4];
482
483 if (rval != QLA_SUCCESS) {
484 /*EMPTY*/
485 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
486 ha->host_no, rval));
487 } else {
488 /*EMPTY*/
489 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
490 }
491}
492
493/*
494 * qla2x00_get_fw_options
495 * Set firmware options.
496 *
497 * Input:
498 * ha = adapter block pointer.
499 * fwopt = pointer for firmware options.
500 *
501 * Returns:
502 * qla2x00 local function return status code.
503 *
504 * Context:
505 * Kernel context.
506 */
507int
508qla2x00_get_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
509{
510 int rval;
511 mbx_cmd_t mc;
512 mbx_cmd_t *mcp = &mc;
513
514 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
515
516 mcp->mb[0] = MBC_GET_FIRMWARE_OPTION;
517 mcp->out_mb = MBX_0;
518 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
519 mcp->tov = 30;
520 mcp->flags = 0;
521 rval = qla2x00_mailbox_command(ha, mcp);
522
523 if (rval != QLA_SUCCESS) {
524 /*EMPTY*/
525 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
526 ha->host_no, rval));
527 } else {
1c7c6357 528 fwopts[0] = mcp->mb[0];
1da177e4
LT
529 fwopts[1] = mcp->mb[1];
530 fwopts[2] = mcp->mb[2];
531 fwopts[3] = mcp->mb[3];
532
533 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
534 }
535
536 return rval;
537}
538
539
540/*
541 * qla2x00_set_fw_options
542 * Set firmware options.
543 *
544 * Input:
545 * ha = adapter block pointer.
546 * fwopt = pointer for firmware options.
547 *
548 * Returns:
549 * qla2x00 local function return status code.
550 *
551 * Context:
552 * Kernel context.
553 */
554int
555qla2x00_set_fw_options(scsi_qla_host_t *ha, uint16_t *fwopts)
556{
557 int rval;
558 mbx_cmd_t mc;
559 mbx_cmd_t *mcp = &mc;
560
561 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
562
563 mcp->mb[0] = MBC_SET_FIRMWARE_OPTION;
564 mcp->mb[1] = fwopts[1];
565 mcp->mb[2] = fwopts[2];
566 mcp->mb[3] = fwopts[3];
1c7c6357 567 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1da177e4 568 mcp->in_mb = MBX_0;
1c7c6357
AV
569 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
570 mcp->in_mb |= MBX_1;
571 } else {
572 mcp->mb[10] = fwopts[10];
573 mcp->mb[11] = fwopts[11];
574 mcp->mb[12] = 0; /* Undocumented, but used */
575 mcp->out_mb |= MBX_12|MBX_11|MBX_10;
576 }
1da177e4
LT
577 mcp->tov = 30;
578 mcp->flags = 0;
579 rval = qla2x00_mailbox_command(ha, mcp);
580
1c7c6357
AV
581 fwopts[0] = mcp->mb[0];
582
1da177e4
LT
583 if (rval != QLA_SUCCESS) {
584 /*EMPTY*/
1c7c6357
AV
585 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x/%x).\n", __func__,
586 ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1da177e4
LT
587 } else {
588 /*EMPTY*/
589 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
590 }
591
592 return rval;
593}
594
595/*
596 * qla2x00_mbx_reg_test
597 * Mailbox register wrap test.
598 *
599 * Input:
600 * ha = adapter block pointer.
601 * TARGET_QUEUE_LOCK must be released.
602 * ADAPTER_STATE_LOCK must be released.
603 *
604 * Returns:
605 * qla2x00 local function return status code.
606 *
607 * Context:
608 * Kernel context.
609 */
610int
611qla2x00_mbx_reg_test(scsi_qla_host_t *ha)
612{
613 int rval;
614 mbx_cmd_t mc;
615 mbx_cmd_t *mcp = &mc;
616
617 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): entered.\n", ha->host_no);)
618
619 mcp->mb[0] = MBC_MAILBOX_REGISTER_TEST;
620 mcp->mb[1] = 0xAAAA;
621 mcp->mb[2] = 0x5555;
622 mcp->mb[3] = 0xAA55;
623 mcp->mb[4] = 0x55AA;
624 mcp->mb[5] = 0xA5A5;
625 mcp->mb[6] = 0x5A5A;
626 mcp->mb[7] = 0x2525;
627 mcp->out_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
628 mcp->in_mb = MBX_7|MBX_6|MBX_5|MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
629 mcp->tov = 30;
630 mcp->flags = 0;
631 rval = qla2x00_mailbox_command(ha, mcp);
632
633 if (rval == QLA_SUCCESS) {
634 if (mcp->mb[1] != 0xAAAA || mcp->mb[2] != 0x5555 ||
635 mcp->mb[3] != 0xAA55 || mcp->mb[4] != 0x55AA)
636 rval = QLA_FUNCTION_FAILED;
637 if (mcp->mb[5] != 0xA5A5 || mcp->mb[6] != 0x5A5A ||
638 mcp->mb[7] != 0x2525)
639 rval = QLA_FUNCTION_FAILED;
640 }
641
642 if (rval != QLA_SUCCESS) {
643 /*EMPTY*/
644 DEBUG2_3_11(printk("qla2x00_mbx_reg_test(%ld): failed=%x.\n",
645 ha->host_no, rval);)
646 } else {
647 /*EMPTY*/
648 DEBUG11(printk("qla2x00_mbx_reg_test(%ld): done.\n",
649 ha->host_no);)
650 }
651
652 return rval;
653}
654
655/*
656 * qla2x00_verify_checksum
657 * Verify firmware checksum.
658 *
659 * Input:
660 * ha = adapter block pointer.
661 * TARGET_QUEUE_LOCK must be released.
662 * ADAPTER_STATE_LOCK must be released.
663 *
664 * Returns:
665 * qla2x00 local function return status code.
666 *
667 * Context:
668 * Kernel context.
669 */
670int
1c7c6357 671qla2x00_verify_checksum(scsi_qla_host_t *ha, uint32_t risc_addr)
1da177e4
LT
672{
673 int rval;
674 mbx_cmd_t mc;
675 mbx_cmd_t *mcp = &mc;
676
1c7c6357 677 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1da177e4
LT
678
679 mcp->mb[0] = MBC_VERIFY_CHECKSUM;
1c7c6357
AV
680 mcp->out_mb = MBX_0;
681 mcp->in_mb = MBX_0;
682 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
683 mcp->mb[1] = MSW(risc_addr);
684 mcp->mb[2] = LSW(risc_addr);
685 mcp->out_mb |= MBX_2|MBX_1;
686 mcp->in_mb |= MBX_2|MBX_1;
687 } else {
688 mcp->mb[1] = LSW(risc_addr);
689 mcp->out_mb |= MBX_1;
690 mcp->in_mb |= MBX_1;
691 }
692
1da177e4
LT
693 mcp->tov = 30;
694 mcp->flags = 0;
695 rval = qla2x00_mailbox_command(ha, mcp);
696
697 if (rval != QLA_SUCCESS) {
1c7c6357
AV
698 DEBUG2_3_11(printk("%s(%ld): failed=%x chk sum=%x.\n", __func__,
699 ha->host_no, rval, (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
700 (mcp->mb[2] << 16) | mcp->mb[1]: mcp->mb[1]));)
1da177e4 701 } else {
1c7c6357 702 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1da177e4
LT
703 }
704
705 return rval;
706}
707
708/*
709 * qla2x00_issue_iocb
710 * Issue IOCB using mailbox command
711 *
712 * Input:
713 * ha = adapter state pointer.
714 * buffer = buffer pointer.
715 * phys_addr = physical address of buffer.
716 * size = size of buffer.
717 * TARGET_QUEUE_LOCK must be released.
718 * ADAPTER_STATE_LOCK must be released.
719 *
720 * Returns:
721 * qla2x00 local function return status code.
722 *
723 * Context:
724 * Kernel context.
725 */
726int
727qla2x00_issue_iocb(scsi_qla_host_t *ha, void* buffer, dma_addr_t phys_addr,
728 size_t size)
729{
730 int rval;
731 mbx_cmd_t mc;
732 mbx_cmd_t *mcp = &mc;
733
734 mcp->mb[0] = MBC_IOCB_COMMAND_A64;
735 mcp->mb[1] = 0;
736 mcp->mb[2] = MSW(phys_addr);
737 mcp->mb[3] = LSW(phys_addr);
738 mcp->mb[6] = MSW(MSD(phys_addr));
739 mcp->mb[7] = LSW(MSD(phys_addr));
740 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
741 mcp->in_mb = MBX_2|MBX_0;
742 mcp->tov = 30;
743 mcp->flags = 0;
744 rval = qla2x00_mailbox_command(ha, mcp);
745
746 if (rval != QLA_SUCCESS) {
747 /*EMPTY*/
1c7c6357
AV
748 DEBUG(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
749 ha->host_no, rval);)
750 DEBUG2(printk("qla2x00_issue_iocb(%ld): failed rval 0x%x\n",
751 ha->host_no, rval);)
1da177e4 752 } else {
8c958a99
AV
753 sts_entry_t *sts_entry = (sts_entry_t *) buffer;
754
755 /* Mask reserved bits. */
756 sts_entry->entry_status &=
757 IS_QLA24XX(ha) || IS_QLA25XX(ha) ? RF_MASK_24XX :RF_MASK;
1da177e4
LT
758 }
759
760 return rval;
761}
762
763/*
764 * qla2x00_abort_command
765 * Abort command aborts a specified IOCB.
766 *
767 * Input:
768 * ha = adapter block pointer.
769 * sp = SB structure pointer.
770 *
771 * Returns:
772 * qla2x00 local function return status code.
773 *
774 * Context:
775 * Kernel context.
776 */
777int
778qla2x00_abort_command(scsi_qla_host_t *ha, srb_t *sp)
779{
780 unsigned long flags = 0;
781 fc_port_t *fcport;
782 int rval;
783 uint32_t handle;
784 mbx_cmd_t mc;
785 mbx_cmd_t *mcp = &mc;
786
787 DEBUG11(printk("qla2x00_abort_command(%ld): entered.\n", ha->host_no);)
788
bdf79621 789 fcport = sp->fcport;
1da177e4
LT
790
791 spin_lock_irqsave(&ha->hardware_lock, flags);
792 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
793 if (ha->outstanding_cmds[handle] == sp)
794 break;
795 }
796 spin_unlock_irqrestore(&ha->hardware_lock, flags);
797
798 if (handle == MAX_OUTSTANDING_COMMANDS) {
799 /* command not found */
800 return QLA_FUNCTION_FAILED;
801 }
802
803 mcp->mb[0] = MBC_ABORT_COMMAND;
804 if (HAS_EXTENDED_IDS(ha))
805 mcp->mb[1] = fcport->loop_id;
806 else
807 mcp->mb[1] = fcport->loop_id << 8;
808 mcp->mb[2] = (uint16_t)handle;
809 mcp->mb[3] = (uint16_t)(handle >> 16);
bdf79621 810 mcp->mb[6] = (uint16_t)sp->cmd->device->lun;
1da177e4
LT
811 mcp->out_mb = MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
812 mcp->in_mb = MBX_0;
813 mcp->tov = 30;
814 mcp->flags = 0;
815 rval = qla2x00_mailbox_command(ha, mcp);
816
817 if (rval != QLA_SUCCESS) {
818 DEBUG2_3_11(printk("qla2x00_abort_command(%ld): failed=%x.\n",
819 ha->host_no, rval);)
820 } else {
821 sp->flags |= SRB_ABORT_PENDING;
822 DEBUG11(printk("qla2x00_abort_command(%ld): done.\n",
823 ha->host_no);)
824 }
825
826 return rval;
827}
828
829#if USE_ABORT_TGT
830/*
831 * qla2x00_abort_target
832 * Issue abort target mailbox command.
833 *
834 * Input:
835 * ha = adapter block pointer.
836 *
837 * Returns:
838 * qla2x00 local function return status code.
839 *
840 * Context:
841 * Kernel context.
842 */
843int
844qla2x00_abort_target(fc_port_t *fcport)
845{
846 int rval;
847 mbx_cmd_t mc;
848 mbx_cmd_t *mcp = &mc;
1c7c6357 849 scsi_qla_host_t *ha;
1da177e4 850
1c7c6357 851 if (fcport == NULL)
1da177e4 852 return 0;
1da177e4 853
1c7c6357
AV
854 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
855
856 ha = fcport->ha;
1da177e4
LT
857 mcp->mb[0] = MBC_ABORT_TARGET;
858 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1c7c6357 859 if (HAS_EXTENDED_IDS(ha)) {
1da177e4
LT
860 mcp->mb[1] = fcport->loop_id;
861 mcp->mb[10] = 0;
862 mcp->out_mb |= MBX_10;
863 } else {
864 mcp->mb[1] = fcport->loop_id << 8;
865 }
1c7c6357 866 mcp->mb[2] = ha->loop_reset_delay;
1da177e4
LT
867
868 mcp->in_mb = MBX_0;
869 mcp->tov = 30;
870 mcp->flags = 0;
1c7c6357 871 rval = qla2x00_mailbox_command(ha, mcp);
1da177e4
LT
872
873 /* Issue marker command. */
1c7c6357 874 ha->marker_needed = 1;
1da177e4
LT
875
876 if (rval != QLA_SUCCESS) {
877 DEBUG2_3_11(printk("qla2x00_abort_target(%ld): failed=%x.\n",
1c7c6357 878 ha->host_no, rval);)
1da177e4
LT
879 } else {
880 /*EMPTY*/
881 DEBUG11(printk("qla2x00_abort_target(%ld): done.\n",
1c7c6357 882 ha->host_no);)
1da177e4
LT
883 }
884
885 return rval;
886}
887#endif
888
1da177e4
LT
889/*
890 * qla2x00_get_adapter_id
891 * Get adapter ID and topology.
892 *
893 * Input:
894 * ha = adapter block pointer.
895 * id = pointer for loop ID.
896 * al_pa = pointer for AL_PA.
897 * area = pointer for area.
898 * domain = pointer for domain.
899 * top = pointer for topology.
900 * TARGET_QUEUE_LOCK must be released.
901 * ADAPTER_STATE_LOCK must be released.
902 *
903 * Returns:
904 * qla2x00 local function return status code.
905 *
906 * Context:
907 * Kernel context.
908 */
909int
910qla2x00_get_adapter_id(scsi_qla_host_t *ha, uint16_t *id, uint8_t *al_pa,
911 uint8_t *area, uint8_t *domain, uint16_t *top)
912{
913 int rval;
914 mbx_cmd_t mc;
915 mbx_cmd_t *mcp = &mc;
916
917 DEBUG11(printk("qla2x00_get_adapter_id(%ld): entered.\n",
918 ha->host_no);)
919
920 mcp->mb[0] = MBC_GET_ADAPTER_LOOP_ID;
921 mcp->out_mb = MBX_0;
922 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
923 mcp->tov = 30;
924 mcp->flags = 0;
925 rval = qla2x00_mailbox_command(ha, mcp);
33135aa2
RA
926 if (mcp->mb[0] == MBS_COMMAND_ERROR)
927 rval = QLA_COMMAND_ERROR;
1da177e4
LT
928
929 /* Return data. */
930 *id = mcp->mb[1];
931 *al_pa = LSB(mcp->mb[2]);
932 *area = MSB(mcp->mb[2]);
933 *domain = LSB(mcp->mb[3]);
934 *top = mcp->mb[6];
935
936 if (rval != QLA_SUCCESS) {
937 /*EMPTY*/
938 DEBUG2_3_11(printk("qla2x00_get_adapter_id(%ld): failed=%x.\n",
939 ha->host_no, rval);)
940 } else {
941 /*EMPTY*/
942 DEBUG11(printk("qla2x00_get_adapter_id(%ld): done.\n",
943 ha->host_no);)
944 }
945
946 return rval;
947}
948
949/*
950 * qla2x00_get_retry_cnt
951 * Get current firmware login retry count and delay.
952 *
953 * Input:
954 * ha = adapter block pointer.
955 * retry_cnt = pointer to login retry count.
956 * tov = pointer to login timeout value.
957 *
958 * Returns:
959 * qla2x00 local function return status code.
960 *
961 * Context:
962 * Kernel context.
963 */
964int
965qla2x00_get_retry_cnt(scsi_qla_host_t *ha, uint8_t *retry_cnt, uint8_t *tov,
966 uint16_t *r_a_tov)
967{
968 int rval;
969 uint16_t ratov;
970 mbx_cmd_t mc;
971 mbx_cmd_t *mcp = &mc;
972
973 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): entered.\n",
974 ha->host_no);)
975
976 mcp->mb[0] = MBC_GET_RETRY_COUNT;
977 mcp->out_mb = MBX_0;
978 mcp->in_mb = MBX_3|MBX_2|MBX_1|MBX_0;
979 mcp->tov = 30;
980 mcp->flags = 0;
981 rval = qla2x00_mailbox_command(ha, mcp);
982
983 if (rval != QLA_SUCCESS) {
984 /*EMPTY*/
985 DEBUG2_3_11(printk("qla2x00_get_retry_cnt(%ld): failed = %x.\n",
986 ha->host_no, mcp->mb[0]);)
987 } else {
988 /* Convert returned data and check our values. */
989 *r_a_tov = mcp->mb[3] / 2;
990 ratov = (mcp->mb[3]/2) / 10; /* mb[3] value is in 100ms */
991 if (mcp->mb[1] * ratov > (*retry_cnt) * (*tov)) {
992 /* Update to the larger values */
993 *retry_cnt = (uint8_t)mcp->mb[1];
994 *tov = ratov;
995 }
996
997 DEBUG11(printk("qla2x00_get_retry_cnt(%ld): done. mb3=%d "
998 "ratov=%d.\n", ha->host_no, mcp->mb[3], ratov);)
999 }
1000
1001 return rval;
1002}
1003
1004/*
1005 * qla2x00_init_firmware
1006 * Initialize adapter firmware.
1007 *
1008 * Input:
1009 * ha = adapter block pointer.
1010 * dptr = Initialization control block pointer.
1011 * size = size of initialization control block.
1012 * TARGET_QUEUE_LOCK must be released.
1013 * ADAPTER_STATE_LOCK must be released.
1014 *
1015 * Returns:
1016 * qla2x00 local function return status code.
1017 *
1018 * Context:
1019 * Kernel context.
1020 */
1021int
1022qla2x00_init_firmware(scsi_qla_host_t *ha, uint16_t size)
1023{
1024 int rval;
1025 mbx_cmd_t mc;
1026 mbx_cmd_t *mcp = &mc;
1027
1028 DEBUG11(printk("qla2x00_init_firmware(%ld): entered.\n",
1029 ha->host_no);)
1030
1031 mcp->mb[0] = MBC_INITIALIZE_FIRMWARE;
1032 mcp->mb[2] = MSW(ha->init_cb_dma);
1033 mcp->mb[3] = LSW(ha->init_cb_dma);
1034 mcp->mb[4] = 0;
1035 mcp->mb[5] = 0;
1036 mcp->mb[6] = MSW(MSD(ha->init_cb_dma));
1037 mcp->mb[7] = LSW(MSD(ha->init_cb_dma));
1038 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1039 mcp->in_mb = MBX_5|MBX_4|MBX_0;
1040 mcp->buf_size = size;
1041 mcp->flags = MBX_DMA_OUT;
1042 mcp->tov = 30;
1043 rval = qla2x00_mailbox_command(ha, mcp);
1044
1045 if (rval != QLA_SUCCESS) {
1046 /*EMPTY*/
1047 DEBUG2_3_11(printk("qla2x00_init_firmware(%ld): failed=%x "
1048 "mb0=%x.\n",
1049 ha->host_no, rval, mcp->mb[0]);)
1050 } else {
1051 /*EMPTY*/
1052 DEBUG11(printk("qla2x00_init_firmware(%ld): done.\n",
1053 ha->host_no);)
1054 }
1055
1056 return rval;
1057}
1058
1059/*
1060 * qla2x00_get_port_database
1061 * Issue normal/enhanced get port database mailbox command
1062 * and copy device name as necessary.
1063 *
1064 * Input:
1065 * ha = adapter state pointer.
1066 * dev = structure pointer.
1067 * opt = enhanced cmd option byte.
1068 *
1069 * Returns:
1070 * qla2x00 local function return status code.
1071 *
1072 * Context:
1073 * Kernel context.
1074 */
1075int
1076qla2x00_get_port_database(scsi_qla_host_t *ha, fc_port_t *fcport, uint8_t opt)
1077{
1078 int rval;
1079 mbx_cmd_t mc;
1080 mbx_cmd_t *mcp = &mc;
1081 port_database_t *pd;
1c7c6357 1082 struct port_database_24xx *pd24;
1da177e4
LT
1083 dma_addr_t pd_dma;
1084
1c7c6357 1085 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1da177e4 1086
1c7c6357
AV
1087 pd24 = NULL;
1088 pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1da177e4 1089 if (pd == NULL) {
1c7c6357
AV
1090 DEBUG2_3(printk("%s(%ld): failed to allocate Port Database "
1091 "structure.\n", __func__, ha->host_no));
1da177e4
LT
1092 return QLA_MEMORY_ALLOC_FAILED;
1093 }
1c7c6357 1094 memset(pd, 0, max(PORT_DATABASE_SIZE, PORT_DATABASE_24XX_SIZE));
1da177e4 1095
1c7c6357
AV
1096 mcp->mb[0] = MBC_GET_PORT_DATABASE;
1097 if (opt != 0 && !IS_QLA24XX(ha) && !IS_QLA25XX(ha))
1da177e4 1098 mcp->mb[0] = MBC_ENHANCED_GET_PORT_DATABASE;
1da177e4
LT
1099 mcp->mb[2] = MSW(pd_dma);
1100 mcp->mb[3] = LSW(pd_dma);
1101 mcp->mb[6] = MSW(MSD(pd_dma));
1102 mcp->mb[7] = LSW(MSD(pd_dma));
1c7c6357 1103 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1da177e4 1104 mcp->in_mb = MBX_0;
1c7c6357
AV
1105 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1106 mcp->mb[1] = fcport->loop_id;
1107 mcp->mb[10] = opt;
1108 mcp->out_mb |= MBX_10|MBX_1;
1109 mcp->in_mb |= MBX_1;
1110 } else if (HAS_EXTENDED_IDS(ha)) {
1111 mcp->mb[1] = fcport->loop_id;
1112 mcp->mb[10] = opt;
1113 mcp->out_mb |= MBX_10|MBX_1;
1114 } else {
1115 mcp->mb[1] = fcport->loop_id << 8 | opt;
1116 mcp->out_mb |= MBX_1;
1117 }
1118 mcp->buf_size = (IS_QLA24XX(ha) || IS_QLA25XX(ha) ?
1119 PORT_DATABASE_24XX_SIZE : PORT_DATABASE_SIZE);
1da177e4
LT
1120 mcp->flags = MBX_DMA_IN;
1121 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1122 rval = qla2x00_mailbox_command(ha, mcp);
1123 if (rval != QLA_SUCCESS)
1124 goto gpd_error_out;
1125
1c7c6357
AV
1126 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1127 pd24 = (struct port_database_24xx *) pd;
1128
1129 /* Check for logged in state. */
1130 if (pd24->current_login_state != PDS_PRLI_COMPLETE &&
1131 pd24->last_login_state != PDS_PRLI_COMPLETE) {
1132 DEBUG2(printk("%s(%ld): Unable to verify "
1133 "login-state (%x/%x) for loop_id %x\n",
1134 __func__, ha->host_no,
1135 pd24->current_login_state,
1136 pd24->last_login_state, fcport->loop_id));
1137 rval = QLA_FUNCTION_FAILED;
1138 goto gpd_error_out;
1139 }
1da177e4 1140
1c7c6357
AV
1141 /* Names are little-endian. */
1142 memcpy(fcport->node_name, pd24->node_name, WWN_SIZE);
1143 memcpy(fcport->port_name, pd24->port_name, WWN_SIZE);
1144
1145 /* Get port_id of device. */
1146 fcport->d_id.b.domain = pd24->port_id[0];
1147 fcport->d_id.b.area = pd24->port_id[1];
1148 fcport->d_id.b.al_pa = pd24->port_id[2];
1149 fcport->d_id.b.rsvd_1 = 0;
1150
1151 /* If not target must be initiator or unknown type. */
1152 if ((pd24->prli_svc_param_word_3[0] & BIT_4) == 0)
1153 fcport->port_type = FCT_INITIATOR;
1154 else
1155 fcport->port_type = FCT_TARGET;
1156 } else {
1157 /* Check for logged in state. */
1158 if (pd->master_state != PD_STATE_PORT_LOGGED_IN &&
1159 pd->slave_state != PD_STATE_PORT_LOGGED_IN) {
1160 rval = QLA_FUNCTION_FAILED;
1161 goto gpd_error_out;
1162 }
1da177e4 1163
1c7c6357
AV
1164 /* Names are little-endian. */
1165 memcpy(fcport->node_name, pd->node_name, WWN_SIZE);
1166 memcpy(fcport->port_name, pd->port_name, WWN_SIZE);
1167
1168 /* Get port_id of device. */
1169 fcport->d_id.b.domain = pd->port_id[0];
1170 fcport->d_id.b.area = pd->port_id[3];
1171 fcport->d_id.b.al_pa = pd->port_id[2];
1172 fcport->d_id.b.rsvd_1 = 0;
1173
1174 /* Check for device require authentication. */
1175 pd->common_features & BIT_5 ? (fcport->flags |= FCF_AUTH_REQ) :
1176 (fcport->flags &= ~FCF_AUTH_REQ);
1177
1178 /* If not target must be initiator or unknown type. */
1179 if ((pd->prli_svc_param_word_3[0] & BIT_4) == 0)
1180 fcport->port_type = FCT_INITIATOR;
1181 else
1182 fcport->port_type = FCT_TARGET;
ad3e0eda
AV
1183
1184 /* Passback COS information. */
1185 fcport->supported_classes = (pd->options & BIT_4) ?
1186 FC_COS_CLASS2: FC_COS_CLASS3;
1c7c6357 1187 }
1da177e4
LT
1188
1189gpd_error_out:
1190 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1191
1192 if (rval != QLA_SUCCESS) {
1c7c6357
AV
1193 DEBUG2_3_11(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x.\n",
1194 __func__, ha->host_no, rval, mcp->mb[0], mcp->mb[1]));
1da177e4 1195 } else {
1c7c6357 1196 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
1da177e4
LT
1197 }
1198
1199 return rval;
1200}
1201
1202/*
1203 * qla2x00_get_firmware_state
1204 * Get adapter firmware state.
1205 *
1206 * Input:
1207 * ha = adapter block pointer.
1208 * dptr = pointer for firmware state.
1209 * TARGET_QUEUE_LOCK must be released.
1210 * ADAPTER_STATE_LOCK must be released.
1211 *
1212 * Returns:
1213 * qla2x00 local function return status code.
1214 *
1215 * Context:
1216 * Kernel context.
1217 */
1218int
1219qla2x00_get_firmware_state(scsi_qla_host_t *ha, uint16_t *dptr)
1220{
1221 int rval;
1222 mbx_cmd_t mc;
1223 mbx_cmd_t *mcp = &mc;
1224
1225 DEBUG11(printk("qla2x00_get_firmware_state(%ld): entered.\n",
1226 ha->host_no);)
1227
1228 mcp->mb[0] = MBC_GET_FIRMWARE_STATE;
1229 mcp->out_mb = MBX_0;
1230 mcp->in_mb = MBX_2|MBX_1|MBX_0;
1231 mcp->tov = 30;
1232 mcp->flags = 0;
1233 rval = qla2x00_mailbox_command(ha, mcp);
1234
1235 /* Return firmware state. */
1236 *dptr = mcp->mb[1];
1237
1238 if (rval != QLA_SUCCESS) {
1239 /*EMPTY*/
1240 DEBUG2_3_11(printk("qla2x00_get_firmware_state(%ld): "
1241 "failed=%x.\n", ha->host_no, rval);)
1242 } else {
1243 /*EMPTY*/
1244 DEBUG11(printk("qla2x00_get_firmware_state(%ld): done.\n",
1245 ha->host_no);)
1246 }
1247
1248 return rval;
1249}
1250
1251/*
1252 * qla2x00_get_port_name
1253 * Issue get port name mailbox command.
1254 * Returned name is in big endian format.
1255 *
1256 * Input:
1257 * ha = adapter block pointer.
1258 * loop_id = loop ID of device.
1259 * name = pointer for name.
1260 * TARGET_QUEUE_LOCK must be released.
1261 * ADAPTER_STATE_LOCK must be released.
1262 *
1263 * Returns:
1264 * qla2x00 local function return status code.
1265 *
1266 * Context:
1267 * Kernel context.
1268 */
1269int
1270qla2x00_get_port_name(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t *name,
1271 uint8_t opt)
1272{
1273 int rval;
1274 mbx_cmd_t mc;
1275 mbx_cmd_t *mcp = &mc;
1276
1277 DEBUG11(printk("qla2x00_get_port_name(%ld): entered.\n",
1278 ha->host_no);)
1279
1280 mcp->mb[0] = MBC_GET_PORT_NAME;
1281 mcp->out_mb = MBX_1|MBX_0;
1282 if (HAS_EXTENDED_IDS(ha)) {
1283 mcp->mb[1] = loop_id;
1284 mcp->mb[10] = opt;
1285 mcp->out_mb |= MBX_10;
1286 } else {
1287 mcp->mb[1] = loop_id << 8 | opt;
1288 }
1289
1290 mcp->in_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1291 mcp->tov = 30;
1292 mcp->flags = 0;
1293 rval = qla2x00_mailbox_command(ha, mcp);
1294
1295 if (rval != QLA_SUCCESS) {
1296 /*EMPTY*/
1297 DEBUG2_3_11(printk("qla2x00_get_port_name(%ld): failed=%x.\n",
1298 ha->host_no, rval);)
1299 } else {
1300 if (name != NULL) {
1301 /* This function returns name in big endian. */
1302 name[0] = LSB(mcp->mb[2]);
1303 name[1] = MSB(mcp->mb[2]);
1304 name[2] = LSB(mcp->mb[3]);
1305 name[3] = MSB(mcp->mb[3]);
1306 name[4] = LSB(mcp->mb[6]);
1307 name[5] = MSB(mcp->mb[6]);
1308 name[6] = LSB(mcp->mb[7]);
1309 name[7] = MSB(mcp->mb[7]);
1310 }
1311
1312 DEBUG11(printk("qla2x00_get_port_name(%ld): done.\n",
1313 ha->host_no);)
1314 }
1315
1316 return rval;
1317}
1318
1319/*
1320 * qla2x00_lip_reset
1321 * Issue LIP reset mailbox command.
1322 *
1323 * Input:
1324 * ha = adapter block pointer.
1325 * TARGET_QUEUE_LOCK must be released.
1326 * ADAPTER_STATE_LOCK must be released.
1327 *
1328 * Returns:
1329 * qla2x00 local function return status code.
1330 *
1331 * Context:
1332 * Kernel context.
1333 */
1334int
1335qla2x00_lip_reset(scsi_qla_host_t *ha)
1336{
1337 int rval;
1338 mbx_cmd_t mc;
1339 mbx_cmd_t *mcp = &mc;
1340
1c7c6357 1341 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1da177e4 1342
1c7c6357
AV
1343 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1344 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1345 mcp->mb[1] = BIT_0;
1346 mcp->mb[2] = 0xff;
1347 mcp->mb[3] = 0;
1348 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1da177e4 1349 } else {
1c7c6357
AV
1350 mcp->mb[0] = MBC_LIP_RESET;
1351 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1352 if (HAS_EXTENDED_IDS(ha)) {
1353 mcp->mb[1] = 0x00ff;
1354 mcp->mb[10] = 0;
1355 mcp->out_mb |= MBX_10;
1356 } else {
1357 mcp->mb[1] = 0xff00;
1358 }
1359 mcp->mb[2] = ha->loop_reset_delay;
1360 mcp->mb[3] = 0;
1da177e4 1361 }
1da177e4
LT
1362 mcp->in_mb = MBX_0;
1363 mcp->tov = 30;
1364 mcp->flags = 0;
1365 rval = qla2x00_mailbox_command(ha, mcp);
1366
1367 if (rval != QLA_SUCCESS) {
1368 /*EMPTY*/
1c7c6357
AV
1369 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n",
1370 __func__, ha->host_no, rval);)
1da177e4
LT
1371 } else {
1372 /*EMPTY*/
1c7c6357 1373 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1da177e4
LT
1374 }
1375
1376 return rval;
1377}
1378
1379/*
1380 * qla2x00_send_sns
1381 * Send SNS command.
1382 *
1383 * Input:
1384 * ha = adapter block pointer.
1385 * sns = pointer for command.
1386 * cmd_size = command size.
1387 * buf_size = response/command size.
1388 * TARGET_QUEUE_LOCK must be released.
1389 * ADAPTER_STATE_LOCK must be released.
1390 *
1391 * Returns:
1392 * qla2x00 local function return status code.
1393 *
1394 * Context:
1395 * Kernel context.
1396 */
1397int
1398qla2x00_send_sns(scsi_qla_host_t *ha, dma_addr_t sns_phys_address,
1399 uint16_t cmd_size, size_t buf_size)
1400{
1401 int rval;
1402 mbx_cmd_t mc;
1403 mbx_cmd_t *mcp = &mc;
1404
1405 DEBUG11(printk("qla2x00_send_sns(%ld): entered.\n",
1406 ha->host_no);)
1407
1408 DEBUG11(printk("qla2x00_send_sns: retry cnt=%d ratov=%d total "
1409 "tov=%d.\n", ha->retry_count, ha->login_timeout, mcp->tov);)
1410
1411 mcp->mb[0] = MBC_SEND_SNS_COMMAND;
1412 mcp->mb[1] = cmd_size;
1413 mcp->mb[2] = MSW(sns_phys_address);
1414 mcp->mb[3] = LSW(sns_phys_address);
1415 mcp->mb[6] = MSW(MSD(sns_phys_address));
1416 mcp->mb[7] = LSW(MSD(sns_phys_address));
1417 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1418 mcp->in_mb = MBX_0|MBX_1;
1419 mcp->buf_size = buf_size;
1420 mcp->flags = MBX_DMA_OUT|MBX_DMA_IN;
1421 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1422 rval = qla2x00_mailbox_command(ha, mcp);
1423
1424 if (rval != QLA_SUCCESS) {
1425 /*EMPTY*/
1426 DEBUG(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1427 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1428 DEBUG2_3_11(printk("qla2x00_send_sns(%ld): failed=%x mb[0]=%x "
1429 "mb[1]=%x.\n", ha->host_no, rval, mcp->mb[0], mcp->mb[1]);)
1430 } else {
1431 /*EMPTY*/
1432 DEBUG11(printk("qla2x00_send_sns(%ld): done.\n", ha->host_no);)
1433 }
1434
1435 return rval;
1436}
1437
1c7c6357
AV
1438int
1439qla24xx_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1440 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1441{
1442 int rval;
1443
1444 struct logio_entry_24xx *lg;
1445 dma_addr_t lg_dma;
1446 uint32_t iop[2];
1447
1448 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1449
1450 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1451 if (lg == NULL) {
1452 DEBUG2_3(printk("%s(%ld): failed to allocate Login IOCB.\n",
1453 __func__, ha->host_no));
1454 return QLA_MEMORY_ALLOC_FAILED;
1455 }
1456 memset(lg, 0, sizeof(struct logio_entry_24xx));
1457
1458 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1459 lg->entry_count = 1;
1460 lg->nport_handle = cpu_to_le16(loop_id);
1461 lg->control_flags = __constant_cpu_to_le16(LCF_COMMAND_PLOGI);
1462 if (opt & BIT_0)
1463 lg->control_flags |= __constant_cpu_to_le16(LCF_COND_PLOGI);
1464 lg->port_id[0] = al_pa;
1465 lg->port_id[1] = area;
1466 lg->port_id[2] = domain;
1467 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1468 if (rval != QLA_SUCCESS) {
1469 DEBUG2_3_11(printk("%s(%ld): failed to issue Login IOCB "
1470 "(%x).\n", __func__, ha->host_no, rval);)
1471 } else if (lg->entry_status != 0) {
1472 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1473 "-- error status (%x).\n", __func__, ha->host_no,
1474 lg->entry_status));
1475 rval = QLA_FUNCTION_FAILED;
1476 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1477 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1478 iop[1] = le32_to_cpu(lg->io_parameter[1]);
1479
1480 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1481 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1482 ha->host_no, le16_to_cpu(lg->comp_status), iop[0],
1483 iop[1]));
1484
1485 switch (iop[0]) {
1486 case LSC_SCODE_PORTID_USED:
1487 mb[0] = MBS_PORT_ID_USED;
1488 mb[1] = LSW(iop[1]);
1489 break;
1490 case LSC_SCODE_NPORT_USED:
1491 mb[0] = MBS_LOOP_ID_USED;
1492 break;
1493 case LSC_SCODE_NOLINK:
1494 case LSC_SCODE_NOIOCB:
1495 case LSC_SCODE_NOXCB:
1496 case LSC_SCODE_CMD_FAILED:
1497 case LSC_SCODE_NOFABRIC:
1498 case LSC_SCODE_FW_NOT_READY:
1499 case LSC_SCODE_NOT_LOGGED_IN:
1500 case LSC_SCODE_NOPCB:
1501 case LSC_SCODE_ELS_REJECT:
1502 case LSC_SCODE_CMD_PARAM_ERR:
1503 case LSC_SCODE_NONPORT:
1504 case LSC_SCODE_LOGGED_IN:
1505 case LSC_SCODE_NOFLOGI_ACC:
1506 default:
1507 mb[0] = MBS_COMMAND_ERROR;
1508 break;
1509 }
1510 } else {
1511 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1512
1513 iop[0] = le32_to_cpu(lg->io_parameter[0]);
1514
1515 mb[0] = MBS_COMMAND_COMPLETE;
1516 mb[1] = 0;
1517 if (iop[0] & BIT_4) {
1518 if (iop[0] & BIT_8)
1519 mb[1] |= BIT_1;
1520 } else
1521 mb[1] = BIT_0;
ad3e0eda
AV
1522
1523 /* Passback COS information. */
1524 mb[10] = 0;
1525 if (lg->io_parameter[7] || lg->io_parameter[8])
1526 mb[10] |= BIT_0; /* Class 2. */
1527 if (lg->io_parameter[9] || lg->io_parameter[10])
1528 mb[10] |= BIT_1; /* Class 3. */
1c7c6357
AV
1529 }
1530
1531 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1532
1533 return rval;
1534}
1535
1da177e4
LT
1536/*
1537 * qla2x00_login_fabric
1538 * Issue login fabric port mailbox command.
1539 *
1540 * Input:
1541 * ha = adapter block pointer.
1542 * loop_id = device loop ID.
1543 * domain = device domain.
1544 * area = device area.
1545 * al_pa = device AL_PA.
1546 * status = pointer for return status.
1547 * opt = command options.
1548 * TARGET_QUEUE_LOCK must be released.
1549 * ADAPTER_STATE_LOCK must be released.
1550 *
1551 * Returns:
1552 * qla2x00 local function return status code.
1553 *
1554 * Context:
1555 * Kernel context.
1556 */
1557int
1558qla2x00_login_fabric(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1559 uint8_t area, uint8_t al_pa, uint16_t *mb, uint8_t opt)
1560{
1561 int rval;
1562 mbx_cmd_t mc;
1563 mbx_cmd_t *mcp = &mc;
1564
1565 DEBUG11(printk("qla2x00_login_fabric(%ld): entered.\n", ha->host_no);)
1566
1567 mcp->mb[0] = MBC_LOGIN_FABRIC_PORT;
1568 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1569 if (HAS_EXTENDED_IDS(ha)) {
1570 mcp->mb[1] = loop_id;
1571 mcp->mb[10] = opt;
1572 mcp->out_mb |= MBX_10;
1573 } else {
1574 mcp->mb[1] = (loop_id << 8) | opt;
1575 }
1576 mcp->mb[2] = domain;
1577 mcp->mb[3] = area << 8 | al_pa;
1578
1579 mcp->in_mb = MBX_7|MBX_6|MBX_2|MBX_1|MBX_0;
1580 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1581 mcp->flags = 0;
1582 rval = qla2x00_mailbox_command(ha, mcp);
1583
1584 /* Return mailbox statuses. */
1585 if (mb != NULL) {
1586 mb[0] = mcp->mb[0];
1587 mb[1] = mcp->mb[1];
1588 mb[2] = mcp->mb[2];
1589 mb[6] = mcp->mb[6];
1590 mb[7] = mcp->mb[7];
ad3e0eda
AV
1591 /* COS retrieved from Get-Port-Database mailbox command. */
1592 mb[10] = 0;
1da177e4
LT
1593 }
1594
1595 if (rval != QLA_SUCCESS) {
1596 /* RLU tmp code: need to change main mailbox_command function to
1597 * return ok even when the mailbox completion value is not
1598 * SUCCESS. The caller needs to be responsible to interpret
1599 * the return values of this mailbox command if we're not
1600 * to change too much of the existing code.
1601 */
1602 if (mcp->mb[0] == 0x4001 || mcp->mb[0] == 0x4002 ||
1603 mcp->mb[0] == 0x4003 || mcp->mb[0] == 0x4005 ||
1604 mcp->mb[0] == 0x4006)
1605 rval = QLA_SUCCESS;
1606
1607 /*EMPTY*/
1608 DEBUG2_3_11(printk("qla2x00_login_fabric(%ld): failed=%x "
1609 "mb[0]=%x mb[1]=%x mb[2]=%x.\n", ha->host_no, rval,
1610 mcp->mb[0], mcp->mb[1], mcp->mb[2]);)
1611 } else {
1612 /*EMPTY*/
1613 DEBUG11(printk("qla2x00_login_fabric(%ld): done.\n",
1614 ha->host_no);)
1615 }
1616
1617 return rval;
1618}
1619
1620/*
1621 * qla2x00_login_local_device
1622 * Issue login loop port mailbox command.
fa2a1ce5 1623 *
1da177e4
LT
1624 * Input:
1625 * ha = adapter block pointer.
1626 * loop_id = device loop ID.
1627 * opt = command options.
fa2a1ce5 1628 *
1da177e4
LT
1629 * Returns:
1630 * Return status code.
fa2a1ce5 1631 *
1da177e4
LT
1632 * Context:
1633 * Kernel context.
fa2a1ce5 1634 *
1da177e4
LT
1635 */
1636int
1637qla2x00_login_local_device(scsi_qla_host_t *ha, uint16_t loop_id,
1638 uint16_t *mb_ret, uint8_t opt)
1639{
1640 int rval;
1641 mbx_cmd_t mc;
1642 mbx_cmd_t *mcp = &mc;
1643
1644 DEBUG3(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1645
1646 mcp->mb[0] = MBC_LOGIN_LOOP_PORT;
1647 if (HAS_EXTENDED_IDS(ha))
1648 mcp->mb[1] = loop_id;
1649 else
1650 mcp->mb[1] = loop_id << 8;
1651 mcp->mb[2] = opt;
1652 mcp->out_mb = MBX_2|MBX_1|MBX_0;
1653 mcp->in_mb = MBX_7|MBX_6|MBX_1|MBX_0;
1654 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1655 mcp->flags = 0;
1656 rval = qla2x00_mailbox_command(ha, mcp);
1657
1658 /* Return mailbox statuses. */
1659 if (mb_ret != NULL) {
1660 mb_ret[0] = mcp->mb[0];
1661 mb_ret[1] = mcp->mb[1];
1662 mb_ret[6] = mcp->mb[6];
1663 mb_ret[7] = mcp->mb[7];
1664 }
1665
1666 if (rval != QLA_SUCCESS) {
1667 /* AV tmp code: need to change main mailbox_command function to
1668 * return ok even when the mailbox completion value is not
1669 * SUCCESS. The caller needs to be responsible to interpret
1670 * the return values of this mailbox command if we're not
1671 * to change too much of the existing code.
1672 */
1673 if (mcp->mb[0] == 0x4005 || mcp->mb[0] == 0x4006)
1674 rval = QLA_SUCCESS;
1675
1676 DEBUG(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1677 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1678 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1679 DEBUG2_3(printk("%s(%ld): failed=%x mb[0]=%x mb[1]=%x "
1680 "mb[6]=%x mb[7]=%x.\n", __func__, ha->host_no, rval,
1681 mcp->mb[0], mcp->mb[1], mcp->mb[6], mcp->mb[7]);)
1682 } else {
1683 /*EMPTY*/
1684 DEBUG3(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1685 }
1686
1687 return (rval);
1688}
1689
1c7c6357
AV
1690int
1691qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1692 uint8_t area, uint8_t al_pa)
1693{
1694 int rval;
1695 struct logio_entry_24xx *lg;
1696 dma_addr_t lg_dma;
1697
1698 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
1699
1700 lg = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &lg_dma);
1701 if (lg == NULL) {
1702 DEBUG2_3(printk("%s(%ld): failed to allocate Logout IOCB.\n",
1703 __func__, ha->host_no));
1704 return QLA_MEMORY_ALLOC_FAILED;
1705 }
1706 memset(lg, 0, sizeof(struct logio_entry_24xx));
1707
1708 lg->entry_type = LOGINOUT_PORT_IOCB_TYPE;
1709 lg->entry_count = 1;
1710 lg->nport_handle = cpu_to_le16(loop_id);
1711 lg->control_flags =
1712 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO);
1713 lg->port_id[0] = al_pa;
1714 lg->port_id[1] = area;
1715 lg->port_id[2] = domain;
1716 rval = qla2x00_issue_iocb(ha, lg, lg_dma, 0);
1717 if (rval != QLA_SUCCESS) {
1718 DEBUG2_3_11(printk("%s(%ld): failed to issue Logout IOCB "
1719 "(%x).\n", __func__, ha->host_no, rval);)
1720 } else if (lg->entry_status != 0) {
1721 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1722 "-- error status (%x).\n", __func__, ha->host_no,
1723 lg->entry_status));
1724 rval = QLA_FUNCTION_FAILED;
1725 } else if (lg->comp_status != __constant_cpu_to_le16(CS_COMPLETE)) {
1726 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
1727 "-- completion status (%x) ioparam=%x/%x.\n", __func__,
1728 ha->host_no, le16_to_cpu(lg->comp_status),
1729 le32_to_cpu(lg->io_parameter[0]),
1730 le32_to_cpu(lg->io_parameter[1]));)
1731 } else {
1732 /*EMPTY*/
1733 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
1734 }
1735
1736 dma_pool_free(ha->s_dma_pool, lg, lg_dma);
1737
1738 return rval;
1739}
1740
1da177e4
LT
1741/*
1742 * qla2x00_fabric_logout
1743 * Issue logout fabric port mailbox command.
1744 *
1745 * Input:
1746 * ha = adapter block pointer.
1747 * loop_id = device loop ID.
1748 * TARGET_QUEUE_LOCK must be released.
1749 * ADAPTER_STATE_LOCK must be released.
1750 *
1751 * Returns:
1752 * qla2x00 local function return status code.
1753 *
1754 * Context:
1755 * Kernel context.
1756 */
1757int
1c7c6357
AV
1758qla2x00_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1759 uint8_t area, uint8_t al_pa)
1da177e4
LT
1760{
1761 int rval;
1762 mbx_cmd_t mc;
1763 mbx_cmd_t *mcp = &mc;
1764
1765 DEBUG11(printk("qla2x00_fabric_logout(%ld): entered.\n",
1766 ha->host_no);)
1767
1768 mcp->mb[0] = MBC_LOGOUT_FABRIC_PORT;
1769 mcp->out_mb = MBX_1|MBX_0;
1770 if (HAS_EXTENDED_IDS(ha)) {
1771 mcp->mb[1] = loop_id;
1772 mcp->mb[10] = 0;
1773 mcp->out_mb |= MBX_10;
1774 } else {
1775 mcp->mb[1] = loop_id << 8;
1776 }
1777
1778 mcp->in_mb = MBX_1|MBX_0;
1779 mcp->tov = 30;
1780 mcp->flags = 0;
1781 rval = qla2x00_mailbox_command(ha, mcp);
1782
1783 if (rval != QLA_SUCCESS) {
1784 /*EMPTY*/
1785 DEBUG2_3_11(printk("qla2x00_fabric_logout(%ld): failed=%x "
1786 "mbx1=%x.\n", ha->host_no, rval, mcp->mb[1]);)
1787 } else {
1788 /*EMPTY*/
1789 DEBUG11(printk("qla2x00_fabric_logout(%ld): done.\n",
1790 ha->host_no);)
1791 }
1792
1793 return rval;
1794}
1795
1796/*
1797 * qla2x00_full_login_lip
1798 * Issue full login LIP mailbox command.
1799 *
1800 * Input:
1801 * ha = adapter block pointer.
1802 * TARGET_QUEUE_LOCK must be released.
1803 * ADAPTER_STATE_LOCK must be released.
1804 *
1805 * Returns:
1806 * qla2x00 local function return status code.
1807 *
1808 * Context:
1809 * Kernel context.
1810 */
1811int
1812qla2x00_full_login_lip(scsi_qla_host_t *ha)
1813{
1814 int rval;
1815 mbx_cmd_t mc;
1816 mbx_cmd_t *mcp = &mc;
1817
1818 DEBUG11(printk("qla2x00_full_login_lip(%ld): entered.\n",
1819 ha->host_no);)
1820
1821 mcp->mb[0] = MBC_LIP_FULL_LOGIN;
1822 mcp->mb[1] = 0;
1c7c6357 1823 mcp->mb[2] = 0xff;
1da177e4
LT
1824 mcp->mb[3] = 0;
1825 mcp->out_mb = MBX_3|MBX_2|MBX_1|MBX_0;
1826 mcp->in_mb = MBX_0;
1827 mcp->tov = 30;
1828 mcp->flags = 0;
1829 rval = qla2x00_mailbox_command(ha, mcp);
1830
1831 if (rval != QLA_SUCCESS) {
1832 /*EMPTY*/
1833 DEBUG2_3_11(printk("qla2x00_full_login_lip(%ld): failed=%x.\n",
1c7c6357 1834 ha->host_no, rval);)
1da177e4
LT
1835 } else {
1836 /*EMPTY*/
1837 DEBUG11(printk("qla2x00_full_login_lip(%ld): done.\n",
1838 ha->host_no);)
1839 }
1840
1841 return rval;
1842}
1843
1844/*
1845 * qla2x00_get_id_list
1846 *
1847 * Input:
1848 * ha = adapter block pointer.
1849 *
1850 * Returns:
1851 * qla2x00 local function return status code.
1852 *
1853 * Context:
1854 * Kernel context.
1855 */
1856int
1857qla2x00_get_id_list(scsi_qla_host_t *ha, void *id_list, dma_addr_t id_list_dma,
1858 uint16_t *entries)
1859{
1860 int rval;
1861 mbx_cmd_t mc;
1862 mbx_cmd_t *mcp = &mc;
1863
1864 DEBUG11(printk("qla2x00_get_id_list(%ld): entered.\n",
1865 ha->host_no);)
1866
1867 if (id_list == NULL)
1868 return QLA_FUNCTION_FAILED;
1869
1870 mcp->mb[0] = MBC_GET_ID_LIST;
1c7c6357
AV
1871 mcp->out_mb = MBX_0;
1872 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
1873 mcp->mb[2] = MSW(id_list_dma);
1874 mcp->mb[3] = LSW(id_list_dma);
1875 mcp->mb[6] = MSW(MSD(id_list_dma));
1876 mcp->mb[7] = LSW(MSD(id_list_dma));
1877 mcp->out_mb |= MBX_7|MBX_6|MBX_3|MBX_2;
1878 } else {
1879 mcp->mb[1] = MSW(id_list_dma);
1880 mcp->mb[2] = LSW(id_list_dma);
1881 mcp->mb[3] = MSW(MSD(id_list_dma));
1882 mcp->mb[6] = LSW(MSD(id_list_dma));
1883 mcp->out_mb |= MBX_6|MBX_3|MBX_2|MBX_1;
1884 }
1da177e4
LT
1885 mcp->in_mb = MBX_1|MBX_0;
1886 mcp->tov = 30;
1887 mcp->flags = 0;
1888 rval = qla2x00_mailbox_command(ha, mcp);
1889
1890 if (rval != QLA_SUCCESS) {
1891 /*EMPTY*/
1892 DEBUG2_3_11(printk("qla2x00_get_id_list(%ld): failed=%x.\n",
1893 ha->host_no, rval);)
1894 } else {
1895 *entries = mcp->mb[1];
1896 DEBUG11(printk("qla2x00_get_id_list(%ld): done.\n",
1897 ha->host_no);)
1898 }
1899
1900 return rval;
1901}
1902
1903/*
1904 * qla2x00_get_resource_cnts
1905 * Get current firmware resource counts.
1906 *
1907 * Input:
1908 * ha = adapter block pointer.
1909 *
1910 * Returns:
1911 * qla2x00 local function return status code.
1912 *
1913 * Context:
1914 * Kernel context.
1915 */
1916int
1917qla2x00_get_resource_cnts(scsi_qla_host_t *ha, uint16_t *cur_xchg_cnt,
1918 uint16_t *orig_xchg_cnt, uint16_t *cur_iocb_cnt, uint16_t *orig_iocb_cnt)
1919{
1920 int rval;
1921 mbx_cmd_t mc;
1922 mbx_cmd_t *mcp = &mc;
1923
1924 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
1925
1926 mcp->mb[0] = MBC_GET_RESOURCE_COUNTS;
1927 mcp->out_mb = MBX_0;
1928 mcp->in_mb = MBX_10|MBX_7|MBX_6|MBX_3|MBX_2|MBX_1|MBX_0;
1929 mcp->tov = 30;
1930 mcp->flags = 0;
1931 rval = qla2x00_mailbox_command(ha, mcp);
1932
1933 if (rval != QLA_SUCCESS) {
1934 /*EMPTY*/
1935 DEBUG2_3_11(printk("%s(%ld): failed = %x.\n", __func__,
1936 ha->host_no, mcp->mb[0]);)
1937 } else {
1938 DEBUG11(printk("%s(%ld): done. mb1=%x mb2=%x mb3=%x mb6=%x "
1939 "mb7=%x mb10=%x.\n", __func__, ha->host_no,
fa2a1ce5 1940 mcp->mb[1], mcp->mb[2], mcp->mb[3], mcp->mb[6], mcp->mb[7],
1da177e4
LT
1941 mcp->mb[10]));
1942
1943 if (cur_xchg_cnt)
1944 *cur_xchg_cnt = mcp->mb[3];
1945 if (orig_xchg_cnt)
1946 *orig_xchg_cnt = mcp->mb[6];
1947 if (cur_iocb_cnt)
1948 *cur_iocb_cnt = mcp->mb[7];
1949 if (orig_iocb_cnt)
1950 *orig_iocb_cnt = mcp->mb[10];
1951 }
1952
1953 return (rval);
1954}
1955
1956#if defined(QL_DEBUG_LEVEL_3)
1957/*
1958 * qla2x00_get_fcal_position_map
1959 * Get FCAL (LILP) position map using mailbox command
1960 *
1961 * Input:
1962 * ha = adapter state pointer.
1963 * pos_map = buffer pointer (can be NULL).
1964 *
1965 * Returns:
1966 * qla2x00 local function return status code.
1967 *
1968 * Context:
1969 * Kernel context.
1970 */
1971int
1972qla2x00_get_fcal_position_map(scsi_qla_host_t *ha, char *pos_map)
1973{
1974 int rval;
1975 mbx_cmd_t mc;
1976 mbx_cmd_t *mcp = &mc;
1977 char *pmap;
1978 dma_addr_t pmap_dma;
1979
1980 pmap = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &pmap_dma);
1981 if (pmap == NULL) {
1982 DEBUG2_3_11(printk("%s(%ld): **** Mem Alloc Failed ****",
1983 __func__, ha->host_no));
1984 return QLA_MEMORY_ALLOC_FAILED;
1985 }
1986 memset(pmap, 0, FCAL_MAP_SIZE);
1987
1988 mcp->mb[0] = MBC_GET_FC_AL_POSITION_MAP;
1989 mcp->mb[2] = MSW(pmap_dma);
1990 mcp->mb[3] = LSW(pmap_dma);
1991 mcp->mb[6] = MSW(MSD(pmap_dma));
1992 mcp->mb[7] = LSW(MSD(pmap_dma));
1993 mcp->out_mb = MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
1994 mcp->in_mb = MBX_1|MBX_0;
1995 mcp->buf_size = FCAL_MAP_SIZE;
1996 mcp->flags = MBX_DMA_IN;
1997 mcp->tov = (ha->login_timeout * 2) + (ha->login_timeout / 2);
1998 rval = qla2x00_mailbox_command(ha, mcp);
1999
2000 if (rval == QLA_SUCCESS) {
2001 DEBUG11(printk("%s(%ld): (mb0=%x/mb1=%x) FC/AL Position Map "
2002 "size (%x)\n", __func__, ha->host_no, mcp->mb[0],
2003 mcp->mb[1], (unsigned)pmap[0]));
2004 DEBUG11(qla2x00_dump_buffer(pmap, pmap[0] + 1));
2005
2006 if (pos_map)
2007 memcpy(pos_map, pmap, FCAL_MAP_SIZE);
2008 }
2009 dma_pool_free(ha->s_dma_pool, pmap, pmap_dma);
2010
2011 if (rval != QLA_SUCCESS) {
2012 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2013 ha->host_no, rval));
2014 } else {
2015 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2016 }
2017
2018 return rval;
2019}
1c7c6357
AV
2020
2021uint8_t
2022qla24xx_get_isp_stats(scsi_qla_host_t *ha, uint32_t *dwbuf, uint32_t dwords,
2023 uint16_t *status)
2024{
2025 int rval;
2026 mbx_cmd_t mc;
2027 mbx_cmd_t *mcp = &mc;
2028 uint32_t *sbuf, *siter;
2029 dma_addr_t sbuf_dma;
2030
2031 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2032
2033 if (dwords > (DMA_POOL_SIZE / 4)) {
2034 DEBUG2_3_11(printk("%s(%ld): Unabled to retrieve %d DWORDs "
2035 "(max %d).\n", __func__, ha->host_no, dwords,
2036 DMA_POOL_SIZE / 4));
2037 return BIT_0;
2038 }
2039 sbuf = dma_pool_alloc(ha->s_dma_pool, GFP_ATOMIC, &sbuf_dma);
2040 if (sbuf == NULL) {
2041 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
2042 __func__, ha->host_no));
2043 return BIT_0;
2044 }
2045 memset(sbuf, 0, DMA_POOL_SIZE);
2046
2047 mcp->mb[0] = MBC_GET_LINK_PRIV_STATS;
2048 mcp->mb[2] = MSW(sbuf_dma);
2049 mcp->mb[3] = LSW(sbuf_dma);
2050 mcp->mb[6] = MSW(MSD(sbuf_dma));
2051 mcp->mb[7] = LSW(MSD(sbuf_dma));
2052 mcp->mb[8] = dwords;
2053 mcp->mb[10] = 0;
2054 mcp->out_mb = MBX_10|MBX_8|MBX_7|MBX_6|MBX_3|MBX_2|MBX_0;
2055 mcp->in_mb = MBX_2|MBX_1|MBX_0;
2056 mcp->tov = 30;
2057 mcp->flags = IOCTL_CMD;
2058 rval = qla2x00_mailbox_command(ha, mcp);
2059
2060 if (rval == QLA_SUCCESS) {
2061 if (mcp->mb[0] != MBS_COMMAND_COMPLETE) {
2062 DEBUG2_3_11(printk("%s(%ld): cmd failed. mbx0=%x.\n",
2063 __func__, ha->host_no, mcp->mb[0]));
2064 status[0] = mcp->mb[0];
2065 rval = BIT_1;
2066 } else {
2067 /* Copy over data -- firmware data is LE. */
2068 siter = sbuf;
2069 while (dwords--)
2070 *dwbuf++ = le32_to_cpu(*siter++);
2071 }
2072 } else {
2073 /* Failed. */
2074 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2075 ha->host_no, rval));
2076 rval = BIT_1;
2077 }
2078
2079 dma_pool_free(ha->s_dma_pool, sbuf, sbuf_dma);
2080
2081 return rval;
2082}
1da177e4 2083#endif
1c7c6357
AV
2084
2085int
2086qla24xx_abort_command(scsi_qla_host_t *ha, srb_t *sp)
2087{
2088 int rval;
2089 fc_port_t *fcport;
2090 unsigned long flags = 0;
2091
2092 struct abort_entry_24xx *abt;
2093 dma_addr_t abt_dma;
2094 uint32_t handle;
2095
2096 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no);)
2097
2098 fcport = sp->fcport;
1c7c6357
AV
2099
2100 spin_lock_irqsave(&ha->hardware_lock, flags);
2101 for (handle = 1; handle < MAX_OUTSTANDING_COMMANDS; handle++) {
2102 if (ha->outstanding_cmds[handle] == sp)
2103 break;
2104 }
2105 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2106 if (handle == MAX_OUTSTANDING_COMMANDS) {
2107 /* Command not found. */
2108 return QLA_FUNCTION_FAILED;
2109 }
2110
2111 abt = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &abt_dma);
2112 if (abt == NULL) {
2113 DEBUG2_3(printk("%s(%ld): failed to allocate Abort IOCB.\n",
2114 __func__, ha->host_no));
2115 return QLA_MEMORY_ALLOC_FAILED;
2116 }
2117 memset(abt, 0, sizeof(struct abort_entry_24xx));
2118
2119 abt->entry_type = ABORT_IOCB_TYPE;
2120 abt->entry_count = 1;
2121 abt->nport_handle = cpu_to_le16(fcport->loop_id);
2122 abt->handle_to_abort = handle;
2123 abt->port_id[0] = fcport->d_id.b.al_pa;
2124 abt->port_id[1] = fcport->d_id.b.area;
2125 abt->port_id[2] = fcport->d_id.b.domain;
2126 rval = qla2x00_issue_iocb(ha, abt, abt_dma, 0);
2127 if (rval != QLA_SUCCESS) {
2128 DEBUG2_3_11(printk("%s(%ld): failed to issue IOCB (%x).\n",
2129 __func__, ha->host_no, rval);)
2130 } else if (abt->entry_status != 0) {
2131 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2132 "-- error status (%x).\n", __func__, ha->host_no,
2133 abt->entry_status));
2134 rval = QLA_FUNCTION_FAILED;
2135 } else if (abt->nport_handle != __constant_cpu_to_le16(0)) {
2136 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2137 "-- completion status (%x).\n", __func__, ha->host_no,
2138 le16_to_cpu(abt->nport_handle));)
2139 rval = QLA_FUNCTION_FAILED;
2140 } else {
2141 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2142 sp->flags |= SRB_ABORT_PENDING;
2143 }
2144
2145 dma_pool_free(ha->s_dma_pool, abt, abt_dma);
2146
2147 return rval;
2148}
2149
2150struct tsk_mgmt_cmd {
2151 union {
2152 struct tsk_mgmt_entry tsk;
2153 struct sts_entry_24xx sts;
2154 } p;
2155};
2156
2157int
2158qla24xx_abort_target(fc_port_t *fcport)
2159{
2160 int rval;
2161 struct tsk_mgmt_cmd *tsk;
2162 dma_addr_t tsk_dma;
2163 scsi_qla_host_t *ha;
2164
2165 if (fcport == NULL)
2166 return 0;
2167
2168 DEBUG11(printk("%s(%ld): entered.\n", __func__, fcport->ha->host_no);)
2169
2170 ha = fcport->ha;
2171 tsk = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &tsk_dma);
2172 if (tsk == NULL) {
2173 DEBUG2_3(printk("%s(%ld): failed to allocate Task Management "
2174 "IOCB.\n", __func__, ha->host_no));
2175 return QLA_MEMORY_ALLOC_FAILED;
2176 }
2177 memset(tsk, 0, sizeof(struct tsk_mgmt_cmd));
2178
2179 tsk->p.tsk.entry_type = TSK_MGMT_IOCB_TYPE;
2180 tsk->p.tsk.entry_count = 1;
2181 tsk->p.tsk.nport_handle = cpu_to_le16(fcport->loop_id);
2182 tsk->p.tsk.timeout = __constant_cpu_to_le16(25);
2183 tsk->p.tsk.control_flags = __constant_cpu_to_le32(TCF_TARGET_RESET);
2184 tsk->p.tsk.port_id[0] = fcport->d_id.b.al_pa;
2185 tsk->p.tsk.port_id[1] = fcport->d_id.b.area;
2186 tsk->p.tsk.port_id[2] = fcport->d_id.b.domain;
2187 rval = qla2x00_issue_iocb(ha, tsk, tsk_dma, 0);
2188 if (rval != QLA_SUCCESS) {
2189 DEBUG2_3_11(printk("%s(%ld): failed to issue Target Reset IOCB "
2190 "(%x).\n", __func__, ha->host_no, rval);)
2191 goto atarget_done;
2192 } else if (tsk->p.sts.entry_status != 0) {
2193 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2194 "-- error status (%x).\n", __func__, ha->host_no,
2195 tsk->p.sts.entry_status));
2196 rval = QLA_FUNCTION_FAILED;
2197 goto atarget_done;
2198 } else if (tsk->p.sts.comp_status !=
2199 __constant_cpu_to_le16(CS_COMPLETE)) {
2200 DEBUG2_3_11(printk("%s(%ld): failed to complete IOCB "
2201 "-- completion status (%x).\n", __func__,
2202 ha->host_no, le16_to_cpu(tsk->p.sts.comp_status));)
2203 rval = QLA_FUNCTION_FAILED;
2204 goto atarget_done;
2205 }
2206
2207 /* Issue marker IOCB. */
2208 rval = qla2x00_marker(ha, fcport->loop_id, 0, MK_SYNC_ID);
2209 if (rval != QLA_SUCCESS) {
2210 DEBUG2_3_11(printk("%s(%ld): failed to issue Marker IOCB "
2211 "(%x).\n", __func__, ha->host_no, rval);)
2212 } else {
2213 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no);)
2214 }
2215
2216atarget_done:
2217 dma_pool_free(ha->s_dma_pool, tsk, tsk_dma);
2218
2219 return rval;
2220}
2221
2222int
2223qla2x00_system_error(scsi_qla_host_t *ha)
2224{
2225 int rval;
2226 mbx_cmd_t mc;
2227 mbx_cmd_t *mcp = &mc;
2228
2229 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
2230 return QLA_FUNCTION_FAILED;
2231
2232 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2233
2234 mcp->mb[0] = MBC_GEN_SYSTEM_ERROR;
2235 mcp->out_mb = MBX_0;
2236 mcp->in_mb = MBX_0;
2237 mcp->tov = 5;
2238 mcp->flags = 0;
2239 rval = qla2x00_mailbox_command(ha, mcp);
2240
2241 if (rval != QLA_SUCCESS) {
2242 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2243 ha->host_no, rval));
2244 } else {
2245 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2246 }
2247
2248 return rval;
2249}
2250
2251/**
2252 * qla2x00_get_serdes_params() -
2253 * @ha: HA context
2254 *
2255 * Returns
2256 */
2257int
2258qla2x00_get_serdes_params(scsi_qla_host_t *ha, uint16_t *sw_em_1g,
2259 uint16_t *sw_em_2g, uint16_t *sw_em_4g)
2260{
2261 int rval;
2262 mbx_cmd_t mc;
2263 mbx_cmd_t *mcp = &mc;
2264
2265 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2266
2267 mcp->mb[0] = MBC_SERDES_PARAMS;
2268 mcp->mb[1] = 0;
2269 mcp->out_mb = MBX_1|MBX_0;
2270 mcp->in_mb = MBX_4|MBX_3|MBX_2|MBX_0;
2271 mcp->tov = 30;
2272 mcp->flags = 0;
2273 rval = qla2x00_mailbox_command(ha, mcp);
2274
2275 if (rval != QLA_SUCCESS) {
2276 /*EMPTY*/
2277 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2278 ha->host_no, rval, mcp->mb[0]));
2279 } else {
2280 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2281
2282 if (sw_em_1g)
2283 *sw_em_1g = mcp->mb[2];
2284 if (sw_em_2g)
2285 *sw_em_2g = mcp->mb[3];
2286 if (sw_em_4g)
2287 *sw_em_4g = mcp->mb[4];
2288 }
2289
2290 return rval;
2291}
2292
2293/**
2294 * qla2x00_set_serdes_params() -
2295 * @ha: HA context
2296 *
2297 * Returns
2298 */
2299int
2300qla2x00_set_serdes_params(scsi_qla_host_t *ha, uint16_t sw_em_1g,
2301 uint16_t sw_em_2g, uint16_t sw_em_4g)
2302{
2303 int rval;
2304 mbx_cmd_t mc;
2305 mbx_cmd_t *mcp = &mc;
2306
2307 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2308
2309 mcp->mb[0] = MBC_SERDES_PARAMS;
2310 mcp->mb[1] = BIT_0;
2311 mcp->mb[2] = sw_em_1g;
2312 mcp->mb[3] = sw_em_2g;
2313 mcp->mb[4] = sw_em_4g;
2314 mcp->out_mb = MBX_4|MBX_3|MBX_2|MBX_1|MBX_0;
2315 mcp->in_mb = MBX_0;
2316 mcp->tov = 30;
2317 mcp->flags = 0;
2318 rval = qla2x00_mailbox_command(ha, mcp);
2319
2320 if (rval != QLA_SUCCESS) {
2321 /*EMPTY*/
2322 DEBUG2_3_11(printk("%s(%ld): failed=%x (%x).\n", __func__,
2323 ha->host_no, rval, mcp->mb[0]));
2324 } else {
2325 /*EMPTY*/
2326 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2327 }
2328
2329 return rval;
2330}
f6ef3b18
AV
2331
2332int
2333qla2x00_stop_firmware(scsi_qla_host_t *ha)
2334{
2335 int rval;
2336 mbx_cmd_t mc;
2337 mbx_cmd_t *mcp = &mc;
2338
2339 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
2340 return QLA_FUNCTION_FAILED;
2341
2342 DEBUG11(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2343
2344 mcp->mb[0] = MBC_STOP_FIRMWARE;
2345 mcp->out_mb = MBX_0;
2346 mcp->in_mb = MBX_0;
2347 mcp->tov = 5;
2348 mcp->flags = 0;
2349 rval = qla2x00_mailbox_command(ha, mcp);
2350
2351 if (rval != QLA_SUCCESS) {
2352 DEBUG2_3_11(printk("%s(%ld): failed=%x.\n", __func__,
2353 ha->host_no, rval));
2354 } else {
2355 DEBUG11(printk("%s(%ld): done.\n", __func__, ha->host_no));
2356 }
2357
2358 return rval;
2359}