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 /* Process an inter-device event completion.
142 * If good, signal the caller's completion.
144 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
147 struct mbox_params *mbcp = &qdev->idc_mbc;
149 status = ql_get_mb_sts(qdev, mbcp);
151 QPRINTK(qdev, DRV, ERR,
152 "Could not read MPI, resetting RISC!\n");
153 ql_queue_fw_error(qdev);
155 /* Wake up the sleeping mpi_idc_work thread that is
156 * waiting for this event.
158 complete(&qdev->ide_completion);
162 static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
166 if (ql_get_mb_sts(qdev, mbcp))
169 qdev->link_status = mbcp->mbox_out[1];
170 QPRINTK(qdev, DRV, ERR, "Link Up.\n");
171 QPRINTK(qdev, DRV, INFO, "Link Status = 0x%.08x.\n", mbcp->mbox_out[1]);
172 if (!netif_carrier_ok(qdev->ndev)) {
173 QPRINTK(qdev, LINK, INFO, "Link is Up.\n");
174 netif_carrier_on(qdev->ndev);
175 netif_wake_queue(qdev->ndev);
178 /* Clear the MPI firmware status. */
179 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
182 static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
186 if (ql_get_mb_sts(qdev, mbcp)) {
187 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
191 if (netif_carrier_ok(qdev->ndev)) {
192 QPRINTK(qdev, LINK, INFO, "Link is Down.\n");
193 netif_carrier_off(qdev->ndev);
194 netif_stop_queue(qdev->ndev);
196 QPRINTK(qdev, DRV, ERR, "Link Down.\n");
197 QPRINTK(qdev, DRV, ERR, "Link Status = 0x%.08x.\n", mbcp->mbox_out[1]);
199 /* Clear the MPI firmware status. */
200 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
203 static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
209 status = ql_get_mb_sts(qdev, mbcp);
211 QPRINTK(qdev, DRV, ERR, "SFP in AEN broken!\n");
213 QPRINTK(qdev, DRV, ERR, "SFP insertion detected.\n");
218 static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
224 status = ql_get_mb_sts(qdev, mbcp);
226 QPRINTK(qdev, DRV, ERR, "SFP out AEN broken!\n");
228 QPRINTK(qdev, DRV, ERR, "SFP removal detected.\n");
233 static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
237 if (ql_get_mb_sts(qdev, mbcp)) {
238 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
241 QPRINTK(qdev, DRV, ERR, "Firmware initialized!\n");
242 QPRINTK(qdev, DRV, ERR, "Firmware status = 0x%.08x.\n",
244 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
247 /* Clear the MPI firmware status. */
248 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
251 /* Process an async event and clear it unless it's an
253 * This can get called iteratively from the mpi_work thread
254 * when events arrive via an interrupt.
255 * It also gets called when a mailbox command is polling for
256 * it's completion. */
257 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
260 int orig_count = mbcp->out_count;
262 /* Just get mailbox zero for now. */
264 status = ql_get_mb_sts(qdev, mbcp);
266 QPRINTK(qdev, DRV, ERR,
267 "Could not read MPI, resetting ASIC!\n");
268 ql_queue_asic_error(qdev);
272 switch (mbcp->mbox_out[0]) {
274 /* This case is only active when we arrive here
275 * as a result of issuing a mailbox command to
278 case MB_CMD_STS_INTRMDT:
279 case MB_CMD_STS_GOOD:
280 case MB_CMD_STS_INVLD_CMD:
281 case MB_CMD_STS_XFC_ERR:
282 case MB_CMD_STS_CSUM_ERR:
284 case MB_CMD_STS_PARAM_ERR:
285 /* We can only get mailbox status if we're polling from an
286 * unfinished command. Get the rest of the status data and
287 * return back to the caller.
288 * We only end up here when we're polling for a mailbox
289 * command completion.
291 mbcp->out_count = orig_count;
292 status = ql_get_mb_sts(qdev, mbcp);
295 /* Process and inbound IDC event.
296 * This will happen when we're trying to
297 * change tx/rx max frame size, change pause
298 * paramters or loopback mode.
302 status = ql_idc_cmplt_aen(qdev);
306 ql_link_up(qdev, mbcp);
310 ql_link_down(qdev, mbcp);
313 case AEN_FW_INIT_DONE:
314 ql_init_fw_done(qdev, mbcp);
318 ql_sfp_in(qdev, mbcp);
321 case AEN_AEN_SFP_OUT:
322 ql_sfp_out(qdev, mbcp);
325 case AEN_FW_INIT_FAIL:
327 ql_queue_fw_error(qdev);
331 QPRINTK(qdev, DRV, ERR,
332 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
333 /* Clear the MPI firmware status. */
336 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
340 /* Execute a single mailbox command.
341 * mbcp is a pointer to an array of u32. Each
342 * element in the array contains the value for it's
343 * respective mailbox register.
345 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
349 mutex_lock(&qdev->mpi_mutex);
351 /* Begin polled mode for MPI */
352 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
354 /* Load the mailbox registers and wake up MPI RISC. */
355 status = ql_exec_mb_cmd(qdev, mbcp);
360 /* If we're generating a system error, then there's nothing
363 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
366 /* Wait for the command to complete. We loop
367 * here because some AEN might arrive while
368 * we're waiting for the mailbox command to
369 * complete. If more than 5 arrive then we can
370 * assume something is wrong. */
373 /* Wait for the interrupt to come in. */
374 status = ql_wait_mbx_cmd_cmplt(qdev);
378 /* Process the event. If it's an AEN, it
379 * will be handled in-line or a worker
380 * will be spawned. If it's our completion
381 * we will catch it below.
383 status = ql_mpi_handler(qdev, mbcp);
387 /* It's either the completion for our mailbox
388 * command complete or an AEN. If it's our
389 * completion then get out.
391 if (((mbcp->mbox_out[0] & 0x0000f000) ==
393 ((mbcp->mbox_out[0] & 0x0000f000) ==
399 QPRINTK(qdev, DRV, ERR,
400 "Timed out waiting for mailbox complete.\n");
405 /* Now we can clear the interrupt condition
406 * and look at our status.
408 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
410 if (((mbcp->mbox_out[0] & 0x0000f000) !=
412 ((mbcp->mbox_out[0] & 0x0000f000) !=
413 MB_CMD_STS_INTRMDT)) {
414 ql_display_mb_sts(qdev, mbcp);
418 mutex_unlock(&qdev->mpi_mutex);
419 /* End polled mode for MPI */
420 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
424 /* Get functional state for MPI firmware.
425 * Returns zero on success.
427 int ql_mb_get_fw_state(struct ql_adapter *qdev)
429 struct mbox_params mbc;
430 struct mbox_params *mbcp = &mbc;
433 memset(mbcp, 0, sizeof(struct mbox_params));
438 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
440 status = ql_mailbox_command(qdev, mbcp);
444 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
445 QPRINTK(qdev, DRV, ERR,
446 "Failed Get Firmware State.\n");
450 /* If bit zero is set in mbx 1 then the firmware is
451 * running, but not initialized. This should never
454 if (mbcp->mbox_out[1] & 1) {
455 QPRINTK(qdev, DRV, ERR,
456 "Firmware waiting for initialization.\n");
463 /* Get link settings and maximum frame size settings
464 * for the current port.
465 * Most likely will block.
467 static int ql_mb_set_port_cfg(struct ql_adapter *qdev)
469 struct mbox_params mbc;
470 struct mbox_params *mbcp = &mbc;
473 memset(mbcp, 0, sizeof(struct mbox_params));
478 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
479 mbcp->mbox_in[1] = qdev->link_config;
480 mbcp->mbox_in[2] = qdev->max_frame_size;
483 status = ql_mailbox_command(qdev, mbcp);
487 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
488 QPRINTK(qdev, DRV, ERR,
489 "Port Config sent, wait for IDC.\n");
490 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
491 QPRINTK(qdev, DRV, ERR,
492 "Failed Set Port Configuration.\n");
498 /* Get link settings and maximum frame size settings
499 * for the current port.
500 * Most likely will block.
502 static int ql_mb_get_port_cfg(struct ql_adapter *qdev)
504 struct mbox_params mbc;
505 struct mbox_params *mbcp = &mbc;
508 memset(mbcp, 0, sizeof(struct mbox_params));
513 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
515 status = ql_mailbox_command(qdev, mbcp);
519 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
520 QPRINTK(qdev, DRV, ERR,
521 "Failed Get Port Configuration.\n");
524 QPRINTK(qdev, DRV, DEBUG,
525 "Passed Get Port Configuration.\n");
526 qdev->link_config = mbcp->mbox_out[1];
527 qdev->max_frame_size = mbcp->mbox_out[2];
532 /* IDC - Inter Device Communication...
533 * Some firmware commands require consent of adjacent FCOE
534 * function. This function waits for the OK, or a
535 * counter-request for a little more time.i
536 * The firmware will complete the request if the other
537 * function doesn't respond.
539 static int ql_idc_wait(struct ql_adapter *qdev)
541 int status = -ETIMEDOUT;
542 long wait_time = 1 * HZ;
543 struct mbox_params *mbcp = &qdev->idc_mbc;
545 /* Wait here for the command to complete
546 * via the IDC process.
549 wait_for_completion_timeout(&qdev->ide_completion,
552 QPRINTK(qdev, DRV, ERR,
556 /* Now examine the response from the IDC process.
557 * We might have a good completion or a request for
560 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
561 QPRINTK(qdev, DRV, ERR,
562 "IDC Time Extension from function.\n");
563 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
564 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
565 QPRINTK(qdev, DRV, ERR,
570 QPRINTK(qdev, DRV, ERR,
571 "IDC: Invalid State 0x%.04x.\n",
581 /* API called in work thread context to set new TX/RX
582 * maximum frame size values to match MTU.
584 static int ql_set_port_cfg(struct ql_adapter *qdev)
587 status = ql_mb_set_port_cfg(qdev);
590 status = ql_idc_wait(qdev);
594 /* The following routines are worker threads that process
595 * events that may sleep waiting for completion.
598 /* This thread gets the maximum TX and RX frame size values
599 * from the firmware and, if necessary, changes them to match
602 void ql_mpi_port_cfg_work(struct work_struct *work)
604 struct ql_adapter *qdev =
605 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
606 struct net_device *ndev = qdev->ndev;
609 status = ql_mb_get_port_cfg(qdev);
611 QPRINTK(qdev, DRV, ERR,
612 "Bug: Failed to get port config data.\n");
616 if (ndev->mtu <= 2500)
618 else if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
619 qdev->max_frame_size ==
620 CFG_DEFAULT_MAX_FRAME_SIZE)
623 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
624 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
625 status = ql_set_port_cfg(qdev);
627 QPRINTK(qdev, DRV, ERR,
628 "Bug: Failed to set port config data.\n");
632 clear_bit(QL_PORT_CFG, &qdev->flags);
635 ql_queue_fw_error(qdev);
639 void ql_mpi_work(struct work_struct *work)
641 struct ql_adapter *qdev =
642 container_of(work, struct ql_adapter, mpi_work.work);
643 struct mbox_params mbc;
644 struct mbox_params *mbcp = &mbc;
646 mutex_lock(&qdev->mpi_mutex);
648 while (ql_read32(qdev, STS) & STS_PI) {
649 memset(mbcp, 0, sizeof(struct mbox_params));
651 ql_mpi_handler(qdev, mbcp);
654 mutex_unlock(&qdev->mpi_mutex);
655 ql_enable_completion_interrupt(qdev, 0);
658 void ql_mpi_reset_work(struct work_struct *work)
660 struct ql_adapter *qdev =
661 container_of(work, struct ql_adapter, mpi_reset_work.work);
662 cancel_delayed_work_sync(&qdev->mpi_work);
663 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
664 ql_soft_reset_mpi_risc(qdev);