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 void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
207 if (ql_get_mb_sts(qdev, mbcp)) {
208 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
211 QPRINTK(qdev, DRV, ERR, "Firmware initialized!\n");
212 QPRINTK(qdev, DRV, ERR, "Firmware status = 0x%.08x.\n",
214 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
217 /* Clear the MPI firmware status. */
218 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
221 /* Process an async event and clear it unless it's an
223 * This can get called iteratively from the mpi_work thread
224 * when events arrive via an interrupt.
225 * It also gets called when a mailbox command is polling for
226 * it's completion. */
227 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
230 int orig_count = mbcp->out_count;
232 /* Just get mailbox zero for now. */
234 status = ql_get_mb_sts(qdev, mbcp);
236 QPRINTK(qdev, DRV, ERR,
237 "Could not read MPI, resetting ASIC!\n");
238 ql_queue_asic_error(qdev);
242 switch (mbcp->mbox_out[0]) {
244 /* This case is only active when we arrive here
245 * as a result of issuing a mailbox command to
248 case MB_CMD_STS_INTRMDT:
249 case MB_CMD_STS_GOOD:
250 case MB_CMD_STS_INVLD_CMD:
251 case MB_CMD_STS_XFC_ERR:
252 case MB_CMD_STS_CSUM_ERR:
254 case MB_CMD_STS_PARAM_ERR:
255 /* We can only get mailbox status if we're polling from an
256 * unfinished command. Get the rest of the status data and
257 * return back to the caller.
258 * We only end up here when we're polling for a mailbox
259 * command completion.
261 mbcp->out_count = orig_count;
262 status = ql_get_mb_sts(qdev, mbcp);
265 /* Process and inbound IDC event.
266 * This will happen when we're trying to
267 * change tx/rx max frame size, change pause
268 * paramters or loopback mode.
272 status = ql_idc_cmplt_aen(qdev);
276 ql_link_up(qdev, mbcp);
280 ql_link_down(qdev, mbcp);
283 case AEN_FW_INIT_DONE:
284 ql_init_fw_done(qdev, mbcp);
287 case AEN_FW_INIT_FAIL:
289 ql_queue_fw_error(qdev);
293 QPRINTK(qdev, DRV, ERR,
294 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
295 /* Clear the MPI firmware status. */
298 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
302 /* Execute a single mailbox command.
303 * mbcp is a pointer to an array of u32. Each
304 * element in the array contains the value for it's
305 * respective mailbox register.
307 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
311 mutex_lock(&qdev->mpi_mutex);
313 /* Begin polled mode for MPI */
314 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
316 /* Load the mailbox registers and wake up MPI RISC. */
317 status = ql_exec_mb_cmd(qdev, mbcp);
322 /* If we're generating a system error, then there's nothing
325 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
328 /* Wait for the command to complete. We loop
329 * here because some AEN might arrive while
330 * we're waiting for the mailbox command to
331 * complete. If more than 5 arrive then we can
332 * assume something is wrong. */
335 /* Wait for the interrupt to come in. */
336 status = ql_wait_mbx_cmd_cmplt(qdev);
340 /* Process the event. If it's an AEN, it
341 * will be handled in-line or a worker
342 * will be spawned. If it's our completion
343 * we will catch it below.
345 status = ql_mpi_handler(qdev, mbcp);
349 /* It's either the completion for our mailbox
350 * command complete or an AEN. If it's our
351 * completion then get out.
353 if (((mbcp->mbox_out[0] & 0x0000f000) ==
355 ((mbcp->mbox_out[0] & 0x0000f000) ==
361 QPRINTK(qdev, DRV, ERR,
362 "Timed out waiting for mailbox complete.\n");
367 /* Now we can clear the interrupt condition
368 * and look at our status.
370 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
372 if (((mbcp->mbox_out[0] & 0x0000f000) !=
374 ((mbcp->mbox_out[0] & 0x0000f000) !=
375 MB_CMD_STS_INTRMDT)) {
376 ql_display_mb_sts(qdev, mbcp);
380 mutex_unlock(&qdev->mpi_mutex);
381 /* End polled mode for MPI */
382 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
386 /* Get functional state for MPI firmware.
387 * Returns zero on success.
389 int ql_mb_get_fw_state(struct ql_adapter *qdev)
391 struct mbox_params mbc;
392 struct mbox_params *mbcp = &mbc;
395 memset(mbcp, 0, sizeof(struct mbox_params));
400 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
402 status = ql_mailbox_command(qdev, mbcp);
406 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
407 QPRINTK(qdev, DRV, ERR,
408 "Failed Get Firmware State.\n");
412 /* If bit zero is set in mbx 1 then the firmware is
413 * running, but not initialized. This should never
416 if (mbcp->mbox_out[1] & 1) {
417 QPRINTK(qdev, DRV, ERR,
418 "Firmware waiting for initialization.\n");
425 /* Get link settings and maximum frame size settings
426 * for the current port.
427 * Most likely will block.
429 static int ql_mb_set_port_cfg(struct ql_adapter *qdev)
431 struct mbox_params mbc;
432 struct mbox_params *mbcp = &mbc;
435 memset(mbcp, 0, sizeof(struct mbox_params));
440 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
441 mbcp->mbox_in[1] = qdev->link_config;
442 mbcp->mbox_in[2] = qdev->max_frame_size;
445 status = ql_mailbox_command(qdev, mbcp);
449 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
450 QPRINTK(qdev, DRV, ERR,
451 "Port Config sent, wait for IDC.\n");
452 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
453 QPRINTK(qdev, DRV, ERR,
454 "Failed Set Port Configuration.\n");
460 /* Get link settings and maximum frame size settings
461 * for the current port.
462 * Most likely will block.
464 static int ql_mb_get_port_cfg(struct ql_adapter *qdev)
466 struct mbox_params mbc;
467 struct mbox_params *mbcp = &mbc;
470 memset(mbcp, 0, sizeof(struct mbox_params));
475 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
477 status = ql_mailbox_command(qdev, mbcp);
481 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
482 QPRINTK(qdev, DRV, ERR,
483 "Failed Get Port Configuration.\n");
486 QPRINTK(qdev, DRV, DEBUG,
487 "Passed Get Port Configuration.\n");
488 qdev->link_config = mbcp->mbox_out[1];
489 qdev->max_frame_size = mbcp->mbox_out[2];
494 /* IDC - Inter Device Communication...
495 * Some firmware commands require consent of adjacent FCOE
496 * function. This function waits for the OK, or a
497 * counter-request for a little more time.i
498 * The firmware will complete the request if the other
499 * function doesn't respond.
501 static int ql_idc_wait(struct ql_adapter *qdev)
503 int status = -ETIMEDOUT;
504 long wait_time = 1 * HZ;
505 struct mbox_params *mbcp = &qdev->idc_mbc;
507 /* Wait here for the command to complete
508 * via the IDC process.
511 wait_for_completion_timeout(&qdev->ide_completion,
514 QPRINTK(qdev, DRV, ERR,
518 /* Now examine the response from the IDC process.
519 * We might have a good completion or a request for
522 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
523 QPRINTK(qdev, DRV, ERR,
524 "IDC Time Extension from function.\n");
525 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
526 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
527 QPRINTK(qdev, DRV, ERR,
532 QPRINTK(qdev, DRV, ERR,
533 "IDC: Invalid State 0x%.04x.\n",
543 /* API called in work thread context to set new TX/RX
544 * maximum frame size values to match MTU.
546 static int ql_set_port_cfg(struct ql_adapter *qdev)
549 status = ql_mb_set_port_cfg(qdev);
552 status = ql_idc_wait(qdev);
556 /* The following routines are worker threads that process
557 * events that may sleep waiting for completion.
560 /* This thread gets the maximum TX and RX frame size values
561 * from the firmware and, if necessary, changes them to match
564 void ql_mpi_port_cfg_work(struct work_struct *work)
566 struct ql_adapter *qdev =
567 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
568 struct net_device *ndev = qdev->ndev;
571 status = ql_mb_get_port_cfg(qdev);
573 QPRINTK(qdev, DRV, ERR,
574 "Bug: Failed to get port config data.\n");
578 if (ndev->mtu <= 2500)
580 else if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
581 qdev->max_frame_size ==
582 CFG_DEFAULT_MAX_FRAME_SIZE)
585 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
586 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
587 status = ql_set_port_cfg(qdev);
589 QPRINTK(qdev, DRV, ERR,
590 "Bug: Failed to set port config data.\n");
594 clear_bit(QL_PORT_CFG, &qdev->flags);
597 ql_queue_fw_error(qdev);
601 void ql_mpi_work(struct work_struct *work)
603 struct ql_adapter *qdev =
604 container_of(work, struct ql_adapter, mpi_work.work);
605 struct mbox_params mbc;
606 struct mbox_params *mbcp = &mbc;
608 mutex_lock(&qdev->mpi_mutex);
610 while (ql_read32(qdev, STS) & STS_PI) {
611 memset(mbcp, 0, sizeof(struct mbox_params));
613 ql_mpi_handler(qdev, mbcp);
616 mutex_unlock(&qdev->mpi_mutex);
617 ql_enable_completion_interrupt(qdev, 0);
620 void ql_mpi_reset_work(struct work_struct *work)
622 struct ql_adapter *qdev =
623 container_of(work, struct ql_adapter, mpi_reset_work.work);
624 cancel_delayed_work_sync(&qdev->mpi_work);
625 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
626 ql_soft_reset_mpi_risc(qdev);