1 // SPDX-License-Identifier: GPL-2.0
4 int ql_unpause_mpi_risc(struct ql_adapter *qdev)
8 /* Un-pause the RISC */
9 tmp = ql_read32(qdev, CSR);
13 ql_write32(qdev, CSR, CSR_CMD_CLR_PAUSE);
17 int ql_pause_mpi_risc(struct ql_adapter *qdev)
20 int count = UDELAY_COUNT;
23 ql_write32(qdev, CSR, CSR_CMD_SET_PAUSE);
25 tmp = ql_read32(qdev, CSR);
31 return (count == 0) ? -ETIMEDOUT : 0;
34 int ql_hard_reset_mpi_risc(struct ql_adapter *qdev)
37 int count = UDELAY_COUNT;
40 ql_write32(qdev, CSR, CSR_CMD_SET_RST);
42 tmp = ql_read32(qdev, CSR);
44 ql_write32(qdev, CSR, CSR_CMD_CLR_RST);
50 return (count == 0) ? -ETIMEDOUT : 0;
53 int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
56 /* wait for reg to come ready */
57 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
60 /* set up for reg read */
61 ql_write32(qdev, PROC_ADDR, reg | PROC_ADDR_R);
62 /* wait for reg to come ready */
63 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
67 *data = ql_read32(qdev, PROC_DATA);
72 int ql_write_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 data)
75 /* wait for reg to come ready */
76 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
79 /* write the data to the data reg */
80 ql_write32(qdev, PROC_DATA, data);
81 /* trigger the write */
82 ql_write32(qdev, PROC_ADDR, reg);
83 /* wait for reg to come ready */
84 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
91 int ql_soft_reset_mpi_risc(struct ql_adapter *qdev)
93 return ql_write_mpi_reg(qdev, 0x00001010, 1);
96 /* Determine if we are in charge of the firwmare. If
97 * we are the lower of the 2 NIC pcie functions, or if
98 * we are the higher function and the lower function
101 int ql_own_firmware(struct ql_adapter *qdev)
105 /* If we are the lower of the 2 NIC functions
106 * on the chip the we are responsible for
107 * core dump and firmware reset after an error.
109 if (qdev->func < qdev->alt_func)
112 /* If we are the higher of the 2 NIC functions
113 * on the chip and the lower function is not
114 * enabled, then we are responsible for
115 * core dump and firmware reset after an error.
117 temp = ql_read32(qdev, STS);
118 if (!(temp & (1 << (8 + qdev->alt_func))))
125 static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
129 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
132 for (i = 0; i < mbcp->out_count; i++) {
134 ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
137 netif_err(qdev, drv, qdev->ndev, "Failed mailbox read.\n");
141 ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */
145 /* Wait for a single mailbox command to complete.
146 * Returns zero on success.
148 static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev)
154 value = ql_read32(qdev, STS);
157 mdelay(UDELAY_DELAY); /* 100ms */
162 /* Execute a single mailbox command.
163 * Caller must hold PROC_ADDR semaphore.
165 static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp)
170 * Make sure there's nothing pending.
171 * This shouldn't happen.
173 if (ql_read32(qdev, CSR) & CSR_HRI)
176 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
181 * Fill the outbound mailboxes.
183 for (i = 0; i < mbcp->in_count; i++) {
184 status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i,
190 * Wake up the MPI firmware.
192 ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT);
194 ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
198 /* We are being asked by firmware to accept
199 * a change to the port. This is only
200 * a change to max frame sizes (Tx/Rx), pause
201 * parameters, or loopback mode. We wake up a worker
202 * to handler processing this since a mailbox command
203 * will need to be sent to ACK the request.
205 static int ql_idc_req_aen(struct ql_adapter *qdev)
208 struct mbox_params *mbcp = &qdev->idc_mbc;
210 netif_err(qdev, drv, qdev->ndev, "Enter!\n");
211 /* Get the status data and start up a thread to
212 * handle the request.
215 status = ql_get_mb_sts(qdev, mbcp);
217 netif_err(qdev, drv, qdev->ndev,
218 "Could not read MPI, resetting ASIC!\n");
219 ql_queue_asic_error(qdev);
221 /* Begin polled mode early so
222 * we don't get another interrupt
223 * when we leave mpi_worker.
225 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
226 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
231 /* Process an inter-device event completion.
232 * If good, signal the caller's completion.
234 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
237 struct mbox_params *mbcp = &qdev->idc_mbc;
240 status = ql_get_mb_sts(qdev, mbcp);
242 netif_err(qdev, drv, qdev->ndev,
243 "Could not read MPI, resetting RISC!\n");
244 ql_queue_fw_error(qdev);
246 /* Wake up the sleeping mpi_idc_work thread that is
247 * waiting for this event.
249 complete(&qdev->ide_completion);
254 static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
260 status = ql_get_mb_sts(qdev, mbcp);
262 netif_err(qdev, drv, qdev->ndev,
263 "%s: Could not get mailbox status.\n", __func__);
267 qdev->link_status = mbcp->mbox_out[1];
268 netif_err(qdev, drv, qdev->ndev, "Link Up.\n");
270 /* If we're coming back from an IDC event
271 * then set up the CAM and frame routing.
273 if (test_bit(QL_CAM_RT_SET, &qdev->flags)) {
274 status = ql_cam_route_initialize(qdev);
276 netif_err(qdev, ifup, qdev->ndev,
277 "Failed to init CAM/Routing tables.\n");
280 clear_bit(QL_CAM_RT_SET, &qdev->flags);
283 /* Queue up a worker to check the frame
284 * size information, and fix it if it's not
287 if (!test_bit(QL_PORT_CFG, &qdev->flags)) {
288 netif_err(qdev, drv, qdev->ndev, "Queue Port Config Worker!\n");
289 set_bit(QL_PORT_CFG, &qdev->flags);
290 /* Begin polled mode early so
291 * we don't get another interrupt
292 * when we leave mpi_worker dpc.
294 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
295 queue_delayed_work(qdev->workqueue,
296 &qdev->mpi_port_cfg_work, 0);
302 static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
308 status = ql_get_mb_sts(qdev, mbcp);
310 netif_err(qdev, drv, qdev->ndev, "Link down AEN broken!\n");
315 static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
321 status = ql_get_mb_sts(qdev, mbcp);
323 netif_err(qdev, drv, qdev->ndev, "SFP in AEN broken!\n");
325 netif_err(qdev, drv, qdev->ndev, "SFP insertion detected.\n");
330 static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
336 status = ql_get_mb_sts(qdev, mbcp);
338 netif_err(qdev, drv, qdev->ndev, "SFP out AEN broken!\n");
340 netif_err(qdev, drv, qdev->ndev, "SFP removal detected.\n");
345 static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp)
351 status = ql_get_mb_sts(qdev, mbcp);
353 netif_err(qdev, drv, qdev->ndev, "Lost AEN broken!\n");
357 netif_err(qdev, drv, qdev->ndev, "Lost AEN detected.\n");
358 for (i = 0; i < mbcp->out_count; i++)
359 netif_err(qdev, drv, qdev->ndev, "mbox_out[%d] = 0x%.08x.\n",
360 i, mbcp->mbox_out[i]);
367 static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
373 status = ql_get_mb_sts(qdev, mbcp);
375 netif_err(qdev, drv, qdev->ndev, "Firmware did not initialize!\n");
377 netif_err(qdev, drv, qdev->ndev, "Firmware Revision = 0x%.08x.\n",
379 qdev->fw_rev_id = mbcp->mbox_out[1];
380 status = ql_cam_route_initialize(qdev);
382 netif_err(qdev, ifup, qdev->ndev,
383 "Failed to init CAM/Routing tables.\n");
387 /* Process an async event and clear it unless it's an
389 * This can get called iteratively from the mpi_work thread
390 * when events arrive via an interrupt.
391 * It also gets called when a mailbox command is polling for
392 * it's completion. */
393 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
396 int orig_count = mbcp->out_count;
398 /* Just get mailbox zero for now. */
400 status = ql_get_mb_sts(qdev, mbcp);
402 netif_err(qdev, drv, qdev->ndev,
403 "Could not read MPI, resetting ASIC!\n");
404 ql_queue_asic_error(qdev);
408 switch (mbcp->mbox_out[0]) {
410 /* This case is only active when we arrive here
411 * as a result of issuing a mailbox command to
414 case MB_CMD_STS_INTRMDT:
415 case MB_CMD_STS_GOOD:
416 case MB_CMD_STS_INVLD_CMD:
417 case MB_CMD_STS_XFC_ERR:
418 case MB_CMD_STS_CSUM_ERR:
420 case MB_CMD_STS_PARAM_ERR:
421 /* We can only get mailbox status if we're polling from an
422 * unfinished command. Get the rest of the status data and
423 * return back to the caller.
424 * We only end up here when we're polling for a mailbox
425 * command completion.
427 mbcp->out_count = orig_count;
428 status = ql_get_mb_sts(qdev, mbcp);
431 /* We are being asked by firmware to accept
432 * a change to the port. This is only
433 * a change to max frame sizes (Tx/Rx), pause
434 * parameters, or loopback mode.
437 status = ql_idc_req_aen(qdev);
440 /* Process and inbound IDC event.
441 * This will happen when we're trying to
442 * change tx/rx max frame size, change pause
443 * parameters or loopback mode.
447 status = ql_idc_cmplt_aen(qdev);
451 ql_link_up(qdev, mbcp);
455 ql_link_down(qdev, mbcp);
458 case AEN_FW_INIT_DONE:
459 /* If we're in process on executing the firmware,
460 * then convert the status to normal mailbox status.
462 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
463 mbcp->out_count = orig_count;
464 status = ql_get_mb_sts(qdev, mbcp);
465 mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
468 ql_init_fw_done(qdev, mbcp);
472 ql_sfp_in(qdev, mbcp);
475 case AEN_AEN_SFP_OUT:
476 ql_sfp_out(qdev, mbcp);
479 /* This event can arrive at boot time or after an
480 * MPI reset if the firmware failed to initialize.
482 case AEN_FW_INIT_FAIL:
483 /* If we're in process on executing the firmware,
484 * then convert the status to normal mailbox status.
486 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
487 mbcp->out_count = orig_count;
488 status = ql_get_mb_sts(qdev, mbcp);
489 mbcp->mbox_out[0] = MB_CMD_STS_ERR;
492 netif_err(qdev, drv, qdev->ndev,
493 "Firmware initialization failed.\n");
495 ql_queue_fw_error(qdev);
499 netif_err(qdev, drv, qdev->ndev, "System Error.\n");
500 ql_queue_fw_error(qdev);
505 ql_aen_lost(qdev, mbcp);
509 /* Need to support AEN 8110 */
512 netif_err(qdev, drv, qdev->ndev,
513 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
514 /* Clear the MPI firmware status. */
517 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
518 /* Restore the original mailbox count to
519 * what the caller asked for. This can get
520 * changed when a mailbox command is waiting
521 * for a response and an AEN arrives and
524 mbcp->out_count = orig_count;
528 /* Execute a single mailbox command.
529 * mbcp is a pointer to an array of u32. Each
530 * element in the array contains the value for it's
531 * respective mailbox register.
533 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
538 mutex_lock(&qdev->mpi_mutex);
540 /* Begin polled mode for MPI */
541 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
543 /* Load the mailbox registers and wake up MPI RISC. */
544 status = ql_exec_mb_cmd(qdev, mbcp);
548 /* If we're generating a system error, then there's nothing
551 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
554 /* Wait for the command to complete. We loop
555 * here because some AEN might arrive while
556 * we're waiting for the mailbox command to
557 * complete. If more than 5 seconds expire we can
558 * assume something is wrong. */
559 count = jiffies + HZ * MAILBOX_TIMEOUT;
561 /* Wait for the interrupt to come in. */
562 status = ql_wait_mbx_cmd_cmplt(qdev);
566 /* Process the event. If it's an AEN, it
567 * will be handled in-line or a worker
568 * will be spawned. If it's our completion
569 * we will catch it below.
571 status = ql_mpi_handler(qdev, mbcp);
575 /* It's either the completion for our mailbox
576 * command complete or an AEN. If it's our
577 * completion then get out.
579 if (((mbcp->mbox_out[0] & 0x0000f000) ==
581 ((mbcp->mbox_out[0] & 0x0000f000) ==
584 } while (time_before(jiffies, count));
586 netif_err(qdev, drv, qdev->ndev,
587 "Timed out waiting for mailbox complete.\n");
593 /* Now we can clear the interrupt condition
594 * and look at our status.
596 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
598 if (((mbcp->mbox_out[0] & 0x0000f000) !=
600 ((mbcp->mbox_out[0] & 0x0000f000) !=
601 MB_CMD_STS_INTRMDT)) {
605 /* End polled mode for MPI */
606 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
607 mutex_unlock(&qdev->mpi_mutex);
611 /* Get MPI firmware version. This will be used for
612 * driver banner and for ethtool info.
613 * Returns zero on success.
615 int ql_mb_about_fw(struct ql_adapter *qdev)
617 struct mbox_params mbc;
618 struct mbox_params *mbcp = &mbc;
621 memset(mbcp, 0, sizeof(struct mbox_params));
626 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
628 status = ql_mailbox_command(qdev, mbcp);
632 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
633 netif_err(qdev, drv, qdev->ndev,
634 "Failed about firmware command\n");
638 /* Store the firmware version */
639 qdev->fw_rev_id = mbcp->mbox_out[1];
644 /* Get functional state for MPI firmware.
645 * Returns zero on success.
647 int ql_mb_get_fw_state(struct ql_adapter *qdev)
649 struct mbox_params mbc;
650 struct mbox_params *mbcp = &mbc;
653 memset(mbcp, 0, sizeof(struct mbox_params));
658 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
660 status = ql_mailbox_command(qdev, mbcp);
664 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
665 netif_err(qdev, drv, qdev->ndev,
666 "Failed Get Firmware State.\n");
670 /* If bit zero is set in mbx 1 then the firmware is
671 * running, but not initialized. This should never
674 if (mbcp->mbox_out[1] & 1) {
675 netif_err(qdev, drv, qdev->ndev,
676 "Firmware waiting for initialization.\n");
683 /* Send and ACK mailbox command to the firmware to
684 * let it continue with the change.
686 static int ql_mb_idc_ack(struct ql_adapter *qdev)
688 struct mbox_params mbc;
689 struct mbox_params *mbcp = &mbc;
692 memset(mbcp, 0, sizeof(struct mbox_params));
697 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
698 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
699 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
700 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
701 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
703 status = ql_mailbox_command(qdev, mbcp);
707 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
708 netif_err(qdev, drv, qdev->ndev, "Failed IDC ACK send.\n");
714 /* Get link settings and maximum frame size settings
715 * for the current port.
716 * Most likely will block.
718 int ql_mb_set_port_cfg(struct ql_adapter *qdev)
720 struct mbox_params mbc;
721 struct mbox_params *mbcp = &mbc;
724 memset(mbcp, 0, sizeof(struct mbox_params));
729 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
730 mbcp->mbox_in[1] = qdev->link_config;
731 mbcp->mbox_in[2] = qdev->max_frame_size;
733 status = ql_mailbox_command(qdev, mbcp);
737 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
738 netif_err(qdev, drv, qdev->ndev,
739 "Port Config sent, wait for IDC.\n");
740 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
741 netif_err(qdev, drv, qdev->ndev,
742 "Failed Set Port Configuration.\n");
748 static int ql_mb_dump_ram(struct ql_adapter *qdev, u64 req_dma, u32 addr,
752 struct mbox_params mbc;
753 struct mbox_params *mbcp = &mbc;
755 memset(mbcp, 0, sizeof(struct mbox_params));
760 mbcp->mbox_in[0] = MB_CMD_DUMP_RISC_RAM;
761 mbcp->mbox_in[1] = LSW(addr);
762 mbcp->mbox_in[2] = MSW(req_dma);
763 mbcp->mbox_in[3] = LSW(req_dma);
764 mbcp->mbox_in[4] = MSW(size);
765 mbcp->mbox_in[5] = LSW(size);
766 mbcp->mbox_in[6] = MSW(MSD(req_dma));
767 mbcp->mbox_in[7] = LSW(MSD(req_dma));
768 mbcp->mbox_in[8] = MSW(addr);
770 status = ql_mailbox_command(qdev, mbcp);
774 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
775 netif_err(qdev, drv, qdev->ndev, "Failed to dump risc RAM.\n");
781 /* Issue a mailbox command to dump RISC RAM. */
782 int ql_dump_risc_ram_area(struct ql_adapter *qdev, void *buf,
783 u32 ram_addr, int word_count)
789 my_buf = pci_alloc_consistent(qdev->pdev, word_count * sizeof(u32),
794 status = ql_mb_dump_ram(qdev, buf_dma, ram_addr, word_count);
796 memcpy(buf, my_buf, word_count * sizeof(u32));
798 pci_free_consistent(qdev->pdev, word_count * sizeof(u32), my_buf,
803 /* Get link settings and maximum frame size settings
804 * for the current port.
805 * Most likely will block.
807 int ql_mb_get_port_cfg(struct ql_adapter *qdev)
809 struct mbox_params mbc;
810 struct mbox_params *mbcp = &mbc;
813 memset(mbcp, 0, sizeof(struct mbox_params));
818 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
820 status = ql_mailbox_command(qdev, mbcp);
824 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
825 netif_err(qdev, drv, qdev->ndev,
826 "Failed Get Port Configuration.\n");
829 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
830 "Passed Get Port Configuration.\n");
831 qdev->link_config = mbcp->mbox_out[1];
832 qdev->max_frame_size = mbcp->mbox_out[2];
837 int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol)
839 struct mbox_params mbc;
840 struct mbox_params *mbcp = &mbc;
843 memset(mbcp, 0, sizeof(struct mbox_params));
848 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MODE;
849 mbcp->mbox_in[1] = wol;
851 status = ql_mailbox_command(qdev, mbcp);
855 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
856 netif_err(qdev, drv, qdev->ndev, "Failed to set WOL mode.\n");
862 int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol)
864 struct mbox_params mbc;
865 struct mbox_params *mbcp = &mbc;
867 u8 *addr = qdev->ndev->dev_addr;
869 memset(mbcp, 0, sizeof(struct mbox_params));
874 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MAGIC;
876 mbcp->mbox_in[1] = (u32)addr[0];
877 mbcp->mbox_in[2] = (u32)addr[1];
878 mbcp->mbox_in[3] = (u32)addr[2];
879 mbcp->mbox_in[4] = (u32)addr[3];
880 mbcp->mbox_in[5] = (u32)addr[4];
881 mbcp->mbox_in[6] = (u32)addr[5];
882 mbcp->mbox_in[7] = 0;
884 mbcp->mbox_in[1] = 0;
885 mbcp->mbox_in[2] = 1;
886 mbcp->mbox_in[3] = 1;
887 mbcp->mbox_in[4] = 1;
888 mbcp->mbox_in[5] = 1;
889 mbcp->mbox_in[6] = 1;
890 mbcp->mbox_in[7] = 0;
893 status = ql_mailbox_command(qdev, mbcp);
897 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
898 netif_err(qdev, drv, qdev->ndev, "Failed to set WOL mode.\n");
904 /* IDC - Inter Device Communication...
905 * Some firmware commands require consent of adjacent FCOE
906 * function. This function waits for the OK, or a
907 * counter-request for a little more time.i
908 * The firmware will complete the request if the other
909 * function doesn't respond.
911 static int ql_idc_wait(struct ql_adapter *qdev)
913 int status = -ETIMEDOUT;
914 long wait_time = 1 * HZ;
915 struct mbox_params *mbcp = &qdev->idc_mbc;
918 /* Wait here for the command to complete
919 * via the IDC process.
922 wait_for_completion_timeout(&qdev->ide_completion,
925 netif_err(qdev, drv, qdev->ndev, "IDC Timeout.\n");
928 /* Now examine the response from the IDC process.
929 * We might have a good completion or a request for
932 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
933 netif_err(qdev, drv, qdev->ndev,
934 "IDC Time Extension from function.\n");
935 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
936 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
937 netif_err(qdev, drv, qdev->ndev, "IDC Success.\n");
941 netif_err(qdev, drv, qdev->ndev,
942 "IDC: Invalid State 0x%.04x.\n",
952 int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config)
954 struct mbox_params mbc;
955 struct mbox_params *mbcp = &mbc;
958 memset(mbcp, 0, sizeof(struct mbox_params));
963 mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG;
964 mbcp->mbox_in[1] = led_config;
966 status = ql_mailbox_command(qdev, mbcp);
970 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
971 netif_err(qdev, drv, qdev->ndev,
972 "Failed to set LED Configuration.\n");
979 int ql_mb_get_led_cfg(struct ql_adapter *qdev)
981 struct mbox_params mbc;
982 struct mbox_params *mbcp = &mbc;
985 memset(mbcp, 0, sizeof(struct mbox_params));
990 mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG;
992 status = ql_mailbox_command(qdev, mbcp);
996 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
997 netif_err(qdev, drv, qdev->ndev,
998 "Failed to get LED Configuration.\n");
1001 qdev->led_config = mbcp->mbox_out[1];
1006 int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
1008 struct mbox_params mbc;
1009 struct mbox_params *mbcp = &mbc;
1012 memset(mbcp, 0, sizeof(struct mbox_params));
1015 mbcp->out_count = 2;
1017 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
1018 mbcp->mbox_in[1] = control;
1020 status = ql_mailbox_command(qdev, mbcp);
1024 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
1027 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1028 netif_err(qdev, drv, qdev->ndev,
1029 "Command not supported by firmware.\n");
1031 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1032 /* This indicates that the firmware is
1033 * already in the state we are trying to
1036 netif_err(qdev, drv, qdev->ndev,
1037 "Command parameters make no change.\n");
1042 /* Returns a negative error code or the mailbox command status. */
1043 static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
1045 struct mbox_params mbc;
1046 struct mbox_params *mbcp = &mbc;
1049 memset(mbcp, 0, sizeof(struct mbox_params));
1053 mbcp->out_count = 1;
1055 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
1057 status = ql_mailbox_command(qdev, mbcp);
1061 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
1062 *control = mbcp->mbox_in[1];
1066 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1067 netif_err(qdev, drv, qdev->ndev,
1068 "Command not supported by firmware.\n");
1070 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1071 netif_err(qdev, drv, qdev->ndev,
1072 "Failed to get MPI traffic control.\n");
1078 int ql_wait_fifo_empty(struct ql_adapter *qdev)
1081 u32 mgmnt_fifo_empty;
1085 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
1086 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
1087 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
1088 if (nic_fifo_empty && mgmnt_fifo_empty)
1091 } while (count-- > 0);
1095 /* API called in work thread context to set new TX/RX
1096 * maximum frame size values to match MTU.
1098 static int ql_set_port_cfg(struct ql_adapter *qdev)
1102 status = ql_mb_set_port_cfg(qdev);
1105 status = ql_idc_wait(qdev);
1109 /* The following routines are worker threads that process
1110 * events that may sleep waiting for completion.
1113 /* This thread gets the maximum TX and RX frame size values
1114 * from the firmware and, if necessary, changes them to match
1117 void ql_mpi_port_cfg_work(struct work_struct *work)
1119 struct ql_adapter *qdev =
1120 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
1123 status = ql_mb_get_port_cfg(qdev);
1125 netif_err(qdev, drv, qdev->ndev,
1126 "Bug: Failed to get port config data.\n");
1130 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
1131 qdev->max_frame_size == CFG_DEFAULT_MAX_FRAME_SIZE)
1134 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
1135 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
1136 status = ql_set_port_cfg(qdev);
1138 netif_err(qdev, drv, qdev->ndev,
1139 "Bug: Failed to set port config data.\n");
1143 clear_bit(QL_PORT_CFG, &qdev->flags);
1146 ql_queue_fw_error(qdev);
1150 /* Process an inter-device request. This is issues by
1151 * the firmware in response to another function requesting
1152 * a change to the port. We set a flag to indicate a change
1153 * has been made and then send a mailbox command ACKing
1154 * the change request.
1156 void ql_mpi_idc_work(struct work_struct *work)
1158 struct ql_adapter *qdev =
1159 container_of(work, struct ql_adapter, mpi_idc_work.work);
1161 struct mbox_params *mbcp = &qdev->idc_mbc;
1165 aen = mbcp->mbox_out[1] >> 16;
1166 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
1170 netif_err(qdev, drv, qdev->ndev,
1171 "Bug: Unhandled IDC action.\n");
1173 case MB_CMD_PORT_RESET:
1174 case MB_CMD_STOP_FW:
1177 case MB_CMD_SET_PORT_CFG:
1178 /* Signal the resulting link up AEN
1179 * that the frame routing and mac addr
1182 set_bit(QL_CAM_RT_SET, &qdev->flags);
1183 /* Do ACK if required */
1185 status = ql_mb_idc_ack(qdev);
1187 netif_err(qdev, drv, qdev->ndev,
1188 "Bug: No pending IDC!\n");
1190 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
1191 "IDC ACK not required\n");
1192 status = 0; /* success */
1196 /* These sub-commands issued by another (FCoE)
1197 * function are requesting to do an operation
1198 * on the shared resource (MPI environment).
1199 * We currently don't issue these so we just
1202 case MB_CMD_IOP_RESTART_MPI:
1203 case MB_CMD_IOP_PREP_LINK_DOWN:
1204 /* Drop the link, reload the routing
1205 * table when link comes up.
1208 set_bit(QL_CAM_RT_SET, &qdev->flags);
1210 case MB_CMD_IOP_DVR_START:
1211 case MB_CMD_IOP_FLASH_ACC:
1212 case MB_CMD_IOP_CORE_DUMP_MPI:
1213 case MB_CMD_IOP_PREP_UPDATE_MPI:
1214 case MB_CMD_IOP_COMP_UPDATE_MPI:
1215 case MB_CMD_IOP_NONE: /* an IDC without params */
1216 /* Do ACK if required */
1218 status = ql_mb_idc_ack(qdev);
1220 netif_err(qdev, drv, qdev->ndev,
1221 "Bug: No pending IDC!\n");
1223 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
1224 "IDC ACK not required\n");
1225 status = 0; /* success */
1231 void ql_mpi_work(struct work_struct *work)
1233 struct ql_adapter *qdev =
1234 container_of(work, struct ql_adapter, mpi_work.work);
1235 struct mbox_params mbc;
1236 struct mbox_params *mbcp = &mbc;
1239 mutex_lock(&qdev->mpi_mutex);
1240 /* Begin polled mode for MPI */
1241 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
1243 while (ql_read32(qdev, STS) & STS_PI) {
1244 memset(mbcp, 0, sizeof(struct mbox_params));
1245 mbcp->out_count = 1;
1246 /* Don't continue if an async event
1247 * did not complete properly.
1249 err = ql_mpi_handler(qdev, mbcp);
1254 /* End polled mode for MPI */
1255 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
1256 mutex_unlock(&qdev->mpi_mutex);
1259 void ql_mpi_reset_work(struct work_struct *work)
1261 struct ql_adapter *qdev =
1262 container_of(work, struct ql_adapter, mpi_reset_work.work);
1263 cancel_delayed_work_sync(&qdev->mpi_work);
1264 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
1265 cancel_delayed_work_sync(&qdev->mpi_idc_work);
1266 /* If we're not the dominant NIC function,
1267 * then there is nothing to do.
1269 if (!ql_own_firmware(qdev)) {
1270 netif_err(qdev, drv, qdev->ndev, "Don't own firmware!\n");
1274 if (qdev->mpi_coredump && !ql_core_dump(qdev, qdev->mpi_coredump)) {
1275 netif_err(qdev, drv, qdev->ndev, "Core is dumped!\n");
1276 qdev->core_is_dumped = 1;
1277 queue_delayed_work(qdev->workqueue,
1278 &qdev->mpi_core_to_log, 5 * HZ);
1280 ql_soft_reset_mpi_risc(qdev);