blob: 2e83c4b8ced44ff4ef013c330406f91c45d9271d [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{
Ron Mercer365da872009-06-07 13:58:29 +000093 int count = 100;
Ron Mercerca0413b2009-03-02 08:07:30 +000094 u32 value;
95
96 do {
97 value = ql_read32(qdev, STS);
98 if (value & STS_PI)
99 return 0;
Ron Mercer365da872009-06-07 13:58:29 +0000100 mdelay(UDELAY_DELAY); /* 100ms */
Ron Mercerca0413b2009-03-02 08:07:30 +0000101 } 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
Martin Olsson98a17082009-04-22 18:21:29 +0200144 * parameters, or loopback mode. We wake up a worker
Ron Mercer2ee1e272009-03-03 12:10:33 +0000145 * 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 Mercer6a473302009-07-02 06:06:12 +0000241 ql_link_on(qdev);
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 Mercer6a473302009-07-02 06:06:12 +0000254 ql_link_off(qdev);
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 Mercerfc1f9ea2009-03-03 12:10:37 +0000287static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp)
288{
289 int status;
290
291 mbcp->out_count = 6;
292
293 status = ql_get_mb_sts(qdev, mbcp);
294 if (status)
295 QPRINTK(qdev, DRV, ERR, "Lost AEN broken!\n");
296 else {
297 int i;
298 QPRINTK(qdev, DRV, ERR, "Lost AEN detected.\n");
299 for (i = 0; i < mbcp->out_count; i++)
300 QPRINTK(qdev, DRV, ERR, "mbox_out[%d] = 0x%.08x.\n",
301 i, mbcp->mbox_out[i]);
302
303 }
304
305 return status;
306}
307
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400308static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
309{
Ron Mercerf56b54f2009-03-03 12:10:34 +0000310 int status;
311
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400312 mbcp->out_count = 2;
313
Ron Mercerf56b54f2009-03-03 12:10:34 +0000314 status = ql_get_mb_sts(qdev, mbcp);
315 if (status) {
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400316 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
Ron Mercerf56b54f2009-03-03 12:10:34 +0000317 } else {
318 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
319 mbcp->mbox_out[1]);
320 status = ql_cam_route_initialize(qdev);
321 if (status)
322 QPRINTK(qdev, IFUP, ERR,
323 "Failed to init CAM/Routing tables.\n");
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400324 }
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400325}
326
Ron Mercer125844e2009-02-26 10:08:34 +0000327/* Process an async event and clear it unless it's an
328 * error condition.
329 * This can get called iteratively from the mpi_work thread
330 * when events arrive via an interrupt.
331 * It also gets called when a mailbox command is polling for
332 * it's completion. */
333static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
334{
335 int status;
Ron Mercerca0413b2009-03-02 08:07:30 +0000336 int orig_count = mbcp->out_count;
Ron Mercer125844e2009-02-26 10:08:34 +0000337
338 /* Just get mailbox zero for now. */
339 mbcp->out_count = 1;
340 status = ql_get_mb_sts(qdev, mbcp);
341 if (status) {
342 QPRINTK(qdev, DRV, ERR,
343 "Could not read MPI, resetting ASIC!\n");
344 ql_queue_asic_error(qdev);
345 goto end;
346 }
347
348 switch (mbcp->mbox_out[0]) {
349
Ron Mercerca0413b2009-03-02 08:07:30 +0000350 /* This case is only active when we arrive here
351 * as a result of issuing a mailbox command to
352 * the firmware.
353 */
354 case MB_CMD_STS_INTRMDT:
355 case MB_CMD_STS_GOOD:
356 case MB_CMD_STS_INVLD_CMD:
357 case MB_CMD_STS_XFC_ERR:
358 case MB_CMD_STS_CSUM_ERR:
359 case MB_CMD_STS_ERR:
360 case MB_CMD_STS_PARAM_ERR:
361 /* We can only get mailbox status if we're polling from an
362 * unfinished command. Get the rest of the status data and
363 * return back to the caller.
364 * We only end up here when we're polling for a mailbox
365 * command completion.
366 */
367 mbcp->out_count = orig_count;
368 status = ql_get_mb_sts(qdev, mbcp);
369 return status;
370
Ron Mercer2ee1e272009-03-03 12:10:33 +0000371 /* We are being asked by firmware to accept
372 * a change to the port. This is only
373 * a change to max frame sizes (Tx/Rx), pause
Martin Olsson98a17082009-04-22 18:21:29 +0200374 * parameters, or loopback mode.
Ron Mercer2ee1e272009-03-03 12:10:33 +0000375 */
376 case AEN_IDC_REQ:
377 status = ql_idc_req_aen(qdev);
378 break;
379
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000380 /* Process and inbound IDC event.
381 * This will happen when we're trying to
382 * change tx/rx max frame size, change pause
Martin Olsson98a17082009-04-22 18:21:29 +0200383 * parameters or loopback mode.
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000384 */
385 case AEN_IDC_CMPLT:
386 case AEN_IDC_EXT:
387 status = ql_idc_cmplt_aen(qdev);
388 break;
389
Ron Mercer125844e2009-02-26 10:08:34 +0000390 case AEN_LINK_UP:
391 ql_link_up(qdev, mbcp);
392 break;
393
394 case AEN_LINK_DOWN:
395 ql_link_down(qdev, mbcp);
396 break;
397
398 case AEN_FW_INIT_DONE:
Ron Mercerf56b54f2009-03-03 12:10:34 +0000399 /* If we're in process on executing the firmware,
400 * then convert the status to normal mailbox status.
401 */
402 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
403 mbcp->out_count = orig_count;
404 status = ql_get_mb_sts(qdev, mbcp);
405 mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
406 return status;
407 }
Ron Mercer125844e2009-02-26 10:08:34 +0000408 ql_init_fw_done(qdev, mbcp);
409 break;
410
Ron Mercereae6b582009-03-03 12:10:30 +0000411 case AEN_AEN_SFP_IN:
412 ql_sfp_in(qdev, mbcp);
413 break;
414
415 case AEN_AEN_SFP_OUT:
416 ql_sfp_out(qdev, mbcp);
417 break;
418
Ron Mercer7c921912009-03-03 12:10:35 +0000419 /* This event can arrive at boot time or after an
420 * MPI reset if the firmware failed to initialize.
421 */
Ron Mercer125844e2009-02-26 10:08:34 +0000422 case AEN_FW_INIT_FAIL:
Ron Mercer7c921912009-03-03 12:10:35 +0000423 /* If we're in process on executing the firmware,
424 * then convert the status to normal mailbox status.
425 */
426 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
427 mbcp->out_count = orig_count;
428 status = ql_get_mb_sts(qdev, mbcp);
429 mbcp->mbox_out[0] = MB_CMD_STS_ERR;
430 return status;
431 }
432 QPRINTK(qdev, DRV, ERR,
433 "Firmware initialization failed.\n");
434 status = -EIO;
435 ql_queue_fw_error(qdev);
436 break;
437
Ron Mercer125844e2009-02-26 10:08:34 +0000438 case AEN_SYS_ERR:
Ron Mercerbb667672009-03-03 12:10:36 +0000439 QPRINTK(qdev, DRV, ERR,
440 "System Error.\n");
Ron Mercer125844e2009-02-26 10:08:34 +0000441 ql_queue_fw_error(qdev);
Ron Mercerbb667672009-03-03 12:10:36 +0000442 status = -EIO;
Ron Mercer125844e2009-02-26 10:08:34 +0000443 break;
444
Ron Mercerfc1f9ea2009-03-03 12:10:37 +0000445 case AEN_AEN_LOST:
446 ql_aen_lost(qdev, mbcp);
447 break;
448
Ron Mercer91ced682009-10-10 09:35:05 +0000449 case AEN_DCBX_CHG:
450 /* Need to support AEN 8110 */
451 break;
Ron Mercer125844e2009-02-26 10:08:34 +0000452 default:
453 QPRINTK(qdev, DRV, ERR,
454 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
455 /* Clear the MPI firmware status. */
456 }
457end:
458 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
Ron Mercer709ac4f2009-06-07 13:58:26 +0000459 /* Restore the original mailbox count to
460 * what the caller asked for. This can get
461 * changed when a mailbox command is waiting
462 * for a response and an AEN arrives and
463 * is handled.
464 * */
465 mbcp->out_count = orig_count;
Ron Mercer125844e2009-02-26 10:08:34 +0000466 return status;
467}
468
Ron Mercerca0413b2009-03-02 08:07:30 +0000469/* Execute a single mailbox command.
470 * mbcp is a pointer to an array of u32. Each
471 * element in the array contains the value for it's
472 * respective mailbox register.
473 */
474static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
475{
476 int status, count;
477
Ron Mercerca0413b2009-03-02 08:07:30 +0000478
479 /* Begin polled mode for MPI */
480 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
481
482 /* Load the mailbox registers and wake up MPI RISC. */
483 status = ql_exec_mb_cmd(qdev, mbcp);
484 if (status)
485 goto end;
486
487
488 /* If we're generating a system error, then there's nothing
489 * to wait for.
490 */
491 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
492 goto end;
493
494 /* Wait for the command to complete. We loop
495 * here because some AEN might arrive while
496 * we're waiting for the mailbox command to
497 * complete. If more than 5 arrive then we can
498 * assume something is wrong. */
499 count = 5;
500 do {
501 /* Wait for the interrupt to come in. */
502 status = ql_wait_mbx_cmd_cmplt(qdev);
503 if (status)
504 goto end;
505
506 /* Process the event. If it's an AEN, it
507 * will be handled in-line or a worker
508 * will be spawned. If it's our completion
509 * we will catch it below.
510 */
511 status = ql_mpi_handler(qdev, mbcp);
512 if (status)
513 goto end;
514
515 /* It's either the completion for our mailbox
516 * command complete or an AEN. If it's our
517 * completion then get out.
518 */
519 if (((mbcp->mbox_out[0] & 0x0000f000) ==
520 MB_CMD_STS_GOOD) ||
521 ((mbcp->mbox_out[0] & 0x0000f000) ==
522 MB_CMD_STS_INTRMDT))
523 break;
524 } while (--count);
525
526 if (!count) {
527 QPRINTK(qdev, DRV, ERR,
528 "Timed out waiting for mailbox complete.\n");
529 status = -ETIMEDOUT;
530 goto end;
531 }
532
533 /* Now we can clear the interrupt condition
534 * and look at our status.
535 */
536 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
537
538 if (((mbcp->mbox_out[0] & 0x0000f000) !=
539 MB_CMD_STS_GOOD) &&
540 ((mbcp->mbox_out[0] & 0x0000f000) !=
541 MB_CMD_STS_INTRMDT)) {
542 ql_display_mb_sts(qdev, mbcp);
543 status = -EIO;
544 }
545end:
Ron Mercerca0413b2009-03-02 08:07:30 +0000546 /* End polled mode for MPI */
547 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
548 return status;
549}
550
Ron Mercercfec0cb2009-06-09 05:39:29 +0000551
552/* Get MPI firmware version. This will be used for
553 * driver banner and for ethtool info.
554 * Returns zero on success.
555 */
556int ql_mb_about_fw(struct ql_adapter *qdev)
557{
558 struct mbox_params mbc;
559 struct mbox_params *mbcp = &mbc;
560 int status = 0;
561
562 memset(mbcp, 0, sizeof(struct mbox_params));
563
564 mbcp->in_count = 1;
565 mbcp->out_count = 3;
566
567 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
568
569 status = ql_mailbox_command(qdev, mbcp);
570 if (status)
571 return status;
572
573 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
574 QPRINTK(qdev, DRV, ERR,
575 "Failed about firmware command\n");
576 status = -EIO;
577 }
578
579 /* Store the firmware version */
580 qdev->fw_rev_id = mbcp->mbox_out[1];
581
582 return status;
583}
584
Ron Mercerca0413b2009-03-02 08:07:30 +0000585/* Get functional state for MPI firmware.
586 * Returns zero on success.
587 */
588int ql_mb_get_fw_state(struct ql_adapter *qdev)
589{
590 struct mbox_params mbc;
591 struct mbox_params *mbcp = &mbc;
592 int status = 0;
593
594 memset(mbcp, 0, sizeof(struct mbox_params));
595
596 mbcp->in_count = 1;
597 mbcp->out_count = 2;
598
599 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
600
601 status = ql_mailbox_command(qdev, mbcp);
602 if (status)
603 return status;
604
605 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
606 QPRINTK(qdev, DRV, ERR,
607 "Failed Get Firmware State.\n");
608 status = -EIO;
609 }
610
611 /* If bit zero is set in mbx 1 then the firmware is
612 * running, but not initialized. This should never
613 * happen.
614 */
615 if (mbcp->mbox_out[1] & 1) {
616 QPRINTK(qdev, DRV, ERR,
617 "Firmware waiting for initialization.\n");
618 status = -EIO;
619 }
620
621 return status;
622}
623
Ron Mercer2ee1e272009-03-03 12:10:33 +0000624/* Send and ACK mailbox command to the firmware to
625 * let it continue with the change.
626 */
627int ql_mb_idc_ack(struct ql_adapter *qdev)
628{
629 struct mbox_params mbc;
630 struct mbox_params *mbcp = &mbc;
631 int status = 0;
632
633 memset(mbcp, 0, sizeof(struct mbox_params));
634
635 mbcp->in_count = 5;
636 mbcp->out_count = 1;
637
638 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
639 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
640 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
641 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
642 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
643
644 status = ql_mailbox_command(qdev, mbcp);
645 if (status)
646 return status;
647
648 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
649 QPRINTK(qdev, DRV, ERR,
650 "Failed IDC ACK send.\n");
651 status = -EIO;
652 }
653 return status;
654}
655
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000656/* Get link settings and maximum frame size settings
657 * for the current port.
658 * Most likely will block.
659 */
660static int ql_mb_set_port_cfg(struct ql_adapter *qdev)
661{
662 struct mbox_params mbc;
663 struct mbox_params *mbcp = &mbc;
664 int status = 0;
665
666 memset(mbcp, 0, sizeof(struct mbox_params));
667
668 mbcp->in_count = 3;
669 mbcp->out_count = 1;
670
671 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
672 mbcp->mbox_in[1] = qdev->link_config;
673 mbcp->mbox_in[2] = qdev->max_frame_size;
674
675
676 status = ql_mailbox_command(qdev, mbcp);
677 if (status)
678 return status;
679
680 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
681 QPRINTK(qdev, DRV, ERR,
682 "Port Config sent, wait for IDC.\n");
683 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
684 QPRINTK(qdev, DRV, ERR,
685 "Failed Set Port Configuration.\n");
686 status = -EIO;
687 }
688 return status;
689}
690
691/* Get link settings and maximum frame size settings
692 * for the current port.
693 * Most likely will block.
694 */
695static int ql_mb_get_port_cfg(struct ql_adapter *qdev)
696{
697 struct mbox_params mbc;
698 struct mbox_params *mbcp = &mbc;
699 int status = 0;
700
701 memset(mbcp, 0, sizeof(struct mbox_params));
702
703 mbcp->in_count = 1;
704 mbcp->out_count = 3;
705
706 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
707
708 status = ql_mailbox_command(qdev, mbcp);
709 if (status)
710 return status;
711
712 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
713 QPRINTK(qdev, DRV, ERR,
714 "Failed Get Port Configuration.\n");
715 status = -EIO;
716 } else {
717 QPRINTK(qdev, DRV, DEBUG,
718 "Passed Get Port Configuration.\n");
719 qdev->link_config = mbcp->mbox_out[1];
720 qdev->max_frame_size = mbcp->mbox_out[2];
721 }
722 return status;
723}
724
725/* IDC - Inter Device Communication...
726 * Some firmware commands require consent of adjacent FCOE
727 * function. This function waits for the OK, or a
728 * counter-request for a little more time.i
729 * The firmware will complete the request if the other
730 * function doesn't respond.
731 */
732static int ql_idc_wait(struct ql_adapter *qdev)
733{
734 int status = -ETIMEDOUT;
735 long wait_time = 1 * HZ;
736 struct mbox_params *mbcp = &qdev->idc_mbc;
737 do {
738 /* Wait here for the command to complete
739 * via the IDC process.
740 */
741 wait_time =
742 wait_for_completion_timeout(&qdev->ide_completion,
743 wait_time);
744 if (!wait_time) {
745 QPRINTK(qdev, DRV, ERR,
746 "IDC Timeout.\n");
747 break;
748 }
749 /* Now examine the response from the IDC process.
750 * We might have a good completion or a request for
751 * more wait time.
752 */
753 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
754 QPRINTK(qdev, DRV, ERR,
755 "IDC Time Extension from function.\n");
756 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
757 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
758 QPRINTK(qdev, DRV, ERR,
759 "IDC Success.\n");
760 status = 0;
761 break;
762 } else {
763 QPRINTK(qdev, DRV, ERR,
764 "IDC: Invalid State 0x%.04x.\n",
765 mbcp->mbox_out[0]);
766 status = -EIO;
767 break;
768 }
769 } while (wait_time);
770
771 return status;
772}
773
Ron Mercer84087f42009-10-08 09:54:41 +0000774int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
775{
776 struct mbox_params mbc;
777 struct mbox_params *mbcp = &mbc;
778 int status;
779
780 memset(mbcp, 0, sizeof(struct mbox_params));
781
782 mbcp->in_count = 1;
783 mbcp->out_count = 2;
784
785 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
786 mbcp->mbox_in[1] = control;
787
788 status = ql_mailbox_command(qdev, mbcp);
789 if (status)
790 return status;
791
792 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
793 return status;
794
795 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
796 QPRINTK(qdev, DRV, ERR,
797 "Command not supported by firmware.\n");
798 status = -EINVAL;
799 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
800 /* This indicates that the firmware is
801 * already in the state we are trying to
802 * change it to.
803 */
804 QPRINTK(qdev, DRV, ERR,
805 "Command parameters make no change.\n");
806 }
807 return status;
808}
809
810/* Returns a negative error code or the mailbox command status. */
811static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
812{
813 struct mbox_params mbc;
814 struct mbox_params *mbcp = &mbc;
815 int status;
816
817 memset(mbcp, 0, sizeof(struct mbox_params));
818 *control = 0;
819
820 mbcp->in_count = 1;
821 mbcp->out_count = 1;
822
823 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
824
825 status = ql_mailbox_command(qdev, mbcp);
826 if (status)
827 return status;
828
829 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
830 *control = mbcp->mbox_in[1];
831 return status;
832 }
833
834 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
835 QPRINTK(qdev, DRV, ERR,
836 "Command not supported by firmware.\n");
837 status = -EINVAL;
838 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
839 QPRINTK(qdev, DRV, ERR,
840 "Failed to get MPI traffic control.\n");
841 status = -EIO;
842 }
843 return status;
844}
845
846int ql_wait_fifo_empty(struct ql_adapter *qdev)
847{
848 int count = 5;
849 u32 mgmnt_fifo_empty;
850 u32 nic_fifo_empty;
851
852 do {
853 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
854 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
855 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
856 if (nic_fifo_empty && mgmnt_fifo_empty)
857 return 0;
858 msleep(100);
859 } while (count-- > 0);
860 return -ETIMEDOUT;
861}
862
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000863/* API called in work thread context to set new TX/RX
864 * maximum frame size values to match MTU.
865 */
866static int ql_set_port_cfg(struct ql_adapter *qdev)
867{
868 int status;
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000869 rtnl_lock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000870 status = ql_mb_set_port_cfg(qdev);
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000871 rtnl_unlock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000872 if (status)
873 return status;
874 status = ql_idc_wait(qdev);
875 return status;
876}
877
878/* The following routines are worker threads that process
879 * events that may sleep waiting for completion.
880 */
881
882/* This thread gets the maximum TX and RX frame size values
883 * from the firmware and, if necessary, changes them to match
884 * the MTU setting.
885 */
886void ql_mpi_port_cfg_work(struct work_struct *work)
887{
888 struct ql_adapter *qdev =
889 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000890 int status;
891
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000892 rtnl_lock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000893 status = ql_mb_get_port_cfg(qdev);
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000894 rtnl_unlock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000895 if (status) {
896 QPRINTK(qdev, DRV, ERR,
897 "Bug: Failed to get port config data.\n");
898 goto err;
899 }
900
Ron Mercerc8269b22009-06-07 13:58:27 +0000901 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000902 qdev->max_frame_size ==
903 CFG_DEFAULT_MAX_FRAME_SIZE)
904 goto end;
905
906 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
907 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
908 status = ql_set_port_cfg(qdev);
909 if (status) {
910 QPRINTK(qdev, DRV, ERR,
911 "Bug: Failed to set port config data.\n");
912 goto err;
913 }
914end:
915 clear_bit(QL_PORT_CFG, &qdev->flags);
916 return;
917err:
918 ql_queue_fw_error(qdev);
919 goto end;
920}
921
Ron Mercer2ee1e272009-03-03 12:10:33 +0000922/* Process an inter-device request. This is issues by
923 * the firmware in response to another function requesting
924 * a change to the port. We set a flag to indicate a change
925 * has been made and then send a mailbox command ACKing
926 * the change request.
927 */
928void ql_mpi_idc_work(struct work_struct *work)
929{
930 struct ql_adapter *qdev =
931 container_of(work, struct ql_adapter, mpi_idc_work.work);
932 int status;
933 struct mbox_params *mbcp = &qdev->idc_mbc;
934 u32 aen;
935
936 aen = mbcp->mbox_out[1] >> 16;
937
938 switch (aen) {
939 default:
940 QPRINTK(qdev, DRV, ERR,
941 "Bug: Unhandled IDC action.\n");
942 break;
943 case MB_CMD_PORT_RESET:
944 case MB_CMD_SET_PORT_CFG:
945 case MB_CMD_STOP_FW:
Ron Mercer6a473302009-07-02 06:06:12 +0000946 ql_link_off(qdev);
Ron Mercer2ee1e272009-03-03 12:10:33 +0000947 /* Signal the resulting link up AEN
948 * that the frame routing and mac addr
949 * needs to be set.
950 * */
951 set_bit(QL_CAM_RT_SET, &qdev->flags);
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000952 rtnl_lock();
Ron Mercer2ee1e272009-03-03 12:10:33 +0000953 status = ql_mb_idc_ack(qdev);
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000954 rtnl_unlock();
Ron Mercer2ee1e272009-03-03 12:10:33 +0000955 if (status) {
956 QPRINTK(qdev, DRV, ERR,
957 "Bug: No pending IDC!\n");
958 }
959 }
960}
961
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400962void ql_mpi_work(struct work_struct *work)
963{
964 struct ql_adapter *qdev =
965 container_of(work, struct ql_adapter, mpi_work.work);
966 struct mbox_params mbc;
967 struct mbox_params *mbcp = &mbc;
Ron Mercerd6f58c22009-06-07 13:58:25 +0000968 int err = 0;
Ron Mercer125844e2009-02-26 10:08:34 +0000969
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000970 rtnl_lock();
Ron Mercerefd7d262009-10-08 09:54:43 +0000971 /* Begin polled mode for MPI */
972 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400973
974 while (ql_read32(qdev, STS) & STS_PI) {
Ron Mercer125844e2009-02-26 10:08:34 +0000975 memset(mbcp, 0, sizeof(struct mbox_params));
976 mbcp->out_count = 1;
Ron Mercerd6f58c22009-06-07 13:58:25 +0000977 /* Don't continue if an async event
978 * did not complete properly.
979 */
980 err = ql_mpi_handler(qdev, mbcp);
981 if (err)
982 break;
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400983 }
Ron Mercer125844e2009-02-26 10:08:34 +0000984
Ron Mercerefd7d262009-10-08 09:54:43 +0000985 /* End polled mode for MPI */
986 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
Ron Mercer86aaf9a2009-10-05 11:46:49 +0000987 rtnl_unlock();
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400988 ql_enable_completion_interrupt(qdev, 0);
989}
990
991void ql_mpi_reset_work(struct work_struct *work)
992{
993 struct ql_adapter *qdev =
994 container_of(work, struct ql_adapter, mpi_reset_work.work);
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000995 cancel_delayed_work_sync(&qdev->mpi_work);
996 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
Ron Mercer2ee1e272009-03-03 12:10:33 +0000997 cancel_delayed_work_sync(&qdev->mpi_idc_work);
Ron Mercera2e809b2009-02-26 10:08:33 +0000998 ql_soft_reset_mpi_risc(qdev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400999}