i40iw_uk.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. I40IW_RING_MOVE_HEAD_BY_COUNT(qp->sq_ring,
  157. wqe_size / I40IW_QP_WQE_MIN_SIZE, ret_code);
  158. if (ret_code)
  159. return NULL;
  160. wqe = qp->sq_base[*wqe_idx].elem;
  161. peek_head = I40IW_RING_GETCURRENT_HEAD(qp->sq_ring);
  162. wqe_0 = qp->sq_base[peek_head].elem;
  163. if (((peek_head & 3) == 1) || ((peek_head & 3) == 3)) {
  164. if (RS_64(wqe_0[3], I40IWQPSQ_VALID) != !qp->swqe_polarity)
  165. wqe_0[3] = LS_64(!qp->swqe_polarity, I40IWQPSQ_VALID);
  166. }
  167. qp->sq_wrtrk_array[*wqe_idx].wrid = wr_id;
  168. qp->sq_wrtrk_array[*wqe_idx].wr_len = total_size;
  169. qp->sq_wrtrk_array[*wqe_idx].wqe_size = wqe_size;
  170. return wqe;
  171. }
  172. /**
  173. * i40iw_set_fragment - set fragment in wqe
  174. * @wqe: wqe for setting fragment
  175. * @offset: offset value
  176. * @sge: sge length and stag
  177. */
  178. static void i40iw_set_fragment(u64 *wqe, u32 offset, struct i40iw_sge *sge)
  179. {
  180. if (sge) {
  181. set_64bit_val(wqe, offset, LS_64(sge->tag_off, I40IWQPSQ_FRAG_TO));
  182. set_64bit_val(wqe, (offset + 8),
  183. (LS_64(sge->len, I40IWQPSQ_FRAG_LEN) |
  184. LS_64(sge->stag, I40IWQPSQ_FRAG_STAG)));
  185. }
  186. }
  187. /**
  188. * i40iw_qp_get_next_recv_wqe - get next qp's rcv wqe
  189. * @qp: hw qp ptr
  190. * @wqe_idx: return wqe index
  191. */
  192. u64 *i40iw_qp_get_next_recv_wqe(struct i40iw_qp_uk *qp, u32 *wqe_idx)
  193. {
  194. u64 *wqe = NULL;
  195. enum i40iw_status_code ret_code;
  196. if (I40IW_RING_FULL_ERR(qp->rq_ring))
  197. return NULL;
  198. I40IW_ATOMIC_RING_MOVE_HEAD(qp->rq_ring, *wqe_idx, ret_code);
  199. if (ret_code)
  200. return NULL;
  201. if (!*wqe_idx)
  202. qp->rwqe_polarity = !qp->rwqe_polarity;
  203. /* rq_wqe_size_multiplier is no of qwords in one rq wqe */
  204. wqe = qp->rq_base[*wqe_idx * (qp->rq_wqe_size_multiplier >> 2)].elem;
  205. return wqe;
  206. }
  207. /**
  208. * i40iw_rdma_write - rdma write operation
  209. * @qp: hw qp ptr
  210. * @info: post sq information
  211. * @post_sq: flag to post sq
  212. */
  213. static enum i40iw_status_code i40iw_rdma_write(struct i40iw_qp_uk *qp,
  214. struct i40iw_post_sq_info *info,
  215. bool post_sq)
  216. {
  217. u64 header;
  218. u64 *wqe;
  219. struct i40iw_rdma_write *op_info;
  220. u32 i, wqe_idx;
  221. u32 total_size = 0, byte_off;
  222. enum i40iw_status_code ret_code;
  223. bool read_fence = false;
  224. u8 wqe_size;
  225. op_info = &info->op.rdma_write;
  226. if (op_info->num_lo_sges > qp->max_sq_frag_cnt)
  227. return I40IW_ERR_INVALID_FRAG_COUNT;
  228. for (i = 0; i < op_info->num_lo_sges; i++)
  229. total_size += op_info->lo_sg_list[i].len;
  230. if (total_size > I40IW_MAX_OUTBOUND_MESSAGE_SIZE)
  231. return I40IW_ERR_QP_INVALID_MSG_SIZE;
  232. read_fence |= info->read_fence;
  233. ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_lo_sges, &wqe_size);
  234. if (ret_code)
  235. return ret_code;
  236. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, total_size, info->wr_id);
  237. if (!wqe)
  238. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  239. set_64bit_val(wqe, 16,
  240. LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  241. if (!op_info->rem_addr.stag)
  242. return I40IW_ERR_BAD_STAG;
  243. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  244. LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  245. LS_64((op_info->num_lo_sges > 1 ? (op_info->num_lo_sges - 1) : 0), I40IWQPSQ_ADDFRAGCNT) |
  246. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  247. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  248. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  249. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  250. i40iw_set_fragment(wqe, 0, op_info->lo_sg_list);
  251. for (i = 1, byte_off = 32; i < op_info->num_lo_sges; i++) {
  252. i40iw_set_fragment(wqe, byte_off, &op_info->lo_sg_list[i]);
  253. byte_off += 16;
  254. }
  255. wmb(); /* make sure WQE is populated before valid bit is set */
  256. set_64bit_val(wqe, 24, header);
  257. if (post_sq)
  258. i40iw_qp_post_wr(qp);
  259. return 0;
  260. }
  261. /**
  262. * i40iw_rdma_read - rdma read command
  263. * @qp: hw qp ptr
  264. * @info: post sq information
  265. * @inv_stag: flag for inv_stag
  266. * @post_sq: flag to post sq
  267. */
  268. static enum i40iw_status_code i40iw_rdma_read(struct i40iw_qp_uk *qp,
  269. struct i40iw_post_sq_info *info,
  270. bool inv_stag,
  271. bool post_sq)
  272. {
  273. u64 *wqe;
  274. struct i40iw_rdma_read *op_info;
  275. u64 header;
  276. u32 wqe_idx;
  277. enum i40iw_status_code ret_code;
  278. u8 wqe_size;
  279. bool local_fence = false;
  280. op_info = &info->op.rdma_read;
  281. ret_code = i40iw_fragcnt_to_wqesize_sq(1, &wqe_size);
  282. if (ret_code)
  283. return ret_code;
  284. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, op_info->lo_addr.len, info->wr_id);
  285. if (!wqe)
  286. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  287. local_fence |= info->local_fence;
  288. set_64bit_val(wqe, 16, LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  289. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  290. LS_64((inv_stag ? I40IWQP_OP_RDMA_READ_LOC_INV : I40IWQP_OP_RDMA_READ), I40IWQPSQ_OPCODE) |
  291. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  292. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  293. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  294. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  295. i40iw_set_fragment(wqe, 0, &op_info->lo_addr);
  296. wmb(); /* make sure WQE is populated before valid bit is set */
  297. set_64bit_val(wqe, 24, header);
  298. if (post_sq)
  299. i40iw_qp_post_wr(qp);
  300. return 0;
  301. }
  302. /**
  303. * i40iw_send - rdma send command
  304. * @qp: hw qp ptr
  305. * @info: post sq information
  306. * @stag_to_inv: stag_to_inv value
  307. * @post_sq: flag to post sq
  308. */
  309. static enum i40iw_status_code i40iw_send(struct i40iw_qp_uk *qp,
  310. struct i40iw_post_sq_info *info,
  311. u32 stag_to_inv,
  312. bool post_sq)
  313. {
  314. u64 *wqe;
  315. struct i40iw_post_send *op_info;
  316. u64 header;
  317. u32 i, wqe_idx, total_size = 0, byte_off;
  318. enum i40iw_status_code ret_code;
  319. bool read_fence = false;
  320. u8 wqe_size;
  321. op_info = &info->op.send;
  322. if (qp->max_sq_frag_cnt < op_info->num_sges)
  323. return I40IW_ERR_INVALID_FRAG_COUNT;
  324. for (i = 0; i < op_info->num_sges; i++)
  325. total_size += op_info->sg_list[i].len;
  326. ret_code = i40iw_fragcnt_to_wqesize_sq(op_info->num_sges, &wqe_size);
  327. if (ret_code)
  328. return ret_code;
  329. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, total_size, info->wr_id);
  330. if (!wqe)
  331. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  332. read_fence |= info->read_fence;
  333. set_64bit_val(wqe, 16, 0);
  334. header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
  335. LS_64(info->op_type, I40IWQPSQ_OPCODE) |
  336. LS_64((op_info->num_sges > 1 ? (op_info->num_sges - 1) : 0),
  337. I40IWQPSQ_ADDFRAGCNT) |
  338. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  339. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  340. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  341. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  342. i40iw_set_fragment(wqe, 0, op_info->sg_list);
  343. for (i = 1, byte_off = 32; i < op_info->num_sges; i++) {
  344. i40iw_set_fragment(wqe, byte_off, &op_info->sg_list[i]);
  345. byte_off += 16;
  346. }
  347. wmb(); /* make sure WQE is populated before valid bit is set */
  348. set_64bit_val(wqe, 24, header);
  349. if (post_sq)
  350. i40iw_qp_post_wr(qp);
  351. return 0;
  352. }
  353. /**
  354. * i40iw_inline_rdma_write - inline rdma write operation
  355. * @qp: hw qp ptr
  356. * @info: post sq information
  357. * @post_sq: flag to post sq
  358. */
  359. static enum i40iw_status_code i40iw_inline_rdma_write(struct i40iw_qp_uk *qp,
  360. struct i40iw_post_sq_info *info,
  361. bool post_sq)
  362. {
  363. u64 *wqe;
  364. u8 *dest, *src;
  365. struct i40iw_inline_rdma_write *op_info;
  366. u64 *push;
  367. u64 header = 0;
  368. u32 wqe_idx;
  369. enum i40iw_status_code ret_code;
  370. bool read_fence = false;
  371. u8 wqe_size;
  372. op_info = &info->op.inline_rdma_write;
  373. if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
  374. return I40IW_ERR_INVALID_INLINE_DATA_SIZE;
  375. ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
  376. if (ret_code)
  377. return ret_code;
  378. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, op_info->len, info->wr_id);
  379. if (!wqe)
  380. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  381. read_fence |= info->read_fence;
  382. set_64bit_val(wqe, 16,
  383. LS_64(op_info->rem_addr.tag_off, I40IWQPSQ_FRAG_TO));
  384. header = LS_64(op_info->rem_addr.stag, I40IWQPSQ_REMSTAG) |
  385. LS_64(I40IWQP_OP_RDMA_WRITE, I40IWQPSQ_OPCODE) |
  386. LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
  387. LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
  388. LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
  389. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  390. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  391. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  392. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  393. dest = (u8 *)wqe;
  394. src = (u8 *)(op_info->data);
  395. if (op_info->len <= 16) {
  396. memcpy(dest, src, op_info->len);
  397. } else {
  398. memcpy(dest, src, 16);
  399. src += 16;
  400. dest = (u8 *)wqe + 32;
  401. memcpy(dest, src, op_info->len - 16);
  402. }
  403. wmb(); /* make sure WQE is populated before valid bit is set */
  404. set_64bit_val(wqe, 24, header);
  405. if (qp->push_db) {
  406. push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
  407. memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
  408. i40iw_qp_ring_push_db(qp, wqe_idx);
  409. } else {
  410. if (post_sq)
  411. i40iw_qp_post_wr(qp);
  412. }
  413. return 0;
  414. }
  415. /**
  416. * i40iw_inline_send - inline send operation
  417. * @qp: hw qp ptr
  418. * @info: post sq information
  419. * @stag_to_inv: remote stag
  420. * @post_sq: flag to post sq
  421. */
  422. static enum i40iw_status_code i40iw_inline_send(struct i40iw_qp_uk *qp,
  423. struct i40iw_post_sq_info *info,
  424. u32 stag_to_inv,
  425. bool post_sq)
  426. {
  427. u64 *wqe;
  428. u8 *dest, *src;
  429. struct i40iw_post_inline_send *op_info;
  430. u64 header;
  431. u32 wqe_idx;
  432. enum i40iw_status_code ret_code;
  433. bool read_fence = false;
  434. u8 wqe_size;
  435. u64 *push;
  436. op_info = &info->op.inline_send;
  437. if (op_info->len > I40IW_MAX_INLINE_DATA_SIZE)
  438. return I40IW_ERR_INVALID_INLINE_DATA_SIZE;
  439. ret_code = i40iw_inline_data_size_to_wqesize(op_info->len, &wqe_size);
  440. if (ret_code)
  441. return ret_code;
  442. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, wqe_size, op_info->len, info->wr_id);
  443. if (!wqe)
  444. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  445. read_fence |= info->read_fence;
  446. header = LS_64(stag_to_inv, I40IWQPSQ_REMSTAG) |
  447. LS_64(info->op_type, I40IWQPSQ_OPCODE) |
  448. LS_64(op_info->len, I40IWQPSQ_INLINEDATALEN) |
  449. LS_64(1, I40IWQPSQ_INLINEDATAFLAG) |
  450. LS_64((qp->push_db ? 1 : 0), I40IWQPSQ_PUSHWQE) |
  451. LS_64(read_fence, I40IWQPSQ_READFENCE) |
  452. LS_64(info->local_fence, I40IWQPSQ_LOCALFENCE) |
  453. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  454. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  455. dest = (u8 *)wqe;
  456. src = (u8 *)(op_info->data);
  457. if (op_info->len <= 16) {
  458. memcpy(dest, src, op_info->len);
  459. } else {
  460. memcpy(dest, src, 16);
  461. src += 16;
  462. dest = (u8 *)wqe + 32;
  463. memcpy(dest, src, op_info->len - 16);
  464. }
  465. wmb(); /* make sure WQE is populated before valid bit is set */
  466. set_64bit_val(wqe, 24, header);
  467. if (qp->push_db) {
  468. push = (u64 *)((uintptr_t)qp->push_wqe + (wqe_idx & 0x3) * 0x20);
  469. memcpy(push, wqe, (op_info->len > 16) ? op_info->len + 16 : 32);
  470. i40iw_qp_ring_push_db(qp, wqe_idx);
  471. } else {
  472. if (post_sq)
  473. i40iw_qp_post_wr(qp);
  474. }
  475. return 0;
  476. }
  477. /**
  478. * i40iw_stag_local_invalidate - stag invalidate operation
  479. * @qp: hw qp ptr
  480. * @info: post sq information
  481. * @post_sq: flag to post sq
  482. */
  483. static enum i40iw_status_code i40iw_stag_local_invalidate(struct i40iw_qp_uk *qp,
  484. struct i40iw_post_sq_info *info,
  485. bool post_sq)
  486. {
  487. u64 *wqe;
  488. struct i40iw_inv_local_stag *op_info;
  489. u64 header;
  490. u32 wqe_idx;
  491. bool local_fence = false;
  492. op_info = &info->op.inv_local_stag;
  493. local_fence = info->local_fence;
  494. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE, 0, info->wr_id);
  495. if (!wqe)
  496. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  497. set_64bit_val(wqe, 0, 0);
  498. set_64bit_val(wqe, 8,
  499. LS_64(op_info->target_stag, I40IWQPSQ_LOCSTAG));
  500. set_64bit_val(wqe, 16, 0);
  501. header = LS_64(I40IW_OP_TYPE_INV_STAG, I40IWQPSQ_OPCODE) |
  502. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  503. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  504. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  505. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  506. wmb(); /* make sure WQE is populated before valid bit is set */
  507. set_64bit_val(wqe, 24, header);
  508. if (post_sq)
  509. i40iw_qp_post_wr(qp);
  510. return 0;
  511. }
  512. /**
  513. * i40iw_mw_bind - Memory Window bind operation
  514. * @qp: hw qp ptr
  515. * @info: post sq information
  516. * @post_sq: flag to post sq
  517. */
  518. static enum i40iw_status_code i40iw_mw_bind(struct i40iw_qp_uk *qp,
  519. struct i40iw_post_sq_info *info,
  520. bool post_sq)
  521. {
  522. u64 *wqe;
  523. struct i40iw_bind_window *op_info;
  524. u64 header;
  525. u32 wqe_idx;
  526. bool local_fence = false;
  527. op_info = &info->op.bind_window;
  528. local_fence |= info->local_fence;
  529. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE, 0, info->wr_id);
  530. if (!wqe)
  531. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  532. set_64bit_val(wqe, 0, (uintptr_t)op_info->va);
  533. set_64bit_val(wqe, 8,
  534. LS_64(op_info->mr_stag, I40IWQPSQ_PARENTMRSTAG) |
  535. LS_64(op_info->mw_stag, I40IWQPSQ_MWSTAG));
  536. set_64bit_val(wqe, 16, op_info->bind_length);
  537. header = LS_64(I40IW_OP_TYPE_BIND_MW, I40IWQPSQ_OPCODE) |
  538. LS_64(((op_info->enable_reads << 2) |
  539. (op_info->enable_writes << 3)),
  540. I40IWQPSQ_STAGRIGHTS) |
  541. LS_64((op_info->addressing_type == I40IW_ADDR_TYPE_VA_BASED ? 1 : 0),
  542. I40IWQPSQ_VABASEDTO) |
  543. LS_64(info->read_fence, I40IWQPSQ_READFENCE) |
  544. LS_64(local_fence, I40IWQPSQ_LOCALFENCE) |
  545. LS_64(info->signaled, I40IWQPSQ_SIGCOMPL) |
  546. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  547. wmb(); /* make sure WQE is populated before valid bit is set */
  548. set_64bit_val(wqe, 24, header);
  549. if (post_sq)
  550. i40iw_qp_post_wr(qp);
  551. return 0;
  552. }
  553. /**
  554. * i40iw_post_receive - post receive wqe
  555. * @qp: hw qp ptr
  556. * @info: post rq information
  557. */
  558. static enum i40iw_status_code i40iw_post_receive(struct i40iw_qp_uk *qp,
  559. struct i40iw_post_rq_info *info)
  560. {
  561. u64 *wqe;
  562. u64 header;
  563. u32 total_size = 0, wqe_idx, i, byte_off;
  564. if (qp->max_rq_frag_cnt < info->num_sges)
  565. return I40IW_ERR_INVALID_FRAG_COUNT;
  566. for (i = 0; i < info->num_sges; i++)
  567. total_size += info->sg_list[i].len;
  568. wqe = i40iw_qp_get_next_recv_wqe(qp, &wqe_idx);
  569. if (!wqe)
  570. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  571. qp->rq_wrid_array[wqe_idx] = info->wr_id;
  572. set_64bit_val(wqe, 16, 0);
  573. header = LS_64((info->num_sges > 1 ? (info->num_sges - 1) : 0),
  574. I40IWQPSQ_ADDFRAGCNT) |
  575. LS_64(qp->rwqe_polarity, I40IWQPSQ_VALID);
  576. i40iw_set_fragment(wqe, 0, info->sg_list);
  577. for (i = 1, byte_off = 32; i < info->num_sges; i++) {
  578. i40iw_set_fragment(wqe, byte_off, &info->sg_list[i]);
  579. byte_off += 16;
  580. }
  581. wmb(); /* make sure WQE is populated before valid bit is set */
  582. set_64bit_val(wqe, 24, header);
  583. return 0;
  584. }
  585. /**
  586. * i40iw_cq_request_notification - cq notification request (door bell)
  587. * @cq: hw cq
  588. * @cq_notify: notification type
  589. */
  590. static void i40iw_cq_request_notification(struct i40iw_cq_uk *cq,
  591. enum i40iw_completion_notify cq_notify)
  592. {
  593. u64 temp_val;
  594. u16 sw_cq_sel;
  595. u8 arm_next_se = 0;
  596. u8 arm_next = 0;
  597. u8 arm_seq_num;
  598. get_64bit_val(cq->shadow_area, 32, &temp_val);
  599. arm_seq_num = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_SEQ_NUM);
  600. arm_seq_num++;
  601. sw_cq_sel = (u16)RS_64(temp_val, I40IW_CQ_DBSA_SW_CQ_SELECT);
  602. arm_next_se = (u8)RS_64(temp_val, I40IW_CQ_DBSA_ARM_NEXT_SE);
  603. arm_next_se |= 1;
  604. if (cq_notify == IW_CQ_COMPL_EVENT)
  605. arm_next = 1;
  606. temp_val = LS_64(arm_seq_num, I40IW_CQ_DBSA_ARM_SEQ_NUM) |
  607. LS_64(sw_cq_sel, I40IW_CQ_DBSA_SW_CQ_SELECT) |
  608. LS_64(arm_next_se, I40IW_CQ_DBSA_ARM_NEXT_SE) |
  609. LS_64(arm_next, I40IW_CQ_DBSA_ARM_NEXT);
  610. set_64bit_val(cq->shadow_area, 32, temp_val);
  611. wmb(); /* make sure WQE is populated before valid bit is set */
  612. writel(cq->cq_id, cq->cqe_alloc_reg);
  613. }
  614. /**
  615. * i40iw_cq_post_entries - update tail in shadow memory
  616. * @cq: hw cq
  617. * @count: # of entries processed
  618. */
  619. static enum i40iw_status_code i40iw_cq_post_entries(struct i40iw_cq_uk *cq,
  620. u8 count)
  621. {
  622. I40IW_RING_MOVE_TAIL_BY_COUNT(cq->cq_ring, count);
  623. set_64bit_val(cq->shadow_area, 0,
  624. I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
  625. return 0;
  626. }
  627. /**
  628. * i40iw_cq_poll_completion - get cq completion info
  629. * @cq: hw cq
  630. * @info: cq poll information returned
  631. * @post_cq: update cq tail
  632. */
  633. static enum i40iw_status_code i40iw_cq_poll_completion(struct i40iw_cq_uk *cq,
  634. struct i40iw_cq_poll_info *info)
  635. {
  636. u64 comp_ctx, qword0, qword2, qword3, wqe_qword;
  637. u64 *cqe, *sw_wqe;
  638. struct i40iw_qp_uk *qp;
  639. struct i40iw_ring *pring = NULL;
  640. u32 wqe_idx, q_type, array_idx = 0;
  641. enum i40iw_status_code ret_code = 0;
  642. bool move_cq_head = true;
  643. u8 polarity;
  644. u8 addl_wqes = 0;
  645. if (cq->avoid_mem_cflct)
  646. cqe = (u64 *)I40IW_GET_CURRENT_EXTENDED_CQ_ELEMENT(cq);
  647. else
  648. cqe = (u64 *)I40IW_GET_CURRENT_CQ_ELEMENT(cq);
  649. get_64bit_val(cqe, 24, &qword3);
  650. polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
  651. if (polarity != cq->polarity)
  652. return I40IW_ERR_QUEUE_EMPTY;
  653. q_type = (u8)RS_64(qword3, I40IW_CQ_SQ);
  654. info->error = (bool)RS_64(qword3, I40IW_CQ_ERROR);
  655. info->push_dropped = (bool)RS_64(qword3, I40IWCQ_PSHDROP);
  656. if (info->error) {
  657. info->comp_status = I40IW_COMPL_STATUS_FLUSHED;
  658. info->major_err = (bool)RS_64(qword3, I40IW_CQ_MAJERR);
  659. info->minor_err = (bool)RS_64(qword3, I40IW_CQ_MINERR);
  660. } else {
  661. info->comp_status = I40IW_COMPL_STATUS_SUCCESS;
  662. }
  663. get_64bit_val(cqe, 0, &qword0);
  664. get_64bit_val(cqe, 16, &qword2);
  665. info->tcp_seq_num = (u32)RS_64(qword0, I40IWCQ_TCPSEQNUM);
  666. info->qp_id = (u32)RS_64(qword2, I40IWCQ_QPID);
  667. get_64bit_val(cqe, 8, &comp_ctx);
  668. info->solicited_event = (bool)RS_64(qword3, I40IWCQ_SOEVENT);
  669. info->is_srq = (bool)RS_64(qword3, I40IWCQ_SRQ);
  670. qp = (struct i40iw_qp_uk *)(unsigned long)comp_ctx;
  671. if (!qp) {
  672. ret_code = I40IW_ERR_QUEUE_DESTROYED;
  673. goto exit;
  674. }
  675. wqe_idx = (u32)RS_64(qword3, I40IW_CQ_WQEIDX);
  676. info->qp_handle = (i40iw_qp_handle)(unsigned long)qp;
  677. if (q_type == I40IW_CQE_QTYPE_RQ) {
  678. array_idx = (wqe_idx * 4) / qp->rq_wqe_size_multiplier;
  679. if (info->comp_status == I40IW_COMPL_STATUS_FLUSHED) {
  680. info->wr_id = qp->rq_wrid_array[qp->rq_ring.tail];
  681. array_idx = qp->rq_ring.tail;
  682. } else {
  683. info->wr_id = qp->rq_wrid_array[array_idx];
  684. }
  685. info->op_type = I40IW_OP_TYPE_REC;
  686. if (qword3 & I40IWCQ_STAG_MASK) {
  687. info->stag_invalid_set = true;
  688. info->inv_stag = (u32)RS_64(qword2, I40IWCQ_INVSTAG);
  689. } else {
  690. info->stag_invalid_set = false;
  691. }
  692. info->bytes_xfered = (u32)RS_64(qword0, I40IWCQ_PAYLDLEN);
  693. I40IW_RING_SET_TAIL(qp->rq_ring, array_idx + 1);
  694. pring = &qp->rq_ring;
  695. } else {
  696. if (info->comp_status != I40IW_COMPL_STATUS_FLUSHED) {
  697. info->wr_id = qp->sq_wrtrk_array[wqe_idx].wrid;
  698. info->bytes_xfered = qp->sq_wrtrk_array[wqe_idx].wr_len;
  699. info->op_type = (u8)RS_64(qword3, I40IWCQ_OP);
  700. sw_wqe = qp->sq_base[wqe_idx].elem;
  701. get_64bit_val(sw_wqe, 24, &wqe_qword);
  702. addl_wqes = qp->sq_wrtrk_array[wqe_idx].wqe_size / I40IW_QP_WQE_MIN_SIZE;
  703. I40IW_RING_SET_TAIL(qp->sq_ring, (wqe_idx + addl_wqes));
  704. } else {
  705. do {
  706. u8 op_type;
  707. u32 tail;
  708. tail = qp->sq_ring.tail;
  709. sw_wqe = qp->sq_base[tail].elem;
  710. get_64bit_val(sw_wqe, 24, &wqe_qword);
  711. op_type = (u8)RS_64(wqe_qword, I40IWQPSQ_OPCODE);
  712. info->op_type = op_type;
  713. addl_wqes = qp->sq_wrtrk_array[tail].wqe_size / I40IW_QP_WQE_MIN_SIZE;
  714. I40IW_RING_SET_TAIL(qp->sq_ring, (tail + addl_wqes));
  715. if (op_type != I40IWQP_OP_NOP) {
  716. info->wr_id = qp->sq_wrtrk_array[tail].wrid;
  717. info->bytes_xfered = qp->sq_wrtrk_array[tail].wr_len;
  718. break;
  719. }
  720. } while (1);
  721. }
  722. pring = &qp->sq_ring;
  723. }
  724. ret_code = 0;
  725. exit:
  726. if (!ret_code &&
  727. (info->comp_status == I40IW_COMPL_STATUS_FLUSHED))
  728. if (pring && (I40IW_RING_MORE_WORK(*pring)))
  729. move_cq_head = false;
  730. if (move_cq_head) {
  731. I40IW_RING_MOVE_HEAD_NOCHECK(cq->cq_ring);
  732. if (I40IW_RING_GETCURRENT_HEAD(cq->cq_ring) == 0)
  733. cq->polarity ^= 1;
  734. I40IW_RING_MOVE_TAIL(cq->cq_ring);
  735. set_64bit_val(cq->shadow_area, 0,
  736. I40IW_RING_GETCURRENT_HEAD(cq->cq_ring));
  737. } else {
  738. if (info->is_srq)
  739. return ret_code;
  740. qword3 &= ~I40IW_CQ_WQEIDX_MASK;
  741. qword3 |= LS_64(pring->tail, I40IW_CQ_WQEIDX);
  742. set_64bit_val(cqe, 24, qword3);
  743. }
  744. return ret_code;
  745. }
  746. /**
  747. * i40iw_get_wqe_shift - get shift count for maximum wqe size
  748. * @wqdepth: depth of wq required.
  749. * @sge: Maximum Scatter Gather Elements wqe
  750. * @inline_data: Maximum inline data size
  751. * @shift: Returns the shift needed based on sge
  752. *
  753. * Shift can be used to left shift the wqe size based on number of SGEs and inlind data size.
  754. * For 1 SGE or inline data <= 16, shift = 0 (wqe size of 32 bytes).
  755. * For 2 or 3 SGEs or inline data <= 48, shift = 1 (wqe size of 64 bytes).
  756. * Shift of 2 otherwise (wqe size of 128 bytes).
  757. */
  758. enum i40iw_status_code i40iw_get_wqe_shift(u32 wqdepth, u32 sge, u32 inline_data, u8 *shift)
  759. {
  760. u32 size;
  761. *shift = 0;
  762. if (sge > 1 || inline_data > 16)
  763. *shift = (sge < 4 && inline_data <= 48) ? 1 : 2;
  764. /* check if wqdepth is multiple of 2 or not */
  765. if ((wqdepth < I40IWQP_SW_MIN_WQSIZE) || (wqdepth & (wqdepth - 1)))
  766. return I40IW_ERR_INVALID_SIZE;
  767. size = wqdepth << *shift; /* multiple of 32 bytes count */
  768. if (size > I40IWQP_SW_MAX_WQSIZE)
  769. return I40IW_ERR_INVALID_SIZE;
  770. return 0;
  771. }
  772. static const struct i40iw_qp_uk_ops iw_qp_uk_ops = {
  773. .iw_qp_post_wr = i40iw_qp_post_wr,
  774. .iw_qp_ring_push_db = i40iw_qp_ring_push_db,
  775. .iw_rdma_write = i40iw_rdma_write,
  776. .iw_rdma_read = i40iw_rdma_read,
  777. .iw_send = i40iw_send,
  778. .iw_inline_rdma_write = i40iw_inline_rdma_write,
  779. .iw_inline_send = i40iw_inline_send,
  780. .iw_stag_local_invalidate = i40iw_stag_local_invalidate,
  781. .iw_mw_bind = i40iw_mw_bind,
  782. .iw_post_receive = i40iw_post_receive,
  783. .iw_post_nop = i40iw_nop
  784. };
  785. static const struct i40iw_cq_ops iw_cq_ops = {
  786. .iw_cq_request_notification = i40iw_cq_request_notification,
  787. .iw_cq_poll_completion = i40iw_cq_poll_completion,
  788. .iw_cq_post_entries = i40iw_cq_post_entries,
  789. .iw_cq_clean = i40iw_clean_cq
  790. };
  791. static const struct i40iw_device_uk_ops iw_device_uk_ops = {
  792. .iwarp_cq_uk_init = i40iw_cq_uk_init,
  793. .iwarp_qp_uk_init = i40iw_qp_uk_init,
  794. };
  795. /**
  796. * i40iw_qp_uk_init - initialize shared qp
  797. * @qp: hw qp (user and kernel)
  798. * @info: qp initialization info
  799. *
  800. * initializes the vars used in both user and kernel mode.
  801. * size of the wqe depends on numbers of max. fragements
  802. * allowed. Then size of wqe * the number of wqes should be the
  803. * amount of memory allocated for sq and rq. If srq is used,
  804. * then rq_base will point to one rq wqe only (not the whole
  805. * array of wqes)
  806. */
  807. enum i40iw_status_code i40iw_qp_uk_init(struct i40iw_qp_uk *qp,
  808. struct i40iw_qp_uk_init_info *info)
  809. {
  810. enum i40iw_status_code ret_code = 0;
  811. u32 sq_ring_size;
  812. u8 sqshift, rqshift;
  813. if (info->max_sq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
  814. return I40IW_ERR_INVALID_FRAG_COUNT;
  815. if (info->max_rq_frag_cnt > I40IW_MAX_WQ_FRAGMENT_COUNT)
  816. return I40IW_ERR_INVALID_FRAG_COUNT;
  817. ret_code = i40iw_get_wqe_shift(info->sq_size, info->max_sq_frag_cnt, info->max_inline_data, &sqshift);
  818. if (ret_code)
  819. return ret_code;
  820. qp->sq_base = info->sq;
  821. qp->rq_base = info->rq;
  822. qp->shadow_area = info->shadow_area;
  823. qp->sq_wrtrk_array = info->sq_wrtrk_array;
  824. qp->rq_wrid_array = info->rq_wrid_array;
  825. qp->wqe_alloc_reg = info->wqe_alloc_reg;
  826. qp->qp_id = info->qp_id;
  827. qp->sq_size = info->sq_size;
  828. qp->push_db = info->push_db;
  829. qp->push_wqe = info->push_wqe;
  830. qp->max_sq_frag_cnt = info->max_sq_frag_cnt;
  831. sq_ring_size = qp->sq_size << sqshift;
  832. I40IW_RING_INIT(qp->sq_ring, sq_ring_size);
  833. I40IW_RING_INIT(qp->initial_ring, sq_ring_size);
  834. I40IW_RING_MOVE_HEAD(qp->sq_ring, ret_code);
  835. I40IW_RING_MOVE_TAIL(qp->sq_ring);
  836. I40IW_RING_MOVE_HEAD(qp->initial_ring, ret_code);
  837. qp->swqe_polarity = 1;
  838. qp->swqe_polarity_deferred = 1;
  839. qp->rwqe_polarity = 0;
  840. if (!qp->use_srq) {
  841. qp->rq_size = info->rq_size;
  842. qp->max_rq_frag_cnt = info->max_rq_frag_cnt;
  843. I40IW_RING_INIT(qp->rq_ring, qp->rq_size);
  844. switch (info->abi_ver) {
  845. case 4:
  846. ret_code = i40iw_get_wqe_shift(info->rq_size, info->max_rq_frag_cnt, 0, &rqshift);
  847. if (ret_code)
  848. return ret_code;
  849. break;
  850. case 5: /* fallthrough until next ABI version */
  851. default:
  852. rqshift = I40IW_MAX_RQ_WQE_SHIFT;
  853. break;
  854. }
  855. qp->rq_wqe_size = rqshift;
  856. qp->rq_wqe_size_multiplier = 4 << rqshift;
  857. }
  858. qp->ops = iw_qp_uk_ops;
  859. return ret_code;
  860. }
  861. /**
  862. * i40iw_cq_uk_init - initialize shared cq (user and kernel)
  863. * @cq: hw cq
  864. * @info: hw cq initialization info
  865. */
  866. enum i40iw_status_code i40iw_cq_uk_init(struct i40iw_cq_uk *cq,
  867. struct i40iw_cq_uk_init_info *info)
  868. {
  869. if ((info->cq_size < I40IW_MIN_CQ_SIZE) ||
  870. (info->cq_size > I40IW_MAX_CQ_SIZE))
  871. return I40IW_ERR_INVALID_SIZE;
  872. cq->cq_base = (struct i40iw_cqe *)info->cq_base;
  873. cq->cq_id = info->cq_id;
  874. cq->cq_size = info->cq_size;
  875. cq->cqe_alloc_reg = info->cqe_alloc_reg;
  876. cq->shadow_area = info->shadow_area;
  877. cq->avoid_mem_cflct = info->avoid_mem_cflct;
  878. I40IW_RING_INIT(cq->cq_ring, cq->cq_size);
  879. cq->polarity = 1;
  880. cq->ops = iw_cq_ops;
  881. return 0;
  882. }
  883. /**
  884. * i40iw_device_init_uk - setup routines for iwarp shared device
  885. * @dev: iwarp shared (user and kernel)
  886. */
  887. void i40iw_device_init_uk(struct i40iw_dev_uk *dev)
  888. {
  889. dev->ops_uk = iw_device_uk_ops;
  890. }
  891. /**
  892. * i40iw_clean_cq - clean cq entries
  893. * @ queue completion context
  894. * @cq: cq to clean
  895. */
  896. void i40iw_clean_cq(void *queue, struct i40iw_cq_uk *cq)
  897. {
  898. u64 *cqe;
  899. u64 qword3, comp_ctx;
  900. u32 cq_head;
  901. u8 polarity, temp;
  902. cq_head = cq->cq_ring.head;
  903. temp = cq->polarity;
  904. do {
  905. if (cq->avoid_mem_cflct)
  906. cqe = (u64 *)&(((struct i40iw_extended_cqe *)cq->cq_base)[cq_head]);
  907. else
  908. cqe = (u64 *)&cq->cq_base[cq_head];
  909. get_64bit_val(cqe, 24, &qword3);
  910. polarity = (u8)RS_64(qword3, I40IW_CQ_VALID);
  911. if (polarity != temp)
  912. break;
  913. get_64bit_val(cqe, 8, &comp_ctx);
  914. if ((void *)(unsigned long)comp_ctx == queue)
  915. set_64bit_val(cqe, 8, 0);
  916. cq_head = (cq_head + 1) % cq->cq_ring.size;
  917. if (!cq_head)
  918. temp ^= 1;
  919. } while (true);
  920. }
  921. /**
  922. * i40iw_nop - send a nop
  923. * @qp: hw qp ptr
  924. * @wr_id: work request id
  925. * @signaled: flag if signaled for completion
  926. * @post_sq: flag to post sq
  927. */
  928. enum i40iw_status_code i40iw_nop(struct i40iw_qp_uk *qp,
  929. u64 wr_id,
  930. bool signaled,
  931. bool post_sq)
  932. {
  933. u64 header, *wqe;
  934. u32 wqe_idx;
  935. wqe = i40iw_qp_get_next_send_wqe(qp, &wqe_idx, I40IW_QP_WQE_MIN_SIZE, 0, wr_id);
  936. if (!wqe)
  937. return I40IW_ERR_QP_TOOMANY_WRS_POSTED;
  938. set_64bit_val(wqe, 0, 0);
  939. set_64bit_val(wqe, 8, 0);
  940. set_64bit_val(wqe, 16, 0);
  941. header = LS_64(I40IWQP_OP_NOP, I40IWQPSQ_OPCODE) |
  942. LS_64(signaled, I40IWQPSQ_SIGCOMPL) |
  943. LS_64(qp->swqe_polarity, I40IWQPSQ_VALID);
  944. wmb(); /* make sure WQE is populated before valid bit is set */
  945. set_64bit_val(wqe, 24, header);
  946. if (post_sq)
  947. i40iw_qp_post_wr(qp);
  948. return 0;
  949. }
  950. /**
  951. * i40iw_fragcnt_to_wqesize_sq - calculate wqe size based on fragment count for SQ
  952. * @frag_cnt: number of fragments
  953. * @wqe_size: size of sq wqe returned
  954. */
  955. enum i40iw_status_code i40iw_fragcnt_to_wqesize_sq(u32 frag_cnt, u8 *wqe_size)
  956. {
  957. switch (frag_cnt) {
  958. case 0:
  959. case 1:
  960. *wqe_size = I40IW_QP_WQE_MIN_SIZE;
  961. break;
  962. case 2:
  963. case 3:
  964. *wqe_size = 64;
  965. break;
  966. case 4:
  967. case 5:
  968. *wqe_size = 96;
  969. break;
  970. case 6:
  971. case 7:
  972. *wqe_size = 128;
  973. break;
  974. default:
  975. return I40IW_ERR_INVALID_FRAG_COUNT;
  976. }
  977. return 0;
  978. }
  979. /**
  980. * i40iw_fragcnt_to_wqesize_rq - calculate wqe size based on fragment count for RQ
  981. * @frag_cnt: number of fragments
  982. * @wqe_size: size of rq wqe returned
  983. */
  984. enum i40iw_status_code i40iw_fragcnt_to_wqesize_rq(u32 frag_cnt, u8 *wqe_size)
  985. {
  986. switch (frag_cnt) {
  987. case 0:
  988. case 1:
  989. *wqe_size = 32;
  990. break;
  991. case 2:
  992. case 3:
  993. *wqe_size = 64;
  994. break;
  995. case 4:
  996. case 5:
  997. case 6:
  998. case 7:
  999. *wqe_size = 128;
  1000. break;
  1001. default:
  1002. return I40IW_ERR_INVALID_FRAG_COUNT;
  1003. }
  1004. return 0;
  1005. }
  1006. /**
  1007. * i40iw_inline_data_size_to_wqesize - based on inline data, wqe size
  1008. * @data_size: data size for inline
  1009. * @wqe_size: size of sq wqe returned
  1010. */
  1011. enum i40iw_status_code i40iw_inline_data_size_to_wqesize(u32 data_size,
  1012. u8 *wqe_size)
  1013. {
  1014. if (data_size > I40IW_MAX_INLINE_DATA_SIZE)
  1015. return I40IW_ERR_INVALID_INLINE_DATA_SIZE;
  1016. if (data_size <= 16)
  1017. *wqe_size = I40IW_QP_WQE_MIN_SIZE;
  1018. else
  1019. *wqe_size = 64;
  1020. return 0;
  1021. }