i40e_adminq.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #include <linux/delay.h>
  4. #include "i40e_alloc.h"
  5. #include "i40e_register.h"
  6. #include "i40e_prototype.h"
  7. static void i40e_resume_aq(struct i40e_hw *hw);
  8. /**
  9. * i40e_alloc_adminq_asq_ring - Allocate Admin Queue send rings
  10. * @hw: pointer to the hardware structure
  11. **/
  12. static int i40e_alloc_adminq_asq_ring(struct i40e_hw *hw)
  13. {
  14. int ret_code;
  15. ret_code = i40e_allocate_dma_mem(hw, &hw->aq.asq.desc_buf,
  16. (hw->aq.num_asq_entries *
  17. sizeof(struct i40e_aq_desc)),
  18. I40E_ADMINQ_DESC_ALIGNMENT);
  19. if (ret_code)
  20. return ret_code;
  21. ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.cmd_buf,
  22. (hw->aq.num_asq_entries *
  23. sizeof(struct i40e_asq_cmd_details)));
  24. if (ret_code) {
  25. i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
  26. return ret_code;
  27. }
  28. return ret_code;
  29. }
  30. /**
  31. * i40e_alloc_adminq_arq_ring - Allocate Admin Queue receive rings
  32. * @hw: pointer to the hardware structure
  33. **/
  34. static int i40e_alloc_adminq_arq_ring(struct i40e_hw *hw)
  35. {
  36. int ret_code;
  37. ret_code = i40e_allocate_dma_mem(hw, &hw->aq.arq.desc_buf,
  38. (hw->aq.num_arq_entries *
  39. sizeof(struct i40e_aq_desc)),
  40. I40E_ADMINQ_DESC_ALIGNMENT);
  41. return ret_code;
  42. }
  43. /**
  44. * i40e_free_adminq_asq - Free Admin Queue send rings
  45. * @hw: pointer to the hardware structure
  46. *
  47. * This assumes the posted send buffers have already been cleaned
  48. * and de-allocated
  49. **/
  50. static void i40e_free_adminq_asq(struct i40e_hw *hw)
  51. {
  52. i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
  53. }
  54. /**
  55. * i40e_free_adminq_arq - Free Admin Queue receive rings
  56. * @hw: pointer to the hardware structure
  57. *
  58. * This assumes the posted receive buffers have already been cleaned
  59. * and de-allocated
  60. **/
  61. static void i40e_free_adminq_arq(struct i40e_hw *hw)
  62. {
  63. i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf);
  64. }
  65. /**
  66. * i40e_alloc_arq_bufs - Allocate pre-posted buffers for the receive queue
  67. * @hw: pointer to the hardware structure
  68. **/
  69. static int i40e_alloc_arq_bufs(struct i40e_hw *hw)
  70. {
  71. struct i40e_aq_desc *desc;
  72. struct i40e_dma_mem *bi;
  73. int ret_code;
  74. int i;
  75. /* We'll be allocating the buffer info memory first, then we can
  76. * allocate the mapped buffers for the event processing
  77. */
  78. /* buffer_info structures do not need alignment */
  79. ret_code = i40e_allocate_virt_mem(hw, &hw->aq.arq.dma_head,
  80. (hw->aq.num_arq_entries * sizeof(struct i40e_dma_mem)));
  81. if (ret_code)
  82. goto alloc_arq_bufs;
  83. hw->aq.arq.r.arq_bi = (struct i40e_dma_mem *)hw->aq.arq.dma_head.va;
  84. /* allocate the mapped buffers */
  85. for (i = 0; i < hw->aq.num_arq_entries; i++) {
  86. bi = &hw->aq.arq.r.arq_bi[i];
  87. ret_code = i40e_allocate_dma_mem(hw, bi,
  88. hw->aq.arq_buf_size,
  89. I40E_ADMINQ_DESC_ALIGNMENT);
  90. if (ret_code)
  91. goto unwind_alloc_arq_bufs;
  92. /* now configure the descriptors for use */
  93. desc = I40E_ADMINQ_DESC(hw->aq.arq, i);
  94. desc->flags = cpu_to_le16(I40E_AQ_FLAG_BUF);
  95. if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
  96. desc->flags |= cpu_to_le16(I40E_AQ_FLAG_LB);
  97. desc->opcode = 0;
  98. /* This is in accordance with Admin queue design, there is no
  99. * register for buffer size configuration
  100. */
  101. desc->datalen = cpu_to_le16((u16)bi->size);
  102. desc->retval = 0;
  103. desc->cookie_high = 0;
  104. desc->cookie_low = 0;
  105. desc->params.external.addr_high =
  106. cpu_to_le32(upper_32_bits(bi->pa));
  107. desc->params.external.addr_low =
  108. cpu_to_le32(lower_32_bits(bi->pa));
  109. desc->params.external.param0 = 0;
  110. desc->params.external.param1 = 0;
  111. }
  112. alloc_arq_bufs:
  113. return ret_code;
  114. unwind_alloc_arq_bufs:
  115. /* don't try to free the one that failed... */
  116. i--;
  117. for (; i >= 0; i--)
  118. i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
  119. i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
  120. return ret_code;
  121. }
  122. /**
  123. * i40e_alloc_asq_bufs - Allocate empty buffer structs for the send queue
  124. * @hw: pointer to the hardware structure
  125. **/
  126. static int i40e_alloc_asq_bufs(struct i40e_hw *hw)
  127. {
  128. struct i40e_dma_mem *bi;
  129. int ret_code;
  130. int i;
  131. /* No mapped memory needed yet, just the buffer info structures */
  132. ret_code = i40e_allocate_virt_mem(hw, &hw->aq.asq.dma_head,
  133. (hw->aq.num_asq_entries * sizeof(struct i40e_dma_mem)));
  134. if (ret_code)
  135. goto alloc_asq_bufs;
  136. hw->aq.asq.r.asq_bi = (struct i40e_dma_mem *)hw->aq.asq.dma_head.va;
  137. /* allocate the mapped buffers */
  138. for (i = 0; i < hw->aq.num_asq_entries; i++) {
  139. bi = &hw->aq.asq.r.asq_bi[i];
  140. ret_code = i40e_allocate_dma_mem(hw, bi,
  141. hw->aq.asq_buf_size,
  142. I40E_ADMINQ_DESC_ALIGNMENT);
  143. if (ret_code)
  144. goto unwind_alloc_asq_bufs;
  145. }
  146. alloc_asq_bufs:
  147. return ret_code;
  148. unwind_alloc_asq_bufs:
  149. /* don't try to free the one that failed... */
  150. i--;
  151. for (; i >= 0; i--)
  152. i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
  153. i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
  154. return ret_code;
  155. }
  156. /**
  157. * i40e_free_arq_bufs - Free receive queue buffer info elements
  158. * @hw: pointer to the hardware structure
  159. **/
  160. static void i40e_free_arq_bufs(struct i40e_hw *hw)
  161. {
  162. int i;
  163. /* free descriptors */
  164. for (i = 0; i < hw->aq.num_arq_entries; i++)
  165. i40e_free_dma_mem(hw, &hw->aq.arq.r.arq_bi[i]);
  166. /* free the descriptor memory */
  167. i40e_free_dma_mem(hw, &hw->aq.arq.desc_buf);
  168. /* free the dma header */
  169. i40e_free_virt_mem(hw, &hw->aq.arq.dma_head);
  170. }
  171. /**
  172. * i40e_free_asq_bufs - Free send queue buffer info elements
  173. * @hw: pointer to the hardware structure
  174. **/
  175. static void i40e_free_asq_bufs(struct i40e_hw *hw)
  176. {
  177. int i;
  178. /* only unmap if the address is non-NULL */
  179. for (i = 0; i < hw->aq.num_asq_entries; i++)
  180. if (hw->aq.asq.r.asq_bi[i].pa)
  181. i40e_free_dma_mem(hw, &hw->aq.asq.r.asq_bi[i]);
  182. /* free the buffer info list */
  183. i40e_free_virt_mem(hw, &hw->aq.asq.cmd_buf);
  184. /* free the descriptor memory */
  185. i40e_free_dma_mem(hw, &hw->aq.asq.desc_buf);
  186. /* free the dma header */
  187. i40e_free_virt_mem(hw, &hw->aq.asq.dma_head);
  188. }
  189. /**
  190. * i40e_config_asq_regs - configure ASQ registers
  191. * @hw: pointer to the hardware structure
  192. *
  193. * Configure base address and length registers for the transmit queue
  194. **/
  195. static int i40e_config_asq_regs(struct i40e_hw *hw)
  196. {
  197. int ret_code = 0;
  198. u32 reg = 0;
  199. /* Clear Head and Tail */
  200. wr32(hw, I40E_PF_ATQH, 0);
  201. wr32(hw, I40E_PF_ATQT, 0);
  202. /* set starting point */
  203. wr32(hw, I40E_PF_ATQLEN, (hw->aq.num_asq_entries |
  204. I40E_PF_ATQLEN_ATQENABLE_MASK));
  205. wr32(hw, I40E_PF_ATQBAL, lower_32_bits(hw->aq.asq.desc_buf.pa));
  206. wr32(hw, I40E_PF_ATQBAH, upper_32_bits(hw->aq.asq.desc_buf.pa));
  207. /* Check one register to verify that config was applied */
  208. reg = rd32(hw, I40E_PF_ATQBAL);
  209. if (reg != lower_32_bits(hw->aq.asq.desc_buf.pa))
  210. ret_code = -EIO;
  211. return ret_code;
  212. }
  213. /**
  214. * i40e_config_arq_regs - ARQ register configuration
  215. * @hw: pointer to the hardware structure
  216. *
  217. * Configure base address and length registers for the receive (event queue)
  218. **/
  219. static int i40e_config_arq_regs(struct i40e_hw *hw)
  220. {
  221. int ret_code = 0;
  222. u32 reg = 0;
  223. /* Clear Head and Tail */
  224. wr32(hw, I40E_PF_ARQH, 0);
  225. wr32(hw, I40E_PF_ARQT, 0);
  226. /* set starting point */
  227. wr32(hw, I40E_PF_ARQLEN, (hw->aq.num_arq_entries |
  228. I40E_PF_ARQLEN_ARQENABLE_MASK));
  229. wr32(hw, I40E_PF_ARQBAL, lower_32_bits(hw->aq.arq.desc_buf.pa));
  230. wr32(hw, I40E_PF_ARQBAH, upper_32_bits(hw->aq.arq.desc_buf.pa));
  231. /* Update tail in the HW to post pre-allocated buffers */
  232. wr32(hw, I40E_PF_ARQT, hw->aq.num_arq_entries - 1);
  233. /* Check one register to verify that config was applied */
  234. reg = rd32(hw, I40E_PF_ARQBAL);
  235. if (reg != lower_32_bits(hw->aq.arq.desc_buf.pa))
  236. ret_code = -EIO;
  237. return ret_code;
  238. }
  239. /**
  240. * i40e_init_asq - main initialization routine for ASQ
  241. * @hw: pointer to the hardware structure
  242. *
  243. * This is the main initialization routine for the Admin Send Queue
  244. * Prior to calling this function, drivers *MUST* set the following fields
  245. * in the hw->aq structure:
  246. * - hw->aq.num_asq_entries
  247. * - hw->aq.arq_buf_size
  248. *
  249. * Do *NOT* hold the lock when calling this as the memory allocation routines
  250. * called are not going to be atomic context safe
  251. **/
  252. static int i40e_init_asq(struct i40e_hw *hw)
  253. {
  254. int ret_code = 0;
  255. if (hw->aq.asq.count > 0) {
  256. /* queue already initialized */
  257. ret_code = -EBUSY;
  258. goto init_adminq_exit;
  259. }
  260. /* verify input for valid configuration */
  261. if ((hw->aq.num_asq_entries == 0) ||
  262. (hw->aq.asq_buf_size == 0)) {
  263. ret_code = -EIO;
  264. goto init_adminq_exit;
  265. }
  266. hw->aq.asq.next_to_use = 0;
  267. hw->aq.asq.next_to_clean = 0;
  268. /* allocate the ring memory */
  269. ret_code = i40e_alloc_adminq_asq_ring(hw);
  270. if (ret_code)
  271. goto init_adminq_exit;
  272. /* allocate buffers in the rings */
  273. ret_code = i40e_alloc_asq_bufs(hw);
  274. if (ret_code)
  275. goto init_adminq_free_rings;
  276. /* initialize base registers */
  277. ret_code = i40e_config_asq_regs(hw);
  278. if (ret_code)
  279. goto init_adminq_free_rings;
  280. /* success! */
  281. hw->aq.asq.count = hw->aq.num_asq_entries;
  282. goto init_adminq_exit;
  283. init_adminq_free_rings:
  284. i40e_free_adminq_asq(hw);
  285. init_adminq_exit:
  286. return ret_code;
  287. }
  288. /**
  289. * i40e_init_arq - initialize ARQ
  290. * @hw: pointer to the hardware structure
  291. *
  292. * The main initialization routine for the Admin Receive (Event) Queue.
  293. * Prior to calling this function, drivers *MUST* set the following fields
  294. * in the hw->aq structure:
  295. * - hw->aq.num_asq_entries
  296. * - hw->aq.arq_buf_size
  297. *
  298. * Do *NOT* hold the lock when calling this as the memory allocation routines
  299. * called are not going to be atomic context safe
  300. **/
  301. static int i40e_init_arq(struct i40e_hw *hw)
  302. {
  303. int ret_code = 0;
  304. if (hw->aq.arq.count > 0) {
  305. /* queue already initialized */
  306. ret_code = -EBUSY;
  307. goto init_adminq_exit;
  308. }
  309. /* verify input for valid configuration */
  310. if ((hw->aq.num_arq_entries == 0) ||
  311. (hw->aq.arq_buf_size == 0)) {
  312. ret_code = -EIO;
  313. goto init_adminq_exit;
  314. }
  315. hw->aq.arq.next_to_use = 0;
  316. hw->aq.arq.next_to_clean = 0;
  317. /* allocate the ring memory */
  318. ret_code = i40e_alloc_adminq_arq_ring(hw);
  319. if (ret_code)
  320. goto init_adminq_exit;
  321. /* allocate buffers in the rings */
  322. ret_code = i40e_alloc_arq_bufs(hw);
  323. if (ret_code)
  324. goto init_adminq_free_rings;
  325. /* initialize base registers */
  326. ret_code = i40e_config_arq_regs(hw);
  327. if (ret_code)
  328. goto init_adminq_free_rings;
  329. /* success! */
  330. hw->aq.arq.count = hw->aq.num_arq_entries;
  331. goto init_adminq_exit;
  332. init_adminq_free_rings:
  333. i40e_free_adminq_arq(hw);
  334. init_adminq_exit:
  335. return ret_code;
  336. }
  337. /**
  338. * i40e_shutdown_asq - shutdown the ASQ
  339. * @hw: pointer to the hardware structure
  340. *
  341. * The main shutdown routine for the Admin Send Queue
  342. **/
  343. static int i40e_shutdown_asq(struct i40e_hw *hw)
  344. {
  345. int ret_code = 0;
  346. mutex_lock(&hw->aq.asq_mutex);
  347. if (hw->aq.asq.count == 0) {
  348. ret_code = -EBUSY;
  349. goto shutdown_asq_out;
  350. }
  351. /* Stop firmware AdminQ processing */
  352. wr32(hw, I40E_PF_ATQH, 0);
  353. wr32(hw, I40E_PF_ATQT, 0);
  354. wr32(hw, I40E_PF_ATQLEN, 0);
  355. wr32(hw, I40E_PF_ATQBAL, 0);
  356. wr32(hw, I40E_PF_ATQBAH, 0);
  357. hw->aq.asq.count = 0; /* to indicate uninitialized queue */
  358. /* free ring buffers */
  359. i40e_free_asq_bufs(hw);
  360. shutdown_asq_out:
  361. mutex_unlock(&hw->aq.asq_mutex);
  362. return ret_code;
  363. }
  364. /**
  365. * i40e_shutdown_arq - shutdown ARQ
  366. * @hw: pointer to the hardware structure
  367. *
  368. * The main shutdown routine for the Admin Receive Queue
  369. **/
  370. static int i40e_shutdown_arq(struct i40e_hw *hw)
  371. {
  372. int ret_code = 0;
  373. mutex_lock(&hw->aq.arq_mutex);
  374. if (hw->aq.arq.count == 0) {
  375. ret_code = -EBUSY;
  376. goto shutdown_arq_out;
  377. }
  378. /* Stop firmware AdminQ processing */
  379. wr32(hw, I40E_PF_ARQH, 0);
  380. wr32(hw, I40E_PF_ARQT, 0);
  381. wr32(hw, I40E_PF_ARQLEN, 0);
  382. wr32(hw, I40E_PF_ARQBAL, 0);
  383. wr32(hw, I40E_PF_ARQBAH, 0);
  384. hw->aq.arq.count = 0; /* to indicate uninitialized queue */
  385. /* free ring buffers */
  386. i40e_free_arq_bufs(hw);
  387. shutdown_arq_out:
  388. mutex_unlock(&hw->aq.arq_mutex);
  389. return ret_code;
  390. }
  391. /**
  392. * i40e_set_hw_caps - set HW flags
  393. * @hw: pointer to the hardware structure
  394. **/
  395. static void i40e_set_hw_caps(struct i40e_hw *hw)
  396. {
  397. bitmap_zero(hw->caps, I40E_HW_CAPS_NBITS);
  398. switch (hw->mac.type) {
  399. case I40E_MAC_XL710:
  400. if (i40e_is_aq_api_ver_ge(hw, 1,
  401. I40E_MINOR_VER_GET_LINK_INFO_XL710)) {
  402. set_bit(I40E_HW_CAP_AQ_PHY_ACCESS, hw->caps);
  403. set_bit(I40E_HW_CAP_FW_LLDP_STOPPABLE, hw->caps);
  404. /* The ability to RX (not drop) 802.1ad frames */
  405. set_bit(I40E_HW_CAP_802_1AD, hw->caps);
  406. }
  407. if (i40e_is_aq_api_ver_ge(hw, 1, 5)) {
  408. /* Supported in FW API version higher than 1.4 */
  409. set_bit(I40E_HW_CAP_GENEVE_OFFLOAD, hw->caps);
  410. }
  411. if (i40e_is_fw_ver_lt(hw, 4, 33)) {
  412. set_bit(I40E_HW_CAP_RESTART_AUTONEG, hw->caps);
  413. /* No DCB support for FW < v4.33 */
  414. set_bit(I40E_HW_CAP_NO_DCB_SUPPORT, hw->caps);
  415. }
  416. if (i40e_is_fw_ver_lt(hw, 4, 3)) {
  417. /* Disable FW LLDP if FW < v4.3 */
  418. set_bit(I40E_HW_CAP_STOP_FW_LLDP, hw->caps);
  419. }
  420. if (i40e_is_fw_ver_ge(hw, 4, 40)) {
  421. /* Use the FW Set LLDP MIB API if FW >= v4.40 */
  422. set_bit(I40E_HW_CAP_USE_SET_LLDP_MIB, hw->caps);
  423. }
  424. if (i40e_is_fw_ver_ge(hw, 6, 0)) {
  425. /* Enable PTP L4 if FW > v6.0 */
  426. set_bit(I40E_HW_CAP_PTP_L4, hw->caps);
  427. }
  428. break;
  429. case I40E_MAC_X722:
  430. set_bit(I40E_HW_CAP_AQ_SRCTL_ACCESS_ENABLE, hw->caps);
  431. set_bit(I40E_HW_CAP_NVM_READ_REQUIRES_LOCK, hw->caps);
  432. set_bit(I40E_HW_CAP_RSS_AQ, hw->caps);
  433. set_bit(I40E_HW_CAP_128_QP_RSS, hw->caps);
  434. set_bit(I40E_HW_CAP_ATR_EVICT, hw->caps);
  435. set_bit(I40E_HW_CAP_WB_ON_ITR, hw->caps);
  436. set_bit(I40E_HW_CAP_MULTI_TCP_UDP_RSS_PCTYPE, hw->caps);
  437. set_bit(I40E_HW_CAP_NO_PCI_LINK_CHECK, hw->caps);
  438. set_bit(I40E_HW_CAP_USE_SET_LLDP_MIB, hw->caps);
  439. set_bit(I40E_HW_CAP_GENEVE_OFFLOAD, hw->caps);
  440. set_bit(I40E_HW_CAP_PTP_L4, hw->caps);
  441. set_bit(I40E_HW_CAP_WOL_MC_MAGIC_PKT_WAKE, hw->caps);
  442. set_bit(I40E_HW_CAP_OUTER_UDP_CSUM, hw->caps);
  443. if (rd32(hw, I40E_GLQF_FDEVICTENA(1)) !=
  444. I40E_FDEVICT_PCTYPE_DEFAULT) {
  445. hw_warn(hw, "FD EVICT PCTYPES are not right, disable FD HW EVICT\n");
  446. clear_bit(I40E_HW_CAP_ATR_EVICT, hw->caps);
  447. }
  448. if (i40e_is_aq_api_ver_ge(hw, 1,
  449. I40E_MINOR_VER_FW_LLDP_STOPPABLE_X722))
  450. set_bit(I40E_HW_CAP_FW_LLDP_STOPPABLE, hw->caps);
  451. if (i40e_is_aq_api_ver_ge(hw, 1,
  452. I40E_MINOR_VER_GET_LINK_INFO_X722))
  453. set_bit(I40E_HW_CAP_AQ_PHY_ACCESS, hw->caps);
  454. if (i40e_is_aq_api_ver_ge(hw, 1,
  455. I40E_MINOR_VER_FW_REQUEST_FEC_X722))
  456. set_bit(I40E_HW_CAP_X722_FEC_REQUEST, hw->caps);
  457. fallthrough;
  458. default:
  459. break;
  460. }
  461. /* Newer versions of firmware require lock when reading the NVM */
  462. if (i40e_is_aq_api_ver_ge(hw, 1, 5))
  463. set_bit(I40E_HW_CAP_NVM_READ_REQUIRES_LOCK, hw->caps);
  464. /* The ability to RX (not drop) 802.1ad frames was added in API 1.7 */
  465. if (i40e_is_aq_api_ver_ge(hw, 1, 7))
  466. set_bit(I40E_HW_CAP_802_1AD, hw->caps);
  467. if (i40e_is_aq_api_ver_ge(hw, 1, 8))
  468. set_bit(I40E_HW_CAP_FW_LLDP_PERSISTENT, hw->caps);
  469. if (i40e_is_aq_api_ver_ge(hw, 1, 9))
  470. set_bit(I40E_HW_CAP_AQ_PHY_ACCESS_EXTENDED, hw->caps);
  471. }
  472. /**
  473. * i40e_init_adminq - main initialization routine for Admin Queue
  474. * @hw: pointer to the hardware structure
  475. *
  476. * Prior to calling this function, drivers *MUST* set the following fields
  477. * in the hw->aq structure:
  478. * - hw->aq.num_asq_entries
  479. * - hw->aq.num_arq_entries
  480. * - hw->aq.arq_buf_size
  481. * - hw->aq.asq_buf_size
  482. **/
  483. int i40e_init_adminq(struct i40e_hw *hw)
  484. {
  485. u16 cfg_ptr, oem_hi, oem_lo;
  486. u16 eetrack_lo, eetrack_hi;
  487. int retry = 0;
  488. int ret_code;
  489. /* verify input for valid configuration */
  490. if ((hw->aq.num_arq_entries == 0) ||
  491. (hw->aq.num_asq_entries == 0) ||
  492. (hw->aq.arq_buf_size == 0) ||
  493. (hw->aq.asq_buf_size == 0)) {
  494. ret_code = -EIO;
  495. goto init_adminq_exit;
  496. }
  497. /* setup ASQ command write back timeout */
  498. hw->aq.asq_cmd_timeout = I40E_ASQ_CMD_TIMEOUT;
  499. /* allocate the ASQ */
  500. ret_code = i40e_init_asq(hw);
  501. if (ret_code)
  502. goto init_adminq_destroy_locks;
  503. /* allocate the ARQ */
  504. ret_code = i40e_init_arq(hw);
  505. if (ret_code)
  506. goto init_adminq_free_asq;
  507. /* There are some cases where the firmware may not be quite ready
  508. * for AdminQ operations, so we retry the AdminQ setup a few times
  509. * if we see timeouts in this first AQ call.
  510. */
  511. do {
  512. ret_code = i40e_aq_get_firmware_version(hw,
  513. &hw->aq.fw_maj_ver,
  514. &hw->aq.fw_min_ver,
  515. &hw->aq.fw_build,
  516. &hw->aq.api_maj_ver,
  517. &hw->aq.api_min_ver,
  518. NULL);
  519. if (ret_code != -EIO)
  520. break;
  521. retry++;
  522. msleep(100);
  523. i40e_resume_aq(hw);
  524. } while (retry < 10);
  525. if (ret_code != 0)
  526. goto init_adminq_free_arq;
  527. /* Some features were introduced in different FW API version
  528. * for different MAC type.
  529. */
  530. i40e_set_hw_caps(hw);
  531. /* get the NVM version info */
  532. i40e_read_nvm_word(hw, I40E_SR_NVM_DEV_STARTER_VERSION,
  533. &hw->nvm.version);
  534. i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_LO, &eetrack_lo);
  535. i40e_read_nvm_word(hw, I40E_SR_NVM_EETRACK_HI, &eetrack_hi);
  536. hw->nvm.eetrack = (eetrack_hi << 16) | eetrack_lo;
  537. i40e_read_nvm_word(hw, I40E_SR_BOOT_CONFIG_PTR, &cfg_ptr);
  538. i40e_read_nvm_word(hw, (cfg_ptr + I40E_NVM_OEM_VER_OFF),
  539. &oem_hi);
  540. i40e_read_nvm_word(hw, (cfg_ptr + (I40E_NVM_OEM_VER_OFF + 1)),
  541. &oem_lo);
  542. hw->nvm.oem_ver = ((u32)oem_hi << 16) | oem_lo;
  543. if (i40e_is_aq_api_ver_ge(hw, I40E_FW_API_VERSION_MAJOR + 1, 0)) {
  544. ret_code = -EIO;
  545. goto init_adminq_free_arq;
  546. }
  547. /* pre-emptive resource lock release */
  548. i40e_aq_release_resource(hw, I40E_NVM_RESOURCE_ID, 0, NULL);
  549. hw->nvm_release_on_done = false;
  550. hw->nvmupd_state = I40E_NVMUPD_STATE_INIT;
  551. ret_code = 0;
  552. /* success! */
  553. goto init_adminq_exit;
  554. init_adminq_free_arq:
  555. i40e_shutdown_arq(hw);
  556. init_adminq_free_asq:
  557. i40e_shutdown_asq(hw);
  558. init_adminq_destroy_locks:
  559. init_adminq_exit:
  560. return ret_code;
  561. }
  562. /**
  563. * i40e_shutdown_adminq - shutdown routine for the Admin Queue
  564. * @hw: pointer to the hardware structure
  565. **/
  566. void i40e_shutdown_adminq(struct i40e_hw *hw)
  567. {
  568. if (i40e_check_asq_alive(hw))
  569. i40e_aq_queue_shutdown(hw, true);
  570. i40e_shutdown_asq(hw);
  571. i40e_shutdown_arq(hw);
  572. if (hw->nvm_buff.va)
  573. i40e_free_virt_mem(hw, &hw->nvm_buff);
  574. }
  575. /**
  576. * i40e_clean_asq - cleans Admin send queue
  577. * @hw: pointer to the hardware structure
  578. *
  579. * returns the number of free desc
  580. **/
  581. static u16 i40e_clean_asq(struct i40e_hw *hw)
  582. {
  583. struct i40e_adminq_ring *asq = &(hw->aq.asq);
  584. struct i40e_asq_cmd_details *details;
  585. u16 ntc = asq->next_to_clean;
  586. struct i40e_aq_desc desc_cb;
  587. struct i40e_aq_desc *desc;
  588. desc = I40E_ADMINQ_DESC(*asq, ntc);
  589. details = I40E_ADMINQ_DETAILS(*asq, ntc);
  590. while (rd32(hw, I40E_PF_ATQH) != ntc) {
  591. i40e_debug(hw, I40E_DEBUG_AQ_COMMAND,
  592. "ntc %d head %d.\n", ntc, rd32(hw, I40E_PF_ATQH));
  593. if (details->callback) {
  594. I40E_ADMINQ_CALLBACK cb_func =
  595. (I40E_ADMINQ_CALLBACK)details->callback;
  596. desc_cb = *desc;
  597. cb_func(hw, &desc_cb);
  598. }
  599. memset(desc, 0, sizeof(*desc));
  600. memset(details, 0, sizeof(*details));
  601. ntc++;
  602. if (ntc == asq->count)
  603. ntc = 0;
  604. desc = I40E_ADMINQ_DESC(*asq, ntc);
  605. details = I40E_ADMINQ_DETAILS(*asq, ntc);
  606. }
  607. asq->next_to_clean = ntc;
  608. return I40E_DESC_UNUSED(asq);
  609. }
  610. /**
  611. * i40e_asq_done - check if FW has processed the Admin Send Queue
  612. * @hw: pointer to the hw struct
  613. *
  614. * Returns true if the firmware has processed all descriptors on the
  615. * admin send queue. Returns false if there are still requests pending.
  616. **/
  617. static bool i40e_asq_done(struct i40e_hw *hw)
  618. {
  619. /* AQ designers suggest use of head for better
  620. * timing reliability than DD bit
  621. */
  622. return rd32(hw, I40E_PF_ATQH) == hw->aq.asq.next_to_use;
  623. }
  624. /**
  625. * i40e_asq_send_command_atomic_exec - send command to Admin Queue
  626. * @hw: pointer to the hw struct
  627. * @desc: prefilled descriptor describing the command (non DMA mem)
  628. * @buff: buffer to use for indirect commands
  629. * @buff_size: size of buffer for indirect commands
  630. * @cmd_details: pointer to command details structure
  631. * @is_atomic_context: is the function called in an atomic context?
  632. *
  633. * This is the main send command driver routine for the Admin Queue send
  634. * queue. It runs the queue, cleans the queue, etc
  635. **/
  636. static int
  637. i40e_asq_send_command_atomic_exec(struct i40e_hw *hw,
  638. struct i40e_aq_desc *desc,
  639. void *buff, /* can be NULL */
  640. u16 buff_size,
  641. struct i40e_asq_cmd_details *cmd_details,
  642. bool is_atomic_context)
  643. {
  644. struct i40e_dma_mem *dma_buff = NULL;
  645. struct i40e_asq_cmd_details *details;
  646. struct i40e_aq_desc *desc_on_ring;
  647. bool cmd_completed = false;
  648. u16 retval = 0;
  649. int status = 0;
  650. u32 val = 0;
  651. if (hw->aq.asq.count == 0) {
  652. i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
  653. "AQTX: Admin queue not initialized.\n");
  654. status = -EIO;
  655. goto asq_send_command_error;
  656. }
  657. hw->aq.asq_last_status = I40E_AQ_RC_OK;
  658. val = rd32(hw, I40E_PF_ATQH);
  659. if (val >= hw->aq.num_asq_entries) {
  660. i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
  661. "AQTX: head overrun at %d\n", val);
  662. status = -ENOSPC;
  663. goto asq_send_command_error;
  664. }
  665. details = I40E_ADMINQ_DETAILS(hw->aq.asq, hw->aq.asq.next_to_use);
  666. if (cmd_details) {
  667. *details = *cmd_details;
  668. /* If the cmd_details are defined copy the cookie. The
  669. * cpu_to_le32 is not needed here because the data is ignored
  670. * by the FW, only used by the driver
  671. */
  672. if (details->cookie) {
  673. desc->cookie_high =
  674. cpu_to_le32(upper_32_bits(details->cookie));
  675. desc->cookie_low =
  676. cpu_to_le32(lower_32_bits(details->cookie));
  677. }
  678. } else {
  679. memset(details, 0, sizeof(struct i40e_asq_cmd_details));
  680. }
  681. /* clear requested flags and then set additional flags if defined */
  682. desc->flags &= ~cpu_to_le16(details->flags_dis);
  683. desc->flags |= cpu_to_le16(details->flags_ena);
  684. if (buff_size > hw->aq.asq_buf_size) {
  685. i40e_debug(hw,
  686. I40E_DEBUG_AQ_MESSAGE,
  687. "AQTX: Invalid buffer size: %d.\n",
  688. buff_size);
  689. status = -EINVAL;
  690. goto asq_send_command_error;
  691. }
  692. if (details->postpone && !details->async) {
  693. i40e_debug(hw,
  694. I40E_DEBUG_AQ_MESSAGE,
  695. "AQTX: Async flag not set along with postpone flag");
  696. status = -EINVAL;
  697. goto asq_send_command_error;
  698. }
  699. /* call clean and check queue available function to reclaim the
  700. * descriptors that were processed by FW, the function returns the
  701. * number of desc available
  702. */
  703. /* the clean function called here could be called in a separate thread
  704. * in case of asynchronous completions
  705. */
  706. if (i40e_clean_asq(hw) == 0) {
  707. i40e_debug(hw,
  708. I40E_DEBUG_AQ_MESSAGE,
  709. "AQTX: Error queue is full.\n");
  710. status = -ENOSPC;
  711. goto asq_send_command_error;
  712. }
  713. /* initialize the temp desc pointer with the right desc */
  714. desc_on_ring = I40E_ADMINQ_DESC(hw->aq.asq, hw->aq.asq.next_to_use);
  715. /* if the desc is available copy the temp desc to the right place */
  716. *desc_on_ring = *desc;
  717. /* if buff is not NULL assume indirect command */
  718. if (buff != NULL) {
  719. dma_buff = &(hw->aq.asq.r.asq_bi[hw->aq.asq.next_to_use]);
  720. /* copy the user buff into the respective DMA buff */
  721. memcpy(dma_buff->va, buff, buff_size);
  722. desc_on_ring->datalen = cpu_to_le16(buff_size);
  723. /* Update the address values in the desc with the pa value
  724. * for respective buffer
  725. */
  726. desc_on_ring->params.external.addr_high =
  727. cpu_to_le32(upper_32_bits(dma_buff->pa));
  728. desc_on_ring->params.external.addr_low =
  729. cpu_to_le32(lower_32_bits(dma_buff->pa));
  730. }
  731. /* bump the tail */
  732. i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQTX: desc and buffer:\n");
  733. i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc_on_ring,
  734. buff, buff_size);
  735. (hw->aq.asq.next_to_use)++;
  736. if (hw->aq.asq.next_to_use == hw->aq.asq.count)
  737. hw->aq.asq.next_to_use = 0;
  738. if (!details->postpone)
  739. wr32(hw, I40E_PF_ATQT, hw->aq.asq.next_to_use);
  740. /* if cmd_details are not defined or async flag is not set,
  741. * we need to wait for desc write back
  742. */
  743. if (!details->async && !details->postpone) {
  744. u32 total_delay = 0;
  745. do {
  746. /* AQ designers suggest use of head for better
  747. * timing reliability than DD bit
  748. */
  749. if (i40e_asq_done(hw))
  750. break;
  751. if (is_atomic_context)
  752. udelay(50);
  753. else
  754. usleep_range(40, 60);
  755. total_delay += 50;
  756. } while (total_delay < hw->aq.asq_cmd_timeout);
  757. }
  758. /* if ready, copy the desc back to temp */
  759. if (i40e_asq_done(hw)) {
  760. *desc = *desc_on_ring;
  761. if (buff != NULL)
  762. memcpy(buff, dma_buff->va, buff_size);
  763. retval = le16_to_cpu(desc->retval);
  764. if (retval != 0) {
  765. i40e_debug(hw,
  766. I40E_DEBUG_AQ_MESSAGE,
  767. "AQTX: Command completed with error 0x%X.\n",
  768. retval);
  769. /* strip off FW internal code */
  770. retval &= 0xff;
  771. }
  772. cmd_completed = true;
  773. if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_OK)
  774. status = 0;
  775. else if ((enum i40e_admin_queue_err)retval == I40E_AQ_RC_EBUSY)
  776. status = -EBUSY;
  777. else
  778. status = -EIO;
  779. hw->aq.asq_last_status = (enum i40e_admin_queue_err)retval;
  780. }
  781. i40e_debug(hw, I40E_DEBUG_AQ_COMMAND,
  782. "AQTX: desc and buffer writeback:\n");
  783. i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, buff, buff_size);
  784. /* save writeback aq if requested */
  785. if (details->wb_desc)
  786. *details->wb_desc = *desc_on_ring;
  787. /* update the error if time out occurred */
  788. if ((!cmd_completed) &&
  789. (!details->async && !details->postpone)) {
  790. if (rd32(hw, I40E_PF_ATQLEN) & I40E_GL_ATQLEN_ATQCRIT_MASK) {
  791. i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
  792. "AQTX: AQ Critical error.\n");
  793. status = -EIO;
  794. } else {
  795. i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
  796. "AQTX: Writeback timeout.\n");
  797. status = -EIO;
  798. }
  799. }
  800. asq_send_command_error:
  801. return status;
  802. }
  803. /**
  804. * i40e_asq_send_command_atomic - send command to Admin Queue
  805. * @hw: pointer to the hw struct
  806. * @desc: prefilled descriptor describing the command (non DMA mem)
  807. * @buff: buffer to use for indirect commands
  808. * @buff_size: size of buffer for indirect commands
  809. * @cmd_details: pointer to command details structure
  810. * @is_atomic_context: is the function called in an atomic context?
  811. *
  812. * Acquires the lock and calls the main send command execution
  813. * routine.
  814. **/
  815. int
  816. i40e_asq_send_command_atomic(struct i40e_hw *hw,
  817. struct i40e_aq_desc *desc,
  818. void *buff, /* can be NULL */
  819. u16 buff_size,
  820. struct i40e_asq_cmd_details *cmd_details,
  821. bool is_atomic_context)
  822. {
  823. int status;
  824. mutex_lock(&hw->aq.asq_mutex);
  825. status = i40e_asq_send_command_atomic_exec(hw, desc, buff, buff_size,
  826. cmd_details,
  827. is_atomic_context);
  828. mutex_unlock(&hw->aq.asq_mutex);
  829. return status;
  830. }
  831. int
  832. i40e_asq_send_command(struct i40e_hw *hw, struct i40e_aq_desc *desc,
  833. void *buff, /* can be NULL */ u16 buff_size,
  834. struct i40e_asq_cmd_details *cmd_details)
  835. {
  836. return i40e_asq_send_command_atomic(hw, desc, buff, buff_size,
  837. cmd_details, false);
  838. }
  839. /**
  840. * i40e_asq_send_command_atomic_v2 - send command to Admin Queue
  841. * @hw: pointer to the hw struct
  842. * @desc: prefilled descriptor describing the command (non DMA mem)
  843. * @buff: buffer to use for indirect commands
  844. * @buff_size: size of buffer for indirect commands
  845. * @cmd_details: pointer to command details structure
  846. * @is_atomic_context: is the function called in an atomic context?
  847. * @aq_status: pointer to Admin Queue status return value
  848. *
  849. * Acquires the lock and calls the main send command execution
  850. * routine. Returns the last Admin Queue status in aq_status
  851. * to avoid race conditions in access to hw->aq.asq_last_status.
  852. **/
  853. int
  854. i40e_asq_send_command_atomic_v2(struct i40e_hw *hw,
  855. struct i40e_aq_desc *desc,
  856. void *buff, /* can be NULL */
  857. u16 buff_size,
  858. struct i40e_asq_cmd_details *cmd_details,
  859. bool is_atomic_context,
  860. enum i40e_admin_queue_err *aq_status)
  861. {
  862. int status;
  863. mutex_lock(&hw->aq.asq_mutex);
  864. status = i40e_asq_send_command_atomic_exec(hw, desc, buff,
  865. buff_size,
  866. cmd_details,
  867. is_atomic_context);
  868. if (aq_status)
  869. *aq_status = hw->aq.asq_last_status;
  870. mutex_unlock(&hw->aq.asq_mutex);
  871. return status;
  872. }
  873. int
  874. i40e_asq_send_command_v2(struct i40e_hw *hw, struct i40e_aq_desc *desc,
  875. void *buff, /* can be NULL */ u16 buff_size,
  876. struct i40e_asq_cmd_details *cmd_details,
  877. enum i40e_admin_queue_err *aq_status)
  878. {
  879. return i40e_asq_send_command_atomic_v2(hw, desc, buff, buff_size,
  880. cmd_details, true, aq_status);
  881. }
  882. /**
  883. * i40e_fill_default_direct_cmd_desc - AQ descriptor helper function
  884. * @desc: pointer to the temp descriptor (non DMA mem)
  885. * @opcode: the opcode can be used to decide which flags to turn off or on
  886. *
  887. * Fill the desc with default values
  888. **/
  889. void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc,
  890. u16 opcode)
  891. {
  892. /* zero out the desc */
  893. memset((void *)desc, 0, sizeof(struct i40e_aq_desc));
  894. desc->opcode = cpu_to_le16(opcode);
  895. desc->flags = cpu_to_le16(I40E_AQ_FLAG_SI);
  896. }
  897. /**
  898. * i40e_clean_arq_element
  899. * @hw: pointer to the hw struct
  900. * @e: event info from the receive descriptor, includes any buffers
  901. * @pending: number of events that could be left to process
  902. *
  903. * This function cleans one Admin Receive Queue element and returns
  904. * the contents through e. It can also return how many events are
  905. * left to process through 'pending'
  906. **/
  907. int i40e_clean_arq_element(struct i40e_hw *hw,
  908. struct i40e_arq_event_info *e,
  909. u16 *pending)
  910. {
  911. u16 ntc = hw->aq.arq.next_to_clean;
  912. struct i40e_aq_desc *desc;
  913. struct i40e_dma_mem *bi;
  914. int ret_code = 0;
  915. u16 desc_idx;
  916. u16 datalen;
  917. u16 flags;
  918. u16 ntu;
  919. /* pre-clean the event info */
  920. memset(&e->desc, 0, sizeof(e->desc));
  921. /* take the lock before we start messing with the ring */
  922. mutex_lock(&hw->aq.arq_mutex);
  923. if (hw->aq.arq.count == 0) {
  924. i40e_debug(hw, I40E_DEBUG_AQ_MESSAGE,
  925. "AQRX: Admin queue not initialized.\n");
  926. ret_code = -EIO;
  927. goto clean_arq_element_err;
  928. }
  929. /* set next_to_use to head */
  930. ntu = rd32(hw, I40E_PF_ARQH) & I40E_PF_ARQH_ARQH_MASK;
  931. if (ntu == ntc) {
  932. /* nothing to do - shouldn't need to update ring's values */
  933. ret_code = -EALREADY;
  934. goto clean_arq_element_out;
  935. }
  936. /* now clean the next descriptor */
  937. desc = I40E_ADMINQ_DESC(hw->aq.arq, ntc);
  938. desc_idx = ntc;
  939. hw->aq.arq_last_status =
  940. (enum i40e_admin_queue_err)le16_to_cpu(desc->retval);
  941. flags = le16_to_cpu(desc->flags);
  942. if (flags & I40E_AQ_FLAG_ERR) {
  943. ret_code = -EIO;
  944. i40e_debug(hw,
  945. I40E_DEBUG_AQ_MESSAGE,
  946. "AQRX: Event received with error 0x%X.\n",
  947. hw->aq.arq_last_status);
  948. }
  949. e->desc = *desc;
  950. datalen = le16_to_cpu(desc->datalen);
  951. e->msg_len = min(datalen, e->buf_len);
  952. if (e->msg_buf != NULL && (e->msg_len != 0))
  953. memcpy(e->msg_buf, hw->aq.arq.r.arq_bi[desc_idx].va,
  954. e->msg_len);
  955. i40e_debug(hw, I40E_DEBUG_AQ_COMMAND, "AQRX: desc and buffer:\n");
  956. i40e_debug_aq(hw, I40E_DEBUG_AQ_COMMAND, (void *)desc, e->msg_buf,
  957. hw->aq.arq_buf_size);
  958. /* Restore the original datalen and buffer address in the desc,
  959. * FW updates datalen to indicate the event message
  960. * size
  961. */
  962. bi = &hw->aq.arq.r.arq_bi[ntc];
  963. memset((void *)desc, 0, sizeof(struct i40e_aq_desc));
  964. desc->flags = cpu_to_le16(I40E_AQ_FLAG_BUF);
  965. if (hw->aq.arq_buf_size > I40E_AQ_LARGE_BUF)
  966. desc->flags |= cpu_to_le16(I40E_AQ_FLAG_LB);
  967. desc->datalen = cpu_to_le16((u16)bi->size);
  968. desc->params.external.addr_high = cpu_to_le32(upper_32_bits(bi->pa));
  969. desc->params.external.addr_low = cpu_to_le32(lower_32_bits(bi->pa));
  970. /* set tail = the last cleaned desc index. */
  971. wr32(hw, I40E_PF_ARQT, ntc);
  972. /* ntc is updated to tail + 1 */
  973. ntc++;
  974. if (ntc == hw->aq.num_arq_entries)
  975. ntc = 0;
  976. hw->aq.arq.next_to_clean = ntc;
  977. hw->aq.arq.next_to_use = ntu;
  978. i40e_nvmupd_check_wait_event(hw, le16_to_cpu(e->desc.opcode), &e->desc);
  979. clean_arq_element_out:
  980. /* Set pending if needed, unlock and return */
  981. if (pending)
  982. *pending = (ntc > ntu ? hw->aq.arq.count : 0) + (ntu - ntc);
  983. clean_arq_element_err:
  984. mutex_unlock(&hw->aq.arq_mutex);
  985. return ret_code;
  986. }
  987. static void i40e_resume_aq(struct i40e_hw *hw)
  988. {
  989. /* Registers are reset after PF reset */
  990. hw->aq.asq.next_to_use = 0;
  991. hw->aq.asq.next_to_clean = 0;
  992. i40e_config_asq_regs(hw);
  993. hw->aq.arq.next_to_use = 0;
  994. hw->aq.arq.next_to_clean = 0;
  995. i40e_config_arq_regs(hw);
  996. }