rxe_qp.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*
  2. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2015 System Fabric Works, Inc. 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. * OpenIB.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. #include <linux/skbuff.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include "rxe.h"
  37. #include "rxe_loc.h"
  38. #include "rxe_queue.h"
  39. #include "rxe_task.h"
  40. char *rxe_qp_state_name[] = {
  41. [QP_STATE_RESET] = "RESET",
  42. [QP_STATE_INIT] = "INIT",
  43. [QP_STATE_READY] = "READY",
  44. [QP_STATE_DRAIN] = "DRAIN",
  45. [QP_STATE_DRAINED] = "DRAINED",
  46. [QP_STATE_ERROR] = "ERROR",
  47. };
  48. static int rxe_qp_chk_cap(struct rxe_dev *rxe, struct ib_qp_cap *cap,
  49. int has_srq)
  50. {
  51. if (cap->max_send_wr > rxe->attr.max_qp_wr) {
  52. pr_warn("invalid send wr = %d > %d\n",
  53. cap->max_send_wr, rxe->attr.max_qp_wr);
  54. goto err1;
  55. }
  56. if (cap->max_send_sge > rxe->attr.max_sge) {
  57. pr_warn("invalid send sge = %d > %d\n",
  58. cap->max_send_sge, rxe->attr.max_sge);
  59. goto err1;
  60. }
  61. if (!has_srq) {
  62. if (cap->max_recv_wr > rxe->attr.max_qp_wr) {
  63. pr_warn("invalid recv wr = %d > %d\n",
  64. cap->max_recv_wr, rxe->attr.max_qp_wr);
  65. goto err1;
  66. }
  67. if (cap->max_recv_sge > rxe->attr.max_sge) {
  68. pr_warn("invalid recv sge = %d > %d\n",
  69. cap->max_recv_sge, rxe->attr.max_sge);
  70. goto err1;
  71. }
  72. }
  73. if (cap->max_inline_data > rxe->max_inline_data) {
  74. pr_warn("invalid max inline data = %d > %d\n",
  75. cap->max_inline_data, rxe->max_inline_data);
  76. goto err1;
  77. }
  78. return 0;
  79. err1:
  80. return -EINVAL;
  81. }
  82. int rxe_qp_chk_init(struct rxe_dev *rxe, struct ib_qp_init_attr *init)
  83. {
  84. struct ib_qp_cap *cap = &init->cap;
  85. struct rxe_port *port;
  86. int port_num = init->port_num;
  87. if (!init->recv_cq || !init->send_cq) {
  88. pr_warn("missing cq\n");
  89. goto err1;
  90. }
  91. if (rxe_qp_chk_cap(rxe, cap, !!init->srq))
  92. goto err1;
  93. if (init->qp_type == IB_QPT_SMI || init->qp_type == IB_QPT_GSI) {
  94. if (port_num != 1) {
  95. pr_warn("invalid port = %d\n", port_num);
  96. goto err1;
  97. }
  98. port = &rxe->port;
  99. if (init->qp_type == IB_QPT_SMI && port->qp_smi_index) {
  100. pr_warn("SMI QP exists for port %d\n", port_num);
  101. goto err1;
  102. }
  103. if (init->qp_type == IB_QPT_GSI && port->qp_gsi_index) {
  104. pr_warn("GSI QP exists for port %d\n", port_num);
  105. goto err1;
  106. }
  107. }
  108. return 0;
  109. err1:
  110. return -EINVAL;
  111. }
  112. static int alloc_rd_atomic_resources(struct rxe_qp *qp, unsigned int n)
  113. {
  114. qp->resp.res_head = 0;
  115. qp->resp.res_tail = 0;
  116. qp->resp.resources = kcalloc(n, sizeof(struct resp_res), GFP_KERNEL);
  117. if (!qp->resp.resources)
  118. return -ENOMEM;
  119. return 0;
  120. }
  121. static void free_rd_atomic_resources(struct rxe_qp *qp)
  122. {
  123. if (qp->resp.resources) {
  124. int i;
  125. for (i = 0; i < qp->attr.max_dest_rd_atomic; i++) {
  126. struct resp_res *res = &qp->resp.resources[i];
  127. free_rd_atomic_resource(qp, res);
  128. }
  129. kfree(qp->resp.resources);
  130. qp->resp.resources = NULL;
  131. }
  132. }
  133. void free_rd_atomic_resource(struct rxe_qp *qp, struct resp_res *res)
  134. {
  135. if (res->type == RXE_ATOMIC_MASK) {
  136. rxe_drop_ref(qp);
  137. kfree_skb(res->atomic.skb);
  138. } else if (res->type == RXE_READ_MASK) {
  139. if (res->read.mr)
  140. rxe_drop_ref(res->read.mr);
  141. }
  142. res->type = 0;
  143. }
  144. static void cleanup_rd_atomic_resources(struct rxe_qp *qp)
  145. {
  146. int i;
  147. struct resp_res *res;
  148. if (qp->resp.resources) {
  149. for (i = 0; i < qp->attr.max_dest_rd_atomic; i++) {
  150. res = &qp->resp.resources[i];
  151. free_rd_atomic_resource(qp, res);
  152. }
  153. }
  154. }
  155. static void rxe_qp_init_misc(struct rxe_dev *rxe, struct rxe_qp *qp,
  156. struct ib_qp_init_attr *init)
  157. {
  158. struct rxe_port *port;
  159. u32 qpn;
  160. qp->sq_sig_type = init->sq_sig_type;
  161. qp->attr.path_mtu = 1;
  162. qp->mtu = ib_mtu_enum_to_int(qp->attr.path_mtu);
  163. qpn = qp->pelem.index;
  164. port = &rxe->port;
  165. switch (init->qp_type) {
  166. case IB_QPT_SMI:
  167. qp->ibqp.qp_num = 0;
  168. port->qp_smi_index = qpn;
  169. qp->attr.port_num = init->port_num;
  170. break;
  171. case IB_QPT_GSI:
  172. qp->ibqp.qp_num = 1;
  173. port->qp_gsi_index = qpn;
  174. qp->attr.port_num = init->port_num;
  175. break;
  176. default:
  177. qp->ibqp.qp_num = qpn;
  178. break;
  179. }
  180. INIT_LIST_HEAD(&qp->grp_list);
  181. skb_queue_head_init(&qp->send_pkts);
  182. spin_lock_init(&qp->grp_lock);
  183. spin_lock_init(&qp->state_lock);
  184. atomic_set(&qp->ssn, 0);
  185. atomic_set(&qp->skb_out, 0);
  186. }
  187. static int rxe_qp_init_req(struct rxe_dev *rxe, struct rxe_qp *qp,
  188. struct ib_qp_init_attr *init,
  189. struct ib_ucontext *context, struct ib_udata *udata)
  190. {
  191. int err;
  192. int wqe_size;
  193. err = sock_create_kern(&init_net, AF_INET, SOCK_DGRAM, 0, &qp->sk);
  194. if (err < 0)
  195. return err;
  196. qp->sk->sk->sk_user_data = qp;
  197. qp->sq.max_wr = init->cap.max_send_wr;
  198. qp->sq.max_sge = init->cap.max_send_sge;
  199. qp->sq.max_inline = init->cap.max_inline_data;
  200. wqe_size = max_t(int, sizeof(struct rxe_send_wqe) +
  201. qp->sq.max_sge * sizeof(struct ib_sge),
  202. sizeof(struct rxe_send_wqe) +
  203. qp->sq.max_inline);
  204. qp->sq.queue = rxe_queue_init(rxe,
  205. &qp->sq.max_wr,
  206. wqe_size);
  207. if (!qp->sq.queue)
  208. return -ENOMEM;
  209. err = do_mmap_info(rxe, udata, true,
  210. context, qp->sq.queue->buf,
  211. qp->sq.queue->buf_size, &qp->sq.queue->ip);
  212. if (err) {
  213. kvfree(qp->sq.queue->buf);
  214. kfree(qp->sq.queue);
  215. return err;
  216. }
  217. qp->req.wqe_index = producer_index(qp->sq.queue);
  218. qp->req.state = QP_STATE_RESET;
  219. qp->req.opcode = -1;
  220. qp->comp.opcode = -1;
  221. spin_lock_init(&qp->sq.sq_lock);
  222. skb_queue_head_init(&qp->req_pkts);
  223. rxe_init_task(rxe, &qp->req.task, qp,
  224. rxe_requester, "req");
  225. rxe_init_task(rxe, &qp->comp.task, qp,
  226. rxe_completer, "comp");
  227. init_timer(&qp->rnr_nak_timer);
  228. qp->rnr_nak_timer.function = rnr_nak_timer;
  229. qp->rnr_nak_timer.data = (unsigned long)qp;
  230. init_timer(&qp->retrans_timer);
  231. qp->retrans_timer.function = retransmit_timer;
  232. qp->retrans_timer.data = (unsigned long)qp;
  233. qp->qp_timeout_jiffies = 0; /* Can't be set for UD/UC in modify_qp */
  234. return 0;
  235. }
  236. static int rxe_qp_init_resp(struct rxe_dev *rxe, struct rxe_qp *qp,
  237. struct ib_qp_init_attr *init,
  238. struct ib_ucontext *context, struct ib_udata *udata)
  239. {
  240. int err;
  241. int wqe_size;
  242. if (!qp->srq) {
  243. qp->rq.max_wr = init->cap.max_recv_wr;
  244. qp->rq.max_sge = init->cap.max_recv_sge;
  245. wqe_size = rcv_wqe_size(qp->rq.max_sge);
  246. pr_debug("qp#%d max_wr = %d, max_sge = %d, wqe_size = %d\n",
  247. qp_num(qp), qp->rq.max_wr, qp->rq.max_sge, wqe_size);
  248. qp->rq.queue = rxe_queue_init(rxe,
  249. &qp->rq.max_wr,
  250. wqe_size);
  251. if (!qp->rq.queue)
  252. return -ENOMEM;
  253. err = do_mmap_info(rxe, udata, false, context,
  254. qp->rq.queue->buf,
  255. qp->rq.queue->buf_size,
  256. &qp->rq.queue->ip);
  257. if (err) {
  258. kvfree(qp->rq.queue->buf);
  259. kfree(qp->rq.queue);
  260. return err;
  261. }
  262. }
  263. spin_lock_init(&qp->rq.producer_lock);
  264. spin_lock_init(&qp->rq.consumer_lock);
  265. skb_queue_head_init(&qp->resp_pkts);
  266. rxe_init_task(rxe, &qp->resp.task, qp,
  267. rxe_responder, "resp");
  268. qp->resp.opcode = OPCODE_NONE;
  269. qp->resp.msn = 0;
  270. qp->resp.state = QP_STATE_RESET;
  271. return 0;
  272. }
  273. /* called by the create qp verb */
  274. int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
  275. struct ib_qp_init_attr *init, struct ib_udata *udata,
  276. struct ib_pd *ibpd)
  277. {
  278. int err;
  279. struct rxe_cq *rcq = to_rcq(init->recv_cq);
  280. struct rxe_cq *scq = to_rcq(init->send_cq);
  281. struct rxe_srq *srq = init->srq ? to_rsrq(init->srq) : NULL;
  282. struct ib_ucontext *context = udata ? ibpd->uobject->context : NULL;
  283. rxe_add_ref(pd);
  284. rxe_add_ref(rcq);
  285. rxe_add_ref(scq);
  286. if (srq)
  287. rxe_add_ref(srq);
  288. qp->pd = pd;
  289. qp->rcq = rcq;
  290. qp->scq = scq;
  291. qp->srq = srq;
  292. rxe_qp_init_misc(rxe, qp, init);
  293. err = rxe_qp_init_req(rxe, qp, init, context, udata);
  294. if (err)
  295. goto err1;
  296. err = rxe_qp_init_resp(rxe, qp, init, context, udata);
  297. if (err)
  298. goto err2;
  299. qp->attr.qp_state = IB_QPS_RESET;
  300. qp->valid = 1;
  301. return 0;
  302. err2:
  303. rxe_queue_cleanup(qp->sq.queue);
  304. err1:
  305. if (srq)
  306. rxe_drop_ref(srq);
  307. rxe_drop_ref(scq);
  308. rxe_drop_ref(rcq);
  309. rxe_drop_ref(pd);
  310. return err;
  311. }
  312. /* called by the query qp verb */
  313. int rxe_qp_to_init(struct rxe_qp *qp, struct ib_qp_init_attr *init)
  314. {
  315. init->event_handler = qp->ibqp.event_handler;
  316. init->qp_context = qp->ibqp.qp_context;
  317. init->send_cq = qp->ibqp.send_cq;
  318. init->recv_cq = qp->ibqp.recv_cq;
  319. init->srq = qp->ibqp.srq;
  320. init->cap.max_send_wr = qp->sq.max_wr;
  321. init->cap.max_send_sge = qp->sq.max_sge;
  322. init->cap.max_inline_data = qp->sq.max_inline;
  323. if (!qp->srq) {
  324. init->cap.max_recv_wr = qp->rq.max_wr;
  325. init->cap.max_recv_sge = qp->rq.max_sge;
  326. }
  327. init->sq_sig_type = qp->sq_sig_type;
  328. init->qp_type = qp->ibqp.qp_type;
  329. init->port_num = 1;
  330. return 0;
  331. }
  332. /* called by the modify qp verb, this routine checks all the parameters before
  333. * making any changes
  334. */
  335. int rxe_qp_chk_attr(struct rxe_dev *rxe, struct rxe_qp *qp,
  336. struct ib_qp_attr *attr, int mask)
  337. {
  338. enum ib_qp_state cur_state = (mask & IB_QP_CUR_STATE) ?
  339. attr->cur_qp_state : qp->attr.qp_state;
  340. enum ib_qp_state new_state = (mask & IB_QP_STATE) ?
  341. attr->qp_state : cur_state;
  342. if (!ib_modify_qp_is_ok(cur_state, new_state, qp_type(qp), mask,
  343. IB_LINK_LAYER_ETHERNET)) {
  344. pr_warn("invalid mask or state for qp\n");
  345. goto err1;
  346. }
  347. if (mask & IB_QP_STATE) {
  348. if (cur_state == IB_QPS_SQD) {
  349. if (qp->req.state == QP_STATE_DRAIN &&
  350. new_state != IB_QPS_ERR)
  351. goto err1;
  352. }
  353. }
  354. if (mask & IB_QP_PORT) {
  355. if (attr->port_num != 1) {
  356. pr_warn("invalid port %d\n", attr->port_num);
  357. goto err1;
  358. }
  359. }
  360. if (mask & IB_QP_CAP && rxe_qp_chk_cap(rxe, &attr->cap, !!qp->srq))
  361. goto err1;
  362. if (mask & IB_QP_AV && rxe_av_chk_attr(rxe, &attr->ah_attr))
  363. goto err1;
  364. if (mask & IB_QP_ALT_PATH) {
  365. if (rxe_av_chk_attr(rxe, &attr->alt_ah_attr))
  366. goto err1;
  367. if (attr->alt_port_num != 1) {
  368. pr_warn("invalid alt port %d\n", attr->alt_port_num);
  369. goto err1;
  370. }
  371. if (attr->alt_timeout > 31) {
  372. pr_warn("invalid QP alt timeout %d > 31\n",
  373. attr->alt_timeout);
  374. goto err1;
  375. }
  376. }
  377. if (mask & IB_QP_PATH_MTU) {
  378. struct rxe_port *port = &rxe->port;
  379. enum ib_mtu max_mtu = port->attr.max_mtu;
  380. enum ib_mtu mtu = attr->path_mtu;
  381. if (mtu > max_mtu) {
  382. pr_debug("invalid mtu (%d) > (%d)\n",
  383. ib_mtu_enum_to_int(mtu),
  384. ib_mtu_enum_to_int(max_mtu));
  385. goto err1;
  386. }
  387. }
  388. if (mask & IB_QP_MAX_QP_RD_ATOMIC) {
  389. if (attr->max_rd_atomic > rxe->attr.max_qp_rd_atom) {
  390. pr_warn("invalid max_rd_atomic %d > %d\n",
  391. attr->max_rd_atomic,
  392. rxe->attr.max_qp_rd_atom);
  393. goto err1;
  394. }
  395. }
  396. if (mask & IB_QP_TIMEOUT) {
  397. if (attr->timeout > 31) {
  398. pr_warn("invalid QP timeout %d > 31\n",
  399. attr->timeout);
  400. goto err1;
  401. }
  402. }
  403. return 0;
  404. err1:
  405. return -EINVAL;
  406. }
  407. /* move the qp to the reset state */
  408. static void rxe_qp_reset(struct rxe_qp *qp)
  409. {
  410. /* stop tasks from running */
  411. rxe_disable_task(&qp->resp.task);
  412. /* stop request/comp */
  413. if (qp->sq.queue) {
  414. if (qp_type(qp) == IB_QPT_RC)
  415. rxe_disable_task(&qp->comp.task);
  416. rxe_disable_task(&qp->req.task);
  417. }
  418. /* move qp to the reset state */
  419. qp->req.state = QP_STATE_RESET;
  420. qp->resp.state = QP_STATE_RESET;
  421. /* let state machines reset themselves drain work and packet queues
  422. * etc.
  423. */
  424. __rxe_do_task(&qp->resp.task);
  425. if (qp->sq.queue) {
  426. __rxe_do_task(&qp->comp.task);
  427. __rxe_do_task(&qp->req.task);
  428. rxe_queue_reset(qp->sq.queue);
  429. }
  430. /* cleanup attributes */
  431. atomic_set(&qp->ssn, 0);
  432. qp->req.opcode = -1;
  433. qp->req.need_retry = 0;
  434. qp->req.noack_pkts = 0;
  435. qp->resp.msn = 0;
  436. qp->resp.opcode = -1;
  437. qp->resp.drop_msg = 0;
  438. qp->resp.goto_error = 0;
  439. qp->resp.sent_psn_nak = 0;
  440. if (qp->resp.mr) {
  441. rxe_drop_ref(qp->resp.mr);
  442. qp->resp.mr = NULL;
  443. }
  444. cleanup_rd_atomic_resources(qp);
  445. /* reenable tasks */
  446. rxe_enable_task(&qp->resp.task);
  447. if (qp->sq.queue) {
  448. if (qp_type(qp) == IB_QPT_RC)
  449. rxe_enable_task(&qp->comp.task);
  450. rxe_enable_task(&qp->req.task);
  451. }
  452. }
  453. /* drain the send queue */
  454. static void rxe_qp_drain(struct rxe_qp *qp)
  455. {
  456. if (qp->sq.queue) {
  457. if (qp->req.state != QP_STATE_DRAINED) {
  458. qp->req.state = QP_STATE_DRAIN;
  459. if (qp_type(qp) == IB_QPT_RC)
  460. rxe_run_task(&qp->comp.task, 1);
  461. else
  462. __rxe_do_task(&qp->comp.task);
  463. rxe_run_task(&qp->req.task, 1);
  464. }
  465. }
  466. }
  467. /* move the qp to the error state */
  468. void rxe_qp_error(struct rxe_qp *qp)
  469. {
  470. qp->req.state = QP_STATE_ERROR;
  471. qp->resp.state = QP_STATE_ERROR;
  472. qp->attr.qp_state = IB_QPS_ERR;
  473. /* drain work and packet queues */
  474. rxe_run_task(&qp->resp.task, 1);
  475. if (qp_type(qp) == IB_QPT_RC)
  476. rxe_run_task(&qp->comp.task, 1);
  477. else
  478. __rxe_do_task(&qp->comp.task);
  479. rxe_run_task(&qp->req.task, 1);
  480. }
  481. /* called by the modify qp verb */
  482. int rxe_qp_from_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask,
  483. struct ib_udata *udata)
  484. {
  485. int err;
  486. struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
  487. union ib_gid sgid;
  488. struct ib_gid_attr sgid_attr;
  489. if (mask & IB_QP_MAX_QP_RD_ATOMIC) {
  490. int max_rd_atomic = __roundup_pow_of_two(attr->max_rd_atomic);
  491. qp->attr.max_rd_atomic = max_rd_atomic;
  492. atomic_set(&qp->req.rd_atomic, max_rd_atomic);
  493. }
  494. if (mask & IB_QP_MAX_DEST_RD_ATOMIC) {
  495. int max_dest_rd_atomic =
  496. __roundup_pow_of_two(attr->max_dest_rd_atomic);
  497. qp->attr.max_dest_rd_atomic = max_dest_rd_atomic;
  498. free_rd_atomic_resources(qp);
  499. err = alloc_rd_atomic_resources(qp, max_dest_rd_atomic);
  500. if (err)
  501. return err;
  502. }
  503. if (mask & IB_QP_CUR_STATE)
  504. qp->attr.cur_qp_state = attr->qp_state;
  505. if (mask & IB_QP_EN_SQD_ASYNC_NOTIFY)
  506. qp->attr.en_sqd_async_notify = attr->en_sqd_async_notify;
  507. if (mask & IB_QP_ACCESS_FLAGS)
  508. qp->attr.qp_access_flags = attr->qp_access_flags;
  509. if (mask & IB_QP_PKEY_INDEX)
  510. qp->attr.pkey_index = attr->pkey_index;
  511. if (mask & IB_QP_PORT)
  512. qp->attr.port_num = attr->port_num;
  513. if (mask & IB_QP_QKEY)
  514. qp->attr.qkey = attr->qkey;
  515. if (mask & IB_QP_AV) {
  516. ib_get_cached_gid(&rxe->ib_dev, 1,
  517. attr->ah_attr.grh.sgid_index, &sgid,
  518. &sgid_attr);
  519. rxe_av_from_attr(rxe, attr->port_num, &qp->pri_av,
  520. &attr->ah_attr);
  521. rxe_av_fill_ip_info(rxe, &qp->pri_av, &attr->ah_attr,
  522. &sgid_attr, &sgid);
  523. if (sgid_attr.ndev)
  524. dev_put(sgid_attr.ndev);
  525. }
  526. if (mask & IB_QP_ALT_PATH) {
  527. ib_get_cached_gid(&rxe->ib_dev, 1,
  528. attr->alt_ah_attr.grh.sgid_index, &sgid,
  529. &sgid_attr);
  530. rxe_av_from_attr(rxe, attr->alt_port_num, &qp->alt_av,
  531. &attr->alt_ah_attr);
  532. rxe_av_fill_ip_info(rxe, &qp->alt_av, &attr->alt_ah_attr,
  533. &sgid_attr, &sgid);
  534. if (sgid_attr.ndev)
  535. dev_put(sgid_attr.ndev);
  536. qp->attr.alt_port_num = attr->alt_port_num;
  537. qp->attr.alt_pkey_index = attr->alt_pkey_index;
  538. qp->attr.alt_timeout = attr->alt_timeout;
  539. }
  540. if (mask & IB_QP_PATH_MTU) {
  541. qp->attr.path_mtu = attr->path_mtu;
  542. qp->mtu = ib_mtu_enum_to_int(attr->path_mtu);
  543. }
  544. if (mask & IB_QP_TIMEOUT) {
  545. qp->attr.timeout = attr->timeout;
  546. if (attr->timeout == 0) {
  547. qp->qp_timeout_jiffies = 0;
  548. } else {
  549. /* According to the spec, timeout = 4.096 * 2 ^ attr->timeout [us] */
  550. int j = nsecs_to_jiffies(4096ULL << attr->timeout);
  551. qp->qp_timeout_jiffies = j ? j : 1;
  552. }
  553. }
  554. if (mask & IB_QP_RETRY_CNT) {
  555. qp->attr.retry_cnt = attr->retry_cnt;
  556. qp->comp.retry_cnt = attr->retry_cnt;
  557. pr_debug("qp#%d set retry count = %d\n", qp_num(qp),
  558. attr->retry_cnt);
  559. }
  560. if (mask & IB_QP_RNR_RETRY) {
  561. qp->attr.rnr_retry = attr->rnr_retry;
  562. qp->comp.rnr_retry = attr->rnr_retry;
  563. pr_debug("qp#%d set rnr retry count = %d\n", qp_num(qp),
  564. attr->rnr_retry);
  565. }
  566. if (mask & IB_QP_RQ_PSN) {
  567. qp->attr.rq_psn = (attr->rq_psn & BTH_PSN_MASK);
  568. qp->resp.psn = qp->attr.rq_psn;
  569. pr_debug("qp#%d set resp psn = 0x%x\n", qp_num(qp),
  570. qp->resp.psn);
  571. }
  572. if (mask & IB_QP_MIN_RNR_TIMER) {
  573. qp->attr.min_rnr_timer = attr->min_rnr_timer;
  574. pr_debug("qp#%d set min rnr timer = 0x%x\n", qp_num(qp),
  575. attr->min_rnr_timer);
  576. }
  577. if (mask & IB_QP_SQ_PSN) {
  578. qp->attr.sq_psn = (attr->sq_psn & BTH_PSN_MASK);
  579. qp->req.psn = qp->attr.sq_psn;
  580. qp->comp.psn = qp->attr.sq_psn;
  581. pr_debug("qp#%d set req psn = 0x%x\n", qp_num(qp), qp->req.psn);
  582. }
  583. if (mask & IB_QP_PATH_MIG_STATE)
  584. qp->attr.path_mig_state = attr->path_mig_state;
  585. if (mask & IB_QP_DEST_QPN)
  586. qp->attr.dest_qp_num = attr->dest_qp_num;
  587. if (mask & IB_QP_STATE) {
  588. qp->attr.qp_state = attr->qp_state;
  589. switch (attr->qp_state) {
  590. case IB_QPS_RESET:
  591. pr_debug("qp#%d state -> RESET\n", qp_num(qp));
  592. rxe_qp_reset(qp);
  593. break;
  594. case IB_QPS_INIT:
  595. pr_debug("qp#%d state -> INIT\n", qp_num(qp));
  596. qp->req.state = QP_STATE_INIT;
  597. qp->resp.state = QP_STATE_INIT;
  598. break;
  599. case IB_QPS_RTR:
  600. pr_debug("qp#%d state -> RTR\n", qp_num(qp));
  601. qp->resp.state = QP_STATE_READY;
  602. break;
  603. case IB_QPS_RTS:
  604. pr_debug("qp#%d state -> RTS\n", qp_num(qp));
  605. qp->req.state = QP_STATE_READY;
  606. break;
  607. case IB_QPS_SQD:
  608. pr_debug("qp#%d state -> SQD\n", qp_num(qp));
  609. rxe_qp_drain(qp);
  610. break;
  611. case IB_QPS_SQE:
  612. pr_warn("qp#%d state -> SQE !!?\n", qp_num(qp));
  613. /* Not possible from modify_qp. */
  614. break;
  615. case IB_QPS_ERR:
  616. pr_debug("qp#%d state -> ERR\n", qp_num(qp));
  617. rxe_qp_error(qp);
  618. break;
  619. }
  620. }
  621. return 0;
  622. }
  623. /* called by the query qp verb */
  624. int rxe_qp_to_attr(struct rxe_qp *qp, struct ib_qp_attr *attr, int mask)
  625. {
  626. struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
  627. *attr = qp->attr;
  628. attr->rq_psn = qp->resp.psn;
  629. attr->sq_psn = qp->req.psn;
  630. attr->cap.max_send_wr = qp->sq.max_wr;
  631. attr->cap.max_send_sge = qp->sq.max_sge;
  632. attr->cap.max_inline_data = qp->sq.max_inline;
  633. if (!qp->srq) {
  634. attr->cap.max_recv_wr = qp->rq.max_wr;
  635. attr->cap.max_recv_sge = qp->rq.max_sge;
  636. }
  637. rxe_av_to_attr(rxe, &qp->pri_av, &attr->ah_attr);
  638. rxe_av_to_attr(rxe, &qp->alt_av, &attr->alt_ah_attr);
  639. if (qp->req.state == QP_STATE_DRAIN) {
  640. attr->sq_draining = 1;
  641. /* applications that get this state
  642. * typically spin on it. yield the
  643. * processor
  644. */
  645. cond_resched();
  646. } else {
  647. attr->sq_draining = 0;
  648. }
  649. pr_debug("attr->sq_draining = %d\n", attr->sq_draining);
  650. return 0;
  651. }
  652. /* called by the destroy qp verb */
  653. void rxe_qp_destroy(struct rxe_qp *qp)
  654. {
  655. qp->valid = 0;
  656. qp->qp_timeout_jiffies = 0;
  657. rxe_cleanup_task(&qp->resp.task);
  658. del_timer_sync(&qp->retrans_timer);
  659. del_timer_sync(&qp->rnr_nak_timer);
  660. rxe_cleanup_task(&qp->req.task);
  661. rxe_cleanup_task(&qp->comp.task);
  662. /* flush out any receive wr's or pending requests */
  663. __rxe_do_task(&qp->req.task);
  664. if (qp->sq.queue) {
  665. __rxe_do_task(&qp->comp.task);
  666. __rxe_do_task(&qp->req.task);
  667. }
  668. }
  669. /* called when the last reference to the qp is dropped */
  670. void rxe_qp_cleanup(void *arg)
  671. {
  672. struct rxe_qp *qp = arg;
  673. rxe_drop_all_mcast_groups(qp);
  674. if (qp->sq.queue)
  675. rxe_queue_cleanup(qp->sq.queue);
  676. if (qp->srq)
  677. rxe_drop_ref(qp->srq);
  678. if (qp->rq.queue)
  679. rxe_queue_cleanup(qp->rq.queue);
  680. if (qp->scq)
  681. rxe_drop_ref(qp->scq);
  682. if (qp->rcq)
  683. rxe_drop_ref(qp->rcq);
  684. if (qp->pd)
  685. rxe_drop_ref(qp->pd);
  686. if (qp->resp.mr) {
  687. rxe_drop_ref(qp->resp.mr);
  688. qp->resp.mr = NULL;
  689. }
  690. free_rd_atomic_resources(qp);
  691. kernel_sock_shutdown(qp->sk, SHUT_RDWR);
  692. sock_release(qp->sk);
  693. }