OSDN Git Service

qlge: Save status from firmware crash (system err).
[uclinux-h8/linux.git] / drivers / net / qlge / qlge_mpi.c
1 #include "qlge.h"
2
3 static void ql_display_mb_sts(struct ql_adapter *qdev,
4                                                 struct mbox_params *mbcp)
5 {
6         int i;
7         static char *err_sts[] = {
8                 "Command Complete",
9                 "Command Not Supported",
10                 "Host Interface Error",
11                 "Checksum Error",
12                 "Unused Completion Status",
13                 "Test Failed",
14                 "Command Parameter Error"};
15
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]);
21 }
22
23 int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
24 {
25         int status;
26         /* wait for reg to come ready */
27         status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
28         if (status)
29                 goto exit;
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);
34         if (status)
35                 goto exit;
36         /* get the data */
37         *data = ql_read32(qdev, PROC_DATA);
38 exit:
39         return status;
40 }
41
42 int ql_write_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 data)
43 {
44         int status = 0;
45         /* wait for reg to come ready */
46         status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
47         if (status)
48                 goto exit;
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);
55         if (status)
56                 goto exit;
57 exit:
58         return status;
59 }
60
61 int ql_soft_reset_mpi_risc(struct ql_adapter *qdev)
62 {
63         int status;
64         status = ql_write_mpi_reg(qdev, 0x00001010, 1);
65         return status;
66 }
67
68 static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
69 {
70         int i, status;
71
72         status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
73         if (status)
74                 return -EBUSY;
75         for (i = 0; i < mbcp->out_count; i++) {
76                 status =
77                     ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
78                                      &mbcp->mbox_out[i]);
79                 if (status) {
80                         QPRINTK(qdev, DRV, ERR, "Failed mailbox read.\n");
81                         break;
82                 }
83         }
84         ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */
85         return status;
86 }
87
88 /* Wait for a single mailbox command to complete.
89  * Returns zero on success.
90  */
91 static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev)
92 {
93         int count = 50; /* TODO: arbitrary for now. */
94         u32 value;
95
96         do {
97                 value = ql_read32(qdev, STS);
98                 if (value & STS_PI)
99                         return 0;
100                 udelay(UDELAY_DELAY); /* 10us */
101         } while (--count);
102         return -ETIMEDOUT;
103 }
104
105 /* Execute a single mailbox command.
106  * Caller must hold PROC_ADDR semaphore.
107  */
108 static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp)
109 {
110         int i, status;
111
112         /*
113          * Make sure there's nothing pending.
114          * This shouldn't happen.
115          */
116         if (ql_read32(qdev, CSR) & CSR_HRI)
117                 return -EIO;
118
119         status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
120         if (status)
121                 return status;
122
123         /*
124          * Fill the outbound mailboxes.
125          */
126         for (i = 0; i < mbcp->in_count; i++) {
127                 status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i,
128                                                 mbcp->mbox_in[i]);
129                 if (status)
130                         goto end;
131         }
132         /*
133          * Wake up the MPI firmware.
134          */
135         ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT);
136 end:
137         ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
138         return status;
139 }
140
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.
147  */
148 static int ql_idc_req_aen(struct ql_adapter *qdev)
149 {
150         int status;
151         struct mbox_params *mbcp = &qdev->idc_mbc;
152
153         QPRINTK(qdev, DRV, ERR, "Enter!\n");
154         /* Get the status data and start up a thread to
155          * handle the request.
156          */
157         mbcp = &qdev->idc_mbc;
158         mbcp->out_count = 4;
159         status = ql_get_mb_sts(qdev, mbcp);
160         if (status) {
161                 QPRINTK(qdev, DRV, ERR,
162                         "Could not read MPI, resetting ASIC!\n");
163                 ql_queue_asic_error(qdev);
164         } else  {
165                 /* Begin polled mode early so
166                  * we don't get another interrupt
167                  * when we leave mpi_worker.
168                  */
169                 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
170                 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
171         }
172         return status;
173 }
174
175 /* Process an inter-device event completion.
176  * If good, signal the caller's completion.
177  */
178 static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
179 {
180         int status;
181         struct mbox_params *mbcp = &qdev->idc_mbc;
182         mbcp->out_count = 4;
183         status = ql_get_mb_sts(qdev, mbcp);
184         if (status) {
185                 QPRINTK(qdev, DRV, ERR,
186                         "Could not read MPI, resetting RISC!\n");
187                 ql_queue_fw_error(qdev);
188         } else
189                 /* Wake up the sleeping mpi_idc_work thread that is
190                  * waiting for this event.
191                  */
192                 complete(&qdev->ide_completion);
193
194         return status;
195 }
196
197 static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
198 {
199         int status;
200         mbcp->out_count = 2;
201
202         status = ql_get_mb_sts(qdev, mbcp);
203         if (status) {
204                 QPRINTK(qdev, DRV, ERR,
205                         "%s: Could not get mailbox status.\n", __func__);
206                 return;
207         }
208
209         qdev->link_status = mbcp->mbox_out[1];
210         QPRINTK(qdev, DRV, ERR, "Link Up.\n");
211
212         /* If we're coming back from an IDC event
213          * then set up the CAM and frame routing.
214          */
215         if (test_bit(QL_CAM_RT_SET, &qdev->flags)) {
216                 status = ql_cam_route_initialize(qdev);
217                 if (status) {
218                         QPRINTK(qdev, IFUP, ERR,
219                         "Failed to init CAM/Routing tables.\n");
220                         return;
221                 } else
222                         clear_bit(QL_CAM_RT_SET, &qdev->flags);
223         }
224
225         /* Queue up a worker to check the frame
226          * size information, and fix it if it's not
227          * to our liking.
228          */
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.
235                  */
236                 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
237                 queue_delayed_work(qdev->workqueue,
238                                 &qdev->mpi_port_cfg_work, 0);
239         }
240
241         netif_carrier_on(qdev->ndev);
242 }
243
244 static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
245 {
246         int status;
247
248         mbcp->out_count = 3;
249
250         status = ql_get_mb_sts(qdev, mbcp);
251         if (status)
252                 QPRINTK(qdev, DRV, ERR, "Link down AEN broken!\n");
253
254         netif_carrier_off(qdev->ndev);
255 }
256
257 static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
258 {
259         int status;
260
261         mbcp->out_count = 5;
262
263         status = ql_get_mb_sts(qdev, mbcp);
264         if (status)
265                 QPRINTK(qdev, DRV, ERR, "SFP in AEN broken!\n");
266         else
267                 QPRINTK(qdev, DRV, ERR, "SFP insertion detected.\n");
268
269         return status;
270 }
271
272 static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
273 {
274         int status;
275
276         mbcp->out_count = 1;
277
278         status = ql_get_mb_sts(qdev, mbcp);
279         if (status)
280                 QPRINTK(qdev, DRV, ERR, "SFP out AEN broken!\n");
281         else
282                 QPRINTK(qdev, DRV, ERR, "SFP removal detected.\n");
283
284         return status;
285 }
286
287 static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
288 {
289         int status;
290
291         mbcp->out_count = 2;
292
293         status = ql_get_mb_sts(qdev, mbcp);
294         if (status) {
295                 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
296         } else {
297                 QPRINTK(qdev, DRV, ERR, "Firmware Revision  = 0x%.08x.\n",
298                         mbcp->mbox_out[1]);
299                 status = ql_cam_route_initialize(qdev);
300                 if (status)
301                         QPRINTK(qdev, IFUP, ERR,
302                                 "Failed to init CAM/Routing tables.\n");
303         }
304 }
305
306 /* Process an async event and clear it unless it's an
307  * error condition.
308  *  This can get called iteratively from the mpi_work thread
309  *  when events arrive via an interrupt.
310  *  It also gets called when a mailbox command is polling for
311  *  it's completion. */
312 static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
313 {
314         int status;
315         int orig_count = mbcp->out_count;
316
317         /* Just get mailbox zero for now. */
318         mbcp->out_count = 1;
319         status = ql_get_mb_sts(qdev, mbcp);
320         if (status) {
321                 QPRINTK(qdev, DRV, ERR,
322                         "Could not read MPI, resetting ASIC!\n");
323                 ql_queue_asic_error(qdev);
324                 goto end;
325         }
326
327         switch (mbcp->mbox_out[0]) {
328
329         /* This case is only active when we arrive here
330          * as a result of issuing a mailbox command to
331          * the firmware.
332          */
333         case MB_CMD_STS_INTRMDT:
334         case MB_CMD_STS_GOOD:
335         case MB_CMD_STS_INVLD_CMD:
336         case MB_CMD_STS_XFC_ERR:
337         case MB_CMD_STS_CSUM_ERR:
338         case MB_CMD_STS_ERR:
339         case MB_CMD_STS_PARAM_ERR:
340                 /* We can only get mailbox status if we're polling from an
341                  * unfinished command.  Get the rest of the status data and
342                  * return back to the caller.
343                  * We only end up here when we're polling for a mailbox
344                  * command completion.
345                  */
346                 mbcp->out_count = orig_count;
347                 status = ql_get_mb_sts(qdev, mbcp);
348                 return status;
349
350         /* We are being asked by firmware to accept
351          * a change to the port.  This is only
352          * a change to max frame sizes (Tx/Rx), pause
353          * paramters, or loopback mode.
354          */
355         case AEN_IDC_REQ:
356                 status = ql_idc_req_aen(qdev);
357                 break;
358
359         /* Process and inbound IDC event.
360          * This will happen when we're trying to
361          * change tx/rx max frame size, change pause
362          * paramters or loopback mode.
363          */
364         case AEN_IDC_CMPLT:
365         case AEN_IDC_EXT:
366                 status = ql_idc_cmplt_aen(qdev);
367                 break;
368
369         case AEN_LINK_UP:
370                 ql_link_up(qdev, mbcp);
371                 break;
372
373         case AEN_LINK_DOWN:
374                 ql_link_down(qdev, mbcp);
375                 break;
376
377         case AEN_FW_INIT_DONE:
378                 /* If we're in process on executing the firmware,
379                  * then convert the status to normal mailbox status.
380                  */
381                 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
382                         mbcp->out_count = orig_count;
383                         status = ql_get_mb_sts(qdev, mbcp);
384                         mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
385                         return status;
386                 }
387                 ql_init_fw_done(qdev, mbcp);
388                 break;
389
390         case AEN_AEN_SFP_IN:
391                 ql_sfp_in(qdev, mbcp);
392                 break;
393
394         case AEN_AEN_SFP_OUT:
395                 ql_sfp_out(qdev, mbcp);
396                 break;
397
398         /* This event can arrive at boot time or after an
399          * MPI reset if the firmware failed to initialize.
400          */
401         case AEN_FW_INIT_FAIL:
402                 /* If we're in process on executing the firmware,
403                  * then convert the status to normal mailbox status.
404                  */
405                 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
406                         mbcp->out_count = orig_count;
407                         status = ql_get_mb_sts(qdev, mbcp);
408                         mbcp->mbox_out[0] = MB_CMD_STS_ERR;
409                         return status;
410                 }
411                 QPRINTK(qdev, DRV, ERR,
412                         "Firmware initialization failed.\n");
413                 status = -EIO;
414                 ql_queue_fw_error(qdev);
415                 break;
416
417         case AEN_SYS_ERR:
418                 QPRINTK(qdev, DRV, ERR,
419                         "System Error.\n");
420                 ql_queue_fw_error(qdev);
421                 status = -EIO;
422                 break;
423
424         default:
425                 QPRINTK(qdev, DRV, ERR,
426                         "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
427                 /* Clear the MPI firmware status. */
428         }
429 end:
430         ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
431         return status;
432 }
433
434 /* Execute a single mailbox command.
435  * mbcp is a pointer to an array of u32.  Each
436  * element in the array contains the value for it's
437  * respective mailbox register.
438  */
439 static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
440 {
441         int status, count;
442
443         mutex_lock(&qdev->mpi_mutex);
444
445         /* Begin polled mode for MPI */
446         ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
447
448         /* Load the mailbox registers and wake up MPI RISC. */
449         status = ql_exec_mb_cmd(qdev, mbcp);
450         if (status)
451                 goto end;
452
453
454         /* If we're generating a system error, then there's nothing
455          * to wait for.
456          */
457         if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
458                 goto end;
459
460         /* Wait for the command to complete. We loop
461          * here because some AEN might arrive while
462          * we're waiting for the mailbox command to
463          * complete. If more than 5 arrive then we can
464          * assume something is wrong. */
465         count = 5;
466         do {
467                 /* Wait for the interrupt to come in. */
468                 status = ql_wait_mbx_cmd_cmplt(qdev);
469                 if (status)
470                         goto end;
471
472                 /* Process the event.  If it's an AEN, it
473                  * will be handled in-line or a worker
474                  * will be spawned. If it's our completion
475                  * we will catch it below.
476                  */
477                 status = ql_mpi_handler(qdev, mbcp);
478                 if (status)
479                         goto end;
480
481                 /* It's either the completion for our mailbox
482                  * command complete or an AEN.  If it's our
483                  * completion then get out.
484                  */
485                 if (((mbcp->mbox_out[0] & 0x0000f000) ==
486                                         MB_CMD_STS_GOOD) ||
487                         ((mbcp->mbox_out[0] & 0x0000f000) ==
488                                         MB_CMD_STS_INTRMDT))
489                         break;
490         } while (--count);
491
492         if (!count) {
493                 QPRINTK(qdev, DRV, ERR,
494                         "Timed out waiting for mailbox complete.\n");
495                 status = -ETIMEDOUT;
496                 goto end;
497         }
498
499         /* Now we can clear the interrupt condition
500          * and look at our status.
501          */
502         ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
503
504         if (((mbcp->mbox_out[0] & 0x0000f000) !=
505                                         MB_CMD_STS_GOOD) &&
506                 ((mbcp->mbox_out[0] & 0x0000f000) !=
507                                         MB_CMD_STS_INTRMDT)) {
508                 ql_display_mb_sts(qdev, mbcp);
509                 status = -EIO;
510         }
511 end:
512         mutex_unlock(&qdev->mpi_mutex);
513         /* End polled mode for MPI */
514         ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
515         return status;
516 }
517
518 /* Get functional state for MPI firmware.
519  * Returns zero on success.
520  */
521 int ql_mb_get_fw_state(struct ql_adapter *qdev)
522 {
523         struct mbox_params mbc;
524         struct mbox_params *mbcp = &mbc;
525         int status = 0;
526
527         memset(mbcp, 0, sizeof(struct mbox_params));
528
529         mbcp->in_count = 1;
530         mbcp->out_count = 2;
531
532         mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
533
534         status = ql_mailbox_command(qdev, mbcp);
535         if (status)
536                 return status;
537
538         if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
539                 QPRINTK(qdev, DRV, ERR,
540                         "Failed Get Firmware State.\n");
541                 status = -EIO;
542         }
543
544         /* If bit zero is set in mbx 1 then the firmware is
545          * running, but not initialized.  This should never
546          * happen.
547          */
548         if (mbcp->mbox_out[1] & 1) {
549                 QPRINTK(qdev, DRV, ERR,
550                         "Firmware waiting for initialization.\n");
551                 status = -EIO;
552         }
553
554         return status;
555 }
556
557 /* Send and ACK mailbox command to the firmware to
558  * let it continue with the change.
559  */
560 int ql_mb_idc_ack(struct ql_adapter *qdev)
561 {
562         struct mbox_params mbc;
563         struct mbox_params *mbcp = &mbc;
564         int status = 0;
565
566         memset(mbcp, 0, sizeof(struct mbox_params));
567
568         mbcp->in_count = 5;
569         mbcp->out_count = 1;
570
571         mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
572         mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
573         mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
574         mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
575         mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
576
577         status = ql_mailbox_command(qdev, mbcp);
578         if (status)
579                 return status;
580
581         if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
582                 QPRINTK(qdev, DRV, ERR,
583                         "Failed IDC ACK send.\n");
584                 status = -EIO;
585         }
586         return status;
587 }
588
589 /* Get link settings and maximum frame size settings
590  * for the current port.
591  * Most likely will block.
592  */
593 static int ql_mb_set_port_cfg(struct ql_adapter *qdev)
594 {
595         struct mbox_params mbc;
596         struct mbox_params *mbcp = &mbc;
597         int status = 0;
598
599         memset(mbcp, 0, sizeof(struct mbox_params));
600
601         mbcp->in_count = 3;
602         mbcp->out_count = 1;
603
604         mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
605         mbcp->mbox_in[1] = qdev->link_config;
606         mbcp->mbox_in[2] = qdev->max_frame_size;
607
608
609         status = ql_mailbox_command(qdev, mbcp);
610         if (status)
611                 return status;
612
613         if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
614                 QPRINTK(qdev, DRV, ERR,
615                         "Port Config sent, wait for IDC.\n");
616         } else  if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
617                 QPRINTK(qdev, DRV, ERR,
618                         "Failed Set Port Configuration.\n");
619                 status = -EIO;
620         }
621         return status;
622 }
623
624 /* Get link settings and maximum frame size settings
625  * for the current port.
626  * Most likely will block.
627  */
628 static int ql_mb_get_port_cfg(struct ql_adapter *qdev)
629 {
630         struct mbox_params mbc;
631         struct mbox_params *mbcp = &mbc;
632         int status = 0;
633
634         memset(mbcp, 0, sizeof(struct mbox_params));
635
636         mbcp->in_count = 1;
637         mbcp->out_count = 3;
638
639         mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
640
641         status = ql_mailbox_command(qdev, mbcp);
642         if (status)
643                 return status;
644
645         if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
646                 QPRINTK(qdev, DRV, ERR,
647                         "Failed Get Port Configuration.\n");
648                 status = -EIO;
649         } else  {
650                 QPRINTK(qdev, DRV, DEBUG,
651                         "Passed Get Port Configuration.\n");
652                 qdev->link_config = mbcp->mbox_out[1];
653                 qdev->max_frame_size = mbcp->mbox_out[2];
654         }
655         return status;
656 }
657
658 /* IDC - Inter Device Communication...
659  * Some firmware commands require consent of adjacent FCOE
660  * function.  This function waits for the OK, or a
661  * counter-request for a little more time.i
662  * The firmware will complete the request if the other
663  * function doesn't respond.
664  */
665 static int ql_idc_wait(struct ql_adapter *qdev)
666 {
667         int status = -ETIMEDOUT;
668         long wait_time = 1 * HZ;
669         struct mbox_params *mbcp = &qdev->idc_mbc;
670         do {
671                 /* Wait here for the command to complete
672                  * via the IDC process.
673                  */
674                 wait_time =
675                         wait_for_completion_timeout(&qdev->ide_completion,
676                                                         wait_time);
677                 if (!wait_time) {
678                         QPRINTK(qdev, DRV, ERR,
679                                 "IDC Timeout.\n");
680                         break;
681                 }
682                 /* Now examine the response from the IDC process.
683                  * We might have a good completion or a request for
684                  * more wait time.
685                  */
686                 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
687                         QPRINTK(qdev, DRV, ERR,
688                                 "IDC Time Extension from function.\n");
689                         wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
690                 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
691                         QPRINTK(qdev, DRV, ERR,
692                                 "IDC Success.\n");
693                         status = 0;
694                         break;
695                 } else {
696                         QPRINTK(qdev, DRV, ERR,
697                                 "IDC: Invalid State 0x%.04x.\n",
698                                 mbcp->mbox_out[0]);
699                         status = -EIO;
700                         break;
701                 }
702         } while (wait_time);
703
704         return status;
705 }
706
707 /* API called in work thread context to set new TX/RX
708  * maximum frame size values to match MTU.
709  */
710 static int ql_set_port_cfg(struct ql_adapter *qdev)
711 {
712         int status;
713         status = ql_mb_set_port_cfg(qdev);
714         if (status)
715                 return status;
716         status = ql_idc_wait(qdev);
717         return status;
718 }
719
720 /* The following routines are worker threads that process
721  * events that may sleep waiting for completion.
722  */
723
724 /* This thread gets the maximum TX and RX frame size values
725  * from the firmware and, if necessary, changes them to match
726  * the MTU setting.
727  */
728 void ql_mpi_port_cfg_work(struct work_struct *work)
729 {
730         struct ql_adapter *qdev =
731             container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
732         struct net_device *ndev = qdev->ndev;
733         int status;
734
735         status = ql_mb_get_port_cfg(qdev);
736         if (status) {
737                 QPRINTK(qdev, DRV, ERR,
738                         "Bug: Failed to get port config data.\n");
739                 goto err;
740         }
741
742         if (ndev->mtu <= 2500)
743                 goto end;
744         else if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
745                         qdev->max_frame_size ==
746                         CFG_DEFAULT_MAX_FRAME_SIZE)
747                 goto end;
748
749         qdev->link_config |=    CFG_JUMBO_FRAME_SIZE;
750         qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
751         status = ql_set_port_cfg(qdev);
752         if (status) {
753                 QPRINTK(qdev, DRV, ERR,
754                         "Bug: Failed to set port config data.\n");
755                 goto err;
756         }
757 end:
758         clear_bit(QL_PORT_CFG, &qdev->flags);
759         return;
760 err:
761         ql_queue_fw_error(qdev);
762         goto end;
763 }
764
765 /* Process an inter-device request.  This is issues by
766  * the firmware in response to another function requesting
767  * a change to the port. We set a flag to indicate a change
768  * has been made and then send a mailbox command ACKing
769  * the change request.
770  */
771 void ql_mpi_idc_work(struct work_struct *work)
772 {
773         struct ql_adapter *qdev =
774             container_of(work, struct ql_adapter, mpi_idc_work.work);
775         int status;
776         struct mbox_params *mbcp = &qdev->idc_mbc;
777         u32 aen;
778
779         aen = mbcp->mbox_out[1] >> 16;
780
781         switch (aen) {
782         default:
783                 QPRINTK(qdev, DRV, ERR,
784                         "Bug: Unhandled IDC action.\n");
785                 break;
786         case MB_CMD_PORT_RESET:
787         case MB_CMD_SET_PORT_CFG:
788         case MB_CMD_STOP_FW:
789                 netif_carrier_off(qdev->ndev);
790                 /* Signal the resulting link up AEN
791                  * that the frame routing and mac addr
792                  * needs to be set.
793                  * */
794                 set_bit(QL_CAM_RT_SET, &qdev->flags);
795                 status = ql_mb_idc_ack(qdev);
796                 if (status) {
797                         QPRINTK(qdev, DRV, ERR,
798                         "Bug: No pending IDC!\n");
799                 }
800         }
801 }
802
803 void ql_mpi_work(struct work_struct *work)
804 {
805         struct ql_adapter *qdev =
806             container_of(work, struct ql_adapter, mpi_work.work);
807         struct mbox_params mbc;
808         struct mbox_params *mbcp = &mbc;
809
810         mutex_lock(&qdev->mpi_mutex);
811
812         while (ql_read32(qdev, STS) & STS_PI) {
813                 memset(mbcp, 0, sizeof(struct mbox_params));
814                 mbcp->out_count = 1;
815                 ql_mpi_handler(qdev, mbcp);
816         }
817
818         mutex_unlock(&qdev->mpi_mutex);
819         ql_enable_completion_interrupt(qdev, 0);
820 }
821
822 void ql_mpi_reset_work(struct work_struct *work)
823 {
824         struct ql_adapter *qdev =
825             container_of(work, struct ql_adapter, mpi_reset_work.work);
826         cancel_delayed_work_sync(&qdev->mpi_work);
827         cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
828         cancel_delayed_work_sync(&qdev->mpi_idc_work);
829         ql_soft_reset_mpi_risc(qdev);
830 }