qlge_mpi.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. status = ql_cam_route_initialize(qdev);
  278. if (status)
  279. QPRINTK(qdev, IFUP, ERR,
  280. "Failed to init CAM/Routing tables.\n");
  281. }
  282. }
  283. /* Process an async event and clear it unless it's an
  284. * error condition.
  285. * This can get called iteratively from the mpi_work thread
  286. * when events arrive via an interrupt.
  287. * It also gets called when a mailbox command is polling for
  288. * it's completion. */
  289. static int ql_mpi_handler(struct ql_adapter *qdev, struct mbox_params *mbcp)
  290. {
  291. int status;
  292. int orig_count = mbcp->out_count;
  293. /* Just get mailbox zero for now. */
  294. mbcp->out_count = 1;
  295. status = ql_get_mb_sts(qdev, mbcp);
  296. if (status) {
  297. QPRINTK(qdev, DRV, ERR,
  298. "Could not read MPI, resetting ASIC!\n");
  299. ql_queue_asic_error(qdev);
  300. goto end;
  301. }
  302. switch (mbcp->mbox_out[0]) {
  303. /* This case is only active when we arrive here
  304. * as a result of issuing a mailbox command to
  305. * the firmware.
  306. */
  307. case MB_CMD_STS_INTRMDT:
  308. case MB_CMD_STS_GOOD:
  309. case MB_CMD_STS_INVLD_CMD:
  310. case MB_CMD_STS_XFC_ERR:
  311. case MB_CMD_STS_CSUM_ERR:
  312. case MB_CMD_STS_ERR:
  313. case MB_CMD_STS_PARAM_ERR:
  314. /* We can only get mailbox status if we're polling from an
  315. * unfinished command. Get the rest of the status data and
  316. * return back to the caller.
  317. * We only end up here when we're polling for a mailbox
  318. * command completion.
  319. */
  320. mbcp->out_count = orig_count;
  321. status = ql_get_mb_sts(qdev, mbcp);
  322. return status;
  323. /* We are being asked by firmware to accept
  324. * a change to the port. This is only
  325. * a change to max frame sizes (Tx/Rx), pause
  326. * parameters, or loopback mode.
  327. */
  328. case AEN_IDC_REQ:
  329. status = ql_idc_req_aen(qdev);
  330. break;
  331. /* Process and inbound IDC event.
  332. * This will happen when we're trying to
  333. * change tx/rx max frame size, change pause
  334. * parameters or loopback mode.
  335. */
  336. case AEN_IDC_CMPLT:
  337. case AEN_IDC_EXT:
  338. status = ql_idc_cmplt_aen(qdev);
  339. break;
  340. case AEN_LINK_UP:
  341. ql_link_up(qdev, mbcp);
  342. break;
  343. case AEN_LINK_DOWN:
  344. ql_link_down(qdev, mbcp);
  345. break;
  346. case AEN_FW_INIT_DONE:
  347. /* If we're in process on executing the firmware,
  348. * then convert the status to normal mailbox status.
  349. */
  350. if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
  351. mbcp->out_count = orig_count;
  352. status = ql_get_mb_sts(qdev, mbcp);
  353. mbcp->mbox_out[0] = MB_CMD_STS_GOOD;
  354. return status;
  355. }
  356. ql_init_fw_done(qdev, mbcp);
  357. break;
  358. case AEN_AEN_SFP_IN:
  359. ql_sfp_in(qdev, mbcp);
  360. break;
  361. case AEN_AEN_SFP_OUT:
  362. ql_sfp_out(qdev, mbcp);
  363. break;
  364. /* This event can arrive at boot time or after an
  365. * MPI reset if the firmware failed to initialize.
  366. */
  367. case AEN_FW_INIT_FAIL:
  368. /* If we're in process on executing the firmware,
  369. * then convert the status to normal mailbox status.
  370. */
  371. if (mbcp->mbox_in[0] == MB_CMD_EX_FW) {
  372. mbcp->out_count = orig_count;
  373. status = ql_get_mb_sts(qdev, mbcp);
  374. mbcp->mbox_out[0] = MB_CMD_STS_ERR;
  375. return status;
  376. }
  377. QPRINTK(qdev, DRV, ERR,
  378. "Firmware initialization failed.\n");
  379. status = -EIO;
  380. ql_queue_fw_error(qdev);
  381. break;
  382. case AEN_SYS_ERR:
  383. QPRINTK(qdev, DRV, ERR,
  384. "System Error.\n");
  385. ql_queue_fw_error(qdev);
  386. status = -EIO;
  387. break;
  388. case AEN_AEN_LOST:
  389. ql_aen_lost(qdev, mbcp);
  390. break;
  391. default:
  392. QPRINTK(qdev, DRV, ERR,
  393. "Unsupported AE %.08x.\n", mbcp->mbox_out[0]);
  394. /* Clear the MPI firmware status. */
  395. }
  396. end:
  397. ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
  398. /* Restore the original mailbox count to
  399. * what the caller asked for. This can get
  400. * changed when a mailbox command is waiting
  401. * for a response and an AEN arrives and
  402. * is handled.
  403. * */
  404. mbcp->out_count = orig_count;
  405. return status;
  406. }
  407. /* Execute a single mailbox command.
  408. * mbcp is a pointer to an array of u32. Each
  409. * element in the array contains the value for it's
  410. * respective mailbox register.
  411. */
  412. static int ql_mailbox_command(struct ql_adapter *qdev, struct mbox_params *mbcp)
  413. {
  414. int status;
  415. unsigned long count;
  416. /* Begin polled mode for MPI */
  417. ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
  418. /* Load the mailbox registers and wake up MPI RISC. */
  419. status = ql_exec_mb_cmd(qdev, mbcp);
  420. if (status)
  421. goto end;
  422. /* If we're generating a system error, then there's nothing
  423. * to wait for.
  424. */
  425. if (mbcp->mbox_in[0] == MB_CMD_MAKE_SYS_ERR)
  426. goto end;
  427. /* Wait for the command to complete. We loop
  428. * here because some AEN might arrive while
  429. * we're waiting for the mailbox command to
  430. * complete. If more than 5 seconds expire we can
  431. * assume something is wrong. */
  432. count = jiffies + HZ * MAILBOX_TIMEOUT;
  433. do {
  434. /* Wait for the interrupt to come in. */
  435. status = ql_wait_mbx_cmd_cmplt(qdev);
  436. if (status)
  437. continue;
  438. /* Process the event. If it's an AEN, it
  439. * will be handled in-line or a worker
  440. * will be spawned. If it's our completion
  441. * we will catch it below.
  442. */
  443. status = ql_mpi_handler(qdev, mbcp);
  444. if (status)
  445. goto end;
  446. /* It's either the completion for our mailbox
  447. * command complete or an AEN. If it's our
  448. * completion then get out.
  449. */
  450. if (((mbcp->mbox_out[0] & 0x0000f000) ==
  451. MB_CMD_STS_GOOD) ||
  452. ((mbcp->mbox_out[0] & 0x0000f000) ==
  453. MB_CMD_STS_INTRMDT))
  454. goto done;
  455. } while (time_before(jiffies, count));
  456. QPRINTK(qdev, DRV, ERR,
  457. "Timed out waiting for mailbox complete.\n");
  458. status = -ETIMEDOUT;
  459. goto end;
  460. done:
  461. /* Now we can clear the interrupt condition
  462. * and look at our status.
  463. */
  464. ql_write32(qdev, CSR, CSR_CMD_CLR_R2PCI_INT);
  465. if (((mbcp->mbox_out[0] & 0x0000f000) !=
  466. MB_CMD_STS_GOOD) &&
  467. ((mbcp->mbox_out[0] & 0x0000f000) !=
  468. MB_CMD_STS_INTRMDT)) {
  469. ql_display_mb_sts(qdev, mbcp);
  470. status = -EIO;
  471. }
  472. end:
  473. /* End polled mode for MPI */
  474. ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
  475. return status;
  476. }
  477. /* Get MPI firmware version. This will be used for
  478. * driver banner and for ethtool info.
  479. * Returns zero on success.
  480. */
  481. int ql_mb_about_fw(struct ql_adapter *qdev)
  482. {
  483. struct mbox_params mbc;
  484. struct mbox_params *mbcp = &mbc;
  485. int status = 0;
  486. memset(mbcp, 0, sizeof(struct mbox_params));
  487. mbcp->in_count = 1;
  488. mbcp->out_count = 3;
  489. mbcp->mbox_in[0] = MB_CMD_ABOUT_FW;
  490. status = ql_mailbox_command(qdev, mbcp);
  491. if (status)
  492. return status;
  493. if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
  494. QPRINTK(qdev, DRV, ERR,
  495. "Failed about firmware command\n");
  496. status = -EIO;
  497. }
  498. /* Store the firmware version */
  499. qdev->fw_rev_id = mbcp->mbox_out[1];
  500. return status;
  501. }
  502. /* Get functional state for MPI firmware.
  503. * Returns zero on success.
  504. */
  505. int ql_mb_get_fw_state(struct ql_adapter *qdev)
  506. {
  507. struct mbox_params mbc;
  508. struct mbox_params *mbcp = &mbc;
  509. int status = 0;
  510. memset(mbcp, 0, sizeof(struct mbox_params));
  511. mbcp->in_count = 1;
  512. mbcp->out_count = 2;
  513. mbcp->mbox_in[0] = MB_CMD_GET_FW_STATE;
  514. status = ql_mailbox_command(qdev, mbcp);
  515. if (status)
  516. return status;
  517. if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
  518. QPRINTK(qdev, DRV, ERR,
  519. "Failed Get Firmware State.\n");
  520. status = -EIO;
  521. }
  522. /* If bit zero is set in mbx 1 then the firmware is
  523. * running, but not initialized. This should never
  524. * happen.
  525. */
  526. if (mbcp->mbox_out[1] & 1) {
  527. QPRINTK(qdev, DRV, ERR,
  528. "Firmware waiting for initialization.\n");
  529. status = -EIO;
  530. }
  531. return status;
  532. }
  533. /* Send and ACK mailbox command to the firmware to
  534. * let it continue with the change.
  535. */
  536. int ql_mb_idc_ack(struct ql_adapter *qdev)
  537. {
  538. struct mbox_params mbc;
  539. struct mbox_params *mbcp = &mbc;
  540. int status = 0;
  541. memset(mbcp, 0, sizeof(struct mbox_params));
  542. mbcp->in_count = 5;
  543. mbcp->out_count = 1;
  544. mbcp->mbox_in[0] = MB_CMD_IDC_ACK;
  545. mbcp->mbox_in[1] = qdev->idc_mbc.mbox_out[1];
  546. mbcp->mbox_in[2] = qdev->idc_mbc.mbox_out[2];
  547. mbcp->mbox_in[3] = qdev->idc_mbc.mbox_out[3];
  548. mbcp->mbox_in[4] = qdev->idc_mbc.mbox_out[4];
  549. status = ql_mailbox_command(qdev, mbcp);
  550. if (status)
  551. return status;
  552. if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
  553. QPRINTK(qdev, DRV, ERR,
  554. "Failed IDC ACK send.\n");
  555. status = -EIO;
  556. }
  557. return status;
  558. }
  559. /* Get link settings and maximum frame size settings
  560. * for the current port.
  561. * Most likely will block.
  562. */
  563. static int ql_mb_set_port_cfg(struct ql_adapter *qdev)
  564. {
  565. struct mbox_params mbc;
  566. struct mbox_params *mbcp = &mbc;
  567. int status = 0;
  568. memset(mbcp, 0, sizeof(struct mbox_params));
  569. mbcp->in_count = 3;
  570. mbcp->out_count = 1;
  571. mbcp->mbox_in[0] = MB_CMD_SET_PORT_CFG;
  572. mbcp->mbox_in[1] = qdev->link_config;
  573. mbcp->mbox_in[2] = qdev->max_frame_size;
  574. status = ql_mailbox_command(qdev, mbcp);
  575. if (status)
  576. return status;
  577. if (mbcp->mbox_out[0] == MB_CMD_STS_INTRMDT) {
  578. QPRINTK(qdev, DRV, ERR,
  579. "Port Config sent, wait for IDC.\n");
  580. } else if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
  581. QPRINTK(qdev, DRV, ERR,
  582. "Failed Set Port Configuration.\n");
  583. status = -EIO;
  584. }
  585. return status;
  586. }
  587. /* Get link settings and maximum frame size settings
  588. * for the current port.
  589. * Most likely will block.
  590. */
  591. static int ql_mb_get_port_cfg(struct ql_adapter *qdev)
  592. {
  593. struct mbox_params mbc;
  594. struct mbox_params *mbcp = &mbc;
  595. int status = 0;
  596. memset(mbcp, 0, sizeof(struct mbox_params));
  597. mbcp->in_count = 1;
  598. mbcp->out_count = 3;
  599. mbcp->mbox_in[0] = MB_CMD_GET_PORT_CFG;
  600. status = ql_mailbox_command(qdev, mbcp);
  601. if (status)
  602. return status;
  603. if (mbcp->mbox_out[0] != MB_CMD_STS_GOOD) {
  604. QPRINTK(qdev, DRV, ERR,
  605. "Failed Get Port Configuration.\n");
  606. status = -EIO;
  607. } else {
  608. QPRINTK(qdev, DRV, DEBUG,
  609. "Passed Get Port Configuration.\n");
  610. qdev->link_config = mbcp->mbox_out[1];
  611. qdev->max_frame_size = mbcp->mbox_out[2];
  612. }
  613. return status;
  614. }
  615. /* IDC - Inter Device Communication...
  616. * Some firmware commands require consent of adjacent FCOE
  617. * function. This function waits for the OK, or a
  618. * counter-request for a little more time.i
  619. * The firmware will complete the request if the other
  620. * function doesn't respond.
  621. */
  622. static int ql_idc_wait(struct ql_adapter *qdev)
  623. {
  624. int status = -ETIMEDOUT;
  625. long wait_time = 1 * HZ;
  626. struct mbox_params *mbcp = &qdev->idc_mbc;
  627. do {
  628. /* Wait here for the command to complete
  629. * via the IDC process.
  630. */
  631. wait_time =
  632. wait_for_completion_timeout(&qdev->ide_completion,
  633. wait_time);
  634. if (!wait_time) {
  635. QPRINTK(qdev, DRV, ERR,
  636. "IDC Timeout.\n");
  637. break;
  638. }
  639. /* Now examine the response from the IDC process.
  640. * We might have a good completion or a request for
  641. * more wait time.
  642. */
  643. if (mbcp->mbox_out[0] == AEN_IDC_EXT) {
  644. QPRINTK(qdev, DRV, ERR,
  645. "IDC Time Extension from function.\n");
  646. wait_time += (mbcp->mbox_out[1] >> 8) & 0x0000000f;
  647. } else if (mbcp->mbox_out[0] == AEN_IDC_CMPLT) {
  648. QPRINTK(qdev, DRV, ERR,
  649. "IDC Success.\n");
  650. status = 0;
  651. break;
  652. } else {
  653. QPRINTK(qdev, DRV, ERR,
  654. "IDC: Invalid State 0x%.04x.\n",
  655. mbcp->mbox_out[0]);
  656. status = -EIO;
  657. break;
  658. }
  659. } while (wait_time);
  660. return status;
  661. }
  662. int ql_mb_set_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 control)
  663. {
  664. struct mbox_params mbc;
  665. struct mbox_params *mbcp = &mbc;
  666. int status;
  667. memset(mbcp, 0, sizeof(struct mbox_params));
  668. mbcp->in_count = 1;
  669. mbcp->out_count = 2;
  670. mbcp->mbox_in[0] = MB_CMD_SET_MGMNT_TFK_CTL;
  671. mbcp->mbox_in[1] = control;
  672. status = ql_mailbox_command(qdev, mbcp);
  673. if (status)
  674. return status;
  675. if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD)
  676. return status;
  677. if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
  678. QPRINTK(qdev, DRV, ERR,
  679. "Command not supported by firmware.\n");
  680. status = -EINVAL;
  681. } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
  682. /* This indicates that the firmware is
  683. * already in the state we are trying to
  684. * change it to.
  685. */
  686. QPRINTK(qdev, DRV, ERR,
  687. "Command parameters make no change.\n");
  688. }
  689. return status;
  690. }
  691. /* Returns a negative error code or the mailbox command status. */
  692. static int ql_mb_get_mgmnt_traffic_ctl(struct ql_adapter *qdev, u32 *control)
  693. {
  694. struct mbox_params mbc;
  695. struct mbox_params *mbcp = &mbc;
  696. int status;
  697. memset(mbcp, 0, sizeof(struct mbox_params));
  698. *control = 0;
  699. mbcp->in_count = 1;
  700. mbcp->out_count = 1;
  701. mbcp->mbox_in[0] = MB_CMD_GET_MGMNT_TFK_CTL;
  702. status = ql_mailbox_command(qdev, mbcp);
  703. if (status)
  704. return status;
  705. if (mbcp->mbox_out[0] == MB_CMD_STS_GOOD) {
  706. *control = mbcp->mbox_in[1];
  707. return status;
  708. }
  709. if (mbcp->mbox_out[0] == MB_CMD_STS_INVLD_CMD) {
  710. QPRINTK(qdev, DRV, ERR,
  711. "Command not supported by firmware.\n");
  712. status = -EINVAL;
  713. } else if (mbcp->mbox_out[0] == MB_CMD_STS_ERR) {
  714. QPRINTK(qdev, DRV, ERR,
  715. "Failed to get MPI traffic control.\n");
  716. status = -EIO;
  717. }
  718. return status;
  719. }
  720. int ql_wait_fifo_empty(struct ql_adapter *qdev)
  721. {
  722. int count = 5;
  723. u32 mgmnt_fifo_empty;
  724. u32 nic_fifo_empty;
  725. do {
  726. nic_fifo_empty = ql_read32(qdev, STS) & STS_NFE;
  727. ql_mb_get_mgmnt_traffic_ctl(qdev, &mgmnt_fifo_empty);
  728. mgmnt_fifo_empty &= MB_GET_MPI_TFK_FIFO_EMPTY;
  729. if (nic_fifo_empty && mgmnt_fifo_empty)
  730. return 0;
  731. msleep(100);
  732. } while (count-- > 0);
  733. return -ETIMEDOUT;
  734. }
  735. /* API called in work thread context to set new TX/RX
  736. * maximum frame size values to match MTU.
  737. */
  738. static int ql_set_port_cfg(struct ql_adapter *qdev)
  739. {
  740. int status;
  741. rtnl_lock();
  742. status = ql_mb_set_port_cfg(qdev);
  743. rtnl_unlock();
  744. if (status)
  745. return status;
  746. status = ql_idc_wait(qdev);
  747. return status;
  748. }
  749. /* The following routines are worker threads that process
  750. * events that may sleep waiting for completion.
  751. */
  752. /* This thread gets the maximum TX and RX frame size values
  753. * from the firmware and, if necessary, changes them to match
  754. * the MTU setting.
  755. */
  756. void ql_mpi_port_cfg_work(struct work_struct *work)
  757. {
  758. struct ql_adapter *qdev =
  759. container_of(work, struct ql_adapter, mpi_port_cfg_work.work);
  760. int status;
  761. rtnl_lock();
  762. status = ql_mb_get_port_cfg(qdev);
  763. rtnl_unlock();
  764. if (status) {
  765. QPRINTK(qdev, DRV, ERR,
  766. "Bug: Failed to get port config data.\n");
  767. goto err;
  768. }
  769. if (qdev->link_config & CFG_JUMBO_FRAME_SIZE &&
  770. qdev->max_frame_size ==
  771. CFG_DEFAULT_MAX_FRAME_SIZE)
  772. goto end;
  773. qdev->link_config |= CFG_JUMBO_FRAME_SIZE;
  774. qdev->max_frame_size = CFG_DEFAULT_MAX_FRAME_SIZE;
  775. status = ql_set_port_cfg(qdev);
  776. if (status) {
  777. QPRINTK(qdev, DRV, ERR,
  778. "Bug: Failed to set port config data.\n");
  779. goto err;
  780. }
  781. end:
  782. clear_bit(QL_PORT_CFG, &qdev->flags);
  783. return;
  784. err:
  785. ql_queue_fw_error(qdev);
  786. goto end;
  787. }
  788. /* Process an inter-device request. This is issues by
  789. * the firmware in response to another function requesting
  790. * a change to the port. We set a flag to indicate a change
  791. * has been made and then send a mailbox command ACKing
  792. * the change request.
  793. */
  794. void ql_mpi_idc_work(struct work_struct *work)
  795. {
  796. struct ql_adapter *qdev =
  797. container_of(work, struct ql_adapter, mpi_idc_work.work);
  798. int status;
  799. struct mbox_params *mbcp = &qdev->idc_mbc;
  800. u32 aen;
  801. aen = mbcp->mbox_out[1] >> 16;
  802. switch (aen) {
  803. default:
  804. QPRINTK(qdev, DRV, ERR,
  805. "Bug: Unhandled IDC action.\n");
  806. break;
  807. case MB_CMD_PORT_RESET:
  808. case MB_CMD_SET_PORT_CFG:
  809. case MB_CMD_STOP_FW:
  810. ql_link_off(qdev);
  811. /* Signal the resulting link up AEN
  812. * that the frame routing and mac addr
  813. * needs to be set.
  814. * */
  815. set_bit(QL_CAM_RT_SET, &qdev->flags);
  816. rtnl_lock();
  817. status = ql_mb_idc_ack(qdev);
  818. rtnl_unlock();
  819. if (status) {
  820. QPRINTK(qdev, DRV, ERR,
  821. "Bug: No pending IDC!\n");
  822. }
  823. }
  824. }
  825. void ql_mpi_work(struct work_struct *work)
  826. {
  827. struct ql_adapter *qdev =
  828. container_of(work, struct ql_adapter, mpi_work.work);
  829. struct mbox_params mbc;
  830. struct mbox_params *mbcp = &mbc;
  831. int err = 0;
  832. rtnl_lock();
  833. /* Begin polled mode for MPI */
  834. ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16));
  835. while (ql_read32(qdev, STS) & STS_PI) {
  836. memset(mbcp, 0, sizeof(struct mbox_params));
  837. mbcp->out_count = 1;
  838. /* Don't continue if an async event
  839. * did not complete properly.
  840. */
  841. err = ql_mpi_handler(qdev, mbcp);
  842. if (err)
  843. break;
  844. }
  845. /* End polled mode for MPI */
  846. ql_write32(qdev, INTR_MASK, (INTR_MASK_PI << 16) | INTR_MASK_PI);
  847. rtnl_unlock();
  848. ql_enable_completion_interrupt(qdev, 0);
  849. }
  850. void ql_mpi_reset_work(struct work_struct *work)
  851. {
  852. struct ql_adapter *qdev =
  853. container_of(work, struct ql_adapter, mpi_reset_work.work);
  854. cancel_delayed_work_sync(&qdev->mpi_work);
  855. cancel_delayed_work_sync(&qdev->mpi_port_cfg_work);
  856. cancel_delayed_work_sync(&qdev->mpi_idc_work);
  857. ql_soft_reset_mpi_risc(qdev);
  858. }