3 static void ql_display_mb_sts(struct ql_adapter
*qdev
,
4 struct mbox_params
*mbcp
)
7 static char *err_sts
[] = {
9 "Command Not Supported",
10 "Host Interface Error",
12 "Unused Completion Status",
14 "Command Parameter Error"};
16 QPRINTK(qdev
, DRV
, DEBUG
, "%s.\n",
17 err_sts
[mbcp
->mbox_out
[0] & 0x0000000f]);
18 for (i
= 0; i
< mbcp
->out_count
; i
++)
19 QPRINTK(qdev
, DRV
, DEBUG
, "mbox_out[%d] = 0x%.08x.\n",
20 i
, mbcp
->mbox_out
[i
]);
23 int ql_read_mpi_reg(struct ql_adapter
*qdev
, u32 reg
, u32
*data
)
26 /* wait for reg to come ready */
27 status
= ql_wait_reg_rdy(qdev
, PROC_ADDR
, PROC_ADDR_RDY
, PROC_ADDR_ERR
);
30 /* set up for reg read */
31 ql_write32(qdev
, PROC_ADDR
, reg
| PROC_ADDR_R
);
32 /* wait for reg to come ready */
33 status
= ql_wait_reg_rdy(qdev
, PROC_ADDR
, PROC_ADDR_RDY
, PROC_ADDR_ERR
);
37 *data
= ql_read32(qdev
, PROC_DATA
);
42 int ql_write_mpi_reg(struct ql_adapter
*qdev
, u32 reg
, u32 data
)
45 /* wait for reg to come ready */
46 status
= ql_wait_reg_rdy(qdev
, PROC_ADDR
, PROC_ADDR_RDY
, PROC_ADDR_ERR
);
49 /* write the data to the data reg */
50 ql_write32(qdev
, PROC_DATA
, data
);
51 /* trigger the write */
52 ql_write32(qdev
, PROC_ADDR
, reg
);
53 /* wait for reg to come ready */
54 status
= ql_wait_reg_rdy(qdev
, PROC_ADDR
, PROC_ADDR_RDY
, PROC_ADDR_ERR
);
61 int ql_soft_reset_mpi_risc(struct ql_adapter
*qdev
)
64 status
= ql_write_mpi_reg(qdev
, 0x00001010, 1);
68 static int ql_get_mb_sts(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
72 status
= ql_sem_spinlock(qdev
, SEM_PROC_REG_MASK
);
75 for (i
= 0; i
< mbcp
->out_count
; i
++) {
77 ql_read_mpi_reg(qdev
, qdev
->mailbox_out
+ i
,
80 QPRINTK(qdev
, DRV
, ERR
, "Failed mailbox read.\n");
84 ql_sem_unlock(qdev
, SEM_PROC_REG_MASK
); /* does flush too */
88 /* Wait for a single mailbox command to complete.
89 * Returns zero on success.
91 static int ql_wait_mbx_cmd_cmplt(struct ql_adapter
*qdev
)
93 int count
= 50; /* TODO: arbitrary for now. */
97 value
= ql_read32(qdev
, STS
);
100 udelay(UDELAY_DELAY
); /* 10us */
105 /* Execute a single mailbox command.
106 * Caller must hold PROC_ADDR semaphore.
108 static int ql_exec_mb_cmd(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
113 * Make sure there's nothing pending.
114 * This shouldn't happen.
116 if (ql_read32(qdev
, CSR
) & CSR_HRI
)
119 status
= ql_sem_spinlock(qdev
, SEM_PROC_REG_MASK
);
124 * Fill the outbound mailboxes.
126 for (i
= 0; i
< mbcp
->in_count
; i
++) {
127 status
= ql_write_mpi_reg(qdev
, qdev
->mailbox_in
+ i
,
133 * Wake up the MPI firmware.
135 ql_write32(qdev
, CSR
, CSR_CMD_SET_H2R_INT
);
137 ql_sem_unlock(qdev
, SEM_PROC_REG_MASK
);
141 /* We are being asked by firmware to accept
142 * a change to the port. This is only
143 * a change to max frame sizes (Tx/Rx), pause
144 * paramters, or loopback mode. We wake up a worker
145 * to handler processing this since a mailbox command
146 * will need to be sent to ACK the request.
148 static int ql_idc_req_aen(struct ql_adapter
*qdev
)
151 struct mbox_params
*mbcp
= &qdev
->idc_mbc
;
153 QPRINTK(qdev
, DRV
, ERR
, "Enter!\n");
154 /* Get the status data and start up a thread to
155 * handle the request.
157 mbcp
= &qdev
->idc_mbc
;
159 status
= ql_get_mb_sts(qdev
, mbcp
);
161 QPRINTK(qdev
, DRV
, ERR
,
162 "Could not read MPI, resetting ASIC!\n");
163 ql_queue_asic_error(qdev
);
165 /* Begin polled mode early so
166 * we don't get another interrupt
167 * when we leave mpi_worker.
169 ql_write32(qdev
, INTR_MASK
, (INTR_MASK_PI
<< 16));
170 queue_delayed_work(qdev
->workqueue
, &qdev
->mpi_idc_work
, 0);
175 /* Process an inter-device event completion.
176 * If good, signal the caller's completion.
178 static int ql_idc_cmplt_aen(struct ql_adapter
*qdev
)
181 struct mbox_params
*mbcp
= &qdev
->idc_mbc
;
183 status
= ql_get_mb_sts(qdev
, mbcp
);
185 QPRINTK(qdev
, DRV
, ERR
,
186 "Could not read MPI, resetting RISC!\n");
187 ql_queue_fw_error(qdev
);
189 /* Wake up the sleeping mpi_idc_work thread that is
190 * waiting for this event.
192 complete(&qdev
->ide_completion
);
197 static void ql_link_up(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
202 status
= ql_get_mb_sts(qdev
, mbcp
);
204 QPRINTK(qdev
, DRV
, ERR
,
205 "%s: Could not get mailbox status.\n", __func__
);
209 qdev
->link_status
= mbcp
->mbox_out
[1];
210 QPRINTK(qdev
, DRV
, ERR
, "Link Up.\n");
212 /* If we're coming back from an IDC event
213 * then set up the CAM and frame routing.
215 if (test_bit(QL_CAM_RT_SET
, &qdev
->flags
)) {
216 status
= ql_cam_route_initialize(qdev
);
218 QPRINTK(qdev
, IFUP
, ERR
,
219 "Failed to init CAM/Routing tables.\n");
222 clear_bit(QL_CAM_RT_SET
, &qdev
->flags
);
225 /* Queue up a worker to check the frame
226 * size information, and fix it if it's not
229 if (!test_bit(QL_PORT_CFG
, &qdev
->flags
)) {
230 QPRINTK(qdev
, DRV
, ERR
, "Queue Port Config Worker!\n");
231 set_bit(QL_PORT_CFG
, &qdev
->flags
);
232 /* Begin polled mode early so
233 * we don't get another interrupt
234 * when we leave mpi_worker dpc.
236 ql_write32(qdev
, INTR_MASK
, (INTR_MASK_PI
<< 16));
237 queue_delayed_work(qdev
->workqueue
,
238 &qdev
->mpi_port_cfg_work
, 0);
241 netif_carrier_on(qdev
->ndev
);
244 static void ql_link_down(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
250 status
= ql_get_mb_sts(qdev
, mbcp
);
252 QPRINTK(qdev
, DRV
, ERR
, "Link down AEN broken!\n");
254 netif_carrier_off(qdev
->ndev
);
257 static int ql_sfp_in(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
263 status
= ql_get_mb_sts(qdev
, mbcp
);
265 QPRINTK(qdev
, DRV
, ERR
, "SFP in AEN broken!\n");
267 QPRINTK(qdev
, DRV
, ERR
, "SFP insertion detected.\n");
272 static int ql_sfp_out(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
278 status
= ql_get_mb_sts(qdev
, mbcp
);
280 QPRINTK(qdev
, DRV
, ERR
, "SFP out AEN broken!\n");
282 QPRINTK(qdev
, DRV
, ERR
, "SFP removal detected.\n");
287 static void ql_init_fw_done(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
291 if (ql_get_mb_sts(qdev
, mbcp
)) {
292 QPRINTK(qdev
, DRV
, ERR
, "Firmware did not initialize!\n");
295 QPRINTK(qdev
, DRV
, ERR
, "Firmware initialized!\n");
296 QPRINTK(qdev
, DRV
, ERR
, "Firmware status = 0x%.08x.\n",
298 QPRINTK(qdev
, DRV
, ERR
, "Firmware Revision = 0x%.08x.\n",
301 /* Clear the MPI firmware status. */
302 ql_write32(qdev
, CSR
, CSR_CMD_CLR_R2PCI_INT
);
305 /* Process an async event and clear it unless it's an
307 * This can get called iteratively from the mpi_work thread
308 * when events arrive via an interrupt.
309 * It also gets called when a mailbox command is polling for
310 * it's completion. */
311 static int ql_mpi_handler(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
314 int orig_count
= mbcp
->out_count
;
316 /* Just get mailbox zero for now. */
318 status
= ql_get_mb_sts(qdev
, mbcp
);
320 QPRINTK(qdev
, DRV
, ERR
,
321 "Could not read MPI, resetting ASIC!\n");
322 ql_queue_asic_error(qdev
);
326 switch (mbcp
->mbox_out
[0]) {
328 /* This case is only active when we arrive here
329 * as a result of issuing a mailbox command to
332 case MB_CMD_STS_INTRMDT
:
333 case MB_CMD_STS_GOOD
:
334 case MB_CMD_STS_INVLD_CMD
:
335 case MB_CMD_STS_XFC_ERR
:
336 case MB_CMD_STS_CSUM_ERR
:
338 case MB_CMD_STS_PARAM_ERR
:
339 /* We can only get mailbox status if we're polling from an
340 * unfinished command. Get the rest of the status data and
341 * return back to the caller.
342 * We only end up here when we're polling for a mailbox
343 * command completion.
345 mbcp
->out_count
= orig_count
;
346 status
= ql_get_mb_sts(qdev
, mbcp
);
349 /* We are being asked by firmware to accept
350 * a change to the port. This is only
351 * a change to max frame sizes (Tx/Rx), pause
352 * paramters, or loopback mode.
355 status
= ql_idc_req_aen(qdev
);
358 /* Process and inbound IDC event.
359 * This will happen when we're trying to
360 * change tx/rx max frame size, change pause
361 * paramters or loopback mode.
365 status
= ql_idc_cmplt_aen(qdev
);
369 ql_link_up(qdev
, mbcp
);
373 ql_link_down(qdev
, mbcp
);
376 case AEN_FW_INIT_DONE
:
377 ql_init_fw_done(qdev
, mbcp
);
381 ql_sfp_in(qdev
, mbcp
);
384 case AEN_AEN_SFP_OUT
:
385 ql_sfp_out(qdev
, mbcp
);
388 case AEN_FW_INIT_FAIL
:
390 ql_queue_fw_error(qdev
);
394 QPRINTK(qdev
, DRV
, ERR
,
395 "Unsupported AE %.08x.\n", mbcp
->mbox_out
[0]);
396 /* Clear the MPI firmware status. */
399 ql_write32(qdev
, CSR
, CSR_CMD_CLR_R2PCI_INT
);
403 /* Execute a single mailbox command.
404 * mbcp is a pointer to an array of u32. Each
405 * element in the array contains the value for it's
406 * respective mailbox register.
408 static int ql_mailbox_command(struct ql_adapter
*qdev
, struct mbox_params
*mbcp
)
412 mutex_lock(&qdev
->mpi_mutex
);
414 /* Begin polled mode for MPI */
415 ql_write32(qdev
, INTR_MASK
, (INTR_MASK_PI
<< 16));
417 /* Load the mailbox registers and wake up MPI RISC. */
418 status
= ql_exec_mb_cmd(qdev
, mbcp
);
423 /* If we're generating a system error, then there's nothing
426 if (mbcp
->mbox_in
[0] == MB_CMD_MAKE_SYS_ERR
)
429 /* Wait for the command to complete. We loop
430 * here because some AEN might arrive while
431 * we're waiting for the mailbox command to
432 * complete. If more than 5 arrive then we can
433 * assume something is wrong. */
436 /* Wait for the interrupt to come in. */
437 status
= ql_wait_mbx_cmd_cmplt(qdev
);
441 /* Process the event. If it's an AEN, it
442 * will be handled in-line or a worker
443 * will be spawned. If it's our completion
444 * we will catch it below.
446 status
= ql_mpi_handler(qdev
, mbcp
);
450 /* It's either the completion for our mailbox
451 * command complete or an AEN. If it's our
452 * completion then get out.
454 if (((mbcp
->mbox_out
[0] & 0x0000f000) ==
456 ((mbcp
->mbox_out
[0] & 0x0000f000) ==
462 QPRINTK(qdev
, DRV
, ERR
,
463 "Timed out waiting for mailbox complete.\n");
468 /* Now we can clear the interrupt condition
469 * and look at our status.
471 ql_write32(qdev
, CSR
, CSR_CMD_CLR_R2PCI_INT
);
473 if (((mbcp
->mbox_out
[0] & 0x0000f000) !=
475 ((mbcp
->mbox_out
[0] & 0x0000f000) !=
476 MB_CMD_STS_INTRMDT
)) {
477 ql_display_mb_sts(qdev
, mbcp
);
481 mutex_unlock(&qdev
->mpi_mutex
);
482 /* End polled mode for MPI */
483 ql_write32(qdev
, INTR_MASK
, (INTR_MASK_PI
<< 16) | INTR_MASK_PI
);
487 /* Get functional state for MPI firmware.
488 * Returns zero on success.
490 int ql_mb_get_fw_state(struct ql_adapter
*qdev
)
492 struct mbox_params mbc
;
493 struct mbox_params
*mbcp
= &mbc
;
496 memset(mbcp
, 0, sizeof(struct mbox_params
));
501 mbcp
->mbox_in
[0] = MB_CMD_GET_FW_STATE
;
503 status
= ql_mailbox_command(qdev
, mbcp
);
507 if (mbcp
->mbox_out
[0] != MB_CMD_STS_GOOD
) {
508 QPRINTK(qdev
, DRV
, ERR
,
509 "Failed Get Firmware State.\n");
513 /* If bit zero is set in mbx 1 then the firmware is
514 * running, but not initialized. This should never
517 if (mbcp
->mbox_out
[1] & 1) {
518 QPRINTK(qdev
, DRV
, ERR
,
519 "Firmware waiting for initialization.\n");
526 /* Send and ACK mailbox command to the firmware to
527 * let it continue with the change.
529 int ql_mb_idc_ack(struct ql_adapter
*qdev
)
531 struct mbox_params mbc
;
532 struct mbox_params
*mbcp
= &mbc
;
535 memset(mbcp
, 0, sizeof(struct mbox_params
));
540 mbcp
->mbox_in
[0] = MB_CMD_IDC_ACK
;
541 mbcp
->mbox_in
[1] = qdev
->idc_mbc
.mbox_out
[1];
542 mbcp
->mbox_in
[2] = qdev
->idc_mbc
.mbox_out
[2];
543 mbcp
->mbox_in
[3] = qdev
->idc_mbc
.mbox_out
[3];
544 mbcp
->mbox_in
[4] = qdev
->idc_mbc
.mbox_out
[4];
546 status
= ql_mailbox_command(qdev
, mbcp
);
550 if (mbcp
->mbox_out
[0] != MB_CMD_STS_GOOD
) {
551 QPRINTK(qdev
, DRV
, ERR
,
552 "Failed IDC ACK send.\n");
558 /* Get link settings and maximum frame size settings
559 * for the current port.
560 * Most likely will block.
562 static int ql_mb_set_port_cfg(struct ql_adapter
*qdev
)
564 struct mbox_params mbc
;
565 struct mbox_params
*mbcp
= &mbc
;
568 memset(mbcp
, 0, sizeof(struct mbox_params
));
573 mbcp
->mbox_in
[0] = MB_CMD_SET_PORT_CFG
;
574 mbcp
->mbox_in
[1] = qdev
->link_config
;
575 mbcp
->mbox_in
[2] = qdev
->max_frame_size
;
578 status
= ql_mailbox_command(qdev
, mbcp
);
582 if (mbcp
->mbox_out
[0] == MB_CMD_STS_INTRMDT
) {
583 QPRINTK(qdev
, DRV
, ERR
,
584 "Port Config sent, wait for IDC.\n");
585 } else if (mbcp
->mbox_out
[0] != MB_CMD_STS_GOOD
) {
586 QPRINTK(qdev
, DRV
, ERR
,
587 "Failed Set Port Configuration.\n");
593 /* Get link settings and maximum frame size settings
594 * for the current port.
595 * Most likely will block.
597 static int ql_mb_get_port_cfg(struct ql_adapter
*qdev
)
599 struct mbox_params mbc
;
600 struct mbox_params
*mbcp
= &mbc
;
603 memset(mbcp
, 0, sizeof(struct mbox_params
));
608 mbcp
->mbox_in
[0] = MB_CMD_GET_PORT_CFG
;
610 status
= ql_mailbox_command(qdev
, mbcp
);
614 if (mbcp
->mbox_out
[0] != MB_CMD_STS_GOOD
) {
615 QPRINTK(qdev
, DRV
, ERR
,
616 "Failed Get Port Configuration.\n");
619 QPRINTK(qdev
, DRV
, DEBUG
,
620 "Passed Get Port Configuration.\n");
621 qdev
->link_config
= mbcp
->mbox_out
[1];
622 qdev
->max_frame_size
= mbcp
->mbox_out
[2];
627 /* IDC - Inter Device Communication...
628 * Some firmware commands require consent of adjacent FCOE
629 * function. This function waits for the OK, or a
630 * counter-request for a little more time.i
631 * The firmware will complete the request if the other
632 * function doesn't respond.
634 static int ql_idc_wait(struct ql_adapter
*qdev
)
636 int status
= -ETIMEDOUT
;
637 long wait_time
= 1 * HZ
;
638 struct mbox_params
*mbcp
= &qdev
->idc_mbc
;
640 /* Wait here for the command to complete
641 * via the IDC process.
644 wait_for_completion_timeout(&qdev
->ide_completion
,
647 QPRINTK(qdev
, DRV
, ERR
,
651 /* Now examine the response from the IDC process.
652 * We might have a good completion or a request for
655 if (mbcp
->mbox_out
[0] == AEN_IDC_EXT
) {
656 QPRINTK(qdev
, DRV
, ERR
,
657 "IDC Time Extension from function.\n");
658 wait_time
+= (mbcp
->mbox_out
[1] >> 8) & 0x0000000f;
659 } else if (mbcp
->mbox_out
[0] == AEN_IDC_CMPLT
) {
660 QPRINTK(qdev
, DRV
, ERR
,
665 QPRINTK(qdev
, DRV
, ERR
,
666 "IDC: Invalid State 0x%.04x.\n",
676 /* API called in work thread context to set new TX/RX
677 * maximum frame size values to match MTU.
679 static int ql_set_port_cfg(struct ql_adapter
*qdev
)
682 status
= ql_mb_set_port_cfg(qdev
);
685 status
= ql_idc_wait(qdev
);
689 /* The following routines are worker threads that process
690 * events that may sleep waiting for completion.
693 /* This thread gets the maximum TX and RX frame size values
694 * from the firmware and, if necessary, changes them to match
697 void ql_mpi_port_cfg_work(struct work_struct
*work
)
699 struct ql_adapter
*qdev
=
700 container_of(work
, struct ql_adapter
, mpi_port_cfg_work
.work
);
701 struct net_device
*ndev
= qdev
->ndev
;
704 status
= ql_mb_get_port_cfg(qdev
);
706 QPRINTK(qdev
, DRV
, ERR
,
707 "Bug: Failed to get port config data.\n");
711 if (ndev
->mtu
<= 2500)
713 else if (qdev
->link_config
& CFG_JUMBO_FRAME_SIZE
&&
714 qdev
->max_frame_size
==
715 CFG_DEFAULT_MAX_FRAME_SIZE
)
718 qdev
->link_config
|= CFG_JUMBO_FRAME_SIZE
;
719 qdev
->max_frame_size
= CFG_DEFAULT_MAX_FRAME_SIZE
;
720 status
= ql_set_port_cfg(qdev
);
722 QPRINTK(qdev
, DRV
, ERR
,
723 "Bug: Failed to set port config data.\n");
727 clear_bit(QL_PORT_CFG
, &qdev
->flags
);
730 ql_queue_fw_error(qdev
);
734 /* Process an inter-device request. This is issues by
735 * the firmware in response to another function requesting
736 * a change to the port. We set a flag to indicate a change
737 * has been made and then send a mailbox command ACKing
738 * the change request.
740 void ql_mpi_idc_work(struct work_struct
*work
)
742 struct ql_adapter
*qdev
=
743 container_of(work
, struct ql_adapter
, mpi_idc_work
.work
);
745 struct mbox_params
*mbcp
= &qdev
->idc_mbc
;
748 aen
= mbcp
->mbox_out
[1] >> 16;
752 QPRINTK(qdev
, DRV
, ERR
,
753 "Bug: Unhandled IDC action.\n");
755 case MB_CMD_PORT_RESET
:
756 case MB_CMD_SET_PORT_CFG
:
758 netif_carrier_off(qdev
->ndev
);
759 /* Signal the resulting link up AEN
760 * that the frame routing and mac addr
763 set_bit(QL_CAM_RT_SET
, &qdev
->flags
);
764 status
= ql_mb_idc_ack(qdev
);
766 QPRINTK(qdev
, DRV
, ERR
,
767 "Bug: No pending IDC!\n");
772 void ql_mpi_work(struct work_struct
*work
)
774 struct ql_adapter
*qdev
=
775 container_of(work
, struct ql_adapter
, mpi_work
.work
);
776 struct mbox_params mbc
;
777 struct mbox_params
*mbcp
= &mbc
;
779 mutex_lock(&qdev
->mpi_mutex
);
781 while (ql_read32(qdev
, STS
) & STS_PI
) {
782 memset(mbcp
, 0, sizeof(struct mbox_params
));
784 ql_mpi_handler(qdev
, mbcp
);
787 mutex_unlock(&qdev
->mpi_mutex
);
788 ql_enable_completion_interrupt(qdev
, 0);
791 void ql_mpi_reset_work(struct work_struct
*work
)
793 struct ql_adapter
*qdev
=
794 container_of(work
, struct ql_adapter
, mpi_reset_work
.work
);
795 cancel_delayed_work_sync(&qdev
->mpi_work
);
796 cancel_delayed_work_sync(&qdev
->mpi_port_cfg_work
);
797 cancel_delayed_work_sync(&qdev
->mpi_idc_work
);
798 ql_soft_reset_mpi_risc(qdev
);