3 int ql_unpause_mpi_risc(struct ql_adapter *qdev)
7 /* Un-pause the RISC */
8 tmp = ql_read32(qdev, CSR);
12 ql_write32(qdev, CSR, CSR_CMD_CLR_PAUSE);
16 int ql_pause_mpi_risc(struct ql_adapter *qdev)
19 int count = UDELAY_COUNT;
22 ql_write32(qdev, CSR, CSR_CMD_SET_PAUSE);
24 tmp = ql_read32(qdev, CSR);
30 return (count == 0) ? -ETIMEDOUT : 0;
33 int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
36 /* wait for reg to come ready */
37 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
40 /* set up for reg read */
41 ql_write32(qdev, PROC_ADDR, reg | PROC_ADDR_R);
42 /* wait for reg to come ready */
43 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
47 *data = ql_read32(qdev, PROC_DATA);
52 int ql_write_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 data)
55 /* wait for reg to come ready */
56 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
59 /* write the data to the data reg */
60 ql_write32(qdev, PROC_DATA, data);
61 /* trigger the write */
62 ql_write32(qdev, PROC_ADDR, reg);
63 /* wait for reg to come ready */
64 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
71 int ql_soft_reset_mpi_risc(struct ql_adapter *qdev)
74 status = ql_write_mpi_reg(qdev, 0x00001010, 1);
78 /* Determine if we are in charge of the firwmare. If
79 * we are the lower of the 2 NIC pcie functions, or if
80 * we are the higher function and the lower function
83 int ql_own_firmware(struct ql_adapter *qdev)
87 /* If we are the lower of the 2 NIC functions
88 * on the chip the we are responsible for
89 * core dump and firmware reset after an error.
91 if (qdev->func < qdev->alt_func)
94 /* If we are the higher of the 2 NIC functions
95 * on the chip and the lower function is not
96 * enabled, then we are responsible for
97 * core dump and firmware reset after an error.
99 temp = ql_read32(qdev, STS);
100 if (!(temp & (1 << (8 + qdev->alt_func))))
107 static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
111 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
114 for (i = 0; i < mbcp->out_count; i++) {
116 ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
119 QPRINTK(qdev, DRV, ERR, "Failed mailbox read.\n");
123 ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */
127 /* Wait for a single mailbox command to complete.
128 * Returns zero on success.
130 static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev)
136 value = ql_read32(qdev, STS);
139 mdelay(UDELAY_DELAY); /* 100ms */
144 /* Execute a single mailbox command.
145 * Caller must hold PROC_ADDR semaphore.
147 static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp)
152 * Make sure there's nothing pending.
153 * This shouldn't happen.
155 if (ql_read32(qdev, CSR) & CSR_HRI)
158 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
163 * Fill the outbound mailboxes.
165 for (i = 0; i < mbcp->in_count; i++) {
166 status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i,
172 * Wake up the MPI firmware.
174 ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT);
176 ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
180 /* We are being asked by firmware to accept
181 * a change to the port. This is only
182 * a change to max frame sizes (Tx/Rx), pause
183 * parameters, or loopback mode. We wake up a worker
184 * to handler processing this since a mailbox command
185 * will need to be sent to ACK the request.
187 static int ql_idc_req_aen(struct ql_adapter *qdev)
190 struct mbox_params *mbcp = &qdev->idc_mbc;
192 QPRINTK(qdev, DRV, ERR, "Enter!\n");
193 /* Get the status data and start up a thread to
194 * handle the request.
196 mbcp = &qdev->idc_mbc;
198 status = ql_get_mb_sts(qdev, mbcp);
200 QPRINTK(qdev, DRV, ERR,
201 "Could not read MPI, resetting ASIC!\n");
202 ql_queue_asic_error(qdev);
204 /* Begin polled mode early so
205 * we don't get another interrupt
206 * when we leave mpi_worker.
208 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
209 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
214 /* Process an inter-device event completion.
215 * If good, signal the caller's completion.
217 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
220 struct mbox_params *mbcp = &qdev->idc_mbc;
222 status = ql_get_mb_sts(qdev, mbcp);
224 QPRINTK(qdev, DRV, ERR,
225 "Could not read MPI, resetting RISC!\n");
226 ql_queue_fw_error(qdev);
228 /* Wake up the sleeping mpi_idc_work thread that is
229 * waiting for this event.
231 complete(&qdev->ide_completion);
236 static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
241 status = ql_get_mb_sts(qdev, mbcp);
243 QPRINTK(qdev, DRV, ERR,
244 "%s: Could not get mailbox status.\n", __func__);
248 qdev->link_status = mbcp->mbox_out[1];
249 QPRINTK(qdev, DRV, ERR, "Link Up.\n");
251 /* If we're coming back from an IDC event
252 * then set up the CAM and frame routing.
254 if (test_bit(QL_CAM_RT_SET, &qdev->flags)) {
255 status = ql_cam_route_initialize(qdev);
257 QPRINTK(qdev, IFUP, ERR,
258 "Failed to init CAM/Routing tables.\n");
261 clear_bit(QL_CAM_RT_SET, &qdev->flags);
264 /* Queue up a worker to check the frame
265 * size information, and fix it if it's not
268 if (!test_bit(QL_PORT_CFG, &qdev->flags)) {
269 QPRINTK(qdev, DRV, ERR, "Queue Port Config Worker!\n");
270 set_bit(QL_PORT_CFG, &qdev->flags);
271 /* Begin polled mode early so
272 * we don't get another interrupt
273 * when we leave mpi_worker dpc.
275 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
276 queue_delayed_work(qdev->workqueue,
277 &qdev->mpi_port_cfg_work, 0);
283 static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
289 status = ql_get_mb_sts(qdev, mbcp);
291 QPRINTK(qdev, DRV, ERR, "Link down AEN broken!\n");
296 static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
302 status = ql_get_mb_sts(qdev, mbcp);
304 QPRINTK(qdev, DRV, ERR, "SFP in AEN broken!\n");
306 QPRINTK(qdev, DRV, ERR, "SFP insertion detected.\n");
311 static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
317 status = ql_get_mb_sts(qdev, mbcp);
319 QPRINTK(qdev, DRV, ERR, "SFP out AEN broken!\n");
321 QPRINTK(qdev, DRV, ERR, "SFP removal detected.\n");
326 static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp)
332 status = ql_get_mb_sts(qdev, mbcp);
334 QPRINTK(qdev, DRV, ERR, "Lost AEN broken!\n");
337 QPRINTK(qdev, DRV, ERR, "Lost AEN detected.\n");
338 for (i = 0; i < mbcp->out_count; i++)
339 QPRINTK(qdev, DRV, ERR, "mbox_out[%d] = 0x%.08x.\n",
340 i, mbcp->mbox_out[i]);
347 static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
353 status = ql_get_mb_sts(qdev, mbcp);
355 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
357 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
359 qdev->fw_rev_id = mbcp->mbox_out[1];
360 status = ql_cam_route_initialize(qdev);
362 QPRINTK(qdev, IFUP, ERR,
363 "Failed to init CAM/Routing tables.\n");
367 /* Process an async event and clear it unless it's an
369 * This can get called iteratively from the mpi_work thread
370 * when events arrive via an interrupt.
371 * It also gets called when a mailbox command is polling for
372 * it's completion. */
373 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
376 int orig_count = mbcp->out_count;
378 /* Just get mailbox zero for now. */
380 status = ql_get_mb_sts(qdev, mbcp);
382 QPRINTK(qdev, DRV, ERR,
383 "Could not read MPI, resetting ASIC!\n");
384 ql_queue_asic_error(qdev);
388 switch (mbcp->mbox_out[0]) {
390 /* This case is only active when we arrive here
391 * as a result of issuing a mailbox command to
394 case MB_CMD_STS_INTRMDT:
395 case MB_CMD_STS_GOOD:
396 case MB_CMD_STS_INVLD_CMD:
397 case MB_CMD_STS_XFC_ERR:
398 case MB_CMD_STS_CSUM_ERR:
400 case MB_CMD_STS_PARAM_ERR:
401 /* We can only get mailbox status if we're polling from an
402 * unfinished command. Get the rest of the status data and
403 * return back to the caller.
404 * We only end up here when we're polling for a mailbox
405 * command completion.
407 mbcp->out_count = orig_count;
408 status = ql_get_mb_sts(qdev, mbcp);
411 /* We are being asked by firmware to accept
412 * a change to the port. This is only
413 * a change to max frame sizes (Tx/Rx), pause
414 * parameters, or loopback mode.
417 status = ql_idc_req_aen(qdev);
420 /* Process and inbound IDC event.
421 * This will happen when we're trying to
422 * change tx/rx max frame size, change pause
423 * parameters or loopback mode.
427 status = ql_idc_cmplt_aen(qdev);
431 ql_link_up(qdev, mbcp);
435 ql_link_down(qdev, mbcp);
438 case AEN_FW_INIT_DONE:
439 /* If we're in process on executing the firmware,
440 * then convert the status to normal mailbox status.
442 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
443 mbcp->out_count = orig_count;
444 status = ql_get_mb_sts(qdev, mbcp);
445 mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
448 ql_init_fw_done(qdev, mbcp);
452 ql_sfp_in(qdev, mbcp);
455 case AEN_AEN_SFP_OUT:
456 ql_sfp_out(qdev, mbcp);
459 /* This event can arrive at boot time or after an
460 * MPI reset if the firmware failed to initialize.
462 case AEN_FW_INIT_FAIL:
463 /* If we're in process on executing the firmware,
464 * then convert the status to normal mailbox status.
466 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
467 mbcp->out_count = orig_count;
468 status = ql_get_mb_sts(qdev, mbcp);
469 mbcp->mbox_out[0] = MB_CMD_STS_ERR;
472 QPRINTK(qdev, DRV, ERR,
473 "Firmware initialization failed.\n");
475 ql_queue_fw_error(qdev);
479 QPRINTK(qdev, DRV, ERR,
481 ql_queue_fw_error(qdev);
486 ql_aen_lost(qdev, mbcp);
490 /* Need to support AEN 8110 */
493 QPRINTK(qdev, DRV, ERR,
494 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
495 /* Clear the MPI firmware status. */
498 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
499 /* Restore the original mailbox count to
500 * what the caller asked for. This can get
501 * changed when a mailbox command is waiting
502 * for a response and an AEN arrives and
505 mbcp->out_count = orig_count;
509 /* Execute a single mailbox command.
510 * mbcp is a pointer to an array of u32. Each
511 * element in the array contains the value for it's
512 * respective mailbox register.
514 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
520 /* Begin polled mode for MPI */
521 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
523 /* Load the mailbox registers and wake up MPI RISC. */
524 status = ql_exec_mb_cmd(qdev, mbcp);
529 /* If we're generating a system error, then there's nothing
532 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
535 /* Wait for the command to complete. We loop
536 * here because some AEN might arrive while
537 * we're waiting for the mailbox command to
538 * complete. If more than 5 seconds expire we can
539 * assume something is wrong. */
540 count = jiffies + HZ * MAILBOX_TIMEOUT;
542 /* Wait for the interrupt to come in. */
543 status = ql_wait_mbx_cmd_cmplt(qdev);
547 /* Process the event. If it's an AEN, it
548 * will be handled in-line or a worker
549 * will be spawned. If it's our completion
550 * we will catch it below.
552 status = ql_mpi_handler(qdev, mbcp);
556 /* It's either the completion for our mailbox
557 * command complete or an AEN. If it's our
558 * completion then get out.
560 if (((mbcp->mbox_out[0] & 0x0000f000) ==
562 ((mbcp->mbox_out[0] & 0x0000f000) ==
565 } while (time_before(jiffies, count));
567 QPRINTK(qdev, DRV, ERR,
568 "Timed out waiting for mailbox complete.\n");
574 /* Now we can clear the interrupt condition
575 * and look at our status.
577 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
579 if (((mbcp->mbox_out[0] & 0x0000f000) !=
581 ((mbcp->mbox_out[0] & 0x0000f000) !=
582 MB_CMD_STS_INTRMDT)) {
586 /* End polled mode for MPI */
587 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
592 /* Get MPI firmware version. This will be used for
593 * driver banner and for ethtool info.
594 * Returns zero on success.
596 int ql_mb_about_fw(struct ql_adapter *qdev)
598 struct mbox_params mbc;
599 struct mbox_params *mbcp = &mbc;
602 memset(mbcp, 0, sizeof(struct mbox_params));
607 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
609 status = ql_mailbox_command(qdev, mbcp);
613 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
614 QPRINTK(qdev, DRV, ERR,
615 "Failed about firmware command\n");
619 /* Store the firmware version */
620 qdev->fw_rev_id = mbcp->mbox_out[1];
625 /* Get functional state for MPI firmware.
626 * Returns zero on success.
628 int ql_mb_get_fw_state(struct ql_adapter *qdev)
630 struct mbox_params mbc;
631 struct mbox_params *mbcp = &mbc;
634 memset(mbcp, 0, sizeof(struct mbox_params));
639 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
641 status = ql_mailbox_command(qdev, mbcp);
645 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
646 QPRINTK(qdev, DRV, ERR,
647 "Failed Get Firmware State.\n");
651 /* If bit zero is set in mbx 1 then the firmware is
652 * running, but not initialized. This should never
655 if (mbcp->mbox_out[1] & 1) {
656 QPRINTK(qdev, DRV, ERR,
657 "Firmware waiting for initialization.\n");
664 /* Send and ACK mailbox command to the firmware to
665 * let it continue with the change.
667 int ql_mb_idc_ack(struct ql_adapter *qdev)
669 struct mbox_params mbc;
670 struct mbox_params *mbcp = &mbc;
673 memset(mbcp, 0, sizeof(struct mbox_params));
678 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
679 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
680 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
681 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
682 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
684 status = ql_mailbox_command(qdev, mbcp);
688 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
689 QPRINTK(qdev, DRV, ERR,
690 "Failed IDC ACK send.\n");
696 /* Get link settings and maximum frame size settings
697 * for the current port.
698 * Most likely will block.
700 int ql_mb_set_port_cfg(struct ql_adapter *qdev)
702 struct mbox_params mbc;
703 struct mbox_params *mbcp = &mbc;
706 memset(mbcp, 0, sizeof(struct mbox_params));
711 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
712 mbcp->mbox_in[1] = qdev->link_config;
713 mbcp->mbox_in[2] = qdev->max_frame_size;
716 status = ql_mailbox_command(qdev, mbcp);
720 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
721 QPRINTK(qdev, DRV, ERR,
722 "Port Config sent, wait for IDC.\n");
723 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
724 QPRINTK(qdev, DRV, ERR,
725 "Failed Set Port Configuration.\n");
731 /* Get link settings and maximum frame size settings
732 * for the current port.
733 * Most likely will block.
735 int ql_mb_get_port_cfg(struct ql_adapter *qdev)
737 struct mbox_params mbc;
738 struct mbox_params *mbcp = &mbc;
741 memset(mbcp, 0, sizeof(struct mbox_params));
746 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
748 status = ql_mailbox_command(qdev, mbcp);
752 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
753 QPRINTK(qdev, DRV, ERR,
754 "Failed Get Port Configuration.\n");
757 QPRINTK(qdev, DRV, DEBUG,
758 "Passed Get Port Configuration.\n");
759 qdev->link_config = mbcp->mbox_out[1];
760 qdev->max_frame_size = mbcp->mbox_out[2];
765 int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol)
767 struct mbox_params mbc;
768 struct mbox_params *mbcp = &mbc;
771 memset(mbcp, 0, sizeof(struct mbox_params));
776 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MODE;
777 mbcp->mbox_in[1] = wol;
780 status = ql_mailbox_command(qdev, mbcp);
784 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
785 QPRINTK(qdev, DRV, ERR,
786 "Failed to set WOL mode.\n");
792 int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol)
794 struct mbox_params mbc;
795 struct mbox_params *mbcp = &mbc;
797 u8 *addr = qdev->ndev->dev_addr;
799 memset(mbcp, 0, sizeof(struct mbox_params));
804 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MAGIC;
806 mbcp->mbox_in[1] = (u32)addr[0];
807 mbcp->mbox_in[2] = (u32)addr[1];
808 mbcp->mbox_in[3] = (u32)addr[2];
809 mbcp->mbox_in[4] = (u32)addr[3];
810 mbcp->mbox_in[5] = (u32)addr[4];
811 mbcp->mbox_in[6] = (u32)addr[5];
812 mbcp->mbox_in[7] = 0;
814 mbcp->mbox_in[1] = 0;
815 mbcp->mbox_in[2] = 1;
816 mbcp->mbox_in[3] = 1;
817 mbcp->mbox_in[4] = 1;
818 mbcp->mbox_in[5] = 1;
819 mbcp->mbox_in[6] = 1;
820 mbcp->mbox_in[7] = 0;
823 status = ql_mailbox_command(qdev, mbcp);
827 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
828 QPRINTK(qdev, DRV, ERR,
829 "Failed to set WOL mode.\n");
835 /* IDC - Inter Device Communication...
836 * Some firmware commands require consent of adjacent FCOE
837 * function. This function waits for the OK, or a
838 * counter-request for a little more time.i
839 * The firmware will complete the request if the other
840 * function doesn't respond.
842 static int ql_idc_wait(struct ql_adapter *qdev)
844 int status = -ETIMEDOUT;
845 long wait_time = 1 * HZ;
846 struct mbox_params *mbcp = &qdev->idc_mbc;
848 /* Wait here for the command to complete
849 * via the IDC process.
852 wait_for_completion_timeout(&qdev->ide_completion,
855 QPRINTK(qdev, DRV, ERR,
859 /* Now examine the response from the IDC process.
860 * We might have a good completion or a request for
863 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
864 QPRINTK(qdev, DRV, ERR,
865 "IDC Time Extension from function.\n");
866 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
867 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
868 QPRINTK(qdev, DRV, ERR,
873 QPRINTK(qdev, DRV, ERR,
874 "IDC: Invalid State 0x%.04x.\n",
884 int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config)
886 struct mbox_params mbc;
887 struct mbox_params *mbcp = &mbc;
890 memset(mbcp, 0, sizeof(struct mbox_params));
895 mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG;
896 mbcp->mbox_in[1] = led_config;
899 status = ql_mailbox_command(qdev, mbcp);
903 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
904 QPRINTK(qdev, DRV, ERR,
905 "Failed to set LED Configuration.\n");
912 int ql_mb_get_led_cfg(struct ql_adapter *qdev)
914 struct mbox_params mbc;
915 struct mbox_params *mbcp = &mbc;
918 memset(mbcp, 0, sizeof(struct mbox_params));
923 mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG;
925 status = ql_mailbox_command(qdev, mbcp);
929 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
930 QPRINTK(qdev, DRV, ERR,
931 "Failed to get LED Configuration.\n");
934 qdev->led_config = mbcp->mbox_out[1];
939 int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
941 struct mbox_params mbc;
942 struct mbox_params *mbcp = &mbc;
945 memset(mbcp, 0, sizeof(struct mbox_params));
950 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
951 mbcp->mbox_in[1] = control;
953 status = ql_mailbox_command(qdev, mbcp);
957 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
960 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
961 QPRINTK(qdev, DRV, ERR,
962 "Command not supported by firmware.\n");
964 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
965 /* This indicates that the firmware is
966 * already in the state we are trying to
969 QPRINTK(qdev, DRV, ERR,
970 "Command parameters make no change.\n");
975 /* Returns a negative error code or the mailbox command status. */
976 static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
978 struct mbox_params mbc;
979 struct mbox_params *mbcp = &mbc;
982 memset(mbcp, 0, sizeof(struct mbox_params));
988 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
990 status = ql_mailbox_command(qdev, mbcp);
994 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
995 *control = mbcp->mbox_in[1];
999 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1000 QPRINTK(qdev, DRV, ERR,
1001 "Command not supported by firmware.\n");
1003 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1004 QPRINTK(qdev, DRV, ERR,
1005 "Failed to get MPI traffic control.\n");
1011 int ql_wait_fifo_empty(struct ql_adapter *qdev)
1014 u32 mgmnt_fifo_empty;
1018 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
1019 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
1020 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
1021 if (nic_fifo_empty && mgmnt_fifo_empty)
1024 } while (count-- > 0);
1028 /* API called in work thread context to set new TX/RX
1029 * maximum frame size values to match MTU.
1031 static int ql_set_port_cfg(struct ql_adapter *qdev)
1035 status = ql_mb_set_port_cfg(qdev);
1039 status = ql_idc_wait(qdev);
1043 /* The following routines are worker threads that process
1044 * events that may sleep waiting for completion.
1047 /* This thread gets the maximum TX and RX frame size values
1048 * from the firmware and, if necessary, changes them to match
1051 void ql_mpi_port_cfg_work(struct work_struct *work)
1053 struct ql_adapter *qdev =
1054 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
1058 status = ql_mb_get_port_cfg(qdev);
1061 QPRINTK(qdev, DRV, ERR,
1062 "Bug: Failed to get port config data.\n");
1066 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
1067 qdev->max_frame_size ==
1068 CFG_DEFAULT_MAX_FRAME_SIZE)
1071 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
1072 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
1073 status = ql_set_port_cfg(qdev);
1075 QPRINTK(qdev, DRV, ERR,
1076 "Bug: Failed to set port config data.\n");
1080 clear_bit(QL_PORT_CFG, &qdev->flags);
1083 ql_queue_fw_error(qdev);
1087 /* Process an inter-device request. This is issues by
1088 * the firmware in response to another function requesting
1089 * a change to the port. We set a flag to indicate a change
1090 * has been made and then send a mailbox command ACKing
1091 * the change request.
1093 void ql_mpi_idc_work(struct work_struct *work)
1095 struct ql_adapter *qdev =
1096 container_of(work, struct ql_adapter, mpi_idc_work.work);
1098 struct mbox_params *mbcp = &qdev->idc_mbc;
1103 aen = mbcp->mbox_out[1] >> 16;
1104 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
1108 QPRINTK(qdev, DRV, ERR,
1109 "Bug: Unhandled IDC action.\n");
1111 case MB_CMD_PORT_RESET:
1112 case MB_CMD_STOP_FW:
1114 case MB_CMD_SET_PORT_CFG:
1115 /* Signal the resulting link up AEN
1116 * that the frame routing and mac addr
1119 set_bit(QL_CAM_RT_SET, &qdev->flags);
1120 /* Do ACK if required */
1122 status = ql_mb_idc_ack(qdev);
1124 QPRINTK(qdev, DRV, ERR,
1125 "Bug: No pending IDC!\n");
1127 QPRINTK(qdev, DRV, DEBUG,
1128 "IDC ACK not required\n");
1129 status = 0; /* success */
1133 /* These sub-commands issued by another (FCoE)
1134 * function are requesting to do an operation
1135 * on the shared resource (MPI environment).
1136 * We currently don't issue these so we just
1139 case MB_CMD_IOP_RESTART_MPI:
1140 case MB_CMD_IOP_PREP_LINK_DOWN:
1141 /* Drop the link, reload the routing
1142 * table when link comes up.
1145 set_bit(QL_CAM_RT_SET, &qdev->flags);
1147 case MB_CMD_IOP_DVR_START:
1148 case MB_CMD_IOP_FLASH_ACC:
1149 case MB_CMD_IOP_CORE_DUMP_MPI:
1150 case MB_CMD_IOP_PREP_UPDATE_MPI:
1151 case MB_CMD_IOP_COMP_UPDATE_MPI:
1152 case MB_CMD_IOP_NONE: /* an IDC without params */
1153 /* Do ACK if required */
1155 status = ql_mb_idc_ack(qdev);
1157 QPRINTK(qdev, DRV, ERR,
1158 "Bug: No pending IDC!\n");
1160 QPRINTK(qdev, DRV, DEBUG,
1161 "IDC ACK not required\n");
1162 status = 0; /* success */
1169 void ql_mpi_work(struct work_struct *work)
1171 struct ql_adapter *qdev =
1172 container_of(work, struct ql_adapter, mpi_work.work);
1173 struct mbox_params mbc;
1174 struct mbox_params *mbcp = &mbc;
1178 /* Begin polled mode for MPI */
1179 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
1181 while (ql_read32(qdev, STS) & STS_PI) {
1182 memset(mbcp, 0, sizeof(struct mbox_params));
1183 mbcp->out_count = 1;
1184 /* Don't continue if an async event
1185 * did not complete properly.
1187 err = ql_mpi_handler(qdev, mbcp);
1192 /* End polled mode for MPI */
1193 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
1195 ql_enable_completion_interrupt(qdev, 0);
1198 void ql_mpi_reset_work(struct work_struct *work)
1200 struct ql_adapter *qdev =
1201 container_of(work, struct ql_adapter, mpi_reset_work.work);
1202 cancel_delayed_work_sync(&qdev->mpi_work);
1203 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
1204 cancel_delayed_work_sync(&qdev->mpi_idc_work);
1205 /* If we're not the dominant NIC function,
1206 * then there is nothing to do.
1208 if (!ql_own_firmware(qdev)) {
1209 QPRINTK(qdev, DRV, ERR, "Don't own firmware!\n");
1213 if (!ql_core_dump(qdev, qdev->mpi_coredump)) {
1214 QPRINTK(qdev, DRV, ERR, "Core is dumped!\n");
1215 qdev->core_is_dumped = 1;
1216 queue_delayed_work(qdev->workqueue,
1217 &qdev->mpi_core_to_log, 5 * HZ);
1219 ql_soft_reset_mpi_risc(qdev);