cm_msgs.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
  2. /*
  3. * Copyright (c) 2004, 2011 Intel Corporation. All rights reserved.
  4. * Copyright (c) 2004 Topspin Corporation. All rights reserved.
  5. * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
  6. * Copyright (c) 2019, Mellanox Technologies inc. All rights reserved.
  7. */
  8. #ifndef CM_MSGS_H
  9. #define CM_MSGS_H
  10. #include <rdma/ibta_vol1_c12.h>
  11. #include <rdma/ib_mad.h>
  12. #include <rdma/ib_cm.h>
  13. /*
  14. * Parameters to routines below should be in network-byte order, and values
  15. * are returned in network-byte order.
  16. */
  17. #define IB_CM_CLASS_VERSION 2 /* IB specification 1.2 */
  18. static inline enum ib_qp_type cm_req_get_qp_type(struct cm_req_msg *req_msg)
  19. {
  20. u8 transport_type = IBA_GET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg);
  21. switch(transport_type) {
  22. case 0: return IB_QPT_RC;
  23. case 1: return IB_QPT_UC;
  24. case 3:
  25. switch (IBA_GET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg)) {
  26. case 1: return IB_QPT_XRC_TGT;
  27. default: return 0;
  28. }
  29. default: return 0;
  30. }
  31. }
  32. static inline void cm_req_set_qp_type(struct cm_req_msg *req_msg,
  33. enum ib_qp_type qp_type)
  34. {
  35. switch(qp_type) {
  36. case IB_QPT_UC:
  37. IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 1);
  38. break;
  39. case IB_QPT_XRC_INI:
  40. IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 3);
  41. IBA_SET(CM_REQ_EXTENDED_TRANSPORT_TYPE, req_msg, 1);
  42. break;
  43. default:
  44. IBA_SET(CM_REQ_TRANSPORT_SERVICE_TYPE, req_msg, 0);
  45. }
  46. }
  47. /* Message REJected or MRAed */
  48. enum cm_msg_response {
  49. CM_MSG_RESPONSE_REQ = 0x0,
  50. CM_MSG_RESPONSE_REP = 0x1,
  51. CM_MSG_RESPONSE_OTHER = 0x2
  52. };
  53. static inline __be32 cm_rep_get_qpn(struct cm_rep_msg *rep_msg, enum ib_qp_type qp_type)
  54. {
  55. return (qp_type == IB_QPT_XRC_INI) ?
  56. cpu_to_be32(IBA_GET(CM_REP_LOCAL_EE_CONTEXT_NUMBER,
  57. rep_msg)) :
  58. cpu_to_be32(IBA_GET(CM_REP_LOCAL_QPN, rep_msg));
  59. }
  60. #endif /* CM_MSGS_H */