c2_ae.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /*
  2. * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
  3. * Copyright (c) 2005 Open Grid Computing, 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 "c2.h"
  34. #include <rdma/iw_cm.h>
  35. #include "c2_status.h"
  36. #include "c2_ae.h"
  37. static int c2_convert_cm_status(u32 c2_status)
  38. {
  39. switch (c2_status) {
  40. case C2_CONN_STATUS_SUCCESS:
  41. return 0;
  42. case C2_CONN_STATUS_REJECTED:
  43. return -ENETRESET;
  44. case C2_CONN_STATUS_REFUSED:
  45. return -ECONNREFUSED;
  46. case C2_CONN_STATUS_TIMEDOUT:
  47. return -ETIMEDOUT;
  48. case C2_CONN_STATUS_NETUNREACH:
  49. return -ENETUNREACH;
  50. case C2_CONN_STATUS_HOSTUNREACH:
  51. return -EHOSTUNREACH;
  52. case C2_CONN_STATUS_INVALID_RNIC:
  53. return -EINVAL;
  54. case C2_CONN_STATUS_INVALID_QP:
  55. return -EINVAL;
  56. case C2_CONN_STATUS_INVALID_QP_STATE:
  57. return -EINVAL;
  58. case C2_CONN_STATUS_ADDR_NOT_AVAIL:
  59. return -EADDRNOTAVAIL;
  60. default:
  61. printk(KERN_ERR PFX
  62. "%s - Unable to convert CM status: %d\n",
  63. __func__, c2_status);
  64. return -EIO;
  65. }
  66. }
  67. static const char* to_event_str(int event)
  68. {
  69. static const char* event_str[] = {
  70. "CCAE_REMOTE_SHUTDOWN",
  71. "CCAE_ACTIVE_CONNECT_RESULTS",
  72. "CCAE_CONNECTION_REQUEST",
  73. "CCAE_LLP_CLOSE_COMPLETE",
  74. "CCAE_TERMINATE_MESSAGE_RECEIVED",
  75. "CCAE_LLP_CONNECTION_RESET",
  76. "CCAE_LLP_CONNECTION_LOST",
  77. "CCAE_LLP_SEGMENT_SIZE_INVALID",
  78. "CCAE_LLP_INVALID_CRC",
  79. "CCAE_LLP_BAD_FPDU",
  80. "CCAE_INVALID_DDP_VERSION",
  81. "CCAE_INVALID_RDMA_VERSION",
  82. "CCAE_UNEXPECTED_OPCODE",
  83. "CCAE_INVALID_DDP_QUEUE_NUMBER",
  84. "CCAE_RDMA_READ_NOT_ENABLED",
  85. "CCAE_RDMA_WRITE_NOT_ENABLED",
  86. "CCAE_RDMA_READ_TOO_SMALL",
  87. "CCAE_NO_L_BIT",
  88. "CCAE_TAGGED_INVALID_STAG",
  89. "CCAE_TAGGED_BASE_BOUNDS_VIOLATION",
  90. "CCAE_TAGGED_ACCESS_RIGHTS_VIOLATION",
  91. "CCAE_TAGGED_INVALID_PD",
  92. "CCAE_WRAP_ERROR",
  93. "CCAE_BAD_CLOSE",
  94. "CCAE_BAD_LLP_CLOSE",
  95. "CCAE_INVALID_MSN_RANGE",
  96. "CCAE_INVALID_MSN_GAP",
  97. "CCAE_IRRQ_OVERFLOW",
  98. "CCAE_IRRQ_MSN_GAP",
  99. "CCAE_IRRQ_MSN_RANGE",
  100. "CCAE_IRRQ_INVALID_STAG",
  101. "CCAE_IRRQ_BASE_BOUNDS_VIOLATION",
  102. "CCAE_IRRQ_ACCESS_RIGHTS_VIOLATION",
  103. "CCAE_IRRQ_INVALID_PD",
  104. "CCAE_IRRQ_WRAP_ERROR",
  105. "CCAE_CQ_SQ_COMPLETION_OVERFLOW",
  106. "CCAE_CQ_RQ_COMPLETION_ERROR",
  107. "CCAE_QP_SRQ_WQE_ERROR",
  108. "CCAE_QP_LOCAL_CATASTROPHIC_ERROR",
  109. "CCAE_CQ_OVERFLOW",
  110. "CCAE_CQ_OPERATION_ERROR",
  111. "CCAE_SRQ_LIMIT_REACHED",
  112. "CCAE_QP_RQ_LIMIT_REACHED",
  113. "CCAE_SRQ_CATASTROPHIC_ERROR",
  114. "CCAE_RNIC_CATASTROPHIC_ERROR"
  115. };
  116. if (event < CCAE_REMOTE_SHUTDOWN ||
  117. event > CCAE_RNIC_CATASTROPHIC_ERROR)
  118. return "<invalid event>";
  119. event -= CCAE_REMOTE_SHUTDOWN;
  120. return event_str[event];
  121. }
  122. static const char *to_qp_state_str(int state)
  123. {
  124. switch (state) {
  125. case C2_QP_STATE_IDLE:
  126. return "C2_QP_STATE_IDLE";
  127. case C2_QP_STATE_CONNECTING:
  128. return "C2_QP_STATE_CONNECTING";
  129. case C2_QP_STATE_RTS:
  130. return "C2_QP_STATE_RTS";
  131. case C2_QP_STATE_CLOSING:
  132. return "C2_QP_STATE_CLOSING";
  133. case C2_QP_STATE_TERMINATE:
  134. return "C2_QP_STATE_TERMINATE";
  135. case C2_QP_STATE_ERROR:
  136. return "C2_QP_STATE_ERROR";
  137. default:
  138. return "<invalid QP state>";
  139. }
  140. }
  141. void c2_ae_event(struct c2_dev *c2dev, u32 mq_index)
  142. {
  143. struct c2_mq *mq = c2dev->qptr_array[mq_index];
  144. union c2wr *wr;
  145. void *resource_user_context;
  146. struct iw_cm_event cm_event;
  147. struct ib_event ib_event;
  148. enum c2_resource_indicator resource_indicator;
  149. enum c2_event_id event_id;
  150. unsigned long flags;
  151. int status;
  152. struct sockaddr_in *laddr = (struct sockaddr_in *)&cm_event.local_addr;
  153. struct sockaddr_in *raddr = (struct sockaddr_in *)&cm_event.remote_addr;
  154. /*
  155. * retrieve the message
  156. */
  157. wr = c2_mq_consume(mq);
  158. if (!wr)
  159. return;
  160. memset(&ib_event, 0, sizeof(ib_event));
  161. memset(&cm_event, 0, sizeof(cm_event));
  162. event_id = c2_wr_get_id(wr);
  163. resource_indicator = be32_to_cpu(wr->ae.ae_generic.resource_type);
  164. resource_user_context =
  165. (void *) (unsigned long) wr->ae.ae_generic.user_context;
  166. status = cm_event.status = c2_convert_cm_status(c2_wr_get_result(wr));
  167. pr_debug("event received c2_dev=%p, event_id=%d, "
  168. "resource_indicator=%d, user_context=%p, status = %d\n",
  169. c2dev, event_id, resource_indicator, resource_user_context,
  170. status);
  171. switch (resource_indicator) {
  172. case C2_RES_IND_QP:{
  173. struct c2_qp *qp = (struct c2_qp *)resource_user_context;
  174. struct iw_cm_id *cm_id = qp->cm_id;
  175. struct c2wr_ae_active_connect_results *res;
  176. if (!cm_id) {
  177. pr_debug("event received, but cm_id is <nul>, qp=%p!\n",
  178. qp);
  179. goto ignore_it;
  180. }
  181. pr_debug("%s: event = %s, user_context=%llx, "
  182. "resource_type=%x, "
  183. "resource=%x, qp_state=%s\n",
  184. __func__,
  185. to_event_str(event_id),
  186. (unsigned long long) wr->ae.ae_generic.user_context,
  187. be32_to_cpu(wr->ae.ae_generic.resource_type),
  188. be32_to_cpu(wr->ae.ae_generic.resource),
  189. to_qp_state_str(be32_to_cpu(wr->ae.ae_generic.qp_state)));
  190. c2_set_qp_state(qp, be32_to_cpu(wr->ae.ae_generic.qp_state));
  191. switch (event_id) {
  192. case CCAE_ACTIVE_CONNECT_RESULTS:
  193. res = &wr->ae.ae_active_connect_results;
  194. cm_event.event = IW_CM_EVENT_CONNECT_REPLY;
  195. laddr->sin_addr.s_addr = res->laddr;
  196. raddr->sin_addr.s_addr = res->raddr;
  197. laddr->sin_port = res->lport;
  198. raddr->sin_port = res->rport;
  199. if (status == 0) {
  200. cm_event.private_data_len =
  201. be32_to_cpu(res->private_data_length);
  202. cm_event.private_data = res->private_data;
  203. } else {
  204. spin_lock_irqsave(&qp->lock, flags);
  205. if (qp->cm_id) {
  206. qp->cm_id->rem_ref(qp->cm_id);
  207. qp->cm_id = NULL;
  208. }
  209. spin_unlock_irqrestore(&qp->lock, flags);
  210. cm_event.private_data_len = 0;
  211. cm_event.private_data = NULL;
  212. }
  213. if (cm_id->event_handler)
  214. cm_id->event_handler(cm_id, &cm_event);
  215. break;
  216. case CCAE_TERMINATE_MESSAGE_RECEIVED:
  217. case CCAE_CQ_SQ_COMPLETION_OVERFLOW:
  218. ib_event.device = &c2dev->ibdev;
  219. ib_event.element.qp = &qp->ibqp;
  220. ib_event.event = IB_EVENT_QP_REQ_ERR;
  221. if (qp->ibqp.event_handler)
  222. qp->ibqp.event_handler(&ib_event,
  223. qp->ibqp.
  224. qp_context);
  225. break;
  226. case CCAE_BAD_CLOSE:
  227. case CCAE_LLP_CLOSE_COMPLETE:
  228. case CCAE_LLP_CONNECTION_RESET:
  229. case CCAE_LLP_CONNECTION_LOST:
  230. BUG_ON(cm_id->event_handler==(void*)0x6b6b6b6b);
  231. spin_lock_irqsave(&qp->lock, flags);
  232. if (qp->cm_id) {
  233. qp->cm_id->rem_ref(qp->cm_id);
  234. qp->cm_id = NULL;
  235. }
  236. spin_unlock_irqrestore(&qp->lock, flags);
  237. cm_event.event = IW_CM_EVENT_CLOSE;
  238. cm_event.status = 0;
  239. if (cm_id->event_handler)
  240. cm_id->event_handler(cm_id, &cm_event);
  241. break;
  242. default:
  243. BUG_ON(1);
  244. pr_debug("%s:%d Unexpected event_id=%d on QP=%p, "
  245. "CM_ID=%p\n",
  246. __func__, __LINE__,
  247. event_id, qp, cm_id);
  248. break;
  249. }
  250. break;
  251. }
  252. case C2_RES_IND_EP:{
  253. struct c2wr_ae_connection_request *req =
  254. &wr->ae.ae_connection_request;
  255. struct iw_cm_id *cm_id =
  256. (struct iw_cm_id *)resource_user_context;
  257. pr_debug("C2_RES_IND_EP event_id=%d\n", event_id);
  258. if (event_id != CCAE_CONNECTION_REQUEST) {
  259. pr_debug("%s: Invalid event_id: %d\n",
  260. __func__, event_id);
  261. break;
  262. }
  263. cm_event.event = IW_CM_EVENT_CONNECT_REQUEST;
  264. cm_event.provider_data = (void*)(unsigned long)req->cr_handle;
  265. laddr->sin_addr.s_addr = req->laddr;
  266. raddr->sin_addr.s_addr = req->raddr;
  267. laddr->sin_port = req->lport;
  268. raddr->sin_port = req->rport;
  269. cm_event.private_data_len =
  270. be32_to_cpu(req->private_data_length);
  271. cm_event.private_data = req->private_data;
  272. /*
  273. * Until ird/ord negotiation via MPAv2 support is added, send
  274. * max supported values
  275. */
  276. cm_event.ird = cm_event.ord = 128;
  277. if (cm_id->event_handler)
  278. cm_id->event_handler(cm_id, &cm_event);
  279. break;
  280. }
  281. case C2_RES_IND_CQ:{
  282. struct c2_cq *cq =
  283. (struct c2_cq *) resource_user_context;
  284. pr_debug("IB_EVENT_CQ_ERR\n");
  285. ib_event.device = &c2dev->ibdev;
  286. ib_event.element.cq = &cq->ibcq;
  287. ib_event.event = IB_EVENT_CQ_ERR;
  288. if (cq->ibcq.event_handler)
  289. cq->ibcq.event_handler(&ib_event,
  290. cq->ibcq.cq_context);
  291. break;
  292. }
  293. default:
  294. printk("Bad resource indicator = %d\n",
  295. resource_indicator);
  296. break;
  297. }
  298. ignore_it:
  299. c2_mq_free(mq);
  300. }