i40iw_uk.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204
  1. /*******************************************************************************
  2. *
  3. * Copyright (c) 2015-2016 Intel Corporation. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenFabrics.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. *
  33. *******************************************************************************/
  34. #include "i40iw_osdep.h"
  35. #include "i40iw_status.h"
  36. #include "i40iw_d.h"
  37. #include "i40iw_user.h"
  38. #include "i40iw_register.h"
  39. static u32 nop_signature = 0x55550000;
  40. /**
  41. * i40iw_nop_1 - insert a nop wqe and move head. no post work
  42. * @qp: hw qp ptr
  43. */
  44. static enum i40iw_status_code i40iw_nop_1(struct i40iw_qp_uk *qp)
  45. {
  46. u64 header, *wqe;
  47. u64 *wqe_0 = NULL;
  48. u32 wqe_idx, peek_head;
  49. bool signaled = false;
  50. if (!qp->sq_ring.head)
  51. return I40IW_ERR_PARAM;
  52. wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  53. wqe = qp->sq_base[wqe_idx].elem;
  54. peek_head = (qp->sq_ring.head + 1) % qp->sq_ring.size;
  55. wqe_0 = qp->sq_base[peek_head].elem;
  56. if (peek_head)
  57. wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
  58. else
  59. wqe_0[3] = LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  60. set_64bit_val(wqe, 0, 0);
  61. set_64bit_val(wqe, 8, 0);
  62. set_64bit_val(wqe, 16, 0);
  63. header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
  64. LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
  65. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID) | nop_signature++;
  66. wmb(); /* Memory barrier to ensure data is written before valid bit is set */
  67. set_64bit_val(wqe, 24, header);
  68. return 0;
  69. }
  70. /**
  71. * i40iw_qp_post_wr - post wr to hrdware
  72. * @qp: hw qp ptr
  73. */
  74. void i40iw_qp_post_wr(struct i40iw_qp_uk *qp)
  75. {
  76. u64 temp;
  77. u32 hw_sq_tail;
  78. u32 sw_sq_head;
  79. mb(); /* valid bit is written and loads completed before reading shadow */
  80. /* read the doorbell shadow area */
  81. get_64bit_val(qp->shadow_area, 0, &temp);
  82. hw_sq_tail = (u32)RS_64(temp, I40IW_QP_DBSA_HW_SQ_TAIL);
  83. sw_sq_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  84. if (sw_sq_head != hw_sq_tail) {
  85. if (sw_sq_head > qp->initial_ring.head) {
  86. if ((hw_sq_tail >= qp->initial_ring.head) &&
  87. (hw_sq_tail < sw_sq_head)) {
  88. writel(qp->qp_id, qp->wqe_alloc_reg);
  89. }
  90. } else if (sw_sq_head != qp->initial_ring.head) {
  91. if ((hw_sq_tail >= qp->initial_ring.head) ||
  92. (hw_sq_tail < sw_sq_head)) {
  93. writel(qp->qp_id, qp->wqe_alloc_reg);
  94. }
  95. }
  96. }
  97. qp->initial_ring.head = qp->sq_ring.head;
  98. }
  99. /**
  100. * i40iw_qp_ring_push_db - ring qp doorbell
  101. * @qp: hw qp ptr
  102. * @wqe_idx: wqe index
  103. */
  104. static void i40iw_qp_ring_push_db(struct i40iw_qp_uk *qp, u32 wqe_idx)
  105. {
  106. set_32bit_val(qp->push_db, 0, LS_32((wqe_idx >> 2), I40E_PFPE_WQEALLOC_WQE_DESC_INDEX) | qp->qp_id);
  107. qp->initial_ring.head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  108. }
  109. /**
  110. * i40iw_qp_get_next_send_wqe - return next wqe ptr
  111. * @qp: hw qp ptr
  112. * @wqe_idx: return wqe index
  113. * @wqe_size: size of sq wqe
  114. */
  115. u64 *i40iw_qp_get_next_send_wqe(struct i40iw_qp_uk *qp,
  116. u32 *wqe_idx,
  117. u8 wqe_size)
  118. {
  119. u64 *wqe = NULL;
  120. u64 wqe_ptr;
  121. u32 peek_head = 0;
  122. u16 offset;
  123. enum i40iw_status_code ret_code = 0;
  124. u8 nop_wqe_cnt = 0, i;
  125. u64 *wqe_0 = NULL;
  126. *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  127. if (!*wqe_idx)
  128. qp->swqe_polarity = !qp->swqe_polarity;
  129. wqe_ptr = (uintptr_t)qp->sq_base[*wqe_idx].elem;
  130. offset = (u16)(wqe_ptr) & 0x7F;
  131. if ((offset + wqe_size) > I40IW_QP_WQE_MAX_SIZE) {
  132. nop_wqe_cnt = (u8)(I40IW_QP_WQE_MAX_SIZE - offset) / I40IW_QP_WQE_MIN_SIZE;
  133. for (i = 0; i < nop_wqe_cnt; i++) {
  134. i40iw_nop_1(qp);
  135. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  136. if (ret_code)
  137. return NULL;
  138. }
  139. *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  140. if (!*wqe_idx)
  141. qp->swqe_polarity = !qp->swqe_polarity;
  142. }
  143. for (i = 0; i < wqe_size / I40IW_QP_WQE_MIN_SIZE; i++) {
  144. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  145. if (ret_code)
  146. return NULL;
  147. }
  148. wqe = qp->sq_base[*wqe_idx].elem;
  149. peek_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  150. wqe_0 = qp->sq_base[peek_head].elem;
  151. if (peek_head & 0x3)
  152. wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
  153. return wqe;
  154. }
  155. /**
  156. * i40iw_set_fragment - set fragment in wqe
  157. * @wqe: wqe for setting fragment
  158. * @offset: offset value
  159. * @sge: sge length and stag
  160. */
  161. static void i40iw_set_fragment(u64 *wqe, u32 offset, struct i40iw_sge *sge)
  162. {
  163. if (sge) {
  164. set_64bit_val(wqe, offset, LS_64(sge->tag_off, I40IWQPSQ_FRAG_TO));
  165. set_64bit_val(wqe, (offset + 8),
  166. (LS_64(sge->len, I40IWQPSQ_FRAG_LEN) |
  167. LS_64(sge->stag, I40IWQPSQ_FRAG_STAG)));
  168. }
  169. }
  170. /**
  171. * i40iw_qp_get_next_recv_wqe - get next qp's rcv wqe
  172. * @qp: hw qp ptr
  173. * @wqe_idx: return wqe index
  174. */
  175. u64 *i40iw_qp_get_next_recv_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx)
  176. {
  177. u64 *wqe = NULL;
  178. enum i40iw_status_code ret_code;
  179. if (I40IW_RING_FULL_ERR(qp->rq_ring))
  180. return NULL;
  181. I40IW_ATOMIC_RING_MOVE_HEAD(qp->rq_ring, *wqe_idx, ret_code);
  182. if (ret_code)
  183. return NULL;
  184. if (!*wqe_idx)
  185. qp->rwqe_polarity = !qp->rwqe_polarity;
  186. /* rq_wqe_size_multiplier is no of qwords in one rq wqe */
  187. wqe = qp->rq_base[*wqe_idx * (qp->rq_wqe_size_multiplier >> 2)].elem;
  188. return wqe;
  189. }
  190. /**
  191. * i40iw_rdma_write - rdma write operation
  192. * @qp: hw qp ptr
  193. * @info: post sq information
  194. * @post_sq: flag to post sq
  195. */
  196. static enum i40iw_status_code i40iw_rdma_write(struct i40iw_qp_uk *qp,
  197. struct i40iw_post_sq_info *info,
  198. bool post_sq)
  199. {
  200. u64 header;
  201. u64 *wqe;
  202. struct i40iw_rdma_write *op_info;
  203. u32 i, wqe_idx;
  204. u32 total_size = 0, byte_off;
  205. enum i40iw_status_code ret_code;
  206. bool read_fence = false;
  207. u8 wqe_size;
  208. op_info = &info->op.rdma_write;
  209. if (op_info->num_lo_sges > qp->max_sq_frag_cnt)
  210. return I40IW_ERR_INVALID_FRAG_COUNT;
  211. for (i = 0; i < op_info->num_lo_sges; i++)
  212. total_size += op_info->lo_sg_list[i].len;
  213. if (total_size > I40IW_MAX_OUTBOUND_MESSAGE_SIZE)
  214. return I40IW_ERR_QP_INVALID_MSG_SIZE;
  215. read_fence |= info->read_fence;
  216. ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_lo_sges, &wqe_size);
  217. if (ret_code)
  218. return ret_code;
  219. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
  220. if (!wqe)
  221. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  222. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  223. qp->sq_wrtrk_array[wqe_idx].wr_len = total_size;
  224. set_64bit_val(wqe, 16,
  225. LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  226. if (!op_info->rem_addr.stag)
  227. return I40IW_ERR_BAD_STAG;
  228. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  229. LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  230. LS_64((op_info->num_lo_sges > 1 ? (op_info->num_lo_sges - 1) : 0), I40IWQPSQ_ADDFRAGCNT) |
  231. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  232. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  233. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  234. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  235. i40iw_set_fragment(wqe, 0, op_info->lo_sg_list);
  236. for (i = 1; i < op_info->num_lo_sges; i++) {
  237. byte_off = 32 + (i - 1) * 16;
  238. i40iw_set_fragment(wqe, byte_off, &op_info->lo_sg_list[i]);
  239. }
  240. wmb(); /* make sure WQE is populated before valid bit is set */
  241. set_64bit_val(wqe, 24, header);
  242. if (post_sq)
  243. i40iw_qp_post_wr(qp);
  244. return 0;
  245. }
  246. /**
  247. * i40iw_rdma_read - rdma read command
  248. * @qp: hw qp ptr
  249. * @info: post sq information
  250. * @inv_stag: flag for inv_stag
  251. * @post_sq: flag to post sq
  252. */
  253. static enum i40iw_status_code i40iw_rdma_read(struct i40iw_qp_uk *qp,
  254. struct i40iw_post_sq_info *info,
  255. bool inv_stag,
  256. bool post_sq)
  257. {
  258. u64 *wqe;
  259. struct i40iw_rdma_read *op_info;
  260. u64 header;
  261. u32 wqe_idx;
  262. enum i40iw_status_code ret_code;
  263. u8 wqe_size;
  264. bool local_fence = false;
  265. op_info = &info->op.rdma_read;
  266. ret_code = i40iw_fragcnt_to_wqesize_sq(1, &wqe_size);
  267. if (ret_code)
  268. return ret_code;
  269. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
  270. if (!wqe)
  271. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  272. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  273. qp->sq_wrtrk_array[wqe_idx].wr_len = op_info->lo_addr.len;
  274. local_fence |= info->local_fence;
  275. set_64bit_val(wqe, 16, LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  276. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  277. LS_64((inv_stag ? I40IWQP_OP_RDMA_READ_LOC_INV : I40IWQP_OP_RDMA_READ), I40IWQPSQ_OPCODE) |
  278. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  279. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  280. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  281. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  282. i40iw_set_fragment(wqe, 0, &op_info->lo_addr);
  283. wmb(); /* make sure WQE is populated before valid bit is set */
  284. set_64bit_val(wqe, 24, header);
  285. if (post_sq)
  286. i40iw_qp_post_wr(qp);
  287. return 0;
  288. }
  289. /**
  290. * i40iw_send - rdma send command
  291. * @qp: hw qp ptr
  292. * @info: post sq information
  293. * @stag_to_inv: stag_to_inv value
  294. * @post_sq: flag to post sq
  295. */
  296. static enum i40iw_status_code i40iw_send(struct i40iw_qp_uk *qp,
  297. struct i40iw_post_sq_info *info,
  298. u32 stag_to_inv,
  299. bool post_sq)
  300. {
  301. u64 *wqe;
  302. struct i40iw_post_send *op_info;
  303. u64 header;
  304. u32 i, wqe_idx, total_size = 0, byte_off;
  305. enum i40iw_status_code ret_code;
  306. bool read_fence = false;
  307. u8 wqe_size;
  308. op_info = &info->op.send;
  309. if (qp->max_sq_frag_cnt < op_info->num_sges)
  310. return I40IW_ERR_INVALID_FRAG_COUNT;
  311. for (i = 0; i < op_info->num_sges; i++)
  312. total_size += op_info->sg_list[i].len;
  313. ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_sges, &wqe_size);
  314. if (ret_code)
  315. return ret_code;
  316. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
  317. if (!wqe)
  318. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  319. read_fence |= info->read_fence;
  320. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  321. qp->sq_wrtrk_array[wqe_idx].wr_len = total_size;
  322. set_64bit_val(wqe, 16, 0);
  323. header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
  324. LS_64(info->op_type, I40IWQPSQ_OPCODE) |
  325. LS_64((op_info->num_sges > 1 ? (op_info->num_sges - 1) : 0),
  326. I40IWQPSQ_ADDFRAGCNT) |
  327. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  328. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  329. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  330. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  331. i40iw_set_fragment(wqe, 0, op_info->sg_list);
  332. for (i = 1; i < op_info->num_sges; i++) {
  333. byte_off = 32 + (i - 1) * 16;
  334. i40iw_set_fragment(wqe, byte_off, &op_info->sg_list[i]);
  335. }
  336. wmb(); /* make sure WQE is populated before valid bit is set */
  337. set_64bit_val(wqe, 24, header);
  338. if (post_sq)
  339. i40iw_qp_post_wr(qp);
  340. return 0;
  341. }
  342. /**
  343. * i40iw_inline_rdma_write - inline rdma write operation
  344. * @qp: hw qp ptr
  345. * @info: post sq information
  346. * @post_sq: flag to post sq
  347. */
  348. static enum i40iw_status_code i40iw_inline_rdma_write(struct i40iw_qp_uk *qp,
  349. struct i40iw_post_sq_info *info,
  350. bool post_sq)
  351. {
  352. u64 *wqe;
  353. u8 *dest, *src;
  354. struct i40iw_inline_rdma_write *op_info;
  355. u64 *push;
  356. u64 header = 0;
  357. u32 i, wqe_idx;
  358. enum i40iw_status_code ret_code;
  359. bool read_fence = false;
  360. u8 wqe_size;
  361. op_info = &info->op.inline_rdma_write;
  362. if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
  363. return I40IW_ERR_INVALID_IMM_DATA_SIZE;
  364. ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
  365. if (ret_code)
  366. return ret_code;
  367. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
  368. if (!wqe)
  369. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  370. read_fence |= info->read_fence;
  371. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  372. qp->sq_wrtrk_array[wqe_idx].wr_len = op_info->len;
  373. set_64bit_val(wqe, 16,
  374. LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  375. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  376. LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  377. LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
  378. LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
  379. LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
  380. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  381. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  382. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  383. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  384. dest = (u8 *)wqe;
  385. src = (u8 *)(op_info->data);
  386. if (op_info->len <= 16) {
  387. for (i = 0; i < op_info->len; i++, src++, dest++)
  388. *dest = *src;
  389. } else {
  390. for (i = 0; i < 16; i++, src++, dest++)
  391. *dest = *src;
  392. dest = (u8 *)wqe + 32;
  393. for (; i < op_info->len; i++, src++, dest++)
  394. *dest = *src;
  395. }
  396. wmb(); /* make sure WQE is populated before valid bit is set */
  397. set_64bit_val(wqe, 24, header);
  398. if (qp->push_db) {
  399. push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
  400. memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
  401. i40iw_qp_ring_push_db(qp, wqe_idx);
  402. } else {
  403. if (post_sq)
  404. i40iw_qp_post_wr(qp);
  405. }
  406. return 0;
  407. }
  408. /**
  409. * i40iw_inline_send - inline send operation
  410. * @qp: hw qp ptr
  411. * @info: post sq information
  412. * @stag_to_inv: remote stag
  413. * @post_sq: flag to post sq
  414. */
  415. static enum i40iw_status_code i40iw_inline_send(struct i40iw_qp_uk *qp,
  416. struct i40iw_post_sq_info *info,
  417. u32 stag_to_inv,
  418. bool post_sq)
  419. {
  420. u64 *wqe;
  421. u8 *dest, *src;
  422. struct i40iw_post_inline_send *op_info;
  423. u64 header;
  424. u32 wqe_idx, i;
  425. enum i40iw_status_code ret_code;
  426. bool read_fence = false;
  427. u8 wqe_size;
  428. u64 *push;
  429. op_info = &info->op.inline_send;
  430. if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
  431. return I40IW_ERR_INVALID_IMM_DATA_SIZE;
  432. ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
  433. if (ret_code)
  434. return ret_code;
  435. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size);
  436. if (!wqe)
  437. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  438. read_fence |= info->read_fence;
  439. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  440. qp->sq_wrtrk_array[wqe_idx].wr_len = op_info->len;
  441. header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
  442. LS_64(info->op_type, I40IWQPSQ_OPCODE) |
  443. LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
  444. LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
  445. LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
  446. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  447. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  448. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  449. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  450. dest = (u8 *)wqe;
  451. src = (u8 *)(op_info->data);
  452. if (op_info->len <= 16) {
  453. for (i = 0; i < op_info->len; i++, src++, dest++)
  454. *dest = *src;
  455. } else {
  456. for (i = 0; i < 16; i++, src++, dest++)
  457. *dest = *src;
  458. dest = (u8 *)wqe + 32;
  459. for (; i < op_info->len; i++, src++, dest++)
  460. *dest = *src;
  461. }
  462. wmb(); /* make sure WQE is populated before valid bit is set */
  463. set_64bit_val(wqe, 24, header);
  464. if (qp->push_db) {
  465. push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
  466. memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
  467. i40iw_qp_ring_push_db(qp, wqe_idx);
  468. } else {
  469. if (post_sq)
  470. i40iw_qp_post_wr(qp);
  471. }
  472. return 0;
  473. }
  474. /**
  475. * i40iw_stag_local_invalidate - stag invalidate operation
  476. * @qp: hw qp ptr
  477. * @info: post sq information
  478. * @post_sq: flag to post sq
  479. */
  480. static enum i40iw_status_code i40iw_stag_local_invalidate(struct i40iw_qp_uk *qp,
  481. struct i40iw_post_sq_info *info,
  482. bool post_sq)
  483. {
  484. u64 *wqe;
  485. struct i40iw_inv_local_stag *op_info;
  486. u64 header;
  487. u32 wqe_idx;
  488. bool local_fence = false;
  489. op_info = &info->op.inv_local_stag;
  490. local_fence = info->local_fence;
  491. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE);
  492. if (!wqe)
  493. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  494. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  495. qp->sq_wrtrk_array[wqe_idx].wr_len = 0;
  496. set_64bit_val(wqe, 0, 0);
  497. set_64bit_val(wqe, 8,
  498. LS_64(op_info->target_stag, I40IWQPSQ_LOCSTAG));
  499. set_64bit_val(wqe, 16, 0);
  500. header = LS_64(I40IW_OP_TYPE_INV_STAG, I40IWQPSQ_OPCODE) |
  501. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  502. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  503. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  504. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  505. wmb(); /* make sure WQE is populated before valid bit is set */
  506. set_64bit_val(wqe, 24, header);
  507. if (post_sq)
  508. i40iw_qp_post_wr(qp);
  509. return 0;
  510. }
  511. /**
  512. * i40iw_mw_bind - Memory Window bind operation
  513. * @qp: hw qp ptr
  514. * @info: post sq information
  515. * @post_sq: flag to post sq
  516. */
  517. static enum i40iw_status_code i40iw_mw_bind(struct i40iw_qp_uk *qp,
  518. struct i40iw_post_sq_info *info,
  519. bool post_sq)
  520. {
  521. u64 *wqe;
  522. struct i40iw_bind_window *op_info;
  523. u64 header;
  524. u32 wqe_idx;
  525. bool local_fence = false;
  526. op_info = &info->op.bind_window;
  527. local_fence |= info->local_fence;
  528. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE);
  529. if (!wqe)
  530. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  531. qp->sq_wrtrk_array[wqe_idx].wrid = info->wr_id;
  532. qp->sq_wrtrk_array[wqe_idx].wr_len = 0;
  533. set_64bit_val(wqe, 0, (uintptr_t)op_info->va);
  534. set_64bit_val(wqe, 8,
  535. LS_64(op_info->mr_stag, I40IWQPSQ_PARENTMRSTAG) |
  536. LS_64(op_info->mw_stag, I40IWQPSQ_MWSTAG));
  537. set_64bit_val(wqe, 16, op_info->bind_length);
  538. header = LS_64(I40IW_OP_TYPE_BIND_MW, I40IWQPSQ_OPCODE) |
  539. LS_64(((op_info->enable_reads << 2) |
  540. (op_info->enable_writes << 3)),
  541. I40IWQPSQ_STAGRIGHTS) |
  542. LS_64((op_info->addressing_type == I40IW_ADDR_TYPE_VA_BASED ? 1 : 0),
  543. I40IWQPSQ_VABASEDTO) |
  544. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  545. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  546. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  547. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  548. wmb(); /* make sure WQE is populated before valid bit is set */
  549. set_64bit_val(wqe, 24, header);
  550. if (post_sq)
  551. i40iw_qp_post_wr(qp);
  552. return 0;
  553. }
  554. /**
  555. * i40iw_post_receive - post receive wqe
  556. * @qp: hw qp ptr
  557. * @info: post rq information
  558. */
  559. static enum i40iw_status_code i40iw_post_receive(struct i40iw_qp_uk *qp,
  560. struct i40iw_post_rq_info *info)
  561. {
  562. u64 *wqe;
  563. u64 header;
  564. u32 total_size = 0, wqe_idx, i, byte_off;
  565. if (qp->max_rq_frag_cnt < info->num_sges)
  566. return I40IW_ERR_INVALID_FRAG_COUNT;
  567. for (i = 0; i < info->num_sges; i++)
  568. total_size += info->sg_list[i].len;
  569. wqe = i40iw_qp_get_next_recv_wqe(qp, &wqe_idx);
  570. if (!wqe)
  571. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  572. qp->rq_wrid_array[wqe_idx] = info->wr_id;
  573. set_64bit_val(wqe, 16, 0);
  574. header = LS_64((info->num_sges > 1 ? (info->num_sges - 1) : 0),
  575. I40IWQPSQ_ADDFRAGCNT) |
  576. LS_64(qp->rwqe_polarity, I40IWQPSQ_VALID);
  577. i40iw_set_fragment(wqe, 0, info->sg_list);
  578. for (i = 1; i < info->num_sges; i++) {
  579. byte_off = 32 + (i - 1) * 16;
  580. i40iw_set_fragment(wqe, byte_off, &info->sg_list[i]);
  581. }
  582. wmb(); /* make sure WQE is populated before valid bit is set */
  583. set_64bit_val(wqe, 24, header);
  584. return 0;
  585. }
  586. /**
  587. * i40iw_cq_request_notification - cq notification request (door bell)
  588. * @cq: hw cq
  589. * @cq_notify: notification type
  590. */
  591. static void i40iw_cq_request_notification(struct i40iw_cq_uk *cq,
  592. enum i40iw_completion_notify cq_notify)
  593. {
  594. u64 temp_val;
  595. u16 sw_cq_sel;
  596. u8 arm_next_se = 0;
  597. u8 arm_next = 0;
  598. u8 arm_seq_num;
  599. get_64bit_val(cq->shadow_area, 32, &temp_val);
  600. arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
  601. arm_seq_num++;
  602. sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
  603. arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
  604. arm_next_se |= 1;
  605. if (cq_notify == IW_CQ_COMPL_EVENT)
  606. arm_next = 1;
  607. temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
  608. LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
  609. LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
  610. LS_64(arm_next, I40IW_CQ_DBSA_ARM_NEXT);
  611. set_64bit_val(cq->shadow_area, 32, temp_val);
  612. wmb(); /* make sure WQE is populated before valid bit is set */
  613. writel(cq->cq_id, cq->cqe_alloc_reg);
  614. }
  615. /**
  616. * i40iw_cq_post_entries - update tail in shadow memory
  617. * @cq: hw cq
  618. * @count: # of entries processed
  619. */
  620. static enum i40iw_status_code i40iw_cq_post_entries(struct i40iw_cq_uk *cq,
  621. u8 count)
  622. {
  623. I40IW_RING_MOVE_TAIL_BY_COUNT(cq->cq_ring, count);
  624. set_64bit_val(cq->shadow_area, 0,
  625. I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
  626. return 0;
  627. }
  628. /**
  629. * i40iw_cq_poll_completion - get cq completion info
  630. * @cq: hw cq
  631. * @info: cq poll information returned
  632. * @post_cq: update cq tail
  633. */
  634. static enum i40iw_status_code i40iw_cq_poll_completion(struct i40iw_cq_uk *cq,
  635. struct i40iw_cq_poll_info *info,
  636. bool post_cq)
  637. {
  638. u64 comp_ctx, qword0, qword2, qword3, wqe_qword;
  639. u64 *cqe, *sw_wqe;
  640. struct i40iw_qp_uk *qp;
  641. struct i40iw_ring *pring = NULL;
  642. u32 wqe_idx, q_type, array_idx = 0;
  643. enum i40iw_status_code ret_code = 0;
  644. enum i40iw_status_code ret_code2 = 0;
  645. bool move_cq_head = true;
  646. u8 polarity;
  647. u8 addl_frag_cnt, addl_wqes = 0;
  648. if (cq->avoid_mem_cflct)
  649. cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(cq);
  650. else
  651. cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(cq);
  652. get_64bit_val(cqe, 24, &qword3);
  653. polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
  654. if (polarity != cq->polarity)
  655. return I40IW_ERR_QUEUE_EMPTY;
  656. q_type = (u8)RS_64(qword3, I40IW_CQ_SQ);
  657. info->error = (bool)RS_64(qword3, I40IW_CQ_ERROR);
  658. info->push_dropped = (bool)RS_64(qword3, I40IWCQ_PSHDROP);
  659. if (info->error) {
  660. info->comp_status = I40IW_COMPL_STATUS_FLUSHED;
  661. info->major_err = (bool)RS_64(qword3, I40IW_CQ_MAJERR);
  662. info->minor_err = (bool)RS_64(qword3, I40IW_CQ_MINERR);
  663. } else {
  664. info->comp_status = I40IW_COMPL_STATUS_SUCCESS;
  665. }
  666. get_64bit_val(cqe, 0, &qword0);
  667. get_64bit_val(cqe, 16, &qword2);
  668. info->tcp_seq_num = (u8)RS_64(qword0, I40IWCQ_TCPSEQNUM);
  669. info->qp_id = (u32)RS_64(qword2, I40IWCQ_QPID);
  670. get_64bit_val(cqe, 8, &comp_ctx);
  671. info->solicited_event = (bool)RS_64(qword3, I40IWCQ_SOEVENT);
  672. info->is_srq = (bool)RS_64(qword3, I40IWCQ_SRQ);
  673. qp = (struct i40iw_qp_uk *)(unsigned long)comp_ctx;
  674. wqe_idx = (u32)RS_64(qword3, I40IW_CQ_WQEIDX);
  675. info->qp_handle = (i40iw_qp_handle)(unsigned long)qp;
  676. if (q_type == I40IW_CQE_QTYPE_RQ) {
  677. array_idx = (wqe_idx * 4) / qp->rq_wqe_size_multiplier;
  678. if (info->comp_status == I40IW_COMPL_STATUS_FLUSHED) {
  679. info->wr_id = qp->rq_wrid_array[qp->rq_ring.tail];
  680. array_idx = qp->rq_ring.tail;
  681. } else {
  682. info->wr_id = qp->rq_wrid_array[array_idx];
  683. }
  684. info->op_type = I40IW_OP_TYPE_REC;
  685. if (qword3 & I40IWCQ_STAG_MASK) {
  686. info->stag_invalid_set = true;
  687. info->inv_stag = (u32)RS_64(qword2, I40IWCQ_INVSTAG);
  688. } else {
  689. info->stag_invalid_set = false;
  690. }
  691. info->bytes_xfered = (u32)RS_64(qword0, I40IWCQ_PAYLDLEN);
  692. I40IW_RING_SET_TAIL(qp->rq_ring, array_idx + 1);
  693. pring = &qp->rq_ring;
  694. } else {
  695. if (info->comp_status != I40IW_COMPL_STATUS_FLUSHED) {
  696. info->wr_id = qp->sq_wrtrk_array[wqe_idx].wrid;
  697. info->bytes_xfered = qp->sq_wrtrk_array[wqe_idx].wr_len;
  698. info->op_type = (u8)RS_64(qword3, I40IWCQ_OP);
  699. sw_wqe = qp->sq_base[wqe_idx].elem;
  700. get_64bit_val(sw_wqe, 24, &wqe_qword);
  701. addl_frag_cnt =
  702. (u8)RS_64(wqe_qword, I40IWQPSQ_ADDFRAGCNT);
  703. i40iw_fragcnt_to_wqesize_sq(addl_frag_cnt + 1, &addl_wqes);
  704. addl_wqes = (addl_wqes / I40IW_QP_WQE_MIN_SIZE);
  705. I40IW_RING_SET_TAIL(qp->sq_ring, (wqe_idx + addl_wqes));
  706. } else {
  707. do {
  708. u8 op_type;
  709. u32 tail;
  710. tail = qp->sq_ring.tail;
  711. sw_wqe = qp->sq_base[tail].elem;
  712. get_64bit_val(sw_wqe, 24, &wqe_qword);
  713. op_type = (u8)RS_64(wqe_qword, I40IWQPSQ_OPCODE);
  714. info->op_type = op_type;
  715. addl_frag_cnt = (u8)RS_64(wqe_qword, I40IWQPSQ_ADDFRAGCNT);
  716. i40iw_fragcnt_to_wqesize_sq(addl_frag_cnt + 1, &addl_wqes);
  717. addl_wqes = (addl_wqes / I40IW_QP_WQE_MIN_SIZE);
  718. I40IW_RING_SET_TAIL(qp->sq_ring, (tail + addl_wqes));
  719. if (op_type != I40IWQP_OP_NOP) {
  720. info->wr_id = qp->sq_wrtrk_array[tail].wrid;
  721. info->bytes_xfered = qp->sq_wrtrk_array[tail].wr_len;
  722. break;
  723. }
  724. } while (1);
  725. }
  726. pring = &qp->sq_ring;
  727. }
  728. ret_code = 0;
  729. if (!ret_code &&
  730. (info->comp_status == I40IW_COMPL_STATUS_FLUSHED))
  731. if (pring && (I40IW_RING_MORE_WORK(*pring)))
  732. move_cq_head = false;
  733. if (move_cq_head) {
  734. I40IW_RING_MOVE_HEAD(cq->cq_ring, ret_code2);
  735. if (ret_code2 && !ret_code)
  736. ret_code = ret_code2;
  737. if (I40IW_RING_GETCURRENT_HEAD(cq->cq_ring) == 0)
  738. cq->polarity ^= 1;
  739. if (post_cq) {
  740. I40IW_RING_MOVE_TAIL(cq->cq_ring);
  741. set_64bit_val(cq->shadow_area, 0,
  742. I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
  743. }
  744. } else {
  745. if (info->is_srq)
  746. return ret_code;
  747. qword3 &= ~I40IW_CQ_WQEIDX_MASK;
  748. qword3 |= LS_64(pring->tail, I40IW_CQ_WQEIDX);
  749. set_64bit_val(cqe, 24, qword3);
  750. }
  751. return ret_code;
  752. }
  753. /**
  754. * i40iw_get_wqe_shift - get shift count for maximum wqe size
  755. * @wqdepth: depth of wq required.
  756. * @sge: Maximum Scatter Gather Elements wqe
  757. * @shift: Returns the shift needed based on sge
  758. *
  759. * Shift can be used to left shift the wqe size based on sge.
  760. * If sge, == 1, shift =0 (wqe_size of 32 bytes), for sge=2 and 3, shift =1
  761. * (64 bytes wqes) and 2 otherwise (128 bytes wqe).
  762. */
  763. enum i40iw_status_code i40iw_get_wqe_shift(u32 wqdepth, u8 sge, u8 *shift)
  764. {
  765. u32 size;
  766. *shift = 0;
  767. if (sge > 1)
  768. *shift = (sge < 4) ? 1 : 2;
  769. /* check if wqdepth is multiple of 2 or not */
  770. if ((wqdepth < I40IWQP_SW_MIN_WQSIZE) || (wqdepth & (wqdepth - 1)))
  771. return I40IW_ERR_INVALID_SIZE;
  772. size = wqdepth << *shift; /* multiple of 32 bytes count */
  773. if (size > I40IWQP_SW_MAX_WQSIZE)
  774. return I40IW_ERR_INVALID_SIZE;
  775. return 0;
  776. }
  777. static struct i40iw_qp_uk_ops iw_qp_uk_ops = {
  778. i40iw_qp_post_wr,
  779. i40iw_qp_ring_push_db,
  780. i40iw_rdma_write,
  781. i40iw_rdma_read,
  782. i40iw_send,
  783. i40iw_inline_rdma_write,
  784. i40iw_inline_send,
  785. i40iw_stag_local_invalidate,
  786. i40iw_mw_bind,
  787. i40iw_post_receive,
  788. i40iw_nop
  789. };
  790. static struct i40iw_cq_ops iw_cq_ops = {
  791. i40iw_cq_request_notification,
  792. i40iw_cq_poll_completion,
  793. i40iw_cq_post_entries,
  794. i40iw_clean_cq
  795. };
  796. static struct i40iw_device_uk_ops iw_device_uk_ops = {
  797. i40iw_cq_uk_init,
  798. i40iw_qp_uk_init,
  799. };
  800. /**
  801. * i40iw_qp_uk_init - initialize shared qp
  802. * @qp: hw qp (user and kernel)
  803. * @info: qp initialization info
  804. *
  805. * initializes the vars used in both user and kernel mode.
  806. * size of the wqe depends on numbers of max. fragements
  807. * allowed. Then size of wqe * the number of wqes should be the
  808. * amount of memory allocated for sq and rq. If srq is used,
  809. * then rq_base will point to one rq wqe only (not the whole
  810. * array of wqes)
  811. */
  812. enum i40iw_status_code i40iw_qp_uk_init(struct i40iw_qp_uk *qp,
  813. struct i40iw_qp_uk_init_info *info)
  814. {
  815. enum i40iw_status_code ret_code = 0;
  816. u32 sq_ring_size;
  817. u8 sqshift, rqshift;
  818. if (info->max_sq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
  819. return I40IW_ERR_INVALID_FRAG_COUNT;
  820. if (info->max_rq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
  821. return I40IW_ERR_INVALID_FRAG_COUNT;
  822. ret_code = i40iw_get_wqe_shift(info->sq_size, info->max_sq_frag_cnt, &sqshift);
  823. if (ret_code)
  824. return ret_code;
  825. ret_code = i40iw_get_wqe_shift(info->rq_size, info->max_rq_frag_cnt, &rqshift);
  826. if (ret_code)
  827. return ret_code;
  828. qp->sq_base = info->sq;
  829. qp->rq_base = info->rq;
  830. qp->shadow_area = info->shadow_area;
  831. qp->sq_wrtrk_array = info->sq_wrtrk_array;
  832. qp->rq_wrid_array = info->rq_wrid_array;
  833. qp->wqe_alloc_reg = info->wqe_alloc_reg;
  834. qp->qp_id = info->qp_id;
  835. qp->sq_size = info->sq_size;
  836. qp->push_db = info->push_db;
  837. qp->push_wqe = info->push_wqe;
  838. qp->max_sq_frag_cnt = info->max_sq_frag_cnt;
  839. sq_ring_size = qp->sq_size << sqshift;
  840. I40IW_RING_INIT(qp->sq_ring, sq_ring_size);
  841. I40IW_RING_INIT(qp->initial_ring, sq_ring_size);
  842. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  843. I40IW_RING_MOVE_TAIL(qp->sq_ring);
  844. I40IW_RING_MOVE_HEAD(qp->initial_ring, ret_code);
  845. qp->swqe_polarity = 1;
  846. qp->swqe_polarity_deferred = 1;
  847. qp->rwqe_polarity = 0;
  848. if (!qp->use_srq) {
  849. qp->rq_size = info->rq_size;
  850. qp->max_rq_frag_cnt = info->max_rq_frag_cnt;
  851. qp->rq_wqe_size = rqshift;
  852. I40IW_RING_INIT(qp->rq_ring, qp->rq_size);
  853. qp->rq_wqe_size_multiplier = 4 << rqshift;
  854. }
  855. qp->ops = iw_qp_uk_ops;
  856. return ret_code;
  857. }
  858. /**
  859. * i40iw_cq_uk_init - initialize shared cq (user and kernel)
  860. * @cq: hw cq
  861. * @info: hw cq initialization info
  862. */
  863. enum i40iw_status_code i40iw_cq_uk_init(struct i40iw_cq_uk *cq,
  864. struct i40iw_cq_uk_init_info *info)
  865. {
  866. if ((info->cq_size < I40IW_MIN_CQ_SIZE) ||
  867. (info->cq_size > I40IW_MAX_CQ_SIZE))
  868. return I40IW_ERR_INVALID_SIZE;
  869. cq->cq_base = (struct i40iw_cqe *)info->cq_base;
  870. cq->cq_id = info->cq_id;
  871. cq->cq_size = info->cq_size;
  872. cq->cqe_alloc_reg = info->cqe_alloc_reg;
  873. cq->shadow_area = info->shadow_area;
  874. cq->avoid_mem_cflct = info->avoid_mem_cflct;
  875. I40IW_RING_INIT(cq->cq_ring, cq->cq_size);
  876. cq->polarity = 1;
  877. cq->ops = iw_cq_ops;
  878. return 0;
  879. }
  880. /**
  881. * i40iw_device_init_uk - setup routines for iwarp shared device
  882. * @dev: iwarp shared (user and kernel)
  883. */
  884. void i40iw_device_init_uk(struct i40iw_dev_uk *dev)
  885. {
  886. dev->ops_uk = iw_device_uk_ops;
  887. }
  888. /**
  889. * i40iw_clean_cq - clean cq entries
  890. * @ queue completion context
  891. * @cq: cq to clean
  892. */
  893. void i40iw_clean_cq(void *queue, struct i40iw_cq_uk *cq)
  894. {
  895. u64 *cqe;
  896. u64 qword3, comp_ctx;
  897. u32 cq_head;
  898. u8 polarity, temp;
  899. cq_head = cq->cq_ring.head;
  900. temp = cq->polarity;
  901. do {
  902. if (cq->avoid_mem_cflct)
  903. cqe = (u64 *)&(((struct i40iw_extended_cqe *)cq->cq_base)[cq_head]);
  904. else
  905. cqe = (u64 *)&cq->cq_base[cq_head];
  906. get_64bit_val(cqe, 24, &qword3);
  907. polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
  908. if (polarity != temp)
  909. break;
  910. get_64bit_val(cqe, 8, &comp_ctx);
  911. if ((void *)(unsigned long)comp_ctx == queue)
  912. set_64bit_val(cqe, 8, 0);
  913. cq_head = (cq_head + 1) % cq->cq_ring.size;
  914. if (!cq_head)
  915. temp ^= 1;
  916. } while (true);
  917. }
  918. /**
  919. * i40iw_nop - send a nop
  920. * @qp: hw qp ptr
  921. * @wr_id: work request id
  922. * @signaled: flag if signaled for completion
  923. * @post_sq: flag to post sq
  924. */
  925. enum i40iw_status_code i40iw_nop(struct i40iw_qp_uk *qp,
  926. u64 wr_id,
  927. bool signaled,
  928. bool post_sq)
  929. {
  930. u64 header, *wqe;
  931. u32 wqe_idx;
  932. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE);
  933. if (!wqe)
  934. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  935. qp->sq_wrtrk_array[wqe_idx].wrid = wr_id;
  936. qp->sq_wrtrk_array[wqe_idx].wr_len = 0;
  937. set_64bit_val(wqe, 0, 0);
  938. set_64bit_val(wqe, 8, 0);
  939. set_64bit_val(wqe, 16, 0);
  940. header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
  941. LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
  942. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  943. wmb(); /* make sure WQE is populated before valid bit is set */
  944. set_64bit_val(wqe, 24, header);
  945. if (post_sq)
  946. i40iw_qp_post_wr(qp);
  947. return 0;
  948. }
  949. /**
  950. * i40iw_fragcnt_to_wqesize_sq - calculate wqe size based on fragment count for SQ
  951. * @frag_cnt: number of fragments
  952. * @wqe_size: size of sq wqe returned
  953. */
  954. enum i40iw_status_code i40iw_fragcnt_to_wqesize_sq(u8 frag_cnt, u8 *wqe_size)
  955. {
  956. switch (frag_cnt) {
  957. case 0:
  958. case 1:
  959. *wqe_size = I40IW_QP_WQE_MIN_SIZE;
  960. break;
  961. case 2:
  962. case 3:
  963. *wqe_size = 64;
  964. break;
  965. case 4:
  966. case 5:
  967. *wqe_size = 96;
  968. break;
  969. case 6:
  970. case 7:
  971. *wqe_size = 128;
  972. break;
  973. default:
  974. return I40IW_ERR_INVALID_FRAG_COUNT;
  975. }
  976. return 0;
  977. }
  978. /**
  979. * i40iw_fragcnt_to_wqesize_rq - calculate wqe size based on fragment count for RQ
  980. * @frag_cnt: number of fragments
  981. * @wqe_size: size of rq wqe returned
  982. */
  983. enum i40iw_status_code i40iw_fragcnt_to_wqesize_rq(u8 frag_cnt, u8 *wqe_size)
  984. {
  985. switch (frag_cnt) {
  986. case 0:
  987. case 1:
  988. *wqe_size = 32;
  989. break;
  990. case 2:
  991. case 3:
  992. *wqe_size = 64;
  993. break;
  994. case 4:
  995. case 5:
  996. case 6:
  997. case 7:
  998. *wqe_size = 128;
  999. break;
  1000. default:
  1001. return I40IW_ERR_INVALID_FRAG_COUNT;
  1002. }
  1003. return 0;
  1004. }
  1005. /**
  1006. * i40iw_inline_data_size_to_wqesize - based on inline data, wqe size
  1007. * @data_size: data size for inline
  1008. * @wqe_size: size of sq wqe returned
  1009. */
  1010. enum i40iw_status_code i40iw_inline_data_size_to_wqesize(u32 data_size,
  1011. u8 *wqe_size)
  1012. {
  1013. if (data_size > I40IW_MAX_INLINE_DATA_SIZE)
  1014. return I40IW_ERR_INVALID_IMM_DATA_SIZE;
  1015. if (data_size <= 16)
  1016. *wqe_size = I40IW_QP_WQE_MIN_SIZE;
  1017. else if (data_size <= 48)
  1018. *wqe_size = 64;
  1019. else if (data_size <= 80)
  1020. *wqe_size = 96;
  1021. else
  1022. *wqe_size = 128;
  1023. return 0;
  1024. }