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.
217 status = ql_get_mb_sts(qdev, mbcp);
219 netif_err(qdev, drv, qdev->ndev,
220 "Could not read MPI, resetting ASIC!\n");
221 ql_queue_asic_error(qdev);
223 /* Begin polled mode early so
224 * we don't get another interrupt
225 * when we leave mpi_worker.
227 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
228 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
233 /* Process an inter-device event completion.
234 * If good, signal the caller's completion.
236 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
239 struct mbox_params *mbcp = &qdev->idc_mbc;
241 status = ql_get_mb_sts(qdev, mbcp);
243 netif_err(qdev, drv, qdev->ndev,
244 "Could not read MPI, resetting RISC!\n");
245 ql_queue_fw_error(qdev);
247 /* Wake up the sleeping mpi_idc_work thread that is
248 * waiting for this event.
250 complete(&qdev->ide_completion);
255 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");
356 netif_err(qdev, drv, qdev->ndev, "Lost AEN detected.\n");
357 for (i = 0; i < mbcp->out_count; i++)
358 netif_err(qdev, drv, qdev->ndev, "mbox_out[%d] = 0x%.08x.\n",
359 i, mbcp->mbox_out[i]);
366 static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
372 status = ql_get_mb_sts(qdev, mbcp);
374 netif_err(qdev, drv, qdev->ndev, "Firmware did not initialize!\n");
376 netif_err(qdev, drv, qdev->ndev, "Firmware Revision = 0x%.08x.\n",
378 qdev->fw_rev_id = mbcp->mbox_out[1];
379 status = ql_cam_route_initialize(qdev);
381 netif_err(qdev, ifup, qdev->ndev,
382 "Failed to init CAM/Routing tables.\n");
386 /* Process an async event and clear it unless it's an
388 * This can get called iteratively from the mpi_work thread
389 * when events arrive via an interrupt.
390 * It also gets called when a mailbox command is polling for
391 * it's completion. */
392 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
395 int orig_count = mbcp->out_count;
397 /* Just get mailbox zero for now. */
399 status = ql_get_mb_sts(qdev, mbcp);
401 netif_err(qdev, drv, qdev->ndev,
402 "Could not read MPI, resetting ASIC!\n");
403 ql_queue_asic_error(qdev);
407 switch (mbcp->mbox_out[0]) {
409 /* This case is only active when we arrive here
410 * as a result of issuing a mailbox command to
413 case MB_CMD_STS_INTRMDT:
414 case MB_CMD_STS_GOOD:
415 case MB_CMD_STS_INVLD_CMD:
416 case MB_CMD_STS_XFC_ERR:
417 case MB_CMD_STS_CSUM_ERR:
419 case MB_CMD_STS_PARAM_ERR:
420 /* We can only get mailbox status if we're polling from an
421 * unfinished command. Get the rest of the status data and
422 * return back to the caller.
423 * We only end up here when we're polling for a mailbox
424 * command completion.
426 mbcp->out_count = orig_count;
427 status = ql_get_mb_sts(qdev, mbcp);
430 /* We are being asked by firmware to accept
431 * a change to the port. This is only
432 * a change to max frame sizes (Tx/Rx), pause
433 * parameters, or loopback mode.
436 status = ql_idc_req_aen(qdev);
439 /* Process and inbound IDC event.
440 * This will happen when we're trying to
441 * change tx/rx max frame size, change pause
442 * parameters or loopback mode.
446 status = ql_idc_cmplt_aen(qdev);
450 ql_link_up(qdev, mbcp);
454 ql_link_down(qdev, mbcp);
457 case AEN_FW_INIT_DONE:
458 /* If we're in process on executing the firmware,
459 * then convert the status to normal mailbox status.
461 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
462 mbcp->out_count = orig_count;
463 status = ql_get_mb_sts(qdev, mbcp);
464 mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
467 ql_init_fw_done(qdev, mbcp);
471 ql_sfp_in(qdev, mbcp);
474 case AEN_AEN_SFP_OUT:
475 ql_sfp_out(qdev, mbcp);
478 /* This event can arrive at boot time or after an
479 * MPI reset if the firmware failed to initialize.
481 case AEN_FW_INIT_FAIL:
482 /* If we're in process on executing the firmware,
483 * then convert the status to normal mailbox status.
485 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
486 mbcp->out_count = orig_count;
487 status = ql_get_mb_sts(qdev, mbcp);
488 mbcp->mbox_out[0] = MB_CMD_STS_ERR;
491 netif_err(qdev, drv, qdev->ndev,
492 "Firmware initialization failed.\n");
494 ql_queue_fw_error(qdev);
498 netif_err(qdev, drv, qdev->ndev, "System Error.\n");
499 ql_queue_fw_error(qdev);
504 ql_aen_lost(qdev, mbcp);
508 /* Need to support AEN 8110 */
511 netif_err(qdev, drv, qdev->ndev,
512 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
513 /* Clear the MPI firmware status. */
516 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
517 /* Restore the original mailbox count to
518 * what the caller asked for. This can get
519 * changed when a mailbox command is waiting
520 * for a response and an AEN arrives and
523 mbcp->out_count = orig_count;
527 /* Execute a single mailbox command.
528 * mbcp is a pointer to an array of u32. Each
529 * element in the array contains the value for it's
530 * respective mailbox register.
532 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
537 mutex_lock(&qdev->mpi_mutex);
539 /* Begin polled mode for MPI */
540 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
542 /* Load the mailbox registers and wake up MPI RISC. */
543 status = ql_exec_mb_cmd(qdev, mbcp);
547 /* If we're generating a system error, then there's nothing
550 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
553 /* Wait for the command to complete. We loop
554 * here because some AEN might arrive while
555 * we're waiting for the mailbox command to
556 * complete. If more than 5 seconds expire we can
557 * assume something is wrong. */
558 count = jiffies + HZ * MAILBOX_TIMEOUT;
560 /* Wait for the interrupt to come in. */
561 status = ql_wait_mbx_cmd_cmplt(qdev);
565 /* Process the event. If it's an AEN, it
566 * will be handled in-line or a worker
567 * will be spawned. If it's our completion
568 * we will catch it below.
570 status = ql_mpi_handler(qdev, mbcp);
574 /* It's either the completion for our mailbox
575 * command complete or an AEN. If it's our
576 * completion then get out.
578 if (((mbcp->mbox_out[0] & 0x0000f000) ==
580 ((mbcp->mbox_out[0] & 0x0000f000) ==
583 } while (time_before(jiffies, count));
585 netif_err(qdev, drv, qdev->ndev,
586 "Timed out waiting for mailbox complete.\n");
592 /* Now we can clear the interrupt condition
593 * and look at our status.
595 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
597 if (((mbcp->mbox_out[0] & 0x0000f000) !=
599 ((mbcp->mbox_out[0] & 0x0000f000) !=
600 MB_CMD_STS_INTRMDT)) {
604 /* End polled mode for MPI */
605 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
606 mutex_unlock(&qdev->mpi_mutex);
610 /* Get MPI firmware version. This will be used for
611 * driver banner and for ethtool info.
612 * Returns zero on success.
614 int ql_mb_about_fw(struct ql_adapter *qdev)
616 struct mbox_params mbc;
617 struct mbox_params *mbcp = &mbc;
620 memset(mbcp, 0, sizeof(struct mbox_params));
625 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
627 status = ql_mailbox_command(qdev, mbcp);
631 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
632 netif_err(qdev, drv, qdev->ndev,
633 "Failed about firmware command\n");
637 /* Store the firmware version */
638 qdev->fw_rev_id = mbcp->mbox_out[1];
643 /* Get functional state for MPI firmware.
644 * Returns zero on success.
646 int ql_mb_get_fw_state(struct ql_adapter *qdev)
648 struct mbox_params mbc;
649 struct mbox_params *mbcp = &mbc;
652 memset(mbcp, 0, sizeof(struct mbox_params));
657 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
659 status = ql_mailbox_command(qdev, mbcp);
663 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
664 netif_err(qdev, drv, qdev->ndev,
665 "Failed Get Firmware State.\n");
669 /* If bit zero is set in mbx 1 then the firmware is
670 * running, but not initialized. This should never
673 if (mbcp->mbox_out[1] & 1) {
674 netif_err(qdev, drv, qdev->ndev,
675 "Firmware waiting for initialization.\n");
682 /* Send and ACK mailbox command to the firmware to
683 * let it continue with the change.
685 static int ql_mb_idc_ack(struct ql_adapter *qdev)
687 struct mbox_params mbc;
688 struct mbox_params *mbcp = &mbc;
691 memset(mbcp, 0, sizeof(struct mbox_params));
696 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
697 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
698 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
699 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
700 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
702 status = ql_mailbox_command(qdev, mbcp);
706 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
707 netif_err(qdev, drv, qdev->ndev, "Failed IDC ACK send.\n");
713 /* Get link settings and maximum frame size settings
714 * for the current port.
715 * Most likely will block.
717 int ql_mb_set_port_cfg(struct ql_adapter *qdev)
719 struct mbox_params mbc;
720 struct mbox_params *mbcp = &mbc;
723 memset(mbcp, 0, sizeof(struct mbox_params));
728 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
729 mbcp->mbox_in[1] = qdev->link_config;
730 mbcp->mbox_in[2] = qdev->max_frame_size;
732 status = ql_mailbox_command(qdev, mbcp);
736 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
737 netif_err(qdev, drv, qdev->ndev,
738 "Port Config sent, wait for IDC.\n");
739 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
740 netif_err(qdev, drv, qdev->ndev,
741 "Failed Set Port Configuration.\n");
747 static int ql_mb_dump_ram(struct ql_adapter *qdev, u64 req_dma, u32 addr,
751 struct mbox_params mbc;
752 struct mbox_params *mbcp = &mbc;
754 memset(mbcp, 0, sizeof(struct mbox_params));
759 mbcp->mbox_in[0] = MB_CMD_DUMP_RISC_RAM;
760 mbcp->mbox_in[1] = LSW(addr);
761 mbcp->mbox_in[2] = MSW(req_dma);
762 mbcp->mbox_in[3] = LSW(req_dma);
763 mbcp->mbox_in[4] = MSW(size);
764 mbcp->mbox_in[5] = LSW(size);
765 mbcp->mbox_in[6] = MSW(MSD(req_dma));
766 mbcp->mbox_in[7] = LSW(MSD(req_dma));
767 mbcp->mbox_in[8] = MSW(addr);
769 status = ql_mailbox_command(qdev, mbcp);
773 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
774 netif_err(qdev, drv, qdev->ndev, "Failed to dump risc RAM.\n");
780 /* Issue a mailbox command to dump RISC RAM. */
781 int ql_dump_risc_ram_area(struct ql_adapter *qdev, void *buf,
782 u32 ram_addr, int word_count)
788 my_buf = pci_alloc_consistent(qdev->pdev, word_count * sizeof(u32),
793 status = ql_mb_dump_ram(qdev, buf_dma, ram_addr, word_count);
795 memcpy(buf, my_buf, word_count * sizeof(u32));
797 pci_free_consistent(qdev->pdev, word_count * sizeof(u32), my_buf,
802 /* Get link settings and maximum frame size settings
803 * for the current port.
804 * Most likely will block.
806 int ql_mb_get_port_cfg(struct ql_adapter *qdev)
808 struct mbox_params mbc;
809 struct mbox_params *mbcp = &mbc;
812 memset(mbcp, 0, sizeof(struct mbox_params));
817 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
819 status = ql_mailbox_command(qdev, mbcp);
823 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
824 netif_err(qdev, drv, qdev->ndev,
825 "Failed Get Port Configuration.\n");
828 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
829 "Passed Get Port Configuration.\n");
830 qdev->link_config = mbcp->mbox_out[1];
831 qdev->max_frame_size = mbcp->mbox_out[2];
836 int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol)
838 struct mbox_params mbc;
839 struct mbox_params *mbcp = &mbc;
842 memset(mbcp, 0, sizeof(struct mbox_params));
847 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MODE;
848 mbcp->mbox_in[1] = wol;
850 status = ql_mailbox_command(qdev, mbcp);
854 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
855 netif_err(qdev, drv, qdev->ndev, "Failed to set WOL mode.\n");
861 int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol)
863 struct mbox_params mbc;
864 struct mbox_params *mbcp = &mbc;
866 u8 *addr = qdev->ndev->dev_addr;
868 memset(mbcp, 0, sizeof(struct mbox_params));
873 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MAGIC;
875 mbcp->mbox_in[1] = (u32)addr[0];
876 mbcp->mbox_in[2] = (u32)addr[1];
877 mbcp->mbox_in[3] = (u32)addr[2];
878 mbcp->mbox_in[4] = (u32)addr[3];
879 mbcp->mbox_in[5] = (u32)addr[4];
880 mbcp->mbox_in[6] = (u32)addr[5];
881 mbcp->mbox_in[7] = 0;
883 mbcp->mbox_in[1] = 0;
884 mbcp->mbox_in[2] = 1;
885 mbcp->mbox_in[3] = 1;
886 mbcp->mbox_in[4] = 1;
887 mbcp->mbox_in[5] = 1;
888 mbcp->mbox_in[6] = 1;
889 mbcp->mbox_in[7] = 0;
892 status = ql_mailbox_command(qdev, mbcp);
896 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
897 netif_err(qdev, drv, qdev->ndev, "Failed to set WOL mode.\n");
903 /* IDC - Inter Device Communication...
904 * Some firmware commands require consent of adjacent FCOE
905 * function. This function waits for the OK, or a
906 * counter-request for a little more time.i
907 * The firmware will complete the request if the other
908 * function doesn't respond.
910 static int ql_idc_wait(struct ql_adapter *qdev)
912 int status = -ETIMEDOUT;
913 long wait_time = 1 * HZ;
914 struct mbox_params *mbcp = &qdev->idc_mbc;
916 /* Wait here for the command to complete
917 * via the IDC process.
920 wait_for_completion_timeout(&qdev->ide_completion,
923 netif_err(qdev, drv, qdev->ndev, "IDC Timeout.\n");
926 /* Now examine the response from the IDC process.
927 * We might have a good completion or a request for
930 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
931 netif_err(qdev, drv, qdev->ndev,
932 "IDC Time Extension from function.\n");
933 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
934 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
935 netif_err(qdev, drv, qdev->ndev, "IDC Success.\n");
939 netif_err(qdev, drv, qdev->ndev,
940 "IDC: Invalid State 0x%.04x.\n",
950 int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config)
952 struct mbox_params mbc;
953 struct mbox_params *mbcp = &mbc;
956 memset(mbcp, 0, sizeof(struct mbox_params));
961 mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG;
962 mbcp->mbox_in[1] = led_config;
964 status = ql_mailbox_command(qdev, mbcp);
968 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
969 netif_err(qdev, drv, qdev->ndev,
970 "Failed to set LED Configuration.\n");
977 int ql_mb_get_led_cfg(struct ql_adapter *qdev)
979 struct mbox_params mbc;
980 struct mbox_params *mbcp = &mbc;
983 memset(mbcp, 0, sizeof(struct mbox_params));
988 mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG;
990 status = ql_mailbox_command(qdev, mbcp);
994 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
995 netif_err(qdev, drv, qdev->ndev,
996 "Failed to get LED Configuration.\n");
999 qdev->led_config = mbcp->mbox_out[1];
1004 int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
1006 struct mbox_params mbc;
1007 struct mbox_params *mbcp = &mbc;
1010 memset(mbcp, 0, sizeof(struct mbox_params));
1013 mbcp->out_count = 2;
1015 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
1016 mbcp->mbox_in[1] = control;
1018 status = ql_mailbox_command(qdev, mbcp);
1022 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
1025 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1026 netif_err(qdev, drv, qdev->ndev,
1027 "Command not supported by firmware.\n");
1029 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1030 /* This indicates that the firmware is
1031 * already in the state we are trying to
1034 netif_err(qdev, drv, qdev->ndev,
1035 "Command parameters make no change.\n");
1040 /* Returns a negative error code or the mailbox command status. */
1041 static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
1043 struct mbox_params mbc;
1044 struct mbox_params *mbcp = &mbc;
1047 memset(mbcp, 0, sizeof(struct mbox_params));
1051 mbcp->out_count = 1;
1053 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
1055 status = ql_mailbox_command(qdev, mbcp);
1059 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
1060 *control = mbcp->mbox_in[1];
1064 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1065 netif_err(qdev, drv, qdev->ndev,
1066 "Command not supported by firmware.\n");
1068 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1069 netif_err(qdev, drv, qdev->ndev,
1070 "Failed to get MPI traffic control.\n");
1076 int ql_wait_fifo_empty(struct ql_adapter *qdev)
1079 u32 mgmnt_fifo_empty;
1083 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
1084 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
1085 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
1086 if (nic_fifo_empty && mgmnt_fifo_empty)
1089 } while (count-- > 0);
1093 /* API called in work thread context to set new TX/RX
1094 * maximum frame size values to match MTU.
1096 static int ql_set_port_cfg(struct ql_adapter *qdev)
1099 status = ql_mb_set_port_cfg(qdev);
1102 status = ql_idc_wait(qdev);
1106 /* The following routines are worker threads that process
1107 * events that may sleep waiting for completion.
1110 /* This thread gets the maximum TX and RX frame size values
1111 * from the firmware and, if necessary, changes them to match
1114 void ql_mpi_port_cfg_work(struct work_struct *work)
1116 struct ql_adapter *qdev =
1117 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
1120 status = ql_mb_get_port_cfg(qdev);
1122 netif_err(qdev, drv, qdev->ndev,
1123 "Bug: Failed to get port config data.\n");
1127 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
1128 qdev->max_frame_size == CFG_DEFAULT_MAX_FRAME_SIZE)
1131 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
1132 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
1133 status = ql_set_port_cfg(qdev);
1135 netif_err(qdev, drv, qdev->ndev,
1136 "Bug: Failed to set port config data.\n");
1140 clear_bit(QL_PORT_CFG, &qdev->flags);
1143 ql_queue_fw_error(qdev);
1147 /* Process an inter-device request. This is issues by
1148 * the firmware in response to another function requesting
1149 * a change to the port. We set a flag to indicate a change
1150 * has been made and then send a mailbox command ACKing
1151 * the change request.
1153 void ql_mpi_idc_work(struct work_struct *work)
1155 struct ql_adapter *qdev =
1156 container_of(work, struct ql_adapter, mpi_idc_work.work);
1158 struct mbox_params *mbcp = &qdev->idc_mbc;
1162 aen = mbcp->mbox_out[1] >> 16;
1163 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
1167 netif_err(qdev, drv, qdev->ndev,
1168 "Bug: Unhandled IDC action.\n");
1170 case MB_CMD_PORT_RESET:
1171 case MB_CMD_STOP_FW:
1174 case MB_CMD_SET_PORT_CFG:
1175 /* Signal the resulting link up AEN
1176 * that the frame routing and mac addr
1179 set_bit(QL_CAM_RT_SET, &qdev->flags);
1180 /* Do ACK if required */
1182 status = ql_mb_idc_ack(qdev);
1184 netif_err(qdev, drv, qdev->ndev,
1185 "Bug: No pending IDC!\n");
1187 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
1188 "IDC ACK not required\n");
1189 status = 0; /* success */
1193 /* These sub-commands issued by another (FCoE)
1194 * function are requesting to do an operation
1195 * on the shared resource (MPI environment).
1196 * We currently don't issue these so we just
1199 case MB_CMD_IOP_RESTART_MPI:
1200 case MB_CMD_IOP_PREP_LINK_DOWN:
1201 /* Drop the link, reload the routing
1202 * table when link comes up.
1205 set_bit(QL_CAM_RT_SET, &qdev->flags);
1207 case MB_CMD_IOP_DVR_START:
1208 case MB_CMD_IOP_FLASH_ACC:
1209 case MB_CMD_IOP_CORE_DUMP_MPI:
1210 case MB_CMD_IOP_PREP_UPDATE_MPI:
1211 case MB_CMD_IOP_COMP_UPDATE_MPI:
1212 case MB_CMD_IOP_NONE: /* an IDC without params */
1213 /* Do ACK if required */
1215 status = ql_mb_idc_ack(qdev);
1217 netif_err(qdev, drv, qdev->ndev,
1218 "Bug: No pending IDC!\n");
1220 netif_printk(qdev, drv, KERN_DEBUG, qdev->ndev,
1221 "IDC ACK not required\n");
1222 status = 0; /* success */
1228 void ql_mpi_work(struct work_struct *work)
1230 struct ql_adapter *qdev =
1231 container_of(work, struct ql_adapter, mpi_work.work);
1232 struct mbox_params mbc;
1233 struct mbox_params *mbcp = &mbc;
1236 mutex_lock(&qdev->mpi_mutex);
1237 /* Begin polled mode for MPI */
1238 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
1240 while (ql_read32(qdev, STS) & STS_PI) {
1241 memset(mbcp, 0, sizeof(struct mbox_params));
1242 mbcp->out_count = 1;
1243 /* Don't continue if an async event
1244 * did not complete properly.
1246 err = ql_mpi_handler(qdev, mbcp);
1251 /* End polled mode for MPI */
1252 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
1253 mutex_unlock(&qdev->mpi_mutex);
1256 void ql_mpi_reset_work(struct work_struct *work)
1258 struct ql_adapter *qdev =
1259 container_of(work, struct ql_adapter, mpi_reset_work.work);
1260 cancel_delayed_work_sync(&qdev->mpi_work);
1261 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
1262 cancel_delayed_work_sync(&qdev->mpi_idc_work);
1263 /* If we're not the dominant NIC function,
1264 * then there is nothing to do.
1266 if (!ql_own_firmware(qdev)) {
1267 netif_err(qdev, drv, qdev->ndev, "Don't own firmware!\n");
1271 if (qdev->mpi_coredump && !ql_core_dump(qdev, qdev->mpi_coredump)) {
1272 netif_err(qdev, drv, qdev->ndev, "Core is dumped!\n");
1273 qdev->core_is_dumped = 1;
1274 queue_delayed_work(qdev->workqueue,
1275 &qdev->mpi_core_to_log, 5 * HZ);
1277 ql_soft_reset_mpi_risc(qdev);