i40iw_uk.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  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. qp->sq_wrtrk_array[wqe_idx].wqe_size = I40IW_QP_WQE_MIN_SIZE;
  55. peek_head = (qp->sq_ring.head + 1) % qp->sq_ring.size;
  56. wqe_0 = qp->sq_base[peek_head].elem;
  57. if (peek_head)
  58. wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
  59. else
  60. wqe_0[3] = LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  61. set_64bit_val(wqe, 0, 0);
  62. set_64bit_val(wqe, 8, 0);
  63. set_64bit_val(wqe, 16, 0);
  64. header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
  65. LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
  66. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID) | nop_signature++;
  67. wmb(); /* Memory barrier to ensure data is written before valid bit is set */
  68. set_64bit_val(wqe, 24, header);
  69. return 0;
  70. }
  71. /**
  72. * i40iw_qp_post_wr - post wr to hrdware
  73. * @qp: hw qp ptr
  74. */
  75. void i40iw_qp_post_wr(struct i40iw_qp_uk *qp)
  76. {
  77. u64 temp;
  78. u32 hw_sq_tail;
  79. u32 sw_sq_head;
  80. mb(); /* valid bit is written and loads completed before reading shadow */
  81. /* read the doorbell shadow area */
  82. get_64bit_val(qp->shadow_area, 0, &temp);
  83. hw_sq_tail = (u32)RS_64(temp, I40IW_QP_DBSA_HW_SQ_TAIL);
  84. sw_sq_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  85. if (sw_sq_head != hw_sq_tail) {
  86. if (sw_sq_head > qp->initial_ring.head) {
  87. if ((hw_sq_tail >= qp->initial_ring.head) &&
  88. (hw_sq_tail < sw_sq_head)) {
  89. writel(qp->qp_id, qp->wqe_alloc_reg);
  90. }
  91. } else if (sw_sq_head != qp->initial_ring.head) {
  92. if ((hw_sq_tail >= qp->initial_ring.head) ||
  93. (hw_sq_tail < sw_sq_head)) {
  94. writel(qp->qp_id, qp->wqe_alloc_reg);
  95. }
  96. }
  97. }
  98. qp->initial_ring.head = qp->sq_ring.head;
  99. }
  100. /**
  101. * i40iw_qp_ring_push_db - ring qp doorbell
  102. * @qp: hw qp ptr
  103. * @wqe_idx: wqe index
  104. */
  105. static void i40iw_qp_ring_push_db(struct i40iw_qp_uk *qp, u32 wqe_idx)
  106. {
  107. set_32bit_val(qp->push_db, 0, LS_32((wqe_idx >> 2), I40E_PFPE_WQEALLOC_WQE_DESC_INDEX) | qp->qp_id);
  108. qp->initial_ring.head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  109. }
  110. /**
  111. * i40iw_qp_get_next_send_wqe - return next wqe ptr
  112. * @qp: hw qp ptr
  113. * @wqe_idx: return wqe index
  114. * @wqe_size: size of sq wqe
  115. */
  116. u64 *i40iw_qp_get_next_send_wqe(struct i40iw_qp_uk *qp,
  117. u32 *wqe_idx,
  118. u8 wqe_size,
  119. u32 total_size,
  120. u64 wr_id
  121. )
  122. {
  123. u64 *wqe = NULL;
  124. u64 wqe_ptr;
  125. u32 peek_head = 0;
  126. u16 offset;
  127. enum i40iw_status_code ret_code = 0;
  128. u8 nop_wqe_cnt = 0, i;
  129. u64 *wqe_0 = NULL;
  130. *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  131. if (!*wqe_idx)
  132. qp->swqe_polarity = !qp->swqe_polarity;
  133. wqe_ptr = (uintptr_t)qp->sq_base[*wqe_idx].elem;
  134. offset = (u16)(wqe_ptr) & 0x7F;
  135. if ((offset + wqe_size) > I40IW_QP_WQE_MAX_SIZE) {
  136. nop_wqe_cnt = (u8)(I40IW_QP_WQE_MAX_SIZE - offset) / I40IW_QP_WQE_MIN_SIZE;
  137. for (i = 0; i < nop_wqe_cnt; i++) {
  138. i40iw_nop_1(qp);
  139. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  140. if (ret_code)
  141. return NULL;
  142. }
  143. *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  144. if (!*wqe_idx)
  145. qp->swqe_polarity = !qp->swqe_polarity;
  146. }
  147. if (((*wqe_idx & 3) == 1) && (wqe_size == I40IW_WQE_SIZE_64)) {
  148. i40iw_nop_1(qp);
  149. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  150. if (ret_code)
  151. return NULL;
  152. *wqe_idx = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  153. if (!*wqe_idx)
  154. qp->swqe_polarity = !qp->swqe_polarity;
  155. }
  156. for (i = 0; i < wqe_size / I40IW_QP_WQE_MIN_SIZE; i++) {
  157. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  158. if (ret_code)
  159. return NULL;
  160. }
  161. wqe = qp->sq_base[*wqe_idx].elem;
  162. peek_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  163. wqe_0 = qp->sq_base[peek_head].elem;
  164. if (((peek_head & 3) == 1) || ((peek_head & 3) == 3)) {
  165. if (RS_64(wqe_0[3], I40IWQPSQ_VALID) != !qp->swqe_polarity)
  166. wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
  167. }
  168. qp->sq_wrtrk_array[*wqe_idx].wrid = wr_id;
  169. qp->sq_wrtrk_array[*wqe_idx].wr_len = total_size;
  170. qp->sq_wrtrk_array[*wqe_idx].wqe_size = wqe_size;
  171. return wqe;
  172. }
  173. /**
  174. * i40iw_set_fragment - set fragment in wqe
  175. * @wqe: wqe for setting fragment
  176. * @offset: offset value
  177. * @sge: sge length and stag
  178. */
  179. static void i40iw_set_fragment(u64 *wqe, u32 offset, struct i40iw_sge *sge)
  180. {
  181. if (sge) {
  182. set_64bit_val(wqe, offset, LS_64(sge->tag_off, I40IWQPSQ_FRAG_TO));
  183. set_64bit_val(wqe, (offset + 8),
  184. (LS_64(sge->len, I40IWQPSQ_FRAG_LEN) |
  185. LS_64(sge->stag, I40IWQPSQ_FRAG_STAG)));
  186. }
  187. }
  188. /**
  189. * i40iw_qp_get_next_recv_wqe - get next qp's rcv wqe
  190. * @qp: hw qp ptr
  191. * @wqe_idx: return wqe index
  192. */
  193. u64 *i40iw_qp_get_next_recv_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx)
  194. {
  195. u64 *wqe = NULL;
  196. enum i40iw_status_code ret_code;
  197. if (I40IW_RING_FULL_ERR(qp->rq_ring))
  198. return NULL;
  199. I40IW_ATOMIC_RING_MOVE_HEAD(qp->rq_ring, *wqe_idx, ret_code);
  200. if (ret_code)
  201. return NULL;
  202. if (!*wqe_idx)
  203. qp->rwqe_polarity = !qp->rwqe_polarity;
  204. /* rq_wqe_size_multiplier is no of qwords in one rq wqe */
  205. wqe = qp->rq_base[*wqe_idx * (qp->rq_wqe_size_multiplier >> 2)].elem;
  206. return wqe;
  207. }
  208. /**
  209. * i40iw_rdma_write - rdma write operation
  210. * @qp: hw qp ptr
  211. * @info: post sq information
  212. * @post_sq: flag to post sq
  213. */
  214. static enum i40iw_status_code i40iw_rdma_write(struct i40iw_qp_uk *qp,
  215. struct i40iw_post_sq_info *info,
  216. bool post_sq)
  217. {
  218. u64 header;
  219. u64 *wqe;
  220. struct i40iw_rdma_write *op_info;
  221. u32 i, wqe_idx;
  222. u32 total_size = 0, byte_off;
  223. enum i40iw_status_code ret_code;
  224. bool read_fence = false;
  225. u8 wqe_size;
  226. op_info = &info->op.rdma_write;
  227. if (op_info->num_lo_sges > qp->max_sq_frag_cnt)
  228. return I40IW_ERR_INVALID_FRAG_COUNT;
  229. for (i = 0; i < op_info->num_lo_sges; i++)
  230. total_size += op_info->lo_sg_list[i].len;
  231. if (total_size > I40IW_MAX_OUTBOUND_MESSAGE_SIZE)
  232. return I40IW_ERR_QP_INVALID_MSG_SIZE;
  233. read_fence |= info->read_fence;
  234. ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_lo_sges, &wqe_size);
  235. if (ret_code)
  236. return ret_code;
  237. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, total_size, info->wr_id);
  238. if (!wqe)
  239. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  240. set_64bit_val(wqe, 16,
  241. LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  242. if (!op_info->rem_addr.stag)
  243. return I40IW_ERR_BAD_STAG;
  244. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  245. LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  246. LS_64((op_info->num_lo_sges > 1 ? (op_info->num_lo_sges - 1) : 0), I40IWQPSQ_ADDFRAGCNT) |
  247. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  248. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  249. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  250. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  251. i40iw_set_fragment(wqe, 0, op_info->lo_sg_list);
  252. for (i = 1, byte_off = 32; i < op_info->num_lo_sges; i++) {
  253. i40iw_set_fragment(wqe, byte_off, &op_info->lo_sg_list[i]);
  254. byte_off += 16;
  255. }
  256. wmb(); /* make sure WQE is populated before valid bit is set */
  257. set_64bit_val(wqe, 24, header);
  258. if (post_sq)
  259. i40iw_qp_post_wr(qp);
  260. return 0;
  261. }
  262. /**
  263. * i40iw_rdma_read - rdma read command
  264. * @qp: hw qp ptr
  265. * @info: post sq information
  266. * @inv_stag: flag for inv_stag
  267. * @post_sq: flag to post sq
  268. */
  269. static enum i40iw_status_code i40iw_rdma_read(struct i40iw_qp_uk *qp,
  270. struct i40iw_post_sq_info *info,
  271. bool inv_stag,
  272. bool post_sq)
  273. {
  274. u64 *wqe;
  275. struct i40iw_rdma_read *op_info;
  276. u64 header;
  277. u32 wqe_idx;
  278. enum i40iw_status_code ret_code;
  279. u8 wqe_size;
  280. bool local_fence = false;
  281. op_info = &info->op.rdma_read;
  282. ret_code = i40iw_fragcnt_to_wqesize_sq(1, &wqe_size);
  283. if (ret_code)
  284. return ret_code;
  285. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, op_info->lo_addr.len, info->wr_id);
  286. if (!wqe)
  287. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  288. local_fence |= info->local_fence;
  289. set_64bit_val(wqe, 16, LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  290. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  291. LS_64((inv_stag ? I40IWQP_OP_RDMA_READ_LOC_INV : I40IWQP_OP_RDMA_READ), I40IWQPSQ_OPCODE) |
  292. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  293. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  294. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  295. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  296. i40iw_set_fragment(wqe, 0, &op_info->lo_addr);
  297. wmb(); /* make sure WQE is populated before valid bit is set */
  298. set_64bit_val(wqe, 24, header);
  299. if (post_sq)
  300. i40iw_qp_post_wr(qp);
  301. return 0;
  302. }
  303. /**
  304. * i40iw_send - rdma send command
  305. * @qp: hw qp ptr
  306. * @info: post sq information
  307. * @stag_to_inv: stag_to_inv value
  308. * @post_sq: flag to post sq
  309. */
  310. static enum i40iw_status_code i40iw_send(struct i40iw_qp_uk *qp,
  311. struct i40iw_post_sq_info *info,
  312. u32 stag_to_inv,
  313. bool post_sq)
  314. {
  315. u64 *wqe;
  316. struct i40iw_post_send *op_info;
  317. u64 header;
  318. u32 i, wqe_idx, total_size = 0, byte_off;
  319. enum i40iw_status_code ret_code;
  320. bool read_fence = false;
  321. u8 wqe_size;
  322. op_info = &info->op.send;
  323. if (qp->max_sq_frag_cnt < op_info->num_sges)
  324. return I40IW_ERR_INVALID_FRAG_COUNT;
  325. for (i = 0; i < op_info->num_sges; i++)
  326. total_size += op_info->sg_list[i].len;
  327. ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_sges, &wqe_size);
  328. if (ret_code)
  329. return ret_code;
  330. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, total_size, info->wr_id);
  331. if (!wqe)
  332. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  333. read_fence |= info->read_fence;
  334. set_64bit_val(wqe, 16, 0);
  335. header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
  336. LS_64(info->op_type, I40IWQPSQ_OPCODE) |
  337. LS_64((op_info->num_sges > 1 ? (op_info->num_sges - 1) : 0),
  338. I40IWQPSQ_ADDFRAGCNT) |
  339. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  340. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  341. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  342. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  343. i40iw_set_fragment(wqe, 0, op_info->sg_list);
  344. for (i = 1, byte_off = 32; i < op_info->num_sges; i++) {
  345. i40iw_set_fragment(wqe, byte_off, &op_info->sg_list[i]);
  346. byte_off += 16;
  347. }
  348. wmb(); /* make sure WQE is populated before valid bit is set */
  349. set_64bit_val(wqe, 24, header);
  350. if (post_sq)
  351. i40iw_qp_post_wr(qp);
  352. return 0;
  353. }
  354. /**
  355. * i40iw_inline_rdma_write - inline rdma write operation
  356. * @qp: hw qp ptr
  357. * @info: post sq information
  358. * @post_sq: flag to post sq
  359. */
  360. static enum i40iw_status_code i40iw_inline_rdma_write(struct i40iw_qp_uk *qp,
  361. struct i40iw_post_sq_info *info,
  362. bool post_sq)
  363. {
  364. u64 *wqe;
  365. u8 *dest, *src;
  366. struct i40iw_inline_rdma_write *op_info;
  367. u64 *push;
  368. u64 header = 0;
  369. u32 i, wqe_idx;
  370. enum i40iw_status_code ret_code;
  371. bool read_fence = false;
  372. u8 wqe_size;
  373. op_info = &info->op.inline_rdma_write;
  374. if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
  375. return I40IW_ERR_INVALID_IMM_DATA_SIZE;
  376. ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
  377. if (ret_code)
  378. return ret_code;
  379. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, op_info->len, info->wr_id);
  380. if (!wqe)
  381. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  382. read_fence |= info->read_fence;
  383. set_64bit_val(wqe, 16,
  384. LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  385. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  386. LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  387. LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
  388. LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
  389. LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
  390. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  391. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  392. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  393. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  394. dest = (u8 *)wqe;
  395. src = (u8 *)(op_info->data);
  396. if (op_info->len <= 16) {
  397. for (i = 0; i < op_info->len; i++, src++, dest++)
  398. *dest = *src;
  399. } else {
  400. for (i = 0; i < 16; i++, src++, dest++)
  401. *dest = *src;
  402. dest = (u8 *)wqe + 32;
  403. for (; i < op_info->len; i++, src++, dest++)
  404. *dest = *src;
  405. }
  406. wmb(); /* make sure WQE is populated before valid bit is set */
  407. set_64bit_val(wqe, 24, header);
  408. if (qp->push_db) {
  409. push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
  410. memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
  411. i40iw_qp_ring_push_db(qp, wqe_idx);
  412. } else {
  413. if (post_sq)
  414. i40iw_qp_post_wr(qp);
  415. }
  416. return 0;
  417. }
  418. /**
  419. * i40iw_inline_send - inline send operation
  420. * @qp: hw qp ptr
  421. * @info: post sq information
  422. * @stag_to_inv: remote stag
  423. * @post_sq: flag to post sq
  424. */
  425. static enum i40iw_status_code i40iw_inline_send(struct i40iw_qp_uk *qp,
  426. struct i40iw_post_sq_info *info,
  427. u32 stag_to_inv,
  428. bool post_sq)
  429. {
  430. u64 *wqe;
  431. u8 *dest, *src;
  432. struct i40iw_post_inline_send *op_info;
  433. u64 header;
  434. u32 wqe_idx, i;
  435. enum i40iw_status_code ret_code;
  436. bool read_fence = false;
  437. u8 wqe_size;
  438. u64 *push;
  439. op_info = &info->op.inline_send;
  440. if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
  441. return I40IW_ERR_INVALID_IMM_DATA_SIZE;
  442. ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
  443. if (ret_code)
  444. return ret_code;
  445. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, op_info->len, info->wr_id);
  446. if (!wqe)
  447. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  448. read_fence |= info->read_fence;
  449. header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
  450. LS_64(info->op_type, I40IWQPSQ_OPCODE) |
  451. LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
  452. LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
  453. LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
  454. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  455. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  456. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  457. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  458. dest = (u8 *)wqe;
  459. src = (u8 *)(op_info->data);
  460. if (op_info->len <= 16) {
  461. for (i = 0; i < op_info->len; i++, src++, dest++)
  462. *dest = *src;
  463. } else {
  464. for (i = 0; i < 16; i++, src++, dest++)
  465. *dest = *src;
  466. dest = (u8 *)wqe + 32;
  467. for (; i < op_info->len; i++, src++, dest++)
  468. *dest = *src;
  469. }
  470. wmb(); /* make sure WQE is populated before valid bit is set */
  471. set_64bit_val(wqe, 24, header);
  472. if (qp->push_db) {
  473. push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
  474. memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
  475. i40iw_qp_ring_push_db(qp, wqe_idx);
  476. } else {
  477. if (post_sq)
  478. i40iw_qp_post_wr(qp);
  479. }
  480. return 0;
  481. }
  482. /**
  483. * i40iw_stag_local_invalidate - stag invalidate operation
  484. * @qp: hw qp ptr
  485. * @info: post sq information
  486. * @post_sq: flag to post sq
  487. */
  488. static enum i40iw_status_code i40iw_stag_local_invalidate(struct i40iw_qp_uk *qp,
  489. struct i40iw_post_sq_info *info,
  490. bool post_sq)
  491. {
  492. u64 *wqe;
  493. struct i40iw_inv_local_stag *op_info;
  494. u64 header;
  495. u32 wqe_idx;
  496. bool local_fence = false;
  497. op_info = &info->op.inv_local_stag;
  498. local_fence = info->local_fence;
  499. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE, 0, info->wr_id);
  500. if (!wqe)
  501. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  502. set_64bit_val(wqe, 0, 0);
  503. set_64bit_val(wqe, 8,
  504. LS_64(op_info->target_stag, I40IWQPSQ_LOCSTAG));
  505. set_64bit_val(wqe, 16, 0);
  506. header = LS_64(I40IW_OP_TYPE_INV_STAG, I40IWQPSQ_OPCODE) |
  507. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  508. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  509. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  510. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  511. wmb(); /* make sure WQE is populated before valid bit is set */
  512. set_64bit_val(wqe, 24, header);
  513. if (post_sq)
  514. i40iw_qp_post_wr(qp);
  515. return 0;
  516. }
  517. /**
  518. * i40iw_mw_bind - Memory Window bind operation
  519. * @qp: hw qp ptr
  520. * @info: post sq information
  521. * @post_sq: flag to post sq
  522. */
  523. static enum i40iw_status_code i40iw_mw_bind(struct i40iw_qp_uk *qp,
  524. struct i40iw_post_sq_info *info,
  525. bool post_sq)
  526. {
  527. u64 *wqe;
  528. struct i40iw_bind_window *op_info;
  529. u64 header;
  530. u32 wqe_idx;
  531. bool local_fence = false;
  532. op_info = &info->op.bind_window;
  533. local_fence |= info->local_fence;
  534. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE, 0, info->wr_id);
  535. if (!wqe)
  536. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  537. set_64bit_val(wqe, 0, (uintptr_t)op_info->va);
  538. set_64bit_val(wqe, 8,
  539. LS_64(op_info->mr_stag, I40IWQPSQ_PARENTMRSTAG) |
  540. LS_64(op_info->mw_stag, I40IWQPSQ_MWSTAG));
  541. set_64bit_val(wqe, 16, op_info->bind_length);
  542. header = LS_64(I40IW_OP_TYPE_BIND_MW, I40IWQPSQ_OPCODE) |
  543. LS_64(((op_info->enable_reads << 2) |
  544. (op_info->enable_writes << 3)),
  545. I40IWQPSQ_STAGRIGHTS) |
  546. LS_64((op_info->addressing_type == I40IW_ADDR_TYPE_VA_BASED ? 1 : 0),
  547. I40IWQPSQ_VABASEDTO) |
  548. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  549. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  550. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  551. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  552. wmb(); /* make sure WQE is populated before valid bit is set */
  553. set_64bit_val(wqe, 24, header);
  554. if (post_sq)
  555. i40iw_qp_post_wr(qp);
  556. return 0;
  557. }
  558. /**
  559. * i40iw_post_receive - post receive wqe
  560. * @qp: hw qp ptr
  561. * @info: post rq information
  562. */
  563. static enum i40iw_status_code i40iw_post_receive(struct i40iw_qp_uk *qp,
  564. struct i40iw_post_rq_info *info)
  565. {
  566. u64 *wqe;
  567. u64 header;
  568. u32 total_size = 0, wqe_idx, i, byte_off;
  569. if (qp->max_rq_frag_cnt < info->num_sges)
  570. return I40IW_ERR_INVALID_FRAG_COUNT;
  571. for (i = 0; i < info->num_sges; i++)
  572. total_size += info->sg_list[i].len;
  573. wqe = i40iw_qp_get_next_recv_wqe(qp, &wqe_idx);
  574. if (!wqe)
  575. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  576. qp->rq_wrid_array[wqe_idx] = info->wr_id;
  577. set_64bit_val(wqe, 16, 0);
  578. header = LS_64((info->num_sges > 1 ? (info->num_sges - 1) : 0),
  579. I40IWQPSQ_ADDFRAGCNT) |
  580. LS_64(qp->rwqe_polarity, I40IWQPSQ_VALID);
  581. i40iw_set_fragment(wqe, 0, info->sg_list);
  582. for (i = 1, byte_off = 32; i < info->num_sges; i++) {
  583. i40iw_set_fragment(wqe, byte_off, &info->sg_list[i]);
  584. byte_off += 16;
  585. }
  586. wmb(); /* make sure WQE is populated before valid bit is set */
  587. set_64bit_val(wqe, 24, header);
  588. return 0;
  589. }
  590. /**
  591. * i40iw_cq_request_notification - cq notification request (door bell)
  592. * @cq: hw cq
  593. * @cq_notify: notification type
  594. */
  595. static void i40iw_cq_request_notification(struct i40iw_cq_uk *cq,
  596. enum i40iw_completion_notify cq_notify)
  597. {
  598. u64 temp_val;
  599. u16 sw_cq_sel;
  600. u8 arm_next_se = 0;
  601. u8 arm_next = 0;
  602. u8 arm_seq_num;
  603. get_64bit_val(cq->shadow_area, 32, &temp_val);
  604. arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
  605. arm_seq_num++;
  606. sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
  607. arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
  608. arm_next_se |= 1;
  609. if (cq_notify == IW_CQ_COMPL_EVENT)
  610. arm_next = 1;
  611. temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
  612. LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
  613. LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
  614. LS_64(arm_next, I40IW_CQ_DBSA_ARM_NEXT);
  615. set_64bit_val(cq->shadow_area, 32, temp_val);
  616. wmb(); /* make sure WQE is populated before valid bit is set */
  617. writel(cq->cq_id, cq->cqe_alloc_reg);
  618. }
  619. /**
  620. * i40iw_cq_post_entries - update tail in shadow memory
  621. * @cq: hw cq
  622. * @count: # of entries processed
  623. */
  624. static enum i40iw_status_code i40iw_cq_post_entries(struct i40iw_cq_uk *cq,
  625. u8 count)
  626. {
  627. I40IW_RING_MOVE_TAIL_BY_COUNT(cq->cq_ring, count);
  628. set_64bit_val(cq->shadow_area, 0,
  629. I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
  630. return 0;
  631. }
  632. /**
  633. * i40iw_cq_poll_completion - get cq completion info
  634. * @cq: hw cq
  635. * @info: cq poll information returned
  636. * @post_cq: update cq tail
  637. */
  638. static enum i40iw_status_code i40iw_cq_poll_completion(struct i40iw_cq_uk *cq,
  639. struct i40iw_cq_poll_info *info)
  640. {
  641. u64 comp_ctx, qword0, qword2, qword3, wqe_qword;
  642. u64 *cqe, *sw_wqe;
  643. struct i40iw_qp_uk *qp;
  644. struct i40iw_ring *pring = NULL;
  645. u32 wqe_idx, q_type, array_idx = 0;
  646. enum i40iw_status_code ret_code = 0;
  647. bool move_cq_head = true;
  648. u8 polarity;
  649. u8 addl_wqes = 0;
  650. if (cq->avoid_mem_cflct)
  651. cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(cq);
  652. else
  653. cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(cq);
  654. get_64bit_val(cqe, 24, &qword3);
  655. polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
  656. if (polarity != cq->polarity)
  657. return I40IW_ERR_QUEUE_EMPTY;
  658. q_type = (u8)RS_64(qword3, I40IW_CQ_SQ);
  659. info->error = (bool)RS_64(qword3, I40IW_CQ_ERROR);
  660. info->push_dropped = (bool)RS_64(qword3, I40IWCQ_PSHDROP);
  661. if (info->error) {
  662. info->comp_status = I40IW_COMPL_STATUS_FLUSHED;
  663. info->major_err = (bool)RS_64(qword3, I40IW_CQ_MAJERR);
  664. info->minor_err = (bool)RS_64(qword3, I40IW_CQ_MINERR);
  665. } else {
  666. info->comp_status = I40IW_COMPL_STATUS_SUCCESS;
  667. }
  668. get_64bit_val(cqe, 0, &qword0);
  669. get_64bit_val(cqe, 16, &qword2);
  670. info->tcp_seq_num = (u8)RS_64(qword0, I40IWCQ_TCPSEQNUM);
  671. info->qp_id = (u32)RS_64(qword2, I40IWCQ_QPID);
  672. get_64bit_val(cqe, 8, &comp_ctx);
  673. info->solicited_event = (bool)RS_64(qword3, I40IWCQ_SOEVENT);
  674. info->is_srq = (bool)RS_64(qword3, I40IWCQ_SRQ);
  675. qp = (struct i40iw_qp_uk *)(unsigned long)comp_ctx;
  676. if (!qp) {
  677. ret_code = I40IW_ERR_QUEUE_DESTROYED;
  678. goto exit;
  679. }
  680. wqe_idx = (u32)RS_64(qword3, I40IW_CQ_WQEIDX);
  681. info->qp_handle = (i40iw_qp_handle)(unsigned long)qp;
  682. if (q_type == I40IW_CQE_QTYPE_RQ) {
  683. array_idx = (wqe_idx * 4) / qp->rq_wqe_size_multiplier;
  684. if (info->comp_status == I40IW_COMPL_STATUS_FLUSHED) {
  685. info->wr_id = qp->rq_wrid_array[qp->rq_ring.tail];
  686. array_idx = qp->rq_ring.tail;
  687. } else {
  688. info->wr_id = qp->rq_wrid_array[array_idx];
  689. }
  690. info->op_type = I40IW_OP_TYPE_REC;
  691. if (qword3 & I40IWCQ_STAG_MASK) {
  692. info->stag_invalid_set = true;
  693. info->inv_stag = (u32)RS_64(qword2, I40IWCQ_INVSTAG);
  694. } else {
  695. info->stag_invalid_set = false;
  696. }
  697. info->bytes_xfered = (u32)RS_64(qword0, I40IWCQ_PAYLDLEN);
  698. I40IW_RING_SET_TAIL(qp->rq_ring, array_idx + 1);
  699. pring = &qp->rq_ring;
  700. } else {
  701. if (info->comp_status != I40IW_COMPL_STATUS_FLUSHED) {
  702. info->wr_id = qp->sq_wrtrk_array[wqe_idx].wrid;
  703. info->bytes_xfered = qp->sq_wrtrk_array[wqe_idx].wr_len;
  704. info->op_type = (u8)RS_64(qword3, I40IWCQ_OP);
  705. sw_wqe = qp->sq_base[wqe_idx].elem;
  706. get_64bit_val(sw_wqe, 24, &wqe_qword);
  707. addl_wqes = qp->sq_wrtrk_array[wqe_idx].wqe_size / I40IW_QP_WQE_MIN_SIZE;
  708. I40IW_RING_SET_TAIL(qp->sq_ring, (wqe_idx + addl_wqes));
  709. } else {
  710. do {
  711. u8 op_type;
  712. u32 tail;
  713. tail = qp->sq_ring.tail;
  714. sw_wqe = qp->sq_base[tail].elem;
  715. get_64bit_val(sw_wqe, 24, &wqe_qword);
  716. op_type = (u8)RS_64(wqe_qword, I40IWQPSQ_OPCODE);
  717. info->op_type = op_type;
  718. addl_wqes = qp->sq_wrtrk_array[tail].wqe_size / I40IW_QP_WQE_MIN_SIZE;
  719. I40IW_RING_SET_TAIL(qp->sq_ring, (tail + addl_wqes));
  720. if (op_type != I40IWQP_OP_NOP) {
  721. info->wr_id = qp->sq_wrtrk_array[tail].wrid;
  722. info->bytes_xfered = qp->sq_wrtrk_array[tail].wr_len;
  723. break;
  724. }
  725. } while (1);
  726. }
  727. pring = &qp->sq_ring;
  728. }
  729. ret_code = 0;
  730. exit:
  731. if (!ret_code &&
  732. (info->comp_status == I40IW_COMPL_STATUS_FLUSHED))
  733. if (pring && (I40IW_RING_MORE_WORK(*pring)))
  734. move_cq_head = false;
  735. if (move_cq_head) {
  736. I40IW_RING_MOVE_HEAD_NOCHECK(cq->cq_ring);
  737. if (I40IW_RING_GETCURRENT_HEAD(cq->cq_ring) == 0)
  738. cq->polarity ^= 1;
  739. I40IW_RING_MOVE_TAIL(cq->cq_ring);
  740. set_64bit_val(cq->shadow_area, 0,
  741. I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
  742. } else {
  743. if (info->is_srq)
  744. return ret_code;
  745. qword3 &= ~I40IW_CQ_WQEIDX_MASK;
  746. qword3 |= LS_64(pring->tail, I40IW_CQ_WQEIDX);
  747. set_64bit_val(cqe, 24, qword3);
  748. }
  749. return ret_code;
  750. }
  751. /**
  752. * i40iw_get_wqe_shift - get shift count for maximum wqe size
  753. * @wqdepth: depth of wq required.
  754. * @sge: Maximum Scatter Gather Elements wqe
  755. * @inline_data: Maximum inline data size
  756. * @shift: Returns the shift needed based on sge
  757. *
  758. * Shift can be used to left shift the wqe size based on number of SGEs and inlind data size.
  759. * For 1 SGE or inline data <= 16, shift = 0 (wqe size of 32 bytes).
  760. * For 2 or 3 SGEs or inline data <= 48, shift = 1 (wqe size of 64 bytes).
  761. * Shift of 2 otherwise (wqe size of 128 bytes).
  762. */
  763. enum i40iw_status_code i40iw_get_wqe_shift(u32 wqdepth, u32 sge, u32 inline_data, u8 *shift)
  764. {
  765. u32 size;
  766. *shift = 0;
  767. if (sge > 1 || inline_data > 16)
  768. *shift = (sge < 4 && inline_data <= 48) ? 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, info->max_inline_data, &sqshift);
  823. if (ret_code)
  824. return ret_code;
  825. ret_code = i40iw_get_wqe_shift(info->rq_size, info->max_rq_frag_cnt, 0, &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, 0, wr_id);
  933. if (!wqe)
  934. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  935. set_64bit_val(wqe, 0, 0);
  936. set_64bit_val(wqe, 8, 0);
  937. set_64bit_val(wqe, 16, 0);
  938. header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
  939. LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
  940. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  941. wmb(); /* make sure WQE is populated before valid bit is set */
  942. set_64bit_val(wqe, 24, header);
  943. if (post_sq)
  944. i40iw_qp_post_wr(qp);
  945. return 0;
  946. }
  947. /**
  948. * i40iw_fragcnt_to_wqesize_sq - calculate wqe size based on fragment count for SQ
  949. * @frag_cnt: number of fragments
  950. * @wqe_size: size of sq wqe returned
  951. */
  952. enum i40iw_status_code i40iw_fragcnt_to_wqesize_sq(u32 frag_cnt, u8 *wqe_size)
  953. {
  954. switch (frag_cnt) {
  955. case 0:
  956. case 1:
  957. *wqe_size = I40IW_QP_WQE_MIN_SIZE;
  958. break;
  959. case 2:
  960. case 3:
  961. *wqe_size = 64;
  962. break;
  963. case 4:
  964. case 5:
  965. *wqe_size = 96;
  966. break;
  967. case 6:
  968. case 7:
  969. *wqe_size = 128;
  970. break;
  971. default:
  972. return I40IW_ERR_INVALID_FRAG_COUNT;
  973. }
  974. return 0;
  975. }
  976. /**
  977. * i40iw_fragcnt_to_wqesize_rq - calculate wqe size based on fragment count for RQ
  978. * @frag_cnt: number of fragments
  979. * @wqe_size: size of rq wqe returned
  980. */
  981. enum i40iw_status_code i40iw_fragcnt_to_wqesize_rq(u32 frag_cnt, u8 *wqe_size)
  982. {
  983. switch (frag_cnt) {
  984. case 0:
  985. case 1:
  986. *wqe_size = 32;
  987. break;
  988. case 2:
  989. case 3:
  990. *wqe_size = 64;
  991. break;
  992. case 4:
  993. case 5:
  994. case 6:
  995. case 7:
  996. *wqe_size = 128;
  997. break;
  998. default:
  999. return I40IW_ERR_INVALID_FRAG_COUNT;
  1000. }
  1001. return 0;
  1002. }
  1003. /**
  1004. * i40iw_inline_data_size_to_wqesize - based on inline data, wqe size
  1005. * @data_size: data size for inline
  1006. * @wqe_size: size of sq wqe returned
  1007. */
  1008. enum i40iw_status_code i40iw_inline_data_size_to_wqesize(u32 data_size,
  1009. u8 *wqe_size)
  1010. {
  1011. if (data_size > I40IW_MAX_INLINE_DATA_SIZE)
  1012. return I40IW_ERR_INVALID_IMM_DATA_SIZE;
  1013. if (data_size <= 16)
  1014. *wqe_size = I40IW_QP_WQE_MIN_SIZE;
  1015. else if (data_size <= 48)
  1016. *wqe_size = 64;
  1017. else if (data_size <= 80)
  1018. *wqe_size = 96;
  1019. else
  1020. *wqe_size = 128;
  1021. return 0;
  1022. }