qlge_mpi.c 23 KB

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