qedr_cm.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /* QLogic qedr NIC Driver
  2. * Copyright (c) 2015-2016 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/dma-mapping.h>
  33. #include <linux/crc32.h>
  34. #include <linux/iommu.h>
  35. #include <net/ip.h>
  36. #include <net/ipv6.h>
  37. #include <net/udp.h>
  38. #include <rdma/ib_verbs.h>
  39. #include <rdma/ib_user_verbs.h>
  40. #include <rdma/iw_cm.h>
  41. #include <rdma/ib_umem.h>
  42. #include <rdma/ib_addr.h>
  43. #include <rdma/ib_cache.h>
  44. #include <linux/qed/qed_if.h>
  45. #include <linux/qed/qed_roce_if.h>
  46. #include "qedr.h"
  47. #include "verbs.h"
  48. #include <rdma/qedr-abi.h>
  49. #include "qedr_cm.h"
  50. void qedr_inc_sw_gsi_cons(struct qedr_qp_hwq_info *info)
  51. {
  52. info->gsi_cons = (info->gsi_cons + 1) % info->max_wr;
  53. }
  54. void qedr_store_gsi_qp_cq(struct qedr_dev *dev, struct qedr_qp *qp,
  55. struct ib_qp_init_attr *attrs)
  56. {
  57. dev->gsi_qp_created = 1;
  58. dev->gsi_sqcq = get_qedr_cq(attrs->send_cq);
  59. dev->gsi_rqcq = get_qedr_cq(attrs->recv_cq);
  60. dev->gsi_qp = qp;
  61. }
  62. void qedr_ll2_tx_cb(void *_qdev, struct qed_roce_ll2_packet *pkt)
  63. {
  64. struct qedr_dev *dev = (struct qedr_dev *)_qdev;
  65. struct qedr_cq *cq = dev->gsi_sqcq;
  66. struct qedr_qp *qp = dev->gsi_qp;
  67. unsigned long flags;
  68. DP_DEBUG(dev, QEDR_MSG_GSI,
  69. "LL2 TX CB: gsi_sqcq=%p, gsi_rqcq=%p, gsi_cons=%d, ibcq_comp=%s\n",
  70. dev->gsi_sqcq, dev->gsi_rqcq, qp->sq.gsi_cons,
  71. cq->ibcq.comp_handler ? "Yes" : "No");
  72. dma_free_coherent(&dev->pdev->dev, pkt->header.len, pkt->header.vaddr,
  73. pkt->header.baddr);
  74. kfree(pkt);
  75. spin_lock_irqsave(&qp->q_lock, flags);
  76. qedr_inc_sw_gsi_cons(&qp->sq);
  77. spin_unlock_irqrestore(&qp->q_lock, flags);
  78. if (cq->ibcq.comp_handler)
  79. (*cq->ibcq.comp_handler) (&cq->ibcq, cq->ibcq.cq_context);
  80. }
  81. void qedr_ll2_rx_cb(void *_dev, struct qed_roce_ll2_packet *pkt,
  82. struct qed_roce_ll2_rx_params *params)
  83. {
  84. struct qedr_dev *dev = (struct qedr_dev *)_dev;
  85. struct qedr_cq *cq = dev->gsi_rqcq;
  86. struct qedr_qp *qp = dev->gsi_qp;
  87. unsigned long flags;
  88. spin_lock_irqsave(&qp->q_lock, flags);
  89. qp->rqe_wr_id[qp->rq.gsi_cons].rc = params->rc;
  90. qp->rqe_wr_id[qp->rq.gsi_cons].vlan_id = params->vlan_id;
  91. qp->rqe_wr_id[qp->rq.gsi_cons].sg_list[0].length = pkt->payload[0].len;
  92. ether_addr_copy(qp->rqe_wr_id[qp->rq.gsi_cons].smac, params->smac);
  93. qedr_inc_sw_gsi_cons(&qp->rq);
  94. spin_unlock_irqrestore(&qp->q_lock, flags);
  95. if (cq->ibcq.comp_handler)
  96. (*cq->ibcq.comp_handler) (&cq->ibcq, cq->ibcq.cq_context);
  97. }
  98. static void qedr_destroy_gsi_cq(struct qedr_dev *dev,
  99. struct ib_qp_init_attr *attrs)
  100. {
  101. struct qed_rdma_destroy_cq_in_params iparams;
  102. struct qed_rdma_destroy_cq_out_params oparams;
  103. struct qedr_cq *cq;
  104. cq = get_qedr_cq(attrs->send_cq);
  105. iparams.icid = cq->icid;
  106. dev->ops->rdma_destroy_cq(dev->rdma_ctx, &iparams, &oparams);
  107. dev->ops->common->chain_free(dev->cdev, &cq->pbl);
  108. cq = get_qedr_cq(attrs->recv_cq);
  109. /* if a dedicated recv_cq was used, delete it too */
  110. if (iparams.icid != cq->icid) {
  111. iparams.icid = cq->icid;
  112. dev->ops->rdma_destroy_cq(dev->rdma_ctx, &iparams, &oparams);
  113. dev->ops->common->chain_free(dev->cdev, &cq->pbl);
  114. }
  115. }
  116. static inline int qedr_check_gsi_qp_attrs(struct qedr_dev *dev,
  117. struct ib_qp_init_attr *attrs)
  118. {
  119. if (attrs->cap.max_recv_sge > QEDR_GSI_MAX_RECV_SGE) {
  120. DP_ERR(dev,
  121. " create gsi qp: failed. max_recv_sge is larger the max %d>%d\n",
  122. attrs->cap.max_recv_sge, QEDR_GSI_MAX_RECV_SGE);
  123. return -EINVAL;
  124. }
  125. if (attrs->cap.max_recv_wr > QEDR_GSI_MAX_RECV_WR) {
  126. DP_ERR(dev,
  127. " create gsi qp: failed. max_recv_wr is too large %d>%d\n",
  128. attrs->cap.max_recv_wr, QEDR_GSI_MAX_RECV_WR);
  129. return -EINVAL;
  130. }
  131. if (attrs->cap.max_send_wr > QEDR_GSI_MAX_SEND_WR) {
  132. DP_ERR(dev,
  133. " create gsi qp: failed. max_send_wr is too large %d>%d\n",
  134. attrs->cap.max_send_wr, QEDR_GSI_MAX_SEND_WR);
  135. return -EINVAL;
  136. }
  137. return 0;
  138. }
  139. struct ib_qp *qedr_create_gsi_qp(struct qedr_dev *dev,
  140. struct ib_qp_init_attr *attrs,
  141. struct qedr_qp *qp)
  142. {
  143. struct qed_roce_ll2_params ll2_params;
  144. int rc;
  145. rc = qedr_check_gsi_qp_attrs(dev, attrs);
  146. if (rc)
  147. return ERR_PTR(rc);
  148. /* configure and start LL2 */
  149. memset(&ll2_params, 0, sizeof(ll2_params));
  150. ll2_params.max_tx_buffers = attrs->cap.max_send_wr;
  151. ll2_params.max_rx_buffers = attrs->cap.max_recv_wr;
  152. ll2_params.cbs.tx_cb = qedr_ll2_tx_cb;
  153. ll2_params.cbs.rx_cb = qedr_ll2_rx_cb;
  154. ll2_params.cb_cookie = (void *)dev;
  155. ll2_params.mtu = dev->ndev->mtu;
  156. ether_addr_copy(ll2_params.mac_address, dev->ndev->dev_addr);
  157. rc = dev->ops->roce_ll2_start(dev->cdev, &ll2_params);
  158. if (rc) {
  159. DP_ERR(dev, "create gsi qp: failed on ll2 start. rc=%d\n", rc);
  160. return ERR_PTR(rc);
  161. }
  162. /* create QP */
  163. qp->ibqp.qp_num = 1;
  164. qp->rq.max_wr = attrs->cap.max_recv_wr;
  165. qp->sq.max_wr = attrs->cap.max_send_wr;
  166. qp->rqe_wr_id = kcalloc(qp->rq.max_wr, sizeof(*qp->rqe_wr_id),
  167. GFP_KERNEL);
  168. if (!qp->rqe_wr_id)
  169. goto err;
  170. qp->wqe_wr_id = kcalloc(qp->sq.max_wr, sizeof(*qp->wqe_wr_id),
  171. GFP_KERNEL);
  172. if (!qp->wqe_wr_id)
  173. goto err;
  174. qedr_store_gsi_qp_cq(dev, qp, attrs);
  175. ether_addr_copy(dev->gsi_ll2_mac_address, dev->ndev->dev_addr);
  176. /* the GSI CQ is handled by the driver so remove it from the FW */
  177. qedr_destroy_gsi_cq(dev, attrs);
  178. dev->gsi_rqcq->cq_type = QEDR_CQ_TYPE_GSI;
  179. dev->gsi_rqcq->cq_type = QEDR_CQ_TYPE_GSI;
  180. DP_DEBUG(dev, QEDR_MSG_GSI, "created GSI QP %p\n", qp);
  181. return &qp->ibqp;
  182. err:
  183. kfree(qp->rqe_wr_id);
  184. rc = dev->ops->roce_ll2_stop(dev->cdev);
  185. if (rc)
  186. DP_ERR(dev, "create gsi qp: failed destroy on create\n");
  187. return ERR_PTR(-ENOMEM);
  188. }
  189. int qedr_destroy_gsi_qp(struct qedr_dev *dev)
  190. {
  191. int rc;
  192. rc = dev->ops->roce_ll2_stop(dev->cdev);
  193. if (rc)
  194. DP_ERR(dev, "destroy gsi qp: failed (rc=%d)\n", rc);
  195. else
  196. DP_DEBUG(dev, QEDR_MSG_GSI, "destroy gsi qp: success\n");
  197. return rc;
  198. }
  199. #define QEDR_MAX_UD_HEADER_SIZE (100)
  200. #define QEDR_GSI_QPN (1)
  201. static inline int qedr_gsi_build_header(struct qedr_dev *dev,
  202. struct qedr_qp *qp,
  203. struct ib_send_wr *swr,
  204. struct ib_ud_header *udh,
  205. int *roce_mode)
  206. {
  207. bool has_vlan = false, has_grh_ipv6 = true;
  208. struct rdma_ah_attr *ah_attr = &get_qedr_ah(ud_wr(swr)->ah)->attr;
  209. const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
  210. union ib_gid sgid;
  211. int send_size = 0;
  212. u16 vlan_id = 0;
  213. u16 ether_type;
  214. struct ib_gid_attr sgid_attr;
  215. int rc;
  216. int ip_ver = 0;
  217. bool has_udp = false;
  218. int i;
  219. send_size = 0;
  220. for (i = 0; i < swr->num_sge; ++i)
  221. send_size += swr->sg_list[i].length;
  222. rc = ib_get_cached_gid(qp->ibqp.device, rdma_ah_get_port_num(ah_attr),
  223. grh->sgid_index, &sgid, &sgid_attr);
  224. if (rc) {
  225. DP_ERR(dev,
  226. "gsi post send: failed to get cached GID (port=%d, ix=%d)\n",
  227. rdma_ah_get_port_num(ah_attr),
  228. grh->sgid_index);
  229. return rc;
  230. }
  231. if (sgid_attr.ndev) {
  232. vlan_id = rdma_vlan_dev_vlan_id(sgid_attr.ndev);
  233. if (vlan_id < VLAN_CFI_MASK)
  234. has_vlan = true;
  235. dev_put(sgid_attr.ndev);
  236. }
  237. if (!memcmp(&sgid, &zgid, sizeof(sgid))) {
  238. DP_ERR(dev, "gsi post send: GID not found GID index %d\n",
  239. grh->sgid_index);
  240. return -ENOENT;
  241. }
  242. has_udp = (sgid_attr.gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP);
  243. if (!has_udp) {
  244. /* RoCE v1 */
  245. ether_type = ETH_P_IBOE;
  246. *roce_mode = ROCE_V1;
  247. } else if (ipv6_addr_v4mapped((struct in6_addr *)&sgid)) {
  248. /* RoCE v2 IPv4 */
  249. ip_ver = 4;
  250. ether_type = ETH_P_IP;
  251. has_grh_ipv6 = false;
  252. *roce_mode = ROCE_V2_IPV4;
  253. } else {
  254. /* RoCE v2 IPv6 */
  255. ip_ver = 6;
  256. ether_type = ETH_P_IPV6;
  257. *roce_mode = ROCE_V2_IPV6;
  258. }
  259. rc = ib_ud_header_init(send_size, false, true, has_vlan,
  260. has_grh_ipv6, ip_ver, has_udp, 0, udh);
  261. if (rc) {
  262. DP_ERR(dev, "gsi post send: failed to init header\n");
  263. return rc;
  264. }
  265. /* ENET + VLAN headers */
  266. ether_addr_copy(udh->eth.dmac_h, ah_attr->roce.dmac);
  267. ether_addr_copy(udh->eth.smac_h, dev->ndev->dev_addr);
  268. if (has_vlan) {
  269. udh->eth.type = htons(ETH_P_8021Q);
  270. udh->vlan.tag = htons(vlan_id);
  271. udh->vlan.type = htons(ether_type);
  272. } else {
  273. udh->eth.type = htons(ether_type);
  274. }
  275. /* BTH */
  276. udh->bth.solicited_event = !!(swr->send_flags & IB_SEND_SOLICITED);
  277. udh->bth.pkey = QEDR_ROCE_PKEY_DEFAULT;
  278. udh->bth.destination_qpn = htonl(ud_wr(swr)->remote_qpn);
  279. udh->bth.psn = htonl((qp->sq_psn++) & ((1 << 24) - 1));
  280. udh->bth.opcode = IB_OPCODE_UD_SEND_ONLY;
  281. /* DETH */
  282. udh->deth.qkey = htonl(0x80010000);
  283. udh->deth.source_qpn = htonl(QEDR_GSI_QPN);
  284. if (has_grh_ipv6) {
  285. /* GRH / IPv6 header */
  286. udh->grh.traffic_class = grh->traffic_class;
  287. udh->grh.flow_label = grh->flow_label;
  288. udh->grh.hop_limit = grh->hop_limit;
  289. udh->grh.destination_gid = grh->dgid;
  290. memcpy(&udh->grh.source_gid.raw, &sgid.raw,
  291. sizeof(udh->grh.source_gid.raw));
  292. } else {
  293. /* IPv4 header */
  294. u32 ipv4_addr;
  295. udh->ip4.protocol = IPPROTO_UDP;
  296. udh->ip4.tos = htonl(grh->flow_label);
  297. udh->ip4.frag_off = htons(IP_DF);
  298. udh->ip4.ttl = grh->hop_limit;
  299. ipv4_addr = qedr_get_ipv4_from_gid(sgid.raw);
  300. udh->ip4.saddr = ipv4_addr;
  301. ipv4_addr = qedr_get_ipv4_from_gid(grh->dgid.raw);
  302. udh->ip4.daddr = ipv4_addr;
  303. /* note: checksum is calculated by the device */
  304. }
  305. /* UDP */
  306. if (has_udp) {
  307. udh->udp.sport = htons(QEDR_ROCE_V2_UDP_SPORT);
  308. udh->udp.dport = htons(ROCE_V2_UDP_DPORT);
  309. udh->udp.csum = 0;
  310. /* UDP length is untouched hence is zero */
  311. }
  312. return 0;
  313. }
  314. static inline int qedr_gsi_build_packet(struct qedr_dev *dev,
  315. struct qedr_qp *qp,
  316. struct ib_send_wr *swr,
  317. struct qed_roce_ll2_packet **p_packet)
  318. {
  319. u8 ud_header_buffer[QEDR_MAX_UD_HEADER_SIZE];
  320. struct qed_roce_ll2_packet *packet;
  321. struct pci_dev *pdev = dev->pdev;
  322. int roce_mode, header_size;
  323. struct ib_ud_header udh;
  324. int i, rc;
  325. *p_packet = NULL;
  326. rc = qedr_gsi_build_header(dev, qp, swr, &udh, &roce_mode);
  327. if (rc)
  328. return rc;
  329. header_size = ib_ud_header_pack(&udh, &ud_header_buffer);
  330. packet = kzalloc(sizeof(*packet), GFP_ATOMIC);
  331. if (!packet)
  332. return -ENOMEM;
  333. packet->header.vaddr = dma_alloc_coherent(&pdev->dev, header_size,
  334. &packet->header.baddr,
  335. GFP_ATOMIC);
  336. if (!packet->header.vaddr) {
  337. kfree(packet);
  338. return -ENOMEM;
  339. }
  340. if (ether_addr_equal(udh.eth.smac_h, udh.eth.dmac_h))
  341. packet->tx_dest = QED_ROCE_LL2_TX_DEST_LB;
  342. else
  343. packet->tx_dest = QED_ROCE_LL2_TX_DEST_NW;
  344. packet->roce_mode = roce_mode;
  345. memcpy(packet->header.vaddr, ud_header_buffer, header_size);
  346. packet->header.len = header_size;
  347. packet->n_seg = swr->num_sge;
  348. for (i = 0; i < packet->n_seg; i++) {
  349. packet->payload[i].baddr = swr->sg_list[i].addr;
  350. packet->payload[i].len = swr->sg_list[i].length;
  351. }
  352. *p_packet = packet;
  353. return 0;
  354. }
  355. int qedr_gsi_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
  356. struct ib_send_wr **bad_wr)
  357. {
  358. struct qed_roce_ll2_packet *pkt = NULL;
  359. struct qedr_qp *qp = get_qedr_qp(ibqp);
  360. struct qed_roce_ll2_tx_params params;
  361. struct qedr_dev *dev = qp->dev;
  362. unsigned long flags;
  363. int rc;
  364. if (qp->state != QED_ROCE_QP_STATE_RTS) {
  365. *bad_wr = wr;
  366. DP_ERR(dev,
  367. "gsi post recv: failed to post rx buffer. state is %d and not QED_ROCE_QP_STATE_RTS\n",
  368. qp->state);
  369. return -EINVAL;
  370. }
  371. if (wr->num_sge > RDMA_MAX_SGE_PER_SQ_WQE) {
  372. DP_ERR(dev, "gsi post send: num_sge is too large (%d>%d)\n",
  373. wr->num_sge, RDMA_MAX_SGE_PER_SQ_WQE);
  374. rc = -EINVAL;
  375. goto err;
  376. }
  377. if (wr->opcode != IB_WR_SEND) {
  378. DP_ERR(dev,
  379. "gsi post send: failed due to unsupported opcode %d\n",
  380. wr->opcode);
  381. rc = -EINVAL;
  382. goto err;
  383. }
  384. memset(&params, 0, sizeof(params));
  385. spin_lock_irqsave(&qp->q_lock, flags);
  386. rc = qedr_gsi_build_packet(dev, qp, wr, &pkt);
  387. if (rc) {
  388. spin_unlock_irqrestore(&qp->q_lock, flags);
  389. goto err;
  390. }
  391. rc = dev->ops->roce_ll2_tx(dev->cdev, pkt, &params);
  392. if (!rc) {
  393. qp->wqe_wr_id[qp->sq.prod].wr_id = wr->wr_id;
  394. qedr_inc_sw_prod(&qp->sq);
  395. DP_DEBUG(qp->dev, QEDR_MSG_GSI,
  396. "gsi post send: opcode=%d, in_irq=%ld, irqs_disabled=%d, wr_id=%llx\n",
  397. wr->opcode, in_irq(), irqs_disabled(), wr->wr_id);
  398. } else {
  399. if (rc == QED_ROCE_TX_HEAD_FAILURE) {
  400. /* TX failed while posting header - release resources */
  401. dma_free_coherent(&dev->pdev->dev, pkt->header.len,
  402. pkt->header.vaddr, pkt->header.baddr);
  403. kfree(pkt);
  404. } else if (rc == QED_ROCE_TX_FRAG_FAILURE) {
  405. /* NTD since TX failed while posting a fragment. We will
  406. * release the resources on TX callback
  407. */
  408. }
  409. DP_ERR(dev, "gsi post send: failed to transmit (rc=%d)\n", rc);
  410. rc = -EAGAIN;
  411. *bad_wr = wr;
  412. }
  413. spin_unlock_irqrestore(&qp->q_lock, flags);
  414. if (wr->next) {
  415. DP_ERR(dev,
  416. "gsi post send: failed second WR. Only one WR may be passed at a time\n");
  417. *bad_wr = wr->next;
  418. rc = -EINVAL;
  419. }
  420. return rc;
  421. err:
  422. *bad_wr = wr;
  423. return rc;
  424. }
  425. int qedr_gsi_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
  426. struct ib_recv_wr **bad_wr)
  427. {
  428. struct qedr_dev *dev = get_qedr_dev(ibqp->device);
  429. struct qedr_qp *qp = get_qedr_qp(ibqp);
  430. struct qed_roce_ll2_buffer buf;
  431. unsigned long flags;
  432. int status = 0;
  433. int rc;
  434. if ((qp->state != QED_ROCE_QP_STATE_RTR) &&
  435. (qp->state != QED_ROCE_QP_STATE_RTS)) {
  436. *bad_wr = wr;
  437. DP_ERR(dev,
  438. "gsi post recv: failed to post rx buffer. state is %d and not QED_ROCE_QP_STATE_RTR/S\n",
  439. qp->state);
  440. return -EINVAL;
  441. }
  442. memset(&buf, 0, sizeof(buf));
  443. spin_lock_irqsave(&qp->q_lock, flags);
  444. while (wr) {
  445. if (wr->num_sge > QEDR_GSI_MAX_RECV_SGE) {
  446. DP_ERR(dev,
  447. "gsi post recv: failed to post rx buffer. too many sges %d>%d\n",
  448. wr->num_sge, QEDR_GSI_MAX_RECV_SGE);
  449. goto err;
  450. }
  451. buf.baddr = wr->sg_list[0].addr;
  452. buf.len = wr->sg_list[0].length;
  453. rc = dev->ops->roce_ll2_post_rx_buffer(dev->cdev, &buf, 0, 1);
  454. if (rc) {
  455. DP_ERR(dev,
  456. "gsi post recv: failed to post rx buffer (rc=%d)\n",
  457. rc);
  458. goto err;
  459. }
  460. memset(&qp->rqe_wr_id[qp->rq.prod], 0,
  461. sizeof(qp->rqe_wr_id[qp->rq.prod]));
  462. qp->rqe_wr_id[qp->rq.prod].sg_list[0] = wr->sg_list[0];
  463. qp->rqe_wr_id[qp->rq.prod].wr_id = wr->wr_id;
  464. qedr_inc_sw_prod(&qp->rq);
  465. wr = wr->next;
  466. }
  467. spin_unlock_irqrestore(&qp->q_lock, flags);
  468. return status;
  469. err:
  470. spin_unlock_irqrestore(&qp->q_lock, flags);
  471. *bad_wr = wr;
  472. return -ENOMEM;
  473. }
  474. int qedr_gsi_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
  475. {
  476. struct qedr_dev *dev = get_qedr_dev(ibcq->device);
  477. struct qedr_cq *cq = get_qedr_cq(ibcq);
  478. struct qedr_qp *qp = dev->gsi_qp;
  479. unsigned long flags;
  480. int i = 0;
  481. spin_lock_irqsave(&cq->cq_lock, flags);
  482. while (i < num_entries && qp->rq.cons != qp->rq.gsi_cons) {
  483. memset(&wc[i], 0, sizeof(*wc));
  484. wc[i].qp = &qp->ibqp;
  485. wc[i].wr_id = qp->rqe_wr_id[qp->rq.cons].wr_id;
  486. wc[i].opcode = IB_WC_RECV;
  487. wc[i].pkey_index = 0;
  488. wc[i].status = (qp->rqe_wr_id[qp->rq.cons].rc) ?
  489. IB_WC_GENERAL_ERR : IB_WC_SUCCESS;
  490. /* 0 - currently only one recv sg is supported */
  491. wc[i].byte_len = qp->rqe_wr_id[qp->rq.cons].sg_list[0].length;
  492. wc[i].wc_flags |= IB_WC_GRH | IB_WC_IP_CSUM_OK;
  493. ether_addr_copy(wc[i].smac, qp->rqe_wr_id[qp->rq.cons].smac);
  494. wc[i].wc_flags |= IB_WC_WITH_SMAC;
  495. if (qp->rqe_wr_id[qp->rq.cons].vlan_id) {
  496. wc[i].wc_flags |= IB_WC_WITH_VLAN;
  497. wc[i].vlan_id = qp->rqe_wr_id[qp->rq.cons].vlan_id;
  498. }
  499. qedr_inc_sw_cons(&qp->rq);
  500. i++;
  501. }
  502. while (i < num_entries && qp->sq.cons != qp->sq.gsi_cons) {
  503. memset(&wc[i], 0, sizeof(*wc));
  504. wc[i].qp = &qp->ibqp;
  505. wc[i].wr_id = qp->wqe_wr_id[qp->sq.cons].wr_id;
  506. wc[i].opcode = IB_WC_SEND;
  507. wc[i].status = IB_WC_SUCCESS;
  508. qedr_inc_sw_cons(&qp->sq);
  509. i++;
  510. }
  511. spin_unlock_irqrestore(&cq->cq_lock, flags);
  512. DP_DEBUG(dev, QEDR_MSG_GSI,
  513. "gsi poll_cq: requested entries=%d, actual=%d, qp->rq.cons=%d, qp->rq.gsi_cons=%x, qp->sq.cons=%d, qp->sq.gsi_cons=%d, qp_num=%d\n",
  514. num_entries, i, qp->rq.cons, qp->rq.gsi_cons, qp->sq.cons,
  515. qp->sq.gsi_cons, qp->ibqp.qp_num);
  516. return i;
  517. }