blob: 9f1fe542e2712da747770989dc87edf9f9650aa1 [file] [log] [blame]
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001#include "qlge.h"
2
Ron Mercerca0413b2009-03-02 08:07:30 +00003static 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
Ron Mercera2e809b2009-02-26 10:08:33 +000023int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
Ron Mercerc4e84bd2008-09-18 11:56:28 -040024{
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);
38exit:
39 return status;
40}
41
Ron Mercera2e809b2009-02-26 10:08:33 +000042int 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;
57exit:
58 return status;
59}
60
61int 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
Hannes Eder2f22d222008-12-26 00:04:53 -080068static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
Ron Mercerc4e84bd2008-09-18 11:56:28 -040069{
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 =
Ron Mercera2e809b2009-02-26 10:08:33 +000077 ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
Ron Mercerc4e84bd2008-09-18 11:56:28 -040078 &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
Ron Mercerca0413b2009-03-02 08:07:30 +000088/* Wait for a single mailbox command to complete.
89 * Returns zero on success.
90 */
91static 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 */
108static 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);
136end:
137 ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
138 return status;
139}
140
Ron Mercer2ee1e272009-03-03 12:10:33 +0000141/* 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 */
148static 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
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000175/* Process an inter-device event completion.
176 * If good, signal the caller's completion.
177 */
178static 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}
Ron Mercer5700abe2009-03-03 12:10:32 +0000196
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400197static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
198{
Ron Mercer5700abe2009-03-03 12:10:32 +0000199 int status;
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400200 mbcp->out_count = 2;
201
Ron Mercer5700abe2009-03-03 12:10:32 +0000202 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 }
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400208
209 qdev->link_status = mbcp->mbox_out[1];
210 QPRINTK(qdev, DRV, ERR, "Link Up.\n");
Ron Mercer5700abe2009-03-03 12:10:32 +0000211
Ron Mercer2ee1e272009-03-03 12:10:33 +0000212 /* 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
Ron Mercer5700abe2009-03-03 12:10:32 +0000241 netif_carrier_on(qdev->ndev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400242}
243
244static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
245{
Ron Mercer11d9fe62009-03-03 12:10:31 +0000246 int status;
247
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400248 mbcp->out_count = 3;
249
Ron Mercer11d9fe62009-03-03 12:10:31 +0000250 status = ql_get_mb_sts(qdev, mbcp);
251 if (status)
252 QPRINTK(qdev, DRV, ERR, "Link down AEN broken!\n");
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400253
Ron Mercer11d9fe62009-03-03 12:10:31 +0000254 netif_carrier_off(qdev->ndev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400255}
256
Ron Mercereae6b582009-03-03 12:10:30 +0000257static 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
272static 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
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400287static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
288{
289 mbcp->out_count = 2;
290
291 if (ql_get_mb_sts(qdev, mbcp)) {
292 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
293 goto exit;
294 }
295 QPRINTK(qdev, DRV, ERR, "Firmware initialized!\n");
296 QPRINTK(qdev, DRV, ERR, "Firmware status = 0x%.08x.\n",
297 mbcp->mbox_out[0]);
298 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
299 mbcp->mbox_out[1]);
300exit:
301 /* Clear the MPI firmware status. */
302 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
303}
304
Ron Mercer125844e2009-02-26 10:08:34 +0000305/* Process an async event and clear it unless it's an
306 * error condition.
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. */
311static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
312{
313 int status;
Ron Mercerca0413b2009-03-02 08:07:30 +0000314 int orig_count = mbcp->out_count;
Ron Mercer125844e2009-02-26 10:08:34 +0000315
316 /* Just get mailbox zero for now. */
317 mbcp->out_count = 1;
318 status = ql_get_mb_sts(qdev, mbcp);
319 if (status) {
320 QPRINTK(qdev, DRV, ERR,
321 "Could not read MPI, resetting ASIC!\n");
322 ql_queue_asic_error(qdev);
323 goto end;
324 }
325
326 switch (mbcp->mbox_out[0]) {
327
Ron Mercerca0413b2009-03-02 08:07:30 +0000328 /* This case is only active when we arrive here
329 * as a result of issuing a mailbox command to
330 * the firmware.
331 */
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:
337 case MB_CMD_STS_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.
344 */
345 mbcp->out_count = orig_count;
346 status = ql_get_mb_sts(qdev, mbcp);
347 return status;
348
Ron Mercer2ee1e272009-03-03 12:10:33 +0000349 /* 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.
353 */
354 case AEN_IDC_REQ:
355 status = ql_idc_req_aen(qdev);
356 break;
357
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000358 /* 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.
362 */
363 case AEN_IDC_CMPLT:
364 case AEN_IDC_EXT:
365 status = ql_idc_cmplt_aen(qdev);
366 break;
367
Ron Mercer125844e2009-02-26 10:08:34 +0000368 case AEN_LINK_UP:
369 ql_link_up(qdev, mbcp);
370 break;
371
372 case AEN_LINK_DOWN:
373 ql_link_down(qdev, mbcp);
374 break;
375
376 case AEN_FW_INIT_DONE:
377 ql_init_fw_done(qdev, mbcp);
378 break;
379
Ron Mercereae6b582009-03-03 12:10:30 +0000380 case AEN_AEN_SFP_IN:
381 ql_sfp_in(qdev, mbcp);
382 break;
383
384 case AEN_AEN_SFP_OUT:
385 ql_sfp_out(qdev, mbcp);
386 break;
387
Ron Mercer125844e2009-02-26 10:08:34 +0000388 case AEN_FW_INIT_FAIL:
389 case AEN_SYS_ERR:
Ron Mercer125844e2009-02-26 10:08:34 +0000390 ql_queue_fw_error(qdev);
391 break;
392
393 default:
394 QPRINTK(qdev, DRV, ERR,
395 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
396 /* Clear the MPI firmware status. */
397 }
398end:
399 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
400 return status;
401}
402
Ron Mercerca0413b2009-03-02 08:07:30 +0000403/* 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.
407 */
408static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
409{
410 int status, count;
411
412 mutex_lock(&qdev->mpi_mutex);
413
414 /* Begin polled mode for MPI */
415 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
416
417 /* Load the mailbox registers and wake up MPI RISC. */
418 status = ql_exec_mb_cmd(qdev, mbcp);
419 if (status)
420 goto end;
421
422
423 /* If we're generating a system error, then there's nothing
424 * to wait for.
425 */
426 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
427 goto end;
428
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. */
434 count = 5;
435 do {
436 /* Wait for the interrupt to come in. */
437 status = ql_wait_mbx_cmd_cmplt(qdev);
438 if (status)
439 goto end;
440
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.
445 */
446 status = ql_mpi_handler(qdev, mbcp);
447 if (status)
448 goto end;
449
450 /* It's either the completion for our mailbox
451 * command complete or an AEN. If it's our
452 * completion then get out.
453 */
454 if (((mbcp->mbox_out[0] & 0x0000f000) ==
455 MB_CMD_STS_GOOD) ||
456 ((mbcp->mbox_out[0] & 0x0000f000) ==
457 MB_CMD_STS_INTRMDT))
458 break;
459 } while (--count);
460
461 if (!count) {
462 QPRINTK(qdev, DRV, ERR,
463 "Timed out waiting for mailbox complete.\n");
464 status = -ETIMEDOUT;
465 goto end;
466 }
467
468 /* Now we can clear the interrupt condition
469 * and look at our status.
470 */
471 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
472
473 if (((mbcp->mbox_out[0] & 0x0000f000) !=
474 MB_CMD_STS_GOOD) &&
475 ((mbcp->mbox_out[0] & 0x0000f000) !=
476 MB_CMD_STS_INTRMDT)) {
477 ql_display_mb_sts(qdev, mbcp);
478 status = -EIO;
479 }
480end:
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);
484 return status;
485}
486
487/* Get functional state for MPI firmware.
488 * Returns zero on success.
489 */
490int ql_mb_get_fw_state(struct ql_adapter *qdev)
491{
492 struct mbox_params mbc;
493 struct mbox_params *mbcp = &mbc;
494 int status = 0;
495
496 memset(mbcp, 0, sizeof(struct mbox_params));
497
498 mbcp->in_count = 1;
499 mbcp->out_count = 2;
500
501 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
502
503 status = ql_mailbox_command(qdev, mbcp);
504 if (status)
505 return status;
506
507 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
508 QPRINTK(qdev, DRV, ERR,
509 "Failed Get Firmware State.\n");
510 status = -EIO;
511 }
512
513 /* If bit zero is set in mbx 1 then the firmware is
514 * running, but not initialized. This should never
515 * happen.
516 */
517 if (mbcp->mbox_out[1] & 1) {
518 QPRINTK(qdev, DRV, ERR,
519 "Firmware waiting for initialization.\n");
520 status = -EIO;
521 }
522
523 return status;
524}
525
Ron Mercer2ee1e272009-03-03 12:10:33 +0000526/* Send and ACK mailbox command to the firmware to
527 * let it continue with the change.
528 */
529int ql_mb_idc_ack(struct ql_adapter *qdev)
530{
531 struct mbox_params mbc;
532 struct mbox_params *mbcp = &mbc;
533 int status = 0;
534
535 memset(mbcp, 0, sizeof(struct mbox_params));
536
537 mbcp->in_count = 5;
538 mbcp->out_count = 1;
539
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];
545
546 status = ql_mailbox_command(qdev, mbcp);
547 if (status)
548 return status;
549
550 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
551 QPRINTK(qdev, DRV, ERR,
552 "Failed IDC ACK send.\n");
553 status = -EIO;
554 }
555 return status;
556}
557
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000558/* Get link settings and maximum frame size settings
559 * for the current port.
560 * Most likely will block.
561 */
562static int ql_mb_set_port_cfg(struct ql_adapter *qdev)
563{
564 struct mbox_params mbc;
565 struct mbox_params *mbcp = &mbc;
566 int status = 0;
567
568 memset(mbcp, 0, sizeof(struct mbox_params));
569
570 mbcp->in_count = 3;
571 mbcp->out_count = 1;
572
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;
576
577
578 status = ql_mailbox_command(qdev, mbcp);
579 if (status)
580 return status;
581
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");
588 status = -EIO;
589 }
590 return status;
591}
592
593/* Get link settings and maximum frame size settings
594 * for the current port.
595 * Most likely will block.
596 */
597static int ql_mb_get_port_cfg(struct ql_adapter *qdev)
598{
599 struct mbox_params mbc;
600 struct mbox_params *mbcp = &mbc;
601 int status = 0;
602
603 memset(mbcp, 0, sizeof(struct mbox_params));
604
605 mbcp->in_count = 1;
606 mbcp->out_count = 3;
607
608 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
609
610 status = ql_mailbox_command(qdev, mbcp);
611 if (status)
612 return status;
613
614 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
615 QPRINTK(qdev, DRV, ERR,
616 "Failed Get Port Configuration.\n");
617 status = -EIO;
618 } else {
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];
623 }
624 return status;
625}
626
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.
633 */
634static int ql_idc_wait(struct ql_adapter *qdev)
635{
636 int status = -ETIMEDOUT;
637 long wait_time = 1 * HZ;
638 struct mbox_params *mbcp = &qdev->idc_mbc;
639 do {
640 /* Wait here for the command to complete
641 * via the IDC process.
642 */
643 wait_time =
644 wait_for_completion_timeout(&qdev->ide_completion,
645 wait_time);
646 if (!wait_time) {
647 QPRINTK(qdev, DRV, ERR,
648 "IDC Timeout.\n");
649 break;
650 }
651 /* Now examine the response from the IDC process.
652 * We might have a good completion or a request for
653 * more wait time.
654 */
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,
661 "IDC Success.\n");
662 status = 0;
663 break;
664 } else {
665 QPRINTK(qdev, DRV, ERR,
666 "IDC: Invalid State 0x%.04x.\n",
667 mbcp->mbox_out[0]);
668 status = -EIO;
669 break;
670 }
671 } while (wait_time);
672
673 return status;
674}
675
676/* API called in work thread context to set new TX/RX
677 * maximum frame size values to match MTU.
678 */
679static int ql_set_port_cfg(struct ql_adapter *qdev)
680{
681 int status;
682 status = ql_mb_set_port_cfg(qdev);
683 if (status)
684 return status;
685 status = ql_idc_wait(qdev);
686 return status;
687}
688
689/* The following routines are worker threads that process
690 * events that may sleep waiting for completion.
691 */
692
693/* This thread gets the maximum TX and RX frame size values
694 * from the firmware and, if necessary, changes them to match
695 * the MTU setting.
696 */
697void ql_mpi_port_cfg_work(struct work_struct *work)
698{
699 struct ql_adapter *qdev =
700 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
701 struct net_device *ndev = qdev->ndev;
702 int status;
703
704 status = ql_mb_get_port_cfg(qdev);
705 if (status) {
706 QPRINTK(qdev, DRV, ERR,
707 "Bug: Failed to get port config data.\n");
708 goto err;
709 }
710
711 if (ndev->mtu <= 2500)
712 goto end;
713 else if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
714 qdev->max_frame_size ==
715 CFG_DEFAULT_MAX_FRAME_SIZE)
716 goto end;
717
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);
721 if (status) {
722 QPRINTK(qdev, DRV, ERR,
723 "Bug: Failed to set port config data.\n");
724 goto err;
725 }
726end:
727 clear_bit(QL_PORT_CFG, &qdev->flags);
728 return;
729err:
730 ql_queue_fw_error(qdev);
731 goto end;
732}
733
Ron Mercer2ee1e272009-03-03 12:10:33 +0000734/* 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.
739 */
740void ql_mpi_idc_work(struct work_struct *work)
741{
742 struct ql_adapter *qdev =
743 container_of(work, struct ql_adapter, mpi_idc_work.work);
744 int status;
745 struct mbox_params *mbcp = &qdev->idc_mbc;
746 u32 aen;
747
748 aen = mbcp->mbox_out[1] >> 16;
749
750 switch (aen) {
751 default:
752 QPRINTK(qdev, DRV, ERR,
753 "Bug: Unhandled IDC action.\n");
754 break;
755 case MB_CMD_PORT_RESET:
756 case MB_CMD_SET_PORT_CFG:
757 case MB_CMD_STOP_FW:
758 netif_carrier_off(qdev->ndev);
759 /* Signal the resulting link up AEN
760 * that the frame routing and mac addr
761 * needs to be set.
762 * */
763 set_bit(QL_CAM_RT_SET, &qdev->flags);
764 status = ql_mb_idc_ack(qdev);
765 if (status) {
766 QPRINTK(qdev, DRV, ERR,
767 "Bug: No pending IDC!\n");
768 }
769 }
770}
771
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400772void ql_mpi_work(struct work_struct *work)
773{
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;
Ron Mercer125844e2009-02-26 10:08:34 +0000778
779 mutex_lock(&qdev->mpi_mutex);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400780
781 while (ql_read32(qdev, STS) & STS_PI) {
Ron Mercer125844e2009-02-26 10:08:34 +0000782 memset(mbcp, 0, sizeof(struct mbox_params));
783 mbcp->out_count = 1;
784 ql_mpi_handler(qdev, mbcp);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400785 }
Ron Mercer125844e2009-02-26 10:08:34 +0000786
787 mutex_unlock(&qdev->mpi_mutex);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400788 ql_enable_completion_interrupt(qdev, 0);
789}
790
791void ql_mpi_reset_work(struct work_struct *work)
792{
793 struct ql_adapter *qdev =
794 container_of(work, struct ql_adapter, mpi_reset_work.work);
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000795 cancel_delayed_work_sync(&qdev->mpi_work);
796 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
Ron Mercer2ee1e272009-03-03 12:10:33 +0000797 cancel_delayed_work_sync(&qdev->mpi_idc_work);
Ron Mercera2e809b2009-02-26 10:08:33 +0000798 ql_soft_reset_mpi_risc(qdev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400799}