mcdi.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  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 "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 /*seconds */
  23. #define MCDI_PDU(efx) \
  24. (efx_port_num(efx) ? MC_SMEM_P1_PDU_OFST : MC_SMEM_P0_PDU_OFST)
  25. #define MCDI_DOORBELL(efx) \
  26. (efx_port_num(efx) ? MC_SMEM_P1_DOORBELL_OFST : MC_SMEM_P0_DOORBELL_OFST)
  27. #define MCDI_STATUS(efx) \
  28. (efx_port_num(efx) ? MC_SMEM_P1_STATUS_OFST : MC_SMEM_P0_STATUS_OFST)
  29. /* A reboot/assertion causes the MCDI status word to be set after the
  30. * command word is set or a REBOOT event is sent. If we notice a reboot
  31. * via these mechanisms then wait 10ms for the status word to be set. */
  32. #define MCDI_STATUS_DELAY_US 100
  33. #define MCDI_STATUS_DELAY_COUNT 100
  34. #define MCDI_STATUS_SLEEP_MS \
  35. (MCDI_STATUS_DELAY_US * MCDI_STATUS_DELAY_COUNT / 1000)
  36. #define SEQ_MASK \
  37. EFX_MASK32(EFX_WIDTH(MCDI_HEADER_SEQ))
  38. static inline struct efx_mcdi_iface *efx_mcdi(struct efx_nic *efx)
  39. {
  40. struct siena_nic_data *nic_data;
  41. EFX_BUG_ON_PARANOID(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
  42. nic_data = efx->nic_data;
  43. return &nic_data->mcdi;
  44. }
  45. void efx_mcdi_init(struct efx_nic *efx)
  46. {
  47. struct efx_mcdi_iface *mcdi;
  48. if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
  49. return;
  50. mcdi = efx_mcdi(efx);
  51. init_waitqueue_head(&mcdi->wq);
  52. spin_lock_init(&mcdi->iface_lock);
  53. atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT);
  54. mcdi->mode = MCDI_MODE_POLL;
  55. (void) efx_mcdi_poll_reboot(efx);
  56. }
  57. static void efx_mcdi_copyin(struct efx_nic *efx, unsigned cmd,
  58. const u8 *inbuf, size_t inlen)
  59. {
  60. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  61. unsigned pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
  62. unsigned doorbell = FR_CZ_MC_TREG_SMEM + MCDI_DOORBELL(efx);
  63. unsigned int i;
  64. efx_dword_t hdr;
  65. u32 xflags, seqno;
  66. BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
  67. BUG_ON(inlen & 3 || inlen >= MC_SMEM_PDU_LEN);
  68. seqno = mcdi->seqno & SEQ_MASK;
  69. xflags = 0;
  70. if (mcdi->mode == MCDI_MODE_EVENTS)
  71. xflags |= MCDI_HEADER_XFLAGS_EVREQ;
  72. EFX_POPULATE_DWORD_6(hdr,
  73. MCDI_HEADER_RESPONSE, 0,
  74. MCDI_HEADER_RESYNC, 1,
  75. MCDI_HEADER_CODE, cmd,
  76. MCDI_HEADER_DATALEN, inlen,
  77. MCDI_HEADER_SEQ, seqno,
  78. MCDI_HEADER_XFLAGS, xflags);
  79. efx_writed(efx, &hdr, pdu);
  80. for (i = 0; i < inlen; i += 4)
  81. _efx_writed(efx, *((__le32 *)(inbuf + i)), pdu + 4 + i);
  82. /* Ensure the payload is written out before the header */
  83. wmb();
  84. /* ring the doorbell with a distinctive value */
  85. _efx_writed(efx, (__force __le32) 0x45789abc, doorbell);
  86. }
  87. static void efx_mcdi_copyout(struct efx_nic *efx, u8 *outbuf, size_t outlen)
  88. {
  89. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  90. unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
  91. int i;
  92. BUG_ON(atomic_read(&mcdi->state) == MCDI_STATE_QUIESCENT);
  93. BUG_ON(outlen & 3 || outlen >= MC_SMEM_PDU_LEN);
  94. for (i = 0; i < outlen; i += 4)
  95. *((__le32 *)(outbuf + i)) = _efx_readd(efx, pdu + 4 + i);
  96. }
  97. static int efx_mcdi_poll(struct efx_nic *efx)
  98. {
  99. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  100. unsigned int time, finish;
  101. unsigned int respseq, respcmd, error;
  102. unsigned int pdu = FR_CZ_MC_TREG_SMEM + MCDI_PDU(efx);
  103. unsigned int rc, spins;
  104. efx_dword_t reg;
  105. /* Check for a reboot atomically with respect to efx_mcdi_copyout() */
  106. rc = -efx_mcdi_poll_reboot(efx);
  107. if (rc)
  108. goto out;
  109. /* Poll for completion. Poll quickly (once a us) for the 1st jiffy,
  110. * because generally mcdi responses are fast. After that, back off
  111. * and poll once a jiffy (approximately)
  112. */
  113. spins = TICK_USEC;
  114. finish = get_seconds() + MCDI_RPC_TIMEOUT;
  115. while (1) {
  116. if (spins != 0) {
  117. --spins;
  118. udelay(1);
  119. } else {
  120. schedule_timeout_uninterruptible(1);
  121. }
  122. time = get_seconds();
  123. rmb();
  124. efx_readd(efx, &reg, pdu);
  125. /* All 1's indicates that shared memory is in reset (and is
  126. * not a valid header). Wait for it to come out reset before
  127. * completing the command */
  128. if (EFX_DWORD_FIELD(reg, EFX_DWORD_0) != 0xffffffff &&
  129. EFX_DWORD_FIELD(reg, MCDI_HEADER_RESPONSE))
  130. break;
  131. if (time >= finish)
  132. return -ETIMEDOUT;
  133. }
  134. mcdi->resplen = EFX_DWORD_FIELD(reg, MCDI_HEADER_DATALEN);
  135. respseq = EFX_DWORD_FIELD(reg, MCDI_HEADER_SEQ);
  136. respcmd = EFX_DWORD_FIELD(reg, MCDI_HEADER_CODE);
  137. error = EFX_DWORD_FIELD(reg, MCDI_HEADER_ERROR);
  138. if (error && mcdi->resplen == 0) {
  139. netif_err(efx, hw, efx->net_dev, "MC rebooted\n");
  140. rc = EIO;
  141. } else if ((respseq ^ mcdi->seqno) & SEQ_MASK) {
  142. netif_err(efx, hw, efx->net_dev,
  143. "MC response mismatch tx seq 0x%x rx seq 0x%x\n",
  144. respseq, mcdi->seqno);
  145. rc = EIO;
  146. } else if (error) {
  147. efx_readd(efx, &reg, pdu + 4);
  148. switch (EFX_DWORD_FIELD(reg, EFX_DWORD_0)) {
  149. #define TRANSLATE_ERROR(name) \
  150. case MC_CMD_ERR_ ## name: \
  151. rc = name; \
  152. break
  153. TRANSLATE_ERROR(ENOENT);
  154. TRANSLATE_ERROR(EINTR);
  155. TRANSLATE_ERROR(EACCES);
  156. TRANSLATE_ERROR(EBUSY);
  157. TRANSLATE_ERROR(EINVAL);
  158. TRANSLATE_ERROR(EDEADLK);
  159. TRANSLATE_ERROR(ENOSYS);
  160. TRANSLATE_ERROR(ETIME);
  161. #undef TRANSLATE_ERROR
  162. default:
  163. rc = EIO;
  164. break;
  165. }
  166. } else
  167. rc = 0;
  168. out:
  169. mcdi->resprc = rc;
  170. if (rc)
  171. mcdi->resplen = 0;
  172. /* Return rc=0 like wait_event_timeout() */
  173. return 0;
  174. }
  175. /* Test and clear MC-rebooted flag for this port/function */
  176. int efx_mcdi_poll_reboot(struct efx_nic *efx)
  177. {
  178. unsigned int addr = FR_CZ_MC_TREG_SMEM + MCDI_STATUS(efx);
  179. efx_dword_t reg;
  180. uint32_t value;
  181. if (efx_nic_rev(efx) < EFX_REV_SIENA_A0)
  182. return false;
  183. efx_readd(efx, &reg, addr);
  184. value = EFX_DWORD_FIELD(reg, EFX_DWORD_0);
  185. if (value == 0)
  186. return 0;
  187. EFX_ZERO_DWORD(reg);
  188. efx_writed(efx, &reg, addr);
  189. if (value == MC_STATUS_DWORD_ASSERT)
  190. return -EINTR;
  191. else
  192. return -EIO;
  193. }
  194. static void efx_mcdi_acquire(struct efx_mcdi_iface *mcdi)
  195. {
  196. /* Wait until the interface becomes QUIESCENT and we win the race
  197. * to mark it RUNNING. */
  198. wait_event(mcdi->wq,
  199. atomic_cmpxchg(&mcdi->state,
  200. MCDI_STATE_QUIESCENT,
  201. MCDI_STATE_RUNNING)
  202. == MCDI_STATE_QUIESCENT);
  203. }
  204. static int efx_mcdi_await_completion(struct efx_nic *efx)
  205. {
  206. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  207. if (wait_event_timeout(
  208. mcdi->wq,
  209. atomic_read(&mcdi->state) == MCDI_STATE_COMPLETED,
  210. msecs_to_jiffies(MCDI_RPC_TIMEOUT * 1000)) == 0)
  211. return -ETIMEDOUT;
  212. /* Check if efx_mcdi_set_mode() switched us back to polled completions.
  213. * In which case, poll for completions directly. If efx_mcdi_ev_cpl()
  214. * completed the request first, then we'll just end up completing the
  215. * request again, which is safe.
  216. *
  217. * We need an smp_rmb() to synchronise with efx_mcdi_mode_poll(), which
  218. * wait_event_timeout() implicitly provides.
  219. */
  220. if (mcdi->mode == MCDI_MODE_POLL)
  221. return efx_mcdi_poll(efx);
  222. return 0;
  223. }
  224. static bool efx_mcdi_complete(struct efx_mcdi_iface *mcdi)
  225. {
  226. /* If the interface is RUNNING, then move to COMPLETED and wake any
  227. * waiters. If the interface isn't in RUNNING then we've received a
  228. * duplicate completion after we've already transitioned back to
  229. * QUIESCENT. [A subsequent invocation would increment seqno, so would
  230. * have failed the seqno check].
  231. */
  232. if (atomic_cmpxchg(&mcdi->state,
  233. MCDI_STATE_RUNNING,
  234. MCDI_STATE_COMPLETED) == MCDI_STATE_RUNNING) {
  235. wake_up(&mcdi->wq);
  236. return true;
  237. }
  238. return false;
  239. }
  240. static void efx_mcdi_release(struct efx_mcdi_iface *mcdi)
  241. {
  242. atomic_set(&mcdi->state, MCDI_STATE_QUIESCENT);
  243. wake_up(&mcdi->wq);
  244. }
  245. static void efx_mcdi_ev_cpl(struct efx_nic *efx, unsigned int seqno,
  246. unsigned int datalen, unsigned int errno)
  247. {
  248. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  249. bool wake = false;
  250. spin_lock(&mcdi->iface_lock);
  251. if ((seqno ^ mcdi->seqno) & SEQ_MASK) {
  252. if (mcdi->credits)
  253. /* The request has been cancelled */
  254. --mcdi->credits;
  255. else
  256. netif_err(efx, hw, efx->net_dev,
  257. "MC response mismatch tx seq 0x%x rx "
  258. "seq 0x%x\n", seqno, mcdi->seqno);
  259. } else {
  260. mcdi->resprc = errno;
  261. mcdi->resplen = datalen;
  262. wake = true;
  263. }
  264. spin_unlock(&mcdi->iface_lock);
  265. if (wake)
  266. efx_mcdi_complete(mcdi);
  267. }
  268. /* Issue the given command by writing the data into the shared memory PDU,
  269. * ring the doorbell and wait for completion. Copyout the result. */
  270. int efx_mcdi_rpc(struct efx_nic *efx, unsigned cmd,
  271. const u8 *inbuf, size_t inlen, u8 *outbuf, size_t outlen,
  272. size_t *outlen_actual)
  273. {
  274. struct efx_mcdi_iface *mcdi = efx_mcdi(efx);
  275. int rc;
  276. BUG_ON(efx_nic_rev(efx) < EFX_REV_SIENA_A0);
  277. efx_mcdi_acquire(mcdi);
  278. /* Serialise with efx_mcdi_ev_cpl() and efx_mcdi_ev_death() */
  279. spin_lock_bh(&mcdi->iface_lock);
  280. ++mcdi->seqno;
  281. spin_unlock_bh(&mcdi->iface_lock);
  282. efx_mcdi_copyin(efx, cmd, inbuf, inlen);
  283. if (mcdi->mode == MCDI_MODE_POLL)
  284. rc = efx_mcdi_poll(efx);
  285. else
  286. rc = efx_mcdi_await_completion(efx);
  287. if (rc != 0) {
  288. /* Close the race with efx_mcdi_ev_cpl() executing just too late
  289. * and completing a request we've just cancelled, by ensuring
  290. * that the seqno check therein fails.
  291. */
  292. spin_lock_bh(&mcdi->iface_lock);
  293. ++mcdi->seqno;
  294. ++mcdi->credits;
  295. spin_unlock_bh(&mcdi->iface_lock);
  296. netif_err(efx, hw, efx->net_dev,
  297. "MC command 0x%x inlen %d mode %d timed out\n",
  298. cmd, (int)inlen, mcdi->mode);
  299. } else {
  300. size_t resplen;
  301. /* At the very least we need a memory barrier here to ensure
  302. * we pick up changes from efx_mcdi_ev_cpl(). Protect against
  303. * a spurious efx_mcdi_ev_cpl() running concurrently by
  304. * acquiring the iface_lock. */
  305. spin_lock_bh(&mcdi->iface_lock);
  306. rc = -mcdi->resprc;
  307. resplen = mcdi->resplen;
  308. spin_unlock_bh(&mcdi->iface_lock);
  309. if (rc == 0) {
  310. efx_mcdi_copyout(efx, outbuf,
  311. min(outlen, mcdi->resplen + 3) & ~0x3);
  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_nic_rev(efx) < EFX_REV_SIENA_A0)
  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_nic_rev(efx) < EFX_REV_SIENA_A0)
  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. static unsigned int efx_mcdi_event_link_speed[] = {
  410. [MCDI_EVENT_LINKCHANGE_SPEED_100M] = 100,
  411. [MCDI_EVENT_LINKCHANGE_SPEED_1G] = 1000,
  412. [MCDI_EVENT_LINKCHANGE_SPEED_10G] = 10000,
  413. };
  414. static void efx_mcdi_process_link_change(struct efx_nic *efx, efx_qword_t *ev)
  415. {
  416. u32 flags, fcntl, speed, lpa;
  417. speed = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_SPEED);
  418. EFX_BUG_ON_PARANOID(speed >= ARRAY_SIZE(efx_mcdi_event_link_speed));
  419. speed = efx_mcdi_event_link_speed[speed];
  420. flags = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LINK_FLAGS);
  421. fcntl = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_FCNTL);
  422. lpa = EFX_QWORD_FIELD(*ev, MCDI_EVENT_LINKCHANGE_LP_CAP);
  423. /* efx->link_state is only modified by efx_mcdi_phy_get_link(),
  424. * which is only run after flushing the event queues. Therefore, it
  425. * is safe to modify the link state outside of the mac_lock here.
  426. */
  427. efx_mcdi_phy_decode_link(efx, &efx->link_state, speed, flags, fcntl);
  428. efx_mcdi_phy_check_fcntl(efx, lpa);
  429. efx_link_status_changed(efx);
  430. }
  431. /* Called from falcon_process_eventq for MCDI events */
  432. void efx_mcdi_process_event(struct efx_channel *channel,
  433. efx_qword_t *event)
  434. {
  435. struct efx_nic *efx = channel->efx;
  436. int code = EFX_QWORD_FIELD(*event, MCDI_EVENT_CODE);
  437. u32 data = EFX_QWORD_FIELD(*event, MCDI_EVENT_DATA);
  438. switch (code) {
  439. case MCDI_EVENT_CODE_BADSSERT:
  440. netif_err(efx, hw, efx->net_dev,
  441. "MC watchdog or assertion failure at 0x%x\n", data);
  442. efx_mcdi_ev_death(efx, EINTR);
  443. break;
  444. case MCDI_EVENT_CODE_PMNOTICE:
  445. netif_info(efx, wol, efx->net_dev, "MCDI PM event.\n");
  446. break;
  447. case MCDI_EVENT_CODE_CMDDONE:
  448. efx_mcdi_ev_cpl(efx,
  449. MCDI_EVENT_FIELD(*event, CMDDONE_SEQ),
  450. MCDI_EVENT_FIELD(*event, CMDDONE_DATALEN),
  451. MCDI_EVENT_FIELD(*event, CMDDONE_ERRNO));
  452. break;
  453. case MCDI_EVENT_CODE_LINKCHANGE:
  454. efx_mcdi_process_link_change(efx, event);
  455. break;
  456. case MCDI_EVENT_CODE_SENSOREVT:
  457. efx_mcdi_sensor_event(efx, event);
  458. break;
  459. case MCDI_EVENT_CODE_SCHEDERR:
  460. netif_info(efx, hw, efx->net_dev,
  461. "MC Scheduler error address=0x%x\n", data);
  462. break;
  463. case MCDI_EVENT_CODE_REBOOT:
  464. netif_info(efx, hw, efx->net_dev, "MC Reboot\n");
  465. efx_mcdi_ev_death(efx, EIO);
  466. break;
  467. case MCDI_EVENT_CODE_MAC_STATS_DMA:
  468. /* MAC stats are gather lazily. We can ignore this. */
  469. break;
  470. case MCDI_EVENT_CODE_FLR:
  471. efx_sriov_flr(efx, MCDI_EVENT_FIELD(*event, FLR_VF));
  472. break;
  473. default:
  474. netif_err(efx, hw, efx->net_dev, "Unknown MCDI event 0x%x\n",
  475. code);
  476. }
  477. }
  478. /**************************************************************************
  479. *
  480. * Specific request functions
  481. *
  482. **************************************************************************
  483. */
  484. void efx_mcdi_print_fwver(struct efx_nic *efx, char *buf, size_t len)
  485. {
  486. u8 outbuf[ALIGN(MC_CMD_GET_VERSION_OUT_LEN, 4)];
  487. size_t outlength;
  488. const __le16 *ver_words;
  489. int rc;
  490. BUILD_BUG_ON(MC_CMD_GET_VERSION_IN_LEN != 0);
  491. rc = efx_mcdi_rpc(efx, MC_CMD_GET_VERSION, NULL, 0,
  492. outbuf, sizeof(outbuf), &outlength);
  493. if (rc)
  494. goto fail;
  495. if (outlength < MC_CMD_GET_VERSION_OUT_LEN) {
  496. rc = -EIO;
  497. goto fail;
  498. }
  499. ver_words = (__le16 *)MCDI_PTR(outbuf, GET_VERSION_OUT_VERSION);
  500. snprintf(buf, len, "%u.%u.%u.%u",
  501. le16_to_cpu(ver_words[0]), le16_to_cpu(ver_words[1]),
  502. le16_to_cpu(ver_words[2]), le16_to_cpu(ver_words[3]));
  503. return;
  504. fail:
  505. netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  506. buf[0] = 0;
  507. }
  508. int efx_mcdi_drv_attach(struct efx_nic *efx, bool driver_operating,
  509. bool *was_attached)
  510. {
  511. u8 inbuf[MC_CMD_DRV_ATTACH_IN_LEN];
  512. u8 outbuf[MC_CMD_DRV_ATTACH_OUT_LEN];
  513. size_t outlen;
  514. int rc;
  515. MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_NEW_STATE,
  516. driver_operating ? 1 : 0);
  517. MCDI_SET_DWORD(inbuf, DRV_ATTACH_IN_UPDATE, 1);
  518. rc = efx_mcdi_rpc(efx, MC_CMD_DRV_ATTACH, inbuf, sizeof(inbuf),
  519. outbuf, sizeof(outbuf), &outlen);
  520. if (rc)
  521. goto fail;
  522. if (outlen < MC_CMD_DRV_ATTACH_OUT_LEN) {
  523. rc = -EIO;
  524. goto fail;
  525. }
  526. if (was_attached != NULL)
  527. *was_attached = MCDI_DWORD(outbuf, DRV_ATTACH_OUT_OLD_STATE);
  528. return 0;
  529. fail:
  530. netif_err(efx, probe, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  531. return rc;
  532. }
  533. int efx_mcdi_get_board_cfg(struct efx_nic *efx, u8 *mac_address,
  534. u16 *fw_subtype_list, u32 *capabilities)
  535. {
  536. uint8_t outbuf[MC_CMD_GET_BOARD_CFG_OUT_LENMIN];
  537. size_t outlen;
  538. int port_num = efx_port_num(efx);
  539. int offset;
  540. int rc;
  541. BUILD_BUG_ON(MC_CMD_GET_BOARD_CFG_IN_LEN != 0);
  542. rc = efx_mcdi_rpc(efx, MC_CMD_GET_BOARD_CFG, NULL, 0,
  543. outbuf, sizeof(outbuf), &outlen);
  544. if (rc)
  545. goto fail;
  546. if (outlen < MC_CMD_GET_BOARD_CFG_OUT_LENMIN) {
  547. rc = -EIO;
  548. goto fail;
  549. }
  550. offset = (port_num)
  551. ? MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT1_OFST
  552. : MC_CMD_GET_BOARD_CFG_OUT_MAC_ADDR_BASE_PORT0_OFST;
  553. if (mac_address)
  554. memcpy(mac_address, outbuf + offset, ETH_ALEN);
  555. if (fw_subtype_list)
  556. memcpy(fw_subtype_list,
  557. outbuf + MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_OFST,
  558. MC_CMD_GET_BOARD_CFG_OUT_FW_SUBTYPE_LIST_MINNUM *
  559. sizeof(fw_subtype_list[0]));
  560. if (capabilities) {
  561. if (port_num)
  562. *capabilities = MCDI_DWORD(outbuf,
  563. GET_BOARD_CFG_OUT_CAPABILITIES_PORT1);
  564. else
  565. *capabilities = MCDI_DWORD(outbuf,
  566. GET_BOARD_CFG_OUT_CAPABILITIES_PORT0);
  567. }
  568. return 0;
  569. fail:
  570. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d len=%d\n",
  571. __func__, rc, (int)outlen);
  572. return rc;
  573. }
  574. int efx_mcdi_log_ctrl(struct efx_nic *efx, bool evq, bool uart, u32 dest_evq)
  575. {
  576. u8 inbuf[MC_CMD_LOG_CTRL_IN_LEN];
  577. u32 dest = 0;
  578. int rc;
  579. if (uart)
  580. dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_UART;
  581. if (evq)
  582. dest |= MC_CMD_LOG_CTRL_IN_LOG_DEST_EVQ;
  583. MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST, dest);
  584. MCDI_SET_DWORD(inbuf, LOG_CTRL_IN_LOG_DEST_EVQ, dest_evq);
  585. BUILD_BUG_ON(MC_CMD_LOG_CTRL_OUT_LEN != 0);
  586. rc = efx_mcdi_rpc(efx, MC_CMD_LOG_CTRL, inbuf, sizeof(inbuf),
  587. NULL, 0, NULL);
  588. if (rc)
  589. goto fail;
  590. return 0;
  591. fail:
  592. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  593. return rc;
  594. }
  595. int efx_mcdi_nvram_types(struct efx_nic *efx, u32 *nvram_types_out)
  596. {
  597. u8 outbuf[MC_CMD_NVRAM_TYPES_OUT_LEN];
  598. size_t outlen;
  599. int rc;
  600. BUILD_BUG_ON(MC_CMD_NVRAM_TYPES_IN_LEN != 0);
  601. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TYPES, NULL, 0,
  602. outbuf, sizeof(outbuf), &outlen);
  603. if (rc)
  604. goto fail;
  605. if (outlen < MC_CMD_NVRAM_TYPES_OUT_LEN) {
  606. rc = -EIO;
  607. goto fail;
  608. }
  609. *nvram_types_out = MCDI_DWORD(outbuf, NVRAM_TYPES_OUT_TYPES);
  610. return 0;
  611. fail:
  612. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  613. __func__, rc);
  614. return rc;
  615. }
  616. int efx_mcdi_nvram_info(struct efx_nic *efx, unsigned int type,
  617. size_t *size_out, size_t *erase_size_out,
  618. bool *protected_out)
  619. {
  620. u8 inbuf[MC_CMD_NVRAM_INFO_IN_LEN];
  621. u8 outbuf[MC_CMD_NVRAM_INFO_OUT_LEN];
  622. size_t outlen;
  623. int rc;
  624. MCDI_SET_DWORD(inbuf, NVRAM_INFO_IN_TYPE, type);
  625. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_INFO, inbuf, sizeof(inbuf),
  626. outbuf, sizeof(outbuf), &outlen);
  627. if (rc)
  628. goto fail;
  629. if (outlen < MC_CMD_NVRAM_INFO_OUT_LEN) {
  630. rc = -EIO;
  631. goto fail;
  632. }
  633. *size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_SIZE);
  634. *erase_size_out = MCDI_DWORD(outbuf, NVRAM_INFO_OUT_ERASESIZE);
  635. *protected_out = !!(MCDI_DWORD(outbuf, NVRAM_INFO_OUT_FLAGS) &
  636. (1 << MC_CMD_NVRAM_INFO_OUT_PROTECTED_LBN));
  637. return 0;
  638. fail:
  639. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  640. return rc;
  641. }
  642. int efx_mcdi_nvram_update_start(struct efx_nic *efx, unsigned int type)
  643. {
  644. u8 inbuf[MC_CMD_NVRAM_UPDATE_START_IN_LEN];
  645. int rc;
  646. MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_START_IN_TYPE, type);
  647. BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_START_OUT_LEN != 0);
  648. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_START, inbuf, sizeof(inbuf),
  649. NULL, 0, NULL);
  650. if (rc)
  651. goto fail;
  652. return 0;
  653. fail:
  654. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  655. return rc;
  656. }
  657. int efx_mcdi_nvram_read(struct efx_nic *efx, unsigned int type,
  658. loff_t offset, u8 *buffer, size_t length)
  659. {
  660. u8 inbuf[MC_CMD_NVRAM_READ_IN_LEN];
  661. u8 outbuf[MC_CMD_NVRAM_READ_OUT_LEN(EFX_MCDI_NVRAM_LEN_MAX)];
  662. size_t outlen;
  663. int rc;
  664. MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_TYPE, type);
  665. MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_OFFSET, offset);
  666. MCDI_SET_DWORD(inbuf, NVRAM_READ_IN_LENGTH, length);
  667. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_READ, inbuf, sizeof(inbuf),
  668. outbuf, sizeof(outbuf), &outlen);
  669. if (rc)
  670. goto fail;
  671. memcpy(buffer, MCDI_PTR(outbuf, NVRAM_READ_OUT_READ_BUFFER), length);
  672. return 0;
  673. fail:
  674. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  675. return rc;
  676. }
  677. int efx_mcdi_nvram_write(struct efx_nic *efx, unsigned int type,
  678. loff_t offset, const u8 *buffer, size_t length)
  679. {
  680. u8 inbuf[MC_CMD_NVRAM_WRITE_IN_LEN(EFX_MCDI_NVRAM_LEN_MAX)];
  681. int rc;
  682. MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_TYPE, type);
  683. MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_OFFSET, offset);
  684. MCDI_SET_DWORD(inbuf, NVRAM_WRITE_IN_LENGTH, length);
  685. memcpy(MCDI_PTR(inbuf, NVRAM_WRITE_IN_WRITE_BUFFER), buffer, length);
  686. BUILD_BUG_ON(MC_CMD_NVRAM_WRITE_OUT_LEN != 0);
  687. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_WRITE, inbuf,
  688. ALIGN(MC_CMD_NVRAM_WRITE_IN_LEN(length), 4),
  689. NULL, 0, NULL);
  690. if (rc)
  691. goto fail;
  692. return 0;
  693. fail:
  694. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  695. return rc;
  696. }
  697. int efx_mcdi_nvram_erase(struct efx_nic *efx, unsigned int type,
  698. loff_t offset, size_t length)
  699. {
  700. u8 inbuf[MC_CMD_NVRAM_ERASE_IN_LEN];
  701. int rc;
  702. MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_TYPE, type);
  703. MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_OFFSET, offset);
  704. MCDI_SET_DWORD(inbuf, NVRAM_ERASE_IN_LENGTH, length);
  705. BUILD_BUG_ON(MC_CMD_NVRAM_ERASE_OUT_LEN != 0);
  706. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_ERASE, inbuf, sizeof(inbuf),
  707. NULL, 0, NULL);
  708. if (rc)
  709. goto fail;
  710. return 0;
  711. fail:
  712. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  713. return rc;
  714. }
  715. int efx_mcdi_nvram_update_finish(struct efx_nic *efx, unsigned int type)
  716. {
  717. u8 inbuf[MC_CMD_NVRAM_UPDATE_FINISH_IN_LEN];
  718. int rc;
  719. MCDI_SET_DWORD(inbuf, NVRAM_UPDATE_FINISH_IN_TYPE, type);
  720. BUILD_BUG_ON(MC_CMD_NVRAM_UPDATE_FINISH_OUT_LEN != 0);
  721. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_UPDATE_FINISH, inbuf, sizeof(inbuf),
  722. NULL, 0, NULL);
  723. if (rc)
  724. goto fail;
  725. return 0;
  726. fail:
  727. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  728. return rc;
  729. }
  730. static int efx_mcdi_nvram_test(struct efx_nic *efx, unsigned int type)
  731. {
  732. u8 inbuf[MC_CMD_NVRAM_TEST_IN_LEN];
  733. u8 outbuf[MC_CMD_NVRAM_TEST_OUT_LEN];
  734. int rc;
  735. MCDI_SET_DWORD(inbuf, NVRAM_TEST_IN_TYPE, type);
  736. rc = efx_mcdi_rpc(efx, MC_CMD_NVRAM_TEST, inbuf, sizeof(inbuf),
  737. outbuf, sizeof(outbuf), NULL);
  738. if (rc)
  739. return rc;
  740. switch (MCDI_DWORD(outbuf, NVRAM_TEST_OUT_RESULT)) {
  741. case MC_CMD_NVRAM_TEST_PASS:
  742. case MC_CMD_NVRAM_TEST_NOTSUPP:
  743. return 0;
  744. default:
  745. return -EIO;
  746. }
  747. }
  748. int efx_mcdi_nvram_test_all(struct efx_nic *efx)
  749. {
  750. u32 nvram_types;
  751. unsigned int type;
  752. int rc;
  753. rc = efx_mcdi_nvram_types(efx, &nvram_types);
  754. if (rc)
  755. goto fail1;
  756. type = 0;
  757. while (nvram_types != 0) {
  758. if (nvram_types & 1) {
  759. rc = efx_mcdi_nvram_test(efx, type);
  760. if (rc)
  761. goto fail2;
  762. }
  763. type++;
  764. nvram_types >>= 1;
  765. }
  766. return 0;
  767. fail2:
  768. netif_err(efx, hw, efx->net_dev, "%s: failed type=%u\n",
  769. __func__, type);
  770. fail1:
  771. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  772. return rc;
  773. }
  774. static int efx_mcdi_read_assertion(struct efx_nic *efx)
  775. {
  776. u8 inbuf[MC_CMD_GET_ASSERTS_IN_LEN];
  777. u8 outbuf[MC_CMD_GET_ASSERTS_OUT_LEN];
  778. unsigned int flags, index, ofst;
  779. const char *reason;
  780. size_t outlen;
  781. int retry;
  782. int rc;
  783. /* Attempt to read any stored assertion state before we reboot
  784. * the mcfw out of the assertion handler. Retry twice, once
  785. * because a boot-time assertion might cause this command to fail
  786. * with EINTR. And once again because GET_ASSERTS can race with
  787. * MC_CMD_REBOOT running on the other port. */
  788. retry = 2;
  789. do {
  790. MCDI_SET_DWORD(inbuf, GET_ASSERTS_IN_CLEAR, 1);
  791. rc = efx_mcdi_rpc(efx, MC_CMD_GET_ASSERTS,
  792. inbuf, MC_CMD_GET_ASSERTS_IN_LEN,
  793. outbuf, sizeof(outbuf), &outlen);
  794. } while ((rc == -EINTR || rc == -EIO) && retry-- > 0);
  795. if (rc)
  796. return rc;
  797. if (outlen < MC_CMD_GET_ASSERTS_OUT_LEN)
  798. return -EIO;
  799. /* Print out any recorded assertion state */
  800. flags = MCDI_DWORD(outbuf, GET_ASSERTS_OUT_GLOBAL_FLAGS);
  801. if (flags == MC_CMD_GET_ASSERTS_FLAGS_NO_FAILS)
  802. return 0;
  803. reason = (flags == MC_CMD_GET_ASSERTS_FLAGS_SYS_FAIL)
  804. ? "system-level assertion"
  805. : (flags == MC_CMD_GET_ASSERTS_FLAGS_THR_FAIL)
  806. ? "thread-level assertion"
  807. : (flags == MC_CMD_GET_ASSERTS_FLAGS_WDOG_FIRED)
  808. ? "watchdog reset"
  809. : "unknown assertion";
  810. netif_err(efx, hw, efx->net_dev,
  811. "MCPU %s at PC = 0x%.8x in thread 0x%.8x\n", reason,
  812. MCDI_DWORD(outbuf, GET_ASSERTS_OUT_SAVED_PC_OFFS),
  813. MCDI_DWORD(outbuf, GET_ASSERTS_OUT_THREAD_OFFS));
  814. /* Print out the registers */
  815. ofst = MC_CMD_GET_ASSERTS_OUT_GP_REGS_OFFS_OFST;
  816. for (index = 1; index < 32; index++) {
  817. netif_err(efx, hw, efx->net_dev, "R%.2d (?): 0x%.8x\n", index,
  818. MCDI_DWORD2(outbuf, ofst));
  819. ofst += sizeof(efx_dword_t);
  820. }
  821. return 0;
  822. }
  823. static void efx_mcdi_exit_assertion(struct efx_nic *efx)
  824. {
  825. u8 inbuf[MC_CMD_REBOOT_IN_LEN];
  826. /* Atomically reboot the mcfw out of the assertion handler */
  827. BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0);
  828. MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS,
  829. MC_CMD_REBOOT_FLAGS_AFTER_ASSERTION);
  830. efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, MC_CMD_REBOOT_IN_LEN,
  831. NULL, 0, NULL);
  832. }
  833. int efx_mcdi_handle_assertion(struct efx_nic *efx)
  834. {
  835. int rc;
  836. rc = efx_mcdi_read_assertion(efx);
  837. if (rc)
  838. return rc;
  839. efx_mcdi_exit_assertion(efx);
  840. return 0;
  841. }
  842. void efx_mcdi_set_id_led(struct efx_nic *efx, enum efx_led_mode mode)
  843. {
  844. u8 inbuf[MC_CMD_SET_ID_LED_IN_LEN];
  845. int rc;
  846. BUILD_BUG_ON(EFX_LED_OFF != MC_CMD_LED_OFF);
  847. BUILD_BUG_ON(EFX_LED_ON != MC_CMD_LED_ON);
  848. BUILD_BUG_ON(EFX_LED_DEFAULT != MC_CMD_LED_DEFAULT);
  849. BUILD_BUG_ON(MC_CMD_SET_ID_LED_OUT_LEN != 0);
  850. MCDI_SET_DWORD(inbuf, SET_ID_LED_IN_STATE, mode);
  851. rc = efx_mcdi_rpc(efx, MC_CMD_SET_ID_LED, inbuf, sizeof(inbuf),
  852. NULL, 0, NULL);
  853. if (rc)
  854. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  855. __func__, rc);
  856. }
  857. int efx_mcdi_reset_port(struct efx_nic *efx)
  858. {
  859. int rc = efx_mcdi_rpc(efx, MC_CMD_ENTITY_RESET, NULL, 0, NULL, 0, NULL);
  860. if (rc)
  861. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n",
  862. __func__, rc);
  863. return rc;
  864. }
  865. int efx_mcdi_reset_mc(struct efx_nic *efx)
  866. {
  867. u8 inbuf[MC_CMD_REBOOT_IN_LEN];
  868. int rc;
  869. BUILD_BUG_ON(MC_CMD_REBOOT_OUT_LEN != 0);
  870. MCDI_SET_DWORD(inbuf, REBOOT_IN_FLAGS, 0);
  871. rc = efx_mcdi_rpc(efx, MC_CMD_REBOOT, inbuf, sizeof(inbuf),
  872. NULL, 0, NULL);
  873. /* White is black, and up is down */
  874. if (rc == -EIO)
  875. return 0;
  876. if (rc == 0)
  877. rc = -EIO;
  878. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  879. return rc;
  880. }
  881. static int efx_mcdi_wol_filter_set(struct efx_nic *efx, u32 type,
  882. const u8 *mac, int *id_out)
  883. {
  884. u8 inbuf[MC_CMD_WOL_FILTER_SET_IN_LEN];
  885. u8 outbuf[MC_CMD_WOL_FILTER_SET_OUT_LEN];
  886. size_t outlen;
  887. int rc;
  888. MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_WOL_TYPE, type);
  889. MCDI_SET_DWORD(inbuf, WOL_FILTER_SET_IN_FILTER_MODE,
  890. MC_CMD_FILTER_MODE_SIMPLE);
  891. memcpy(MCDI_PTR(inbuf, WOL_FILTER_SET_IN_MAGIC_MAC), mac, ETH_ALEN);
  892. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_SET, inbuf, sizeof(inbuf),
  893. outbuf, sizeof(outbuf), &outlen);
  894. if (rc)
  895. goto fail;
  896. if (outlen < MC_CMD_WOL_FILTER_SET_OUT_LEN) {
  897. rc = -EIO;
  898. goto fail;
  899. }
  900. *id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_SET_OUT_FILTER_ID);
  901. return 0;
  902. fail:
  903. *id_out = -1;
  904. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  905. return rc;
  906. }
  907. int
  908. efx_mcdi_wol_filter_set_magic(struct efx_nic *efx, const u8 *mac, int *id_out)
  909. {
  910. return efx_mcdi_wol_filter_set(efx, MC_CMD_WOL_TYPE_MAGIC, mac, id_out);
  911. }
  912. int efx_mcdi_wol_filter_get_magic(struct efx_nic *efx, int *id_out)
  913. {
  914. u8 outbuf[MC_CMD_WOL_FILTER_GET_OUT_LEN];
  915. size_t outlen;
  916. int rc;
  917. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_GET, NULL, 0,
  918. outbuf, sizeof(outbuf), &outlen);
  919. if (rc)
  920. goto fail;
  921. if (outlen < MC_CMD_WOL_FILTER_GET_OUT_LEN) {
  922. rc = -EIO;
  923. goto fail;
  924. }
  925. *id_out = (int)MCDI_DWORD(outbuf, WOL_FILTER_GET_OUT_FILTER_ID);
  926. return 0;
  927. fail:
  928. *id_out = -1;
  929. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  930. return rc;
  931. }
  932. int efx_mcdi_wol_filter_remove(struct efx_nic *efx, int id)
  933. {
  934. u8 inbuf[MC_CMD_WOL_FILTER_REMOVE_IN_LEN];
  935. int rc;
  936. MCDI_SET_DWORD(inbuf, WOL_FILTER_REMOVE_IN_FILTER_ID, (u32)id);
  937. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_REMOVE, inbuf, sizeof(inbuf),
  938. NULL, 0, NULL);
  939. if (rc)
  940. goto fail;
  941. return 0;
  942. fail:
  943. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  944. return rc;
  945. }
  946. int efx_mcdi_flush_rxqs(struct efx_nic *efx)
  947. {
  948. struct efx_channel *channel;
  949. struct efx_rx_queue *rx_queue;
  950. __le32 *qid;
  951. int rc, count;
  952. qid = kmalloc(EFX_MAX_CHANNELS * sizeof(*qid), GFP_KERNEL);
  953. if (qid == NULL)
  954. return -ENOMEM;
  955. count = 0;
  956. efx_for_each_channel(channel, efx) {
  957. efx_for_each_channel_rx_queue(rx_queue, channel) {
  958. if (rx_queue->flush_pending) {
  959. rx_queue->flush_pending = false;
  960. atomic_dec(&efx->rxq_flush_pending);
  961. qid[count++] = cpu_to_le32(
  962. efx_rx_queue_index(rx_queue));
  963. }
  964. }
  965. }
  966. rc = efx_mcdi_rpc(efx, MC_CMD_FLUSH_RX_QUEUES, (u8 *)qid,
  967. count * sizeof(*qid), NULL, 0, NULL);
  968. WARN_ON(rc > 0);
  969. kfree(qid);
  970. return rc;
  971. }
  972. int efx_mcdi_wol_filter_reset(struct efx_nic *efx)
  973. {
  974. int rc;
  975. rc = efx_mcdi_rpc(efx, MC_CMD_WOL_FILTER_RESET, NULL, 0, NULL, 0, NULL);
  976. if (rc)
  977. goto fail;
  978. return 0;
  979. fail:
  980. netif_err(efx, hw, efx->net_dev, "%s: failed rc=%d\n", __func__, rc);
  981. return rc;
  982. }