mcdi.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2008-2011 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include <linux/delay.h>
  10. #include "net_driver.h"
  11. #include "nic.h"
  12. #include "io.h"
  13. #include "farch_regs.h"
  14. #include "mcdi_pcol.h"
  15. #include "phy.h"
  16. /**************************************************************************
  17. *
  18. * Management-Controller-to-Driver Interface
  19. *
  20. **************************************************************************
  21. */
  22. #define MCDI_RPC_TIMEOUT (10 * HZ)
  23. /* A reboot/assertion causes the MCDI status word to be set after the
  24. * command word is set or a REBOOT event is sent. If we notice a reboot
  25. * via these mechanisms then wait 10ms for the status word to be set. */
  26. #define MCDI_STATUS_DELAY_US 100
  27. #define MCDI_STATUS_DELAY_COUNT 100
  28. #define MCDI_STATUS_SLEEP_MS \
  29. (MCDI_STATUS_DELAY_US * MCDI_STATUS_DELAY_COUNT / 1000)
  30. #define SEQ_MASK \
  31. EFX_MASK32(EFX_WIDTH(MCDI_HEADER_SEQ))
  32. static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
  33. {
  34. EFX_BUG_ON_PARANOID(!efx->mcdi);
  35. return &efx->mcdi->iface;
  36. }
  37. int efx_mcdi_init(struct efx_nic *efx)
  38. {
  39. struct efx_mcdi_iface *mcdi;
  40. efx->mcdi = kzalloc(sizeof(*efx->mcdi), GFP_KERNEL);
  41. if (!efx->mcdi)
  42. return -ENOMEM;
  43. mcdi = efx_mcdi(efx);
  44. init_waitqueue_head(&mcdi->wq);
  45. spin_lock_init(&mcdi->iface_lock);
  46. atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT);
  47. mcdi->mode = MCDI_MODE_POLL;
  48. (void) efx_mcdi_poll_reboot(efx);
  49. /* Recover from a failed assertion before probing */
  50. return efx_mcdi_handle_assertion(efx);
  51. }
  52. void efx_mcdi_fini(struct efx_nic *efx)
  53. {
  54. BUG_ON(efx->mcdi &&
  55. atomic_read(&efx->mcdi->iface.state) != MCDI_STATE_QUIESCENT);
  56. kfree(efx->mcdi);
  57. }
  58. static void efx_mcdi_copyin(struct efx_nic *efx, unsigned cmd,
  59. const efx_dword_t *inbuf, size_t inlen)
  60. {
  61. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  62. efx_dword_t hdr;
  63. u32 xflags, seqno;
  64. BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
  65. BUG_ON(inlen > MCDI_CTL_SDU_LEN_MAX_V1);
  66. seqno = mcdi->seqno & SEQ_MASK;
  67. xflags = 0;
  68. if (mcdi->mode == MCDI_MODE_EVENTS)
  69. xflags |= MCDI_HEADER_XFLAGS_EVREQ;
  70. EFX_POPULATE_DWORD_6(hdr,
  71. MCDI_HEADER_RESPONSE, 0,
  72. MCDI_HEADER_RESYNC, 1,
  73. MCDI_HEADER_CODE, cmd,
  74. MCDI_HEADER_DATALEN, inlen,
  75. MCDI_HEADER_SEQ, seqno,
  76. MCDI_HEADER_XFLAGS, xflags);
  77. efx->type->mcdi_request(efx, &hdr, 4, inbuf, inlen);
  78. }
  79. static void
  80. efx_mcdi_copyout(struct efx_nic *efx, efx_dword_t *outbuf, size_t outlen)
  81. {
  82. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  83. BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
  84. BUG_ON(outlen > MCDI_CTL_SDU_LEN_MAX_V1);
  85. efx->type->mcdi_read_response(efx, outbuf, 4, outlen);
  86. }
  87. static int efx_mcdi_errno(unsigned int mcdi_err)
  88. {
  89. switch (mcdi_err) {
  90. case 0:
  91. return 0;
  92. #define TRANSLATE_ERROR(name) \
  93. case MC_CMD_ERR_ ## name: \
  94. return -name;
  95. TRANSLATE_ERROR(ENOENT);
  96. TRANSLATE_ERROR(EINTR);
  97. TRANSLATE_ERROR(EACCES);
  98. TRANSLATE_ERROR(EBUSY);
  99. TRANSLATE_ERROR(EINVAL);
  100. TRANSLATE_ERROR(EDEADLK);
  101. TRANSLATE_ERROR(ENOSYS);
  102. TRANSLATE_ERROR(ETIME);
  103. #undef TRANSLATE_ERROR
  104. default:
  105. return -EIO;
  106. }
  107. }
  108. static int efx_mcdi_poll(struct efx_nic *efx)
  109. {
  110. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  111. unsigned long time, finish;
  112. unsigned int respseq, respcmd, error;
  113. unsigned int spins;
  114. efx_dword_t reg;
  115. int rc;
  116. /* Check for a reboot atomically with respect to efx_mcdi_copyout() */
  117. rc = efx_mcdi_poll_reboot(efx);
  118. if (rc)
  119. goto out;
  120. /* Poll for completion. Poll quickly (once a us) for the 1st jiffy,
  121. * because generally mcdi responses are fast. After that, back off
  122. * and poll once a jiffy (approximately)
  123. */
  124. spins = TICK_USEC;
  125. finish = jiffies + MCDI_RPC_TIMEOUT;
  126. while (1) {
  127. if (spins != 0) {
  128. --spins;
  129. udelay(1);
  130. } else {
  131. schedule_timeout_uninterruptible(1);
  132. }
  133. time = jiffies;
  134. rmb();
  135. if (efx->type->mcdi_poll_response(efx))
  136. break;
  137. if (time_after(time, finish))
  138. return -ETIMEDOUT;
  139. }
  140. efx->type->mcdi_read_response(efx, &reg, 0, 4);
  141. mcdi->resplen = EFX_DWORD_FIELD(reg, MCDI_HEADER_DATALEN);
  142. respseq = EFX_DWORD_FIELD(reg, MCDI_HEADER_SEQ);
  143. respcmd = EFX_DWORD_FIELD(reg, MCDI_HEADER_CODE);
  144. error = EFX_DWORD_FIELD(reg, MCDI_HEADER_ERROR);
  145. if (error && mcdi->resplen == 0) {
  146. netif_err(efx, hw, efx->net_dev, "MC rebooted\n");
  147. rc = -EIO;
  148. } else if ((respseq ^ mcdi->seqno) & SEQ_MASK) {
  149. netif_err(efx, hw, efx->net_dev,
  150. "MC response mismatch tx seq 0x%x rx seq 0x%x\n",
  151. respseq, mcdi->seqno);
  152. rc = -EIO;
  153. } else if (error) {
  154. efx->type->mcdi_read_response(efx, &reg, 4, 4);
  155. rc = efx_mcdi_errno(EFX_DWORD_FIELD(reg, EFX_DWORD_0));
  156. } else
  157. rc = 0;
  158. out:
  159. mcdi->resprc = rc;
  160. if (rc)
  161. mcdi->resplen = 0;
  162. /* Return rc=0 like wait_event_timeout() */
  163. return 0;
  164. }
  165. /* Test and clear MC-rebooted flag for this port/function; reset
  166. * software state as necessary.
  167. */
  168. int efx_mcdi_poll_reboot(struct efx_nic *efx)
  169. {
  170. int rc;
  171. if (!efx->mcdi)
  172. return 0;
  173. rc = efx->type->mcdi_poll_reboot(efx);
  174. if (!rc)
  175. return 0;
  176. /* MAC statistics have been cleared on the NIC; clear our copy
  177. * so that efx_update_diff_stat() can continue to work.
  178. */
  179. memset(&efx->mac_stats, 0, sizeof(efx->mac_stats));
  180. return rc;
  181. }
  182. static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi)
  183. {
  184. /* Wait until the interface becomes QUIESCENT and we win the race
  185. * to mark it RUNNING. */
  186. wait_event(mcdi->wq,
  187. atomic_cmpxchg(&mcdi->state,
  188. MCDI_STATE_QUIESCENT,
  189. MCDI_STATE_RUNNING)
  190. == MCDI_STATE_QUIESCENT);
  191. }
  192. static int efx_mcdi_await_completion(struct efx_nic *efx)
  193. {
  194. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  195. if (wait_event_timeout(
  196. mcdi->wq,
  197. atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED,
  198. MCDI_RPC_TIMEOUT) == 0)
  199. return -ETIMEDOUT;
  200. /* Check if efx_mcdi_set_mode() switched us back to polled completions.
  201. * In which case, poll for completions directly. If efx_mcdi_ev_cpl()
  202. * completed the request first, then we'll just end up completing the
  203. * request again, which is safe.
  204. *
  205. * We need an smp_rmb() to synchronise with efx_mcdi_mode_poll(), which
  206. * wait_event_timeout() implicitly provides.
  207. */
  208. if (mcdi->mode == MCDI_MODE_POLL)
  209. return efx_mcdi_poll(efx);
  210. return 0;
  211. }
  212. static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
  213. {
  214. /* If the interface is RUNNING, then move to COMPLETED and wake any
  215. * waiters. If the interface isn't in RUNNING then we've received a
  216. * duplicate completion after we've already transitioned back to
  217. * QUIESCENT. [A subsequent invocation would increment seqno, so would
  218. * have failed the seqno check].
  219. */
  220. if (atomic_cmpxchg(&mcdi->state,
  221. MCDI_STATE_RUNNING,
  222. MCDI_STATE_COMPLETED) == MCDI_STATE_RUNNING) {
  223. wake_up(&mcdi->wq);
  224. return true;
  225. }
  226. return false;
  227. }
  228. static void efx_mcdi_release(struct efx_mcdi_iface *mcdi)
  229. {
  230. atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT);
  231. wake_up(&mcdi->wq);
  232. }
  233. static void efx_mcdi_ev_cpl(struct efx_nic *efx, unsigned int seqno,
  234. unsigned int datalen, unsigned int mcdi_err)
  235. {
  236. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  237. bool wake = false;
  238. spin_lock(&mcdi->iface_lock);
  239. if ((seqno ^ mcdi->seqno) & SEQ_MASK) {
  240. if (mcdi->credits)
  241. /* The request has been cancelled */
  242. --mcdi->credits;
  243. else
  244. netif_err(efx, hw, efx->net_dev,
  245. "MC response mismatch tx seq 0x%x rx "
  246. "seq 0x%x\n", seqno, mcdi->seqno);
  247. } else {
  248. mcdi->resprc = efx_mcdi_errno(mcdi_err);
  249. mcdi->resplen = datalen;
  250. wake = true;
  251. }
  252. spin_unlock(&mcdi->iface_lock);
  253. if (wake)
  254. efx_mcdi_complete(mcdi);
  255. }
  256. int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd,
  257. const efx_dword_t *inbuf, size_t inlen,
  258. efx_dword_t *outbuf, size_t outlen,
  259. size_t *outlen_actual)
  260. {
  261. efx_mcdi_rpc_start(efx, cmd, inbuf, inlen);
  262. return efx_mcdi_rpc_finish(efx, cmd, inlen,
  263. outbuf, outlen, outlen_actual);
  264. }
  265. void efx_mcdi_rpc_start(struct efx_nic *efx, unsigned cmd,
  266. const efx_dword_t *inbuf, size_t inlen)
  267. {
  268. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  269. efx_mcdi_acquire(mcdi);
  270. /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
  271. spin_lock_bh(&mcdi->iface_lock);
  272. ++mcdi->seqno;
  273. spin_unlock_bh(&mcdi->iface_lock);
  274. efx_mcdi_copyin(efx, cmd, inbuf, inlen);
  275. }
  276. int efx_mcdi_rpc_finish(struct efx_nic *efx, unsigned cmd, size_t inlen,
  277. efx_dword_t *outbuf, size_t outlen,
  278. size_t *outlen_actual)
  279. {
  280. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  281. int rc;
  282. if (mcdi->mode == MCDI_MODE_POLL)
  283. rc = efx_mcdi_poll(efx);
  284. else
  285. rc = efx_mcdi_await_completion(efx);
  286. if (rc != 0) {
  287. /* Close the race with efx_mcdi_ev_cpl() executing just too late
  288. * and completing a request we've just cancelled, by ensuring
  289. * that the seqno check therein fails.
  290. */
  291. spin_lock_bh(&mcdi->iface_lock);
  292. ++mcdi->seqno;
  293. ++mcdi->credits;
  294. spin_unlock_bh(&mcdi->iface_lock);
  295. netif_err(efx, hw, efx->net_dev,
  296. "MC command 0x%x inlen %d mode %d timed out\n",
  297. cmd, (int)inlen, mcdi->mode);
  298. } else {
  299. size_t resplen;
  300. /* At the very least we need a memory barrier here to ensure
  301. * we pick up changes from efx_mcdi_ev_cpl(). Protect against
  302. * a spurious efx_mcdi_ev_cpl() running concurrently by
  303. * acquiring the iface_lock. */
  304. spin_lock_bh(&mcdi->iface_lock);
  305. rc = mcdi->resprc;
  306. resplen = mcdi->resplen;
  307. spin_unlock_bh(&mcdi->iface_lock);
  308. BUG_ON(rc > 0);
  309. if (rc == 0) {
  310. efx_mcdi_copyout(efx, outbuf,
  311. min(outlen, mcdi->resplen));
  312. if (outlen_actual != NULL)
  313. *outlen_actual = resplen;
  314. } else if (cmd == MC_CMD_REBOOT && rc == -EIO)
  315. ; /* Don't reset if MC_CMD_REBOOT returns EIO */
  316. else if (rc == -EIO || rc == -EINTR) {
  317. netif_err(efx, hw, efx->net_dev, "MC fatal error %d\n",
  318. -rc);
  319. efx_schedule_reset(efx, RESET_TYPE_MC_FAILURE);
  320. } else
  321. netif_dbg(efx, hw, efx->net_dev,
  322. "MC command 0x%x inlen %d failed rc=%d\n",
  323. cmd, (int)inlen, -rc);
  324. if (rc == -EIO || rc == -EINTR) {
  325. msleep(MCDI_STATUS_SLEEP_MS);
  326. efx_mcdi_poll_reboot(efx);
  327. }
  328. }
  329. efx_mcdi_release(mcdi);
  330. return rc;
  331. }
  332. void efx_mcdi_mode_poll(struct efx_nic *efx)
  333. {
  334. struct efx_mcdi_iface *mcdi;
  335. if (!efx->mcdi)
  336. return;
  337. mcdi = efx_mcdi(efx);
  338. if (mcdi->mode == MCDI_MODE_POLL)
  339. return;
  340. /* We can switch from event completion to polled completion, because
  341. * mcdi requests are always completed in shared memory. We do this by
  342. * switching the mode to POLL'd then completing the request.
  343. * efx_mcdi_await_completion() will then call efx_mcdi_poll().
  344. *
  345. * We need an smp_wmb() to synchronise with efx_mcdi_await_completion(),
  346. * which efx_mcdi_complete() provides for us.
  347. */
  348. mcdi->mode = MCDI_MODE_POLL;
  349. efx_mcdi_complete(mcdi);
  350. }
  351. void efx_mcdi_mode_event(struct efx_nic *efx)
  352. {
  353. struct efx_mcdi_iface *mcdi;
  354. if (!efx->mcdi)
  355. return;
  356. mcdi = efx_mcdi(efx);
  357. if (mcdi->mode == MCDI_MODE_EVENTS)
  358. return;
  359. /* We can't switch from polled to event completion in the middle of a
  360. * request, because the completion method is specified in the request.
  361. * So acquire the interface to serialise the requestors. We don't need
  362. * to acquire the iface_lock to change the mode here, but we do need a
  363. * write memory barrier ensure that efx_mcdi_rpc() sees it, which
  364. * efx_mcdi_acquire() provides.
  365. */
  366. efx_mcdi_acquire(mcdi);
  367. mcdi->mode = MCDI_MODE_EVENTS;
  368. efx_mcdi_release(mcdi);
  369. }
  370. static void efx_mcdi_ev_death(struct efx_nic *efx, int rc)
  371. {
  372. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  373. /* If there is an outstanding MCDI request, it has been terminated
  374. * either by a BADASSERT or REBOOT event. If the mcdi interface is
  375. * in polled mode, then do nothing because the MC reboot handler will
  376. * set the header correctly. However, if the mcdi interface is waiting
  377. * for a CMDDONE event it won't receive it [and since all MCDI events
  378. * are sent to the same queue, we can't be racing with
  379. * efx_mcdi_ev_cpl()]
  380. *
  381. * There's a race here with efx_mcdi_rpc(), because we might receive
  382. * a REBOOT event *before* the request has been copied out. In polled
  383. * mode (during startup) this is irrelevant, because efx_mcdi_complete()
  384. * is ignored. In event mode, this condition is just an edge-case of
  385. * receiving a REBOOT event after posting the MCDI request. Did the mc
  386. * reboot before or after the copyout? The best we can do always is
  387. * just return failure.
  388. */
  389. spin_lock(&mcdi->iface_lock);
  390. if (efx_mcdi_complete(mcdi)) {
  391. if (mcdi->mode == MCDI_MODE_EVENTS) {
  392. mcdi->resprc = rc;
  393. mcdi->resplen = 0;
  394. ++mcdi->credits;
  395. }
  396. } else {
  397. int count;
  398. /* Nobody was waiting for an MCDI request, so trigger a reset */
  399. efx_schedule_reset(efx, RESET_TYPE_MC_FAILURE);
  400. /* Consume the status word since efx_mcdi_rpc_finish() won't */
  401. for (count = 0; count < MCDI_STATUS_DELAY_COUNT; ++count) {
  402. if (efx_mcdi_poll_reboot(efx))
  403. break;
  404. udelay(MCDI_STATUS_DELAY_US);
  405. }
  406. }
  407. spin_unlock(&mcdi->iface_lock);
  408. }
  409. /* Called from falcon_process_eventq for MCDI events */
  410. void efx_mcdi_process_event(struct efx_channel *channel,
  411. efx_qword_t *event)
  412. {
  413. struct efx_nic *efx = channel->efx;
  414. int code = EFX_QWORD_FIELD(*event, MCDI_EVENT_CODE);
  415. u32 data = EFX_QWORD_FIELD(*event, MCDI_EVENT_DATA);
  416. switch (code) {
  417. case MCDI_EVENT_CODE_BADSSERT:
  418. netif_err(efx, hw, efx->net_dev,
  419. "MC watchdog or assertion failure at 0x%x\n", data);
  420. efx_mcdi_ev_death(efx, -EINTR);
  421. break;
  422. case MCDI_EVENT_CODE_PMNOTICE:
  423. netif_info(efx, wol, efx->net_dev, "MCDI PM event.\n");
  424. break;
  425. case MCDI_EVENT_CODE_CMDDONE:
  426. efx_mcdi_ev_cpl(efx,
  427. MCDI_EVENT_FIELD(*event, CMDDONE_SEQ),
  428. MCDI_EVENT_FIELD(*event, CMDDONE_DATALEN),
  429. MCDI_EVENT_FIELD(*event, CMDDONE_ERRNO));
  430. break;
  431. case MCDI_EVENT_CODE_LINKCHANGE:
  432. efx_mcdi_process_link_change(efx, event);
  433. break;
  434. case MCDI_EVENT_CODE_SENSOREVT:
  435. efx_mcdi_sensor_event(efx, event);
  436. break;
  437. case MCDI_EVENT_CODE_SCHEDERR:
  438. netif_info(efx, hw, efx->net_dev,
  439. "MC Scheduler error address=0x%x\n", data);
  440. break;
  441. case MCDI_EVENT_CODE_REBOOT:
  442. netif_info(efx, hw, efx->net_dev, "MC Reboot\n");
  443. efx_mcdi_ev_death(efx, -EIO);
  444. break;
  445. case MCDI_EVENT_CODE_MAC_STATS_DMA:
  446. /* MAC stats are gather lazily. We can ignore this. */
  447. break;
  448. case MCDI_EVENT_CODE_FLR:
  449. efx_sriov_flr(efx, MCDI_EVENT_FIELD(*event, FLR_VF));
  450. break;
  451. case MCDI_EVENT_CODE_PTP_RX:
  452. case MCDI_EVENT_CODE_PTP_FAULT:
  453. case MCDI_EVENT_CODE_PTP_PPS:
  454. efx_ptp_event(efx, event);
  455. break;
  456. default:
  457. netif_err(efx, hw, efx->net_dev, "Unknown MCDI event 0x%x\n",
  458. code);
  459. }
  460. }
  461. /**************************************************************************
  462. *
  463. * Specific request functions
  464. *
  465. **************************************************************************
  466. */
  467. void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len)
  468. {
  469. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_VERSION_OUT_LEN);
  470. size_t outlength;
  471. const __le16 *ver_words;
  472. int rc;
  473. BUILD_BUG_ON(MC_CMD_GET_VERSION_IN_LEN != 0);
  474. rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, NULL, 0,
  475. outbuf, sizeof(outbuf), &outlength);
  476. if (rc)
  477. goto fail;
  478. if (outlength < MC_CMD_GET_VERSION_OUT_LEN) {
  479. rc = -EIO;
  480. goto fail;
  481. }
  482. ver_words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_OUT_VERSION);
  483. snprintf(buf, len, "%u.%u.%u.%u",
  484. le16_to_cpu(ver_words[0]), le16_to_cpu(ver_words[1]),
  485. le16_to_cpu(ver_words[2]), le16_to_cpu(ver_words[3]));
  486. return;
  487. fail:
  488. netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  489. buf[0] = 0;
  490. }
  491. int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
  492. bool *was_attached)
  493. {
  494. MCDI_DECLARE_BUF(inbuf, MC_CMD_DRV_ATTACH_IN_LEN);
  495. MCDI_DECLARE_BUF(outbuf, MC_CMD_DRV_ATTACH_OUT_LEN);
  496. size_t outlen;
  497. int rc;
  498. MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_NEW_STATE,
  499. driver_operating ? 1 : 0);
  500. MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_UPDATE, 1);
  501. rc = efx_mcdi_rpc(efx, MC_CMD_DRV_ATTACH, inbuf, sizeof(inbuf),
  502. outbuf, sizeof(outbuf), &outlen);
  503. if (rc)
  504. goto fail;
  505. if (outlen < MC_CMD_DRV_ATTACH_OUT_LEN) {
  506. rc = -EIO;
  507. goto fail;
  508. }
  509. if (was_attached != NULL)
  510. *was_attached = MCDI_DWORD(outbuf, DRV_ATTACH_OUT_OLD_STATE);
  511. return 0;
  512. fail:
  513. netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  514. return rc;
  515. }
  516. int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
  517. u16 *fw_subtype_list, u32 *capabilities)
  518. {
  519. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_BOARD_CFG_OUT_LENMAX);
  520. size_t outlen, i;
  521. int port_num = efx_port_num(efx);
  522. int rc;
  523. BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN != 0);
  524. rc = efx_mcdi_rpc(efx, MC_CMD_GET_BOARD_CFG, NULL, 0,
  525. outbuf, sizeof(outbuf), &outlen);
  526. if (rc)
  527. goto fail;
  528. if (outlen < MC_CMD_GET_BOARD_CFG_OUT_LENMIN) {
  529. rc = -EIO;
  530. goto fail;
  531. }
  532. if (mac_address)
  533. memcpy(mac_address,
  534. port_num ?
  535. MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1) :
  536. MCDI_PTR(outbuf, GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0),
  537. ETH_ALEN);
  538. if (fw_subtype_list) {
  539. for (i = 0;
  540. i < MCDI_VAR_ARRAY_LEN(outlen,
  541. GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST);
  542. i++)
  543. fw_subtype_list[i] = MCDI_ARRAY_WORD(
  544. outbuf, GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST, i);
  545. for (; i < MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MAXNUM; i++)
  546. fw_subtype_list[i] = 0;
  547. }
  548. if (capabilities) {
  549. if (port_num)
  550. *capabilities = MCDI_DWORD(outbuf,
  551. GET_BOARD_CFG_OUT_CAPABILITIES_PORT1);
  552. else
  553. *capabilities = MCDI_DWORD(outbuf,
  554. GET_BOARD_CFG_OUT_CAPABILITIES_PORT0);
  555. }
  556. return 0;
  557. fail:
  558. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d len=%d\n",
  559. __func__, rc, (int)outlen);
  560. return rc;
  561. }
  562. int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq)
  563. {
  564. MCDI_DECLARE_BUF(inbuf, MC_CMD_LOG_CTRL_IN_LEN);
  565. u32 dest = 0;
  566. int rc;
  567. if (uart)
  568. dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_UART;
  569. if (evq)
  570. dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ;
  571. MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST, dest);
  572. MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST_EVQ, dest_evq);
  573. BUILD_BUG_ON(MC_CMD_LOG_CTRL_OUT_LEN != 0);
  574. rc = efx_mcdi_rpc(efx, MC_CMD_LOG_CTRL, inbuf, sizeof(inbuf),
  575. NULL, 0, NULL);
  576. if (rc)
  577. goto fail;
  578. return 0;
  579. fail:
  580. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  581. return rc;
  582. }
  583. int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out)
  584. {
  585. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_TYPES_OUT_LEN);
  586. size_t outlen;
  587. int rc;
  588. BUILD_BUG_ON(MC_CMD_NVRAM_TYPES_IN_LEN != 0);
  589. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TYPES, NULL, 0,
  590. outbuf, sizeof(outbuf), &outlen);
  591. if (rc)
  592. goto fail;
  593. if (outlen < MC_CMD_NVRAM_TYPES_OUT_LEN) {
  594. rc = -EIO;
  595. goto fail;
  596. }
  597. *nvram_types_out = MCDI_DWORD(outbuf, NVRAM_TYPES_OUT_TYPES);
  598. return 0;
  599. fail:
  600. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  601. __func__, rc);
  602. return rc;
  603. }
  604. int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
  605. size_t *size_out, size_t *erase_size_out,
  606. bool *protected_out)
  607. {
  608. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_INFO_IN_LEN);
  609. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_INFO_OUT_LEN);
  610. size_t outlen;
  611. int rc;
  612. MCDI_SET_DWORD(inbuf, NVRAM_INFO_IN_TYPE, type);
  613. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_INFO, inbuf, sizeof(inbuf),
  614. outbuf, sizeof(outbuf), &outlen);
  615. if (rc)
  616. goto fail;
  617. if (outlen < MC_CMD_NVRAM_INFO_OUT_LEN) {
  618. rc = -EIO;
  619. goto fail;
  620. }
  621. *size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_SIZE);
  622. *erase_size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_ERASESIZE);
  623. *protected_out = !!(MCDI_DWORD(outbuf, NVRAM_INFO_OUT_FLAGS) &
  624. (1 << MC_CMD_NVRAM_INFO_OUT_PROTECTED_LBN));
  625. return 0;
  626. fail:
  627. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  628. return rc;
  629. }
  630. int efx_mcdi_nvram_update_start(struct efx_nic *efx, unsigned int type)
  631. {
  632. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_UPDATE_START_IN_LEN);
  633. int rc;
  634. MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_START_IN_TYPE, type);
  635. BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_START_OUT_LEN != 0);
  636. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_START, inbuf, sizeof(inbuf),
  637. NULL, 0, NULL);
  638. if (rc)
  639. goto fail;
  640. return 0;
  641. fail:
  642. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  643. return rc;
  644. }
  645. int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
  646. loff_t offset, u8 *buffer, size_t length)
  647. {
  648. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_READ_IN_LEN);
  649. MCDI_DECLARE_BUF(outbuf,
  650. MC_CMD_NVRAM_READ_OUT_LEN(EFX_MCDI_NVRAM_LEN_MAX));
  651. size_t outlen;
  652. int rc;
  653. MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_TYPE, type);
  654. MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_OFFSET, offset);
  655. MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_LENGTH, length);
  656. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_READ, inbuf, sizeof(inbuf),
  657. outbuf, sizeof(outbuf), &outlen);
  658. if (rc)
  659. goto fail;
  660. memcpy(buffer, MCDI_PTR(outbuf, NVRAM_READ_OUT_READ_BUFFER), length);
  661. return 0;
  662. fail:
  663. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  664. return rc;
  665. }
  666. int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
  667. loff_t offset, const u8 *buffer, size_t length)
  668. {
  669. MCDI_DECLARE_BUF(inbuf,
  670. MC_CMD_NVRAM_WRITE_IN_LEN(EFX_MCDI_NVRAM_LEN_MAX));
  671. int rc;
  672. MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_TYPE, type);
  673. MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_OFFSET, offset);
  674. MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_LENGTH, length);
  675. memcpy(MCDI_PTR(inbuf, NVRAM_WRITE_IN_WRITE_BUFFER), buffer, length);
  676. BUILD_BUG_ON(MC_CMD_NVRAM_WRITE_OUT_LEN != 0);
  677. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_WRITE, inbuf,
  678. ALIGN(MC_CMD_NVRAM_WRITE_IN_LEN(length), 4),
  679. NULL, 0, NULL);
  680. if (rc)
  681. goto fail;
  682. return 0;
  683. fail:
  684. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  685. return rc;
  686. }
  687. int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
  688. loff_t offset, size_t length)
  689. {
  690. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_ERASE_IN_LEN);
  691. int rc;
  692. MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_TYPE, type);
  693. MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_OFFSET, offset);
  694. MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_LENGTH, length);
  695. BUILD_BUG_ON(MC_CMD_NVRAM_ERASE_OUT_LEN != 0);
  696. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_ERASE, inbuf, sizeof(inbuf),
  697. NULL, 0, NULL);
  698. if (rc)
  699. goto fail;
  700. return 0;
  701. fail:
  702. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  703. return rc;
  704. }
  705. int efx_mcdi_nvram_update_finish(struct efx_nic *efx, unsigned int type)
  706. {
  707. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN);
  708. int rc;
  709. MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_FINISH_IN_TYPE, type);
  710. BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN != 0);
  711. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_FINISH, inbuf, sizeof(inbuf),
  712. NULL, 0, NULL);
  713. if (rc)
  714. goto fail;
  715. return 0;
  716. fail:
  717. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  718. return rc;
  719. }
  720. static int efx_mcdi_nvram_test(struct efx_nic *efx, unsigned int type)
  721. {
  722. MCDI_DECLARE_BUF(inbuf, MC_CMD_NVRAM_TEST_IN_LEN);
  723. MCDI_DECLARE_BUF(outbuf, MC_CMD_NVRAM_TEST_OUT_LEN);
  724. int rc;
  725. MCDI_SET_DWORD(inbuf, NVRAM_TEST_IN_TYPE, type);
  726. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TEST, inbuf, sizeof(inbuf),
  727. outbuf, sizeof(outbuf), NULL);
  728. if (rc)
  729. return rc;
  730. switch (MCDI_DWORD(outbuf, NVRAM_TEST_OUT_RESULT)) {
  731. case MC_CMD_NVRAM_TEST_PASS:
  732. case MC_CMD_NVRAM_TEST_NOTSUPP:
  733. return 0;
  734. default:
  735. return -EIO;
  736. }
  737. }
  738. int efx_mcdi_nvram_test_all(struct efx_nic *efx)
  739. {
  740. u32 nvram_types;
  741. unsigned int type;
  742. int rc;
  743. rc = efx_mcdi_nvram_types(efx, &nvram_types);
  744. if (rc)
  745. goto fail1;
  746. type = 0;
  747. while (nvram_types != 0) {
  748. if (nvram_types & 1) {
  749. rc = efx_mcdi_nvram_test(efx, type);
  750. if (rc)
  751. goto fail2;
  752. }
  753. type++;
  754. nvram_types >>= 1;
  755. }
  756. return 0;
  757. fail2:
  758. netif_err(efx, hw, efx->net_dev, "%s: failed type=%u\n",
  759. __func__, type);
  760. fail1:
  761. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  762. return rc;
  763. }
  764. static int efx_mcdi_read_assertion(struct efx_nic *efx)
  765. {
  766. MCDI_DECLARE_BUF(inbuf, MC_CMD_GET_ASSERTS_IN_LEN);
  767. MCDI_DECLARE_BUF(outbuf, MC_CMD_GET_ASSERTS_OUT_LEN);
  768. unsigned int flags, index;
  769. const char *reason;
  770. size_t outlen;
  771. int retry;
  772. int rc;
  773. /* Attempt to read any stored assertion state before we reboot
  774. * the mcfw out of the assertion handler. Retry twice, once
  775. * because a boot-time assertion might cause this command to fail
  776. * with EINTR. And once again because GET_ASSERTS can race with
  777. * MC_CMD_REBOOT running on the other port. */
  778. retry = 2;
  779. do {
  780. MCDI_SET_DWORD(inbuf, GET_ASSERTS_IN_CLEAR, 1);
  781. rc = efx_mcdi_rpc(efx, MC_CMD_GET_ASSERTS,
  782. inbuf, MC_CMD_GET_ASSERTS_IN_LEN,
  783. outbuf, sizeof(outbuf), &outlen);
  784. } while ((rc == -EINTR || rc == -EIO) && retry-- > 0);
  785. if (rc)
  786. return rc;
  787. if (outlen < MC_CMD_GET_ASSERTS_OUT_LEN)
  788. return -EIO;
  789. /* Print out any recorded assertion state */
  790. flags = MCDI_DWORD(outbuf, GET_ASSERTS_OUT_GLOBAL_FLAGS);
  791. if (flags == MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS)
  792. return 0;
  793. reason = (flags == MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL)
  794. ? "system-level assertion"
  795. : (flags == MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL)
  796. ? "thread-level assertion"
  797. : (flags == MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED)
  798. ? "watchdog reset"
  799. : "unknown assertion";
  800. netif_err(efx, hw, efx->net_dev,
  801. "MCPU %s at PC = 0x%.8x in thread 0x%.8x\n", reason,
  802. MCDI_DWORD(outbuf, GET_ASSERTS_OUT_SAVED_PC_OFFS),
  803. MCDI_DWORD(outbuf, GET_ASSERTS_OUT_THREAD_OFFS));
  804. /* Print out the registers */
  805. for (index = 0;
  806. index < MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_NUM;
  807. index++)
  808. netif_err(efx, hw, efx->net_dev, "R%.2d (?): 0x%.8x\n",
  809. 1 + index,
  810. MCDI_ARRAY_DWORD(outbuf, GET_ASSERTS_OUT_GP_REGS_OFFS,
  811. index));
  812. return 0;
  813. }
  814. static void efx_mcdi_exit_assertion(struct efx_nic *efx)
  815. {
  816. MCDI_DECLARE_BUF(inbuf, MC_CMD_REBOOT_IN_LEN);
  817. /* If the MC is running debug firmware, it might now be
  818. * waiting for a debugger to attach, but we just want it to
  819. * reboot. We set a flag that makes the command a no-op if it
  820. * has already done so. We don't know what return code to
  821. * expect (0 or -EIO), so ignore it.
  822. */
  823. BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0);
  824. MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS,
  825. MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION);
  826. (void) efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, MC_CMD_REBOOT_IN_LEN,
  827. NULL, 0, NULL);
  828. }
  829. int efx_mcdi_handle_assertion(struct efx_nic *efx)
  830. {
  831. int rc;
  832. rc = efx_mcdi_read_assertion(efx);
  833. if (rc)
  834. return rc;
  835. efx_mcdi_exit_assertion(efx);
  836. return 0;
  837. }
  838. void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  839. {
  840. MCDI_DECLARE_BUF(inbuf, MC_CMD_SET_ID_LED_IN_LEN);
  841. int rc;
  842. BUILD_BUG_ON(EFX_LED_OFF != MC_CMD_LED_OFF);
  843. BUILD_BUG_ON(EFX_LED_ON != MC_CMD_LED_ON);
  844. BUILD_BUG_ON(EFX_LED_DEFAULT != MC_CMD_LED_DEFAULT);
  845. BUILD_BUG_ON(MC_CMD_SET_ID_LED_OUT_LEN != 0);
  846. MCDI_SET_DWORD(inbuf, SET_ID_LED_IN_STATE, mode);
  847. rc = efx_mcdi_rpc(efx, MC_CMD_SET_ID_LED, inbuf, sizeof(inbuf),
  848. NULL, 0, NULL);
  849. if (rc)
  850. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  851. __func__, rc);
  852. }
  853. static int efx_mcdi_reset_port(struct efx_nic *efx)
  854. {
  855. int rc = efx_mcdi_rpc(efx, MC_CMD_ENTITY_RESET, NULL, 0, NULL, 0, NULL);
  856. if (rc)
  857. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  858. __func__, rc);
  859. return rc;
  860. }
  861. static int efx_mcdi_reset_mc(struct efx_nic *efx)
  862. {
  863. MCDI_DECLARE_BUF(inbuf, MC_CMD_REBOOT_IN_LEN);
  864. int rc;
  865. BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0);
  866. MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS, 0);
  867. rc = efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, sizeof(inbuf),
  868. NULL, 0, NULL);
  869. /* White is black, and up is down */
  870. if (rc == -EIO)
  871. return 0;
  872. if (rc == 0)
  873. rc = -EIO;
  874. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  875. return rc;
  876. }
  877. enum reset_type efx_mcdi_map_reset_reason(enum reset_type reason)
  878. {
  879. return RESET_TYPE_RECOVER_OR_ALL;
  880. }
  881. int efx_mcdi_reset(struct efx_nic *efx, enum reset_type method)
  882. {
  883. int rc;
  884. /* Recover from a failed assertion pre-reset */
  885. rc = efx_mcdi_handle_assertion(efx);
  886. if (rc)
  887. return rc;
  888. if (method == RESET_TYPE_WORLD)
  889. return efx_mcdi_reset_mc(efx);
  890. else
  891. return efx_mcdi_reset_port(efx);
  892. }
  893. static int efx_mcdi_wol_filter_set(struct efx_nic *efx, u32 type,
  894. const u8 *mac, int *id_out)
  895. {
  896. MCDI_DECLARE_BUF(inbuf, MC_CMD_WOL_FILTER_SET_IN_LEN);
  897. MCDI_DECLARE_BUF(outbuf, MC_CMD_WOL_FILTER_SET_OUT_LEN);
  898. size_t outlen;
  899. int rc;
  900. MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_WOL_TYPE, type);
  901. MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_FILTER_MODE,
  902. MC_CMD_FILTER_MODE_SIMPLE);
  903. memcpy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac, ETH_ALEN);
  904. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_SET, inbuf, sizeof(inbuf),
  905. outbuf, sizeof(outbuf), &outlen);
  906. if (rc)
  907. goto fail;
  908. if (outlen < MC_CMD_WOL_FILTER_SET_OUT_LEN) {
  909. rc = -EIO;
  910. goto fail;
  911. }
  912. *id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_SET_OUT_FILTER_ID);
  913. return 0;
  914. fail:
  915. *id_out = -1;
  916. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  917. return rc;
  918. }
  919. int
  920. efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac, int *id_out)
  921. {
  922. return efx_mcdi_wol_filter_set(efx, MC_CMD_WOL_TYPE_MAGIC, mac, id_out);
  923. }
  924. int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out)
  925. {
  926. MCDI_DECLARE_BUF(outbuf, MC_CMD_WOL_FILTER_GET_OUT_LEN);
  927. size_t outlen;
  928. int rc;
  929. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_GET, NULL, 0,
  930. outbuf, sizeof(outbuf), &outlen);
  931. if (rc)
  932. goto fail;
  933. if (outlen < MC_CMD_WOL_FILTER_GET_OUT_LEN) {
  934. rc = -EIO;
  935. goto fail;
  936. }
  937. *id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_GET_OUT_FILTER_ID);
  938. return 0;
  939. fail:
  940. *id_out = -1;
  941. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  942. return rc;
  943. }
  944. int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id)
  945. {
  946. MCDI_DECLARE_BUF(inbuf, MC_CMD_WOL_FILTER_REMOVE_IN_LEN);
  947. int rc;
  948. MCDI_SET_DWORD(inbuf, WOL_FILTER_REMOVE_IN_FILTER_ID, (u32)id);
  949. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_REMOVE, inbuf, sizeof(inbuf),
  950. NULL, 0, NULL);
  951. if (rc)
  952. goto fail;
  953. return 0;
  954. fail:
  955. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  956. return rc;
  957. }
  958. int efx_mcdi_flush_rxqs(struct efx_nic *efx)
  959. {
  960. struct efx_channel *channel;
  961. struct efx_rx_queue *rx_queue;
  962. MCDI_DECLARE_BUF(inbuf,
  963. MC_CMD_FLUSH_RX_QUEUES_IN_LEN(EFX_MAX_CHANNELS));
  964. int rc, count;
  965. BUILD_BUG_ON(EFX_MAX_CHANNELS >
  966. MC_CMD_FLUSH_RX_QUEUES_IN_QID_OFST_MAXNUM);
  967. count = 0;
  968. efx_for_each_channel(channel, efx) {
  969. efx_for_each_channel_rx_queue(rx_queue, channel) {
  970. if (rx_queue->flush_pending) {
  971. rx_queue->flush_pending = false;
  972. atomic_dec(&efx->rxq_flush_pending);
  973. MCDI_SET_ARRAY_DWORD(
  974. inbuf, FLUSH_RX_QUEUES_IN_QID_OFST,
  975. count, efx_rx_queue_index(rx_queue));
  976. count++;
  977. }
  978. }
  979. }
  980. rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, inbuf,
  981. MC_CMD_FLUSH_RX_QUEUES_IN_LEN(count), NULL, 0, NULL);
  982. WARN_ON(rc < 0);
  983. return rc;
  984. }
  985. int efx_mcdi_wol_filter_reset(struct efx_nic *efx)
  986. {
  987. int rc;
  988. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_RESET, NULL, 0, NULL, 0, NULL);
  989. if (rc)
  990. goto fail;
  991. return 0;
  992. fail:
  993. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  994. return rc;
  995. }