qlge_mpi.c 28 KB

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