qlge_mpi.c 30 KB

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