Linux 2.6.33-rc8
[linux-2.6/lguest.git] / drivers / net / qlge / qlge_mpi.c
blobe2b2286102d498795de75319c7f76920bb8f84fb
1 #include "qlge.h"
3 int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
5 int status;
6 /* wait for reg to come ready */
7 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
8 if (status)
9 goto exit;
10 /* set up for reg read */
11 ql_write32(qdev, PROC_ADDR, reg | PROC_ADDR_R);
12 /* wait for reg to come ready */
13 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
14 if (status)
15 goto exit;
16 /* get the data */
17 *data = ql_read32(qdev, PROC_DATA);
18 exit:
19 return status;
22 int ql_write_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 data)
24 int status = 0;
25 /* wait for reg to come ready */
26 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
27 if (status)
28 goto exit;
29 /* write the data to the data reg */
30 ql_write32(qdev, PROC_DATA, data);
31 /* trigger the write */
32 ql_write32(qdev, PROC_ADDR, reg);
33 /* wait for reg to come ready */
34 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
35 if (status)
36 goto exit;
37 exit:
38 return status;
41 int ql_soft_reset_mpi_risc(struct ql_adapter *qdev)
43 int status;
44 status = ql_write_mpi_reg(qdev, 0x00001010, 1);
45 return status;
48 static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
50 int i, status;
52 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
53 if (status)
54 return -EBUSY;
55 for (i = 0; i < mbcp->out_count; i++) {
56 status =
57 ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
58 &mbcp->mbox_out[i]);
59 if (status) {
60 QPRINTK(qdev, DRV, ERR, "Failed mailbox read.\n");
61 break;
64 ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */
65 return status;
68 /* Wait for a single mailbox command to complete.
69 * Returns zero on success.
71 static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev)
73 int count = 100;
74 u32 value;
76 do {
77 value = ql_read32(qdev, STS);
78 if (value & STS_PI)
79 return 0;
80 mdelay(UDELAY_DELAY); /* 100ms */
81 } while (--count);
82 return -ETIMEDOUT;
85 /* Execute a single mailbox command.
86 * Caller must hold PROC_ADDR semaphore.
88 static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp)
90 int i, status;
93 * Make sure there's nothing pending.
94 * This shouldn't happen.
96 if (ql_read32(qdev, CSR) & CSR_HRI)
97 return -EIO;
99 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
100 if (status)
101 return status;
104 * Fill the outbound mailboxes.
106 for (i = 0; i < mbcp->in_count; i++) {
107 status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i,
108 mbcp->mbox_in[i]);
109 if (status)
110 goto end;
113 * Wake up the MPI firmware.
115 ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT);
116 end:
117 ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
118 return status;
121 /* We are being asked by firmware to accept
122 * a change to the port. This is only
123 * a change to max frame sizes (Tx/Rx), pause
124 * parameters, or loopback mode. We wake up a worker
125 * to handler processing this since a mailbox command
126 * will need to be sent to ACK the request.
128 static int ql_idc_req_aen(struct ql_adapter *qdev)
130 int status;
131 struct mbox_params *mbcp = &qdev->idc_mbc;
133 QPRINTK(qdev, DRV, ERR, "Enter!\n");
134 /* Get the status data and start up a thread to
135 * handle the request.
137 mbcp = &qdev->idc_mbc;
138 mbcp->out_count = 4;
139 status = ql_get_mb_sts(qdev, mbcp);
140 if (status) {
141 QPRINTK(qdev, DRV, ERR,
142 "Could not read MPI, resetting ASIC!\n");
143 ql_queue_asic_error(qdev);
144 } else {
145 /* Begin polled mode early so
146 * we don't get another interrupt
147 * when we leave mpi_worker.
149 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
150 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
152 return status;
155 /* Process an inter-device event completion.
156 * If good, signal the caller's completion.
158 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
160 int status;
161 struct mbox_params *mbcp = &qdev->idc_mbc;
162 mbcp->out_count = 4;
163 status = ql_get_mb_sts(qdev, mbcp);
164 if (status) {
165 QPRINTK(qdev, DRV, ERR,
166 "Could not read MPI, resetting RISC!\n");
167 ql_queue_fw_error(qdev);
168 } else
169 /* Wake up the sleeping mpi_idc_work thread that is
170 * waiting for this event.
172 complete(&qdev->ide_completion);
174 return status;
177 static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
179 int status;
180 mbcp->out_count = 2;
182 status = ql_get_mb_sts(qdev, mbcp);
183 if (status) {
184 QPRINTK(qdev, DRV, ERR,
185 "%s: Could not get mailbox status.\n", __func__);
186 return;
189 qdev->link_status = mbcp->mbox_out[1];
190 QPRINTK(qdev, DRV, ERR, "Link Up.\n");
192 /* If we're coming back from an IDC event
193 * then set up the CAM and frame routing.
195 if (test_bit(QL_CAM_RT_SET, &qdev->flags)) {
196 status = ql_cam_route_initialize(qdev);
197 if (status) {
198 QPRINTK(qdev, IFUP, ERR,
199 "Failed to init CAM/Routing tables.\n");
200 return;
201 } else
202 clear_bit(QL_CAM_RT_SET, &qdev->flags);
205 /* Queue up a worker to check the frame
206 * size information, and fix it if it's not
207 * to our liking.
209 if (!test_bit(QL_PORT_CFG, &qdev->flags)) {
210 QPRINTK(qdev, DRV, ERR, "Queue Port Config Worker!\n");
211 set_bit(QL_PORT_CFG, &qdev->flags);
212 /* Begin polled mode early so
213 * we don't get another interrupt
214 * when we leave mpi_worker dpc.
216 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
217 queue_delayed_work(qdev->workqueue,
218 &qdev->mpi_port_cfg_work, 0);
221 ql_link_on(qdev);
224 static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
226 int status;
228 mbcp->out_count = 3;
230 status = ql_get_mb_sts(qdev, mbcp);
231 if (status)
232 QPRINTK(qdev, DRV, ERR, "Link down AEN broken!\n");
234 ql_link_off(qdev);
237 static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
239 int status;
241 mbcp->out_count = 5;
243 status = ql_get_mb_sts(qdev, mbcp);
244 if (status)
245 QPRINTK(qdev, DRV, ERR, "SFP in AEN broken!\n");
246 else
247 QPRINTK(qdev, DRV, ERR, "SFP insertion detected.\n");
249 return status;
252 static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
254 int status;
256 mbcp->out_count = 1;
258 status = ql_get_mb_sts(qdev, mbcp);
259 if (status)
260 QPRINTK(qdev, DRV, ERR, "SFP out AEN broken!\n");
261 else
262 QPRINTK(qdev, DRV, ERR, "SFP removal detected.\n");
264 return status;
267 static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp)
269 int status;
271 mbcp->out_count = 6;
273 status = ql_get_mb_sts(qdev, mbcp);
274 if (status)
275 QPRINTK(qdev, DRV, ERR, "Lost AEN broken!\n");
276 else {
277 int i;
278 QPRINTK(qdev, DRV, ERR, "Lost AEN detected.\n");
279 for (i = 0; i < mbcp->out_count; i++)
280 QPRINTK(qdev, DRV, ERR, "mbox_out[%d] = 0x%.08x.\n",
281 i, mbcp->mbox_out[i]);
285 return status;
288 static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
290 int status;
292 mbcp->out_count = 2;
294 status = ql_get_mb_sts(qdev, mbcp);
295 if (status) {
296 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
297 } else {
298 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
299 mbcp->mbox_out[1]);
300 qdev->fw_rev_id = mbcp->mbox_out[1];
301 status = ql_cam_route_initialize(qdev);
302 if (status)
303 QPRINTK(qdev, IFUP, ERR,
304 "Failed to init CAM/Routing tables.\n");
308 /* Process an async event and clear it unless it's an
309 * error condition.
310 * This can get called iteratively from the mpi_work thread
311 * when events arrive via an interrupt.
312 * It also gets called when a mailbox command is polling for
313 * it's completion. */
314 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
316 int status;
317 int orig_count = mbcp->out_count;
319 /* Just get mailbox zero for now. */
320 mbcp->out_count = 1;
321 status = ql_get_mb_sts(qdev, mbcp);
322 if (status) {
323 QPRINTK(qdev, DRV, ERR,
324 "Could not read MPI, resetting ASIC!\n");
325 ql_queue_asic_error(qdev);
326 goto end;
329 switch (mbcp->mbox_out[0]) {
331 /* This case is only active when we arrive here
332 * as a result of issuing a mailbox command to
333 * the firmware.
335 case MB_CMD_STS_INTRMDT:
336 case MB_CMD_STS_GOOD:
337 case MB_CMD_STS_INVLD_CMD:
338 case MB_CMD_STS_XFC_ERR:
339 case MB_CMD_STS_CSUM_ERR:
340 case MB_CMD_STS_ERR:
341 case MB_CMD_STS_PARAM_ERR:
342 /* We can only get mailbox status if we're polling from an
343 * unfinished command. Get the rest of the status data and
344 * return back to the caller.
345 * We only end up here when we're polling for a mailbox
346 * command completion.
348 mbcp->out_count = orig_count;
349 status = ql_get_mb_sts(qdev, mbcp);
350 return status;
352 /* We are being asked by firmware to accept
353 * a change to the port. This is only
354 * a change to max frame sizes (Tx/Rx), pause
355 * parameters, or loopback mode.
357 case AEN_IDC_REQ:
358 status = ql_idc_req_aen(qdev);
359 break;
361 /* Process and inbound IDC event.
362 * This will happen when we're trying to
363 * change tx/rx max frame size, change pause
364 * parameters or loopback mode.
366 case AEN_IDC_CMPLT:
367 case AEN_IDC_EXT:
368 status = ql_idc_cmplt_aen(qdev);
369 break;
371 case AEN_LINK_UP:
372 ql_link_up(qdev, mbcp);
373 break;
375 case AEN_LINK_DOWN:
376 ql_link_down(qdev, mbcp);
377 break;
379 case AEN_FW_INIT_DONE:
380 /* If we're in process on executing the firmware,
381 * then convert the status to normal mailbox status.
383 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
384 mbcp->out_count = orig_count;
385 status = ql_get_mb_sts(qdev, mbcp);
386 mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
387 return status;
389 ql_init_fw_done(qdev, mbcp);
390 break;
392 case AEN_AEN_SFP_IN:
393 ql_sfp_in(qdev, mbcp);
394 break;
396 case AEN_AEN_SFP_OUT:
397 ql_sfp_out(qdev, mbcp);
398 break;
400 /* This event can arrive at boot time or after an
401 * MPI reset if the firmware failed to initialize.
403 case AEN_FW_INIT_FAIL:
404 /* If we're in process on executing the firmware,
405 * then convert the status to normal mailbox status.
407 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
408 mbcp->out_count = orig_count;
409 status = ql_get_mb_sts(qdev, mbcp);
410 mbcp->mbox_out[0] = MB_CMD_STS_ERR;
411 return status;
413 QPRINTK(qdev, DRV, ERR,
414 "Firmware initialization failed.\n");
415 status = -EIO;
416 ql_queue_fw_error(qdev);
417 break;
419 case AEN_SYS_ERR:
420 QPRINTK(qdev, DRV, ERR,
421 "System Error.\n");
422 ql_queue_fw_error(qdev);
423 status = -EIO;
424 break;
426 case AEN_AEN_LOST:
427 ql_aen_lost(qdev, mbcp);
428 break;
430 case AEN_DCBX_CHG:
431 /* Need to support AEN 8110 */
432 break;
433 default:
434 QPRINTK(qdev, DRV, ERR,
435 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
436 /* Clear the MPI firmware status. */
438 end:
439 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
440 /* Restore the original mailbox count to
441 * what the caller asked for. This can get
442 * changed when a mailbox command is waiting
443 * for a response and an AEN arrives and
444 * is handled.
445 * */
446 mbcp->out_count = orig_count;
447 return status;
450 /* Execute a single mailbox command.
451 * mbcp is a pointer to an array of u32. Each
452 * element in the array contains the value for it's
453 * respective mailbox register.
455 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
457 int status;
458 unsigned long count;
461 /* Begin polled mode for MPI */
462 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
464 /* Load the mailbox registers and wake up MPI RISC. */
465 status = ql_exec_mb_cmd(qdev, mbcp);
466 if (status)
467 goto end;
470 /* If we're generating a system error, then there's nothing
471 * to wait for.
473 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
474 goto end;
476 /* Wait for the command to complete. We loop
477 * here because some AEN might arrive while
478 * we're waiting for the mailbox command to
479 * complete. If more than 5 seconds expire we can
480 * assume something is wrong. */
481 count = jiffies + HZ * MAILBOX_TIMEOUT;
482 do {
483 /* Wait for the interrupt to come in. */
484 status = ql_wait_mbx_cmd_cmplt(qdev);
485 if (status)
486 continue;
488 /* Process the event. If it's an AEN, it
489 * will be handled in-line or a worker
490 * will be spawned. If it's our completion
491 * we will catch it below.
493 status = ql_mpi_handler(qdev, mbcp);
494 if (status)
495 goto end;
497 /* It's either the completion for our mailbox
498 * command complete or an AEN. If it's our
499 * completion then get out.
501 if (((mbcp->mbox_out[0] & 0x0000f000) ==
502 MB_CMD_STS_GOOD) ||
503 ((mbcp->mbox_out[0] & 0x0000f000) ==
504 MB_CMD_STS_INTRMDT))
505 goto done;
506 } while (time_before(jiffies, count));
508 QPRINTK(qdev, DRV, ERR,
509 "Timed out waiting for mailbox complete.\n");
510 status = -ETIMEDOUT;
511 goto end;
513 done:
515 /* Now we can clear the interrupt condition
516 * and look at our status.
518 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
520 if (((mbcp->mbox_out[0] & 0x0000f000) !=
521 MB_CMD_STS_GOOD) &&
522 ((mbcp->mbox_out[0] & 0x0000f000) !=
523 MB_CMD_STS_INTRMDT)) {
524 status = -EIO;
526 end:
527 /* End polled mode for MPI */
528 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
529 return status;
533 /* Get MPI firmware version. This will be used for
534 * driver banner and for ethtool info.
535 * Returns zero on success.
537 int ql_mb_about_fw(struct ql_adapter *qdev)
539 struct mbox_params mbc;
540 struct mbox_params *mbcp = &mbc;
541 int status = 0;
543 memset(mbcp, 0, sizeof(struct mbox_params));
545 mbcp->in_count = 1;
546 mbcp->out_count = 3;
548 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
550 status = ql_mailbox_command(qdev, mbcp);
551 if (status)
552 return status;
554 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
555 QPRINTK(qdev, DRV, ERR,
556 "Failed about firmware command\n");
557 status = -EIO;
560 /* Store the firmware version */
561 qdev->fw_rev_id = mbcp->mbox_out[1];
563 return status;
566 /* Get functional state for MPI firmware.
567 * Returns zero on success.
569 int ql_mb_get_fw_state(struct ql_adapter *qdev)
571 struct mbox_params mbc;
572 struct mbox_params *mbcp = &mbc;
573 int status = 0;
575 memset(mbcp, 0, sizeof(struct mbox_params));
577 mbcp->in_count = 1;
578 mbcp->out_count = 2;
580 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
582 status = ql_mailbox_command(qdev, mbcp);
583 if (status)
584 return status;
586 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
587 QPRINTK(qdev, DRV, ERR,
588 "Failed Get Firmware State.\n");
589 status = -EIO;
592 /* If bit zero is set in mbx 1 then the firmware is
593 * running, but not initialized. This should never
594 * happen.
596 if (mbcp->mbox_out[1] & 1) {
597 QPRINTK(qdev, DRV, ERR,
598 "Firmware waiting for initialization.\n");
599 status = -EIO;
602 return status;
605 /* Send and ACK mailbox command to the firmware to
606 * let it continue with the change.
608 int ql_mb_idc_ack(struct ql_adapter *qdev)
610 struct mbox_params mbc;
611 struct mbox_params *mbcp = &mbc;
612 int status = 0;
614 memset(mbcp, 0, sizeof(struct mbox_params));
616 mbcp->in_count = 5;
617 mbcp->out_count = 1;
619 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
620 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
621 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
622 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
623 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
625 status = ql_mailbox_command(qdev, mbcp);
626 if (status)
627 return status;
629 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
630 QPRINTK(qdev, DRV, ERR,
631 "Failed IDC ACK send.\n");
632 status = -EIO;
634 return status;
637 /* Get link settings and maximum frame size settings
638 * for the current port.
639 * Most likely will block.
641 int ql_mb_set_port_cfg(struct ql_adapter *qdev)
643 struct mbox_params mbc;
644 struct mbox_params *mbcp = &mbc;
645 int status = 0;
647 memset(mbcp, 0, sizeof(struct mbox_params));
649 mbcp->in_count = 3;
650 mbcp->out_count = 1;
652 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
653 mbcp->mbox_in[1] = qdev->link_config;
654 mbcp->mbox_in[2] = qdev->max_frame_size;
657 status = ql_mailbox_command(qdev, mbcp);
658 if (status)
659 return status;
661 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
662 QPRINTK(qdev, DRV, ERR,
663 "Port Config sent, wait for IDC.\n");
664 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
665 QPRINTK(qdev, DRV, ERR,
666 "Failed Set Port Configuration.\n");
667 status = -EIO;
669 return status;
672 /* Get link settings and maximum frame size settings
673 * for the current port.
674 * Most likely will block.
676 int ql_mb_get_port_cfg(struct ql_adapter *qdev)
678 struct mbox_params mbc;
679 struct mbox_params *mbcp = &mbc;
680 int status = 0;
682 memset(mbcp, 0, sizeof(struct mbox_params));
684 mbcp->in_count = 1;
685 mbcp->out_count = 3;
687 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
689 status = ql_mailbox_command(qdev, mbcp);
690 if (status)
691 return status;
693 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
694 QPRINTK(qdev, DRV, ERR,
695 "Failed Get Port Configuration.\n");
696 status = -EIO;
697 } else {
698 QPRINTK(qdev, DRV, DEBUG,
699 "Passed Get Port Configuration.\n");
700 qdev->link_config = mbcp->mbox_out[1];
701 qdev->max_frame_size = mbcp->mbox_out[2];
703 return status;
706 int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol)
708 struct mbox_params mbc;
709 struct mbox_params *mbcp = &mbc;
710 int status;
712 memset(mbcp, 0, sizeof(struct mbox_params));
714 mbcp->in_count = 2;
715 mbcp->out_count = 1;
717 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MODE;
718 mbcp->mbox_in[1] = wol;
721 status = ql_mailbox_command(qdev, mbcp);
722 if (status)
723 return status;
725 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
726 QPRINTK(qdev, DRV, ERR,
727 "Failed to set WOL mode.\n");
728 status = -EIO;
730 return status;
733 int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol)
735 struct mbox_params mbc;
736 struct mbox_params *mbcp = &mbc;
737 int status;
738 u8 *addr = qdev->ndev->dev_addr;
740 memset(mbcp, 0, sizeof(struct mbox_params));
742 mbcp->in_count = 8;
743 mbcp->out_count = 1;
745 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MAGIC;
746 if (enable_wol) {
747 mbcp->mbox_in[1] = (u32)addr[0];
748 mbcp->mbox_in[2] = (u32)addr[1];
749 mbcp->mbox_in[3] = (u32)addr[2];
750 mbcp->mbox_in[4] = (u32)addr[3];
751 mbcp->mbox_in[5] = (u32)addr[4];
752 mbcp->mbox_in[6] = (u32)addr[5];
753 mbcp->mbox_in[7] = 0;
754 } else {
755 mbcp->mbox_in[1] = 0;
756 mbcp->mbox_in[2] = 1;
757 mbcp->mbox_in[3] = 1;
758 mbcp->mbox_in[4] = 1;
759 mbcp->mbox_in[5] = 1;
760 mbcp->mbox_in[6] = 1;
761 mbcp->mbox_in[7] = 0;
764 status = ql_mailbox_command(qdev, mbcp);
765 if (status)
766 return status;
768 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
769 QPRINTK(qdev, DRV, ERR,
770 "Failed to set WOL mode.\n");
771 status = -EIO;
773 return status;
776 /* IDC - Inter Device Communication...
777 * Some firmware commands require consent of adjacent FCOE
778 * function. This function waits for the OK, or a
779 * counter-request for a little more time.i
780 * The firmware will complete the request if the other
781 * function doesn't respond.
783 static int ql_idc_wait(struct ql_adapter *qdev)
785 int status = -ETIMEDOUT;
786 long wait_time = 1 * HZ;
787 struct mbox_params *mbcp = &qdev->idc_mbc;
788 do {
789 /* Wait here for the command to complete
790 * via the IDC process.
792 wait_time =
793 wait_for_completion_timeout(&qdev->ide_completion,
794 wait_time);
795 if (!wait_time) {
796 QPRINTK(qdev, DRV, ERR,
797 "IDC Timeout.\n");
798 break;
800 /* Now examine the response from the IDC process.
801 * We might have a good completion or a request for
802 * more wait time.
804 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
805 QPRINTK(qdev, DRV, ERR,
806 "IDC Time Extension from function.\n");
807 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
808 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
809 QPRINTK(qdev, DRV, ERR,
810 "IDC Success.\n");
811 status = 0;
812 break;
813 } else {
814 QPRINTK(qdev, DRV, ERR,
815 "IDC: Invalid State 0x%.04x.\n",
816 mbcp->mbox_out[0]);
817 status = -EIO;
818 break;
820 } while (wait_time);
822 return status;
825 int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config)
827 struct mbox_params mbc;
828 struct mbox_params *mbcp = &mbc;
829 int status;
831 memset(mbcp, 0, sizeof(struct mbox_params));
833 mbcp->in_count = 2;
834 mbcp->out_count = 1;
836 mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG;
837 mbcp->mbox_in[1] = led_config;
840 status = ql_mailbox_command(qdev, mbcp);
841 if (status)
842 return status;
844 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
845 QPRINTK(qdev, DRV, ERR,
846 "Failed to set LED Configuration.\n");
847 status = -EIO;
850 return status;
853 int ql_mb_get_led_cfg(struct ql_adapter *qdev)
855 struct mbox_params mbc;
856 struct mbox_params *mbcp = &mbc;
857 int status;
859 memset(mbcp, 0, sizeof(struct mbox_params));
861 mbcp->in_count = 1;
862 mbcp->out_count = 2;
864 mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG;
866 status = ql_mailbox_command(qdev, mbcp);
867 if (status)
868 return status;
870 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
871 QPRINTK(qdev, DRV, ERR,
872 "Failed to get LED Configuration.\n");
873 status = -EIO;
874 } else
875 qdev->led_config = mbcp->mbox_out[1];
877 return status;
880 int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
882 struct mbox_params mbc;
883 struct mbox_params *mbcp = &mbc;
884 int status;
886 memset(mbcp, 0, sizeof(struct mbox_params));
888 mbcp->in_count = 1;
889 mbcp->out_count = 2;
891 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
892 mbcp->mbox_in[1] = control;
894 status = ql_mailbox_command(qdev, mbcp);
895 if (status)
896 return status;
898 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
899 return status;
901 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
902 QPRINTK(qdev, DRV, ERR,
903 "Command not supported by firmware.\n");
904 status = -EINVAL;
905 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
906 /* This indicates that the firmware is
907 * already in the state we are trying to
908 * change it to.
910 QPRINTK(qdev, DRV, ERR,
911 "Command parameters make no change.\n");
913 return status;
916 /* Returns a negative error code or the mailbox command status. */
917 static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
919 struct mbox_params mbc;
920 struct mbox_params *mbcp = &mbc;
921 int status;
923 memset(mbcp, 0, sizeof(struct mbox_params));
924 *control = 0;
926 mbcp->in_count = 1;
927 mbcp->out_count = 1;
929 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
931 status = ql_mailbox_command(qdev, mbcp);
932 if (status)
933 return status;
935 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
936 *control = mbcp->mbox_in[1];
937 return status;
940 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
941 QPRINTK(qdev, DRV, ERR,
942 "Command not supported by firmware.\n");
943 status = -EINVAL;
944 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
945 QPRINTK(qdev, DRV, ERR,
946 "Failed to get MPI traffic control.\n");
947 status = -EIO;
949 return status;
952 int ql_wait_fifo_empty(struct ql_adapter *qdev)
954 int count = 5;
955 u32 mgmnt_fifo_empty;
956 u32 nic_fifo_empty;
958 do {
959 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
960 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
961 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
962 if (nic_fifo_empty && mgmnt_fifo_empty)
963 return 0;
964 msleep(100);
965 } while (count-- > 0);
966 return -ETIMEDOUT;
969 /* API called in work thread context to set new TX/RX
970 * maximum frame size values to match MTU.
972 static int ql_set_port_cfg(struct ql_adapter *qdev)
974 int status;
975 rtnl_lock();
976 status = ql_mb_set_port_cfg(qdev);
977 rtnl_unlock();
978 if (status)
979 return status;
980 status = ql_idc_wait(qdev);
981 return status;
984 /* The following routines are worker threads that process
985 * events that may sleep waiting for completion.
988 /* This thread gets the maximum TX and RX frame size values
989 * from the firmware and, if necessary, changes them to match
990 * the MTU setting.
992 void ql_mpi_port_cfg_work(struct work_struct *work)
994 struct ql_adapter *qdev =
995 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
996 int status;
998 rtnl_lock();
999 status = ql_mb_get_port_cfg(qdev);
1000 rtnl_unlock();
1001 if (status) {
1002 QPRINTK(qdev, DRV, ERR,
1003 "Bug: Failed to get port config data.\n");
1004 goto err;
1007 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
1008 qdev->max_frame_size ==
1009 CFG_DEFAULT_MAX_FRAME_SIZE)
1010 goto end;
1012 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
1013 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
1014 status = ql_set_port_cfg(qdev);
1015 if (status) {
1016 QPRINTK(qdev, DRV, ERR,
1017 "Bug: Failed to set port config data.\n");
1018 goto err;
1020 end:
1021 clear_bit(QL_PORT_CFG, &qdev->flags);
1022 return;
1023 err:
1024 ql_queue_fw_error(qdev);
1025 goto end;
1028 /* Process an inter-device request. This is issues by
1029 * the firmware in response to another function requesting
1030 * a change to the port. We set a flag to indicate a change
1031 * has been made and then send a mailbox command ACKing
1032 * the change request.
1034 void ql_mpi_idc_work(struct work_struct *work)
1036 struct ql_adapter *qdev =
1037 container_of(work, struct ql_adapter, mpi_idc_work.work);
1038 int status;
1039 struct mbox_params *mbcp = &qdev->idc_mbc;
1040 u32 aen;
1041 int timeout;
1043 rtnl_lock();
1044 aen = mbcp->mbox_out[1] >> 16;
1045 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
1047 switch (aen) {
1048 default:
1049 QPRINTK(qdev, DRV, ERR,
1050 "Bug: Unhandled IDC action.\n");
1051 break;
1052 case MB_CMD_PORT_RESET:
1053 case MB_CMD_STOP_FW:
1054 ql_link_off(qdev);
1055 case MB_CMD_SET_PORT_CFG:
1056 /* Signal the resulting link up AEN
1057 * that the frame routing and mac addr
1058 * needs to be set.
1059 * */
1060 set_bit(QL_CAM_RT_SET, &qdev->flags);
1061 /* Do ACK if required */
1062 if (timeout) {
1063 status = ql_mb_idc_ack(qdev);
1064 if (status)
1065 QPRINTK(qdev, DRV, ERR,
1066 "Bug: No pending IDC!\n");
1067 } else {
1068 QPRINTK(qdev, DRV, DEBUG,
1069 "IDC ACK not required\n");
1070 status = 0; /* success */
1072 break;
1074 /* These sub-commands issued by another (FCoE)
1075 * function are requesting to do an operation
1076 * on the shared resource (MPI environment).
1077 * We currently don't issue these so we just
1078 * ACK the request.
1080 case MB_CMD_IOP_RESTART_MPI:
1081 case MB_CMD_IOP_PREP_LINK_DOWN:
1082 /* Drop the link, reload the routing
1083 * table when link comes up.
1085 ql_link_off(qdev);
1086 set_bit(QL_CAM_RT_SET, &qdev->flags);
1087 /* Fall through. */
1088 case MB_CMD_IOP_DVR_START:
1089 case MB_CMD_IOP_FLASH_ACC:
1090 case MB_CMD_IOP_CORE_DUMP_MPI:
1091 case MB_CMD_IOP_PREP_UPDATE_MPI:
1092 case MB_CMD_IOP_COMP_UPDATE_MPI:
1093 case MB_CMD_IOP_NONE: /* an IDC without params */
1094 /* Do ACK if required */
1095 if (timeout) {
1096 status = ql_mb_idc_ack(qdev);
1097 if (status)
1098 QPRINTK(qdev, DRV, ERR,
1099 "Bug: No pending IDC!\n");
1100 } else {
1101 QPRINTK(qdev, DRV, DEBUG,
1102 "IDC ACK not required\n");
1103 status = 0; /* success */
1105 break;
1107 rtnl_unlock();
1110 void ql_mpi_work(struct work_struct *work)
1112 struct ql_adapter *qdev =
1113 container_of(work, struct ql_adapter, mpi_work.work);
1114 struct mbox_params mbc;
1115 struct mbox_params *mbcp = &mbc;
1116 int err = 0;
1118 rtnl_lock();
1119 /* Begin polled mode for MPI */
1120 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
1122 while (ql_read32(qdev, STS) & STS_PI) {
1123 memset(mbcp, 0, sizeof(struct mbox_params));
1124 mbcp->out_count = 1;
1125 /* Don't continue if an async event
1126 * did not complete properly.
1128 err = ql_mpi_handler(qdev, mbcp);
1129 if (err)
1130 break;
1133 /* End polled mode for MPI */
1134 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
1135 rtnl_unlock();
1136 ql_enable_completion_interrupt(qdev, 0);
1139 void ql_mpi_reset_work(struct work_struct *work)
1141 struct ql_adapter *qdev =
1142 container_of(work, struct ql_adapter, mpi_reset_work.work);
1143 cancel_delayed_work_sync(&qdev->mpi_work);
1144 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
1145 cancel_delayed_work_sync(&qdev->mpi_idc_work);
1146 ql_soft_reset_mpi_risc(qdev);