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)
94 status = ql_write_mpi_reg(qdev, 0x00001010, 1);
98 /* Determine if we are in charge of the firwmare. If
99 * we are the lower of the 2 NIC pcie functions, or if
100 * we are the higher function and the lower function
103 int ql_own_firmware(struct ql_adapter *qdev)
107 /* If we are the lower of the 2 NIC functions
108 * on the chip the we are responsible for
109 * core dump and firmware reset after an error.
111 if (qdev->func < qdev->alt_func)
114 /* If we are the higher of the 2 NIC functions
115 * on the chip and the lower function is not
116 * enabled, then we are responsible for
117 * core dump and firmware reset after an error.
119 temp = ql_read32(qdev, STS);
120 if (!(temp & (1 << (8 + qdev->alt_func))))
127 static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
131 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
134 for (i = 0; i < mbcp->out_count; i++) {
136 ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
139 netif_err(qdev, drv, qdev->ndev, "Failed mailbox read.\n");
143 ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */
147 /* Wait for a single mailbox command to complete.
148 * Returns zero on success.
150 static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev)
156 value = ql_read32(qdev, STS);
159 mdelay(UDELAY_DELAY); /* 100ms */
164 /* Execute a single mailbox command.
165 * Caller must hold PROC_ADDR semaphore.
167 static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp)
172 * Make sure there's nothing pending.
173 * This shouldn't happen.
175 if (ql_read32(qdev, CSR) & CSR_HRI)
178 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
183 * Fill the outbound mailboxes.
185 for (i = 0; i < mbcp->in_count; i++) {
186 status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i,
192 * Wake up the MPI firmware.
194 ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT);
196 ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
200 /* We are being asked by firmware to accept
201 * a change to the port. This is only
202 * a change to max frame sizes (Tx/Rx), pause
203 * parameters, or loopback mode. We wake up a worker
204 * to handler processing this since a mailbox command
205 * will need to be sent to ACK the request.
207 static int ql_idc_req_aen(struct ql_adapter *qdev)
210 struct mbox_params *mbcp = &qdev->idc_mbc;
212 netif_err(qdev, drv, qdev->ndev, "Enter!\n");
213 /* Get the status data and start up a thread to
214 * handle the request.
216 mbcp = &qdev->idc_mbc;
218 status = ql_get_mb_sts(qdev, mbcp);
220 netif_err(qdev, drv, qdev->ndev,
221 "Could not read MPI, resetting ASIC!\n");
222 ql_queue_asic_error(qdev);
224 /* Begin polled mode early so
225 * we don't get another interrupt
226 * when we leave mpi_worker.
228 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
229 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
234 /* Process an inter-device event completion.
235 * If good, signal the caller's completion.
237 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
240 struct mbox_params *mbcp = &qdev->idc_mbc;
242 status = ql_get_mb_sts(qdev, mbcp);
244 netif_err(qdev, drv, qdev->ndev,
245 "Could not read MPI, resetting RISC!\n");
246 ql_queue_fw_error(qdev);
248 /* Wake up the sleeping mpi_idc_work thread that is
249 * waiting for this event.
251 complete(&qdev->ide_completion);
256 static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
261 status = ql_get_mb_sts(qdev, mbcp);
263 netif_err(qdev, drv, qdev->ndev,
264 "%s: Could not get mailbox status.\n", __func__);
268 qdev->link_status = mbcp->mbox_out[1];
269 netif_err(qdev, drv, qdev->ndev, "Link Up.\n");
271 /* If we're coming back from an IDC event
272 * then set up the CAM and frame routing.
274 if (test_bit(QL_CAM_RT_SET, &qdev->flags)) {
275 status = ql_cam_route_initialize(qdev);
277 netif_err(qdev, ifup, qdev->ndev,
278 "Failed to init CAM/Routing tables.\n");
281 clear_bit(QL_CAM_RT_SET, &qdev->flags);
284 /* Queue up a worker to check the frame
285 * size information, and fix it if it's not
288 if (!test_bit(QL_PORT_CFG, &qdev->flags)) {
289 netif_err(qdev, drv, qdev->ndev, "Queue Port Config Worker!\n");
290 set_bit(QL_PORT_CFG, &qdev->flags);
291 /* Begin polled mode early so
292 * we don't get another interrupt
293 * when we leave mpi_worker dpc.
295 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
296 queue_delayed_work(qdev->workqueue,
297 &qdev->mpi_port_cfg_work, 0);
303 static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
309 status = ql_get_mb_sts(qdev, mbcp);
311 netif_err(qdev, drv, qdev->ndev, "Link down AEN broken!\n");
316 static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
322 status = ql_get_mb_sts(qdev, mbcp);
324 netif_err(qdev, drv, qdev->ndev, "SFP in AEN broken!\n");
326 netif_err(qdev, drv, qdev->ndev, "SFP insertion detected.\n");
331 static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
337 status = ql_get_mb_sts(qdev, mbcp);
339 netif_err(qdev, drv, qdev->ndev, "SFP out AEN broken!\n");
341 netif_err(qdev, drv, qdev->ndev, "SFP removal detected.\n");
346 static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp)
352 status = ql_get_mb_sts(qdev, mbcp);
354 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);
549 /* If we're generating a system error, then there's nothing
552 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
555 /* Wait for the command to complete. We loop
556 * here because some AEN might arrive while
557 * we're waiting for the mailbox command to
558 * complete. If more than 5 seconds expire we can
559 * assume something is wrong. */
560 count = jiffies + HZ * MAILBOX_TIMEOUT;
562 /* Wait for the interrupt to come in. */
563 status = ql_wait_mbx_cmd_cmplt(qdev);
567 /* Process the event. If it's an AEN, it
568 * will be handled in-line or a worker
569 * will be spawned. If it's our completion
570 * we will catch it below.
572 status = ql_mpi_handler(qdev, mbcp);
576 /* It's either the completion for our mailbox
577 * command complete or an AEN. If it's our
578 * completion then get out.
580 if (((mbcp->mbox_out[0] & 0x0000f000) ==
582 ((mbcp->mbox_out[0] & 0x0000f000) ==
585 } while (time_before(jiffies, count));
587 netif_err(qdev, drv, qdev->ndev,
588 "Timed out waiting for mailbox complete.\n");
594 /* Now we can clear the interrupt condition
595 * and look at our status.
597 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
599 if (((mbcp->mbox_out[0] & 0x0000f000) !=
601 ((mbcp->mbox_out[0] & 0x0000f000) !=
602 MB_CMD_STS_INTRMDT)) {
606 /* End polled mode for MPI */
607 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
608 mutex_unlock(&qdev->mpi_mutex);
612 /* Get MPI firmware version. This will be used for
613 * driver banner and for ethtool info.
614 * Returns zero on success.
616 int ql_mb_about_fw(struct ql_adapter *qdev)
618 struct mbox_params mbc;
619 struct mbox_params *mbcp = &mbc;
622 memset(mbcp, 0, sizeof(struct mbox_params));
627 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
629 status = ql_mailbox_command(qdev, mbcp);
633 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
634 netif_err(qdev, drv, qdev->ndev,
635 "Failed about firmware command\n");
639 /* Store the firmware version */
640 qdev->fw_rev_id = mbcp->mbox_out[1];
645 /* Get functional state for MPI firmware.
646 * Returns zero on success.
648 int ql_mb_get_fw_state(struct ql_adapter *qdev)
650 struct mbox_params mbc;
651 struct mbox_params *mbcp = &mbc;
654 memset(mbcp, 0, sizeof(struct mbox_params));
659 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
661 status = ql_mailbox_command(qdev, mbcp);
665 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
666 netif_err(qdev, drv, qdev->ndev,
667 "Failed Get Firmware State.\n");
671 /* If bit zero is set in mbx 1 then the firmware is
672 * running, but not initialized. This should never
675 if (mbcp->mbox_out[1] & 1) {
676 netif_err(qdev, drv, qdev->ndev,
677 "Firmware waiting for initialization.\n");
684 /* Send and ACK mailbox command to the firmware to
685 * let it continue with the change.
687 static int ql_mb_idc_ack(struct ql_adapter *qdev)
689 struct mbox_params mbc;
690 struct mbox_params *mbcp = &mbc;
693 memset(mbcp, 0, sizeof(struct mbox_params));
698 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
699 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
700 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
701 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
702 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
704 status = ql_mailbox_command(qdev, mbcp);
708 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
709 netif_err(qdev, drv, qdev->ndev, "Failed IDC ACK send.\n");
715 /* Get link settings and maximum frame size settings
716 * for the current port.
717 * Most likely will block.
719 int ql_mb_set_port_cfg(struct ql_adapter *qdev)
721 struct mbox_params mbc;
722 struct mbox_params *mbcp = &mbc;
725 memset(mbcp, 0, sizeof(struct mbox_params));
730 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
731 mbcp->mbox_in[1] = qdev->link_config;
732 mbcp->mbox_in[2] = qdev->max_frame_size;
735 status = ql_mailbox_command(qdev, mbcp);
739 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
740 netif_err(qdev, drv, qdev->ndev,
741 "Port Config sent, wait for IDC.\n");
742 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
743 netif_err(qdev, drv, qdev->ndev,
744 "Failed Set Port Configuration.\n");
750 static int ql_mb_dump_ram(struct ql_adapter *qdev, u64 req_dma, u32 addr,
754 struct mbox_params mbc;
755 struct mbox_params *mbcp = &mbc;
757 memset(mbcp, 0, sizeof(struct mbox_params));
762 mbcp->mbox_in[0] = MB_CMD_DUMP_RISC_RAM;
763 mbcp->mbox_in[1] = LSW(addr);
764 mbcp->mbox_in[2] = MSW(req_dma);
765 mbcp->mbox_in[3] = LSW(req_dma);
766 mbcp->mbox_in[4] = MSW(size);
767 mbcp->mbox_in[5] = LSW(size);
768 mbcp->mbox_in[6] = MSW(MSD(req_dma));
769 mbcp->mbox_in[7] = LSW(MSD(req_dma));
770 mbcp->mbox_in[8] = MSW(addr);
773 status = ql_mailbox_command(qdev, mbcp);
777 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
778 netif_err(qdev, drv, qdev->ndev, "Failed to dump risc RAM.\n");
784 /* Issue a mailbox command to dump RISC RAM. */
785 int ql_dump_risc_ram_area(struct ql_adapter *qdev, void *buf,
786 u32 ram_addr, int word_count)
792 my_buf = pci_alloc_consistent(qdev->pdev, word_count * sizeof(u32),
797 status = ql_mb_dump_ram(qdev, buf_dma, ram_addr, word_count);
799 memcpy(buf, my_buf, word_count * sizeof(u32));
801 pci_free_consistent(qdev->pdev, word_count * sizeof(u32), my_buf,
806 /* Get link settings and maximum frame size settings
807 * for the current port.
808 * Most likely will block.
810 int ql_mb_get_port_cfg(struct ql_adapter *qdev)
812 struct mbox_params mbc;
813 struct mbox_params *mbcp = &mbc;
816 memset(mbcp, 0, sizeof(struct mbox_params));
821 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
823 status = ql_mailbox_command(qdev, mbcp);
827 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
828 netif_err(qdev, drv, qdev->ndev,
829 "Failed Get Port Configuration.\n");
832 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
833 "Passed Get Port Configuration.\n");
834 qdev->link_config = mbcp->mbox_out[1];
835 qdev->max_frame_size = mbcp->mbox_out[2];
840 int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol)
842 struct mbox_params mbc;
843 struct mbox_params *mbcp = &mbc;
846 memset(mbcp, 0, sizeof(struct mbox_params));
851 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MODE;
852 mbcp->mbox_in[1] = wol;
855 status = ql_mailbox_command(qdev, mbcp);
859 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
860 netif_err(qdev, drv, qdev->ndev, "Failed to set WOL mode.\n");
866 int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol)
868 struct mbox_params mbc;
869 struct mbox_params *mbcp = &mbc;
871 u8 *addr = qdev->ndev->dev_addr;
873 memset(mbcp, 0, sizeof(struct mbox_params));
878 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MAGIC;
880 mbcp->mbox_in[1] = (u32)addr[0];
881 mbcp->mbox_in[2] = (u32)addr[1];
882 mbcp->mbox_in[3] = (u32)addr[2];
883 mbcp->mbox_in[4] = (u32)addr[3];
884 mbcp->mbox_in[5] = (u32)addr[4];
885 mbcp->mbox_in[6] = (u32)addr[5];
886 mbcp->mbox_in[7] = 0;
888 mbcp->mbox_in[1] = 0;
889 mbcp->mbox_in[2] = 1;
890 mbcp->mbox_in[3] = 1;
891 mbcp->mbox_in[4] = 1;
892 mbcp->mbox_in[5] = 1;
893 mbcp->mbox_in[6] = 1;
894 mbcp->mbox_in[7] = 0;
897 status = ql_mailbox_command(qdev, mbcp);
901 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
902 netif_err(qdev, drv, qdev->ndev, "Failed to set WOL mode.\n");
908 /* IDC - Inter Device Communication...
909 * Some firmware commands require consent of adjacent FCOE
910 * function. This function waits for the OK, or a
911 * counter-request for a little more time.i
912 * The firmware will complete the request if the other
913 * function doesn't respond.
915 static int ql_idc_wait(struct ql_adapter *qdev)
917 int status = -ETIMEDOUT;
918 long wait_time = 1 * HZ;
919 struct mbox_params *mbcp = &qdev->idc_mbc;
921 /* Wait here for the command to complete
922 * via the IDC process.
925 wait_for_completion_timeout(&qdev->ide_completion,
928 netif_err(qdev, drv, qdev->ndev, "IDC Timeout.\n");
931 /* Now examine the response from the IDC process.
932 * We might have a good completion or a request for
935 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
936 netif_err(qdev, drv, qdev->ndev,
937 "IDC Time Extension from function.\n");
938 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
939 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
940 netif_err(qdev, drv, qdev->ndev, "IDC Success.\n");
944 netif_err(qdev, drv, qdev->ndev,
945 "IDC: Invalid State 0x%.04x.\n",
955 int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config)
957 struct mbox_params mbc;
958 struct mbox_params *mbcp = &mbc;
961 memset(mbcp, 0, sizeof(struct mbox_params));
966 mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG;
967 mbcp->mbox_in[1] = led_config;
970 status = ql_mailbox_command(qdev, mbcp);
974 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
975 netif_err(qdev, drv, qdev->ndev,
976 "Failed to set LED Configuration.\n");
983 int ql_mb_get_led_cfg(struct ql_adapter *qdev)
985 struct mbox_params mbc;
986 struct mbox_params *mbcp = &mbc;
989 memset(mbcp, 0, sizeof(struct mbox_params));
994 mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG;
996 status = ql_mailbox_command(qdev, mbcp);
1000 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
1001 netif_err(qdev, drv, qdev->ndev,
1002 "Failed to get LED Configuration.\n");
1005 qdev->led_config = mbcp->mbox_out[1];
1010 int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
1012 struct mbox_params mbc;
1013 struct mbox_params *mbcp = &mbc;
1016 memset(mbcp, 0, sizeof(struct mbox_params));
1019 mbcp->out_count = 2;
1021 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
1022 mbcp->mbox_in[1] = control;
1024 status = ql_mailbox_command(qdev, mbcp);
1028 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
1031 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1032 netif_err(qdev, drv, qdev->ndev,
1033 "Command not supported by firmware.\n");
1035 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1036 /* This indicates that the firmware is
1037 * already in the state we are trying to
1040 netif_err(qdev, drv, qdev->ndev,
1041 "Command parameters make no change.\n");
1046 /* Returns a negative error code or the mailbox command status. */
1047 static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
1049 struct mbox_params mbc;
1050 struct mbox_params *mbcp = &mbc;
1053 memset(mbcp, 0, sizeof(struct mbox_params));
1057 mbcp->out_count = 1;
1059 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
1061 status = ql_mailbox_command(qdev, mbcp);
1065 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
1066 *control = mbcp->mbox_in[1];
1070 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1071 netif_err(qdev, drv, qdev->ndev,
1072 "Command not supported by firmware.\n");
1074 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1075 netif_err(qdev, drv, qdev->ndev,
1076 "Failed to get MPI traffic control.\n");
1082 int ql_wait_fifo_empty(struct ql_adapter *qdev)
1085 u32 mgmnt_fifo_empty;
1089 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
1090 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
1091 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
1092 if (nic_fifo_empty && mgmnt_fifo_empty)
1095 } while (count-- > 0);
1099 /* API called in work thread context to set new TX/RX
1100 * maximum frame size values to match MTU.
1102 static int ql_set_port_cfg(struct ql_adapter *qdev)
1105 status = ql_mb_set_port_cfg(qdev);
1108 status = ql_idc_wait(qdev);
1112 /* The following routines are worker threads that process
1113 * events that may sleep waiting for completion.
1116 /* This thread gets the maximum TX and RX frame size values
1117 * from the firmware and, if necessary, changes them to match
1120 void ql_mpi_port_cfg_work(struct work_struct *work)
1122 struct ql_adapter *qdev =
1123 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
1126 status = ql_mb_get_port_cfg(qdev);
1128 netif_err(qdev, drv, qdev->ndev,
1129 "Bug: Failed to get port config data.\n");
1133 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
1134 qdev->max_frame_size ==
1135 CFG_DEFAULT_MAX_FRAME_SIZE)
1138 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
1139 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
1140 status = ql_set_port_cfg(qdev);
1142 netif_err(qdev, drv, qdev->ndev,
1143 "Bug: Failed to set port config data.\n");
1147 clear_bit(QL_PORT_CFG, &qdev->flags);
1150 ql_queue_fw_error(qdev);
1154 /* Process an inter-device request. This is issues by
1155 * the firmware in response to another function requesting
1156 * a change to the port. We set a flag to indicate a change
1157 * has been made and then send a mailbox command ACKing
1158 * the change request.
1160 void ql_mpi_idc_work(struct work_struct *work)
1162 struct ql_adapter *qdev =
1163 container_of(work, struct ql_adapter, mpi_idc_work.work);
1165 struct mbox_params *mbcp = &qdev->idc_mbc;
1169 aen = mbcp->mbox_out[1] >> 16;
1170 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
1174 netif_err(qdev, drv, qdev->ndev,
1175 "Bug: Unhandled IDC action.\n");
1177 case MB_CMD_PORT_RESET:
1178 case MB_CMD_STOP_FW:
1180 case MB_CMD_SET_PORT_CFG:
1181 /* Signal the resulting link up AEN
1182 * that the frame routing and mac addr
1185 set_bit(QL_CAM_RT_SET, &qdev->flags);
1186 /* Do ACK if required */
1188 status = ql_mb_idc_ack(qdev);
1190 netif_err(qdev, drv, qdev->ndev,
1191 "Bug: No pending IDC!\n");
1193 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
1194 "IDC ACK not required\n");
1195 status = 0; /* success */
1199 /* These sub-commands issued by another (FCoE)
1200 * function are requesting to do an operation
1201 * on the shared resource (MPI environment).
1202 * We currently don't issue these so we just
1205 case MB_CMD_IOP_RESTART_MPI:
1206 case MB_CMD_IOP_PREP_LINK_DOWN:
1207 /* Drop the link, reload the routing
1208 * table when link comes up.
1211 set_bit(QL_CAM_RT_SET, &qdev->flags);
1213 case MB_CMD_IOP_DVR_START:
1214 case MB_CMD_IOP_FLASH_ACC:
1215 case MB_CMD_IOP_CORE_DUMP_MPI:
1216 case MB_CMD_IOP_PREP_UPDATE_MPI:
1217 case MB_CMD_IOP_COMP_UPDATE_MPI:
1218 case MB_CMD_IOP_NONE: /* an IDC without params */
1219 /* Do ACK if required */
1221 status = ql_mb_idc_ack(qdev);
1223 netif_err(qdev, drv, qdev->ndev,
1224 "Bug: No pending IDC!\n");
1226 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
1227 "IDC ACK not required\n");
1228 status = 0; /* success */
1234 void ql_mpi_work(struct work_struct *work)
1236 struct ql_adapter *qdev =
1237 container_of(work, struct ql_adapter, mpi_work.work);
1238 struct mbox_params mbc;
1239 struct mbox_params *mbcp = &mbc;
1242 mutex_lock(&qdev->mpi_mutex);
1243 /* Begin polled mode for MPI */
1244 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
1246 while (ql_read32(qdev, STS) & STS_PI) {
1247 memset(mbcp, 0, sizeof(struct mbox_params));
1248 mbcp->out_count = 1;
1249 /* Don't continue if an async event
1250 * did not complete properly.
1252 err = ql_mpi_handler(qdev, mbcp);
1257 /* End polled mode for MPI */
1258 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
1259 mutex_unlock(&qdev->mpi_mutex);
1260 ql_enable_completion_interrupt(qdev, 0);
1263 void ql_mpi_reset_work(struct work_struct *work)
1265 struct ql_adapter *qdev =
1266 container_of(work, struct ql_adapter, mpi_reset_work.work);
1267 cancel_delayed_work_sync(&qdev->mpi_work);
1268 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
1269 cancel_delayed_work_sync(&qdev->mpi_idc_work);
1270 /* If we're not the dominant NIC function,
1271 * then there is nothing to do.
1273 if (!ql_own_firmware(qdev)) {
1274 netif_err(qdev, drv, qdev->ndev, "Don't own firmware!\n");
1278 if (qdev->mpi_coredump && !ql_core_dump(qdev, qdev->mpi_coredump)) {
1279 netif_err(qdev, drv, qdev->ndev, "Core is dumped!\n");
1280 qdev->core_is_dumped = 1;
1281 queue_delayed_work(qdev->workqueue,
1282 &qdev->mpi_core_to_log, 5 * HZ);
1284 ql_soft_reset_mpi_risc(qdev);