blob: e2c846f17fc7616515d5f06a29fab48b15d98bc3 [file] [log] [blame]
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001#include "qlge.h"
2
Ron Mercer8aae2602010-01-15 13:31:28 +00003int ql_unpause_mpi_risc(struct ql_adapter *qdev)
4{
5 u32 tmp;
6
7 /* Un-pause the RISC */
8 tmp = ql_read32(qdev, CSR);
9 if (!(tmp & CSR_RP))
10 return -EIO;
11
12 ql_write32(qdev, CSR, CSR_CMD_CLR_PAUSE);
13 return 0;
14}
15
16int ql_pause_mpi_risc(struct ql_adapter *qdev)
17{
18 u32 tmp;
19 int count = UDELAY_COUNT;
20
21 /* Pause the RISC */
22 ql_write32(qdev, CSR, CSR_CMD_SET_PAUSE);
23 do {
24 tmp = ql_read32(qdev, CSR);
25 if (tmp & CSR_RP)
26 break;
27 mdelay(UDELAY_DELAY);
28 count--;
29 } while (count);
30 return (count == 0) ? -ETIMEDOUT : 0;
31}
32
Ron Mercer2c1f73c2010-01-15 13:31:30 +000033int ql_hard_reset_mpi_risc(struct ql_adapter *qdev)
34{
35 u32 tmp;
36 int count = UDELAY_COUNT;
37
38 /* Reset the RISC */
39 ql_write32(qdev, CSR, CSR_CMD_SET_RST);
40 do {
41 tmp = ql_read32(qdev, CSR);
42 if (tmp & CSR_RR) {
43 ql_write32(qdev, CSR, CSR_CMD_CLR_RST);
44 break;
45 }
46 mdelay(UDELAY_DELAY);
47 count--;
48 } while (count);
49 return (count == 0) ? -ETIMEDOUT : 0;
50}
51
Ron Mercera2e809b2009-02-26 10:08:33 +000052int ql_read_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 *data)
Ron Mercerc4e84bd2008-09-18 11:56:28 -040053{
54 int status;
55 /* wait for reg to come ready */
56 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
57 if (status)
58 goto exit;
59 /* set up for reg read */
60 ql_write32(qdev, PROC_ADDR, reg | PROC_ADDR_R);
61 /* wait for reg to come ready */
62 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
63 if (status)
64 goto exit;
65 /* get the data */
66 *data = ql_read32(qdev, PROC_DATA);
67exit:
68 return status;
69}
70
Ron Mercera2e809b2009-02-26 10:08:33 +000071int ql_write_mpi_reg(struct ql_adapter *qdev, u32 reg, u32 data)
72{
73 int status = 0;
74 /* wait for reg to come ready */
75 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
76 if (status)
77 goto exit;
78 /* write the data to the data reg */
79 ql_write32(qdev, PROC_DATA, data);
80 /* trigger the write */
81 ql_write32(qdev, PROC_ADDR, reg);
82 /* wait for reg to come ready */
83 status = ql_wait_reg_rdy(qdev, PROC_ADDR, PROC_ADDR_RDY, PROC_ADDR_ERR);
84 if (status)
85 goto exit;
86exit:
87 return status;
88}
89
90int ql_soft_reset_mpi_risc(struct ql_adapter *qdev)
91{
92 int status;
93 status = ql_write_mpi_reg(qdev, 0x00001010, 1);
94 return status;
95}
96
Ron Mercer8aae2602010-01-15 13:31:28 +000097/* Determine if we are in charge of the firwmare. If
98 * we are the lower of the 2 NIC pcie functions, or if
99 * we are the higher function and the lower function
100 * is not enabled.
101 */
102int ql_own_firmware(struct ql_adapter *qdev)
103{
104 u32 temp;
105
106 /* If we are the lower of the 2 NIC functions
107 * on the chip the we are responsible for
108 * core dump and firmware reset after an error.
109 */
110 if (qdev->func < qdev->alt_func)
111 return 1;
112
113 /* If we are the higher of the 2 NIC functions
114 * on the chip and the lower function is not
115 * enabled, then we are responsible for
116 * core dump and firmware reset after an error.
117 */
118 temp = ql_read32(qdev, STS);
119 if (!(temp & (1 << (8 + qdev->alt_func))))
120 return 1;
121
122 return 0;
123
124}
125
Hannes Eder2f22d222008-12-26 00:04:53 -0800126static int ql_get_mb_sts(struct ql_adapter *qdev, struct mbox_params *mbcp)
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400127{
128 int i, status;
129
130 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
131 if (status)
132 return -EBUSY;
133 for (i = 0; i < mbcp->out_count; i++) {
134 status =
Ron Mercera2e809b2009-02-26 10:08:33 +0000135 ql_read_mpi_reg(qdev, qdev->mailbox_out + i,
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400136 &mbcp->mbox_out[i]);
137 if (status) {
138 QPRINTK(qdev, DRV, ERR, "Failed mailbox read.\n");
139 break;
140 }
141 }
142 ql_sem_unlock(qdev, SEM_PROC_REG_MASK); /* does flush too */
143 return status;
144}
145
Ron Mercerca0413b2009-03-02 08:07:30 +0000146/* Wait for a single mailbox command to complete.
147 * Returns zero on success.
148 */
149static int ql_wait_mbx_cmd_cmplt(struct ql_adapter *qdev)
150{
Ron Mercer365da872009-06-07 13:58:29 +0000151 int count = 100;
Ron Mercerca0413b2009-03-02 08:07:30 +0000152 u32 value;
153
154 do {
155 value = ql_read32(qdev, STS);
156 if (value & STS_PI)
157 return 0;
Ron Mercer365da872009-06-07 13:58:29 +0000158 mdelay(UDELAY_DELAY); /* 100ms */
Ron Mercerca0413b2009-03-02 08:07:30 +0000159 } while (--count);
160 return -ETIMEDOUT;
161}
162
163/* Execute a single mailbox command.
164 * Caller must hold PROC_ADDR semaphore.
165 */
166static int ql_exec_mb_cmd(struct ql_adapter *qdev, struct mbox_params *mbcp)
167{
168 int i, status;
169
170 /*
171 * Make sure there's nothing pending.
172 * This shouldn't happen.
173 */
174 if (ql_read32(qdev, CSR) & CSR_HRI)
175 return -EIO;
176
177 status = ql_sem_spinlock(qdev, SEM_PROC_REG_MASK);
178 if (status)
179 return status;
180
181 /*
182 * Fill the outbound mailboxes.
183 */
184 for (i = 0; i < mbcp->in_count; i++) {
185 status = ql_write_mpi_reg(qdev, qdev->mailbox_in + i,
186 mbcp->mbox_in[i]);
187 if (status)
188 goto end;
189 }
190 /*
191 * Wake up the MPI firmware.
192 */
193 ql_write32(qdev, CSR, CSR_CMD_SET_H2R_INT);
194end:
195 ql_sem_unlock(qdev, SEM_PROC_REG_MASK);
196 return status;
197}
198
Ron Mercer2ee1e272009-03-03 12:10:33 +0000199/* We are being asked by firmware to accept
200 * a change to the port. This is only
201 * a change to max frame sizes (Tx/Rx), pause
Martin Olsson98a17082009-04-22 18:21:29 +0200202 * parameters, or loopback mode. We wake up a worker
Ron Mercer2ee1e272009-03-03 12:10:33 +0000203 * to handler processing this since a mailbox command
204 * will need to be sent to ACK the request.
205 */
206static int ql_idc_req_aen(struct ql_adapter *qdev)
207{
208 int status;
209 struct mbox_params *mbcp = &qdev->idc_mbc;
210
211 QPRINTK(qdev, DRV, ERR, "Enter!\n");
212 /* Get the status data and start up a thread to
213 * handle the request.
214 */
215 mbcp = &qdev->idc_mbc;
216 mbcp->out_count = 4;
217 status = ql_get_mb_sts(qdev, mbcp);
218 if (status) {
219 QPRINTK(qdev, DRV, ERR,
220 "Could not read MPI, resetting ASIC!\n");
221 ql_queue_asic_error(qdev);
222 } else {
223 /* Begin polled mode early so
224 * we don't get another interrupt
225 * when we leave mpi_worker.
226 */
227 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
228 queue_delayed_work(qdev->workqueue, &qdev->mpi_idc_work, 0);
229 }
230 return status;
231}
232
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000233/* Process an inter-device event completion.
234 * If good, signal the caller's completion.
235 */
236static int ql_idc_cmplt_aen(struct ql_adapter *qdev)
237{
238 int status;
239 struct mbox_params *mbcp = &qdev->idc_mbc;
240 mbcp->out_count = 4;
241 status = ql_get_mb_sts(qdev, mbcp);
242 if (status) {
243 QPRINTK(qdev, DRV, ERR,
244 "Could not read MPI, resetting RISC!\n");
245 ql_queue_fw_error(qdev);
246 } else
247 /* Wake up the sleeping mpi_idc_work thread that is
248 * waiting for this event.
249 */
250 complete(&qdev->ide_completion);
251
252 return status;
253}
Ron Mercer5700abe2009-03-03 12:10:32 +0000254
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400255static void ql_link_up(struct ql_adapter *qdev, struct mbox_params *mbcp)
256{
Ron Mercer5700abe2009-03-03 12:10:32 +0000257 int status;
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400258 mbcp->out_count = 2;
259
Ron Mercer5700abe2009-03-03 12:10:32 +0000260 status = ql_get_mb_sts(qdev, mbcp);
261 if (status) {
262 QPRINTK(qdev, DRV, ERR,
263 "%s: Could not get mailbox status.\n", __func__);
264 return;
265 }
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400266
267 qdev->link_status = mbcp->mbox_out[1];
268 QPRINTK(qdev, DRV, ERR, "Link Up.\n");
Ron Mercer5700abe2009-03-03 12:10:32 +0000269
Ron Mercer2ee1e272009-03-03 12:10:33 +0000270 /* If we're coming back from an IDC event
271 * then set up the CAM and frame routing.
272 */
273 if (test_bit(QL_CAM_RT_SET, &qdev->flags)) {
274 status = ql_cam_route_initialize(qdev);
275 if (status) {
276 QPRINTK(qdev, IFUP, ERR,
277 "Failed to init CAM/Routing tables.\n");
278 return;
279 } else
280 clear_bit(QL_CAM_RT_SET, &qdev->flags);
281 }
282
283 /* Queue up a worker to check the frame
284 * size information, and fix it if it's not
285 * to our liking.
286 */
287 if (!test_bit(QL_PORT_CFG, &qdev->flags)) {
288 QPRINTK(qdev, DRV, ERR, "Queue Port Config Worker!\n");
289 set_bit(QL_PORT_CFG, &qdev->flags);
290 /* Begin polled mode early so
291 * we don't get another interrupt
292 * when we leave mpi_worker dpc.
293 */
294 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
295 queue_delayed_work(qdev->workqueue,
296 &qdev->mpi_port_cfg_work, 0);
297 }
298
Ron Mercer6a473302009-07-02 06:06:12 +0000299 ql_link_on(qdev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400300}
301
302static void ql_link_down(struct ql_adapter *qdev, struct mbox_params *mbcp)
303{
Ron Mercer11d9fe62009-03-03 12:10:31 +0000304 int status;
305
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400306 mbcp->out_count = 3;
307
Ron Mercer11d9fe62009-03-03 12:10:31 +0000308 status = ql_get_mb_sts(qdev, mbcp);
309 if (status)
310 QPRINTK(qdev, DRV, ERR, "Link down AEN broken!\n");
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400311
Ron Mercer6a473302009-07-02 06:06:12 +0000312 ql_link_off(qdev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400313}
314
Ron Mercereae6b582009-03-03 12:10:30 +0000315static int ql_sfp_in(struct ql_adapter *qdev, struct mbox_params *mbcp)
316{
317 int status;
318
319 mbcp->out_count = 5;
320
321 status = ql_get_mb_sts(qdev, mbcp);
322 if (status)
323 QPRINTK(qdev, DRV, ERR, "SFP in AEN broken!\n");
324 else
325 QPRINTK(qdev, DRV, ERR, "SFP insertion detected.\n");
326
327 return status;
328}
329
330static int ql_sfp_out(struct ql_adapter *qdev, struct mbox_params *mbcp)
331{
332 int status;
333
334 mbcp->out_count = 1;
335
336 status = ql_get_mb_sts(qdev, mbcp);
337 if (status)
338 QPRINTK(qdev, DRV, ERR, "SFP out AEN broken!\n");
339 else
340 QPRINTK(qdev, DRV, ERR, "SFP removal detected.\n");
341
342 return status;
343}
344
Ron Mercerfc1f9ea2009-03-03 12:10:37 +0000345static int ql_aen_lost(struct ql_adapter *qdev, struct mbox_params *mbcp)
346{
347 int status;
348
349 mbcp->out_count = 6;
350
351 status = ql_get_mb_sts(qdev, mbcp);
352 if (status)
353 QPRINTK(qdev, DRV, ERR, "Lost AEN broken!\n");
354 else {
355 int i;
356 QPRINTK(qdev, DRV, ERR, "Lost AEN detected.\n");
357 for (i = 0; i < mbcp->out_count; i++)
358 QPRINTK(qdev, DRV, ERR, "mbox_out[%d] = 0x%.08x.\n",
359 i, mbcp->mbox_out[i]);
360
361 }
362
363 return status;
364}
365
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400366static void ql_init_fw_done(struct ql_adapter *qdev, struct mbox_params *mbcp)
367{
Ron Mercerf56b54f2009-03-03 12:10:34 +0000368 int status;
369
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400370 mbcp->out_count = 2;
371
Ron Mercerf56b54f2009-03-03 12:10:34 +0000372 status = ql_get_mb_sts(qdev, mbcp);
373 if (status) {
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400374 QPRINTK(qdev, DRV, ERR, "Firmware did not initialize!\n");
Ron Mercerf56b54f2009-03-03 12:10:34 +0000375 } else {
376 QPRINTK(qdev, DRV, ERR, "Firmware Revision = 0x%.08x.\n",
377 mbcp->mbox_out[1]);
Ron Mercer88051b42009-10-10 09:35:06 +0000378 qdev->fw_rev_id = mbcp->mbox_out[1];
Ron Mercerf56b54f2009-03-03 12:10:34 +0000379 status = ql_cam_route_initialize(qdev);
380 if (status)
381 QPRINTK(qdev, IFUP, ERR,
382 "Failed to init CAM/Routing tables.\n");
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400383 }
Ron Mercerc4e84bd2008-09-18 11:56:28 -0400384}
385
Ron Mercer125844e2009-02-26 10:08:34 +0000386/* Process an async event and clear it unless it's an
387 * error condition.
388 * This can get called iteratively from the mpi_work thread
389 * when events arrive via an interrupt.
390 * It also gets called when a mailbox command is polling for
391 * it's completion. */
392static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
393{
394 int status;
Ron Mercerca0413b2009-03-02 08:07:30 +0000395 int orig_count = mbcp->out_count;
Ron Mercer125844e2009-02-26 10:08:34 +0000396
397 /* Just get mailbox zero for now. */
398 mbcp->out_count = 1;
399 status = ql_get_mb_sts(qdev, mbcp);
400 if (status) {
401 QPRINTK(qdev, DRV, ERR,
402 "Could not read MPI, resetting ASIC!\n");
403 ql_queue_asic_error(qdev);
404 goto end;
405 }
406
407 switch (mbcp->mbox_out[0]) {
408
Ron Mercerca0413b2009-03-02 08:07:30 +0000409 /* This case is only active when we arrive here
410 * as a result of issuing a mailbox command to
411 * the firmware.
412 */
413 case MB_CMD_STS_INTRMDT:
414 case MB_CMD_STS_GOOD:
415 case MB_CMD_STS_INVLD_CMD:
416 case MB_CMD_STS_XFC_ERR:
417 case MB_CMD_STS_CSUM_ERR:
418 case MB_CMD_STS_ERR:
419 case MB_CMD_STS_PARAM_ERR:
420 /* We can only get mailbox status if we're polling from an
421 * unfinished command. Get the rest of the status data and
422 * return back to the caller.
423 * We only end up here when we're polling for a mailbox
424 * command completion.
425 */
426 mbcp->out_count = orig_count;
427 status = ql_get_mb_sts(qdev, mbcp);
428 return status;
429
Ron Mercer2ee1e272009-03-03 12:10:33 +0000430 /* We are being asked by firmware to accept
431 * a change to the port. This is only
432 * a change to max frame sizes (Tx/Rx), pause
Martin Olsson98a17082009-04-22 18:21:29 +0200433 * parameters, or loopback mode.
Ron Mercer2ee1e272009-03-03 12:10:33 +0000434 */
435 case AEN_IDC_REQ:
436 status = ql_idc_req_aen(qdev);
437 break;
438
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000439 /* Process and inbound IDC event.
440 * This will happen when we're trying to
441 * change tx/rx max frame size, change pause
Martin Olsson98a17082009-04-22 18:21:29 +0200442 * parameters or loopback mode.
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000443 */
444 case AEN_IDC_CMPLT:
445 case AEN_IDC_EXT:
446 status = ql_idc_cmplt_aen(qdev);
447 break;
448
Ron Mercer125844e2009-02-26 10:08:34 +0000449 case AEN_LINK_UP:
450 ql_link_up(qdev, mbcp);
451 break;
452
453 case AEN_LINK_DOWN:
454 ql_link_down(qdev, mbcp);
455 break;
456
457 case AEN_FW_INIT_DONE:
Ron Mercerf56b54f2009-03-03 12:10:34 +0000458 /* If we're in process on executing the firmware,
459 * then convert the status to normal mailbox status.
460 */
461 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
462 mbcp->out_count = orig_count;
463 status = ql_get_mb_sts(qdev, mbcp);
464 mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
465 return status;
466 }
Ron Mercer125844e2009-02-26 10:08:34 +0000467 ql_init_fw_done(qdev, mbcp);
468 break;
469
Ron Mercereae6b582009-03-03 12:10:30 +0000470 case AEN_AEN_SFP_IN:
471 ql_sfp_in(qdev, mbcp);
472 break;
473
474 case AEN_AEN_SFP_OUT:
475 ql_sfp_out(qdev, mbcp);
476 break;
477
Ron Mercer7c921912009-03-03 12:10:35 +0000478 /* This event can arrive at boot time or after an
479 * MPI reset if the firmware failed to initialize.
480 */
Ron Mercer125844e2009-02-26 10:08:34 +0000481 case AEN_FW_INIT_FAIL:
Ron Mercer7c921912009-03-03 12:10:35 +0000482 /* If we're in process on executing the firmware,
483 * then convert the status to normal mailbox status.
484 */
485 if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
486 mbcp->out_count = orig_count;
487 status = ql_get_mb_sts(qdev, mbcp);
488 mbcp->mbox_out[0] = MB_CMD_STS_ERR;
489 return status;
490 }
491 QPRINTK(qdev, DRV, ERR,
492 "Firmware initialization failed.\n");
493 status = -EIO;
494 ql_queue_fw_error(qdev);
495 break;
496
Ron Mercer125844e2009-02-26 10:08:34 +0000497 case AEN_SYS_ERR:
Ron Mercerbb667672009-03-03 12:10:36 +0000498 QPRINTK(qdev, DRV, ERR,
499 "System Error.\n");
Ron Mercer125844e2009-02-26 10:08:34 +0000500 ql_queue_fw_error(qdev);
Ron Mercerbb667672009-03-03 12:10:36 +0000501 status = -EIO;
Ron Mercer125844e2009-02-26 10:08:34 +0000502 break;
503
Ron Mercerfc1f9ea2009-03-03 12:10:37 +0000504 case AEN_AEN_LOST:
505 ql_aen_lost(qdev, mbcp);
506 break;
507
Ron Mercer91ced682009-10-10 09:35:05 +0000508 case AEN_DCBX_CHG:
509 /* Need to support AEN 8110 */
510 break;
Ron Mercer125844e2009-02-26 10:08:34 +0000511 default:
512 QPRINTK(qdev, DRV, ERR,
513 "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
514 /* Clear the MPI firmware status. */
515 }
516end:
517 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
Ron Mercer709ac4f2009-06-07 13:58:26 +0000518 /* Restore the original mailbox count to
519 * what the caller asked for. This can get
520 * changed when a mailbox command is waiting
521 * for a response and an AEN arrives and
522 * is handled.
523 * */
524 mbcp->out_count = orig_count;
Ron Mercer125844e2009-02-26 10:08:34 +0000525 return status;
526}
527
Ron Mercerca0413b2009-03-02 08:07:30 +0000528/* Execute a single mailbox command.
529 * mbcp is a pointer to an array of u32. Each
530 * element in the array contains the value for it's
531 * respective mailbox register.
532 */
533static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
534{
Ron Mercerda039452009-10-28 08:39:21 +0000535 int status;
536 unsigned long count;
Ron Mercerca0413b2009-03-02 08:07:30 +0000537
Ron Mercerca0413b2009-03-02 08:07:30 +0000538
539 /* Begin polled mode for MPI */
540 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
541
542 /* Load the mailbox registers and wake up MPI RISC. */
543 status = ql_exec_mb_cmd(qdev, mbcp);
544 if (status)
545 goto end;
546
547
548 /* If we're generating a system error, then there's nothing
549 * to wait for.
550 */
551 if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
552 goto end;
553
554 /* Wait for the command to complete. We loop
555 * here because some AEN might arrive while
556 * we're waiting for the mailbox command to
Ron Mercerda039452009-10-28 08:39:21 +0000557 * complete. If more than 5 seconds expire we can
Ron Mercerca0413b2009-03-02 08:07:30 +0000558 * assume something is wrong. */
Ron Mercerda039452009-10-28 08:39:21 +0000559 count = jiffies + HZ * MAILBOX_TIMEOUT;
Ron Mercerca0413b2009-03-02 08:07:30 +0000560 do {
561 /* Wait for the interrupt to come in. */
562 status = ql_wait_mbx_cmd_cmplt(qdev);
563 if (status)
Ron Mercer60fa6c32009-11-06 07:44:57 +0000564 continue;
Ron Mercerca0413b2009-03-02 08:07:30 +0000565
566 /* Process the event. If it's an AEN, it
567 * will be handled in-line or a worker
568 * will be spawned. If it's our completion
569 * we will catch it below.
570 */
571 status = ql_mpi_handler(qdev, mbcp);
572 if (status)
573 goto end;
574
575 /* It's either the completion for our mailbox
576 * command complete or an AEN. If it's our
577 * completion then get out.
578 */
579 if (((mbcp->mbox_out[0] & 0x0000f000) ==
580 MB_CMD_STS_GOOD) ||
581 ((mbcp->mbox_out[0] & 0x0000f000) ==
582 MB_CMD_STS_INTRMDT))
Ron Mercerda039452009-10-28 08:39:21 +0000583 goto done;
584 } while (time_before(jiffies, count));
Ron Mercerca0413b2009-03-02 08:07:30 +0000585
Ron Mercerda039452009-10-28 08:39:21 +0000586 QPRINTK(qdev, DRV, ERR,
587 "Timed out waiting for mailbox complete.\n");
588 status = -ETIMEDOUT;
589 goto end;
590
591done:
Ron Mercerca0413b2009-03-02 08:07:30 +0000592
593 /* Now we can clear the interrupt condition
594 * and look at our status.
595 */
596 ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
597
598 if (((mbcp->mbox_out[0] & 0x0000f000) !=
599 MB_CMD_STS_GOOD) &&
600 ((mbcp->mbox_out[0] & 0x0000f000) !=
601 MB_CMD_STS_INTRMDT)) {
Ron Mercerca0413b2009-03-02 08:07:30 +0000602 status = -EIO;
603 }
604end:
Ron Mercerca0413b2009-03-02 08:07:30 +0000605 /* End polled mode for MPI */
606 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
607 return status;
608}
609
Ron Mercerd5c1da52010-01-15 13:31:34 +0000610int ql_mb_sys_err(struct ql_adapter *qdev)
611{
612 struct mbox_params mbc;
613 struct mbox_params *mbcp = &mbc;
614 int status;
615
616 memset(mbcp, 0, sizeof(struct mbox_params));
617
618 mbcp->in_count = 1;
619 mbcp->out_count = 0;
620
621 mbcp->mbox_in[0] = MB_CMD_MAKE_SYS_ERR;
622
623 status = ql_mailbox_command(qdev, mbcp);
624 return status;
625}
Ron Mercercfec0cb2009-06-09 05:39:29 +0000626
627/* Get MPI firmware version. This will be used for
628 * driver banner and for ethtool info.
629 * Returns zero on success.
630 */
631int ql_mb_about_fw(struct ql_adapter *qdev)
632{
633 struct mbox_params mbc;
634 struct mbox_params *mbcp = &mbc;
635 int status = 0;
636
637 memset(mbcp, 0, sizeof(struct mbox_params));
638
639 mbcp->in_count = 1;
640 mbcp->out_count = 3;
641
642 mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
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 about firmware command\n");
651 status = -EIO;
652 }
653
654 /* Store the firmware version */
655 qdev->fw_rev_id = mbcp->mbox_out[1];
656
657 return status;
658}
659
Ron Mercerca0413b2009-03-02 08:07:30 +0000660/* Get functional state for MPI firmware.
661 * Returns zero on success.
662 */
663int ql_mb_get_fw_state(struct ql_adapter *qdev)
664{
665 struct mbox_params mbc;
666 struct mbox_params *mbcp = &mbc;
667 int status = 0;
668
669 memset(mbcp, 0, sizeof(struct mbox_params));
670
671 mbcp->in_count = 1;
672 mbcp->out_count = 2;
673
674 mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
675
676 status = ql_mailbox_command(qdev, mbcp);
677 if (status)
678 return status;
679
680 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
681 QPRINTK(qdev, DRV, ERR,
682 "Failed Get Firmware State.\n");
683 status = -EIO;
684 }
685
686 /* If bit zero is set in mbx 1 then the firmware is
687 * running, but not initialized. This should never
688 * happen.
689 */
690 if (mbcp->mbox_out[1] & 1) {
691 QPRINTK(qdev, DRV, ERR,
692 "Firmware waiting for initialization.\n");
693 status = -EIO;
694 }
695
696 return status;
697}
698
Ron Mercer2ee1e272009-03-03 12:10:33 +0000699/* Send and ACK mailbox command to the firmware to
700 * let it continue with the change.
701 */
702int ql_mb_idc_ack(struct ql_adapter *qdev)
703{
704 struct mbox_params mbc;
705 struct mbox_params *mbcp = &mbc;
706 int status = 0;
707
708 memset(mbcp, 0, sizeof(struct mbox_params));
709
710 mbcp->in_count = 5;
711 mbcp->out_count = 1;
712
713 mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
714 mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
715 mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
716 mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
717 mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
718
719 status = ql_mailbox_command(qdev, mbcp);
720 if (status)
721 return status;
722
723 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
724 QPRINTK(qdev, DRV, ERR,
725 "Failed IDC ACK send.\n");
726 status = -EIO;
727 }
728 return status;
729}
730
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000731/* Get link settings and maximum frame size settings
732 * for the current port.
733 * Most likely will block.
734 */
Ron Mercer1d30df22009-10-21 11:07:38 +0000735int ql_mb_set_port_cfg(struct ql_adapter *qdev)
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000736{
737 struct mbox_params mbc;
738 struct mbox_params *mbcp = &mbc;
739 int status = 0;
740
741 memset(mbcp, 0, sizeof(struct mbox_params));
742
743 mbcp->in_count = 3;
744 mbcp->out_count = 1;
745
746 mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
747 mbcp->mbox_in[1] = qdev->link_config;
748 mbcp->mbox_in[2] = qdev->max_frame_size;
749
750
751 status = ql_mailbox_command(qdev, mbcp);
752 if (status)
753 return status;
754
755 if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
756 QPRINTK(qdev, DRV, ERR,
757 "Port Config sent, wait for IDC.\n");
758 } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
759 QPRINTK(qdev, DRV, ERR,
760 "Failed Set Port Configuration.\n");
761 status = -EIO;
762 }
763 return status;
764}
765
Ron Mercer2c1f73c2010-01-15 13:31:30 +0000766int ql_mb_dump_ram(struct ql_adapter *qdev, u64 req_dma, u32 addr,
767 u32 size)
768{
769 int status = 0;
770 struct mbox_params mbc;
771 struct mbox_params *mbcp = &mbc;
772
773 memset(mbcp, 0, sizeof(struct mbox_params));
774
775 mbcp->in_count = 9;
776 mbcp->out_count = 1;
777
778 mbcp->mbox_in[0] = MB_CMD_DUMP_RISC_RAM;
779 mbcp->mbox_in[1] = LSW(addr);
780 mbcp->mbox_in[2] = MSW(req_dma);
781 mbcp->mbox_in[3] = LSW(req_dma);
782 mbcp->mbox_in[4] = MSW(size);
783 mbcp->mbox_in[5] = LSW(size);
784 mbcp->mbox_in[6] = MSW(MSD(req_dma));
785 mbcp->mbox_in[7] = LSW(MSD(req_dma));
786 mbcp->mbox_in[8] = MSW(addr);
787
788
789 status = ql_mailbox_command(qdev, mbcp);
790 if (status)
791 return status;
792
793 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
794 QPRINTK(qdev, DRV, ERR,
795 "Failed to dump risc RAM.\n");
796 status = -EIO;
797 }
798 return status;
799}
800
801/* Issue a mailbox command to dump RISC RAM. */
802int ql_dump_risc_ram_area(struct ql_adapter *qdev, void *buf,
803 u32 ram_addr, int word_count)
804{
805 int status;
806 char *my_buf;
807 dma_addr_t buf_dma;
808
809 my_buf = pci_alloc_consistent(qdev->pdev, word_count * sizeof(u32),
810 &buf_dma);
811 if (!my_buf)
812 return -EIO;
813
814 status = ql_mb_dump_ram(qdev, buf_dma, ram_addr, word_count);
815 if (!status)
816 memcpy(buf, my_buf, word_count * sizeof(u32));
817
818 pci_free_consistent(qdev->pdev, word_count * sizeof(u32), my_buf,
819 buf_dma);
820 return status;
821}
822
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000823/* Get link settings and maximum frame size settings
824 * for the current port.
825 * Most likely will block.
826 */
Ron Mercer1d30df22009-10-21 11:07:38 +0000827int ql_mb_get_port_cfg(struct ql_adapter *qdev)
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000828{
829 struct mbox_params mbc;
830 struct mbox_params *mbcp = &mbc;
831 int status = 0;
832
833 memset(mbcp, 0, sizeof(struct mbox_params));
834
835 mbcp->in_count = 1;
836 mbcp->out_count = 3;
837
838 mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
839
840 status = ql_mailbox_command(qdev, mbcp);
841 if (status)
842 return status;
843
844 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
845 QPRINTK(qdev, DRV, ERR,
846 "Failed Get Port Configuration.\n");
847 status = -EIO;
848 } else {
849 QPRINTK(qdev, DRV, DEBUG,
850 "Passed Get Port Configuration.\n");
851 qdev->link_config = mbcp->mbox_out[1];
852 qdev->max_frame_size = mbcp->mbox_out[2];
853 }
854 return status;
855}
856
Ron Mercerbc083ce2009-10-21 11:07:40 +0000857int ql_mb_wol_mode(struct ql_adapter *qdev, u32 wol)
858{
859 struct mbox_params mbc;
860 struct mbox_params *mbcp = &mbc;
861 int status;
862
863 memset(mbcp, 0, sizeof(struct mbox_params));
864
865 mbcp->in_count = 2;
866 mbcp->out_count = 1;
867
868 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MODE;
869 mbcp->mbox_in[1] = wol;
870
871
872 status = ql_mailbox_command(qdev, mbcp);
873 if (status)
874 return status;
875
876 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
877 QPRINTK(qdev, DRV, ERR,
878 "Failed to set WOL mode.\n");
879 status = -EIO;
880 }
881 return status;
882}
883
884int ql_mb_wol_set_magic(struct ql_adapter *qdev, u32 enable_wol)
885{
886 struct mbox_params mbc;
887 struct mbox_params *mbcp = &mbc;
888 int status;
889 u8 *addr = qdev->ndev->dev_addr;
890
891 memset(mbcp, 0, sizeof(struct mbox_params));
892
893 mbcp->in_count = 8;
894 mbcp->out_count = 1;
895
896 mbcp->mbox_in[0] = MB_CMD_SET_WOL_MAGIC;
897 if (enable_wol) {
898 mbcp->mbox_in[1] = (u32)addr[0];
899 mbcp->mbox_in[2] = (u32)addr[1];
900 mbcp->mbox_in[3] = (u32)addr[2];
901 mbcp->mbox_in[4] = (u32)addr[3];
902 mbcp->mbox_in[5] = (u32)addr[4];
903 mbcp->mbox_in[6] = (u32)addr[5];
904 mbcp->mbox_in[7] = 0;
905 } else {
906 mbcp->mbox_in[1] = 0;
907 mbcp->mbox_in[2] = 1;
908 mbcp->mbox_in[3] = 1;
909 mbcp->mbox_in[4] = 1;
910 mbcp->mbox_in[5] = 1;
911 mbcp->mbox_in[6] = 1;
912 mbcp->mbox_in[7] = 0;
913 }
914
915 status = ql_mailbox_command(qdev, mbcp);
916 if (status)
917 return status;
918
919 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
920 QPRINTK(qdev, DRV, ERR,
921 "Failed to set WOL mode.\n");
922 status = -EIO;
923 }
924 return status;
925}
926
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +0000927/* IDC - Inter Device Communication...
928 * Some firmware commands require consent of adjacent FCOE
929 * function. This function waits for the OK, or a
930 * counter-request for a little more time.i
931 * The firmware will complete the request if the other
932 * function doesn't respond.
933 */
934static int ql_idc_wait(struct ql_adapter *qdev)
935{
936 int status = -ETIMEDOUT;
937 long wait_time = 1 * HZ;
938 struct mbox_params *mbcp = &qdev->idc_mbc;
939 do {
940 /* Wait here for the command to complete
941 * via the IDC process.
942 */
943 wait_time =
944 wait_for_completion_timeout(&qdev->ide_completion,
945 wait_time);
946 if (!wait_time) {
947 QPRINTK(qdev, DRV, ERR,
948 "IDC Timeout.\n");
949 break;
950 }
951 /* Now examine the response from the IDC process.
952 * We might have a good completion or a request for
953 * more wait time.
954 */
955 if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
956 QPRINTK(qdev, DRV, ERR,
957 "IDC Time Extension from function.\n");
958 wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
959 } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
960 QPRINTK(qdev, DRV, ERR,
961 "IDC Success.\n");
962 status = 0;
963 break;
964 } else {
965 QPRINTK(qdev, DRV, ERR,
966 "IDC: Invalid State 0x%.04x.\n",
967 mbcp->mbox_out[0]);
968 status = -EIO;
969 break;
970 }
971 } while (wait_time);
972
973 return status;
974}
975
Ron Mercerd8eb59d2009-10-21 11:07:39 +0000976int ql_mb_set_led_cfg(struct ql_adapter *qdev, u32 led_config)
977{
978 struct mbox_params mbc;
979 struct mbox_params *mbcp = &mbc;
980 int status;
981
982 memset(mbcp, 0, sizeof(struct mbox_params));
983
984 mbcp->in_count = 2;
985 mbcp->out_count = 1;
986
987 mbcp->mbox_in[0] = MB_CMD_SET_LED_CFG;
988 mbcp->mbox_in[1] = led_config;
989
990
991 status = ql_mailbox_command(qdev, mbcp);
992 if (status)
993 return status;
994
995 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
996 QPRINTK(qdev, DRV, ERR,
997 "Failed to set LED Configuration.\n");
998 status = -EIO;
999 }
1000
1001 return status;
1002}
1003
1004int ql_mb_get_led_cfg(struct ql_adapter *qdev)
1005{
1006 struct mbox_params mbc;
1007 struct mbox_params *mbcp = &mbc;
1008 int status;
1009
1010 memset(mbcp, 0, sizeof(struct mbox_params));
1011
1012 mbcp->in_count = 1;
1013 mbcp->out_count = 2;
1014
1015 mbcp->mbox_in[0] = MB_CMD_GET_LED_CFG;
1016
1017 status = ql_mailbox_command(qdev, mbcp);
1018 if (status)
1019 return status;
1020
1021 if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
1022 QPRINTK(qdev, DRV, ERR,
1023 "Failed to get LED Configuration.\n");
1024 status = -EIO;
1025 } else
1026 qdev->led_config = mbcp->mbox_out[1];
1027
1028 return status;
1029}
1030
Ron Mercer84087f42009-10-08 09:54:41 +00001031int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
1032{
1033 struct mbox_params mbc;
1034 struct mbox_params *mbcp = &mbc;
1035 int status;
1036
1037 memset(mbcp, 0, sizeof(struct mbox_params));
1038
1039 mbcp->in_count = 1;
1040 mbcp->out_count = 2;
1041
1042 mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
1043 mbcp->mbox_in[1] = control;
1044
1045 status = ql_mailbox_command(qdev, mbcp);
1046 if (status)
1047 return status;
1048
1049 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
1050 return status;
1051
1052 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1053 QPRINTK(qdev, DRV, ERR,
1054 "Command not supported by firmware.\n");
1055 status = -EINVAL;
1056 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1057 /* This indicates that the firmware is
1058 * already in the state we are trying to
1059 * change it to.
1060 */
1061 QPRINTK(qdev, DRV, ERR,
1062 "Command parameters make no change.\n");
1063 }
1064 return status;
1065}
1066
1067/* Returns a negative error code or the mailbox command status. */
1068static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
1069{
1070 struct mbox_params mbc;
1071 struct mbox_params *mbcp = &mbc;
1072 int status;
1073
1074 memset(mbcp, 0, sizeof(struct mbox_params));
1075 *control = 0;
1076
1077 mbcp->in_count = 1;
1078 mbcp->out_count = 1;
1079
1080 mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
1081
1082 status = ql_mailbox_command(qdev, mbcp);
1083 if (status)
1084 return status;
1085
1086 if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
1087 *control = mbcp->mbox_in[1];
1088 return status;
1089 }
1090
1091 if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
1092 QPRINTK(qdev, DRV, ERR,
1093 "Command not supported by firmware.\n");
1094 status = -EINVAL;
1095 } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
1096 QPRINTK(qdev, DRV, ERR,
1097 "Failed to get MPI traffic control.\n");
1098 status = -EIO;
1099 }
1100 return status;
1101}
1102
1103int ql_wait_fifo_empty(struct ql_adapter *qdev)
1104{
1105 int count = 5;
1106 u32 mgmnt_fifo_empty;
1107 u32 nic_fifo_empty;
1108
1109 do {
1110 nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
1111 ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
1112 mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
1113 if (nic_fifo_empty && mgmnt_fifo_empty)
1114 return 0;
1115 msleep(100);
1116 } while (count-- > 0);
1117 return -ETIMEDOUT;
1118}
1119
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001120/* API called in work thread context to set new TX/RX
1121 * maximum frame size values to match MTU.
1122 */
1123static int ql_set_port_cfg(struct ql_adapter *qdev)
1124{
1125 int status;
Ron Mercer86aaf9a2009-10-05 11:46:49 +00001126 rtnl_lock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001127 status = ql_mb_set_port_cfg(qdev);
Ron Mercer86aaf9a2009-10-05 11:46:49 +00001128 rtnl_unlock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001129 if (status)
1130 return status;
1131 status = ql_idc_wait(qdev);
1132 return status;
1133}
1134
1135/* The following routines are worker threads that process
1136 * events that may sleep waiting for completion.
1137 */
1138
1139/* This thread gets the maximum TX and RX frame size values
1140 * from the firmware and, if necessary, changes them to match
1141 * the MTU setting.
1142 */
1143void ql_mpi_port_cfg_work(struct work_struct *work)
1144{
1145 struct ql_adapter *qdev =
1146 container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001147 int status;
1148
Ron Mercer86aaf9a2009-10-05 11:46:49 +00001149 rtnl_lock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001150 status = ql_mb_get_port_cfg(qdev);
Ron Mercer86aaf9a2009-10-05 11:46:49 +00001151 rtnl_unlock();
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001152 if (status) {
1153 QPRINTK(qdev, DRV, ERR,
1154 "Bug: Failed to get port config data.\n");
1155 goto err;
1156 }
1157
Ron Mercerc8269b22009-06-07 13:58:27 +00001158 if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001159 qdev->max_frame_size ==
1160 CFG_DEFAULT_MAX_FRAME_SIZE)
1161 goto end;
1162
1163 qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
1164 qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
1165 status = ql_set_port_cfg(qdev);
1166 if (status) {
1167 QPRINTK(qdev, DRV, ERR,
1168 "Bug: Failed to set port config data.\n");
1169 goto err;
1170 }
1171end:
1172 clear_bit(QL_PORT_CFG, &qdev->flags);
1173 return;
1174err:
1175 ql_queue_fw_error(qdev);
1176 goto end;
1177}
1178
Ron Mercer2ee1e272009-03-03 12:10:33 +00001179/* Process an inter-device request. This is issues by
1180 * the firmware in response to another function requesting
1181 * a change to the port. We set a flag to indicate a change
1182 * has been made and then send a mailbox command ACKing
1183 * the change request.
1184 */
1185void ql_mpi_idc_work(struct work_struct *work)
1186{
1187 struct ql_adapter *qdev =
1188 container_of(work, struct ql_adapter, mpi_idc_work.work);
1189 int status;
1190 struct mbox_params *mbcp = &qdev->idc_mbc;
1191 u32 aen;
Ron Mercer1e34e302009-11-03 13:49:30 +00001192 int timeout;
Ron Mercer2ee1e272009-03-03 12:10:33 +00001193
Ron Mercer1e34e302009-11-03 13:49:30 +00001194 rtnl_lock();
Ron Mercer2ee1e272009-03-03 12:10:33 +00001195 aen = mbcp->mbox_out[1] >> 16;
Ron Mercer1e34e302009-11-03 13:49:30 +00001196 timeout = (mbcp->mbox_out[1] >> 8) & 0xf;
Ron Mercer2ee1e272009-03-03 12:10:33 +00001197
1198 switch (aen) {
1199 default:
1200 QPRINTK(qdev, DRV, ERR,
1201 "Bug: Unhandled IDC action.\n");
1202 break;
1203 case MB_CMD_PORT_RESET:
Ron Mercer2ee1e272009-03-03 12:10:33 +00001204 case MB_CMD_STOP_FW:
Ron Mercer6a473302009-07-02 06:06:12 +00001205 ql_link_off(qdev);
Ron Mercer1e34e302009-11-03 13:49:30 +00001206 case MB_CMD_SET_PORT_CFG:
Ron Mercer2ee1e272009-03-03 12:10:33 +00001207 /* Signal the resulting link up AEN
1208 * that the frame routing and mac addr
1209 * needs to be set.
1210 * */
1211 set_bit(QL_CAM_RT_SET, &qdev->flags);
Ron Mercer1e34e302009-11-03 13:49:30 +00001212 /* Do ACK if required */
1213 if (timeout) {
1214 status = ql_mb_idc_ack(qdev);
1215 if (status)
1216 QPRINTK(qdev, DRV, ERR,
1217 "Bug: No pending IDC!\n");
1218 } else {
1219 QPRINTK(qdev, DRV, DEBUG,
1220 "IDC ACK not required\n");
1221 status = 0; /* success */
Ron Mercer2ee1e272009-03-03 12:10:33 +00001222 }
Ron Mercer1e34e302009-11-03 13:49:30 +00001223 break;
1224
1225 /* These sub-commands issued by another (FCoE)
1226 * function are requesting to do an operation
1227 * on the shared resource (MPI environment).
1228 * We currently don't issue these so we just
1229 * ACK the request.
1230 */
1231 case MB_CMD_IOP_RESTART_MPI:
1232 case MB_CMD_IOP_PREP_LINK_DOWN:
1233 /* Drop the link, reload the routing
1234 * table when link comes up.
1235 */
1236 ql_link_off(qdev);
1237 set_bit(QL_CAM_RT_SET, &qdev->flags);
1238 /* Fall through. */
1239 case MB_CMD_IOP_DVR_START:
1240 case MB_CMD_IOP_FLASH_ACC:
1241 case MB_CMD_IOP_CORE_DUMP_MPI:
1242 case MB_CMD_IOP_PREP_UPDATE_MPI:
1243 case MB_CMD_IOP_COMP_UPDATE_MPI:
1244 case MB_CMD_IOP_NONE: /* an IDC without params */
1245 /* Do ACK if required */
1246 if (timeout) {
1247 status = ql_mb_idc_ack(qdev);
1248 if (status)
1249 QPRINTK(qdev, DRV, ERR,
1250 "Bug: No pending IDC!\n");
1251 } else {
1252 QPRINTK(qdev, DRV, DEBUG,
1253 "IDC ACK not required\n");
1254 status = 0; /* success */
1255 }
1256 break;
Ron Mercer2ee1e272009-03-03 12:10:33 +00001257 }
Ron Mercer1e34e302009-11-03 13:49:30 +00001258 rtnl_unlock();
Ron Mercer2ee1e272009-03-03 12:10:33 +00001259}
1260
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001261void ql_mpi_work(struct work_struct *work)
1262{
1263 struct ql_adapter *qdev =
1264 container_of(work, struct ql_adapter, mpi_work.work);
1265 struct mbox_params mbc;
1266 struct mbox_params *mbcp = &mbc;
Ron Mercerd6f58c22009-06-07 13:58:25 +00001267 int err = 0;
Ron Mercer125844e2009-02-26 10:08:34 +00001268
Ron Mercer86aaf9a2009-10-05 11:46:49 +00001269 rtnl_lock();
Ron Mercerefd7d262009-10-08 09:54:43 +00001270 /* Begin polled mode for MPI */
1271 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001272
1273 while (ql_read32(qdev, STS) & STS_PI) {
Ron Mercer125844e2009-02-26 10:08:34 +00001274 memset(mbcp, 0, sizeof(struct mbox_params));
1275 mbcp->out_count = 1;
Ron Mercerd6f58c22009-06-07 13:58:25 +00001276 /* Don't continue if an async event
1277 * did not complete properly.
1278 */
1279 err = ql_mpi_handler(qdev, mbcp);
1280 if (err)
1281 break;
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001282 }
Ron Mercer125844e2009-02-26 10:08:34 +00001283
Ron Mercerefd7d262009-10-08 09:54:43 +00001284 /* End polled mode for MPI */
1285 ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
Ron Mercer86aaf9a2009-10-05 11:46:49 +00001286 rtnl_unlock();
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001287 ql_enable_completion_interrupt(qdev, 0);
1288}
1289
1290void ql_mpi_reset_work(struct work_struct *work)
1291{
1292 struct ql_adapter *qdev =
1293 container_of(work, struct ql_adapter, mpi_reset_work.work);
Ron Mercerbcc2cb3b2009-03-02 08:07:32 +00001294 cancel_delayed_work_sync(&qdev->mpi_work);
1295 cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
Ron Mercer2ee1e272009-03-03 12:10:33 +00001296 cancel_delayed_work_sync(&qdev->mpi_idc_work);
Ron Mercer8aae2602010-01-15 13:31:28 +00001297 /* If we're not the dominant NIC function,
1298 * then there is nothing to do.
1299 */
1300 if (!ql_own_firmware(qdev)) {
1301 QPRINTK(qdev, DRV, ERR, "Don't own firmware!\n");
1302 return;
1303 }
1304
1305 if (!ql_core_dump(qdev, qdev->mpi_coredump)) {
1306 QPRINTK(qdev, DRV, ERR, "Core is dumped!\n");
1307 qdev->core_is_dumped = 1;
1308 queue_delayed_work(qdev->workqueue,
1309 &qdev->mpi_core_to_log, 5 * HZ);
1310 }
Ron Mercera2e809b2009-02-26 10:08:33 +00001311 ql_soft_reset_mpi_risc(qdev);
Ron Mercerc4e84bd2008-09-18 11:56:28 -04001312}