qlge_mpi.c 26 KB

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